X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_filter%2Flogo.c;h=37e51f26e70ee13b2665c4b8a2b2d30119be9088;hb=d6abd400bfadd7c0bfe4bfe2cf1547d72e153508;hp=4c4978cee09c6f4d5e06081a0c72ce94c894a710;hpb=cc3d897d2f7070007149122b293b891166cc17f9;p=vlc diff --git a/modules/video_filter/logo.c b/modules/video_filter/logo.c index 4c4978cee0..37e51f26e7 100644 --- a/modules/video_filter/logo.c +++ b/modules/video_filter/logo.c @@ -25,10 +25,13 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#include /* malloc(), free() */ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include #include "vlc_filter.h" @@ -92,40 +95,39 @@ static int LogoCallback( vlc_object_t *, char const *, #define CFG_PREFIX "logo-" -static int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 }; -static const char *ppsz_pos_descriptions[] = +static const int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 }; +static const char *const ppsz_pos_descriptions[] = { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"), N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") }; vlc_module_begin(); - set_description( _("Logo video filter") ); + set_description( N_("Logo video filter") ); set_capability( "video filter", 0 ); - set_shortname( _("Logo overlay") ); + set_shortname( N_("Logo overlay") ); set_category( CAT_VIDEO ); set_subcategory( SUBCAT_VIDEO_SUBPIC ); add_shortcut( "logo" ); set_callbacks( Create, Destroy ); - add_file( CFG_PREFIX "file", NULL, NULL, FILE_TEXT, FILE_LONGTEXT, VLC_FALSE ); - add_integer( CFG_PREFIX "x", -1, NULL, POSX_TEXT, POSX_LONGTEXT, VLC_TRUE ); - add_integer( CFG_PREFIX "y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, VLC_TRUE ); + add_file( CFG_PREFIX "file", NULL, NULL, FILE_TEXT, FILE_LONGTEXT, false ); + add_integer( CFG_PREFIX "x", 0, NULL, POSX_TEXT, POSX_LONGTEXT, true ); + add_integer( CFG_PREFIX "y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, true ); /* default to 1000 ms per image, continuously cycle through them */ - add_integer( CFG_PREFIX "delay", 1000, NULL, DELAY_TEXT, DELAY_LONGTEXT, VLC_TRUE ); - add_integer( CFG_PREFIX "repeat", -1, NULL, REPEAT_TEXT, REPEAT_LONGTEXT, VLC_TRUE ); + add_integer( CFG_PREFIX "delay", 1000, NULL, DELAY_TEXT, DELAY_LONGTEXT, true ); + add_integer( CFG_PREFIX "repeat", -1, NULL, REPEAT_TEXT, REPEAT_LONGTEXT, true ); add_integer_with_range( CFG_PREFIX "transparency", 255, 0, 255, NULL, - TRANS_TEXT, TRANS_LONGTEXT, VLC_FALSE ); - add_integer( CFG_PREFIX "position", 6, NULL, POS_TEXT, POS_LONGTEXT, VLC_FALSE ); + TRANS_TEXT, TRANS_LONGTEXT, false ); + add_integer( CFG_PREFIX "position", -1, NULL, POS_TEXT, POS_LONGTEXT, false ); change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 ); /* subpicture filter submodule */ add_submodule(); set_capability( "sub filter", 0 ); set_callbacks( CreateFilter, DestroyFilter ); - set_description( _("Logo sub filter") ); - add_shortcut( "logo" ); + set_description( N_("Logo sub filter") ); vlc_module_end(); -static const char *ppsz_filter_options[] = { +static const char *const ppsz_filter_options[] = { "file", "x", "y", "delay", "repeat", "transparency", "position", NULL }; @@ -171,7 +173,11 @@ static picture_t *LoadImage( vlc_object_t *p_this, char *psz_filename ) { picture_t *p_pic; image_handler_t *p_image; - video_format_t fmt_in = {0}, fmt_out = {0}; + video_format_t fmt_in; + video_format_t fmt_out; + + memset( &fmt_in, 0, sizeof(video_format_t) ); + memset( &fmt_out, 0, sizeof(video_format_t) ); fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A'); p_image = image_HandlerCreate( p_this ); @@ -273,7 +279,7 @@ static void FreeLogoList( logo_list_t *p_logo_list ) FREENULL( p_logo->psz_file ); if( p_logo->p_pic ) { - p_logo->p_pic->pf_release( p_logo->p_pic ); + picture_Release( p_logo->p_pic ); p_logo->p_pic = NULL; } } @@ -304,24 +310,32 @@ static int Create( vlc_object_t *p_this ) { vout_thread_t *p_vout = (vout_thread_t *)p_this; vout_sys_t *p_sys; - vlc_value_t val; logo_list_t *p_logo_list; /* Allocate structure */ p_sys = p_vout->p_sys = malloc( sizeof( vout_sys_t ) ); if( p_sys == NULL ) - { - msg_Err( p_vout, "out of memory" ); return VLC_ENOMEM; - } p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) ); if( p_logo_list == NULL ) { - msg_Err( p_vout, "out of memory" ); free( p_sys ); return VLC_ENOMEM; } + config_ChainParse( p_vout, CFG_PREFIX, ppsz_filter_options, + p_vout->p_cfg ); + + p_logo_list->psz_filename = var_CreateGetStringCommand( p_vout, + "logo-file" ); + if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename ) + { + msg_Err( p_vout, "logo file not specified" ); + free( p_logo_list->psz_filename ); + free( p_sys ); + return VLC_EGENERIC; + } + p_vout->pf_init = Init; p_vout->pf_end = End; p_vout->pf_manage = NULL; @@ -329,22 +343,14 @@ static int Create( vlc_object_t *p_this ) p_vout->pf_display = NULL; p_vout->pf_control = Control; - p_logo_list->psz_filename = var_CreateGetStringCommand( p_this, - "logo-file" ); - if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename ) - { - msg_Err( p_this, "logo file not specified" ); - return 0; - } - - p_sys->pos = var_CreateGetIntegerCommand( p_this, "logo-position" ); - p_sys->posx = var_CreateGetIntegerCommand( p_this, "logo-x" ); - p_sys->posy = var_CreateGetIntegerCommand( p_this, "logo-y" ); + p_sys->pos = var_CreateGetIntegerCommand( p_vout, "logo-position" ); + p_sys->posx = var_CreateGetIntegerCommand( p_vout, "logo-x" ); + p_sys->posy = var_CreateGetIntegerCommand( p_vout, "logo-y" ); p_logo_list->i_delay = __MAX( __MIN( - var_CreateGetIntegerCommand( p_this, "logo-delay" ) , 60000 ), 0 ); - p_logo_list->i_repeat = var_CreateGetIntegerCommand( p_this, "logo-repeat"); + var_CreateGetIntegerCommand( p_vout, "logo-delay" ) , 60000 ), 0 ); + p_logo_list->i_repeat = var_CreateGetIntegerCommand( p_vout, "logo-repeat"); p_logo_list->i_alpha = __MAX( __MIN( - var_CreateGetIntegerCommand( p_this, "logo-transparency" ), 255 ), 0 ); + var_CreateGetIntegerCommand( p_vout, "logo-transparency" ), 255 ), 0 ); LoadLogoList( p_vout, p_logo_list ); @@ -359,11 +365,11 @@ static int Init( vout_thread_t *p_vout ) vout_sys_t *p_sys = p_vout->p_sys; picture_t *p_pic; int i_index; - video_format_t fmt = {0}; - + video_format_t fmt; logo_list_t *p_logo_list = p_sys->p_logo_list; I_OUTPUTPICTURES = 0; + memset( &fmt, 0, sizeof(video_format_t) ); /* adjust index to the next logo */ p_logo_list->i_counter = @@ -410,7 +416,7 @@ static int Init( vout_thread_t *p_vout ) { msg_Err( p_vout, "can't open blending filter, aborting" ); vlc_object_detach( p_sys->p_blend ); - vlc_object_destroy( p_sys->p_blend ); + vlc_object_release( p_sys->p_blend ); return VLC_EGENERIC; } @@ -471,6 +477,10 @@ static void End( vout_thread_t *p_vout ) vout_sys_t *p_sys = p_vout->p_sys; int i_index; + DEL_PARENT_CALLBACKS( SendEventsToChild ); + + DEL_CALLBACKS( p_sys->p_vout, SendEvents ); + /* Free the fake output buffers we allocated */ for( i_index = I_OUTPUTPICTURES ; i_index ; ) { @@ -481,17 +491,12 @@ static void End( vout_thread_t *p_vout ) var_DelCallback( p_sys->p_vout, "mouse-x", MouseEvent, p_vout); var_DelCallback( p_sys->p_vout, "mouse-y", MouseEvent, p_vout); - if( p_sys->p_vout ) - { - DEL_CALLBACKS( p_sys->p_vout, SendEvents ); - vlc_object_detach( p_sys->p_vout ); - vout_Destroy( p_sys->p_vout ); - } + vout_CloseAndRelease( p_sys->p_vout ); if( p_sys->p_blend->p_module ) module_Unneed( p_sys->p_blend, p_sys->p_blend->p_module ); vlc_object_detach( p_sys->p_blend ); - vlc_object_destroy( p_sys->p_blend ); + vlc_object_release( p_sys->p_blend ); } /***************************************************************************** @@ -502,7 +507,6 @@ static void Destroy( vlc_object_t *p_this ) vout_thread_t *p_vout = (vout_thread_t *)p_this; vout_sys_t *p_sys = p_vout->p_sys; - DEL_PARENT_CALLBACKS( SendEventsToChild ); FreeLogoList( p_sys->p_logo_list ); free( p_sys->p_logo_list ); @@ -575,7 +579,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_inpic ) /* This is a new frame. Get a structure from the video_output. */ while( !(p_outpic = vout_CreatePicture( p_sys->p_vout, 0, 0, 0 )) ) { - if( p_vout->b_die || p_vout->b_error ) return; + if( !vlc_object_alive (p_vout) || p_vout->b_error ) return; msleep( VOUT_OUTMEM_SLEEP ); } @@ -597,6 +601,7 @@ static void Render( vout_thread_t *p_vout, picture_t *p_inpic ) static int SendEvents( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { + VLC_UNUSED(p_this); VLC_UNUSED(oldval); var_Set( (vlc_object_t *)p_data, psz_var, newval ); return VLC_SUCCESS; } @@ -607,6 +612,7 @@ static int SendEvents( vlc_object_t *p_this, char const *psz_var, static int MouseEvent( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { + VLC_UNUSED(p_this); VLC_UNUSED(oldval); vout_thread_t *p_vout = (vout_thread_t*)p_data; vout_sys_t *p_sys = p_vout->p_sys; vlc_value_t valb; @@ -665,6 +671,7 @@ static int Control( vout_thread_t *p_vout, int i_query, va_list args ) static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { + VLC_UNUSED(p_data); VLC_UNUSED(oldval); vout_thread_t *p_vout = (vout_thread_t *)p_this; var_Set( p_vout->p_sys->p_vout, psz_var, newval ); return VLC_SUCCESS; @@ -679,11 +686,11 @@ struct filter_sys_t int pos, posx, posy; - vlc_bool_t b_absolute; + bool b_absolute; mtime_t i_last_date; /* On the fly control variable */ - vlc_bool_t b_need_update; + bool b_need_update; }; static subpicture_t *Filter( filter_t *, mtime_t ); @@ -700,14 +707,10 @@ static int CreateFilter( vlc_object_t *p_this ) /* Allocate structure */ p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) ); if( p_sys == NULL ) - { - msg_Err( p_filter, "out of memory" ); return VLC_ENOMEM; - } p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) ); if( p_logo_list == NULL ) { - msg_Err( p_filter, "out of memory" ); free( p_sys ); return VLC_ENOMEM; } @@ -715,7 +718,6 @@ static int CreateFilter( vlc_object_t *p_this ) config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options, p_filter->p_cfg ); - /* Hook used for callback variables */ p_logo_list->psz_filename = var_CreateGetStringCommand( p_filter, "logo-file" ); @@ -737,14 +739,14 @@ static int CreateFilter( vlc_object_t *p_this ) p_logo_list->i_repeat = var_CreateGetIntegerCommand( p_filter, "logo-repeat" ); - var_AddCallback( p_filter->p_libvlc_global, "logo-file", LogoCallback, p_sys ); - var_AddCallback( p_filter->p_libvlc_global, "logo-x", LogoCallback, p_sys ); - var_AddCallback( p_filter->p_libvlc_global, "logo-y", LogoCallback, p_sys ); - var_AddCallback( p_filter->p_libvlc_global, "logo-position", LogoCallback, p_sys ); - var_AddCallback( p_filter->p_libvlc_global, "logo-transparency", LogoCallback, p_sys ); - var_AddCallback( p_filter->p_libvlc_global, "logo-repeat", LogoCallback, p_sys ); + var_AddCallback( p_filter, "logo-file", LogoCallback, p_sys ); + var_AddCallback( p_filter, "logo-x", LogoCallback, p_sys ); + var_AddCallback( p_filter, "logo-y", LogoCallback, p_sys ); + var_AddCallback( p_filter, "logo-position", LogoCallback, p_sys ); + var_AddCallback( p_filter, "logo-transparency", LogoCallback, p_sys ); + var_AddCallback( p_filter, "logo-repeat", LogoCallback, p_sys ); - vlc_mutex_init( p_filter, &p_logo_list->lock ); + vlc_mutex_init( &p_logo_list->lock ); vlc_mutex_lock( &p_logo_list->lock ); LoadLogoList( p_this, p_logo_list ); @@ -753,7 +755,7 @@ static int CreateFilter( vlc_object_t *p_this ) /* Misc init */ p_filter->pf_sub_filter = Filter; - p_sys->b_need_update = VLC_TRUE; + p_sys->b_need_update = true; p_sys->i_last_date = 0; @@ -774,13 +776,13 @@ static void DestroyFilter( vlc_object_t *p_this ) free( p_sys ); /* Delete the logo variables from INPUT */ - var_Destroy( p_filter->p_libvlc_global , "logo-file" ); - var_Destroy( p_filter->p_libvlc_global , "logo-x" ); - var_Destroy( p_filter->p_libvlc_global , "logo-y" ); - var_Destroy( p_filter->p_libvlc_global , "logo-delay" ); - var_Destroy( p_filter->p_libvlc_global , "logo-repeat" ); - var_Destroy( p_filter->p_libvlc_global , "logo-position" ); - var_Destroy( p_filter->p_libvlc_global , "logo-transparency" ); + var_Destroy( p_filter->p_libvlc, "logo-file" ); + var_Destroy( p_filter->p_libvlc, "logo-x" ); + var_Destroy( p_filter->p_libvlc, "logo-y" ); + var_Destroy( p_filter->p_libvlc, "logo-delay" ); + var_Destroy( p_filter->p_libvlc, "logo-repeat" ); + var_Destroy( p_filter->p_libvlc, "logo-position" ); + var_Destroy( p_filter->p_libvlc, "logo-transparency" ); } /***************************************************************************** @@ -819,7 +821,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date ) p_pic = p_logo->p_pic; /* Allocate the subpicture internal data. */ - p_spu = p_filter->pf_sub_buffer_new( p_filter ); + p_spu = filter_NewSubpicture( p_filter ); if( !p_spu ) { vlc_mutex_unlock( &p_logo_list->lock ); @@ -829,9 +831,9 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date ) p_spu->b_absolute = p_sys->b_absolute; p_spu->i_start = p_sys->i_last_date = date; p_spu->i_stop = 0; - p_spu->b_ephemer = VLC_TRUE; + p_spu->b_ephemer = true; - p_sys->b_need_update = VLC_FALSE; + p_sys->b_need_update = false; p_logo_list->i_next_pic = date + ( p_logo->i_delay != -1 ? p_logo->i_delay : p_logo_list->i_delay ) * 1000; @@ -875,21 +877,20 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date ) vlc_mutex_unlock( &p_logo_list->lock ); /* where to locate the logo: */ - if( p_sys->posx < 0 || p_sys->posy < 0 ) - { /* set to one of the 9 relative locations */ - p_spu->i_flags = p_sys->pos; - p_spu->i_x = 0; - p_spu->i_y = 0; - p_spu->b_absolute = VLC_FALSE; + if( p_sys->pos < 0 ) + { /* set to an absolute xy */ + p_region->i_align = OSD_ALIGN_RIGHT | OSD_ALIGN_TOP; + p_spu->b_absolute = true; } else - { /* set to an absolute xy, referenced to upper left corner */ - p_spu->i_flags = OSD_ALIGN_LEFT | OSD_ALIGN_TOP; - p_spu->i_x = p_sys->posx; - p_spu->i_y = p_sys->posy; - p_spu->b_absolute = VLC_TRUE; + { /* set to one of the 9 relative locations */ + p_region->i_align = p_sys->pos; + p_spu->b_absolute = false; } + p_spu->i_x = p_sys->posx; + p_spu->i_y = p_sys->posy; + p_spu->p_region = p_region; p_spu->i_alpha = ( p_logo->i_alpha != -1 ? @@ -904,6 +905,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date ) static int LogoCallback( vlc_object_t *p_this, char const *psz_var, vlc_value_t oldval, vlc_value_t newval, void *p_data ) { + VLC_UNUSED(oldval); filter_sys_t *p_sys = (filter_sys_t *)p_data; logo_list_t *p_logo_list = p_sys->p_logo_list; @@ -914,7 +916,7 @@ static int LogoCallback( vlc_object_t *p_this, char const *psz_var, p_logo_list->psz_filename = strdup( newval.psz_string ); LoadLogoList( p_this, p_logo_list ); vlc_mutex_unlock( &p_logo_list->lock ); - p_sys->b_need_update = VLC_TRUE; + p_sys->b_need_update = true; } else if ( !strncmp( psz_var, "logo-x", 6 ) ) { @@ -940,6 +942,6 @@ static int LogoCallback( vlc_object_t *p_this, char const *psz_var, p_logo_list->i_repeat = newval.i_int; vlc_mutex_unlock( &p_logo_list->lock ); } - p_sys->b_need_update = VLC_TRUE; + p_sys->b_need_update = true; return VLC_SUCCESS; }