libcvd-members
[Top][All Lists]
Advanced

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

[libcvd-members] libcvd cvd/colourspacebuffer.h cvd/videobuffer....


From: Edward Rosten
Subject: [libcvd-members] libcvd cvd/colourspacebuffer.h cvd/videobuffer....
Date: Mon, 02 Nov 2009 16:50:26 +0000

CVSROOT:        /cvsroot/libcvd
Module name:    libcvd
Changes by:     Edward Rosten <edrosten>        09/11/02 16:50:26

Modified files:
        cvd            : colourspacebuffer.h videobuffer.h 
                         videobufferwithdata.h videosource.h 
        cvd/Linux      : v4lbuffer.h 
        cvd_src/Linux  : v4lbuffer.cc 
        progs          : video_play_source.cc 

Log message:
        Introduced untyped base class for all video buffers. This is intended to
        allow access to grabber controls without knowing the type of the 
original
        video buffer. This is intended to be useful with the new 
        open_video_source

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/colourspacebuffer.h?cvsroot=libcvd&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/videobuffer.h?cvsroot=libcvd&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/videobufferwithdata.h?cvsroot=libcvd&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/videosource.h?cvsroot=libcvd&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd/Linux/v4lbuffer.h?cvsroot=libcvd&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/libcvd/cvd_src/Linux/v4lbuffer.cc?cvsroot=libcvd&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/libcvd/progs/video_play_source.cc?cvsroot=libcvd&r1=1.4&r2=1.5

Patches:
Index: cvd/colourspacebuffer.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/colourspacebuffer.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- cvd/colourspacebuffer.h     2 Dec 2008 17:30:39 -0000       1.6
+++ cvd/colourspacebuffer.h     2 Nov 2009 16:50:25 -0000       1.7
@@ -59,6 +59,11 @@
                {
                }
  
+               virtual RawVideoBuffer* source_buffer()
+               {
+                       return &m_vidbuf;
+               }
+ 
                /// The size of the VideoFrames returns by this buffer.
                ImageRef size()
                {

Index: cvd/videobuffer.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/videobuffer.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- cvd/videobuffer.h   23 Oct 2009 14:49:43 -0000      1.16
+++ cvd/videobuffer.h   2 Nov 2009 16:50:25 -0000       1.17
@@ -46,12 +46,68 @@
        };
 };
 
-/// Base class for objects which provide a video stream. A video 
+///Base class which provides untyped access to video grabber objects.
+///This provides all of the functionality for which the type does not
+///need to be known (eg size, etc).
+///
+///This allows one to follow chains of video buffers which change types (for 
instance
+///<code>ColourspaceBuffer<Rgb<byte>, byte>) and get to the underlying video 
grabber.
+///This provides access to the grabber specific controls.
+///
+///See progs/video_play_source.cc for a very basic example.
+class RawVideoBuffer
+{
+       public:
+
+               /// Which video grabber provides the source images for this
+               /// video grabber.
+               virtual RawVideoBuffer* source_buffer()
+               {
+                       return this;
+               }
+               
+               /// Follow the chain of video grabbers back as far as at will 
go. This will
+               /// usually yield the video grabber dealing with the hardware.
+               RawVideoBuffer* root_buffer()
+               {
+                       RawVideoBuffer* b = this;
+                       while(b->source_buffer() != b)
+                               b = b->source_buffer();
+                       return b;
+               }
+
+
+               virtual ~RawVideoBuffer(){}
+
+               /// The size of the VideoFrames returned by this buffer
+               virtual ImageRef size()=0;
+
+               /// Is there a frame waiting in the buffer? This function does 
not block. 
+               /// See is_live and is_flushable.
+               virtual bool frame_pending()=0;
+
+               /// What is the (expected) frame rate of this video buffer, in 
frames per second?               
+               virtual double frame_rate()=0;
+               /// Go to a particular point in the video buffer (only 
implemented in buffers of recorded video)
+               /// \param t The frame time in seconds
+               virtual void seek_to(double)
+               {}
+
+
+               /// Flush all old frames out of the video buffer,
+               /// on a flushable buffer, causing the next get_frame()
+               /// to sleep until a frame arrives. On a non-flushable
+               /// buffer, this does nothing.
+               virtual void flush()=0;
+               
+};
+
+/// Base class for objects which provide a typed video stream. A video 
 /// stream is a sequence of video frames (derived from VideoFrame).
 /// @param T The pixel type of the video frames
 /// @ingroup gVideoBuffer
 template <class T> 
