From 40b557db6a64f56916efc02f52e67f51f3eb5001 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 25 Oct 2019 22:36:19 +0200 Subject: mp_image: move buffer ref assigning to a function Mostly untested, for the next commit. There's another case of this in this file (ref_buffer()), but it's too weird, so ignore it. --- video/mp_image.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/video/mp_image.c b/video/mp_image.c index 3b8307573f..5d0caca977 100644 --- a/video/mp_image.c +++ b/video/mp_image.c @@ -493,6 +493,15 @@ static enum mp_csp mp_image_params_get_forced_csp(struct mp_image_params *params return mp_imgfmt_get_forced_csp(imgfmt); } +static void assign_bufref(AVBufferRef **dst, AVBufferRef *new) +{ + av_buffer_unref(dst); + if (new) { + *dst = av_buffer_ref(new); + MP_HANDLE_OOM(*dst); + } +} + void mp_image_copy_attributes(struct mp_image *dst, struct mp_image *src) { dst->pict_type = src->pict_type; @@ -517,13 +526,7 @@ void mp_image_copy_attributes(struct mp_image *dst, struct mp_image *src) memcpy(dst->planes[1], src->planes[1], AVPALETTE_SIZE); } } - av_buffer_unref(&dst->icc_profile); - dst->icc_profile = src->icc_profile; - if (dst->icc_profile) { - dst->icc_profile = av_buffer_ref(dst->icc_profile); - if (!dst->icc_profile) - abort(); - } + assign_bufref(&dst->icc_profile, src->icc_profile); } // Crop the given image to (x0, y0)-(x1, y1) (bottom/right border exclusive) -- cgit v1.2.3