[vlc-commits] ttml codec: sending a duplicate of the style instead of the original

Stanislas Plessia git at videolan.org
Wed Sep 14 18:39:44 CEST 2016


vlc | branch: master | Stanislas Plessia <stplessia at gmail.com> | Mon Aug 29 16:01:14 2016 +0200| [74b936be17bea277644dd1f6fd0da15e082096ef] | committer: Hugo Beauzée-Luyssen

ttml codec: sending a duplicate of the style instead of the original

The functions which use the styles will merge their
attributes, and to avoid consequences of these merges on the
original styles, we work with duplicates.

Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>

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

 modules/codec/substtml.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/modules/codec/substtml.c b/modules/codec/substtml.c
index f53c897..f20eb19 100644
--- a/modules/codec/substtml.c
+++ b/modules/codec/substtml.c
@@ -99,6 +99,30 @@ static void MergeTTMLStyle( ttml_style_t *p_dst, const ttml_style_t *p_src)
         p_dst->i_margin_percent_v = p_src->i_margin_percent_v;
 }
 
+static ttml_style_t* DuplicateStyle( ttml_style_t* p_style_src )
+{
+    ttml_style_t* p_style = calloc( 1, sizeof( *p_style ) );
+    if( unlikely( p_style == NULL ) )
+        return NULL;
+
+    *p_style = *p_style_src;
+    p_style->psz_styleid = strdup( p_style_src->psz_styleid );
+    if( unlikely( p_style->psz_styleid == NULL ) )
+    {
+        free( p_style );
+        return NULL;
+    }
+
+    p_style->font_style = text_style_Duplicate( p_style_src->font_style );
+    if( unlikely( p_style->font_style == NULL ) )
+    {
+        free( p_style->psz_styleid );
+        free( p_style );
+        return NULL;
+    }
+    return p_style;
+}
+
 static void CleanupStyle( ttml_style_t* p_ttml_style )
 {
     text_style_Delete( p_ttml_style->font_style );
@@ -113,7 +137,8 @@ static ttml_style_t *FindTextStyle( decoder_t *p_dec, const char *psz_style )
     for( size_t i = 0; i < p_sys->i_styles; i++ )
     {
         if( !strcmp( p_sys->pp_styles[i]->psz_styleid, psz_style ) )
-            return p_sys->pp_styles[i];
+            return DuplicateStyle( p_sys->pp_styles[i] );
+
     }
     return NULL;
 }
@@ -193,7 +218,10 @@ static ttml_style_t* ParseTTMLStyle( decoder_t *p_dec, xml_reader_t* p_reader, c
                 {
                     if( !strcasecmp( p_sys->pp_styles[i]->psz_styleid, val ) )
                     {
-                        p_base_style = p_sys->pp_styles[i];
+                        p_base_style = DuplicateStyle( p_sys->pp_styles[i] );
+                        if( unlikely( p_base_style == NULL ) )
+                            return NULL;
+
                         break;
                     }
                 }



More information about the vlc-commits mailing list