-class VideoBuffer 
+class VideoBuffer: public virtual RawVideoBuffer
 {
        public:
                ///Construct the buffer with the known semantics
@@ -62,16 +118,19 @@
                virtual ~VideoBuffer()
                {}
 
-               /// The size of the VideoFrames returned by this buffer
-               virtual ImageRef size()=0;
                /// Returns the next frame from the buffer. This function 
blocks until a frame is ready.
                virtual VideoFrame<T>* get_frame()=0;           
+
                /// Tell the buffer that you are finished with this frame. 
Typically the VideoBuffer then destroys the frame.
                /// \param f The frame that you are finished with.
                virtual void put_frame(VideoFrame<T>* f)=0;
-               /// Is there a frame waiting in the buffer? This function does 
not block. 
-               /// See is_live and is_flushable.
-               virtual bool frame_pending()=0;
+               
+               virtual void flush()
+               {
+                       if(type() == VideoBufferType::Flushable)
+                               while(frame_pending())
+                                       put_frame(get_frame());
+               }
 
                /// Returns the type of the video stream
                ///
@@ -92,30 +151,13 @@
                ///
                /// Otherwise, streams have a type VideoBuffer::Type::NotLive, 
and
                /// frame_pending is always 1
+               ///
+               ///This should be in the base class
                VideoBufferType::Type type()
                {
                        return m_type;
                }
                
-               /// Flush all old frames out of the video buffer,
-               /// on a flushable buffer, causing the next get_frame()
-               /// to sleep until a frame arrives. On a non-flushable
-               /// buffer, this does nothing.
-               virtual void flush()
-               {
-                       if(type() == VideoBufferType::Flushable)
-                               while(frame_pending())
-                                       put_frame(get_frame());
-               }
-
-               /// What is the (expected) frame rate of this video buffer, in 
frames per second?               
-               virtual double frame_rate()=0;
-               /// Go to a particular point in the video buffer (only 
implemented in buffers of recorded video)
-               /// \param t The frame time in seconds
-               virtual void seek_to(double)
-               {}
-               
-
        private:
                VideoBufferType::Type m_type;
 };

Index: cvd/videobufferwithdata.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/videobufferwithdata.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- cvd/videobufferwithdata.h   26 Oct 2009 15:44:58 -0000      1.2
+++ cvd/videobufferwithdata.h   2 Nov 2009 16:50:25 -0000       1.3
@@ -45,6 +45,11 @@
                        return buf->size();
                }
 
+               virtual RawVideoBuffer* source_buffer()
+               {
+                       return buf.get();
+               }
+
                VideoFrame<T>* get_frame()
                {
                        return buf->get_frame();

Index: cvd/videosource.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/videosource.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- cvd/videosource.h   26 Oct 2009 18:10:03 -0000      1.23
+++ cvd/videosource.h   2 Nov 2009 16:50:25 -0000       1.24
@@ -279,7 +279,6 @@
 
                        return makeColourspaceBuffer<T>(from, vs.identifier);
                }
-#if CVD_HAVE_GLOB
                else if (vs.protocol == "files") {
                        int fps, ra_frames=0;
                        VideoBufferFlags::OnEndOfBuffer eob;
@@ -289,15 +288,11 @@
                                vb = new ReadAheadVideoBuffer<T>(*vb, 
ra_frames);
                        return vb;
                }
-#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;
                        int input;
@@ -305,8 +300,6 @@
                        get_v4l2_options(vs, size, input, interlaced, verbose);
                        return makeV4LBuffer<T>(vs.identifier, size, input, 
interlaced, verbose);       
                } 
-#endif
-#if CVD_HAVE_DVBUFFER3
                else if (vs.protocol == "dc1394") {
                        int cam_no = atoi(vs.identifier.c_str());
                        ImageRef size, offset;
@@ -314,8 +307,6 @@
                        get_dc1394_options(vs, size, fps, offset);
                        return makeDVBuffer2<T>(cam_no, size, fps, offset);
                } 
-#endif
-#if CVD_HAVE_FFMPEG
                else if (vs.protocol == "file") {
                        int ra_frames = 0;
                        VideoBufferFlags::OnEndOfBuffer eob;
@@ -325,8 +316,6 @@
                                vb = new ReadAheadVideoBuffer<T>(*vb, 
ra_frames);
                        return vb;
                } 
