+ p_block = ProcessVideoFrame( p_demux, (uint8_t*)p_sys->p_buffers[0].start, i_ret );
+ if( !p_block ) return 0;
+
+ break;
+
+ case IO_METHOD_MMAP:
+ memset( &buf, 0, sizeof(buf) );
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_MMAP;
+
+ /* Wait for next frame */
+ if (ioctl( p_sys->i_fd_video, VIDIOC_DQBUF, &buf ) < 0 )
+ {
+ switch( errno )
+ {
+ case EAGAIN:
+ return 0;
+ case EIO:
+ /* Could ignore EIO, see spec. */
+ /* fall through */
+ default:
+ msg_Err( p_demux, "Failed to wait (VIDIOC_DQBUF)" );
+ return 0;
+ }
+ }
+
+ if( buf.index >= p_sys->i_nbuffers ) {
+ msg_Err( p_demux, "Failed capturing new frame as i>=nbuffers" );
+ return 0;
+ }
+
+ p_block = ProcessVideoFrame( p_demux, p_sys->p_buffers[buf.index].start, buf.bytesused );
+ if( !p_block ) return 0;
+
+ /* Unlock */
+ if( ioctl( p_sys->i_fd_video, VIDIOC_QBUF, &buf ) < 0 )
+ {
+ msg_Err (p_demux, "Failed to unlock (VIDIOC_QBUF)");
+ return 0;
+ }
+
+ break;
+
+ case IO_METHOD_USERPTR:
+ memset( &buf, 0, sizeof(buf) );
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_USERPTR;
+
+ /* Wait for next frame */
+ if (ioctl( p_sys->i_fd_video, VIDIOC_DQBUF, &buf ) < 0 )
+ {
+ switch( errno )
+ {
+ case EAGAIN:
+ return 0;
+ case EIO:
+ /* Could ignore EIO, see spec. */
+ /* fall through */
+ default:
+ msg_Err( p_demux, "Failed to wait (VIDIOC_DQBUF)" );
+ return 0;
+ }
+ }
+
+ /* Find frame? */
+ unsigned int i;
+ for( i = 0; i < p_sys->i_nbuffers; i++ )
+ {
+ if( buf.m.userptr == (unsigned long)p_sys->p_buffers[i].start &&
+ buf.length == p_sys->p_buffers[i].length ) break;
+ }
+
+ if( i >= p_sys->i_nbuffers )
+ {
+ msg_Err( p_demux, "Failed capturing new frame as i>=nbuffers" );
+ return 0;
+ }
+
+ p_block = ProcessVideoFrame( p_demux, (uint8_t*)buf.m.userptr, buf.bytesused );
+ if( !p_block ) return 0;
+
+ /* Unlock */
+ if( ioctl( p_sys->i_fd_video, VIDIOC_QBUF, &buf ) < 0 )
+ {
+ msg_Err (p_demux, "Failed to unlock (VIDIOC_QBUF)");
+ return 0;
+ }
+
+ break;
+
+ }
+
+ /* Timestamp */
+ p_sys->i_video_pts = p_block->i_pts = p_block->i_dts = mdate();
+
+ return p_block;
+}
+
+/*****************************************************************************
+ * ProcessVideoFrame: Helper function to take a buffer and copy it into
+ * a new block
+ *****************************************************************************/
+static block_t* ProcessVideoFrame( demux_t *p_demux, uint8_t *p_frame, size_t i_size )
+{
+ block_t *p_block;
+
+ if( !p_frame ) return 0;
+
+ /* New block */
+ if( !( p_block = block_New( p_demux, i_size ) ) )
+ {
+ msg_Warn( p_demux, "Cannot get new block" );
+ return 0;
+ }
+
+ /* Copy frame */
+ memcpy( p_block->p_buffer, p_frame, i_size );
+
+ return p_block;
+}
+
+/*****************************************************************************
+ * GrabAudio: Grab an audio frame
+ *****************************************************************************/
+static block_t* GrabAudio( demux_t *p_demux )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+ struct audio_buf_info buf_info;
+ int i_read, i_correct;
+ block_t *p_block;
+
+ if( p_sys->p_block_audio ) p_block = p_sys->p_block_audio;
+ else p_block = block_New( p_demux, p_sys->i_audio_max_frame_size );
+
+ if( !p_block )
+ {
+ msg_Warn( p_demux, "cannot get block" );
+ return 0;
+ }
+
+ p_sys->p_block_audio = p_block;
+
+#ifdef HAVE_ALSA
+ if( p_sys->b_use_alsa )
+ {
+ /* ALSA */
+ i_read = snd_pcm_readi( p_sys->p_alsa_pcm, p_block->p_buffer, p_sys->i_alsa_chunk_size );
+ /* TODO: ALSA ERROR HANDLING?? xrun?? */
+
+ /* convert from frames to bytes */
+ if( i_read > 0 ) i_read *= p_sys->i_alsa_frame_size;
+ }
+ else
+#endif
+ {
+ /* OSS */
+ i_read = read( p_sys->i_fd_audio, p_block->p_buffer,
+ p_sys->i_audio_max_frame_size );
+ }
+
+ if( i_read <= 0 ) return 0;
+
+ p_block->i_buffer = i_read;
+ p_sys->p_block_audio = 0;
+
+ /* Correct the date because of kernel buffering */
+ i_correct = i_read;
+#ifdef HAVE_ALSA
+ if( !p_sys->b_use_alsa )
+#endif
+ {
+ if( ioctl( p_sys->i_fd_audio, SNDCTL_DSP_GETISPACE, &buf_info ) == 0 )
+ {
+ i_correct += buf_info.bytes;
+ }
+ }
+#ifdef HAVE_ALSA
+ else
+ {
+ /* TODO: ALSA timing */
+ /* Very experimental code... */
+ int i_err;
+ snd_pcm_sframes_t delay = 0;
+ if( ( i_err = snd_pcm_delay( p_sys->p_alsa_pcm, &delay ) ) >= 0 )
+ {
+ int i_correction_delta = delay * p_sys->i_alsa_frame_size;
+ /* Test for overrun */
+ if( i_correction_delta>p_sys->i_audio_max_frame_size )
+ {
+ msg_Warn( p_demux, "ALSA read overrun" );
+ i_correction_delta = p_sys->i_audio_max_frame_size;
+ snd_pcm_prepare( p_sys->p_alsa_pcm );
+ }
+ i_correct += i_correction_delta;
+ }
+ else
+ {
+ /* delay failed so reset */
+ msg_Warn( p_demux, "ALSA snd_pcm_delay failed (%s)", snd_strerror( i_err ) );
+ snd_pcm_prepare( p_sys->p_alsa_pcm );
+ }
+ }
+#endif
+
+ /* Timestamp */
+ p_block->i_pts = p_block->i_dts =
+ mdate() - I64C(1000000) * (mtime_t)i_correct /
+ 2 / ( p_sys->b_stereo ? 2 : 1) / p_sys->i_sample_rate;
+
+ return p_block;
+}
+
+/*****************************************************************************
+ * Helper function to initalise video IO using the Read method
+ *****************************************************************************/
+static int InitRead( demux_t *p_demux, int i_fd, unsigned int i_buffer_size )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+
+ p_sys->p_buffers = calloc( 1, sizeof( *p_sys->p_buffers ) );
+ if( !p_sys->p_buffers )
+ {
+ msg_Err( p_demux, "Out of memory" );
+ goto open_failed;
+ }
+
+ p_sys->p_buffers[0].length = i_buffer_size;
+ p_sys->p_buffers[0].start = malloc( i_buffer_size );
+ if( !p_sys->p_buffers[0].start )
+ {
+ msg_Err( p_demux, "Out of memory" );
+ goto open_failed;
+ }
+
+ return VLC_SUCCESS;
+
+open_failed:
+ return VLC_EGENERIC;
+
+}
+
+/*****************************************************************************
+ * Helper function to initalise video IO using the mmap method
+ *****************************************************************************/
+static int InitMmap( demux_t *p_demux, int i_fd )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+ struct v4l2_requestbuffers req;
+
+ memset( &req, 0, sizeof(req) );
+ req.count = 4;
+ req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ req.memory = V4L2_MEMORY_MMAP;
+
+ if( ioctl( i_fd, VIDIOC_REQBUFS, &req ) < 0 )
+ {
+ msg_Err( p_demux, "device does not support mmap i/o" );
+ goto open_failed;
+ }
+
+ if( req.count < 2 )
+ {
+ msg_Err( p_demux, "Insufficient buffer memory" );
+ goto open_failed;
+ }
+
+ p_sys->p_buffers = calloc( req.count, sizeof( *p_sys->p_buffers ) );
+ if( !p_sys->p_buffers )
+ {
+ msg_Err( p_demux, "Out of memory" );
+ goto open_failed;
+ }
+
+ for( p_sys->i_nbuffers = 0; p_sys->i_nbuffers < req.count; ++p_sys->i_nbuffers )
+ {
+ struct v4l2_buffer buf;
+
+ memset( &buf, 0, sizeof(buf) );
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_MMAP;
+ buf.index = p_sys->i_nbuffers;
+
+ if( ioctl( i_fd, VIDIOC_QUERYBUF, &buf ) < 0 )
+ {
+ msg_Err( p_demux, "VIDIOC_QUERYBUF" );
+ goto open_failed;
+ }
+
+ p_sys->p_buffers[p_sys->i_nbuffers].length = buf.length;
+ p_sys->p_buffers[p_sys->i_nbuffers].start =
+ mmap( NULL, buf.length, PROT_READ | PROT_WRITE, MAP_SHARED, i_fd, buf.m.offset );
+
+ if( p_sys->p_buffers[p_sys->i_nbuffers].start == MAP_FAILED )
+ {
+ msg_Err( p_demux, "mmap failed (%m)" );
+ goto open_failed;
+ }
+ }
+
+ return VLC_SUCCESS;
+
+open_failed:
+ return VLC_EGENERIC;
+
+}
+
+/*****************************************************************************
+ * Helper function to initalise video IO using the userbuf method
+ *****************************************************************************/
+static int InitUserP( demux_t *p_demux, int i_fd, unsigned int i_buffer_size )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+ struct v4l2_requestbuffers req;
+ unsigned int i_page_size;
+
+ i_page_size = getpagesize();
+ i_buffer_size = ( i_buffer_size + i_page_size - 1 ) & ~( i_page_size - 1);
+
+ memset( &req, 0, sizeof(req) );
+ req.count = 4;
+ req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ req.memory = V4L2_MEMORY_USERPTR;
+
+ if( ioctl( i_fd, VIDIOC_REQBUFS, &req ) < 0 )
+ {
+ msg_Err( p_demux, "device does not support user pointer i/o" );
+ goto open_failed;
+ }
+
+ p_sys->p_buffers = calloc( 4, sizeof( *p_sys->p_buffers ) );
+ if( !p_sys->p_buffers )
+ {
+ msg_Err( p_demux, "Out of memory" );
+ goto open_failed;
+ }
+
+ for( p_sys->i_nbuffers = 0; p_sys->i_nbuffers < 4; ++p_sys->i_nbuffers )
+ {
+ p_sys->p_buffers[p_sys->i_nbuffers].length = i_buffer_size;
+ p_sys->p_buffers[p_sys->i_nbuffers].start =
+ vlc_memalign( &p_sys->p_buffers[p_sys->i_nbuffers].orig_userp,
+ /* boundary */ i_page_size, i_buffer_size );
+
+ if( !p_sys->p_buffers[p_sys->i_nbuffers].start )
+ {
+ msg_Err( p_demux, "out of memory" );
+ goto open_failed;
+ }
+ }
+
+ return VLC_SUCCESS;
+
+open_failed:
+ return VLC_EGENERIC;
+
+}
+
+/*****************************************************************************
+ * IsPixelFormatSupported: returns true if the specified V4L2 pixel format is
+ * in the array of supported formats returned by the driver
+ *****************************************************************************/
+vlc_bool_t IsPixelFormatSupported( demux_t *p_demux, unsigned int i_pixelformat )
+{
+ demux_sys_t *p_sys = p_demux->p_sys;
+
+ for( int i_index = 0; i_index < p_sys->i_codec; i_index++ )
+ {
+ if( p_sys->p_codecs[i_index].pixelformat == i_pixelformat ) return VLC_TRUE;
+ }
+
+ return VLC_FALSE;
+}
+
+/*****************************************************************************
+ * OpenVideoDev: open and set up the video device and probe for capabilities
+ *****************************************************************************/
+int OpenVideoDev( demux_t *p_demux, char *psz_device )
+{
+ int i_fd;
+ demux_sys_t *p_sys = p_demux->p_sys;
+ struct v4l2_cropcap cropcap;
+ struct v4l2_crop crop;
+ struct v4l2_format fmt;
+ unsigned int i_min;
+ enum v4l2_buf_type buf_type;
+ int i;
+
+ if( ( i_fd = open( psz_device, O_RDWR ) ) < 0 )
+ {
+ msg_Err( p_demux, "cannot open device (%m)" );
+ goto open_failed;
+ }
+
+ /* Select standard */
+
+ if( p_sys->i_selected_standard_id != V4L2_STD_UNKNOWN )
+ {
+ if( ioctl( i_fd, VIDIOC_S_STD, &p_sys->i_selected_standard_id ) < 0 )
+ {
+ msg_Err( p_demux, "cannot set standard (%m)" );
+ goto open_failed;
+ }
+ msg_Dbg( p_demux, "Set standard" );
+ }
+
+ /* Select input */
+
+ if( p_sys->i_selected_input > p_sys->i_input )
+ {
+ msg_Warn( p_demux, "invalid input. Using the default one" );
+ p_sys->i_selected_input = 0;
+ }
+
+ if( ioctl( i_fd, VIDIOC_S_INPUT, &p_sys->i_selected_input ) < 0 )
+ {
+ msg_Err( p_demux, "cannot set input (%m)" );
+ goto open_failed;
+ }
+
+ /* Verify device support for the various IO methods */
+ switch( p_sys->io )
+ {
+ case IO_METHOD_READ:
+ if( !(p_sys->dev_cap.capabilities & V4L2_CAP_READWRITE) )
+ {
+ msg_Err( p_demux, "device does not support read i/o" );
+ goto open_failed;
+ }
+ break;
+
+ case IO_METHOD_MMAP:
+ case IO_METHOD_USERPTR:
+ if( !(p_sys->dev_cap.capabilities & V4L2_CAP_STREAMING) )
+ {
+ msg_Err( p_demux, "device does not support streaming i/o" );
+ goto open_failed;
+ }
+ break;
+
+ default:
+ msg_Err( p_demux, "io method not supported" );
+ goto open_failed;
+ }
+
+ /* Reset Cropping */
+ memset( &cropcap, 0, sizeof(cropcap) );
+ cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ if( ioctl( i_fd, VIDIOC_CROPCAP, &cropcap ) >= 0 )
+ {
+ crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ crop.c = cropcap.defrect; /* reset to default */
+ if( ioctl( i_fd, VIDIOC_S_CROP, &crop ) < 0 )
+ {
+ switch( errno )
+ {
+ case EINVAL:
+ /* Cropping not supported. */
+ break;
+ default:
+ /* Errors ignored. */
+ break;
+ }
+ }
+ }
+
+ /* Try and find default resolution if not specified */
+ memset( &fmt, 0, sizeof(fmt) );
+ fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+
+ if( p_sys->i_width <= 0 || p_sys->i_height <= 0 )
+ {
+ if( ioctl( i_fd, VIDIOC_G_FMT, &fmt ) < 0 )
+ {
+ msg_Err( p_demux, "Cannot get default width and height." );
+ goto open_failed;
+ }
+
+ p_sys->i_width = fmt.fmt.pix.width;
+ p_sys->i_height = fmt.fmt.pix.height;
+
+ if( fmt.fmt.pix.field == V4L2_FIELD_ALTERNATE )
+ {
+ p_sys->i_height = p_sys->i_height * 2;
+ }
+ }
+ else
+ {
+ msg_Dbg( p_demux, "trying specified size %dx%d", p_sys->i_width, p_sys->i_height );
+ }
+
+ fmt.fmt.pix.width = p_sys->i_width;
+ fmt.fmt.pix.height = p_sys->i_height;
+ fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
+
+ /* Test and set Chroma */
+ fmt.fmt.pix.pixelformat = 0;
+ if( p_sys->psz_requested_chroma && strlen( p_sys->psz_requested_chroma ) > 0 )
+ {
+ /* User specified chroma */
+ if( strlen( p_sys->psz_requested_chroma ) >= 4 )
+ {
+ int i_requested_fourcc = VLC_FOURCC(
+ p_sys->psz_requested_chroma[0], p_sys->psz_requested_chroma[1],
+ p_sys->psz_requested_chroma[2], p_sys->psz_requested_chroma[3] );
+ for( int i = 0; v4l2chroma_to_fourcc[i].i_v4l2 != 0; i++ )
+ {
+ if( v4l2chroma_to_fourcc[i].i_fourcc == i_requested_fourcc )
+ {
+ fmt.fmt.pix.pixelformat = v4l2chroma_to_fourcc[i].i_v4l2;
+ break;
+ }
+ }
+ }
+ /* Try and set user chroma */
+ if( !IsPixelFormatSupported( p_demux, fmt.fmt.pix.pixelformat ) || ( fmt.fmt.pix.pixelformat && ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 ) )
+ {
+ msg_Warn( p_demux, "Driver is unable to use specified chroma %s. Trying defaults.", p_sys->psz_requested_chroma );
+ fmt.fmt.pix.pixelformat = 0;
+ }
+ }
+
+ /* If no user specified chroma, find best */
+ if( !fmt.fmt.pix.pixelformat )
+ {
+ fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YVU420;
+ if( !IsPixelFormatSupported( p_demux, fmt.fmt.pix.pixelformat ) || ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 )
+ {
+ fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUV422P;
+ if( !IsPixelFormatSupported( p_demux, fmt.fmt.pix.pixelformat ) || ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 )
+ {
+ fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
+ if( !IsPixelFormatSupported( p_demux, fmt.fmt.pix.pixelformat ) || ioctl( i_fd, VIDIOC_S_FMT, &fmt ) < 0 )
+ {
+ msg_Err( p_demux, "Could not select any of the default chromas!" );
+ goto open_failed;
+ }
+ }
+ }
+ }
+
+ /* Reassign width, height and chroma incase driver override */
+ p_sys->i_width = fmt.fmt.pix.width;
+ p_sys->i_height = fmt.fmt.pix.height;
+
+ /* Look up final fourcc */
+ p_sys->i_fourcc = 0;
+ for( int i = 0; v4l2chroma_to_fourcc[i].i_fourcc != 0; i++ )
+ {
+ if( v4l2chroma_to_fourcc[i].i_v4l2 == fmt.fmt.pix.pixelformat )
+ {
+ p_sys->i_fourcc = v4l2chroma_to_fourcc[i].i_fourcc;
+ break;
+ }
+ }
+
+ /* Buggy driver paranoia */
+ i_min = fmt.fmt.pix.width * 2;
+ if( fmt.fmt.pix.bytesperline < i_min )
+ fmt.fmt.pix.bytesperline = i_min;
+ i_min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height;
+ if( fmt.fmt.pix.sizeimage < i_min )
+ fmt.fmt.pix.sizeimage = i_min;
+
+#ifdef VIDIOC_ENUM_FRAMEINTERVALS
+ /* This is new in Linux 2.6.19 */
+ /* List supported frame rates */
+ struct v4l2_frmivalenum frmival;
+ frmival.index = 0;
+ frmival.pixel_format = fmt.fmt.pix.pixelformat;
+ frmival.width = p_sys->i_width;
+ frmival.height = p_sys->i_height;
+ if( ioctl( i_fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival ) >= 0 )
+ {
+ char sz_fourcc[5];
+ memset( &sz_fourcc, 0, sizeof( sz_fourcc ) );
+ vlc_fourcc_to_char( p_sys->i_fourcc, &sz_fourcc );
+ msg_Dbg( p_demux, "supported frame intervals for %4s, %dx%d:",
+ sz_fourcc, frmival.width, frmival.height );
+ switch( frmival.type )
+ {
+ case V4L2_FRMIVAL_TYPE_DISCRETE:
+ do
+ {
+ msg_Dbg( p_demux, " supported frame interval: %d/%d",
+ frmival.discrete.numerator,
+ frmival.discrete.denominator );
+ frmival.index++;
+ } while( ioctl( i_fd, VIDIOC_ENUM_FRAMEINTERVALS, &frmival ) >= 0 );
+ break;
+ case V4L2_FRMIVAL_TYPE_STEPWISE:
+ msg_Dbg( p_demux, " supported frame intervals: %d/%d to "
+ "%d/%d using %d/%d increments",
+ frmival.stepwise.min.numerator,
+ frmival.stepwise.min.denominator,
+ frmival.stepwise.max.numerator,
+ frmival.stepwise.max.denominator,
+ frmival.stepwise.step.numerator,
+ frmival.stepwise.step.denominator );
+ break;
+ case V4L2_FRMIVAL_TYPE_CONTINUOUS:
+ msg_Dbg( p_demux, " supported frame intervals: %d/%d to %d/%d",
+ frmival.stepwise.min.numerator,
+ frmival.stepwise.min.denominator,
+ frmival.stepwise.max.numerator,
+ frmival.stepwise.max.denominator );
+ break;
+ }
+ }
+#endif
+
+ VideoControlList( p_demux, i_fd,
+ var_GetBool( p_demux, "v4l2-control-reset" ) );
+
+ /* Init IO method */
+ switch( p_sys->io )
+ {
+ case IO_METHOD_READ:
+ if( InitRead( p_demux, i_fd, fmt.fmt.pix.sizeimage ) != VLC_SUCCESS ) goto open_failed;
+ break;
+
+ case IO_METHOD_MMAP:
+ if( InitMmap( p_demux, i_fd ) != VLC_SUCCESS ) goto open_failed;
+ break;
+
+ case IO_METHOD_USERPTR:
+ if( InitUserP( p_demux, i_fd, fmt.fmt.pix.sizeimage ) != VLC_SUCCESS ) goto open_failed;
+ break;
+
+ }
+
+ /* Add */
+ es_format_t es_fmt;
+ es_format_Init( &es_fmt, VIDEO_ES, p_sys->i_fourcc );
+ es_fmt.video.i_width = p_sys->i_width;
+ es_fmt.video.i_height = p_sys->i_height;
+ es_fmt.video.i_aspect = 4 * VOUT_ASPECT_FACTOR / 3;
+
+ /* Setup rgb mask for RGB formats */
+ if( p_sys->i_fourcc == VLC_FOURCC( 'R','V','2','4' ) )
+ {
+ /* This is in BGR format */
+ es_fmt.video.i_bmask = 0x00ff0000;
+ es_fmt.video.i_gmask = 0x0000ff00;
+ es_fmt.video.i_rmask = 0x000000ff;
+ }
+
+ msg_Dbg( p_demux, "added new video es %4.4s %dx%d",
+ (char*)&es_fmt.i_codec, es_fmt.video.i_width, es_fmt.video.i_height );
+ p_sys->p_es_video = es_out_Add( p_demux->out, &es_fmt );
+
+ /* Start Capture */
+
+ switch( p_sys->io )
+ {
+ case IO_METHOD_READ:
+ /* Nothing to do */
+ break;
+
+ case IO_METHOD_MMAP:
+ for (unsigned int i = 0; i < p_sys->i_nbuffers; ++i)
+ {
+ struct v4l2_buffer buf;
+
+ memset( &buf, 0, sizeof(buf) );
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_MMAP;
+ buf.index = i;
+
+ if( ioctl( i_fd, VIDIOC_QBUF, &buf ) < 0 )
+ {
+ msg_Err( p_demux, "VIDIOC_QBUF failed" );
+ goto open_failed;
+ }
+ }
+
+ buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ if( ioctl( i_fd, VIDIOC_STREAMON, &buf_type ) < 0 )
+ {
+ msg_Err( p_demux, "VIDIOC_STREAMON failed" );
+ goto open_failed;
+ }
+
+ break;
+
+ case IO_METHOD_USERPTR:
+ for( unsigned int i = 0; i < p_sys->i_nbuffers; ++i )
+ {
+ struct v4l2_buffer buf;
+
+ memset( &buf, 0, sizeof(buf) );
+ buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ buf.memory = V4L2_MEMORY_USERPTR;
+ buf.index = i;
+ buf.m.userptr = (unsigned long)p_sys->p_buffers[i].start;
+ buf.length = p_sys->p_buffers[i].length;
+
+ if( ioctl( i_fd, VIDIOC_QBUF, &buf ) < 0 )
+ {
+ msg_Err( p_demux, "VIDIOC_QBUF failed" );
+ goto open_failed;
+ }
+ }