]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/marq.c
Remove useless test before a free().
[vlc] / modules / video_filter / marq.c
index ed956557bcf486925f67bb2bc81db467e694c69d..619c485f164a9908fbcab34ed9eb31f1055b0f3a 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * marq.c : marquee display video plugin for vlc
  *****************************************************************************
- * Copyright (C) 2003-2005 the VideoLAN team
+ * Copyright (C) 2003-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Mark Moriarty
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <stdlib.h>                                      /* malloc(), free() */
-#include <string.h>
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <vlc/vlc.h>
 #include <vlc_vout.h>
@@ -72,7 +74,8 @@ struct filter_sys_t
 
     text_style_t *p_style; /* font control */
 
-    time_t last_time;
+    mtime_t last_time;
+    mtime_t i_refresh;
 
     vlc_bool_t b_need_update;
 };
@@ -102,6 +105,10 @@ struct filter_sys_t
 #define TIMEOUT_LONGTEXT N_("Number of milliseconds the marquee must remain " \
                             "displayed. Default value is " \
                             "0 (remains forever).")
+#define REFRESH_TEXT N_("Refresh period in ms")
+#define REFRESH_LONGTEXT N_("Number of milliseconds between string updates. " \
+                            "This is mainly usefull when using meta data " \
+                            "or time format string sequences.")
 #define OPACITY_TEXT N_("Opacity")
 #define OPACITY_LONGTEXT N_("Opacity (inverse of transparency) of " \
     "overlayed text. 0 = transparent, 255 = totally opaque. " )
@@ -141,9 +148,9 @@ vlc_module_begin();
                 VLC_FALSE );
 
     set_section( N_("Position"), NULL );
-    add_integer( CFG_PREFIX "x", -1, NULL, POSX_TEXT, POSX_LONGTEXT, VLC_TRUE );
+    add_integer( CFG_PREFIX "x", 0, NULL, POSX_TEXT, POSX_LONGTEXT, VLC_TRUE );
     add_integer( CFG_PREFIX "y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, VLC_TRUE );
-    add_integer( CFG_PREFIX "position", 5, NULL, POS_TEXT, POS_LONGTEXT, VLC_FALSE );
+    add_integer( CFG_PREFIX "position", -1, NULL, POS_TEXT, POS_LONGTEXT, VLC_FALSE );
         change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
 
     set_section( N_("Font"), NULL );
@@ -159,14 +166,23 @@ vlc_module_begin();
     set_section( N_("Misc"), NULL );
     add_integer( CFG_PREFIX "timeout", 0, NULL, TIMEOUT_TEXT, TIMEOUT_LONGTEXT,
                  VLC_FALSE );
+    add_integer( CFG_PREFIX "refresh", 1000, NULL, REFRESH_TEXT,
+                 REFRESH_LONGTEXT, VLC_FALSE );
 
     set_description( _("Marquee display") );
-    add_shortcut( "marq" );
     add_shortcut( "time" );
+    add_obsolete_string( "time-format" );
+    add_obsolete_string( "time-x" );
+    add_obsolete_string( "time-y" );
+    add_obsolete_string( "time-position" );
+    add_obsolete_string( "time-opacity" );
+    add_obsolete_string( "time-color" );
+    add_obsolete_string( "time-size" );
 vlc_module_end();
 
 static const char *ppsz_filter_options[] = {
-    "marquee", "x", "y", "position", "color", "size", "timeout", NULL
+    "marquee", "x", "y", "position", "color", "size", "timeout", "refresh",
+    NULL
 };
 
 /*****************************************************************************
@@ -198,6 +214,7 @@ static int CreateFilter( vlc_object_t *p_this )
     CREATE_VAR( i_xoff, Integer, "marq-x" );
     CREATE_VAR( i_yoff, Integer, "marq-y" );
     CREATE_VAR( i_timeout,Integer, "marq-timeout" );
+    CREATE_VAR( i_refresh,Integer, "marq-refresh" );
     CREATE_VAR( i_pos, Integer, "marq-position" );
     CREATE_VAR( psz_marquee, String, "marq-marquee" );
     CREATE_VAR( p_style->i_font_alpha, Integer, "marq-opacity" );
@@ -208,7 +225,7 @@ static int CreateFilter( vlc_object_t *p_this )
 
     /* Misc init */
     p_filter->pf_sub_filter = Filter;
-    p_sys->last_time = ((time_t)-1);
+    p_sys->last_time = 0;
     p_sys->b_need_update = VLC_TRUE;
 
     return VLC_SUCCESS;
@@ -221,8 +238,8 @@ static void DestroyFilter( vlc_object_t *p_this )
     filter_t *p_filter = (filter_t *)p_this;
     filter_sys_t *p_sys = p_filter->p_sys;
 
-    if( p_sys->p_style ) free( p_sys->p_style );
-    if( p_sys->psz_marquee ) free( p_sys->psz_marquee );
+    free( p_sys->p_style );
+    free( p_sys->psz_marquee );
 
     /* Delete the marquee variables */
 #define DEL_VAR(var) \
@@ -250,9 +267,8 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
     filter_sys_t *p_sys = p_filter->p_sys;
     subpicture_t *p_spu;
     video_format_t fmt;
-    time_t t;
 
-    if( p_sys->last_time == time( NULL ) )
+    if( p_sys->last_time + p_sys->i_refresh*1000 > date )
     {
         return NULL;
     }
@@ -278,7 +294,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
         return NULL;
     }
 
