[vlc-devel] [PATCH v2 05/14] picture: use picture_DestroyDummy for picture_NewFromFormat() with no planes

Steve Lhomme robux4 at ycbcr.xyz
Fri Aug 14 14:01:40 CEST 2020


No need to set the gc to some values and then change it later. We don't need to
reset the opaque and p_sys, we just need to use picture_DestroyDummy when we know.

We keep setting p_sys to NULL for compatibility.

No need to pass a value in the gc.opaque as we don't use it, even for
picture_DestroyFromFormat.
---
 src/misc/picture.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/misc/picture.c b/src/misc/picture.c
index 3c23d1230d4..92e5087f648 100644
--- a/src/misc/picture.c
+++ b/src/misc/picture.c
@@ -67,8 +67,7 @@ static void picture_DestroyFromFormat(picture_t *pic)
 {
     picture_buffer_t *res = pic->p_sys;
 
-    if (res != NULL)
-        picture_Deallocate(res->fd, res->base, res->size);
+    picture_Deallocate(res->fd, res->base, res->size);
 }
 
 VLC_WEAK void *picture_Allocate(int *restrict fdp, size_t size)
@@ -269,14 +268,16 @@ picture_t *picture_NewFromFormat(const video_format_t *restrict fmt)
 
     picture_t *pic = &priv->picture;
 
-    pic->p_sys = res;
-    priv->gc = (picture_gc_t) { picture_DestroyFromFormat, NULL };
-
     if (pic->i_planes == 0) {
-        pic->p_sys = NULL; // not compatible with picture_DestroyFromFormat
+        pic->p_sys = NULL;
+        // we allocated a picture_priv_buffer_t for nothing
+        priv->gc = (picture_gc_t) { picture_DestroyDummy, NULL };
         return pic;
     }
 
+    pic->p_sys = res;
+    priv->gc = (picture_gc_t) { picture_DestroyFromFormat, res };
+
     /* Calculate how big the new image should be */
     assert(pic->i_planes <= PICTURE_PLANE_MAX);
     size_t plane_sizes[PICTURE_PLANE_MAX];
-- 
2.26.2



More information about the vlc-devel mailing list