[vlc-commits] picture: separate destroy callbacks

Rémi Denis-Courmont git at videolan.org
Thu Oct 30 18:28:10 CET 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Oct 30 18:02:27 2014 +0200| [7609918fc2e99dc7a0e163e13aec6e57bfd9b02b] | committer: Rémi Denis-Courmont

picture: separate destroy callbacks

Use a separate callback for pictures allocated in heap and pictures
allocated from video output buffers.

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

 src/misc/picture.c |   30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/misc/picture.c b/src/misc/picture.c
index 7c6fa6a..358de65 100644
--- a/src/misc/picture.c
+++ b/src/misc/picture.c
@@ -68,7 +68,6 @@ static int AllocatePicture( picture_t *p_pic )
         p_pic->i_planes = 0;
         return VLC_EGENERIC;
     }
-    p_pic->gc.p_sys = (void *)p_data;
 
     /* Fill the p_pixels field for each plane */
     p_pic->p[0].p_pixels = p_data;
@@ -96,16 +95,26 @@ static void PictureDestroyContext( picture_t *p_picture )
     }
 }
 
-static void PictureDestroy( picture_t *p_picture )
+/**
+ * Destroys a picture allocated by picture_NewFromResource() but without
+ * a custom destruction callback.
+ */
+static void picture_DestroyFromResource( picture_t *p_picture )
 {
-    assert( p_picture &&
-            atomic_load( &p_picture->gc.refcount ) == 0 );
-
-    vlc_free( p_picture->gc.p_sys );
     free( p_picture->p_sys );
     free( p_picture );
 }
 
+/**
+ * Destroys a picture allocated with picture_NewFromFormat()
+ * (and thus AllocatePicture()).
+ */
+static void picture_Destroy( picture_t *p_picture )
+{
+    vlc_free( p_picture->p[0].p_pixels );
+    free( p_picture );
+}
+
 /*****************************************************************************
  *
  *****************************************************************************/
@@ -140,7 +149,6 @@ int picture_Setup( picture_t *p_picture, const video_format_t *restrict fmt )
     }
 
     atomic_init( &p_picture->gc.refcount, 0 );
-    p_picture->gc.pf_destroy = NULL;
     p_picture->gc.p_sys = NULL;
 
     p_picture->i_nb_fields = 2;
@@ -226,7 +234,8 @@ picture_t *picture_NewFromResource( const video_format_t *p_fmt, const picture_r
     {
         p_picture->p_sys = p_resource->p_sys;
         p_picture->gc.pf_destroy = p_resource->pf_destroy;
-        assert( p_picture->gc.p_sys == NULL );
+        if( p_picture->gc.pf_destroy == NULL )
+            p_picture->gc.pf_destroy = picture_DestroyFromResource;
 
         for( int i = 0; i < p_picture->i_planes; i++ )
         {
@@ -242,14 +251,13 @@ picture_t *picture_NewFromResource( const video_format_t *p_fmt, const picture_r
             free( p_picture );
             return NULL;
         }
+        p_picture->gc.pf_destroy = picture_Destroy;
     }
 
     /* */
     p_picture->format = fmt;
 
     atomic_init( &p_picture->gc.refcount, 1 );
-    if( p_picture->gc.pf_destroy == NULL )
-        p_picture->gc.pf_destroy = PictureDestroy;
 
     return p_picture;
 }
@@ -282,6 +290,8 @@ picture_t *picture_Hold( picture_t *p_picture )
 
 void picture_Release( picture_t *p_picture )
 {
+    assert( p_picture != NULL );
+
     uintptr_t refs = atomic_fetch_sub( &p_picture->gc.refcount, 1 );
     assert( refs != 0 );
     if( refs > 1 )



More information about the vlc-commits mailing list