X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faccess%2Fdc1394.c;h=8ab82de5d318d8495f86b723c74c23d3f75013da;hb=19263ccaa05ee9fee50d13671e1c6e5dff1fdca4;hp=75a1146719c1ad6d3f09abb01e286888bbfeac20;hpb=577ce5a67c51c812f7ad97bf3e7f7f38913b72d3;p=vlc diff --git a/modules/access/dc1394.c b/modules/access/dc1394.c index 75a1146719..8ab82de5d3 100644 --- a/modules/access/dc1394.c +++ b/modules/access/dc1394.c @@ -36,7 +36,7 @@ #include #include #include -#include +#include #include #ifdef HAVE_FCNTL_H @@ -62,15 +62,15 @@ *****************************************************************************/ static int Open ( vlc_object_t * ); static void Close( vlc_object_t * ); -static void OpenAudioDev( demux_t *p_demux ); +static int OpenAudioDev( demux_t *p_demux ); static inline void CloseAudioDev( demux_t *p_demux ); -vlc_module_begin () +vlc_module_begin() set_description( N_("dc1394 input") ) set_capability( "access_demux", 10 ) add_shortcut( "dc1394" ) set_callbacks( Open, Close ) -vlc_module_end () +vlc_module_end() struct demux_sys_t { @@ -104,9 +104,6 @@ struct demux_sys_t int i_audio_max_frame_size; int fd_audio; char *audio_device; -#define NO_ROTATION 0 -#define ROTATION_LEFT 1 -#define ROTATION_RIGHT 2 es_out_id_t *p_es_audio; }; @@ -125,27 +122,20 @@ static int process_options( demux_t *p_demux); static int FindCamera( demux_sys_t *sys, demux_t *p_demux ) { dc1394camera_list_t *list; + int i_ret = VLC_EGENERIC; msg_Dbg( p_demux, "Scanning for ieee1394 ports ..." ); if( dc1394_camera_enumerate (sys->p_dccontext, &list) != DC1394_SUCCESS ) { msg_Err(p_demux, "Can not ennumerate cameras"); - dc1394_camera_free_list (list); - dc1394_free( sys->p_dccontext ); - free( sys ); - p_demux->p_sys = NULL; - return VLC_EGENERIC; + goto end; } if( list->num == 0 ) { msg_Err(p_demux, "Can not find cameras"); - dc1394_camera_free_list (list); - dc1394_free( sys->p_dccontext ); - free( sys ); - p_demux->p_sys = NULL; - return VLC_EGENERIC; + goto end; } sys->num_cameras = list->num; @@ -166,24 +156,16 @@ static int FindCamera( demux_sys_t *sys, demux_t *p_demux ) } if( !found ) { - msg_Err( p_demux, "Can't find camera with uid : 0x%llx.", + msg_Err( p_demux, "Can't find camera with uid : 0x%"PRIx64".", sys->selected_uid ); - dc1394_camera_free_list (list); - dc1394_free( sys->p_dccontext ); - free( sys ); - p_demux->p_sys = NULL; - return VLC_EGENERIC; + goto end; } } else if( sys->selected_camera >= (int)list->num ) { msg_Err( p_demux, "There are not this many cameras. (%d/%d)", sys->selected_camera, sys->num_cameras ); - dc1394_camera_free_list (list); - dc1394_free( sys->p_dccontext ); - free( sys ); - p_demux->p_sys = NULL; - return VLC_EGENERIC; + goto end; } else if( sys->selected_camera >= 0 ) { @@ -196,8 +178,11 @@ static int FindCamera( demux_sys_t *sys, demux_t *p_demux ) list->ids[0].guid); } + i_ret = VLC_SUCCESS; + +end: dc1394_camera_free_list (list); - return VLC_SUCCESS; + return i_ret; } /***************************************************************************** @@ -247,9 +232,8 @@ static int Open( vlc_object_t *p_this ) { msg_Err( p_demux, "Bad MRL, please check the option line " "(MRL was: %s)", - p_demux->psz_path ); + p_demux->psz_location ); free( p_sys ); - p_demux->p_sys = NULL; return VLC_EGENERIC; } @@ -257,20 +241,22 @@ static int Open( vlc_object_t *p_this ) if( !p_sys->p_dccontext ) { msg_Err( p_demux, "Failed to initialise libdc1394"); - free(p_demux->p_sys); - p_demux->p_sys = NULL; + free( p_sys ); return VLC_EGENERIC; } if( FindCamera( p_sys, p_demux ) != VLC_SUCCESS ) + { + dc1394_free( p_sys->p_dccontext ); + free( p_sys ); return VLC_EGENERIC; + } if( !p_sys->camera ) { msg_Err( p_demux, "No camera found !!" ); dc1394_free( p_sys->p_dccontext ); free( p_sys ); - p_demux->p_sys = NULL; return VLC_EGENERIC; } @@ -332,7 +318,8 @@ static int Open( vlc_object_t *p_this ) msg_Err( p_demux, "Unable to set initial focus to %u", p_sys->focus ); } - msg_Dbg( p_demux, "Initial focus set to %u", p_sys->focus ); + else + msg_Dbg( p_demux, "Initial focus set to %u", p_sys->focus ); } if( dc1394_feature_set_value( p_sys->camera, @@ -342,7 +329,8 @@ static int Open( vlc_object_t *p_this ) msg_Err( p_demux, "Unable to set initial brightness to %u", p_sys->brightness ); } - msg_Dbg( p_demux, "Initial brightness set to %u", p_sys->brightness ); + else + msg_Dbg( p_demux, "Initial brightness set to %u", p_sys->brightness ); if( dc1394_video_set_framerate( p_sys->camera, p_sys->frame_rate ) != DC1394_SUCCESS ) @@ -394,8 +382,7 @@ static int Open( vlc_object_t *p_this ) i_height = p_sys->height; if( picture_Setup( &p_sys->pic, VLC_CODEC_UYVY, - i_width, i_height, - i_width * VOUT_ASPECT_FACTOR / i_height ) ) + i_width, i_height, 1, 1 ) ) { msg_Err( p_demux ,"unknown chroma" ); Close( p_this ); @@ -414,8 +401,7 @@ static int Open( vlc_object_t *p_this ) if( p_sys->audio_device ) { - OpenAudioDev( p_demux ); - if( p_sys->fd_audio >= 0 ) + if( OpenAudioDev( p_demux ) == VLC_SUCCESS ) { es_format_t fmt; es_format_Init( &fmt, AUDIO_ES, VLC_CODEC_S16L ); /* FIXME: hmm, ?? */ @@ -449,18 +435,18 @@ static int Open( vlc_object_t *p_this ) return VLC_SUCCESS; } -static void OpenAudioDev( demux_t *p_demux ) +static int OpenAudioDev( demux_t *p_demux ) { demux_sys_t *p_sys = p_demux->p_sys; char *psz_device = p_sys->audio_device; int i_format = AFMT_S16_LE; int result; - p_sys->fd_audio = utf8_open( psz_device, O_RDONLY | O_NONBLOCK ); + p_sys->fd_audio = vlc_open( psz_device, O_RDONLY | O_NONBLOCK ); if( p_sys->fd_audio < 0 ) { msg_Err( p_demux, "Cannot open audio device (%s)", psz_device ); - CloseAudioDev( p_demux ); + return VLC_EGENERIC; } if( !p_sys->i_sample_rate ) @@ -471,7 +457,7 @@ static void OpenAudioDev( demux_t *p_demux ) { msg_Err( p_demux, "Cannot set audio format (16b little endian) " "(%d)", i_format ); - CloseAudioDev( p_demux ); + goto error; } result = ioctl( p_sys->fd_audio, SNDCTL_DSP_CHANNELS, &p_sys->channels ); @@ -479,7 +465,7 @@ static void OpenAudioDev( demux_t *p_demux ) { msg_Err( p_demux, "Cannot set audio channels count (%d)", p_sys->channels ); - CloseAudioDev( p_demux ); + goto error; } result = ioctl( p_sys->fd_audio, SNDCTL_DSP_SPEED, &p_sys->i_sample_rate ); @@ -487,7 +473,7 @@ static void OpenAudioDev( demux_t *p_demux ) { msg_Err( p_demux, "Cannot set audio sample rate (%d)", p_sys->i_sample_rate ); - CloseAudioDev( p_demux ); + goto error; } msg_Dbg( p_demux, "Opened adev=`%s' %s %dHz", @@ -496,18 +482,21 @@ static void OpenAudioDev( demux_t *p_demux ) p_sys->i_sample_rate ); p_sys->i_audio_max_frame_size = 32 * 1024; + + return VLC_SUCCESS; + +error: + CloseAudioDev( p_demux ); + p_sys->fd_audio = -1; + return VLC_EGENERIC; } static inline void CloseAudioDev( demux_t *p_demux ) { - demux_sys_t *p_sys = NULL; + demux_sys_t *p_sys = p_demux->p_sys; - if( p_demux ) - { - p_sys = p_demux->p_sys; - if( p_sys->fd_audio >= 0 ) - close( p_sys->fd_audio ); - } + if( p_sys->fd_audio >= 0 ) + close( p_sys->fd_audio ); } /***************************************************************************** @@ -531,9 +520,8 @@ static void Close( vlc_object_t *p_this ) dc1394_camera_free(p_sys->camera); dc1394_free(p_sys->p_dccontext); - if( p_sys->audio_device ) - free( p_sys->audio_device ); - + free( p_sys->video_device ); + free( p_sys->audio_device ); free( p_sys ); } @@ -630,7 +618,10 @@ static block_t *GrabAudio( demux_t *p_demux ) p_sys->i_audio_max_frame_size ); if( i_read <= 0 ) + { + block_Release( p_block ); return NULL; + } p_block->i_buffer = i_read; @@ -653,7 +644,7 @@ static int Demux( demux_t *p_demux ) block_t *p_blockv = NULL; /* Try grabbing audio frames first */ - if( p_sys->fd_audio > 0 ) + if( p_sys->fd_audio >= 0 ) p_blocka = GrabAudio( p_demux ); /* Try grabbing video frame */ @@ -724,10 +715,7 @@ static int process_options( demux_t *p_demux ) const char *in_fmt = NULL; float rate_f; - if( strncmp(p_demux->psz_access, "dc1394", 6) != 0 ) - return VLC_EGENERIC; - - psz_dup = strdup( p_demux->psz_path ); + psz_dup = strdup( p_demux->psz_location ); psz_parser = psz_dup; for( token = strtok_r( psz_parser,":",&state); token; token = strtok_r( NULL, ":", &state ) ) @@ -942,7 +930,7 @@ static int process_options( demux_t *p_demux ) else if( strncmp( token, "uid=", strlen("uid=") ) == 0) { token += strlen("uid="); - sscanf( token, "0x%llx", &p_sys->selected_uid ); + sscanf( token, "0x%"SCNx64, &p_sys->selected_uid ); } } @@ -981,5 +969,7 @@ static int process_options( demux_t *p_demux ) else // YUV422 default p_sys->video_mode = DC1394_VIDEO_MODE_640x480_YUV422; } + + free( psz_dup ); return VLC_SUCCESS; }