-#endif
-#if CVD_HAVE_QTBUFFER
        else if (vs.protocol == "qt") {
                ImageRef size;
                bool showsettings;
@@ -334,28 +323,15 @@
                get_qt_options(vs, size, showsettings);
                return makeQTBuffer<T>(size, input, showsettings);
        }
-#endif
                else
                        throw VideoSourceException("undefined video source 
protocol: '" + vs.protocol + "'\n\t valid protocols: "
                                                                           
"colourspace, jpegstream, "
-#if CVD_HAVE_FFMPEG
                                                                           
"file, "
-#endif
-#if CVD_INTERNAL_HAVE_V4LBUFFER
                                                                           
"v4l2, "
-#endif
-#if CVD_HAVE_V4L1BUFFER
                                                                           
"v4l1, "
-#endif
-#if CVD_HAVE_DVBUFFER3
                                                                           
"dc1394, "
-#endif
-#if CVD_HAVE_QTBUFFER
                                                                           "qt, 
"
-#endif
-#ifdef CVD_HAVE_GLOB
                                                                           
"files"
-#endif 
                                                                           );
        }
 
@@ -377,6 +353,12 @@
 runtime what kind of video input your program is using. Basic use is to call
 open_video_source<T>(url) to get a VideoBuffer<T>*.
 
+
+In many cases, the VideoBuffer returned by open_video_source() is a wrapper
+around the video buffer dealing with the hardware and so does not provide 
+access to the controls. The underlying buffer can be accessed with 
+VideoBuffer::root_buffer().
+
 The url syntax is the following:
 @verbatim
 url             := protocol ':' [ '[' options ']' ] // identifier

Index: cvd/Linux/v4lbuffer.h
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd/Linux/v4lbuffer.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- cvd/Linux/v4lbuffer.h       11 Mar 2009 21:35:12 -0000      1.15
+++ cvd/Linux/v4lbuffer.h       2 Nov 2009 16:50:25 -0000       1.16
@@ -127,7 +127,7 @@
     };
 #endif
     
-    class V4L2Client
+       class RawV4LBuffer: public virtual RawVideoBuffer
     {
     public:
        struct Buffer {
@@ -135,21 +135,30 @@
            unsigned char* data;
            double when;
        };
-       V4L2Client(int fd, unsigned int fmt, ImageRef size, int input, bool 
fields, int frame_per_second, bool verbose);
+
+                       RawV4LBuffer(const std::string& dev, unsigned int fmt, 
ImageRef size, int input, bool fields, int frame_per_second, bool verbose);
        ImageRef getSize();
        Buffer getFrame();
        void releaseFrame(int id);
        double getRate();
        bool pendingFrame();
-       virtual ~V4L2Client();
+                       virtual ~RawV4LBuffer();
+
        int num_buffers()
        {
                return num_bufs;
        }
+
+                       const std::string & device_name() const 
+                       { 
+                               return dev; 
+                       }
+
     private:
        int num_bufs;
        struct State; 
        State* state;
+                       std::string dev;
     };
     
     class V4L1Client;
@@ -160,83 +169,65 @@
 /// A live video buffer which uses the Video for Linux 2 (V4L2) API.
 /// A replacement for the (deprecated?) V4L2Buffer
 /// @ingroup gVideoBuffer
