From 57981acd570f0cc5a0f998e05f2b4bf437d08d5a Mon Sep 17 00:00:00 2001 From: Laurent Aimar Date: Thu, 14 May 2009 22:06:58 +0200 Subject: [PATCH] Used vlc_fourcc_GetCodecFromString where applicable. --- modules/access/dshow/dshow.cpp | 13 +++++-------- modules/access/v4l.c | 9 +++++---- modules/access/v4l2.c | 22 +++++++++------------- modules/codec/fake.c | 11 ++--------- modules/demux/rawaud.c | 10 +++------- modules/misc/dummy/vout.c | 15 +++------------ modules/video_output/fb.c | 11 +++++------ modules/video_output/sdl.c | 7 +++---- modules/video_output/snapshot.c | 23 ++++++++++------------- modules/video_output/vmem.c | 25 +++++++++++-------------- modules/video_output/yuv.c | 10 ++++------ 11 files changed, 60 insertions(+), 96 deletions(-) diff --git a/modules/access/dshow/dshow.cpp b/modules/access/dshow/dshow.cpp index 9a6cf7cd3b..c2dfd9c685 100644 --- a/modules/access/dshow/dshow.cpp +++ b/modules/access/dshow/dshow.cpp @@ -349,7 +349,8 @@ static int CommonOpen( vlc_object_t *p_this, access_sys_t *p_sys, /* Get/parse options and open device(s) */ string vdevname, adevname; - int i_width = 0, i_height = 0, i_chroma = 0; + int i_width = 0, i_height = 0; + vlc_fourcc_t i_chroma = 0; bool b_use_audio = true; bool b_use_video = true; @@ -419,13 +420,9 @@ static int CommonOpen( vlc_object_t *p_this, access_sys_t *p_sys, p_sys->b_chroma = false; var_Create( p_this, "dshow-chroma", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); var_Get( p_this, "dshow-chroma", &val ); - if( val.psz_string && strlen( val.psz_string ) >= 4 ) - { - i_chroma = vlc_fourcc_GetCodec( UNKNOWN_ES, - VLC_FOURCC( val.psz_string[0], val.psz_string[1], - val.psz_string[2], val.psz_string[3] ) ); - p_sys->b_chroma = true; - } + + i_chroma = vlc_fourcc_GetCodecFromString( UNKNOWN_ES, val.psz_string ); + p_sys->b_chroma = i_chroma != 0; free( val.psz_string ); var_Create( p_this, "dshow-fps", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT ); diff --git a/modules/access/v4l.c b/modules/access/v4l.c index 197756cf37..16e408a792 100644 --- a/modules/access/v4l.c +++ b/modules/access/v4l.c @@ -212,7 +212,7 @@ struct quicktime_mjpeg_app1 static const struct { int i_v4l; - int i_fourcc; + vlc_fourcc_t i_fourcc; } v4lchroma_to_fourcc[] = { @@ -975,11 +975,12 @@ static int OpenVideoDev( demux_t *p_demux, char *psz_device ) p_sys->i_fourcc = 0; psz = var_CreateGetString( p_demux, "v4l-chroma" ); - if( strlen( psz ) >= 4 ) + + const vlc_fourcc_t i_chroma = + vlc_fourcc_GetCodecFromString( VIDEO_ES, psz ); + if( i_chroma ) { vid_picture.palette = 0; - int i_chroma = vlc_fourcc_GetCodec( VIDEO_ES, - VLC_FOURCC( psz[0], psz[1], psz[2], psz[3] ) ); /* Find out v4l chroma code */ for( i = 0; v4lchroma_to_fourcc[i].i_v4l != 0; i++ ) diff --git a/modules/access/v4l2.c b/modules/access/v4l2.c index c6688d6b11..aa511ee06d 100644 --- a/modules/access/v4l2.c +++ b/modules/access/v4l2.c @@ -393,7 +393,7 @@ static int AccessControlResetCallback( vlc_object_t *p_this, static const struct { unsigned int i_v4l2; - int i_fourcc; + vlc_fourcc_t i_fourcc; int i_rmask; int i_gmask; int i_bmask; @@ -1945,22 +1945,18 @@ static int OpenVideoDev( vlc_object_t *p_obj, demux_sys_t *p_sys, bool b_demux ) /* Test and set Chroma */ fmt.fmt.pix.pixelformat = 0; - if( p_sys->psz_requested_chroma && strlen( p_sys->psz_requested_chroma ) > 0 ) + if( p_sys->psz_requested_chroma && *p_sys->psz_requested_chroma ) { /* User specified chroma */ - if( strlen( p_sys->psz_requested_chroma ) >= 4 ) + const vlc_fourcc_t i_requested_fourcc = + vlc_fourcc_GetCodecFromString( VIDEO_ES, p_sys->psz_requested_chroma ); + + for( int i = 0; v4l2chroma_to_fourcc[i].i_v4l2 != 0; i++ ) { - int i_requested_fourcc = vlc_fourcc_GetCodec( VIDEO_ES, - 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 ) { - if( v4l2chroma_to_fourcc[i].i_fourcc == i_requested_fourcc ) - { - fmt.fmt.pix.pixelformat = v4l2chroma_to_fourcc[i].i_v4l2; - break; - } + fmt.fmt.pix.pixelformat = v4l2chroma_to_fourcc[i].i_v4l2; + break; } } /* Try and set user chroma */ diff --git a/modules/codec/fake.c b/modules/codec/fake.c index b9787851c7..a13b671790 100644 --- a/modules/codec/fake.c +++ b/modules/codec/fake.c @@ -169,19 +169,12 @@ static int OpenDecoder( vlc_object_t *p_this ) var_AddCallback( p_dec, "fake-file-reload", FakeCallback , p_dec ); psz_chroma = var_CreateGetString( p_dec, "fake-chroma" ); - if( strlen( psz_chroma ) != 4 ) + fmt_out.i_chroma = vlc_fourcc_GetCodecFromString( VIDEO_ES, psz_chroma ); + if( !fmt_out.i_chroma ) { msg_Warn( p_dec, "Invalid chroma (%s). Using I420.", psz_chroma ); fmt_out.i_chroma = VLC_CODEC_I420; } - else - { - fmt_out.i_chroma = vlc_fourcc_GetCodec( VIDEO_ES, - VLC_FOURCC( psz_chroma[0], - psz_chroma[1], - psz_chroma[2], - psz_chroma[3] ) ); - } free( psz_chroma ); var_Create( p_dec, "fake-keep-ar", VLC_VAR_BOOL | VLC_VAR_DOINHERIT ); diff --git a/modules/demux/rawaud.c b/modules/demux/rawaud.c index 4d5476fdee..a9473a0606 100644 --- a/modules/demux/rawaud.c +++ b/modules/demux/rawaud.c @@ -106,21 +106,17 @@ static int Open( vlc_object_t * p_this ) es_format_Init( &p_sys->fmt, AUDIO_ES, 0 ); char *psz_fourcc = var_CreateGetString( p_demux, "rawaud-fourcc" ); + p_sys->fmt.i_codec = vlc_fourcc_GetCodecFromString( AUDIO_ES, psz_fourcc ); + free( psz_fourcc ); - if( ( psz_fourcc == NULL ? 0 : strlen( psz_fourcc ) ) != 4 ) + if( !p_sys->fmt.i_codec ) { msg_Err( p_demux, "rawaud-fourcc must be a 4 character string"); - free( psz_fourcc ); es_format_Clean( &p_sys->fmt ); free( p_sys ); return VLC_EGENERIC; } - p_sys->fmt.i_codec = vlc_fourcc_GetCodec( AUDIO_ES, - VLC_FOURCC( psz_fourcc[0], psz_fourcc[1], - psz_fourcc[2], psz_fourcc[3] ) ); - - free( psz_fourcc ); // get the bits per sample ratio based on codec switch( p_sys->fmt.i_codec ) { diff --git a/modules/misc/dummy/vout.c b/modules/misc/dummy/vout.c index 5d5e7aced5..3311041e03 100644 --- a/modules/misc/dummy/vout.c +++ b/modules/misc/dummy/vout.c @@ -89,18 +89,9 @@ static int Init( vout_thread_t *p_vout ) bool b_chroma = 0; psz_chroma = config_GetPsz( p_vout, "dummy-chroma" ); - if( psz_chroma ) - { - if( strlen( psz_chroma ) >= 4 ) - { - i_chroma = vlc_fourcc_GetCodec( VIDEO_ES, - VLC_FOURCC( psz_chroma[0], psz_chroma[1], - psz_chroma[2], psz_chroma[3] ) ); - b_chroma = 1; - } - - free( psz_chroma ); - } + i_chroma = vlc_fourcc_GetCodecFromString( VIDEO_ES, psz_chroma ); + b_chroma = i_chroma != 0; + free( psz_chroma ); I_OUTPUTPICTURES = 0; diff --git a/modules/video_output/fb.c b/modules/video_output/fb.c index 36bf04e2ae..95f17c1d36 100644 --- a/modules/video_output/fb.c +++ b/modules/video_output/fb.c @@ -225,13 +225,12 @@ static int Create( vlc_object_t *p_this ) psz_chroma = var_CreateGetNonEmptyString( p_vout, "fb-chroma" ); if( psz_chroma ) { - if( strlen( psz_chroma ) == 4 ) + const vlc_fourcc_t i_chroma = + vlc_fourcc_GetCodecFromString( VIDEO_ES, psz_chroma ); + + if( i_chroma ) { - p_sys->i_chroma = vlc_fourcc_GetCodec( VIDEO_ES, - VLC_FOURCC( psz_chroma[0], - psz_chroma[1], - psz_chroma[2], - psz_chroma[3] ) ); + p_sys->i_chroma = i_chroma; msg_Dbg( p_vout, "forcing chroma '%s'", psz_chroma ); } else diff --git a/modules/video_output/sdl.c b/modules/video_output/sdl.c index f2cfa7449a..e3f4a92643 100644 --- a/modules/video_output/sdl.c +++ b/modules/video_output/sdl.c @@ -753,7 +753,7 @@ static int OpenDisplay( vout_thread_t *p_vout ) /* SDL fucked up fourcc definitions on bigendian machines */ uint32_t i_sdl_chroma; char *psz_chroma = NULL; - uint32_t i_chroma = 0; + vlc_fourcc_t i_chroma = 0; bool b_overlay = config_GetInt( p_vout, "overlay" ); @@ -796,10 +796,9 @@ static int OpenDisplay( vout_thread_t *p_vout ) if( ( psz_chroma = config_GetPsz( p_vout, "sdl-chroma" ) ) ) { - if( strlen( psz_chroma ) >= 4 ) + i_chroma = vlc_fourcc_GetCodecFromString( VIDEO_ES, psz_chroma ); + if( i_chroma ) { - memcpy(&i_chroma, psz_chroma, 4); - i_chroma = vlc_fourcc_GetCodec( VIDEO_ES, i_chroma ); msg_Dbg( p_vout, "Forcing chroma to 0x%.8x (%4.4s)", i_chroma, (char*)&i_chroma ); } else diff --git a/modules/video_output/snapshot.c b/modules/video_output/snapshot.c index 0dedf12ffb..5b6c4c330a 100644 --- a/modules/video_output/snapshot.c +++ b/modules/video_output/snapshot.c @@ -152,7 +152,7 @@ static int Init( vout_thread_t *p_vout ) picture_t *p_pic; vlc_value_t val; char* psz_chroma; - int i_chroma; + vlc_fourcc_t i_chroma; int i_width; int i_height; int i_datasize; @@ -161,21 +161,18 @@ static int Init( vout_thread_t *p_vout ) i_height = config_GetInt( p_vout, "snapshot-height" ); psz_chroma = config_GetPsz( p_vout, "snapshot-chroma" ); - if( psz_chroma ) + if( !psz_chroma ) { - if( strlen( psz_chroma ) < 4 ) - { - msg_Err( p_vout, "snapshot-chroma should be 4 characters long" ); - return VLC_EGENERIC; - } - i_chroma = vlc_fourcc_GetCodec( VIDEO_ES, - VLC_FOURCC( psz_chroma[0], psz_chroma[1], - psz_chroma[2], psz_chroma[3] ) ); - free( psz_chroma ); + msg_Err( p_vout, "Cannot find chroma information." ); + return VLC_EGENERIC; } - else + + i_chroma = vlc_fourcc_GetCodecFromString( VIDEO_ES, psz_chroma ); + free( psz_chroma ); + + if( !i_chroma ) { - msg_Err( p_vout, "Cannot find chroma information." ); + msg_Err( p_vout, "snapshot-chroma should be 4 characters long" ); return VLC_EGENERIC; } diff --git a/modules/video_output/vmem.c b/modules/video_output/vmem.c index 17ba736ff3..21bd8b622b 100644 --- a/modules/video_output/vmem.c +++ b/modules/video_output/vmem.c @@ -133,29 +133,26 @@ static int Init( vout_thread_t *p_vout ) int i_index; picture_t *p_pic; char *psz_chroma, *psz_tmp; - int i_width, i_height, i_pitch, i_chroma; + int i_width, i_height, i_pitch; + vlc_fourcc_t i_chroma; i_width = var_CreateGetInteger( p_vout, "vmem-width" ); i_height = var_CreateGetInteger( p_vout, "vmem-height" ); i_pitch = var_CreateGetInteger( p_vout, "vmem-pitch" ); psz_chroma = var_CreateGetString( p_vout, "vmem-chroma" ); - if( psz_chroma ) + if( !psz_chroma ) { - if( strlen( psz_chroma ) < 4 ) - { - msg_Err( p_vout, "vmem-chroma should be 4 characters long" ); - free( psz_chroma ); - return VLC_EGENERIC; - } - i_chroma = vlc_fourcc_GetCodec( VIDEO_ES, - VLC_FOURCC( psz_chroma[0], psz_chroma[1], - psz_chroma[2], psz_chroma[3] ) ); - free( psz_chroma ); + msg_Err( p_vout, "Cannot find chroma information." ); + return VLC_EGENERIC; } - else + + i_chroma = vlc_fourcc_GetCodecFromString( VIDEO_ES, psz_chroma ); + free( psz_chroma ); + + if( !i_chroma ) { - msg_Err( p_vout, "Cannot find chroma information." ); + msg_Err( p_vout, "vmem-chroma should be 4 characters long" ); return VLC_EGENERIC; } diff --git a/modules/video_output/yuv.c b/modules/video_output/yuv.c index fffb6009b8..35542ebfa9 100644 --- a/modules/video_output/yuv.c +++ b/modules/video_output/yuv.c @@ -134,12 +134,10 @@ static int Create( vlc_object_t *p_this ) } psz_fcc = var_CreateGetNonEmptyString( p_this, CFG_PREFIX "chroma" ); - if( psz_fcc && (strlen( psz_fcc ) == 4) ) - { - p_sys->i_chroma = vlc_fourcc_GetCodec( VIDEO_ES, - VLC_FOURCC( psz_fcc[0], psz_fcc[1], - psz_fcc[2], psz_fcc[3] ) ); - } + const vlc_fourcc_t i_requested_chroma = + vlc_fourcc_GetCodecFromString( VIDEO_ES, psz_fcc ); + if( i_requested_chroma ) + p_sys->i_chroma = i_requested_chroma; free( psz_fcc ); if( p_sys->b_yuv4mpeg2 ) -- 2.39.2