public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] gentoo-x86 commit in media-video/vdr/files: vdr-1.6.0-use-v4l2.patch
@ 2011-04-11 13:33 Matthias Schwarzott (zzam)
  0 siblings, 0 replies; only message in thread
From: Matthias Schwarzott (zzam) @ 2011-04-11 13:33 UTC (permalink / raw
  To: gentoo-commits

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=utf8, Size: 8841 bytes --]

zzam        11/04/11 13:33:01

  Added:                vdr-1.6.0-use-v4l2.patch
  Log:
  Backported v4l2 support from vdr-1.7.3. Bug #359409.
  
  (Portage version: 2.1.9.45/cvs/Linux x86_64)

Revision  Changes    Path
1.1                  media-video/vdr/files/vdr-1.6.0-use-v4l2.patch

file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/media-video/vdr/files/vdr-1.6.0-use-v4l2.patch?rev=1.1&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/media-video/vdr/files/vdr-1.6.0-use-v4l2.patch?rev=1.1&content-type=text/plain

Index: vdr-1.6.0-use-v4l2.patch
===================================================================

    from Version 1.7.3
    - Changed cDvbDevice::GrabImage() to use V4L2 (thanks to Marco Schlüßler).

diff --git a/dvbdevice.c b/dvbdevice.c
index e0b05a1..6aa0056 100644
--- a/dvbdevice.c
+++ b/dvbdevice.c
@@ -10,7 +10,7 @@
 #include "dvbdevice.h"
 #include <errno.h>
 #include <limits.h>
-#include <linux/videodev.h>
+#include <linux/videodev2.h>
 #include <linux/dvb/audio.h>
 #include <linux/dvb/dmx.h>
 #include <linux/dvb/frontend.h>