-template <class T> class V4LBuffer : public VideoBuffer<T>
+template <class T> class V4LBuffer : public VideoBuffer<T>, public 
V4L::RawV4LBuffer
 {
-public:
+       public:
  V4LBuffer(const std::string & dev, ImageRef size, int input=-1, bool 
fields=false, int frames_per_second=0, bool verbose=0) 
- :VideoBuffer<T>(VideoBufferType::Flushable), 
-  devname(dev)
+               :VideoBuffer<T>(VideoBufferType::Flushable), RawV4LBuffer(dev, 
V4L::format<T>::v4l2_fmt, size, input, fields, frames_per_second, verbose)
     {
-       int device = open(devname.c_str(), O_RDWR | O_NONBLOCK);
-       if (device == -1)
-           throw Exceptions::V4LBuffer::DeviceOpen(dev);
-       try {
-         v4l2 = new V4L::V4L2Client(device, V4L::format<T>::v4l2_fmt, size, 
input, fields,frames_per_second, verbose);
-       }
-       catch (std::string& s) {
-           v4l2 = 0;
-           throw Exceptions::V4LBuffer::DeviceSetup(devname, "V4L2: "+s);
        }
-       v4l1 = 0;
+
+               virtual ImageRef size() 
+               { 
+                       return getSize();
     }
-       virtual ImageRef size() { return v4l2 ? v4l2->getSize() : 
ImageRef(-1,-1); }
+
+
     virtual VideoFrame<T> * get_frame() {
-       if (v4l2) {
-           try {
-               V4L::V4L2Client::Buffer buffer = v4l2->getFrame();
-               return new V4LFrame(buffer.id, buffer.when, buffer.data, 
v4l2->getSize());
-           } catch (std::string& s) {
-               throw Exceptions::V4LBuffer::GetFrame(devname, "V4L2: "+s);
-           }
-       } else {
-           throw Exceptions::V4LBuffer::GetFrame(devname, "V4L1 not yet 
supported by V4LBuffer");
-       }
+                       V4L::RawV4LBuffer::Buffer buffer = getFrame();
+                       return new V4LFrame(buffer.id, buffer.when, 
buffer.data, getSize());
     }
+
     virtual void put_frame(VideoFrame<T>* f) {
        V4LFrame* vf = dynamic_cast<V4LFrame*>(f);
        if (vf == 0)
-           throw Exceptions::V4LBuffer::PutFrame(devname, "Invalid 
VideoFrame");
+                               throw 
Exceptions::V4LBuffer::PutFrame(device_name(), "Invalid VideoFrame");
        int id = vf->id;
        delete vf;
-       if (v4l2) {
-           try {
-               v4l2->releaseFrame(id);
-           } catch (std::string& s) {
-               throw Exceptions::V4LBuffer::PutFrame(devname, "V4L2: "+s);
-           }
-       } else {
-           throw Exceptions::V4LBuffer::PutFrame(devname, "V4L1 not yet 
supported by V4LBuffer");
+
+                       releaseFrame(id);
        }
+
+               virtual bool frame_pending() 
+               { 
+                       return pendingFrame(); 
     }
-    virtual bool frame_pending() { return v4l2->pendingFrame(); }
-    virtual double frame_rate() { return v4l2 ? v4l2->getRate() : 0.0; }
-    virtual ~V4LBuffer() {
-       if (v4l2)
-           delete v4l2;
+
+               virtual double frame_rate() 
+               { 
+                       return getRate();
     }
 
        int num_buffers()
        {
-       if (v4l2) {
-               return v4l2->num_buffers();
-       } else {
-           throw Exceptions::V4LBuffer::PutFrame(devname, "V4L1 not yet 
supported by V4LBuffer");
-       }
+                       return num_buffers();
        }
 
-    const std::string & device_name() const { return devname; }
     
  private:
+
     struct V4LFrame : public VideoFrame<T> {
-       V4LFrame(int i, double t, void* data, ImageRef size) : 
VideoFrame<T>(t,reinterpret_cast<T*>(data),size), id(i) {}
+                       V4LFrame(int i, double t, void* data, ImageRef size) 
+                       :VideoFrame<T>(t,reinterpret_cast<T*>(data),size), 
id(i) 
+                       {}
+
        int id;
        friend class V4LBuffer<T>;
     };
-    std::string devname;
-    V4L::V4L2Client* v4l2;
-    V4L::V4L1Client* v4l1;
+
     V4LBuffer( V4LBuffer& copyof ) {}
     void operator=( V4LBuffer& copyof ) {}
+
 };
 
 };

Index: cvd_src/Linux/v4lbuffer.cc
===================================================================
RCS file: /cvsroot/libcvd/libcvd/cvd_src/Linux/v4lbuffer.cc,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- cvd_src/Linux/v4lbuffer.cc  22 Jul 2009 19:25:31 -0000      1.14
+++ cvd_src/Linux/v4lbuffer.cc  2 Nov 2009 16:50:26 -0000       1.15
@@ -81,7 +81,7 @@
                template<class C> VPrint_& operator<<(const C& c)
                {
                        if(p)
-                               cerr << "V4L2Client: " << c;
+                                                               cerr << 
"RawV4LBuffer: " << c;
                        
                        return *this;
                }
@@ -132,7 +132,7 @@
 
 namespace V4L { // V4L
 
-    struct V4L2Client::State {
+       struct RawV4LBuffer::State {
        struct Frame {
            void* data;
            size_t length;
@@ -144,8 +144,14 @@
        v4l2_buffer refbuf;
     };
 
-  V4L2Client::V4L2Client(int fd, unsigned int fmt, ImageRef size, int input, 
bool fields, int frames_per_second, bool verbose)
+       RawV4LBuffer::RawV4LBuffer(const std::string& devname , unsigned int 
fmt, ImageRef size, int input, bool fields, int frames_per_second, bool verbose)
        {
+               dev= devname ;
+
+               int fd = open(devname.c_str(), O_RDWR | O_NONBLOCK);
+               if (fd == -1)
+                       throw Exceptions::V4LBuffer::DeviceOpen(dev);
+
        state = 0;
 
        VPrint log(verbose);
@@ -155,7 +161,7 @@
        struct v4l2_capability caps;
        if (0 != ioctl(fd, VIDIOC_QUERYCAP, &caps))
        {
-           throw string("VIDIOC_QUERYCAP failed");
+                       throw Exceptions::V4LBuffer::DeviceSetup(dev, "V4L2: 
VIDIOC_QUERYCAP failed");
        }
 
        log << "   driver: " << caps.driver << "\n";
@@ -238,7 +244,7 @@
     }
 
        if(errno != EINVAL)
-               throw string("VIDIOC_ENUM_FMT");
+                       throw Exceptions::V4LBuffer::DeviceSetup(dev, "V4L2: 
VIDIOC_ENUM_FMT");
        
        fmt = actual_fmt;
        log << "Selected format: " << unfourcc(fmt) << "\n";
@@ -248,14 +254,14 @@
        {
            v4l2_std_id stdId=V4L2_STD_PAL;
            if(ioctl(fd, VIDIOC_S_STD, &stdId ))
-                               throw string("VIDIOC_S_STD");
+                               throw Exceptions::V4LBuffer::DeviceSetup(dev, 
"V4L2: VIDIOC_S_STD");
        }
        
        if (input != -1) {
            struct v4l2_input v4l2Input;
            v4l2Input.index=input; 
            if (0 != ioctl(fd, VIDIOC_S_INPUT, &v4l2Input))
-                               throw string("VIDIOC_S_INPUT");
+                               throw Exceptions::V4LBuffer::DeviceSetup(dev, 
"V4L2: VIDIOC_S_INPUT");
        }
 
        // Get / Set capture format.
@@ -265,7 +271,7 @@
        log << "Getting format (VIDIOC_G_FMT)\n";
        
        if (0 != ioctl(fd, VIDIOC_G_FMT, &format))
-           throw string("VIDIOC_G_FMT");
+                       throw Exceptions::V4LBuffer::DeviceSetup(dev, "V4L2: 
VIDIOC_G_FMT");
 
        log << "   size: " << format.fmt.pix.width  << "x" <<   
format.fmt.pix.height << "\n";
        log << "   format: " << unfourcc(format.fmt.pix.pixelformat) << "\n";
@@ -288,11 +294,11 @@
        log << "   colourspace: " << format.fmt.pix.colorspace << "\n";
 
        if (0 != ioctl(fd, VIDIOC_S_FMT, &format))
-           throw string("VIDIOC_S_FMT");
+                       throw Exceptions::V4LBuffer::DeviceSetup(dev, "V4L2: 
VIDIOC_S_FMT");
 
        log << "Getting format (VIDIOC_G_FMT)\n";
        if (0 != ioctl(fd, VIDIOC_G_FMT, &format))
-           throw string("VIDIOC_G_FMT");
+                       throw Exceptions::V4LBuffer::DeviceSetup(dev, "V4L2: 
VIDIOC_G_FMT");
 
        log << "   size: " << format.fmt.pix.width  << "x" <<   
format.fmt.pix.height << "\n";
        log << "   format: " << unfourcc(format.fmt.pix.pixelformat) << "\n";
@@ -303,7 +309,7 @@
 
        
        if (fmt != format.fmt.pix.pixelformat)
-           throw string("Requested format not supported");
+                       throw Exceptions::V4LBuffer::DeviceSetup(dev, "V4L2: 
equested format not supported");
 
        struct v4l2_requestbuffers reqbufs;
        reqbufs.count = 10;
@@ -319,14 +325,14 @@
        //The BTTV driver returns num_bufs on success!
        //So the test against 0 fails.
        if (ioctl(fd,VIDIOC_REQBUFS,&reqbufs) == -1)
-           throw string("VIDIOC_REQBUFS");
+                       throw Exceptions::V4LBuffer::DeviceSetup(dev, "V4L2: 
VIDIOC_REQBUFS");
 
        num_bufs = reqbufs.count;
 
        log << "Number of buffers: " << num_bufs << "\n";
        
        if (reqbufs.count < 2)
-           throw string("Insufficient buffers available");
+                       throw Exceptions::V4LBuffer::DeviceSetup(dev, "V4L2: 
Insufficient buffers available");
        vector<State::Frame> frames(reqbufs.count);
        struct v4l2_buffer refbuf;
        for (size_t i=0; i<frames.size(); i++) {
@@ -335,18 +341,18 @@
            buffer.memory = V4L2_MEMORY_MMAP;
            buffer.index = i;
            if (0 != ioctl(fd, VIDIOC_QUERYBUF, &buffer))
-               throw string("VIDIOC_QUERYBUF");
+                               throw Exceptions::V4LBuffer::DeviceSetup(dev, 
"V4L2: VIDIOC_QUERYBUF");
            if (i == 0)
                refbuf = buffer;
            frames[i].data = mmap(0,buffer.length, PROT_READ | PROT_WRITE, 
MAP_SHARED, fd, buffer.m.offset);
            if (frames[i].data == MAP_FAILED) {
                frames[i].data = mmap(0,buffer.length, PROT_READ, MAP_SHARED, 
fd, buffer.m.offset);
                if (frames[i].data == MAP_FAILED)
-                   throw string("mmap failed");
+                                       throw 
Exceptions::V4LBuffer::DeviceSetup(dev, "V4L2: mmap failed");
            }
            frames[i].length = buffer.length;
            if (0 != ioctl(fd, VIDIOC_QBUF, &buffer))
-               throw string("VIDIOC_QBUF");
+                               throw Exceptions::V4LBuffer::DeviceSetup(dev, 
"V4L2: VIDIOC_QBUF");
        }
 
        // Do we want to manually set FPS?
@@ -355,7 +361,7 @@
            v4l2_streamparm streamparams;
            streamparams.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
            if (0 != ioctl(fd, VIDIOC_G_PARM, &streamparams))
-             throw string("VIDIOC_G_PARM");
+                               throw Exceptions::V4LBuffer::DeviceSetup(dev, 
"V4L2: VIDIOC_G_PARM");
            
            // Check if the device has the capability to set a frame-rate.
            if(streamparams.parm.capture.capability & V4L2_CAP_TIMEPERFRAME)
@@ -363,12 +369,12 @@
                streamparams.parm.capture.timeperframe.denominator = 
frames_per_second;
                streamparams.parm.capture.timeperframe.numerator = 1;
                if (0 != ioctl(fd, VIDIOC_S_PARM, &streamparams))
-                 throw string("VIDIOC_S_PARM");
+                                       throw 
Exceptions::V4LBuffer::DeviceSetup(dev, "V4L2: VIDIOC_S_PARM");
              }
          }
 
        if (0 != ioctl(fd, VIDIOC_STREAMON, &reqbufs.type))
-           throw string("STREAMON");
+                       throw Exceptions::V4LBuffer::DeviceSetup(dev, "V4L2: 
VIDIOC_STREAMON");
        state = new State;
        state->fd = fd;
        state->format = format;
@@ -376,25 +382,26 @@
        state->frameRate = 0;
        state->refbuf = refbuf;
     }
-    V4L2Client::~V4L2Client() {
+
+       RawV4LBuffer::~RawV4LBuffer() {
        if (state == 0)
            return;
        if(0 != ioctl(state->fd, VIDIOC_STREAMOFF, &state->refbuf.type))
-         throw string("streamoff failed");
+                       throw Exceptions::V4LBuffer::DeviceSetup(dev, "V4L2: 
VIDIOC_STREAMOFF");
        for (size_t i=0; i<state->frames.size(); i++) {
            if (0 != munmap(state->frames[i].data, state->frames[i].length))
-               throw string("munmap failed");
+                               throw Exceptions::V4LBuffer::DeviceSetup(dev, 
"V4L2: munmap failed");
        }
        close(state->fd);
        delete state;
     }
 
-    ImageRef V4L2Client::getSize()
+       ImageRef RawV4LBuffer::getSize()
     {
        return ImageRef(state->format.fmt.pix.width, 
state->format.fmt.pix.height);
     }
     
-    V4L2Client::Buffer V4L2Client::getFrame()
+       RawV4LBuffer::Buffer RawV4LBuffer::getFrame()
     {
        struct v4l2_buffer buffer = state->refbuf;
        buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -405,7 +412,7 @@
            err = ioctl(state->fd, VIDIOC_DQBUF, &buffer);
        }
        if (err != 0)
-           throw string("VIDIOC_DQBUF");
+                       throw Exceptions::V4LBuffer::DeviceSetup(dev, "V4L2: 
VIDIOC_DQBUF");
 
        Buffer ret;
        ret.id = buffer.index;
@@ -414,7 +421,7 @@
        return ret;
     }
     
-    void V4L2Client::releaseFrame(int id)
+       void RawV4LBuffer::releaseFrame(int id)
     {
        struct v4l2_buffer buffer = state->refbuf;
        buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -422,14 +429,14 @@
        buffer.index = id;
        
        if (0 != ioctl(state->fd, VIDIOC_QBUF, &buffer))
-           throw string("VIDIOC_QBUF");
+                       throw Exceptions::V4LBuffer::DeviceSetup(dev, "V4L2: 
VIDIOC_QBUF");
     }
 
-    double V4L2Client::getRate() {
+       double RawV4LBuffer::getRate() {
        return state->frameRate;
     }
 
-    bool V4L2Client::pendingFrame() {
+       bool RawV4LBuffer::pendingFrame() {
        fd_set fdsetRead;
        fd_set fdsetOther;
        struct timeval tv;
@@ -446,4 +453,5 @@
 
 };
 
+
 };

Index: progs/video_play_source.cc
===================================================================
RCS file: /cvsroot/libcvd/libcvd/progs/video_play_source.cc,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- progs/video_play_source.cc  26 Oct 2009 18:09:51 -0000      1.4
+++ progs/video_play_source.cc  2 Nov 2009 16:50:26 -0000       1.5
@@ -29,12 +29,18 @@
 /////////////////////////////////////////////////////////////////////////////
 
 #include <cvd/image.h>
+#include <typeinfo>
+#include <cstdlib>
 #include <cvd/rgb.h>
 #include <cvd/byte.h>
-#include <cvd/videodisplay.h>
+#include <cvd/glwindow.h>
 #include <cvd/gl_helpers.h>
 #include <cvd/videosource.h>
 
+#ifdef CVD_HAVE_V4LBUFFER
+       #include <cvd/Linux/v4lbuffer.h>
+#endif
+
 using namespace std;
 using namespace CVD;
 
@@ -42,10 +48,25 @@
 {
        VideoBuffer<C> *buffer = open_video_source<C>(s);
        
-       VideoDisplay display(buffer->size());
+       GLWindow display(buffer->size());
        glDrawBuffer(GL_BACK);
        
        //while(buffer->frame_pending())
+       
+       cout << "FPS: " << buffer->frame_rate();
+       cout << "Size: " << buffer->size();
+
+       RawVideoBuffer* root = buffer->root_buffer();
+
+       cout << typeid(*root).name() << endl;
+
+       #ifdef CVD_HAVE_V4LBUFFER
+               if(dynamic_cast<V4L::RawV4LBuffer*>(root))
+               {
+                       cout << "Using V4LBuffer.\n";
+               }
+       #endif
+
        for(;;)
        {
                VideoFrame<C>* frame = buffer->get_frame();
@@ -84,11 +105,11 @@
        }
        try
        {
-               if(type == 1)
-                       play<byte>(argv[arg]);
-               else if(type == 2)
-                       play<Rgb8>(argv[arg]);
-               else
+//             if(type == 1)
+//                     play<byte>(argv[arg]);
+//             else if(type == 2)
+//                     play<Rgb8>(argv[arg]);
+//             else
                        play<Rgb<byte> >(argv[arg]);
        }
        catch(CVD::Exceptions::All& e)




reply via email to

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