Index: /trunk/Cosy/videodev/MVideo.cc
===================================================================
--- /trunk/Cosy/videodev/MVideo.cc	(revision 16765)
+++ /trunk/Cosy/videodev/MVideo.cc	(revision 16766)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz 1/2008 <mailto:tbretz@astro.uni-wuerzburg.de>
+!   Author(s): Thomas Bretz 1/2008 <mailto:thomas.bretz@epfl.ch>
 !
-!   Copyright: MAGIC Software Development, 2000-2008
+!   Copyright: MAGIC Software Development, 2000-2011
 !
 !
@@ -28,4 +28,6 @@
 //
 // Interface to Video4Linux at a simple level
+//
+// V4L2 spcifications from http://v4l2spec.bytesex.org/spec/
 //
 /////////////////////////////////////////////////////////////////////////////
@@ -84,7 +86,10 @@
 void MVideo::Reset()
 {
+    fInputs.clear();
+    fStandards.clear();
+
     memset(&fCaps,    0, sizeof(fCaps));
     memset(&fChannel, 0, sizeof(fChannel));
-    memset(&fBuffer,  0, sizeof(fBuffer));
+//    memset(&fBuffer,  0, sizeof(fBuffer));
     memset(&fAbil,    0, sizeof(fAbil));
 
@@ -113,6 +118,14 @@
         // FIXME: This call is a possible source for a hangup
         const int rc = ioctl(fFileDesc, req, opt);
-        if (rc>=0)
-            return rc;
+        if (rc==0)
+            return 0;
+
+        if (errno==EINVAL)
+            return 1;
+
+        if (!allowirq && errno==EAGAIN)
+            return -4;
+
+        cout <<"errno="<< errno << endl;
 
         // errno== 4: Interrupted system call (e.g. by alarm())
@@ -331,4 +344,139 @@
 }
 