-    t = p_sys->last_time = time( NULL );
+    p_sys->last_time = date;
 
     if( strchr( p_sys->psz_marquee, '%' ) || strchr( p_sys->psz_marquee, '$' ) )
     {
@@ -294,20 +310,20 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
     p_spu->b_ephemer = VLC_TRUE;
 
     /*  where to locate the string: */
-    if( p_sys->i_xoff < 0 || p_sys->i_yoff < 0 )
-    {   /* set to one of the 9 relative locations */
-        p_spu->i_flags = p_sys->i_pos;
-        p_spu->i_x = 0;
-        p_spu->i_y = 0;
-        p_spu->b_absolute = VLC_FALSE;
+    if( p_sys->i_pos < 0 )
+    {   /*  set to an absolute xy */
+        p_spu->p_region->i_align = OSD_ALIGN_LEFT | OSD_ALIGN_TOP;
+        p_spu->b_absolute = VLC_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->i_xoff;
-        p_spu->i_y = p_sys->i_yoff;
-        p_spu->b_absolute = VLC_TRUE;
+    {   /* set to one of the 9 relative locations */
+        p_spu->p_region->i_align = p_sys->i_pos;
+        p_spu->b_absolute = VLC_FALSE;
     }
+
+    p_spu->i_x = p_sys->i_xoff;
+    p_spu->i_y = p_sys->i_yoff;
+
     p_spu->p_region->p_style = p_sys->p_style;
 
     return p_spu;
@@ -320,11 +336,12 @@ static int MarqueeCallback( 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);
     filter_sys_t *p_sys = (filter_sys_t *) p_data;
 
     if( !strncmp( psz_var, "marq-marquee", 7 ) )
     {
-        if( p_sys->psz_marquee ) free( p_sys->psz_marquee );
+        free( p_sys->psz_marquee );
         p_sys->psz_marquee = strdup( newval.psz_string );
     }
     else if ( !strncmp( psz_var, "marq-x", 6 ) )
@@ -351,6 +368,10 @@ static int MarqueeCallback( vlc_object_t *p_this, char const *psz_var,
     {
         p_sys->i_timeout = newval.i_int;
     }
+    else if ( !strncmp( psz_var, "marq-refresh", 12 ) )
+    {
+        p_sys->i_refresh = newval.i_int;
+    }
     else if ( !strncmp( psz_var, "marq-position", 8 ) )
     /* willing to accept a match against marq-pos */
     {