X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faccess%2Fv4l%2Fv4l.c;h=de0cb79206f9c5c23e460a471cd46936662cddd2;hb=08be895ad56325bb18277bcc55a658e9d6cd04bf;hp=c9e781bf4dfa1aee87ef44106acff4ef28f21e6a;hpb=4363f75abf93c34cb68f83ad93370bf2df5ba51e;p=vlc diff --git a/modules/access/v4l/v4l.c b/modules/access/v4l/v4l.c index c9e781bf4d..de0cb79206 100644 --- a/modules/access/v4l/v4l.c +++ b/modules/access/v4l/v4l.c @@ -1,11 +1,12 @@ /***************************************************************************** * v4l.c : Video4Linux input module for vlc ***************************************************************************** - * Copyright (C) 2002 VideoLAN - * $Id: v4l.c,v 1.27 2003/10/25 20:19:19 fenrir Exp $ + * Copyright (C) 2002-2004 VideoLAN + * $Id$ * * Author: Laurent Aimar * Paul Forgey + * Gildas Bazin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,53 +41,94 @@ #include #include #include - #include + +/* 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 + * ourselves. In all their intelligence, these people decided to fix + * this in the next version (video4linux2) in such a cool way that it + * breaks all compilations of old stuff... + * The real problem is actually that linux/time.h doesn't use proper + * macro checks before defining types like struct timeval. The proper + * fix here is to either fuck the kernel header (which is what we do + * by defining _LINUX_TIME_H, an innocent little hack) or by fixing it + * upstream, which I'll consider doing later on. If you get compiler + * errors here, check your linux/time.h && sys/time.h header setup. +*/ +#define _LINUX_TIME_H + #include #include "videodev_mjpeg.h" #include /***************************************************************************** - * Local prototypes + * Module descriptior *****************************************************************************/ -static int AccessOpen ( vlc_object_t * ); -static void AccessClose ( vlc_object_t * ); -static int Read ( input_thread_t *, byte_t *, size_t ); +static int AccessOpen ( vlc_object_t * ); +static void AccessClose( vlc_object_t * ); static int DemuxOpen ( vlc_object_t * ); static void DemuxClose ( vlc_object_t * ); -static int Demux ( input_thread_t * ); - -/***************************************************************************** - * Module descriptior - *****************************************************************************/ #define CACHING_TEXT N_("Caching value in ms") #define CACHING_LONGTEXT N_( \ "Allows you to modify the default caching value for v4l streams. This " \ - "value should be set in miliseconds units." ) + "value should be set in millisecond units." ) +#define VDEV_TEXT N_("Video device name") +#define VDEV_LONGTEXT N_( \ + "Specify the name of the video device that will be used. " \ + "If you don't specify anything, no video device will be used.") +#define ADEV_TEXT N_("Audio device name") +#define ADEV_LONGTEXT N_( \ + "Specify the name of the audio device that will be used. " \ + "If you don't specify anything, no audio device will be used.") +#define CHROMA_TEXT N_("Video input chroma format") +#define CHROMA_LONGTEXT N_( \ + "Force the Video4Linux video device to use a specific chroma format " \ + "(eg. I420 (default), RV24, etc.)") vlc_module_begin(); + set_shortname( _("Video4Linux") ); set_description( _("Video4Linux input") ); - add_category_hint( N_("v4l"), NULL, VLC_TRUE ); + add_integer( "v4l-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE ); + add_string( "v4l-vdev", "/dev/video", 0, VDEV_TEXT, VDEV_LONGTEXT, + VLC_FALSE ); + add_string( "v4l-adev", "/dev/dsp", 0, ADEV_TEXT, ADEV_LONGTEXT, + VLC_FALSE ); + add_string( "v4l-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT, + VLC_TRUE ); + add_shortcut( "v4l" ); - set_capability( "access", 10 ); + set_capability( "access2", 10 ); set_callbacks( AccessOpen, AccessClose ); add_submodule(); set_description( _("Video4Linux demuxer") ); add_shortcut( "v4l" ); - set_capability( "demux", 200 ); + set_capability( "demux2", 20 ); set_callbacks( DemuxOpen, DemuxClose ); vlc_module_end(); -/**************************************************************************** - * I. Access Part - ****************************************************************************/ +/***************************************************************************** + * Access: local prototypes + *****************************************************************************/ +static int AccessRead ( access_t *, uint8_t *, int ); +static int AccessControl( access_t *, int, va_list ); + + +static void ParseMRL ( access_t * ); +static int OpenVideoDev( access_t *, char * ); +static int OpenAudioDev( access_t *, char * ); + +static int GrabAudio( access_t *, uint8_t **, int *, mtime_t * ); +static int GrabVideo( access_t *, uint8_t **, int *, mtime_t * ); + + #define MJPEG_BUFFER_SIZE (256*1024) struct quicktime_mjpeg_app1 @@ -103,12 +145,44 @@ struct quicktime_mjpeg_app1 uint32_t i_data_offset; /* following SOS marker data */ }; +static struct +{ + int i_v4l; + int i_fourcc; + +} v4lchroma_to_fourcc[] = +{ + { VIDEO_PALETTE_GREY, VLC_FOURCC( 'G', 'R', 'E', 'Y' ) }, + { VIDEO_PALETTE_HI240, VLC_FOURCC( 'I', '2', '4', '0' ) }, + { VIDEO_PALETTE_RGB565, VLC_FOURCC( 'R', 'V', '1', '6' ) }, + { VIDEO_PALETTE_RGB555, VLC_FOURCC( 'R', 'V', '1', '5' ) }, + { VIDEO_PALETTE_RGB24, VLC_FOURCC( 'R', 'V', '2', '4' ) }, + { VIDEO_PALETTE_RGB32, VLC_FOURCC( 'R', 'V', '3', '2' ) }, + { VIDEO_PALETTE_YUV422, VLC_FOURCC( 'I', '4', '2', '2' ) }, + { VIDEO_PALETTE_YUYV, VLC_FOURCC( 'Y', 'U', 'Y', 'V' ) }, + { VIDEO_PALETTE_UYVY, VLC_FOURCC( 'U', 'Y', 'V', 'Y' ) }, + { VIDEO_PALETTE_YUV420, VLC_FOURCC( 'I', '4', '2', 'N' ) }, + { VIDEO_PALETTE_YUV411, VLC_FOURCC( 'I', '4', '1', 'N' ) }, + { VIDEO_PALETTE_RAW, VLC_FOURCC( 'G', 'R', 'A', 'W' ) }, + { VIDEO_PALETTE_YUV422P, VLC_FOURCC( 'I', '4', '2', '2' ) }, + { VIDEO_PALETTE_YUV420P, VLC_FOURCC( 'I', '4', '2', '0' ) }, + { VIDEO_PALETTE_YUV411P, VLC_FOURCC( 'I', '4', '1', '1' ) }, + { 0, 0 } +}; + struct access_sys_t { - char *psz_video_device; - int fd; + /* Devices */ + char *psz_device; /* Main device from MRL, can be video or audio */ + + char *psz_vdev; + int fd_video; - picture_t pic; + char *psz_adev; + int fd_audio; + + /* Video properties */ + picture_t pic; int i_fourcc; int i_channel; @@ -119,6 +193,11 @@ struct access_sys_t int i_width; int i_height; + int i_brightness; + int i_hue; + int i_colour; + int i_contrast; + float f_fps; /* <= 0.0 mean to grab at full rate */ mtime_t i_video_pts; /* only used when f_fps > 0 */ @@ -140,8 +219,7 @@ struct access_sys_t int i_video_frame_size; int i_video_frame_size_allocated; - char *psz_adev; - int fd_audio; + /* Audio properties */ vlc_fourcc_t i_acodec_raw; int i_sample_rate; vlc_bool_t b_stereo; @@ -151,6 +229,7 @@ struct access_sys_t int i_audio_frame_size_allocated; /* header */ + int i_streams; int i_header_size; int i_header_pos; uint8_t *p_header; // at lest 8 bytes allocated @@ -159,7 +238,6 @@ struct access_sys_t int i_data_size; int i_data_pos; uint8_t *p_data; // never allocated - }; /* @@ -183,7 +261,7 @@ struct access_sys_t * u8 data */ -static void SetDWBE( uint8_t *p, uint32_t dw ) +static void SetDWBE( uint8_t *p, uint32_t dw ) { p[0] = (dw >> 24)&0xff; p[1] = (dw >> 16)&0xff; @@ -191,14 +269,14 @@ static void SetDWBE( uint8_t *p, uint32_t dw ) p[3] = (dw )&0xff; } -static void SetQWBE( uint8_t *p, uint64_t qw ) +static void SetQWBE( uint8_t *p, uint64_t qw ) { SetDWBE( p, (qw >> 32)&0xffffffff ); SetDWBE( &p[4], qw&0xffffffff); } /***************************************************************************** - * Open: open device: + * AccessOpen: opens v4l device ***************************************************************************** * * url: