[vlc-devel] [PATCH 03/19] picture: pass the clone destructor via a picture_gc_t structure
Steve Lhomme
robux4 at ycbcr.xyz
Thu Jul 30 14:16:44 CEST 2020
Rather than internal fields in a bigger structure. It's really meant to release
the resources of the picture.
Always set the gc opaque to the resource p_sys.
Set picture_priv_t.gc outside of picture_InitPrivate().
---
src/misc/picture.c | 24 ++++++++++++------------
src/misc/picture.h | 16 +++++++++-------
src/misc/picture_pool.c | 4 ++--
3 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/src/misc/picture.c b/src/misc/picture.c
index e00b1303253..caea971a092 100644
--- a/src/misc/picture.c
+++ b/src/misc/picture.c
@@ -211,15 +211,9 @@ static bool picture_InitPrivate(const video_format_t *restrict p_fmt,
return false;
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;
}
@@ -237,6 +231,11 @@ picture_t *picture_NewFromResource( const video_format_t *p_fmt, const picture_r
return NULL;
}
+ priv->gc = (picture_gc_t) {
+ p_resource->pf_destroy ? p_resource->pf_destroy : picture_DestroyDummy,
+ p_resource->p_sys,
+ };
+
picture_t *p_picture = &priv->picture;
for( int i = 0; i < p_picture->i_planes; i++ )
@@ -269,7 +268,6 @@ picture_t *picture_NewFromFormat(const video_format_t *restrict fmt)
picture_resource_t pic_res = {
.p_sys = res,
- .pf_destroy = picture_DestroyFromFormat,
};
picture_priv_t *priv = &privbuf->priv;
@@ -277,6 +275,9 @@ picture_t *picture_NewFromFormat(const video_format_t *restrict fmt)
goto error;
picture_t *pic = &priv->picture;
+
+ priv->gc = (picture_gc_t) { picture_DestroyFromFormat, NULL };
+
if (pic->i_planes == 0) {
pic->p_sys = NULL; // not compatible with picture_DestroyFromFormat
return pic;
@@ -423,12 +424,10 @@ static void picture_DestroyClone(picture_t *clone)
picture_Release(picture);
}
-picture_t *picture_InternalClone(picture_t *picture,
- void (*pf_destroy)(picture_t *), void *opaque)
+picture_t *picture_InternalClone(picture_t *picture, picture_gc_t *pic_gc)
{
picture_resource_t res = {
.p_sys = picture->p_sys,
- .pf_destroy = pf_destroy,
};
for (int i = 0; i < picture->i_planes; i++) {
@@ -439,7 +438,7 @@ picture_t *picture_InternalClone(picture_t *picture,
picture_t *clone = picture_NewFromResource(&picture->format, &res);
if (likely(clone != NULL)) {
- ((picture_priv_t *)clone)->gc.opaque = opaque;
+ ((picture_priv_t *)clone)->gc = *pic_gc;
picture_Hold(picture);
}
return clone;
@@ -447,7 +446,8 @@ picture_t *picture_InternalClone(picture_t *picture,
picture_t *picture_Clone(picture_t *picture)
{
- picture_t *clone = picture_InternalClone(picture, picture_DestroyClone, picture);
+ picture_gc_t gc = { picture_DestroyClone, picture };
+ picture_t *clone = picture_InternalClone(picture, &gc);
if (likely(clone != NULL)) {
if (picture->context != NULL)
clone->context = picture->context->copy(picture->context);
diff --git a/src/misc/picture.h b/src/misc/picture.h
index 684eb2ada69..0afaca95f44 100644
--- a/src/misc/picture.h
+++ b/src/misc/picture.h
@@ -25,15 +25,17 @@
typedef struct
{
- picture_t picture;
- struct
- {
- void (*destroy)(picture_t *);
- void *opaque;
- } gc;
+ void (*destroy)(picture_t *);
+ void *opaque;
+} picture_gc_t;
+
+typedef struct
+{
+ picture_t picture;
+ picture_gc_t gc;
} picture_priv_t;
void *picture_Allocate(int *, size_t);
void picture_Deallocate(int, void *, size_t);
-picture_t * picture_InternalClone(picture_t *, void (*pf_destroy)(picture_t *), void *);
+picture_t * picture_InternalClone(picture_t *, picture_gc_t *);
diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c
index 988df70fb8d..0a2e4eaa433 100644
--- a/src/misc/picture_pool.c
+++ b/src/misc/picture_pool.c
@@ -90,8 +90,8 @@ static picture_t *picture_pool_ClonePicture(picture_pool_t *pool,
picture_t *picture = pool->picture[offset];
uintptr_t sys = ((uintptr_t)pool) + offset;
- picture_t *clone = picture_InternalClone(picture, picture_pool_ReleaseClone,
- (void*)sys);
+ picture_gc_t gc = { picture_pool_ReleaseClone, (void*)sys };
+ picture_t *clone = picture_InternalClone(picture, &gc);
if (clone != NULL) {
assert(clone->p_next == NULL);
atomic_fetch_add_explicit(&pool->refs, 1, memory_order_relaxed);
--
2.26.2
More information about the vlc-devel
mailing list