+template<class S>
+Bool_t MVideo::Enumerate(vector<S> &vec, int request)
+{
+    for (int i=0; ; i++)
+    {
+        S input;
+        input.index = i;
+
+        const int rc = Ioctl(request, &input);
+        if (rc<0)
+            return kFALSE;
+        if (rc==1)
+            return kTRUE;
+
+        vec.push_back(input);
+    }
+
+    return kFALSE;
+}
+
+void MVideo::PrintInputs() const
+{
+    gLog << all;
+    for (vector<v4l2_input>::const_iterator it=fInputs.begin(); it!=fInputs.end(); it++)
+    {
+        gLog << "Input #" << it->index << endl;
+        gLog << " - " << it->name << endl;
+        gLog << " - " << (it->type==V4L2_INPUT_TYPE_CAMERA?"Camera":"Tuner") << endl;
+        gLog << " - TV Standard: " << hex << it->std << dec << endl;
+
+        gLog << " - Status: 0x" << hex << it->status;
+        if (it->status&V4L2_IN_ST_NO_POWER)
+            gLog << " NoPower";
+        if (it->status&V4L2_IN_ST_NO_SIGNAL)
+            gLog << " NoSignal";
+        if (it->status&V4L2_IN_ST_NO_COLOR)
+            gLog << " NoColor";
+        if (it->status&V4L2_IN_ST_NO_H_LOCK)
+            gLog << " NoHLock";
+        if (it->status&V4L2_IN_ST_COLOR_KILL)
+            gLog << " ColorKill";
+        gLog << endl;
+
+        /*
+         TV Standard
+         ===========
+         #define V4L2_STD_PAL_B          ((v4l2_std_id)0x00000001)
+         #define V4L2_STD_PAL_B1         ((v4l2_std_id)0x00000002)
+         #define V4L2_STD_PAL_G          ((v4l2_std_id)0x00000004)
+         #define V4L2_STD_PAL_H          ((v4l2_std_id)0x00000008)
+         #define V4L2_STD_PAL_I          ((v4l2_std_id)0x00000010)
+         #define V4L2_STD_PAL_D          ((v4l2_std_id)0x00000020)
+         #define V4L2_STD_PAL_D1         ((v4l2_std_id)0x00000040)
+         #define V4L2_STD_PAL_K          ((v4l2_std_id)0x00000080)
+
+         #define V4L2_STD_PAL_M          ((v4l2_std_id)0x00000100)
+         #define V4L2_STD_PAL_N          ((v4l2_std_id)0x00000200)
+         #define V4L2_STD_PAL_Nc         ((v4l2_std_id)0x00000400)
+         #define V4L2_STD_PAL_60         ((v4l2_std_id)0x00000800)
+         V4L2_STD_PAL_60 is a hybrid standard with 525 lines, 60 Hz refresh rate, and PAL color modulation with a 4.43 MHz color subcarrier. Some PAL video recorders can play back NTSC tapes in this mode for display on a 50/60 Hz agnostic PAL TV.
+
+         #define V4L2_STD_NTSC_M         ((v4l2_std_id)0x00001000)
+         #define V4L2_STD_NTSC_M_JP      ((v4l2_std_id)0x00002000)
+         #define V4L2_STD_NTSC_443       ((v4l2_std_id)0x00004000)
+         V4L2_STD_NTSC_443 is a hybrid standard with 525 lines, 60 Hz refresh rate, and NTSC color modulation with a 4.43 MHz color subcarrier.
+
+         #define V4L2_STD_NTSC_M_KR      ((v4l2_std_id)0x00008000)
+
+         #define V4L2_STD_SECAM_B        ((v4l2_std_id)0x00010000)
+         #define V4L2_STD_SECAM_D        ((v4l2_std_id)0x00020000)
+         #define V4L2_STD_SECAM_G        ((v4l2_std_id)0x00040000)
+         #define V4L2_STD_SECAM_H        ((v4l2_std_id)0x00080000)
+         #define V4L2_STD_SECAM_K        ((v4l2_std_id)0x00100000)
+         #define V4L2_STD_SECAM_K1       ((v4l2_std_id)0x00200000)
+         #define V4L2_STD_SECAM_L        ((v4l2_std_id)0x00400000)
+         #define V4L2_STD_SECAM_LC       ((v4l2_std_id)0x00800000)
+
+
+         // ATSC/HDTV
+         #define V4L2_STD_ATSC_8_VSB     ((v4l2_std_id)0x01000000)
+         #define V4L2_STD_ATSC_16_VSB    ((v4l2_std_id)0x02000000)
+         V4L2_STD_ATSC_8_VSB and V4L2_STD_ATSC_16_VSB are U.S. terrestrial digital TV standards. Presently the V4L2 API does not support digital TV. See also the Linux DVB API at http://linuxtv.org.
+
+         #define V4L2_STD_PAL_BG   (V4L2_STD_PAL_B   | V4L2_STD_PAL_B1    | V4L2_STD_PAL_G)
+         #define V4L2_STD_B        (V4L2_STD_PAL_B   | V4L2_STD_PAL_B1    | V4L2_STD_SECAM_B)
+         #define V4L2_STD_GH       (V4L2_STD_PAL_G   | V4L2_STD_PAL_H     | V4L2_STD_SECAM_G  | V4L2_STD_SECAM_H)
+         #define V4L2_STD_PAL_DK   (V4L2_STD_PAL_D   | V4L2_STD_PAL_D1    | V4L2_STD_PAL_K)
+         #define V4L2_STD_PAL      (V4L2_STD_PAL_BG  | V4L2_STD_PAL_DK    | V4L2_STD_PAL_H    | V4L2_STD_PAL_I)
+         #define V4L2_STD_NTSC     (V4L2_STD_NTSC_M  | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_M_KR)
+         #define V4L2_STD_MN       (V4L2_STD_PAL_M   | V4L2_STD_PAL_N     | V4L2_STD_PAL_Nc   | V4L2_STD_NTSC)
+         #define V4L2_STD_SECAM_DK (V4L2_STD_SECAM_D | V4L2_STD_SECAM_K   | V4L2_STD_SECAM_K1)
+         #define V4L2_STD_DK       (V4L2_STD_PAL_DK  | V4L2_STD_SECAM_DK)
+         #define V4L2_STD_SECAM    (V4L2_STD_SECAM_B | V4L2_STD_SECAM_G   | V4L2_STD_SECAM_H  | V4L2_STD_SECAM_DK | V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)
+         #define V4L2_STD_525_60   (V4L2_STD_PAL_M   | V4L2_STD_PAL_60    | V4L2_STD_NTSC     | V4L2_STD_NTSC_443)
+         #define V4L2_STD_625_50   (V4L2_STD_PAL     | V4L2_STD_PAL_N     | V4L2_STD_PAL_Nc   | V4L2_STD_SECAM)
+         #define V4L2_STD_UNKNOWN  0
+         #define V4L2_STD_ALL      (V4L2_STD_525_60  | V4L2_STD_625_50)
+         */
+
+         /*
+          Status:
+         =======
+         General
+         V4L2_IN_ST_NO_POWER	0x00000001	Attached device is off.
+         V4L2_IN_ST_NO_SIGNAL	0x00000002
+         V4L2_IN_ST_NO_COLOR	0x00000004	The hardware supports color decoding, but does not detect color modulation in the signal.
+
+         Analog Video
+         V4L2_IN_ST_NO_H_LOCK	0x00000100	No horizontal sync lock.
+         V4L2_IN_ST_COLOR_KILL	0x00000200	A color killer circuit automatically disables color decoding when it detects no color modulation. When this flag is set the color killer is enabled and has shut off color decoding.
+
+         Digital Video
+         V4L2_IN_ST_NO_SYNC	0x00010000	No synchronization lock.
+         V4L2_IN_ST_NO_EQU	0x00020000	No equalizer lock.
+         V4L2_IN_ST_NO_CARRIER	0x00040000	Carrier recovery failed.
+
+         VCR and Set-Top Box
+         V4L2_IN_ST_MACROVISION	0x01000000	Macrovision is an analog copy prevention system mangling the video signal to confuse video recorders. When this flag is set Macrovision has been detected.
+         V4L2_IN_ST_NO_ACCESS	0x02000000	Conditional access denied.
+         V4L2_IN_ST_VTR	        0x04000000	VTR time constant. [?]
+         */
+    }
+}
+
+void MVideo::PrintStandards() const
+{
+    gLog << all;
+    for (vector<v4l2_standard>::const_iterator it=fStandards.begin(); it!=fStandards.end(); it++)
+    {
+        gLog << "Index #" << it->index << endl;
+        gLog << " - TV Standard: " << it->name << hex << "(" << it->id << ")" << dec << endl;
+        gLog << " - FPS: " << it->frameperiod.numerator << "/" << it->frameperiod.denominator << endl;
+        gLog << " - Lines: " << it->framelines << endl;
+    }
+}
 
 // -------------------------------------------------------------
