[vlc-devel] [PATCH v3 12/12] picture: use no gc for picture_NewFromFormat() with no planes
Steve Lhomme
robux4 at ycbcr.xyz
Tue Aug 18 08:24:53 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.
No need to pass a value in the gc.opaque as we don't use it, even for
picture_DestroyFromFormat.
Now picture_Deallocate can never be called with NULL.
---
src/misc/picture.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/src/misc/picture.c b/src/misc/picture.c
index 9b251398bb3..17b587c2b6d 100644
--- a/src/misc/picture.c
+++ b/src/misc/picture.c
@@ -58,8 +58,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)
@@ -239,22 +238,21 @@ picture_t *picture_NewFromFormat(const video_format_t *restrict fmt)
if (unlikely(privbuf == NULL))
return NULL;
- picture_buffer_t *res = &privbuf->res;
-
picture_priv_t *priv = &privbuf->priv;
if (!picture_InitPrivate(fmt, &priv->picture))
goto error;
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
+ // we allocated a picture_priv_buffer_t for nothing
return pic;
}
+ picture_buffer_t *res = &privbuf->res;
+ 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