libcvd-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libcvd-members] libcvd cvd/videosource.h cvd_src/videosource.cp...


From: Edward Rosten
Subject: [libcvd-members] libcvd cvd/videosource.h cvd_src/videosource.cp...
Date: Thu, 28 Aug 2008 04:16:44 +0000

CVSROOT:        /cvsroot/libcvd
Module name:    libcvd
Changes by:     Edward Rosten <edrosten>        08/08/28 04:16:43

Modified files:
        cvd            : videosource.h 
        cvd_src        : videosource.cpp 
        cvd_src/Linux  : v4l1buffer.cc 

Log message:
        Added v4l1buffer to videosource.
        
        Put evil hack in to v4l1 buffer: if VIDEO_PALETTE_GREY fails, then 
        attempt VIDEO_PALETTE_YUV420P, since the end result will be close 
enough that
        it will be usable. 
        
        Is there a better way than this? 

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/videosource.h?cvsroot=libcvd&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd_src/videosource.cpp?cvsroot=libcvd&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd_src/Linux/v4l1buffer.cc?cvsroot=libcvd&r1=1.10&r2=1.11

Patches:
Index: cvd/videosource.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/videosource.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- cvd/videosource.h   20 May 2008 04:14:30 -0000      1.10
+++ cvd/videosource.h   28 Aug 2008 04:16:43 -0000      1.11
@@ -22,6 +22,10 @@
 #include <cvd/Linux/v4lbuffer.h>
 #endif
 
+#if CVD_HAVE_V4L1BUFFER
+#include <cvd/Linux/v4l1buffer.h>
+#endif
+
 #if CVD_HAVE_DVBUFFER
 #include <cvd/Linux/dvbuffer.h>
 #endif
@@ -70,6 +74,22 @@
 
     void get_files_options(const VideoSource& vs, int& fps, int& ra_frames, 
VideoBufferFlags::OnEndOfBuffer& eob);
     
