]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/dynamicoverlay/dynamicoverlay.c
Fix encoding (and writing).
[vlc] / modules / video_filter / dynamicoverlay / dynamicoverlay.c
index be3327dd0114bc83cb209a12250f8060e078f243..dca20ce2cef72f0f3a4dbe2fa3edc1c7e7961063 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (C) 2007 the VideoLAN team
  * $Id$
  *
- * Author: Soren Bog <avacore@videolan.org>
+ * Author: Søren Bøg <avacore@videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -69,9 +69,9 @@ vlc_module_begin ()
     set_capability( "sub filter", 0 )
 
     add_file( "overlay-input", NULL, NULL, INPUT_TEXT, INPUT_LONGTEXT,
-              false );
+              false )
     add_file( "overlay-output", NULL, NULL, OUTPUT_TEXT, OUTPUT_LONGTEXT,
-              false );
+              false )
 
     add_shortcut( "overlay" )
     set_callbacks( Create, Destroy )
@@ -108,6 +108,7 @@ static int Create( vlc_object_t *p_this )
     p_sys->i_outputfd = -1;
     p_sys->b_updated = true;
     p_sys->b_atomic = false;
+    vlc_mutex_init( &p_sys->lock );
 
     p_filter->pf_sub_filter = Filter;
 
@@ -134,18 +135,23 @@ static int Create( vlc_object_t *p_this )
 static void Destroy( vlc_object_t *p_this )
 {
     filter_t *p_filter = (filter_t *)p_this;
+    filter_sys_t *p_sys = p_filter->p_sys;
 
-    BufferDestroy( &p_filter->p_sys->input );
-    BufferDestroy( &p_filter->p_sys->output );
-    QueueDestroy( &p_filter->p_sys->atomic );
-    QueueDestroy( &p_filter->p_sys->pending );
-    QueueDestroy( &p_filter->p_sys->processed );
-    ListDestroy( &p_filter->p_sys->overlays );
+    BufferDestroy( &p_sys->input );
+    BufferDestroy( &p_sys->output );
+    QueueDestroy( &p_sys->atomic );
+    QueueDestroy( &p_sys->pending );
+    QueueDestroy( &p_sys->processed );
+    ListDestroy( &p_sys->overlays );
     UnregisterCommand( p_filter );
 
-    free( p_filter->p_sys->psz_inputfile );
-    free( p_filter->p_sys->psz_outputfile );
-    free( p_filter->p_sys );
+    var_DelCallback( p_filter, "overlay-input", AdjustCallback, p_sys );
+    var_DelCallback( p_filter, "overlay-output", AdjustCallback, p_sys );
+
+    vlc_mutex_destroy( &p_sys->lock );
+    free( p_sys->psz_inputfile );
+    free( p_sys->psz_outputfile );
+    free( p_sys );
 }
 
 /*****************************************************************************
@@ -160,6 +166,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
     filter_sys_t *p_sys = p_filter->p_sys;
 
     /* We might need to open these at any time. */
+    vlc_mutex_lock( &p_sys->lock );
     if( p_sys->i_inputfd == -1 )
     {
         p_sys->i_inputfd = open( p_sys->psz_inputfile, O_RDONLY | O_NONBLOCK );
@@ -193,6 +200,7 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
                       p_sys->psz_outputfile );
         }
     }
+    vlc_mutex_unlock( &p_sys->lock );
 
     /* Read any waiting commands */
     if( p_sys->i_inputfd != -1 )
@@ -355,12 +363,10 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
                  (char*)&p_overlay->format.i_chroma, p_overlay->i_x, p_overlay->i_y,
                  p_overlay->i_alpha );
 
-        if( p_overlay->format.i_chroma == VLC_FOURCC('T','E','X','T') )
+        if( p_overlay->format.i_chroma == VLC_CODEC_TEXT )
         {
             p_region->psz_text = strdup( p_overlay->data.p_text );
-            p_region->p_style = malloc( sizeof(struct text_style_t) );
-            if( p_region->p_style )
-                *p_region->p_style = p_overlay->fontstyle;
+            p_region->p_style = text_style_Duplicate( p_overlay->p_fontstyle );
         }
         else
         {
@@ -385,10 +391,18 @@ static int AdjustCallback( vlc_object_t *p_this, char const *psz_var,
     filter_sys_t *p_sys = (filter_sys_t *)p_data;
     VLC_UNUSED(p_this); VLC_UNUSED(oldval);
 
+    vlc_mutex_lock( &p_sys->lock );
     if( !strncmp( psz_var, "overlay-input", 13 ) )
-        p_sys->psz_inputfile = newval.psz_string;
+    {
+        free( p_sys->psz_inputfile );
+        p_sys->psz_inputfile = strdup( newval.psz_string );
+    }
     else if( !strncmp( psz_var, "overlay-output", 14 ) )
-        p_sys->psz_outputfile = newval.psz_string;
+    {
+        free( p_sys->psz_outputfile );
+        p_sys->psz_outputfile = strdup( newval.psz_string );
+    }
+    vlc_mutex_unlock( &p_sys->lock );
 
     return VLC_EGENERIC;
 }