camera/drv-v4l2.c
static int capture_mmap(V4L2Capture *dev,int nBuffer){
  int res;
  struct v4l2_requestbuffers reqbuf;
  unsigned int i;

  memset (&reqbuf, 0, sizeof (reqbuf));
  reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  reqbuf.memory = V4L2_MEMORY_MMAP;
  reqbuf.count = nBuffer;
	
  res = v4l_ioctl (dev, VIDIOC_REQBUFS, &reqbuf);
	
  if (res<0){
    capture_log(dev,"Video mmap-streaming is not supported\n");
    return res;
  } 
	
  //capture_log(dev,"Allocated %d frames for buffer reading\n",reqbuf.count); 
	
  capture_create_frames_buffer(dev,reqbuf.count);

  for (i=0; i < dev->frames ; i++){
    struct v4l2_buffer buffer;
    memset (&buffer, 0, sizeof (buffer));
		
    buffer.type = reqbuf.type;
    buffer.memory = V4L2_MEMORY_MMAP;
    buffer.index = i;
    res = v4l_ioctl (dev, VIDIOC_QUERYBUF, &buffer);
    if (!res){
      dev->framesbuffer[i].buflen =buffer.length; /* remember for munmap() */
      dev->framesbuffer[i].readonly = 1; /* Do not allow to be modified by client */
#if 0			 
      dev->framesbuffer[i].data = mmap (NULL, buffer.bufsize,
                                        PROT_READ, /* required */
                                        MAP_SHARED,             /* recommended */
                                        dev->fd, buffer.m.offset);
#else
      dev->framesbuffer[i].data = mmap (NULL, buffer.length,
                                        PROT_READ | PROT_WRITE, /* required */
                                        MAP_SHARED,             /* recommended */
                                        dev->fd, buffer.m.offset);
#endif                                 
                                 
      if (dev->framesbuffer[i].data == MAP_FAILED){
        capture_log(dev,"mmap: %s\n",strerror(errno));
        res = -1;
        break;
      }                              
    } else {
      break;	
    }
  }
  return res;
}
/**
 *  @todo  implement vidFrameMmap() to avoid to access VidFrame
 *  member attributes directly 
 */
@todo  implement vidFrameMmap() to avoid to access VidFrame
member attributes directly
@todo implement vidFrameMmap () to avoid to access VidFrame member attributes directly
static int capture_mmap(V4L2Capture *dev,int nBuffer){
  int res;
  struct v4l2_requestbuffers reqbuf;
  unsigned int i;
  memset (&reqbuf, 0, sizeof (reqbuf));
  reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  reqbuf.memory = V4L2_MEMORY_MMAP;
  reqbuf.count = nBuffer;
  res = v4l_ioctl (dev, VIDIOC_REQBUFS, &reqbuf);
  if (res<0){
    capture_log(dev,"Video mmap-streaming is not supported\n");
    return res;
  } 
  capture_create_frames_buffer(dev,reqbuf.count);
  for (i=0; i < dev->frames ; i++){
    struct v4l2_buffer buffer;
    memset (&buffer, 0, sizeof (buffer));
    buffer.type = reqbuf.type;
    buffer.memory = V4L2_MEMORY_MMAP;
    buffer.index = i;
    res = v4l_ioctl (dev, VIDIOC_QUERYBUF, &buffer);
    if (!res){
      dev->framesbuffer[i].buflen =buffer.length; 
      dev->framesbuffer[i].readonly = 1; 
#if 0			 
      dev->framesbuffer[i].data = mmap (NULL, buffer.bufsize,
                                        PROT_READ, 
                                        MAP_SHARED,             
                                        dev->fd, buffer.m.offset);
#else
      dev->framesbuffer[i].data = mmap (NULL, buffer.length,
                                        PROT_READ | PROT_WRITE, 
                                        MAP_SHARED,             
                                        dev->fd, buffer.m.offset);
#endif                                 
      if (dev->framesbuffer[i].data == MAP_FAILED){
        capture_log(dev,"mmap: %s\n",strerror(errno));
        res = -1;
        break;
      }                              
    } else {
      break;	
    }
  }
  return res;
}
static int capture_mmap ( V4L2Capture * dev , int nBuffer ) { int res ; struct v4l2_requestbuffers reqbuf ; unsigned int i ; memset ( & reqbuf , 0 , sizeof ( reqbuf ) ) ; reqbuf . type = V4L2_BUF_TYPE_VIDEO_CAPTURE ; reqbuf . memory = V4L2_MEMORY_MMAP ; reqbuf . count = nBuffer ; res = v4l_ioctl ( dev , VIDIOC_REQBUFS , & reqbuf ) ; if ( res < 0 ) { capture_log ( dev , " \n " ) ; return res ; } capture_create_frames_buffer ( dev , reqbuf . count ) ; for ( i = 0 ; i < dev -> frames ; i ++ ) { struct v4l2_buffer buffer ; memset ( & buffer , 0 , sizeof ( buffer ) ) ; buffer . type = reqbuf . type ; buffer . memory = V4L2_MEMORY_MMAP ; buffer . index = i ; res = v4l_ioctl ( dev , VIDIOC_QUERYBUF , & buffer ) ; if ( ! res ) { dev -> framesbuffer [ i ] . buflen = buffer . length ; dev -> framesbuffer [ i ] . readonly = 1 ; #if 0 dev -> framesbuffer [ i ] . data = mmap ( NULL , buffer . bufsize , PROT_READ , MAP_SHARED , dev -> fd , buffer . m . offset ) ; #else dev -> framesbuffer [ i ] . data = mmap ( NULL , buffer . length , PROT_READ | PROT_WRITE , MAP_SHARED , dev -> fd , buffer . m . offset ) ; #endif if ( dev -> framesbuffer [ i ] . data == MAP_FAILED ) { capture_log ( dev , " \n " , strerror ( errno ) ) ; res = -1 ; break ; } } else { break ; } } return res ; }
@todo  implement vidFrameMmap() to avoid to access VidFrame
  member attributes directly
@todo implement vidFrameMmap () to avoid to access VidFrame member attributes directly
//capture_log(dev,"Allocated %d frames for buffer reading\n",reqbuf.count);  /* remember for munmap() */ /* Do not allow to be modified by client */ /* required */ /* recommended */ /* required */ /* recommended */