+#if CVD_HAVE_V4L1BUFFER
+    template <class T> VideoBuffer<T>* makeV4L1Buffer(const std::string& dev, 
const ImageRef& size)
+    {
+       throw VideoSourceException("V4L1Buffer cannot handle types other than 
byte, bayer, yuv422, Rgb<byte>");
+    }
+
+    template <> VideoBuffer<byte>* makeV4L1Buffer(const std::string& dev, 
const ImageRef& size);
+    template <> VideoBuffer<bayer>* makeV4L1Buffer(const std::string& dev, 
const ImageRef& size);
+    template <> VideoBuffer<yuv422>* makeV4L1Buffer(const std::string& dev, 
const ImageRef& size);
+    template <> VideoBuffer<Rgb<byte> >* makeV4L1Buffer(const std::string& 
dev, const ImageRef& size);
+
+    void get_v4l1_options(const VideoSource& vs, ImageRef& size);
+
+#endif
+
+    
 #if CVD_INTERNAL_HAVE_V4LBUFFER
     template <class T> VideoBuffer<T>* makeV4LBuffer(const std::string& dev, 
const ImageRef& size, int input, bool interlaced)
     {
@@ -140,6 +160,14 @@
        }
 #endif
 
+
+#if CVD_HAVE_V4L1BUFFER
+       else if (vs.protocol == "v4l1") {
+           ImageRef size;
+           get_v4l1_options(vs, size);
+           return makeV4L1Buffer<T>(vs.identifier, size);
+       } 
+#endif
 #if CVD_INTERNAL_HAVE_V4LBUFFER
        else if (vs.protocol == "v4l2") {
            ImageRef size;
@@ -185,6 +213,9 @@
 #if CVD_INTERNAL_HAVE_V4LBUFFER
                                       "v4l2, "
 #endif
+#if CVD_HAVE_V4L1BUFFER
+                                      "v4l1, "
+#endif
 #if CVD_HAVE_DVBUFFER
                                       "dc1394, "
 #endif

Index: cvd_src/videosource.cpp
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd_src/videosource.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- cvd_src/videosource.cpp     20 May 2008 04:14:30 -0000      1.6
+++ cvd_src/videosource.cpp     28 Aug 2008 04:16:43 -0000      1.7
@@ -226,6 +226,57 @@
     }
 
 
+
+#if CVD_HAVE_V4L1BUFFER
+    template <> CVD::VideoBuffer<CVD::byte>* makeV4L1Buffer(const std::string& 
dev, const CVD::ImageRef& size)
+    {
+       return new CVD::V4L1Buffer<CVD::byte>(dev, size);
+    }
+
+    template <> CVD::VideoBuffer<CVD::yuv422>* makeV4L1Buffer(const 
std::string& dev, const CVD::ImageRef& size)
+    {
+       return new CVD::V4L1Buffer<CVD::yuv422>(dev, size);
+    }
+    template <> CVD::VideoBuffer<CVD::Rgb<CVD::byte> >* makeV4L1Buffer(const 
std::string& dev, const CVD::ImageRef& size)
+    {
+       return new CVD::V4L1Buffer<CVD::Rgb<CVD::byte> >(dev, size);
+    }
+
+    template <> CVD::VideoBuffer<CVD::bayer>* makeV4L1Buffer(const 
std::string& dev, const CVD::ImageRef& size)
+    {
+       return new CVD::V4LBuffer<CVD::bayer>(dev, size);
+    }
+
+    void get_v4l1_options(const VideoSource& vs, ImageRef& size)
+    {
+       size = ImageRef(0,0);
+
+       for (VideoSource::option_list::const_iterator it=vs.options.begin(); it 
!= vs.options.end(); ++it) {
+           if (it->first == "size") {          
+               std::string s = it->second;
+               tolower(s);
+               if (s == "vga")
+                   size = ImageRef(640,480);
+               else if (s == "qvga")
+                   size = ImageRef(320,240);
+               else if (s == "pal") 
+                   size = ImageRef(720,576);
+               else if (s == "ntsc")
+                   size = ImageRef(720,480);
+               else {
+                   std::istringstream size_in(s);
+                   char x;
+                   if (!(size_in >> size.x >> x >> size.y))
+                       throw ParseException("invalid image size specification: 
'"+it->second+"'\n\t valid specs: vga, qvga, pal, ntsc, <width>x<height>");
+               }
+           } else
+               throw VideoSourceException("invalid option for 'v4l2' protocol: 
"+it->first+"\n\t valid options: size, input, interlaced, fields");
+       }
+    }
+
+#endif
+
+
 #if CVD_INTERNAL_HAVE_V4LBUFFER
     template <> CVD::VideoBuffer<CVD::byte>* makeV4LBuffer(const std::string& 
dev, const CVD::ImageRef& size, int input, bool interlaced)
     {

Index: cvd_src/Linux/v4l1buffer.cc
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd_src/Linux/v4l1buffer.cc,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- cvd_src/Linux/v4l1buffer.cc 12 May 2008 17:52:02 -0000      1.10
+++ cvd_src/Linux/v4l1buffer.cc 28 Aug 2008 04:16:43 -0000      1.11
@@ -167,6 +167,8 @@
     struct video_picture pic;
     if(ioctl(myDevice, VIDIOCGPICT, &pic) !=0)
         throw Exceptions::V4L1Buffer::DeviceSetup(deviceName, "get 
video_picture");
+
+       again:
     pic.brightness=(unsigned short)(myBrightness*65535+0.5);
     pic.whiteness=(unsigned short)(myWhiteness*65535+0.5);
     pic.colour=(unsigned short)(mySaturation*65535+0.5);
@@ -175,6 +177,12 @@
     pic.depth=myBpp;
     pic.palette=myPalette;
     if(ioctl(myDevice, VIDIOCSPICT, &pic) !=0)
+               if(myPalette == VIDEO_PALETTE_GREY)
+               {
+                       myPalette = VIDEO_PALETTE_YUV420P;
+                       goto again;
+               }
+               else
         throw Exceptions::V4L1Buffer::DeviceSetup(deviceName, "set 
video_picture");
 
     retrieveSettings();




reply via email to

[Prev in Thread] Current Thread [Next in Thread]