[vlc-commits] es: cleaner handling of the video palette

Steve Lhomme git at videolan.org
Sat Apr 16 11:11:54 CEST 2016


vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Sat Apr 16 11:57:43 2016 +0300| [85a305d292ac5e5b509bf46f58b6405f0fe4a902] | committer: Jean-Baptiste Kempf

es: cleaner handling of the video palette

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 include/vlc_es.h      |    1 -
 src/misc/es_format.c  |   13 ++++---------
 src/misc/subpicture.c |   25 +++++++++----------------
 3 files changed, 13 insertions(+), 26 deletions(-)

diff --git a/include/vlc_es.h b/include/vlc_es.h
index 97cdb78..cbd03e5 100644
--- a/include/vlc_es.h
+++ b/include/vlc_es.h
@@ -261,7 +261,6 @@ static inline void video_format_Clean( video_format_t *p_src )
 {
     free( p_src->p_palette );
     memset( p_src, 0, sizeof( video_format_t ) );
-    p_src->p_palette = NULL;
 }
 
 /**
diff --git a/src/misc/es_format.c b/src/misc/es_format.c
index bdd57bb..0375767 100644
--- a/src/misc/es_format.c
+++ b/src/misc/es_format.c
@@ -506,14 +506,9 @@ int es_format_Copy(es_format_t *restrict dst, const es_format_t *src)
             ret = VLC_ENOMEM;
     }
 
-    if (src->video.p_palette != NULL)
-    {
-        dst->video.p_palette = malloc(sizeof (video_palette_t));
-        if (likely(dst->video.p_palette != NULL))
-            *dst->video.p_palette = *src->video.p_palette;
-        else
-            ret = VLC_ENOMEM;
-    }
+    int err = video_format_Copy( &dst->video, &src->video );
+    if ( err != VLC_SUCCESS )
+        return err;
 
     if (src->i_extra_languages > 0)
     {
@@ -547,7 +542,7 @@ void es_format_Clean(es_format_t *fmt)
     assert(fmt->i_extra == 0 || fmt->p_extra != NULL);
     free(fmt->p_extra);
 
-    free(fmt->video.p_palette);
+    video_format_Clean( &fmt->video );
     free(fmt->subs.psz_encoding);
 
     if (fmt->subs.p_style != NULL)
diff --git a/src/misc/subpicture.c b/src/misc/subpicture.c
index 2638bd0..7f5d109 100644
--- a/src/misc/subpicture.c
+++ b/src/misc/subpicture.c
@@ -185,13 +185,8 @@ subpicture_region_private_t *subpicture_region_private_New( video_format_t *p_fm
     if( !p_private )
         return NULL;
 
-    p_private->fmt = *p_fmt;
-    if( p_fmt->p_palette )
-    {
-        p_private->fmt.p_palette = malloc( sizeof(*p_private->fmt.p_palette) );
-        if( p_private->fmt.p_palette )
-            *p_private->fmt.p_palette = *p_fmt->p_palette;
-    }
+    if ( video_format_Copy( &p_private->fmt, p_fmt ) != VLC_SUCCESS )
+        return NULL;
     p_private->p_picture = NULL;
 
     return p_private;
@@ -201,7 +196,7 @@ void subpicture_region_private_Delete( subpicture_region_private_t *p_private )
 {
     if( p_private->p_picture )
         picture_Release( p_private->p_picture );
-    free( p_private->fmt.p_palette );
+    video_format_Clean( &p_private->fmt );
     free( p_private );
 }
 
@@ -211,13 +206,11 @@ subpicture_region_t *subpicture_region_New( const video_format_t *p_fmt )
     if( !p_region )
         return NULL;
 
-    p_region->fmt = *p_fmt;
-    p_region->fmt.p_palette = NULL;
-    if( p_fmt->i_chroma == VLC_CODEC_YUVP )
+    video_format_Copy( &p_region->fmt, p_fmt );
+    if ( p_fmt->i_chroma != VLC_CODEC_YUVP )
     {
-        p_region->fmt.p_palette = calloc( 1, sizeof(*p_region->fmt.p_palette) );
-        if( p_fmt->p_palette )
-            *p_region->fmt.p_palette = *p_fmt->p_palette;
+        free( p_region->fmt.p_palette );
+        p_region->fmt.p_palette = NULL;
     }
     p_region->i_alpha = 0xff;
 
@@ -227,7 +220,7 @@ subpicture_region_t *subpicture_region_New( const video_format_t *p_fmt )
     p_region->p_picture = picture_NewFromFormat( p_fmt );
     if( !p_region->p_picture )
     {
-        free( p_region->fmt.p_palette );
+        video_format_Clean( &p_region->fmt );
         free( p_region );
         return NULL;
     }
@@ -247,7 +240,7 @@ void subpicture_region_Delete( subpicture_region_t *p_region )
         picture_Release( p_region->p_picture );
 
     text_segment_ChainDelete( p_region->p_text );
-    free( p_region->fmt.p_palette );
+    video_format_Clean( &p_region->fmt );
     free( p_region );
 }
 



More information about the vlc-commits mailing list