mirror of
https://github.com/VDR4Arch/vdr.git
synced 2023-10-10 13:36:52 +02:00
The device /dev/video is now opened only if necessary (to GRAB an image)
This commit is contained in:
parent
9bba1ce73e
commit
2f7f2084a5
2
HISTORY
2
HISTORY
@ -863,3 +863,5 @@ Video Disk Recorder Revision History
|
|||||||
- Removed all video overlay stuff from cDvbApi and SVDRP. Guido Fiala's new
|
- Removed all video overlay stuff from cDvbApi and SVDRP. Guido Fiala's new
|
||||||
'kvdr' version 0.4 now does these things itself. As a consequence of this you
|
'kvdr' version 0.4 now does these things itself. As a consequence of this you
|
||||||
will now need to use kvdr 0.4 or later.
|
will now need to use kvdr 0.4 or later.
|
||||||
|
- The device /dev/video is now opened only if necessary (to GRAB an image),
|
||||||
|
allowing other programs (like 'kvdr', for instance) to use that device.
|
||||||
|
170
dvbapi.c
170
dvbapi.c
@ -7,7 +7,7 @@
|
|||||||
* DVD support initially written by Andreas Schultz <aschultz@warp10.net>
|
* DVD support initially written by Andreas Schultz <aschultz@warp10.net>
|
||||||
* based on dvdplayer-0.5 by Matjaz Thaler <matjaz.thaler@guest.arnes.si>
|
* based on dvdplayer-0.5 by Matjaz Thaler <matjaz.thaler@guest.arnes.si>
|
||||||
*
|
*
|
||||||
* $Id: dvbapi.c 1.136 2001/11/04 11:30:00 kls Exp $
|
* $Id: dvbapi.c 1.137 2001/11/04 12:05:36 kls Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//#define DVDDEBUG 1
|
//#define DVDDEBUG 1
|
||||||
@ -2557,10 +2557,6 @@ cDvbApi::cDvbApi(int n)
|
|||||||
fd_video = OstOpen(DEV_OST_VIDEO, n, O_RDWR | O_NONBLOCK);
|
fd_video = OstOpen(DEV_OST_VIDEO, n, O_RDWR | O_NONBLOCK);
|
||||||
fd_audio = OstOpen(DEV_OST_AUDIO, n, O_RDWR | O_NONBLOCK);
|
fd_audio = OstOpen(DEV_OST_AUDIO, n, O_RDWR | O_NONBLOCK);
|
||||||
|
|
||||||
// Devices that may not be available, and are not necessary for normal operation:
|
|
||||||
|
|
||||||
videoDev = OstOpen(DEV_VIDEO, n, O_RDWR);
|
|
||||||
|
|
||||||
// Devices that will be dynamically opened and closed when necessary:
|
// Devices that will be dynamically opened and closed when necessary:
|
||||||
|
|
||||||
fd_dvr = -1;
|
fd_dvr = -1;
|
||||||
@ -2725,91 +2721,93 @@ const cSchedules *cDvbApi::Schedules(cThreadLock *ThreadLock) const
|
|||||||
|
|
||||||
bool cDvbApi::GrabImage(const char *FileName, bool Jpeg, int Quality, int SizeX, int SizeY)
|
bool cDvbApi::GrabImage(const char *FileName, bool Jpeg, int Quality, int SizeX, int SizeY)
|
||||||
{
|
{
|
||||||
if (videoDev < 0)
|
|
||||||
return false;
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
// just do this once?
|
int videoDev = OstOpen(DEV_VIDEO, CardIndex(), O_RDWR);
|
||||||
struct video_mbuf mbuf;
|
if (videoDev >= 0) {
|
||||||
result |= ioctl(videoDev, VIDIOCGMBUF, &mbuf);
|
struct video_mbuf mbuf;
|
||||||
int msize = mbuf.size;
|
result |= ioctl(videoDev, VIDIOCGMBUF, &mbuf);
|
||||||
// gf: this needs to be a protected member of cDvbApi! //XXX kls: WHY???
|
if (result == 0) {
|
||||||
unsigned char *mem = (unsigned char *)mmap(0, msize, PROT_READ | PROT_WRITE, MAP_SHARED, videoDev, 0);
|
int msize = mbuf.size;
|
||||||
if (!mem || mem == (unsigned char *)-1)
|
unsigned char *mem = (unsigned char *)mmap(0, msize, PROT_READ | PROT_WRITE, MAP_SHARED, videoDev, 0);
|
||||||
return false;
|
if (mem && mem != (unsigned char *)-1) {
|
||||||
// set up the size and RGB
|
// set up the size and RGB
|
||||||
struct video_capability vc;
|
struct video_capability vc;
|
||||||
result |= ioctl(videoDev, VIDIOCGCAP, &vc);
|
result |= ioctl(videoDev, VIDIOCGCAP, &vc);
|
||||||
struct video_mmap vm;
|
struct video_mmap vm;
|
||||||
vm.frame = 0;
|
vm.frame = 0;
|
||||||
if ((SizeX > 0) && (SizeX <= vc.maxwidth) &&
|
if ((SizeX > 0) && (SizeX <= vc.maxwidth) &&
|
||||||
(SizeY > 0) && (SizeY <= vc.maxheight)) {
|
(SizeY > 0) && (SizeY <= vc.maxheight)) {
|
||||||
vm.width = SizeX;
|
vm.width = SizeX;
|
||||||
vm.height = SizeY;
|
vm.height = SizeY;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
vm.width = vc.maxwidth;
|
vm.width = vc.maxwidth;
|
||||||
vm.height = vc.maxheight;
|
vm.height = vc.maxheight;
|
||||||
}
|
}
|
||||||
vm.format = VIDEO_PALETTE_RGB24;
|
vm.format = VIDEO_PALETTE_RGB24;
|
||||||
// this needs to be done every time:
|
result |= ioctl(videoDev, VIDIOCMCAPTURE, &vm);
|
||||||
result |= ioctl(videoDev, VIDIOCMCAPTURE, &vm);
|
result |= ioctl(videoDev, VIDIOCSYNC, &vm.frame);
|
||||||
result |= ioctl(videoDev, VIDIOCSYNC, &vm.frame);
|
// make RGB out of BGR:
|
||||||
// make RGB out of BGR:
|
int memsize = vm.width * vm.height;
|
||||||
int memsize = vm.width * vm.height;
|
unsigned char *mem1 = mem;
|
||||||
unsigned char *mem1 = mem;
|
for (int i = 0; i < memsize; i++) {
|
||||||
for (int i = 0; i < memsize; i++) {
|
unsigned char tmp = mem1[2];
|
||||||
unsigned char tmp = mem1[2];
|
mem1[2] = mem1[0];
|
||||||
mem1[2] = mem1[0];
|
mem1[0] = tmp;
|
||||||
mem1[0] = tmp;
|
mem1 += 3;
|
||||||
mem1 += 3;
|
}
|
||||||
}
|
|
||||||
|
if (Quality < 0)
|
||||||
if (Quality < 0)
|
Quality = 255; //XXX is this 'best'???
|
||||||
Quality = 255; //XXX is this 'best'???
|
|
||||||
|
isyslog(LOG_INFO, "grabbing to %s (%s %d %d %d)", FileName, Jpeg ? "JPEG" : "PNM", Quality, vm.width, vm.height);
|
||||||
isyslog(LOG_INFO, "grabbing to %s (%s %d %d %d)", FileName, Jpeg ? "JPEG" : "PNM", Quality, vm.width, vm.height);
|
FILE *f = fopen(FileName, "wb");
|
||||||
FILE *f = fopen(FileName, "wb");
|
if (f) {
|
||||||
if (f) {
|
if (Jpeg) {
|
||||||
if (Jpeg) {
|
// write JPEG file:
|
||||||
// write JPEG file:
|
struct jpeg_compress_struct cinfo;
|
||||||
struct jpeg_compress_struct cinfo;
|
struct jpeg_error_mgr jerr;
|
||||||
struct jpeg_error_mgr jerr;
|
cinfo.err = jpeg_std_error(&jerr);
|
||||||
cinfo.err = jpeg_std_error(&jerr);
|
jpeg_create_compress(&cinfo);
|
||||||
jpeg_create_compress(&cinfo);
|
jpeg_stdio_dest(&cinfo, f);
|
||||||
jpeg_stdio_dest(&cinfo, f);
|
cinfo.image_width = vm.width;
|
||||||
cinfo.image_width = vm.width;
|
cinfo.image_height = vm.height;
|
||||||
cinfo.image_height = vm.height;
|
cinfo.input_components = 3;
|
||||||
cinfo.input_components = 3;
|
cinfo.in_color_space = JCS_RGB;
|
||||||
cinfo.in_color_space = JCS_RGB;
|
|
||||||
|
jpeg_set_defaults(&cinfo);
|
||||||
jpeg_set_defaults(&cinfo);
|
jpeg_set_quality(&cinfo, Quality, true);
|
||||||
jpeg_set_quality(&cinfo, Quality, true);
|
jpeg_start_compress(&cinfo, true);
|
||||||
jpeg_start_compress(&cinfo, true);
|
|
||||||
|
int rs = vm.width * 3;
|
||||||
int rs = vm.width * 3;
|
JSAMPROW rp[vm.height];
|
||||||
JSAMPROW rp[vm.height];
|
for (int k = 0; k < vm.height; k++)
|
||||||
for (int k = 0; k < vm.height; k++)
|
rp[k] = &mem[rs * k];
|
||||||
rp[k] = &mem[rs * k];
|
jpeg_write_scanlines(&cinfo, rp, vm.height);
|
||||||
jpeg_write_scanlines(&cinfo, rp, vm.height);
|
jpeg_finish_compress(&cinfo);
|
||||||
jpeg_finish_compress(&cinfo);
|
jpeg_destroy_compress(&cinfo);
|
||||||
jpeg_destroy_compress(&cinfo);
|
}
|
||||||
}
|
else {
|
||||||
else {
|
// write PNM file:
|
||||||
// write PNM file:
|
if (fprintf(f, "P6\n%d\n%d\n255\n", vm.width, vm.height) < 0 ||
|
||||||
if (fprintf(f, "P6\n%d\n%d\n255\n", vm.width, vm.height) < 0 ||
|
fwrite(mem, vm.width * vm.height * 3, 1, f) < 0) {
|
||||||
fwrite(mem, vm.width * vm.height * 3, 1, f) < 0) {
|
LOG_ERROR_STR(FileName);
|
||||||
LOG_ERROR_STR(FileName);
|
result |= 1;
|
||||||
result |= 1;
|
}
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LOG_ERROR_STR(FileName);
|
||||||
|
result |= 1;
|
||||||
|
}
|
||||||
|
munmap(mem, msize);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
result |= 1;
|
||||||
}
|
}
|
||||||
fclose(f);
|
close(videoDev);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
LOG_ERROR_STR(FileName);
|
|
||||||
result |= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
munmap(mem, msize);
|
|
||||||
return result == 0;
|
return result == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
dvbapi.h
3
dvbapi.h
@ -4,7 +4,7 @@
|
|||||||
* See the main source file 'vdr.c' for copyright information and
|
* See the main source file 'vdr.c' for copyright information and
|
||||||
* how to reach the author.
|
* how to reach the author.
|
||||||
*
|
*
|
||||||
* $Id: dvbapi.h 1.57 2001/11/04 11:27:18 kls Exp $
|
* $Id: dvbapi.h 1.58 2001/11/04 11:39:42 kls Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __DVBAPI_H
|
#ifndef __DVBAPI_H
|
||||||
@ -84,7 +84,6 @@ class cDvbApi {
|
|||||||
friend class cTransferBuffer;
|
friend class cTransferBuffer;
|
||||||
private:
|
private:
|
||||||
FrontendType frontendType;
|
FrontendType frontendType;
|
||||||
int videoDev;
|
|
||||||
int fd_osd, fd_frontend, fd_sec, fd_dvr, fd_audio, fd_video, fd_demuxa1, fd_demuxa2, fd_demuxd1, fd_demuxd2, fd_demuxv, fd_demuxt;
|
int fd_osd, fd_frontend, fd_sec, fd_dvr, fd_audio, fd_video, fd_demuxa1, fd_demuxa2, fd_demuxd1, fd_demuxd2, fd_demuxv, fd_demuxt;
|
||||||
int vPid, aPid1, aPid2, dPid1, dPid2;
|
int vPid, aPid1, aPid2, dPid1, dPid2;
|
||||||
bool SetPid(int fd, dmxPesType_t PesType, int Pid, dmxOutput_t Output);
|
bool SetPid(int fd, dmxPesType_t PesType, int Pid, dmxOutput_t Output);
|
||||||
|
Loading…
Reference in New Issue
Block a user