[vlc-devel] [PATCH 12/19] chroma: copy: set the picture test buffers after picture_NewFromResource()

Steve Lhomme robux4 at ycbcr.xyz
Thu Jul 30 14:16:53 CEST 2020


---
 modules/video_chroma/copy.c | 49 +++++++++++++++++++++++++++++--------
 1 file changed, 39 insertions(+), 10 deletions(-)

diff --git a/modules/video_chroma/copy.c b/modules/video_chroma/copy.c
index 95fc17a3fcb..9c10d52ecc1 100644
--- a/modules/video_chroma/copy.c
+++ b/modules/video_chroma/copy.c
@@ -1015,6 +1015,18 @@ static const struct test_size sizes[] = {
 };
 #define NB_SIZES ARRAY_SIZE(sizes)
 
+typedef struct
+{
+    int i_planes;
+    struct
+    {
+        uint8_t *p_pixels;  /**< Start of the plane's data */
+        int i_lines;        /**< Number of lines, including margins */
+        int i_pitch;        /**< Number of bytes in a line, including margins */
+    } p[PICTURE_PLANE_MAX];
+
+} pic_resource_t;
+
 static void piccheck(picture_t *pic, const vlc_chroma_description_t *dsc,
                      bool init)
 {
@@ -1085,8 +1097,10 @@ static void piccheck(picture_t *pic, const vlc_chroma_description_t *dsc,
 
 static void pic_rsc_destroy(picture_t *pic)
 {
-    for (unsigned i = 0; i < 3; i++)
-        free(pic->p[i].p_pixels);
+    pic_resource_t *rsc = pic->p_sys;
+    for (unsigned i = 0; i < rsc->i_planes; i++)
+        free(rsc->p[i].p_pixels);
+    free(rsc);
 }
 
 static picture_t *pic_new_unaligned(const video_format_t *fmt)
@@ -1095,16 +1109,31 @@ static picture_t *pic_new_unaligned(const video_format_t *fmt)
      * from the source picture */
     const vlc_chroma_description_t *dsc = vlc_fourcc_GetChromaDescription(fmt->i_chroma);
     assert(dsc);
-    picture_resource_t rsc = {};
-    for (unsigned i = 0; i < dsc->plane_count; i++)
+    pic_resource_t *rsc = malloc(sizeof(*rsc));
+    if (unlikely(rsc == NULL))
+        return NULL;
+    rsc->i_planes = dsc->plane_count;
+    for (unsigned i = 0; i < rsc->i_planes; i++)
+    {
+        rsc->p[i].i_lines = ((fmt->i_visible_height + (dsc->p[i].h.den - 1)) / dsc->p[i].h.den) * dsc->p[i].h.num;
+        rsc->p[i].i_pitch = ((fmt->i_visible_width + (dsc->p[i].w.den - 1)) / dsc->p[i].w.den) * dsc->p[i].w.num * dsc->pixel_size;
+        rsc->p[i].p_pixels = malloc(rsc->p[i].i_lines * rsc->p[i].i_pitch);
+        assert(rsc->p[i].p_pixels);
+    }
+    picture_gc_t gc = { pic_rsc_destroy, rsc };
+    picture_t *pic = picture_NewFromResource(fmt, &gc, NULL);
+    if (unlikely(pic == NULL))
+    {
+        pic_rsc_destroy(rsc);
+        return NULL;
+    }
+    for (int i = 0; i < pic->i_planes; i++)
     {
-        rsc.p[i].i_lines = ((fmt->i_visible_height + (dsc->p[i].h.den - 1)) / dsc->p[i].h.den) * dsc->p[i].h.num;
-        rsc.p[i].i_pitch = ((fmt->i_visible_width + (dsc->p[i].w.den - 1)) / dsc->p[i].w.den) * dsc->p[i].w.num * dsc->pixel_size;
-        rsc.p[i].p_pixels = malloc(rsc.p[i].i_lines * rsc.p[i].i_pitch);
-        assert(rsc.p[i].p_pixels);
+        pic->p[i].i_lines  = rsc->p[i].i_lines;
+        pic->p[i].i_pitch  = rsc->p[i].i_pitch;
+        pic->p[i].p_pixels = rsc->p[i].p_pixels;
     }
-    picture_gc_t gc = { pic_rsc_destroy, NULL };
-    return picture_NewFromResource(fmt, &gc, &rsc);
+    return pic;
 }
 
 int main(void)
-- 
2.26.2



More information about the vlc-devel mailing list