Changeset 348 in flair-src for trunk/lib/FlairSensorActuator


Ignore:
Timestamp:
Feb 17, 2020, 3:44:56 PM (5 years ago)
Author:
Sanahuja Guillaume
Message:

update v4l cam, ok on gcs

Location:
trunk/lib/FlairSensorActuator/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairSensorActuator/src/Camera.h

    r340 r348  
    139139        */
    140140  void SetLogFormat(LogFormat logFormat);
    141 void ProcessUpdate(core::io_data* data);
     141  void ProcessUpdate(core::io_data* data);
    142142protected:
    143143  /*!
  • trunk/lib/FlairSensorActuator/src/V4LCamera.cpp

    r347 r348  
    3333#define DEFAULT_V4L_BUFFERS 4
    3434
    35 #define CLEAR(x) memset (&(x), 0, sizeof (x))
    36 
    3735using std::string;
    3836using namespace flair::core;
     
    5553  }
    5654
    57   /* w/o memset some parts  arent initialized - AKA: Fill it with zeros so it is clean */
    58   memset(&capture,0,sizeof(CvCaptureCAM_V4L));
    59   n_buffers = 0;
    60 
    61  
    6255  if(format == Image::Type::Format::UYVY) {
    6356    if(init(width,height,V4L2_PIX_FMT_UYVY) == -1) {
     
    7770  allocBuffers();
    7871
    79   for (capture.bufferIndex = 0;capture.bufferIndex < ((int)capture.req.count);++capture.bufferIndex) {
     72  for (int i=0;i < nbBuffers;i++) {
    8073    struct v4l2_buffer buf;
    81 
    82     CLEAR (buf);
     74    memset(&buf, 0, sizeof (v4l2_buffer));
    8375
    8476    buf.type        = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    8577    buf.memory      = V4L2_MEMORY_MMAP;
    86     buf.index       = (unsigned long)capture.bufferIndex;
     78    buf.index       = (unsigned long)i;
    8779
    8880    if (-1 == xioctl (device, VIDIOC_QBUF, &buf)) {
     
    9284
    9385  /* enable the streaming */
    94   capture.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    95   if (-1 == xioctl (device, VIDIOC_STREAMON,&capture.type)) {
    96     /* error enabling the stream */
     86  v4l2_buf_type type;
     87  type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
     88  if (-1 == xioctl (device, VIDIOC_STREAMON,&type)) {
    9789    Thread::Err("VIDIOC_STREAMON error\n");
    9890  }
     
    115107
    116108V4LCamera::~V4LCamera() {
    117   for (int n_buffers = 0; n_buffers < nbBuffers; n_buffers++) {
    118        //FreeFunction((char*)buffers[n_buffers].start);
     109  for (int i = 0; i < nbBuffers; i++) {
     110       //FreeFunction((char*)buffers[i].start);
    119111  }
    120112  SafeStop();
    121113  Join();
     114  close(device);
    122115}
    123116
    124117int V4LCamera::init(int width, int height,unsigned long colorspace) {
    125   CLEAR (capture.cap);
    126   if(-1 == xioctl(device, VIDIOC_QUERYCAP, &capture.cap)) {
     118  struct v4l2_capability cap;
     119  memset(&cap, 0, sizeof (v4l2_capability));
     120 
     121  if(-1 == xioctl(device, VIDIOC_QUERYCAP, &cap)) {
    127122    return -1;
    128   } else {
    129     CLEAR (capture.capability);
    130     capture.capability.type = capture.cap.capabilities;
    131 
    132     /* Query channels number */
    133     if (-1 == xioctl(device, VIDIOC_G_INPUT, &capture.capability.channels)) {
    134       return -1;
    135     }
    136123  }
    137124     
    138   if ((capture.cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {
     125  if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {
    139126    Thread::Err("device is unable to capture video memory.\n");
    140127    return -1;
    141128  }
    142129
    143   /* Find Window info */
    144   CLEAR (capture.form);
    145   capture.form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    146      
    147   if (-1 == xioctl (device, VIDIOC_G_FMT, &capture.form)) {
    148      Thread::Err("Could not obtain specifics of capture window.\n");
    149      return -1;
     130  struct v4l2_format form;
     131  memset(&form, 0, sizeof (v4l2_format));
     132  form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
     133
     134  /* read the current setting */
     135  if(-1 == xioctl(device, VIDIOC_G_FMT, &form)) {
     136   Thread::Err("Could not obtain specifics of capture window.\n");
     137   return -1;
     138  }
     139
     140  /* set the values we want to change */
     141  form.fmt.pix.width = width;
     142  form.fmt.pix.height = height;
     143  form.fmt.win.chromakey = 0;
     144  form.fmt.win.field = V4L2_FIELD_ANY;
     145  form.fmt.win.clips = 0;
     146  form.fmt.win.clipcount = 0;
     147  form.fmt.pix.field = V4L2_FIELD_ANY;
     148  form.fmt.pix.pixelformat = colorspace;
     149
     150  /* ask the device to change the size*/
     151  if(-1 == xioctl (device, VIDIOC_S_FMT, &form)) {
     152    Thread::Err("Could not set specifics of capture window.\n");
     153    return -1;
     154  }
     155
     156  /* Get window info again, to get the real value */
     157  if(-1 == xioctl (device, VIDIOC_G_FMT, &form)) {
     158    Thread::Err("Could not obtain specifics of capture window.\n");
     159    return -1;
    150160  }
    151161 
    152   setVideoSize(width, height,colorspace);
    153 
    154   unsigned int min;
    155 
    156   /* Buggy driver paranoia. */
    157   min = capture.form.fmt.pix.width * 2;
    158   if (capture.form.fmt.pix.bytesperline < min) {
    159    capture.form.fmt.pix.bytesperline = min;
    160   }
    161 
    162   min = capture.form.fmt.pix.bytesperline * capture.form.fmt.pix.height;
    163   if (capture.form.fmt.pix.sizeimage < min) {
    164    capture.form.fmt.pix.sizeimage = min;
    165   }
    166 
    167   return 1;
    168 }
    169 
    170 int V4LCamera::setVideoSize(int width, int height,unsigned long colorspace) {
    171 
    172     CLEAR (capture.crop);
    173     capture.crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    174     capture.crop.c.left       = 0;
    175     capture.crop.c.top        = 0;
    176     capture.crop.c.height     = height*24;
    177     capture.crop.c.width      = width*24;
    178 
    179     /* set the crop area, but don't exit if the device don't support croping */
    180     xioctl (device, VIDIOC_S_CROP, &capture.crop);
    181 
    182     CLEAR (capture.form);
    183     capture.form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    184 
    185     /* read the current setting */
    186     xioctl (device, VIDIOC_G_FMT, &capture.form);
    187 
    188     /* set the values we want to change */
    189     capture.form.fmt.pix.width = width;
    190     capture.form.fmt.pix.height = height;
    191     capture.form.fmt.win.chromakey = 0;
    192     capture.form.fmt.win.field = V4L2_FIELD_ANY;
    193     capture.form.fmt.win.clips = 0;
    194     capture.form.fmt.win.clipcount = 0;
    195     capture.form.fmt.pix.field = V4L2_FIELD_ANY;
    196     capture.form.fmt.pix.pixelformat = colorspace;
    197 
    198     /* ask the device to change the size*/
    199     if (-1 == xioctl (device, VIDIOC_S_FMT, &capture.form)) {
    200       Thread::Err("Could not set specifics of capture window.\n");
    201       return -1;
    202     }
    203 
    204     /* Get window info again, to get the real value */
    205     if (-1 == xioctl (device, VIDIOC_G_FMT, &capture.form)) {
    206       Thread::Err("Could not obtain specifics of capture window.\n");
    207       return -1;
    208     }
    209     return 0;
    210 
     162  return 0;
    211163}
    212164
    213165/*
    214 V4LCamera::V4LCamera(string name,
    215                      uint8_t camera_index, uint16_t width, uint16_t height,
    216                      Image::Type::Format format, uint8_t priority)
    217     : Thread(getFrameworkManager(), name, priority),
    218       Camera(name, width, height, format) {
    219  
    220     string deviceName="/dev/video"+std::to_string(camera_index);
    221     device = open(deviceName.c_str(), O_RDWR | O_NONBLOCK);
    222     if (device == -1) {
    223         Thread::Err("Cannot open %s\n",deviceName.c_str());
    224     } else {
    225         Printf("V4LCamera %s, opened %s\n",name.c_str(),deviceName.c_str());
    226     }
    227 
    228     struct v4l2_capability cap;
    229     memset(&cap, 0, sizeof (v4l2_capability));
    230     if (xioctl (device, VIDIOC_QUERYCAP, &cap)==-1) {
    231         Thread::Err("VIDIOC_QUERYCAP xioctl\n");
    232     }
    233     if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {
    234         Thread::Err("device is unable to capture video memory.\n");
    235     }
    236 
    237     //get v4l2_format
    238     struct v4l2_format form;
    239     form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    240     if(xioctl (device, VIDIOC_G_FMT,&form)==-1) {
    241         Thread::Err("VIDIOC_G_FMT xioctl\n");
    242     }
    243  
    244     //set width, height and format
    245     if (format == Image::Type::Format::UYVY) {
    246         form.fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY;
    247     } else if (format == Image::Type::Format::YUYV) {
    248         form.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
    249     } else {
    250         Thread::Err("format not supported\n");
    251     }
    252  
    253     form.fmt.pix.width = width;
    254     form.fmt.pix.height = height;
    255     form.fmt.win.chromakey = 0;
    256     form.fmt.win.field = V4L2_FIELD_ANY;
    257     form.fmt.win.clips = 0;
    258     form.fmt.win.clipcount = 0;
    259     form.fmt.pix.field = V4L2_FIELD_ANY;
    260     if(xioctl (device, VIDIOC_S_FMT,&form)==-1) {
    261         Thread::Err("VIDIOC_S_FMT xioctl\n");
    262     }
    263  
    264     //alloc and queue bufs
    265     AllocBuffers();
    266     for (int bufferIndex = 0; bufferIndex < nbBuffers;++bufferIndex) {
    267         QueueBuffer(bufferIndex);
    268     }
    269    
    270     // enable the streaming
    271     v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    272     if (xioctl (device, VIDIOC_STREAMON,&type)==-1) {
    273         Thread::Err("VIDIOC_STREAMON xioctl\n");
    274     }
    275 
    276     // skip first frame. it is often bad -- this is unnotied in traditional apps,
    277     //  but could be fatal if bad jpeg is enabled
    278     bufferIndex=-1;
    279     GrabFrame();
    280 
    281     // ground station
    282     gain = new DoubleSpinBox(GetGroupBox()->NewRow(), "gain:", 0, 1, 0.1);
    283     exposure = new DoubleSpinBox(GetGroupBox()->LastRowLastCol(), "exposure:", 0,1, 0.1);
    284     bright = new DoubleSpinBox(GetGroupBox()->LastRowLastCol(), "bright:", 0, 1, 0.1);
    285     contrast = new DoubleSpinBox(GetGroupBox()->LastRowLastCol(), "contrast:", 0,1, 0.1);
    286     hue = new DoubleSpinBox(GetGroupBox()->LastRowLastCol(), "hue:", 0, 1, 0.1);
    287     sharpness = new DoubleSpinBox(GetGroupBox()->LastRowLastCol(), "sharpness:", 0, 1, 0.1);
    288     sat = new DoubleSpinBox(GetGroupBox()->LastRowLastCol(), "saturation:", 0, 1,0.1);
    289     autogain = new CheckBox(GetGroupBox()->NewRow(), "autogain:");
    290     autoexposure = new CheckBox(GetGroupBox()->LastRowLastCol(), "autoexposure:");
    291     awb = new CheckBox(GetGroupBox()->LastRowLastCol(), "awb:");
    292     fps = new Label(GetGroupBox()->NewRow(), "fps");
    293 
    294     hasProblems=false;
    295 }
    296 
    297 V4LCamera::~V4LCamera() {
    298     for (int n_buffers = 0; n_buffers < nbBuffers; n_buffers++) {
    299        FreeFunction((char*)buffers[n_buffers].start);
    300    }
    301     SafeStop();
    302     Join();
    303 }
    304 
    305166void V4LCamera::Run(void) {
    306167  Time cam_time, new_time, fpsNow, fpsPrev;
     
    395256*/
    396257int V4LCamera::allocBuffers() {
    397    CLEAR (capture.req);
    398    
    399    unsigned int buffer_number = DEFAULT_V4L_BUFFERS;
    400 
    401    try_again:
    402    
    403    capture.req.count = buffer_number;
    404    capture.req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    405    capture.req.memory = V4L2_MEMORY_MMAP;
    406 
    407    if (-1 == xioctl (device, VIDIOC_REQBUFS, &capture.req)) {
    408        if (EINVAL == errno) {
    409          Thread::Warn("does not support memory mapping\n");
    410        } else {
    411          perror ("VIDIOC_REQBUFS");
    412        }
    413        /* free capture, and returns an error code */
    414        return -1;
    415    }
    416 
    417    if (capture.req.count < buffer_number) {
    418        if (buffer_number == 1) {
    419            Thread::Warn("Insufficient buffer memory\n");
    420            /* free capture, and returns an error code */
    421            return -1;
    422        } else {
    423           buffer_number--;
    424           Thread::Warn("Insufficient buffer memory -- decreaseing buffers\n");
    425           goto try_again;
    426        }
    427    }
    428 
    429    for (n_buffers = 0; n_buffers < capture.req.count; ++n_buffers) {
    430        struct v4l2_buffer buf;
    431        CLEAR (buf);
    432 
    433        buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    434        buf.memory = V4L2_MEMORY_MMAP;
    435        buf.index = n_buffers;
    436 
    437        if (-1 == xioctl (device, VIDIOC_QUERYBUF, &buf)) {
    438            Thread::Warn ("VIDIOC_QUERYBUF error\n");
    439            /* free capture, and returns an error code */
    440            return -1;
    441        }
    442 
    443        capture.buffers[n_buffers].length = buf.length;
    444        capture.buffers[n_buffers].start =
    445          mmap (NULL /* start anywhere */,
    446                buf.length,
    447                PROT_READ | PROT_WRITE /* required */,
    448                MAP_SHARED /* recommended */,
    449                device, buf.m.offset);
    450 
    451        if (MAP_FAILED == capture.buffers[n_buffers].start) {
    452            Thread::Warn("mmap error\n");
    453            /* free capture, and returns an error code */
    454            return -1;
    455        }
    456    }
    457 
    458    /* Set up Image data */
    459    /*
    460    cvInitImageHeader( &capture.frame,
    461                       cvSize( capture.captureWindow.width,
    462                               capture.captureWindow.height ),
    463                       IPL_DEPTH_8U, 3, IPL_ORIGIN_TL, 4 );*/
    464    /* Allocate space for RGBA data */
    465    capture.imageSize=capture.form.fmt.pix.width*capture.form.fmt.pix.height*2;
    466    capture.imageData = AllocFunction(capture.imageSize);
    467    Printf("cmem allocated %i at %x\n",capture.imageSize,capture.imageData);
    468    
    469    return 1;
     258  struct v4l2_requestbuffers req;
     259  memset(&req, 0, sizeof (v4l2_requestbuffers));
     260  nbBuffers=DEFAULT_V4L_BUFFERS;
     261
     262  try_again:
     263
     264  req.count = nbBuffers;
     265  req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
     266  req.memory = V4L2_MEMORY_MMAP;
     267
     268  if(-1 == xioctl(device, VIDIOC_REQBUFS, &req)) {
     269    if (EINVAL == errno) {
     270      Thread::Err("camera does not support memory mapping\n");
     271    } else {
     272      Thread::Err("VIDIOC_REQBUFS failed\n");
     273    }
     274    return -1;
     275  }
     276
     277  if(req.count < nbBuffers) {
     278    if (nbBuffers == 1) {
     279      Thread::Err("Insufficient buffer memory\n");
     280      return -1;
     281    } else {
     282      nbBuffers--;
     283      Thread::Warn("Insufficient buffer memory -- decreaseing buffers to %i\n",nbBuffers);
     284      goto try_again;
     285    }
     286  }
     287
     288  for(int i=0; i<req.count; i++) {
     289    struct v4l2_buffer buf;
     290    memset(&buf, 0, sizeof (v4l2_buffer));
     291
     292    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
     293    buf.memory = V4L2_MEMORY_MMAP;
     294    buf.index = i;
     295
     296    if(-1 == xioctl(device, VIDIOC_QUERYBUF, &buf)) {
     297      Thread::Err("VIDIOC_QUERYBUF error\n");
     298      return -1;
     299    }
     300
     301    if(output->GetDataType().GetSize()!=buf.length) {
     302      Thread::Err("buf size is not as exepcted %i/%i\n",buf.length,output->GetDataType().GetSize());
     303      return -1;
     304    }
     305
     306    buffers[i]=mmap(NULL,buf.length,PROT_READ | PROT_WRITE,MAP_SHARED,device, buf.m.offset);
     307
     308    if(MAP_FAILED == buffers[i]) {
     309      Thread::Err("mmap error\n");
     310      return -1;
     311    }
     312  }
     313
     314  //allocate output data
     315  imageData = AllocFunction(output->GetDataType().GetSize());
     316  Printf("cmem allocated %i at %x\n",output->GetDataType().GetSize(),imageData);
     317
     318  return 1;
    470319};
    471320
     321int V4LCamera::AllocBuffers(void) {
     322  struct v4l2_requestbuffers requestbuffers;
     323  memset(&requestbuffers, 0, sizeof (v4l2_requestbuffers));
     324
     325  unsigned int buffer_number = DEFAULT_V4L_BUFFERS;
     326
     327  try_again:
     328
     329  requestbuffers.count = buffer_number;
     330  requestbuffers.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
     331  requestbuffers.memory = V4L2_MEMORY_USERPTR;
     332
     333  if (xioctl (device, VIDIOC_REQBUFS, &requestbuffers)==-1) {
     334    if (errno==EINVAL) {
     335      Thread::Err("VIDIOC_REQBUFS user memory not supported\n");
     336    } else {
     337      Thread::Err ("VIDIOC_REQBUFS xioctl\n");
     338    }
     339    return -1;
     340  }
     341
     342  nbBuffers=DEFAULT_V4L_BUFFERS;
     343  for (int i=0; i<nbBuffers; i++) {
     344    buffers[i] =AllocFunction(output->GetDataType().GetSize());
     345  }
     346
     347  return 1;
     348};
    472349
    473350int V4LCamera::cvGrabFrame(void) {
     
    505382            }
    506383
    507             if (read_frame_v4l2 (&capture))
     384            if (read_frame_v4l2 ())
    508385                break;
    509386        }
     
    512389}
    513390
    514 int V4LCamera::read_frame_v4l2(CvCaptureCAM_V4L* capture) {
     391int V4LCamera::read_frame_v4l2(void) {
    515392    struct v4l2_buffer buf;
    516 
    517     CLEAR (buf);
     393    memset(&buf, 0, sizeof (v4l2_buffer));
    518394
    519395    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
     
    537413   }
    538414
    539    if(buf.index >= capture->req.count) {
     415   if(buf.index >= nbBuffers) {
    540416     Thread::Err("buf.index >= capture->req.count\n");
    541417   }
    542    
    543 
    544    capture->bufferIndex = buf.index;
    545 
     418
     419   bufferIndex = buf.index;
    546420
    547421   if (-1 == xioctl (device, VIDIOC_QBUF, &buf))
     
    611485   
    612486    // cam pictures
    613     cvRetrieveRawFrame(&capture);
     487    cvRetrieveRawFrame();
    614488    if (!cvGrabFrame()) {
    615489      Printf("Could not grab a frame\n");
     
    625499    output->GetMutex();
    626500   
    627     output->buffer=capture.imageData;
     501    output->buffer=imageData;
    628502    output->ReleaseMutex();
    629503   
     
    632506    cam_time = new_time;
    633507  }
    634 
    635   //cvReleaseCapture(&capture);
    636 }
    637 
    638 void V4LCamera::cvRetrieveRawFrame( CvCaptureCAM_V4L* capture) {
    639 
    640 
    641 
    642 
    643    /* Now get what has already been captured as a IplImage return */
    644 
    645    /* First, reallocate imageData if the frame size changed */
    646 
    647 
    648 /*
    649     if(((unsigned long)capture->frame.width != capture->form.fmt.pix.width)
    650        || ((unsigned long)capture->frame.height != capture->form.fmt.pix.height)) {
    651            if (PALETTE_YUYV == 1 || PALETTE_UYVY == 1)
    652            {
    653                 cvFree(&capture->frame.imageData);
    654                 cvInitImageHeader( &capture->frame,
    655                 cvSize( capture->form.fmt.pix.width,
    656                 capture->form.fmt.pix.height ),
    657                 IPL_DEPTH_8U,2, IPL_ORIGIN_TL, 4 );
    658                 capture->frame.imageData = (char *)cvAlloc(capture->frame.imageSize);
    659            }else
    660            {
    661               fprintf( stderr,
    662                  "HIGHGUI ERROR: V4L: raw output not supported for this palette\n");
    663            }
    664 
    665     }
    666 
    667  */
    668 
    669 
    670    
    671   memcpy((char *)capture->imageData,(char *)capture->buffers[capture->bufferIndex].start,capture->imageSize);
    672    
    673  
    674 
    675    
    676 }
     508}
     509
     510void V4LCamera::cvRetrieveRawFrame(void) {
     511  memcpy(imageData,(char *)buffers[bufferIndex],output->GetDataType().GetSize());
     512}
     513
    677514int V4LCamera::QueueBuffer(int index) {
    678515    struct v4l2_buffer buf;
     
    682519        buf.memory      = V4L2_MEMORY_USERPTR;//V4L2_MEMORY_MMAP;
    683520        buf.index       = (unsigned long)index;
    684         buf.m.userptr=(unsigned long)(buffers[index].start);
    685         buf.length=buffers[index].length;
     521        buf.m.userptr=(unsigned long)(buffers[index]);
     522        buf.length=output->GetDataType().GetSize();
    686523       
    687524        int ret=xioctl (device, VIDIOC_QBUF, &buf);
     
    738575               QueueBuffer(prevDQbuf);
    739576           }
    740            for (int n_buffers = 0; n_buffers < nbBuffers; n_buffers++) {
    741                if((void*)(buf.m.userptr)==buffers[n_buffers].start) {
    742                    prevDQbuf=n_buffers;
    743                    bufferIndex=n_buffers;
     577           for (int i=0; i<nbBuffers; i++) {
     578               if((void*)(buf.m.userptr)==buffers[i]) {
     579                   prevDQbuf=i;
     580                   bufferIndex=i;
    744581                   break;
    745582               }
     
    750587   return 1;
    751588}
    752 
    753 int V4LCamera::AllocBuffers(void) {
    754     struct v4l2_requestbuffers requestbuffers;
    755    memset(&requestbuffers, 0, sizeof (v4l2_requestbuffers));
    756    
    757    unsigned int buffer_number = DEFAULT_V4L_BUFFERS;
    758 
    759    try_again:
    760    
    761    requestbuffers.count = buffer_number;
    762    requestbuffers.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    763    requestbuffers.memory = V4L2_MEMORY_USERPTR;//V4L2_MEMORY_MMAP;
    764 
    765    if (xioctl (device, VIDIOC_REQBUFS, &requestbuffers)==-1) {
    766        if (errno==EINVAL) {
    767          Thread::Err("VIDIOC_REQBUFS user memory not supported\n");
    768        } else {
    769          Thread::Err ("VIDIOC_REQBUFS xioctl\n");
    770        }
    771        return -1;
    772    }
    773    
    774    nbBuffers=DEFAULT_V4L_BUFFERS;
    775    for (int n_buffers = 0; n_buffers < nbBuffers; n_buffers++) {
    776        buffers[n_buffers].length = output->GetDataType().GetSize();
    777        buffers[n_buffers].start =AllocFunction(output->GetDataType().GetSize());
    778    }
    779 
    780    return 1;
    781 };
    782589
    783590bool V4LCamera::HasProblems(void) {
  • trunk/lib/FlairSensorActuator/src/V4LCamera.h

    r347 r348  
    142142  void Run(void);
    143143 
    144   int device;
    145144  gui::Tab *sensor_tab;
    146145  gui::DoubleSpinBox *bright, *exposure, *gain, *contrast, *hue, *sharpness,*sat;
    147146  gui::CheckBox *autogain, *awb, *autoexposure;
    148147  gui::Label *fps;
     148 
     149  int device;
    149150  bool hasProblems;
     151  struct video_mmap *mmaps;
     152  void* buffers[MAX_V4L_BUFFERS];
     153  int nbBuffers;
     154  int bufferIndex;
     155  char *imageData;
     156 
     157  int init(int width, int height,unsigned long colorspace);
    150158  static int xioctl( int fd, int request, void *arg);
    151159  void SetProperty(int property,float value);
     
    153161  int GrabFrame(void);
    154162  int AllocBuffers(void);
     163  int allocBuffers (void);
    155164  int QueueBuffer(int index);
    156   struct video_mmap *mmaps;
    157   int bufferIndex;
    158   struct buffer {
    159     void *  start;
    160     size_t  length;
    161   };
    162   buffer buffers[MAX_V4L_BUFFERS];
    163   char* frame;
    164   int nbBuffers;
    165165 
    166     typedef struct CvCaptureCAM_V4L
    167 {
    168     //int deviceHandle;
    169     int bufferIndex;
    170     struct video_capability capability;
    171     struct video_window     captureWindow;
    172     struct video_picture    imageProperties;
    173     struct video_mbuf       memoryBuffer;
    174     struct video_mmap       *mmaps;
    175     char *memoryMap;
    176     //IplImage frame;
    177 char *imageData;
    178 int imageSize;
    179166
    180    /* V4L2 variables */
    181    buffer buffers[MAX_V4L_BUFFERS + 1];
    182    struct v4l2_capability cap;
    183    struct v4l2_input inp;
    184    struct v4l2_format form;
    185    struct v4l2_crop crop;
    186    struct v4l2_cropcap cropcap;
    187    struct v4l2_requestbuffers req;
    188    struct v4l2_jpegcompression compr;
    189    struct v4l2_control control;
    190    enum v4l2_buf_type type;
    191    struct v4l2_queryctrl queryctrl;
    192    struct v4l2_querymenu querymenu;
    193 } CvCaptureCAM_V4L;
     167int cvGrabFrame(void);
    194168
    195 CvCaptureCAM_V4L capture;
    196 int init(int width, int height,unsigned long colorspace);
    197 int setVideoSize(int width, int height,unsigned long colorspace);
    198 int cvGrabFrame(void);
    199 int allocBuffers (void);
    200 int read_frame_v4l2(CvCaptureCAM_V4L* capture);
    201 void cvRetrieveRawFrame( CvCaptureCAM_V4L* capture);
    202 unsigned int n_buffers ;
     169int read_frame_v4l2(void);
     170void cvRetrieveRawFrame(void);
     171
     172
    203173};
    204174} // end namespace sensor
Note: See TracChangeset for help on using the changeset viewer.