Commit e2e5bcb7 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

marq: cleanly check if a SPU update is required

Format the text. If it is identical and all parameters are unchanged,
there is no need to update - even if the format contains a $ sign.
parent 5a59ffd1
...@@ -73,14 +73,13 @@ struct filter_sys_t ...@@ -73,14 +73,13 @@ struct filter_sys_t
int i_pos; /* permit relative positioning (top, bottom, left, right, center) */ int i_pos; /* permit relative positioning (top, bottom, left, right, center) */
int i_timeout; int i_timeout;
char *psz_marquee; /* marquee string */ char *format; /**< marquee text format */
char *message; /**< marquee plain text */
text_style_t *p_style; /* font control */ text_style_t *p_style; /* font control */
mtime_t last_time; mtime_t last_time;
mtime_t i_refresh; mtime_t i_refresh;
bool b_need_update;
}; };
#define MSG_TEXT N_("Text") #define MSG_TEXT N_("Text")
...@@ -210,7 +209,6 @@ static int CreateFilter( vlc_object_t *p_this ) ...@@ -210,7 +209,6 @@ static int CreateFilter( vlc_object_t *p_this )
p_sys->stor = var_CreateGet##type##Command( p_filter, var ); \ p_sys->stor = var_CreateGet##type##Command( p_filter, var ); \
var_AddCallback( p_filter, var, MarqueeCallback, p_sys ); var_AddCallback( p_filter, var, MarqueeCallback, p_sys );
p_sys->b_need_update = true;
CREATE_VAR( i_xoff, Integer, "marq-x" ); CREATE_VAR( i_xoff, Integer, "marq-x" );
CREATE_VAR( i_yoff, Integer, "marq-y" ); CREATE_VAR( i_yoff, Integer, "marq-y" );
CREATE_VAR( i_timeout,Integer, "marq-timeout" ); CREATE_VAR( i_timeout,Integer, "marq-timeout" );
...@@ -218,7 +216,8 @@ static int CreateFilter( vlc_object_t *p_this ) ...@@ -218,7 +216,8 @@ static int CreateFilter( vlc_object_t *p_this )
"marq-refresh" ); "marq-refresh" );
var_AddCallback( p_filter, "marq-refresh", MarqueeCallback, p_sys ); var_AddCallback( p_filter, "marq-refresh", MarqueeCallback, p_sys );
CREATE_VAR( i_pos, Integer, "marq-position" ); CREATE_VAR( i_pos, Integer, "marq-position" );
CREATE_VAR( psz_marquee, String, "marq-marquee" ); CREATE_VAR( format, String, "marq-marquee" );
p_sys->message = NULL;
p_sys->p_style->i_font_alpha = var_CreateGetIntegerCommand( p_filter, p_sys->p_style->i_font_alpha = var_CreateGetIntegerCommand( p_filter,
"marq-opacity" ); "marq-opacity" );
var_AddCallback( p_filter, "marq-opacity", MarqueeCallback, p_sys ); var_AddCallback( p_filter, "marq-opacity", MarqueeCallback, p_sys );
...@@ -255,7 +254,8 @@ static void DestroyFilter( vlc_object_t *p_this ) ...@@ -255,7 +254,8 @@ static void DestroyFilter( vlc_object_t *p_this )
vlc_mutex_destroy( &p_sys->lock ); vlc_mutex_destroy( &p_sys->lock );
text_style_Delete( p_sys->p_style ); text_style_Delete( p_sys->p_style );
free( p_sys->psz_marquee ); free( p_sys->format );
free( p_sys->message );
free( p_sys ); free( p_sys );
} }
...@@ -273,8 +273,17 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date ) ...@@ -273,8 +273,17 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
if( p_sys->last_time + p_sys->i_refresh > date ) if( p_sys->last_time + p_sys->i_refresh > date )
goto out; goto out;
if( !p_sys->b_need_update )
char *msg = str_format( p_filter, p_sys->format ? p_sys->format : "" );
if( unlikely( msg == NULL ) )
goto out;
if( p_sys->message != NULL && !strcmp( msg, p_sys->message ) )
{
free( msg );
goto out; goto out;
}
free( p_sys->message );
p_sys->message = msg;
p_spu = filter_NewSubpicture( p_filter ); p_spu = filter_NewSubpicture( p_filter );
if( !p_spu ) if( !p_spu )
...@@ -295,11 +304,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date ) ...@@ -295,11 +304,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
p_sys->last_time = date; p_sys->last_time = date;
if( !strchr( p_sys->psz_marquee, '%' ) p_spu->p_region->psz_text = strdup( msg );
&& !strchr( p_sys->psz_marquee, '$' ) )
p_sys->b_need_update = false;
p_spu->p_region->psz_text = str_format( p_filter, p_sys->psz_marquee );
p_spu->i_start = date; p_spu->i_start = date;
p_spu->i_stop = p_sys->i_timeout == 0 ? 0 : date + p_sys->i_timeout * 1000; p_spu->i_stop = p_sys->i_timeout == 0 ? 0 : date + p_sys->i_timeout * 1000;
p_spu->b_ephemer = true; p_spu->b_ephemer = true;
...@@ -341,8 +346,8 @@ static int MarqueeCallback( vlc_object_t *p_this, char const *psz_var, ...@@ -341,8 +346,8 @@ static int MarqueeCallback( vlc_object_t *p_this, char const *psz_var,
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
if( !strcmp( psz_var, "marq-marquee" ) ) if( !strcmp( psz_var, "marq-marquee" ) )
{ {
free( p_sys->psz_marquee ); free( p_sys->format );
p_sys->psz_marquee = strdup( newval.psz_string ); p_sys->format = strdup( newval.psz_string );
} }
else if ( !strcmp( psz_var, "marq-x" ) ) else if ( !strcmp( psz_var, "marq-x" ) )
{ {
...@@ -378,7 +383,10 @@ static int MarqueeCallback( vlc_object_t *p_this, char const *psz_var, ...@@ -378,7 +383,10 @@ static int MarqueeCallback( vlc_object_t *p_this, char const *psz_var,
p_sys->i_pos = newval.i_int; p_sys->i_pos = newval.i_int;
p_sys->i_xoff = -1; /* force to relative positioning */ p_sys->i_xoff = -1; /* force to relative positioning */
} }
p_sys->b_need_update = true;
free( p_sys->message );
p_sys->message = NULL; /* force update */
vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_unlock( &p_sys->lock );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment