[vlc-devel] [PATCH 3/3] picture: always init the picture p_sys/destroy in picture_InitPrivate()

Steve Lhomme robux4 at ycbcr.xyz
Fri Nov 15 10:04:01 CET 2019


---
 src/misc/picture.c | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/src/misc/picture.c b/src/misc/picture.c
index 5a7158fe0bc..e46c945ec58 100644
--- a/src/misc/picture.c
+++ b/src/misc/picture.c
@@ -194,7 +194,8 @@ int picture_Setup( picture_t *p_picture, const video_format_t *restrict fmt )
  *****************************************************************************/
 
 static bool picture_InitPrivate(const video_format_t *restrict p_fmt,
-                                picture_priv_t *priv)
+                                picture_priv_t *priv,
+                                const picture_resource_t *p_resource)
 {
     picture_t *p_picture = &priv->picture;
 
@@ -210,6 +211,14 @@ static bool picture_InitPrivate(const video_format_t *restrict p_fmt,
 
     atomic_init(&p_picture->refs, 1);
     priv->gc.opaque = NULL;
+
+    p_picture->p_sys = p_resource->p_sys;
+
+    if( p_resource->pf_destroy != NULL )
+        priv->gc.destroy = p_resource->pf_destroy;
+    else
+        priv->gc.destroy = picture_DestroyDummy;
+
     return true;
 }
 
@@ -221,7 +230,7 @@ picture_t *picture_NewFromResource( const video_format_t *p_fmt, const picture_r
     if( unlikely(priv == NULL) )
         return NULL;
 
-    if (!picture_InitPrivate(p_fmt, priv))
+    if (!picture_InitPrivate(p_fmt, priv, p_resource))
     {
         free(priv);
         return NULL;
@@ -229,13 +238,6 @@ picture_t *picture_NewFromResource( const video_format_t *p_fmt, const picture_r
 
     picture_t *p_picture = &priv->picture;
 
-    p_picture->p_sys = p_resource->p_sys;
-
-    if( p_resource->pf_destroy != NULL )
-        priv->gc.destroy = p_resource->pf_destroy;
-    else
-        priv->gc.destroy = picture_DestroyDummy;
-
     for( int i = 0; i < p_picture->i_planes; i++ )
     {
         p_picture->p[i].p_pixels = p_resource->p[i].p_pixels;
@@ -262,18 +264,22 @@ picture_t *picture_NewFromFormat(const video_format_t *restrict fmt)
     if( unlikely(localpriv == NULL) )
         return NULL;
 
+    picture_buffer_t *res = &localpriv->res;
+
+    picture_resource_t pic_res = {
+        .p_sys = res,
+        .pf_destroy = picture_DestroyFromFormat,
+    };
+
     picture_priv_t *priv = &localpriv->priv;
-    if (!picture_InitPrivate(fmt, priv))
+    if (!picture_InitPrivate(fmt, priv, &pic_res))
     {
         free(priv);
         return NULL;
     }
 
-    priv->gc.destroy = picture_DestroyFromFormat;
-
     picture_t *pic = &priv->picture;
     if (pic->i_planes == 0) {
-        pic->p_sys = NULL;
         return pic;
     }
 
@@ -293,8 +299,6 @@ picture_t *picture_NewFromFormat(const video_format_t *restrict fmt)
     if (unlikely(pic_size >= PICTURE_SW_SIZE_MAX))
         goto error;
 
-    picture_buffer_t *res = &localpriv->res;
-
     unsigned char *buf = picture_Allocate(&res->fd, pic_size);
     if (unlikely(buf == NULL))
         goto error;
@@ -302,7 +306,6 @@ picture_t *picture_NewFromFormat(const video_format_t *restrict fmt)
     res->base = buf;
     res->size = pic_size;
     res->offset = 0;
-    pic->p_sys = res;
 
     /* Fill the p_pixels field for each plane */
     for (int i = 0; i < pic->i_planes; i++)
-- 
2.17.1



More information about the vlc-devel mailing list