@@ -338,5 +486,5 @@
 Bool_t MVideo::Open(Int_t ch)
 {
-    Bool_t rc = Init(ch);
+    const Bool_t rc = Init(ch);
     if (!rc)
         Close();
@@ -361,5 +509,5 @@
     do
     {
-        fFileDesc = open(fPath, O_RDWR);
+        fFileDesc = open(fPath, O_RDWR|O_NONBLOCK, 0);
         usleep(1);
     }
@@ -381,66 +529,160 @@
     }
 
-    gLog << warn << "Setting video standard to PAL-N." << endl;
-
-    fVideoStandard = V4L2_STD_PAL_N;
-    if (Ioctl(VIDIOC_S_STD, &fVideoStandard)==-1)
-    {
-        gLog << err << "ERROR - Could not set video standard to PAL-N." << endl;
-        return kFALSE;
-    }
-
-    if (!EnumerateControls())
-    {
-        gLog << err << "ERROR - Could not enumerate controls." << endl;
-        return kFALSE;
-    }
-
-    if (!ResetControls())
-    {
-        gLog << err << "ERROR - Could not reset controls to default." << endl;
-        return kFALSE;
-    }
-
-    if (!GetCapabilities())
-    {
-        gLog << err << "ERROR - Getting device capabilities failed." << endl;
-        return kFALSE;
-    }
-
-    if (!SetChannel(channel))
-        return kFALSE;
-
-    if (!GetProperties())
-    {
-        gLog << err << "ERROR - Couldn't get picture properties." << endl;
-        return kFALSE;
-    }
+
+
 /*
-    if (HasTuner())
-    {
-        if (!GetTunerAbilities())
+    if (!Enumerate(fInputs, VIDIOC_ENUMINPUT))
+    {
+        gLog << err << "ERROR - Could not enumerate inputs." << endl;
+        return kFALSE;
+    }
+    PrintInputs();
+
+    if (!Enumerate(fStandards, VIDIOC_ENUMSTD))
+    {
+        gLog << err << "ERROR - Could not enumerate inputs." << endl;
+        return kFALSE;
+    }
+    PrintStandards();
+   */
+
+    int index = 3;
+    if (Ioctl(VIDIOC_S_INPUT, &index)==-1)
+    {
+        gLog << err << "ERROR - Could not set input." << endl;
+        return kFALSE;
+    }
+
+    //check the input
+    if (Ioctl(VIDIOC_G_INPUT, &index))
+    {
+        gLog << err << "ERROR - Could not get input." << endl;
+        return kFALSE;
+    }
+
+    v4l2_input input;
+    memset(&input, 0, sizeof (input));
+    input.index = index;
+    if (Ioctl(VIDIOC_ENUMINPUT, &input))
+    {
+        gLog << err << "ERROR - Could enum input." << endl;
+        return kFALSE;
+    }
+    gLog << "*** Input: " << input.name << " (" << input.index << ")" << endl;
+
+    v4l2_std_id st = 4;//standard.id;
+    if (Ioctl (VIDIOC_S_STD, &st))
+    {
+        gLog << err << "ERROR - Could not set standard." << endl;
+        return kFALSE;
+    }
+
+    v4l2_capability cap;
+    if (Ioctl(VIDIOC_QUERYCAP, &cap))
+    {
+        gLog << err << "ERROR - Could not get capabilities." << endl;
+        return kFALSE;
+    }
+
+    if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
+    {
+        gLog << err << "ERROR - No capture capabaility." << endl;
+        return kFALSE;
+    }
+
+    v4l2_cropcap cropcap;
+    cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+
+    if (Ioctl(VIDIOC_CROPCAP, &cropcap)==-1)
+    {
+    }
+
+    v4l2_crop crop;
+    crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+    crop.c = cropcap.defrect; /* reset to default */
+
+    if (Ioctl(VIDIOC_S_CROP, &crop))
+    {
+        gLog << err << "Could not reset cropping." << endl;
+        return kFALSE;
+    }
+
+    v4l2_format fmt;
+    fmt.type                = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+    fmt.fmt.pix.width       = 768;
+    fmt.fmt.pix.height      = 576;
+    fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB32;
+
+    if (Ioctl(VIDIOC_S_FMT, &fmt)==-1)
+    {
+        gLog << err << "ERROR - Could not set format." << endl;
+        return kFALSE;
+    }
+    // The image format must be selected before buffers are allocated,
+    // with the VIDIOC_S_FMT ioctl. When no format is selected the driver
+    // may use the last, possibly by another application requested format.
+
+    v4l2_requestbuffers reqbuf;
+    memset (&reqbuf, 0, sizeof (reqbuf));
+
+    reqbuf.type   = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+    reqbuf.memory = V4L2_MEMORY_MMAP;
+    reqbuf.count  = 4;//125;
+
+    if (Ioctl(VIDIOC_REQBUFS, &reqbuf)==-1)
+    {
+        gLog << err << "ERROR - Couldn't setup frame buffers." << endl;
+        return kFALSE;
+    }
+
+    gLog << all << "Allocated " << reqbuf.count << " frame buffers." << endl;
+
+    for (unsigned int i=0; i<reqbuf.count; i++)
+    {
+        v4l2_buffer buffer;
+        memset (&buffer, 0, sizeof (buffer));
+
+        buffer.type   = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+	buffer.memory = V4L2_MEMORY_MMAP;
+        buffer.index  = i;
+
+        if (Ioctl(VIDIOC_QUERYBUF, &buffer))
         {
-            gLog << err << "ERROR - Couldn't get tuner abilities." << endl;
+            gLog << err << "ERROR - Request of frame buffer " << i << " failed." << endl;
             return kFALSE;
         }
-    }
- */
-    // get mmap grab buffer info
-    if (Ioctl(VIDIOCGMBUF, &fBuffer)==-1)
-    {
-        gLog << err << "ERROR - Couldn't get info about memory map buffer." << endl;
-        return kFALSE;
-    }
-
-    // map file (device) into memory
-    fMapBuffer = (unsigned char*)mmap(0, fBuffer.size, PROT_READ|PROT_WRITE, MAP_SHARED, fFileDesc, 0);
-    if (fMapBuffer == (void*)-1)
-    {
-        gLog << err << "ERROR - Couldn't map device buffer into memory." << endl;
-        fMapBuffer = 0;
-        return kFALSE;
-    }
-
-    Print();
+
+        void *ptr = mmap(NULL, buffer.length,
+                         PROT_READ | PROT_WRITE,
+                         MAP_SHARED,
+                         fFileDesc, buffer.m.offset);
+
+        if (MAP_FAILED == ptr)
+        {
+
+            gLog << err << "ERROR - Could not allocate shared memory." << endl;
+            return kFALSE;
+                // If you do not exit here you should unmap() and free()
+                // the buffers mapped so far.
+                //perror ("mmap");
+                //exit (EXIT_FAILURE);
+        }
+
+        fBuffers.push_back(make_pair(buffer, ptr));
+    }
+
+    return kTRUE;
+}
+
+Bool_t MVideo::Start()
+{
+    v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+    if (Ioctl(VIDIOC_STREAMON, &type)==-1)
+    {
+        gLog << err << "ERROR - Couldn't start capturing." << endl;
+        return kFALSE;
+    }
+
+    cout << "*** Stream on" << endl;
 
     return kTRUE;
@@ -455,5 +697,11 @@
     //    if (!IsOpen())
     //        return kTRUE;
-
+/*
+    if (Ioctl(VIDIOC_STREAMON, &fBuffers[0])==-1)
+    {
+        gLog << err << "ERROR - Couldn't start capturing." << endl;
+        return kFALSE;
+    }
+*/
     Bool_t rc = kTRUE;
 
@@ -471,6 +719,9 @@
 
     // unmap device memory
-    if (fMapBuffer)
-        munmap(fMapBuffer, fBuffer.size);
+    for (vector<pair<v4l2_buffer,void*> >::iterator it=fBuffers.begin(); it!=fBuffers.end(); it++)
+    {
+        munmap(it->second, it->first.length);
+        fBuffers.erase(it);
+    }
 
     Reset();
@@ -485,6 +736,19 @@
 Bool_t MVideo::CaptureStart(unsigned int frame) const
 {
-    frame %= fBuffer.frames;
-
+    frame %= fBuffers.size();
+
+//    cout << "*** CaptureStart " << frame << endl;
+
+    if (Ioctl(VIDIOC_QBUF, const_cast<v4l2_buffer*>(&fBuffers[frame].first))==-1)
+    {
+        gLog << err << "ERROR - Couldn't buffer " << frame << "." << endl;
+        return kFALSE;
+    }
+
+//    cout << "*** " << errno << endl;
+
+    return kTRUE;
+
+    /*
     struct video_mmap gb =
     {
@@ -508,6 +772,6 @@
     gLog << "ERROR - Couldn't start capturing frame " << frame << "." << endl;
     gLog << "        Maybe your card doesn't support VIDEO_PALETTE_RGB24." << endl;
-
     return kFALSE;
+    */
 }
 
@@ -518,17 +782,17 @@
 Int_t MVideo::CaptureWait(unsigned int frame, unsigned char **ptr) const
 {
-    frame %= fBuffer.frames;
+    frame %= fBuffers.size();
 
     if (ptr)
         *ptr = NULL;
 
-    const int SYNC_TIMEOUT = 1;
-
-#ifdef DEBUG
-    gLog << dbg << "CaptureWait(" << frame << ")" << endl;
-#endif
-
-    alarm(SYNC_TIMEOUT);
-    const Int_t rc = Ioctl(VIDIOCSYNC, &frame, false);
+//    const int SYNC_TIMEOUT = 1;
+
+//#ifdef DEBUG
+//    cout << "*** CaptureWait " << frame << endl;
+//#endif
+
+    //alarm(SYNC_TIMEOUT);
+    const Int_t rc = Ioctl(VIDIOC_DQBUF, const_cast<v4l2_buffer*>(&fBuffers[frame].first), false);
     if (rc==-4)
     {
@@ -536,5 +800,5 @@
         return kSKIP;
     }
-    alarm(0);
+    //alarm(0);
 
     if (rc==-1)
@@ -545,5 +809,5 @@
 
     if (ptr)
-        *ptr = fMapBuffer+fBuffer.offsets[frame];
+        *ptr = static_cast<unsigned char*>(fBuffers[frame].second);
 
     return kTRUE;
@@ -556,4 +820,6 @@
 Int_t MVideo::SetChannel(Int_t chan)
 {
+    return kSKIP;
+
     if (fChannel.channel==chan)
         return kSKIP;
@@ -612,5 +878,5 @@
 Int_t MVideo::GetNumBuffers() const
 {
-    return fBuffer.frames;
+    return fBuffers.size();
 }
 
@@ -621,5 +887,5 @@
 Int_t MVideo::GetWidth() const
 {
-    return fCaps.maxwidth;
+    return 768;//fCaps.maxwidth;
 }
 
@@ -630,5 +896,5 @@
 Int_t MVideo::GetHeight() const
 {
-    return fCaps.maxheight;
+    return 576;//fCaps.maxheight;
 }
 
@@ -775,7 +1041,7 @@
     gLog << all << dec;
 
-    gLog << "Device " << fPath << " " << (IsOpen()?"open":"closed") << "." << endl;
-
-    if (!IsOpen())
+    gLog << "Device " << fPath << " " << (fFileDesc>0?"open":"closed") << "." << endl;
+
+    if (fFileDesc<=0)
         return;
 
@@ -801,5 +1067,5 @@
         gLog << " - Tuner:           " << fAbil.tuner << endl;
         gLog << " - Name:            " << fAbil.name << endl;
-        gLog << " - Tuner Range:     " << fAbil.rangelow << " - " << fAbil.rangehigh << endl;
+ //       gLog << " - Tuner Range:     " << fAbil.rangelow << " - " << fAbil.rangehigh << endl;
         gLog << " - Tuner flags:    " << GetTunerFlags(fAbil.flags) << " (" << fAbil.flags << ")" << endl;
         gLog << " - Tuner mode:      " << GetTunerMode(fAbil.mode) << " (" << fAbil.mode << ")" <<endl;
@@ -816,9 +1082,9 @@
     gLog  << endl;
 
-    gLog  << " - BufferSize: 0x" << hex << fBuffer.size << " (" << dec << fBuffer.frames << " frames)" << endl;
-    gLog  << " - Offsets:   " << hex;
-    for (int i=0; i<fBuffer.frames; i++)
-        gLog  << " 0x" << fBuffer.offsets[i];
-    gLog  << dec << endl;
+//    gLog  << " - BufferSize: 0x" << hex << fBuffer.size << " (" << dec << fBuffer.frames << " frames)" << endl;
+//    gLog  << " - Offsets:   " << hex;
+//    for (int i=0; i<fBuffer.frames; i++)
+//        gLog  << " 0x" << fBuffer.offsets[i];
+//    gLog  << dec << endl;
 
     gLog << inf2 << "Controls:" << endl;
Index: /trunk/Cosy/videodev/MVideo.h
===================================================================
--- /trunk/Cosy/videodev/MVideo.h	(revision 16765)
+++ /trunk/Cosy/videodev/MVideo.h	(revision 16766)
@@ -8,5 +8,5 @@
 #ifndef __CINT__
 #ifndef __LINUX_VIDEODEV_H
-#include <linux/videodev.h>  // video4linux
+#include "videodev.h"  // video4linux
 #endif
 #ifndef __LINUX_VIDEODEV2_H
@@ -15,5 +15,11 @@
 #endif
 
+#include <vector>
+
 struct v4l2_queryctrl;
+struct v4l2_input;
+struct v4l2_standard;
+struct v4l2_buffer;
+
 class TEnv;
 
@@ -53,9 +59,13 @@
     struct video_capability fCaps;      // Device capabilities
     struct video_channel    fChannel;   // Channel information
-    struct video_mbuf       fBuffer;    // Buffer information
+    //struct video_mbuf       fBuffer;    // Buffer information
     struct video_picture    fProp;      // Picture properties
     struct video_tuner      fAbil;      // Tuner abilities
 
     ULong64_t fVideoStandard;
+
+    std::vector<v4l2_input>      fInputs;
+    std::vector<v4l2_standard>   fStandards;
+    std::vector<std::pair<v4l2_buffer, void*> > fBuffers;
 
     TList fControls;
@@ -74,4 +84,10 @@
     Bool_t Init(Int_t channel);
 
+    template<class S>
+        Bool_t Enumerate(std::vector<S> &s, int request);
+
+    void PrintInputs() const;
+    void PrintStandards() const;
+
     // Conversion functions
     TString GetDevType(int type) const;
@@ -83,9 +99,9 @@
 
 public:
-    MVideo(const char *path="/dev/video");
+    MVideo(const char *path="/dev/video0");
     virtual ~MVideo() { Close(); }
 
     // Getter
-    Bool_t IsOpen() const { return fFileDesc>0 && fMapBuffer; }
+    Bool_t IsOpen() const { return fFileDesc>0 && fBuffers.size()>0; }
     Bool_t CanCapture() const;
     Bool_t HasTuner() const;
@@ -109,4 +125,5 @@
     Bool_t CaptureStart(unsigned int frame) const;
     Int_t  CaptureWait(unsigned int frame, unsigned char **ptr=0) const;
+    Bool_t Start();
 
     // Support
