[vlc-commits] marq: cleanly check if a SPU update is required

Rémi Denis-Courmont git at videolan.org
Thu May 10 18:51:13 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu May 10 19:30:08 2012 +0300| [e2e5bcb73ceb482de0a81f1dd429127af9d0b069] | committer: 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.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e2e5bcb73ceb482de0a81f1dd429127af9d0b069
---

 modules/video_filter/marq.c |   38 +++++++++++++++++++++++---------------
 1 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/modules/video_filter/marq.c b/modules/video_filter/marq.c
index f972047..9806b90 100644
--- a/modules/video_filter/marq.c
+++ b/modules/video_filter/marq.c
@@ -73,14 +73,13 @@ struct filter_sys_t
     int i_pos; /* permit relative positioning (top, bottom, left, right, center) */
     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 */
 
     mtime_t last_time;
     mtime_t i_refresh;
-
-    bool b_need_update;
 };
 
 #define MSG_TEXT N_("Text")
@@ -210,7 +209,6 @@ static int CreateFilter( vlc_object_t *p_this )
     p_sys->stor = var_CreateGet##type##Command( p_filter, var ); \
     var_AddCallback( p_filter, var, MarqueeCallback, p_sys );
 
-    p_sys->b_need_update = true;
     CREATE_VAR( i_xoff, Integer, "marq-x" );
     CREATE_VAR( i_yoff, Integer, "marq-y" );
     CREATE_VAR( i_timeout,Integer, "marq-timeout" );
@@ -218,7 +216,8 @@ static int CreateFilter( vlc_object_t *p_this )
                                                            "marq-refresh" );
     var_AddCallback( p_filter, "marq-refresh", MarqueeCallback, p_sys );
     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,
                                                             "marq-opacity" );
     var_AddCallback( p_filter, "marq-opacity", MarqueeCallback, p_sys );
@@ -255,7 +254,8 @@ static void DestroyFilter( vlc_object_t *p_this )
 
     vlc_mutex_destroy( &p_sys->lock );
     text_style_Delete( p_sys->p_style );
-    free( p_sys->psz_marquee );
+    free( p_sys->format );
+    free( p_sys->message );
     free( p_sys );
 }
 
@@ -273,8 +273,17 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
     vlc_mutex_lock( &p_sys->lock );
     if( p_sys->last_time + p_sys->i_refresh > date )
         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;
+    }
+    free( p_sys->message );
+    p_sys->message = msg;
 
     p_spu = filter_NewSubpicture( p_filter );
     if( !p_spu )
@@ -295,11 +304,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
 
     p_sys->last_time = date;
 
-    if( !strchr( p_sys->psz_marquee, '%' )
-     && !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->p_region->psz_text = strdup( msg );
     p_spu->i_start = date;
     p_spu->i_stop  = p_sys->i_timeout == 0 ? 0 : date + p_sys->i_timeout * 1000;
     p_spu->b_ephemer = true;
@@ -341,8 +346,8 @@ static int MarqueeCallback( vlc_object_t *p_this, char const *psz_var,
     vlc_mutex_lock( &p_sys->lock );
     if( !strcmp( psz_var, "marq-marquee" ) )
     {
-        free( p_sys->psz_marquee );
-        p_sys->psz_marquee = strdup( newval.psz_string );
+        free( p_sys->format );
+        p_sys->format = strdup( newval.psz_string );
     }
     else if ( !strcmp( psz_var, "marq-x" ) )
     {
@@ -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_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 );
     return VLC_SUCCESS;
 }



More information about the vlc-commits mailing list