[vlc-devel] [PATCH v3 11/12] picture: do not use picture_NewFromResource for picture_InternalClone

Steve Lhomme robux4 at ycbcr.xyz
Tue Aug 18 08:24:52 CEST 2020


picture_InternalClone() doesn't need to call picture_NewFromResource() and
cast the result anymore. It creates its own picture_priv_t.

We check/set the gc of the clone before initializing the picture_priv_t. It
doesn't need to be passed in the fake resource anymore.

We can use the picture planes directly, rather than setting up a fake resource
structure to set the same fields.
---
 src/misc/picture.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/src/misc/picture.c b/src/misc/picture.c
index 183a7969e39..9b251398bb3 100644
--- a/src/misc/picture.c
+++ b/src/misc/picture.c
@@ -398,19 +398,24 @@ static void picture_DestroyClone(picture_t *clone)
 
 picture_t *picture_InternalClone(picture_t *picture, picture_gc_t *pic_gc)
 {
-    picture_resource_t res = {
-        .p_sys = picture->p_sys,
-    };
+    picture_priv_t *clone = calloc(1, sizeof(*clone));
+    if (unlikely(clone == NULL))
+        return NULL;
+    if (unlikely(!picture_InitPrivate(&picture->format, &clone->picture))) {
+        free(clone);
+        return NULL;
+    }
 
-    picture_t *clone = picture_NewFromResource(&picture->format, &res);
-    if (likely(clone != NULL)) {
-        for (int i = 0; i < picture->i_planes; i++) {
-            clone->p[i] = picture->p[i];
-        }
-        ((picture_priv_t *)clone)->gc = *pic_gc;
-        picture_Hold(picture);
+    assert(pic_gc->destroy != NULL); // we need to release the held picture
+    clone->gc = *pic_gc;
+
+    clone->picture.p_sys = picture->p_sys;
+    for( int i = 0; i < clone->picture.i_planes; i++ )
+    {
+        clone->picture.p[i] = picture->p[i];
     }
-    return clone;
+    picture_Hold(picture);
+    return &clone->picture;
 }
 
 picture_t *picture_Clone(picture_t *picture)
-- 
2.26.2



More information about the vlc-devel mailing list