Changeset 16766 for trunk/Cosy/videodev


Ignore:
Timestamp:
06/07/13 23:30:10 (11 years ago)
Author:
tbretz
Message:
Changed to use v4l2.
Location:
trunk/Cosy/videodev
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cosy/videodev/MVideo.cc

    r8869 r16766  
    1616!
    1717!
    18 !   Author(s): Thomas Bretz 1/2008 <mailto:tbretz@astro.uni-wuerzburg.de>
     18!   Author(s): Thomas Bretz 1/2008 <mailto:thomas.bretz@epfl.ch>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2008
     20!   Copyright: MAGIC Software Development, 2000-2011
    2121!
    2222!
     
    2828//
    2929// Interface to Video4Linux at a simple level
     30//
     31// V4L2 spcifications from http://v4l2spec.bytesex.org/spec/
    3032//
    3133/////////////////////////////////////////////////////////////////////////////
     
    8486void MVideo::Reset()
    8587{
     88    fInputs.clear();
     89    fStandards.clear();
     90
    8691    memset(&fCaps,    0, sizeof(fCaps));
    8792    memset(&fChannel, 0, sizeof(fChannel));
    88     memset(&fBuffer,  0, sizeof(fBuffer));
     93//    memset(&fBuffer,  0, sizeof(fBuffer));
    8994    memset(&fAbil,    0, sizeof(fAbil));
    9095
     
    113118        // FIXME: This call is a possible source for a hangup
    114119        const int rc = ioctl(fFileDesc, req, opt);
    115         if (rc>=0)
    116             return rc;
     120        if (rc==0)
     121            return 0;
     122
     123        if (errno==EINVAL)
     124            return 1;
     125
     126        if (!allowirq && errno==EAGAIN)
     127            return -4;
     128
     129        cout <<"errno="<< errno << endl;
    117130
    118131        // errno== 4: Interrupted system call (e.g. by alarm())
     
    331344}
    332345
     346template<class S>
     347Bool_t MVideo::Enumerate(vector<S> &vec, int request)
     348{
     349    for (int i=0; ; i++)
     350    {
     351        S input;
     352        input.index = i;
     353
     354        const int rc = Ioctl(request, &input);
     355        if (rc<0)
     356            return kFALSE;
     357        if (rc==1)
     358            return kTRUE;
     359
     360        vec.push_back(input);
     361    }
     362
     363    return kFALSE;
     364}
     365
     366void MVideo::PrintInputs() const
     367{
     368    gLog << all;
     369    for (vector<v4l2_input>::const_iterator it=fInputs.begin(); it!=fInputs.end(); it++)
     370    {
     371        gLog << "Input #" << it->index << endl;
     372        gLog << " - " << it->name << endl;
     373        gLog << " - " << (it->type==V4L2_INPUT_TYPE_CAMERA?"Camera":"Tuner") << endl;
     374        gLog << " - TV Standard: " << hex << it->std << dec << endl;
     375
     376        gLog << " - Status: 0x" << hex << it->status;
     377        if (it->status&V4L2_IN_ST_NO_POWER)
     378            gLog << " NoPower";
     379        if (it->status&V4L2_IN_ST_NO_SIGNAL)
     380            gLog << " NoSignal";
     381        if (it->status&V4L2_IN_ST_NO_COLOR)
     382            gLog << " NoColor";
     383        if (it->status&V4L2_IN_ST_NO_H_LOCK)
     384            gLog << " NoHLock";
     385        if (it->status&V4L2_IN_ST_COLOR_KILL)
     386            gLog << " ColorKill";
     387        gLog << endl;
     388
     389        /*
     390         TV Standard
     391         ===========
     392         #define V4L2_STD_PAL_B          ((v4l2_std_id)0x00000001)
     393         #define V4L2_STD_PAL_B1         ((v4l2_std_id)0x00000002)
     394         #define V4L2_STD_PAL_G          ((v4l2_std_id)0x00000004)
     395         #define V4L2_STD_PAL_H          ((v4l2_std_id)0x00000008)
     396         #define V4L2_STD_PAL_I          ((v4l2_std_id)0x00000010)
     397         #define V4L2_STD_PAL_D          ((v4l2_std_id)0x00000020)
     398         #define V4L2_STD_PAL_D1         ((v4l2_std_id)0x00000040)
     399         #define V4L2_STD_PAL_K          ((v4l2_std_id)0x00000080)
     400
     401         #define V4L2_STD_PAL_M          ((v4l2_std_id)0x00000100)
     402         #define V4L2_STD_PAL_N          ((v4l2_std_id)0x00000200)
     403         #define V4L2_STD_PAL_Nc         ((v4l2_std_id)0x00000400)
     404         #define V4L2_STD_PAL_60         ((v4l2_std_id)0x00000800)
     405         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.
     406
     407         #define V4L2_STD_NTSC_M         ((v4l2_std_id)0x00001000)
     408         #define V4L2_STD_NTSC_M_JP      ((v4l2_std_id)0x00002000)
     409         #define V4L2_STD_NTSC_443       ((v4l2_std_id)0x00004000)
     410         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.
     411
     412         #define V4L2_STD_NTSC_M_KR      ((v4l2_std_id)0x00008000)
     413
     414         #define V4L2_STD_SECAM_B        ((v4l2_std_id)0x00010000)
     415         #define V4L2_STD_SECAM_D        ((v4l2_std_id)0x00020000)
     416         #define V4L2_STD_SECAM_G        ((v4l2_std_id)0x00040000)
     417         #define V4L2_STD_SECAM_H        ((v4l2_std_id)0x00080000)
     418         #define V4L2_STD_SECAM_K        ((v4l2_std_id)0x00100000)
     419         #define V4L2_STD_SECAM_K1       ((v4l2_std_id)0x00200000)
     420         #define V4L2_STD_SECAM_L        ((v4l2_std_id)0x00400000)
     421         #define V4L2_STD_SECAM_LC       ((v4l2_std_id)0x00800000)
     422
     423
     424         // ATSC/HDTV
     425         #define V4L2_STD_ATSC_8_VSB     ((v4l2_std_id)0x01000000)
     426         #define V4L2_STD_ATSC_16_VSB    ((v4l2_std_id)0x02000000)
     427         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.
     428
     429         #define V4L2_STD_PAL_BG   (V4L2_STD_PAL_B   | V4L2_STD_PAL_B1    | V4L2_STD_PAL_G)
     430         #define V4L2_STD_B        (V4L2_STD_PAL_B   | V4L2_STD_PAL_B1    | V4L2_STD_SECAM_B)
     431         #define V4L2_STD_GH       (V4L2_STD_PAL_G   | V4L2_STD_PAL_H     | V4L2_STD_SECAM_G  | V4L2_STD_SECAM_H)
     432         #define V4L2_STD_PAL_DK   (V4L2_STD_PAL_D   | V4L2_STD_PAL_D1    | V4L2_STD_PAL_K)
     433         #define V4L2_STD_PAL      (V4L2_STD_PAL_BG  | V4L2_STD_PAL_DK    | V4L2_STD_PAL_H    | V4L2_STD_PAL_I)
     434         #define V4L2_STD_NTSC     (V4L2_STD_NTSC_M  | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_M_KR)
     435         #define V4L2_STD_MN       (V4L2_STD_PAL_M   | V4L2_STD_PAL_N     | V4L2_STD_PAL_Nc   | V4L2_STD_NTSC)
     436         #define V4L2_STD_SECAM_DK (V4L2_STD_SECAM_D | V4L2_STD_SECAM_K   | V4L2_STD_SECAM_K1)
     437         #define V4L2_STD_DK       (V4L2_STD_PAL_DK  | V4L2_STD_SECAM_DK)
     438         #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)
     439         #define V4L2_STD_525_60   (V4L2_STD_PAL_M   | V4L2_STD_PAL_60    | V4L2_STD_NTSC     | V4L2_STD_NTSC_443)
     440         #define V4L2_STD_625_50   (V4L2_STD_PAL     | V4L2_STD_PAL_N     | V4L2_STD_PAL_Nc   | V4L2_STD_SECAM)
     441         #define V4L2_STD_UNKNOWN  0
     442         #define V4L2_STD_ALL      (V4L2_STD_525_60  | V4L2_STD_625_50)
     443         */
     444
     445         /*
     446          Status:
     447         =======
     448         General
     449         V4L2_IN_ST_NO_POWER    0x00000001      Attached device is off.
     450         V4L2_IN_ST_NO_SIGNAL   0x00000002
     451         V4L2_IN_ST_NO_COLOR    0x00000004      The hardware supports color decoding, but does not detect color modulation in the signal.
     452
     453         Analog Video
     454         V4L2_IN_ST_NO_H_LOCK   0x00000100      No horizontal sync lock.
     455         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.
     456
     457         Digital Video
     458         V4L2_IN_ST_NO_SYNC     0x00010000      No synchronization lock.
     459         V4L2_IN_ST_NO_EQU      0x00020000      No equalizer lock.
     460         V4L2_IN_ST_NO_CARRIER  0x00040000      Carrier recovery failed.
     461
     462         VCR and Set-Top Box
     463         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.
     464         V4L2_IN_ST_NO_ACCESS   0x02000000      Conditional access denied.
     465         V4L2_IN_ST_VTR         0x04000000      VTR time constant. [?]
     466         */
     467    }
     468}
     469
     470void MVideo::PrintStandards() const
     471{
     472    gLog << all;
     473    for (vector<v4l2_standard>::const_iterator it=fStandards.begin(); it!=fStandards.end(); it++)
     474    {
     475        gLog << "Index #" << it->index << endl;
     476        gLog << " - TV Standard: " << it->name << hex << "(" << it->id << ")" << dec << endl;
     477        gLog << " - FPS: " << it->frameperiod.numerator << "/" << it->frameperiod.denominator << endl;
     478        gLog << " - Lines: " << it->framelines << endl;
     479    }
     480}
    333481
    334482// -------------------------------------------------------------
     
    338486Bool_t MVideo::Open(Int_t ch)
    339487{
    340     Bool_t rc = Init(ch);
     488    const Bool_t rc = Init(ch);
    341489    if (!rc)
    342490        Close();
     
    361509    do
    362510    {
    363         fFileDesc = open(fPath, O_RDWR);
     511        fFileDesc = open(fPath, O_RDWR|O_NONBLOCK, 0);
    364512        usleep(1);
    365513    }
     
    381529    }
    382530
    383     gLog << warn << "Setting video standard to PAL-N." << endl;
    384 
    385     fVideoStandard = V4L2_STD_PAL_N;
    386     if (Ioctl(VIDIOC_S_STD, &fVideoStandard)==-1)
    387     {
    388         gLog << err << "ERROR - Could not set video standard to PAL-N." << endl;
    389         return kFALSE;
    390     }
    391 
    392     if (!EnumerateControls())
    393     {
    394         gLog << err << "ERROR - Could not enumerate controls." << endl;
    395         return kFALSE;
    396     }
    397 
    398     if (!ResetControls())
    399     {
    400         gLog << err << "ERROR - Could not reset controls to default." << endl;
    401         return kFALSE;
    402     }
    403 
    404     if (!GetCapabilities())
    405     {
    406         gLog << err << "ERROR - Getting device capabilities failed." << endl;
    407         return kFALSE;
    408     }
    409 
    410     if (!SetChannel(channel))
    411         return kFALSE;
    412 
    413     if (!GetProperties())
    414     {
    415         gLog << err << "ERROR - Couldn't get picture properties." << endl;
    416         return kFALSE;
    417     }
     531
     532
    418533/*
    419     if (HasTuner())
    420     {
    421         if (!GetTunerAbilities())
     534    if (!Enumerate(fInputs, VIDIOC_ENUMINPUT))
     535    {
     536        gLog << err << "ERROR - Could not enumerate inputs." << endl;
     537        return kFALSE;
     538    }
     539    PrintInputs();
     540
     541    if (!Enumerate(fStandards, VIDIOC_ENUMSTD))
     542    {
     543        gLog << err << "ERROR - Could not enumerate inputs." << endl;
     544        return kFALSE;
     545    }
     546    PrintStandards();
     547   */
     548
     549    int index = 3;
     550    if (Ioctl(VIDIOC_S_INPUT, &index)==-1)
     551    {
     552        gLog << err << "ERROR - Could not set input." << endl;
     553        return kFALSE;
     554    }
     555
     556    //check the input
     557    if (Ioctl(VIDIOC_G_INPUT, &index))
     558    {
     559        gLog << err << "ERROR - Could not get input." << endl;
     560        return kFALSE;
     561    }
     562
     563    v4l2_input input;
     564    memset(&input, 0, sizeof (input));
     565    input.index = index;
     566    if (Ioctl(VIDIOC_ENUMINPUT, &input))
     567    {
     568        gLog << err << "ERROR - Could enum input." << endl;
     569        return kFALSE;
     570    }
     571    gLog << "*** Input: " << input.name << " (" << input.index << ")" << endl;
     572
     573    v4l2_std_id st = 4;//standard.id;
     574    if (Ioctl (VIDIOC_S_STD, &st))
     575    {
     576        gLog << err << "ERROR - Could not set standard." << endl;
     577        return kFALSE;
     578    }
     579
     580    v4l2_capability cap;
     581    if (Ioctl(VIDIOC_QUERYCAP, &cap))
     582    {
     583        gLog << err << "ERROR - Could not get capabilities." << endl;
     584        return kFALSE;
     585    }
     586
     587    if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
     588    {
     589        gLog << err << "ERROR - No capture capabaility." << endl;
     590        return kFALSE;
     591    }
     592
     593    v4l2_cropcap cropcap;
     594    cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
     595
     596    if (Ioctl(VIDIOC_CROPCAP, &cropcap)==-1)
     597    {
     598    }
     599
     600    v4l2_crop crop;
     601    crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
     602    crop.c = cropcap.defrect; /* reset to default */
     603
     604    if (Ioctl(VIDIOC_S_CROP, &crop))
     605    {
     606        gLog << err << "Could not reset cropping." << endl;
     607        return kFALSE;
     608    }
     609
     610    v4l2_format fmt;
     611    fmt.type                = V4L2_BUF_TYPE_VIDEO_CAPTURE;
     612    fmt.fmt.pix.width       = 768;
     613    fmt.fmt.pix.height      = 576;
     614    fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB32;
     615
     616    if (Ioctl(VIDIOC_S_FMT, &fmt)==-1)
     617    {
     618        gLog << err << "ERROR - Could not set format." << endl;
     619        return kFALSE;
     620    }
     621    // The image format must be selected before buffers are allocated,
     622    // with the VIDIOC_S_FMT ioctl. When no format is selected the driver
     623    // may use the last, possibly by another application requested format.
     624
     625    v4l2_requestbuffers reqbuf;
     626    memset (&reqbuf, 0, sizeof (reqbuf));
     627
     628    reqbuf.type   = V4L2_BUF_TYPE_VIDEO_CAPTURE;
     629    reqbuf.memory = V4L2_MEMORY_MMAP;
     630    reqbuf.count  = 4;//125;
     631
     632    if (Ioctl(VIDIOC_REQBUFS, &reqbuf)==-1)
     633    {
     634        gLog << err << "ERROR - Couldn't setup frame buffers." << endl;
     635        return kFALSE;
     636    }
     637
     638    gLog << all << "Allocated " << reqbuf.count << " frame buffers." << endl;
     639
     640    for (unsigned int i=0; i<reqbuf.count; i++)
     641    {
     642        v4l2_buffer buffer;
     643        memset (&buffer, 0, sizeof (buffer));
     644
     645        buffer.type   = V4L2_BUF_TYPE_VIDEO_CAPTURE;
     646        buffer.memory = V4L2_MEMORY_MMAP;
     647        buffer.index  = i;
     648
     649        if (Ioctl(VIDIOC_QUERYBUF, &buffer))
    422650        {
    423             gLog << err << "ERROR - Couldn't get tuner abilities." << endl;
     651            gLog << err << "ERROR - Request of frame buffer " << i << " failed." << endl;
    424652            return kFALSE;
    425653        }
    426     }
    427  */
    428     // get mmap grab buffer info
    429     if (Ioctl(VIDIOCGMBUF, &fBuffer)==-1)
    430     {
    431         gLog << err << "ERROR - Couldn't get info about memory map buffer." << endl;
    432         return kFALSE;
    433     }
    434 
    435     // map file (device) into memory
    436     fMapBuffer = (unsigned char*)mmap(0, fBuffer.size, PROT_READ|PROT_WRITE, MAP_SHARED, fFileDesc, 0);
    437     if (fMapBuffer == (void*)-1)
    438     {
    439         gLog << err << "ERROR - Couldn't map device buffer into memory." << endl;
    440         fMapBuffer = 0;
    441         return kFALSE;
    442     }
    443 
    444     Print();
     654
     655        void *ptr = mmap(NULL, buffer.length,
     656                         PROT_READ | PROT_WRITE,
     657                         MAP_SHARED,
     658                         fFileDesc, buffer.m.offset);
     659
     660        if (MAP_FAILED == ptr)
     661        {
     662
     663            gLog << err << "ERROR - Could not allocate shared memory." << endl;
     664            return kFALSE;
     665                // If you do not exit here you should unmap() and free()
     666                // the buffers mapped so far.
     667                //perror ("mmap");
     668                //exit (EXIT_FAILURE);
     669        }
     670
     671        fBuffers.push_back(make_pair(buffer, ptr));
     672    }
     673
     674    return kTRUE;
     675}
     676
     677Bool_t MVideo::Start()
     678{
     679    v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
     680    if (Ioctl(VIDIOC_STREAMON, &type)==-1)
     681    {
     682        gLog << err << "ERROR - Couldn't start capturing." << endl;
     683        return kFALSE;
     684    }
     685
     686    cout << "*** Stream on" << endl;
    445687
    446688    return kTRUE;
     
    455697    //    if (!IsOpen())
    456698    //        return kTRUE;
    457 
     699/*
     700    if (Ioctl(VIDIOC_STREAMON, &fBuffers[0])==-1)
     701    {
     702        gLog << err << "ERROR - Couldn't start capturing." << endl;
     703        return kFALSE;
     704    }
     705*/
    458706    Bool_t rc = kTRUE;
    459707
     
    471719
    472720    // unmap device memory
    473     if (fMapBuffer)
    474         munmap(fMapBuffer, fBuffer.size);
     721    for (vector<pair<v4l2_buffer,void*> >::iterator it=fBuffers.begin(); it!=fBuffers.end(); it++)
     722    {
     723        munmap(it->second, it->first.length);
     724        fBuffers.erase(it);
     725    }
    475726
    476727    Reset();
     
    485736Bool_t MVideo::CaptureStart(unsigned int frame) const
    486737{
    487     frame %= fBuffer.frames;
    488 
     738    frame %= fBuffers.size();
     739
     740//    cout << "*** CaptureStart " << frame << endl;
     741
     742    if (Ioctl(VIDIOC_QBUF, const_cast<v4l2_buffer*>(&fBuffers[frame].first))==-1)
     743    {
     744        gLog << err << "ERROR - Couldn't buffer " << frame << "." << endl;
     745        return kFALSE;
     746    }
     747
     748//    cout << "*** " << errno << endl;
     749
     750    return kTRUE;
     751
     752    /*
    489753    struct video_mmap gb =
    490754    {
     
    508772    gLog << "ERROR - Couldn't start capturing frame " << frame << "." << endl;
    509773    gLog << "        Maybe your card doesn't support VIDEO_PALETTE_RGB24." << endl;
    510 
    511774    return kFALSE;
     775    */
    512776}
    513777
     
    518782Int_t MVideo::CaptureWait(unsigned int frame, unsigned char **ptr) const
    519783{
    520     frame %= fBuffer.frames;
     784    frame %= fBuffers.size();
    521785
    522786    if (ptr)
    523787        *ptr = NULL;
    524788
    525     const int SYNC_TIMEOUT = 1;
    526 
    527 #ifdef DEBUG
    528     gLog << dbg << "CaptureWait(" << frame << ")" << endl;
    529 #endif
    530 
    531     alarm(SYNC_TIMEOUT);
    532     const Int_t rc = Ioctl(VIDIOCSYNC, &frame, false);
     789//    const int SYNC_TIMEOUT = 1;
     790
     791//#ifdef DEBUG
     792//    cout << "*** CaptureWait " << frame << endl;
     793//#endif
     794
     795    //alarm(SYNC_TIMEOUT);
     796    const Int_t rc = Ioctl(VIDIOC_DQBUF, const_cast<v4l2_buffer*>(&fBuffers[frame].first), false);
    533797    if (rc==-4)
    534798    {
     
    536800        return kSKIP;
    537801    }
    538     alarm(0);
     802    //alarm(0);
    539803
    540804    if (rc==-1)
     
    545809
    546810    if (ptr)
    547         *ptr = fMapBuffer+fBuffer.offsets[frame];
     811        *ptr = static_cast<unsigned char*>(fBuffers[frame].second);
    548812
    549813    return kTRUE;
     
    556820Int_t MVideo::SetChannel(Int_t chan)
    557821{
     822    return kSKIP;
     823
    558824    if (fChannel.channel==chan)
    559825        return kSKIP;
     
    612878Int_t MVideo::GetNumBuffers() const
    613879{
    614     return fBuffer.frames;
     880    return fBuffers.size();
    615881}
    616882
     
    621887Int_t MVideo::GetWidth() const
    622888{
    623     return fCaps.maxwidth;
     889    return 768;//fCaps.maxwidth;
    624890}
    625891
     
    630896Int_t MVideo::GetHeight() const
    631897{
    632     return fCaps.maxheight;
     898    return 576;//fCaps.maxheight;
    633899}
    634900
     
    7751041    gLog << all << dec;
    7761042
    777     gLog << "Device " << fPath << " " << (IsOpen()?"open":"closed") << "." << endl;
    778 
    779     if (!IsOpen())
     1043    gLog << "Device " << fPath << " " << (fFileDesc>0?"open":"closed") << "." << endl;
     1044
     1045    if (fFileDesc<=0)
    7801046        return;
    7811047
     
    8011067        gLog << " - Tuner:           " << fAbil.tuner << endl;
    8021068        gLog << " - Name:            " << fAbil.name << endl;
    803         gLog << " - Tuner Range:     " << fAbil.rangelow << " - " << fAbil.rangehigh << endl;
     1069 //       gLog << " - Tuner Range:     " << fAbil.rangelow << " - " << fAbil.rangehigh << endl;
    8041070        gLog << " - Tuner flags:    " << GetTunerFlags(fAbil.flags) << " (" << fAbil.flags << ")" << endl;
    8051071        gLog << " - Tuner mode:      " << GetTunerMode(fAbil.mode) << " (" << fAbil.mode << ")" <<endl;
     
    8161082    gLog  << endl;
    8171083
    818     gLog  << " - BufferSize: 0x" << hex << fBuffer.size << " (" << dec << fBuffer.frames << " frames)" << endl;
    819     gLog  << " - Offsets:   " << hex;
    820     for (int i=0; i<fBuffer.frames; i++)
    821         gLog  << " 0x" << fBuffer.offsets[i];
    822     gLog  << dec << endl;
     1084//    gLog  << " - BufferSize: 0x" << hex << fBuffer.size << " (" << dec << fBuffer.frames << " frames)" << endl;
     1085//    gLog  << " - Offsets:   " << hex;
     1086//    for (int i=0; i<fBuffer.frames; i++)
     1087//        gLog  << " 0x" << fBuffer.offsets[i];
     1088//    gLog  << dec << endl;
    8231089
    8241090    gLog << inf2 << "Controls:" << endl;
  • trunk/Cosy/videodev/MVideo.h

    r8862 r16766  
    88#ifndef __CINT__
    99#ifndef __LINUX_VIDEODEV_H
    10 #include <linux/videodev.h>  // video4linux
     10#include "videodev.h"  // video4linux
    1111#endif
    1212#ifndef __LINUX_VIDEODEV2_H
     
    1515#endif
    1616
     17#include <vector>
     18
    1719struct v4l2_queryctrl;
     20struct v4l2_input;
     21struct v4l2_standard;
     22struct v4l2_buffer;
     23
    1824class TEnv;
    1925
     
    5359    struct video_capability fCaps;      // Device capabilities
    5460    struct video_channel    fChannel;   // Channel information
    55     struct video_mbuf       fBuffer;    // Buffer information
     61    //struct video_mbuf       fBuffer;    // Buffer information
    5662    struct video_picture    fProp;      // Picture properties
    5763    struct video_tuner      fAbil;      // Tuner abilities
    5864
    5965    ULong64_t fVideoStandard;
     66
     67    std::vector<v4l2_input>      fInputs;
     68    std::vector<v4l2_standard>   fStandards;
     69    std::vector<std::pair<v4l2_buffer, void*> > fBuffers;
    6070
    6171    TList fControls;
     
    7484    Bool_t Init(Int_t channel);
    7585
     86    template<class S>
     87        Bool_t Enumerate(std::vector<S> &s, int request);
     88
     89    void PrintInputs() const;
     90    void PrintStandards() const;
     91
    7692    // Conversion functions
    7793    TString GetDevType(int type) const;
     
    8399
    84100public:
    85     MVideo(const char *path="/dev/video");
     101    MVideo(const char *path="/dev/video0");
    86102    virtual ~MVideo() { Close(); }
    87103
    88104    // Getter
    89     Bool_t IsOpen() const { return fFileDesc>0 && fMapBuffer; }
     105    Bool_t IsOpen() const { return fFileDesc>0 && fBuffers.size()>0; }
    90106    Bool_t CanCapture() const;
    91107    Bool_t HasTuner() const;
     
    109125    Bool_t CaptureStart(unsigned int frame) const;
    110126    Int_t  CaptureWait(unsigned int frame, unsigned char **ptr=0) const;
     127    Bool_t Start();
    111128
    112129    // Support
Note: See TracChangeset for help on using the changeset viewer.