#include <vlc_demux.h>
#include <vlc_access.h>
#include <vlc_vout.h>
-#include <vlc_codecs.h>
-#include <sys/types.h>
-#include <sys/stat.h>
#include <sys/ioctl.h>
-#include <unistd.h>
#include <sys/mman.h>
-#include <errno.h>
#include <fcntl.h>
#include <arpa/inet.h>
+#include <poll.h>
+
/* From GStreamer's v4l plugin:
* Because of some really cool feature in video4linux1, also known as
* 'not including sys/types.h and sys/time.h', we had to include it
#define AUDIO_DEPRECATED_ERROR N_( \
"Alsa or OSS audio capture in the v4l access is deprecated. " \
- "please use 'v4l:/""/ --input-slave alsa:/""/' or " \
- "'v4l:/""/ --input-slave oss:/""/' instead." )
+ "please use 'v4l:/""/ :input-slave=alsa:/""/' or " \
+ "'v4l:/""/ :input-slave=oss:/""/' instead." )
static const int i_norm_list[] =
{ VIDEO_MODE_AUTO, VIDEO_MODE_SECAM, VIDEO_MODE_PAL, VIDEO_MODE_NTSC };
set_subcategory( SUBCAT_INPUT_ACCESS )
add_integer( "v4l-caching", DEFAULT_PTS_DELAY / 1000, NULL,
- CACHING_TEXT, CACHING_LONGTEXT, true );
+ CACHING_TEXT, CACHING_LONGTEXT, true )
add_obsolete_string( "v4l-vdev" );
add_obsolete_string( "v4l-adev" );
add_string( "v4l-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT,
- true );
+ true )
add_float( "v4l-fps", -1.0, NULL, FPS_TEXT, FPS_LONGTEXT, true )
add_obsolete_integer( "v4l-samplerate" );
add_integer( "v4l-channel", 0, NULL, CHANNEL_TEXT, CHANNEL_LONGTEXT,
- true );
+ true )
add_integer( "v4l-tuner", -1, NULL, TUNER_TEXT, TUNER_LONGTEXT, true )
add_integer( "v4l-norm", VIDEO_MODE_AUTO, NULL, NORM_TEXT, NORM_LONGTEXT,
- false );
+ false )
change_integer_list( i_norm_list, psz_norm_list_text, NULL );
add_integer( "v4l-frequency", -1, NULL, FREQUENCY_TEXT, FREQUENCY_LONGTEXT,
- false );
+ false )
add_integer( "v4l-audio", -1, NULL, AUDIO_TEXT, AUDIO_LONGTEXT, true )
add_obsolete_bool( "v4l-stereo" );
add_integer( "v4l-width", 0, NULL, WIDTH_TEXT, WIDTH_LONGTEXT, true )
add_integer( "v4l-height", 0, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT,
- true );
+ true )
add_integer( "v4l-brightness", -1, NULL, BRIGHTNESS_TEXT,
- BRIGHTNESS_LONGTEXT, true );
+ BRIGHTNESS_LONGTEXT, true )
add_integer( "v4l-colour", -1, NULL, COLOUR_TEXT, COLOUR_LONGTEXT,
- true );
+ true )
add_integer( "v4l-hue", -1, NULL, HUE_TEXT, HUE_LONGTEXT, true )
add_integer( "v4l-contrast", -1, NULL, CONTRAST_TEXT, CONTRAST_LONGTEXT,
- true );
+ true )
add_bool( "v4l-mjpeg", false, NULL, MJPEG_TEXT, MJPEG_LONGTEXT,
- true );
+ true )
add_integer( "v4l-decimation", 1, NULL, DECIMATION_TEXT,
- DECIMATION_LONGTEXT, true );
+ DECIMATION_LONGTEXT, true )
add_integer( "v4l-quality", 100, NULL, QUALITY_TEXT, QUALITY_LONGTEXT,
- true );
+ true )
add_shortcut( "v4l" )
set_capability( "access_demux", 10 )
{
/* Devices */
char *psz_device; /* Main device from MRL */
- int fd_video;
+ int i_fd;
/* Video properties */
picture_t pic;
p_sys->i_quality = val.i_int;
p_sys->psz_device = NULL;
- p_sys->fd_video = -1;
+ p_sys->i_fd = -1;
p_sys->p_es = NULL;
ParseMRL( p_demux );
msg_Dbg( p_this, "opening device '%s'", p_sys->psz_device );
- p_sys->fd_video = OpenVideoDev( p_demux, p_sys->psz_device );
- if( p_sys->fd_video < 0 )
+ p_sys->i_fd = OpenVideoDev( p_demux, p_sys->psz_device );
+ if( p_sys->i_fd < 0 )
{
Close( p_this );
return VLC_EGENERIC;
demux_sys_t *p_sys = p_demux->p_sys;
free( p_sys->psz_device );
- if( p_sys->fd_video >= 0 ) close( p_sys->fd_video );
+ if( p_sys->i_fd >= 0 ) close( p_sys->i_fd );
if( p_sys->b_mjpeg )
{
int i_noframe = -1;
- ioctl( p_sys->fd_video, MJPIOC_QBUF_CAPT, &i_noframe );
+ ioctl( p_sys->i_fd, MJPIOC_QBUF_CAPT, &i_noframe );
}
if( p_sys->p_video_mmap && p_sys->p_video_mmap != MAP_FAILED )
static int Demux( demux_t *p_demux )
{
demux_sys_t *p_sys = p_demux->p_sys;
- block_t *p_block = GrabVideo( p_demux );
- if( !p_block )
+ struct pollfd fd;
+ fd.fd = p_sys->i_fd;
+ fd.events = POLLIN|POLLPRI;
+ fd.revents = 0;
+
+ /* Wait for data */
+ if( poll( &fd, 1, 500 ) )
{
- /* Sleep so we do not consume all the cpu, 10ms seems
- * like a good value (100fps) */
- msleep( 10000 );
- return 1;
+ if( fd.revents & (POLLIN|POLLPRI) )
+ {
+ block_t *p_block = GrabVideo( p_demux );
+ if( p_block )
+ {
+ es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
+ es_out_Send( p_demux->out, p_sys->p_es, p_block );
+ }
+ }
}
- es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
- es_out_Send( p_demux->out, p_sys->p_es, p_block );
-
return 1;
}
p_sys->vid_mmap.frame = (p_sys->i_frame_pos + 1) % p_sys->vid_mbuf.frames;
- while( ioctl( p_sys->fd_video, VIDIOCMCAPTURE, &p_sys->vid_mmap ) < 0 )
+ while( ioctl( p_sys->i_fd, VIDIOCMCAPTURE, &p_sys->vid_mmap ) < 0 )
{
if( errno != EAGAIN )
{
msg_Dbg( p_demux, "grab failed, trying again" );
}
- while( ioctl(p_sys->fd_video, VIDIOCSYNC, &p_sys->i_frame_pos) < 0 )
+ while( ioctl(p_sys->i_fd, VIDIOCSYNC, &p_sys->i_frame_pos) < 0 )
{
if( errno != EAGAIN && errno != EINTR )
{
/* re-queue the last frame we sync'd */
if( p_sys->i_frame_pos != -1 )
{
- while( ioctl( p_sys->fd_video, MJPIOC_QBUF_CAPT,
+ while( ioctl( p_sys->i_fd, MJPIOC_QBUF_CAPT,
&p_sys->i_frame_pos ) < 0 )
{
if( errno != EAGAIN && errno != EINTR )
}
/* sync on the next frame */
- while( ioctl( p_sys->fd_video, MJPIOC_SYNC, &sync ) < 0 )
+ while( ioctl( p_sys->i_fd, MJPIOC_SYNC, &sync ) < 0 )
{
if( errno != EAGAIN && errno != EINTR )
{