[vdr] [PATCH] vdr-xine 0.7.6: fix GRAB for VDR 1.3.38
Darren Salt
linux at youmustbejoking.demon.co.uk
Thu Jan 12 01:50:20 CET 2006
vdr-xine's support for GRAB is broken by VDR 1.3.38. This patch restores it.
--
| Darren Salt | d youmustbejoking,demon,co,uk | nr. Ashington,
| Debian, | s zap,tartarus,org | Northumberland
| RISC OS | @ | Toon Army
| I don't ask for much, just untold riches...
Your disk will self-destruct in 5 seconds.
-------------- next part --------------
diff -urNad vdr-plugin-xine-0.7.6~/xineDevice.c vdr-plugin-xine-0.7.6/xineDevice.c
--- vdr-plugin-xine-0.7.6~/xineDevice.c 2006-01-12 00:43:12.000000000 +0000
+++ vdr-plugin-xine-0.7.6/xineDevice.c 2006-01-12 00:43:12.715161206 +0000
@@ -2487,18 +2487,13 @@
return Length;
}
- bool cXineDevice::GrabImage(const char *FileName, bool Jpeg /* = true */, int Quality /* = -1 */, int SizeX /* = -1 */, int SizeY /* = -1 */)
+ uchar *cXineDevice::GrabImage(int &Size, bool Jpeg /* = true */, int Quality /* = -1 */, int SizeX /* = -1 */, int SizeY /* = -1 */)
{
xfprintf(stderr, "GrabImage ...\n\n");
-
- if (m_xineLib.execFuncGrabImage(FileName, Jpeg, Quality, SizeX, SizeY))
- {
- xfprintf(stderr, "\nGrabImage succeeded.\n");
- return true;
- }
- xfprintf(stderr, "\nGrabImage failed.\n");
- return false;
+ uchar *result = m_xineLib.execFuncGrabImage(Size, Jpeg, Quality, SizeX, SizeY);
+ xfprintf(stderr, result ? "\nGrabImage succeeded.\n" : "\nGrabImage failed.\n");
+ return result;
}
int64_t cXineDevice::GetSTC(void)
diff -urNad vdr-plugin-xine-0.7.6~/xineDevice.h vdr-plugin-xine-0.7.6/xineDevice.h
--- vdr-plugin-xine-0.7.6~/xineDevice.h 2006-01-12 00:43:12.000000000 +0000
+++ vdr-plugin-xine-0.7.6/xineDevice.h 2006-01-12 00:43:12.715161206 +0000
@@ -66,7 +66,7 @@
int PlayCommon2(const uchar *Data, int Length);
int PlayCommon3(const uchar *Data, int Length);
- virtual bool GrabImage(const char *FileName, bool Jpeg = true, int Quality = -1, int SizeX = -1, int SizeY = -1);
+ virtual uchar *GrabImage(int &Size, bool Jpeg = true, int Quality = -1, int SizeX = -1, int SizeY = -1);
virtual void SetVideoFormat(bool VideoFormat16_9);
virtual void SetVolumeDevice(int Volume);
diff -urNad vdr-plugin-xine-0.7.6~/xineLib.c vdr-plugin-xine-0.7.6/xineLib.c
--- vdr-plugin-xine-0.7.6~/xineLib.c 2006-01-12 00:43:12.000000000 +0000
+++ vdr-plugin-xine-0.7.6/xineLib.c 2006-01-12 00:45:33.377856050 +0000
@@ -3444,7 +3444,7 @@
#define PNMTOJPEG "pnmtojpeg"
#endif
- bool cXineLib::execFuncGrabImage(const char *FileName, bool Jpeg, int Quality, int SizeX, int SizeY)
+ uchar *cXineLib::execFuncGrabImage(int &Size, bool Jpeg, int Quality, int SizeX, int SizeY)
{
if (!isConnected())
return false;
@@ -3453,7 +3453,7 @@
cMutexLock ioLock(&m_ioMutex);
if (!isConnected())
- return false;
+ return NULL;
data_grab_image_t data;
data.header.func = func_grab_image;
@@ -3465,32 +3465,32 @@
off_t n = xread(fd_result, (char *)&resultUnion, sizeof (resultUnion.header));
if (n != sizeof (resultUnion.header))
- return false;
+ return NULL;
if (data.header.func != resultUnion.header.func)
- return false;
+ return NULL;
result_grab_image_t *result = &resultUnion.grab_image;
n = xread(fd_result, (char *)result + sizeof (result->header), sizeof (*result) - sizeof (result->header));
if (n != sizeof (*result) - sizeof (result->header))
- return false;
+ return NULL;
const size_t frameSize = result->header.len - sizeof (*result);
// ::fprintf(stderr, "frameSize: %d\n", frameSize);
if (frameSize <= 0)
- return false;
+ return NULL;
uint8_t *img = (uint8_t *)::malloc(frameSize);
if (!img)
- return false;
+ return NULL;
if (frameSize != (size_t)xread(fd_result, img, frameSize))
{
::free(img);
- return false;
+ return NULL;
}
if (XINE_IMGFMT_YUY2 == result->format)
@@ -3499,7 +3499,7 @@
if (!img2)
{
::free(img);
- return false;
+ return NULL;
}
::memset(img2, 0x80, frameSize);
@@ -3531,11 +3531,10 @@
int videoH = -1;
execFuncVideoSize(videoX, videoY, videoW, videoH);
- bool success = false;
-
- int outfd = ::open(FileName, O_CREAT /* | O_EXCL */ | O_TRUNC | O_RDWR, 0644);
- if (-1 != outfd)
+ FILE *fd = ::tmpfile();
+ if (fd)
{
+ int outfd = fileno(fd);
int sizeX = SizeX;
int sizeY = SizeY;
@@ -3595,22 +3594,41 @@
, result->width, result->height
, 25, 1
, ratioX, ratioY);
-
- success = (frameSize == ::fwrite(img, 1, frameSize, f));
-
- ::pclose(f);
+
+ if (frameSize == ::fwrite(img, 1, frameSize, f))
+ {
+ ::pclose(f); // close the pipe here, grab the image in one go
+ ::free(img);
+ img = NULL;
+
+ Size = (int) lseek (outfd, 0, SEEK_END);
+ lseek (outfd, 0, SEEK_SET);
+
+ if (Size != -1)
+ {
+ img = (uint8_t *)::malloc(Size);
+ if (img && Size != ::read(outfd, img, Size))
+ {
+ ::free(img);
+ img = NULL;
+ }
+ }
+ }
+ else
+ ::pclose(f);
}
::free(cmd);
- ::close(outfd);
+
+ ::fclose(fd);
+
+ return (uchar *)img;
}
-
- ::free(img);
- return success;
+ ::free(img);
}
- return false;
+ return NULL;
}
bool cXineLib::execFuncGetPTS(int64_t &pts)
diff -urNad vdr-plugin-xine-0.7.6~/xineLib.h vdr-plugin-xine-0.7.6/xineLib.h
--- vdr-plugin-xine-0.7.6~/xineLib.h 2006-01-12 00:43:12.000000000 +0000
+++ vdr-plugin-xine-0.7.6/xineLib.h 2006-01-12 00:43:12.715161206 +0000
@@ -254,7 +254,7 @@
bool execFuncMetronom(int64_t pts, uint32_t flags = 0);
bool execFuncNop();
bool execFuncSetPrebuffer(int frames);
- bool execFuncGrabImage(const char *FileName, bool Jpeg, int Quality, int SizeX, int SizeY);
+ uchar *execFuncGrabImage(int &Size, bool Jpeg, int Quality, int SizeX, int SizeY);
bool execFuncGetPTS(int64_t &pts);
bool execFuncVideoSize(int &videoLeft, int &videoTop, int &videoWidth, int &videoHeight);
More information about the vdr
mailing list