- frmival.stepwise.max.denominator );
- break;
- }
- }
-#endif
-
- ControlList( p_demux, i_fd,
- var_GetBool( p_demux, "v4l2-controls-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;
- }
- }
-
- 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;
- }
-
- /* report fps */
- if( p_sys->f_fps >= 0.1 )
- {
- msg_Dbg( p_demux, "User set fps=%f", p_sys->f_fps );
- }
-
- return i_fd;
-
-open_failed:
- if( i_fd >= 0 ) close( i_fd );
- return -1;
-
-}
-
-#ifdef HAVE_ALSA
-/*****************************************************************************
- * ResolveALSADeviceName: Change any . to : in the ALSA device name
- *****************************************************************************/
-char* ResolveALSADeviceName( char *psz_device )
-{
- char* psz_alsa_name = strdup( psz_device );
- for( unsigned int i = 0; i < strlen( psz_device ); i++ )
- {
- if( psz_alsa_name[i] == '.' ) psz_alsa_name[i] = ':';
- }
- return psz_alsa_name;
-}
-#endif
-
-/*****************************************************************************
- * OpenAudioDev: open and set up the audio device and probe for capabilities
- *****************************************************************************/
-int OpenAudioDev( demux_t *p_demux, char *psz_device )
-{
- demux_sys_t *p_sys = p_demux->p_sys;
- int i_fd = 0;
- int i_format;
-#ifdef HAVE_ALSA
- p_sys->p_alsa_pcm = NULL;
- char* psz_alsa_device_name = ResolveALSADeviceName( psz_device );
- snd_pcm_hw_params_t *p_hw_params = NULL;
- snd_pcm_uframes_t buffer_size;
- snd_pcm_uframes_t chunk_size;
-#endif
-
-#ifdef HAVE_ALSA
- if( p_sys->b_use_alsa )
- {
- /* ALSA */
-
- int i_err;
-
- if( ( i_err = snd_pcm_open( &p_sys->p_alsa_pcm, psz_alsa_device_name,
- SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK ) ) < 0)
- {
- msg_Err( p_demux, "Cannot open ALSA audio device %s (%s)",
- psz_alsa_device_name,
- snd_strerror( i_err ) );
- goto adev_fail;
- }
-
- if( ( i_err = snd_pcm_nonblock( p_sys->p_alsa_pcm, 1 ) ) < 0)
- {
- msg_Err( p_demux, "Cannot set ALSA nonblock (%s)",
- snd_strerror( i_err ) );
- goto adev_fail;
- }
-
- /* Begin setting hardware parameters */
-
- if( ( i_err = snd_pcm_hw_params_malloc( &p_hw_params ) ) < 0 )
- {
- msg_Err( p_demux, "ALSA: cannot allocate hardware parameter structure (%s)",
- snd_strerror( i_err ) );
- goto adev_fail;
- }
-
- if( ( i_err = snd_pcm_hw_params_any( p_sys->p_alsa_pcm, p_hw_params ) ) < 0 )
- {
- msg_Err( p_demux, "ALSA: cannot initialize hardware parameter structure (%s)",
- snd_strerror( i_err ) );
- goto adev_fail;
- }
-
- /* Set Interleaved access */
- if( ( i_err = snd_pcm_hw_params_set_access( p_sys->p_alsa_pcm, p_hw_params, SND_PCM_ACCESS_RW_INTERLEAVED ) ) < 0 )
- {
- msg_Err( p_demux, "ALSA: cannot set access type (%s)",
- snd_strerror( i_err ) );
- goto adev_fail;
- }
-
- /* Set 16 bit little endian */
- if( ( i_err = snd_pcm_hw_params_set_format( p_sys->p_alsa_pcm, p_hw_params, SND_PCM_FORMAT_S16_LE ) ) < 0 )
- {
- msg_Err( p_demux, "ALSA: cannot set sample format (%s)",
- snd_strerror( i_err ) );
- goto adev_fail;
- }
-
- /* Set sample rate */
-#ifdef HAVE_ALSA_NEW_API
- i_err = snd_pcm_hw_params_set_rate_near( p_sys->p_alsa_pcm, p_hw_params, &p_sys->i_sample_rate, NULL );
-#else
- i_err = snd_pcm_hw_params_set_rate_near( p_sys->p_alsa_pcm, p_hw_params, p_sys->i_sample_rate, NULL );
-#endif
- if( i_err < 0 )
- {
- msg_Err( p_demux, "ALSA: cannot set sample rate (%s)",
- snd_strerror( i_err ) );
- goto adev_fail;
- }
-
- /* Set channels */
- unsigned int channels = p_sys->b_stereo ? 2 : 1;
- if( ( i_err = snd_pcm_hw_params_set_channels( p_sys->p_alsa_pcm, p_hw_params, channels ) ) < 0 )
- {
- channels = ( channels==1 ) ? 2 : 1;
- msg_Warn( p_demux, "ALSA: cannot set channel count (%s). Trying with channels=%d",
- snd_strerror( i_err ),
- channels );
- if( ( i_err = snd_pcm_hw_params_set_channels( p_sys->p_alsa_pcm, p_hw_params, channels ) ) < 0 )
- {
- msg_Err( p_demux, "ALSA: cannot set channel count (%s)",
- snd_strerror( i_err ) );
- goto adev_fail;
- }
- p_sys->b_stereo = ( channels == 2 );
- }
-
- /* Set metrics for buffer calculations later */
- unsigned int buffer_time;
- if( ( i_err = snd_pcm_hw_params_get_buffer_time_max(p_hw_params, &buffer_time, 0) ) < 0 )
- {
- msg_Err( p_demux, "ALSA: cannot get buffer time max (%s)",
- snd_strerror( i_err ) );
- goto adev_fail;
- }
- if (buffer_time > 500000) buffer_time = 500000;
-
- /* Set period time */
- unsigned int period_time = buffer_time / 4;
-#ifdef HAVE_ALSA_NEW_API
- i_err = snd_pcm_hw_params_set_period_time_near( p_sys->p_alsa_pcm, p_hw_params, &period_time, 0 );
-#else
- i_err = snd_pcm_hw_params_set_period_time_near( p_sys->p_alsa_pcm, p_hw_params, period_time, 0 );
-#endif
- if( i_err < 0 )
- {
- msg_Err( p_demux, "ALSA: cannot set period time (%s)",
- snd_strerror( i_err ) );
- goto adev_fail;