@@ -604,69 +604,103 @@ uchar *cDvbDevice::GrabImage(int &Size, bool Jpeg, int Quality, int SizeX, int S
   int videoDev = open(buffer, O_RDWR);
   if (videoDev >= 0) {
      uchar *result = NULL;
-     struct video_mbuf mbuf;
-     if (ioctl(videoDev, VIDIOCGMBUF, &mbuf) == 0) {
-        int msize = mbuf.size;
-        unsigned char *mem = (unsigned char *)mmap(0, msize, PROT_READ | PROT_WRITE, MAP_SHARED, videoDev, 0);
-        if (mem && mem != (unsigned char *)-1) {
-           // set up the size and RGB
-           struct video_capability vc;
-           if (ioctl(videoDev, VIDIOCGCAP, &vc) == 0) {
-              struct video_mmap vm;
-              vm.frame = 0;
-              if ((SizeX > 0) && (SizeX <= vc.maxwidth) &&
-                  (SizeY > 0) && (SizeY <= vc.maxheight)) {
-                 vm.width = SizeX;
-                 vm.height = SizeY;
-                 }
-              else {
-                 vm.width = vc.maxwidth;
-                 vm.height = vc.maxheight;
-                 }
-              vm.format = VIDEO_PALETTE_RGB24;
-              if (ioctl(videoDev, VIDIOCMCAPTURE, &vm) == 0 && ioctl(videoDev, VIDIOCSYNC, &vm.frame) == 0) {
-                 // make RGB out of BGR:
-                 int memsize = vm.width * vm.height;
-                 unsigned char *mem1 = mem;
-                 for (int i = 0; i < memsize; i++) {
-                     unsigned char tmp = mem1[2];
-                     mem1[2] = mem1[0];
-                     mem1[0] = tmp;
-                     mem1 += 3;
-                     }
-
-                 if (Quality < 0)
-                    Quality = 100;
-
-                 dsyslog("grabbing to %s %d %d %d", Jpeg ? "JPEG" : "PNM", Quality, vm.width, vm.height);
-                 if (Jpeg) {
-                    // convert to JPEG:
-                    result = RgbToJpeg(mem, vm.width, vm.height, Size, Quality);
-                    if (!result)
-                       esyslog("ERROR: failed to convert image to JPEG");
-                    }
-                 else {
-                    // convert to PNM:
-                    char buf[32];
-                    snprintf(buf, sizeof(buf), "P6\n%d\n%d\n255\n", vm.width, vm.height);
-                    int l = strlen(buf);
-                    int bytes = memsize * 3;
-                    Size = l + bytes;
-                    result = MALLOC(uchar, Size);
-                    if (result) {
-                       memcpy(result, buf, l);
-                       memcpy(result + l, mem, bytes);
+     // set up the size and RGB
+     v4l2_format fmt;
+     memset(&fmt, 0, sizeof(fmt));
+     fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+     fmt.fmt.pix.width = SizeX;
+     fmt.fmt.pix.height = SizeY;
+     fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_BGR24;
+     fmt.fmt.pix.field = V4L2_FIELD_ANY;
+     if (ioctl(videoDev, VIDIOC_S_FMT, &fmt) == 0) {
+        v4l2_requestbuffers reqBuf;
+        memset(&reqBuf, 0, sizeof(reqBuf));
+        reqBuf.count = 2;
+        reqBuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+        reqBuf.memory = V4L2_MEMORY_MMAP;
+        if (ioctl(videoDev, VIDIOC_REQBUFS, &reqBuf) >= 0) {
+           v4l2_buffer mbuf;
+           memset(&mbuf, 0, sizeof(mbuf));
+           mbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+           mbuf.memory = V4L2_MEMORY_MMAP;
+           if (ioctl(videoDev, VIDIOC_QUERYBUF, &mbuf) == 0) {
+              int msize = mbuf.length;
+              unsigned char *mem = (unsigned char *)mmap(0, msize, PROT_READ | PROT_WRITE, MAP_SHARED, videoDev, 0);
+              if (mem && mem != (unsigned char *)-1) {
+                 v4l2_buffer buf;
+                 memset(&buf, 0, sizeof(buf));
+                 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+                 buf.memory = V4L2_MEMORY_MMAP;
+                 buf.index = 0;
+                 if (ioctl(videoDev, VIDIOC_QBUF, &buf) == 0) {
+                    v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+                    if (ioctl (videoDev, VIDIOC_STREAMON, &type) == 0) {
+                       memset(&buf, 0, sizeof(buf));
+                       buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+                       buf.memory = V4L2_MEMORY_MMAP;
+                       buf.index = 0;
+                       if (ioctl(videoDev, VIDIOC_DQBUF, &buf) == 0) {
+                          if (ioctl(videoDev, VIDIOC_STREAMOFF, &type) == 0) {
+                             // make RGB out of BGR:
+                             int memsize = fmt.fmt.pix.width * fmt.fmt.pix.height;
+                             unsigned char *mem1 = mem;
+                             for (int i = 0; i < memsize; i++) {
+                                 unsigned char tmp = mem1[2];
+                                 mem1[2] = mem1[0];
+                                 mem1[0] = tmp;
+                                 mem1 += 3;
+                                 }
+
+                             if (Quality < 0)
+                                Quality = 100;
+
+                             dsyslog("grabbing to %s %d %d %d", Jpeg ? "JPEG" : "PNM", Quality, fmt.fmt.pix.width, fmt.fmt.pix.height);
+                             if (Jpeg) {
+                                // convert to JPEG:
+                                result = RgbToJpeg(mem, fmt.fmt.pix.width, fmt.fmt.pix.height, Size, Quality);
+                                if (!result)
+                                   esyslog("ERROR: failed to convert image to JPEG");
+                                }
+                             else {
+                                // convert to PNM:
+                                char buf[32];
+                                snprintf(buf, sizeof(buf), "P6\n%d\n%d\n255\n", fmt.fmt.pix.width, fmt.fmt.pix.height);
+                                int l = strlen(buf);
+                                int bytes = memsize * 3;
+                                Size = l + bytes;
+                                result = MALLOC(uchar, Size);
+                                if (result) {
+                                   memcpy(result, buf, l);
+                                   memcpy(result + l, mem, bytes);
+                                   }
+                                else
+                                   esyslog("ERROR: failed to convert image to PNM");
+                                }
+                             }
+                          else
+                             esyslog("ERROR: video device VIDIOC_STREAMOFF failed");
+                          }
+                       else
+                          esyslog("ERROR: video device VIDIOC_DQBUF failed");
                        }
                     else
-                       esyslog("ERROR: failed to convert image to PNM");
+                       esyslog("ERROR: video device VIDIOC_STREAMON failed");
                     }
+                 else
+                    esyslog("ERROR: video device VIDIOC_QBUF failed");
+                 munmap(mem, msize);
                  }
+              else
+                 esyslog("ERROR: failed to memmap video device");
               }
-           munmap(mem, msize);
+           else
+              esyslog("ERROR: video device VIDIOC_QUERYBUF failed");
            }
         else
-           esyslog("ERROR: failed to memmap video device");
+           esyslog("ERROR: video device VIDIOC_REQBUFS failed");
         }
+     else
+        esyslog("ERROR: video device VIDIOC_S_FMT failed");
      close(videoDev);
      return result;
      }






^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2011-04-11 13:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-11 13:33 [gentoo-commits] gentoo-x86 commit in media-video/vdr/files: vdr-1.6.0-use-v4l2.patch Matthias Schwarzott (zzam)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox