From patchwork Fri Jun 5 10:02:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 20154 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id ED8B744AC59 for ; Fri, 5 Jun 2020 13:02:36 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C2AD468B0AD; Fri, 5 Jun 2020 13:02:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (unknown [176.97.15.10]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5375568AF9A for ; Fri, 5 Jun 2020 13:02:30 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 8208528A96B for ; Fri, 5 Jun 2020 12:02:29 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Ptk0ERhCkvtm for ; Fri, 5 Jun 2020 12:02:26 +0200 (CEST) Received: from quelana.khirnov.net (quelana.khirnov.net [IPv6:2a00:c500:561:200::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "quelana.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 61AD028A945 for ; Fri, 5 Jun 2020 12:02:26 +0200 (CEST) Received: from localhost (quelana.khirnov.net [IPv6:::1]) by quelana.khirnov.net (Postfix) with ESMTP id 201AD22E36 for ; Fri, 5 Jun 2020 12:02:26 +0200 (CEST) Received: from quelana.khirnov.net ([IPv6:::1]) by localhost (quelana.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id ElboLQq9cGvd for ; Fri, 5 Jun 2020 12:02:24 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) by quelana.khirnov.net (Postfix) with ESMTP id 177E520278 for ; Fri, 5 Jun 2020 12:02:24 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id A9C5C20E0099; Fri, 5 Jun 2020 12:02:22 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Jun 2020 12:02:16 +0200 Message-Id: <20200605100219.14930-1-anton@khirnov.net> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] lavu/buffer: add a convenience function for replacing buffers X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" A common pattern e.g. in libavcodec is replacing/updating buffer references: unref old one, ref new one. This function allows simplifying such code an avoiding unnecessary refs+unrefs if the references are already equivalent. --- doc/APIchanges | 3 +++ libavutil/buffer.c | 22 ++++++++++++++++++++++ libavutil/buffer.h | 17 +++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/doc/APIchanges b/doc/APIchanges index fb5534b5f5..757d814eee 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,9 @@ libavutil: 2017-10-21 API changes, most recent first: +2020-xx-xx - xxxxxxxxxx - lavc 56.50.100 - buffer.h + Add a av_buffer_replace() convenience function. + 2020-xx-xx - xxxxxxxxxx - lavc 58.88.100 - avcodec.h codec.h Move AVCodec-related public API to new header codec.h. diff --git a/libavutil/buffer.c b/libavutil/buffer.c index 6d9cb7428e..ecd83da9c3 100644 --- a/libavutil/buffer.c +++ b/libavutil/buffer.c @@ -216,6 +216,28 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size) return 0; } +int av_buffer_replace(AVBufferRef **pdst, AVBufferRef *src) +{ + AVBufferRef *dst = *pdst; + + if (!src) { + av_buffer_unref(pdst); + return !!dst; + } + + if (dst && dst->buffer == src->buffer) { + /* make sure the data pointers match */ + dst->data = src->data; + dst->size = src->size; + return 0; + } + + av_buffer_unref(pdst); + *pdst = av_buffer_ref(src); + + return *pdst ? 1 : AVERROR(ENOMEM); +} + AVBufferPool *av_buffer_pool_init2(int size, void *opaque, AVBufferRef* (*alloc)(void *opaque, int size), void (*pool_free)(void *opaque)) diff --git a/libavutil/buffer.h b/libavutil/buffer.h index e0f94314f4..497dc98c20 100644 --- a/libavutil/buffer.h +++ b/libavutil/buffer.h @@ -197,6 +197,23 @@ int av_buffer_make_writable(AVBufferRef **buf); */ int av_buffer_realloc(AVBufferRef **buf, int size); +/** + * Ensure dst refers to the same data as src. + * + * When *dst is already equivalent to src, do nothing. Otherwise unreference dst + * and replace it with a new reference to src. + * + * @param dst Pointer to either a valid buffer reference or NULL. On success, + * this will point to a buffer reference equivalent to src. On + * failure, dst will be unreferenced. + * @param src A buffer reference to replace dst with. May be NULL, then this + * function is equivalent to av_buffer_unref(dst). + * @return 0 if dst was equivalent to src on input and nothing was done + * 1 if dst was replaced with a new reference to src + * A negative error code on failure. + */ +int av_buffer_replace(AVBufferRef **dst, AVBufferRef *src); + /** * @} */ From patchwork Fri Jun 5 10:02:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 20156 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id D931144AC59 for ; Fri, 5 Jun 2020 13:02:40 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C4A0568B0BF; Fri, 5 Jun 2020 13:02:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (unknown [176.97.15.10]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1D05768B0B2 for ; Fri, 5 Jun 2020 13:02:34 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 9672D28A956 for ; Fri, 5 Jun 2020 12:02:33 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id MlmLiYaoIfVp for ; Fri, 5 Jun 2020 12:02:32 +0200 (CEST) Received: from quelana.khirnov.net (quelana.khirnov.net [IPv6:2a00:c500:561:200::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) client-signature RSA-PSS (2048 bits)) (Client CN "quelana.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 4210D28A962 for ; Fri, 5 Jun 2020 12:02:27 +0200 (CEST) Received: from localhost (quelana.khirnov.net [IPv6:::1]) by quelana.khirnov.net (Postfix) with ESMTP id 1E32A22E06 for ; Fri, 5 Jun 2020 12:02:27 +0200 (CEST) Received: from quelana.khirnov.net ([IPv6:::1]) by localhost (quelana.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id iivGEV60Nw0S for ; Fri, 5 Jun 2020 12:02:26 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) by quelana.khirnov.net (Postfix) with ESMTP id 1B5E022E10 for ; Fri, 5 Jun 2020 12:02:24 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id C367E20E0040; Fri, 5 Jun 2020 12:02:22 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Jun 2020 12:02:17 +0200 Message-Id: <20200605100219.14930-2-anton@khirnov.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200605100219.14930-1-anton@khirnov.net> References: <20200605100219.14930-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/4] hevcdec: use av_buffer_replace() to simplify code X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavcodec/hevcdec.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 0772608a30..94fd6f6e0d 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -3420,30 +3420,21 @@ static int hevc_update_thread_context(AVCodecContext *dst, if (s->ps.sps != s0->ps.sps) s->ps.sps = NULL; for (i = 0; i < FF_ARRAY_ELEMS(s->ps.vps_list); i++) { - av_buffer_unref(&s->ps.vps_list[i]); - if (s0->ps.vps_list[i]) { - s->ps.vps_list[i] = av_buffer_ref(s0->ps.vps_list[i]); - if (!s->ps.vps_list[i]) - return AVERROR(ENOMEM); - } + ret = av_buffer_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]); + if (ret < 0) + return ret; } for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) { - av_buffer_unref(&s->ps.sps_list[i]); - if (s0->ps.sps_list[i]) { - s->ps.sps_list[i] = av_buffer_ref(s0->ps.sps_list[i]); - if (!s->ps.sps_list[i]) - return AVERROR(ENOMEM); - } + ret = av_buffer_replace(&s->ps.sps_list[i], s0->ps.sps_list[i]); + if (ret < 0) + return ret; } for (i = 0; i < FF_ARRAY_ELEMS(s->ps.pps_list); i++) { - av_buffer_unref(&s->ps.pps_list[i]); - if (s0->ps.pps_list[i]) { - s->ps.pps_list[i] = av_buffer_ref(s0->ps.pps_list[i]); - if (!s->ps.pps_list[i]) - return AVERROR(ENOMEM); - } + ret = av_buffer_replace(&s->ps.pps_list[i], s0->ps.pps_list[i]); + if (ret < 0) + return ret; } if (s->ps.sps != s0->ps.sps) @@ -3468,12 +3459,9 @@ static int hevc_update_thread_context(AVCodecContext *dst, s->max_ra = INT_MAX; } - av_buffer_unref(&s->sei.a53_caption.buf_ref); - if (s0->sei.a53_caption.buf_ref) { - s->sei.a53_caption.buf_ref = av_buffer_ref(s0->sei.a53_caption.buf_ref); - if (!s->sei.a53_caption.buf_ref) - return AVERROR(ENOMEM); - } + ret = av_buffer_replace(&s->sei.a53_caption.buf_ref, s0->sei.a53_caption.buf_ref); + if (ret < 0) + return ret; s->sei.frame_packing = s0->sei.frame_packing; s->sei.display_orientation = s0->sei.display_orientation; From patchwork Fri Jun 5 10:02:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 20157 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id CA4C644AC59 for ; Fri, 5 Jun 2020 13:02:42 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AE4B468B0D3; Fri, 5 Jun 2020 13:02:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (unknown [176.97.15.10]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C7DFD68B0BE for ; Fri, 5 Jun 2020 13:02:34 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id 54B5928A962 for ; Fri, 5 Jun 2020 12:02:34 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id kKbjxUIVo_Hd for ; Fri, 5 Jun 2020 12:02:26 +0200 (CEST) Received: from quelana.khirnov.net (quelana.khirnov.net [IPv6:2a00:c500:561:200::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "quelana.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 6301C28A950 for ; Fri, 5 Jun 2020 12:02:26 +0200 (CEST) Received: from localhost (quelana.khirnov.net [IPv6:::1]) by quelana.khirnov.net (Postfix) with ESMTP id 24E3E22E4E for ; Fri, 5 Jun 2020 12:02:26 +0200 (CEST) Received: from quelana.khirnov.net ([IPv6:::1]) by localhost (quelana.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id dU8RyGCiHVag for ; Fri, 5 Jun 2020 12:02:24 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) by quelana.khirnov.net (Postfix) with ESMTP id 197A022E06 for ; Fri, 5 Jun 2020 12:02:24 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id E083520E009B; Fri, 5 Jun 2020 12:02:22 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Jun 2020 12:02:18 +0200 Message-Id: <20200605100219.14930-3-anton@khirnov.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200605100219.14930-1-anton@khirnov.net> References: <20200605100219.14930-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/4] mpegvideo: use av_buffer_replace() to simplify code X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavcodec/mpegpicture.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c index 5fce25ec6e..59097fab0c 100644 --- a/libavcodec/mpegpicture.c +++ b/libavcodec/mpegpicture.c @@ -320,30 +320,22 @@ void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *pic) int ff_update_picture_tables(Picture *dst, Picture *src) { - int i; - -#define UPDATE_TABLE(table) \ -do { \ - if (src->table && \ - (!dst->table || dst->table->buffer != src->table->buffer)) { \ - av_buffer_unref(&dst->table); \ - dst->table = av_buffer_ref(src->table); \ - if (!dst->table) { \ - ff_free_picture_tables(dst); \ - return AVERROR(ENOMEM); \ - } \ - } \ -} while (0) + int i, ret; - UPDATE_TABLE(mb_var_buf); - UPDATE_TABLE(mc_mb_var_buf); - UPDATE_TABLE(mb_mean_buf); - UPDATE_TABLE(mbskip_table_buf); - UPDATE_TABLE(qscale_table_buf); - UPDATE_TABLE(mb_type_buf); + ret = av_buffer_replace(&dst->mb_var_buf, src->mb_var_buf); + ret |= av_buffer_replace(&dst->mc_mb_var_buf, src->mc_mb_var_buf); + ret |= av_buffer_replace(&dst->mb_mean_buf, src->mb_mean_buf); + ret |= av_buffer_replace(&dst->mbskip_table_buf, src->mbskip_table_buf); + ret |= av_buffer_replace(&dst->qscale_table_buf, src->qscale_table_buf); + ret |= av_buffer_replace(&dst->mb_type_buf, src->mb_type_buf); for (i = 0; i < 2; i++) { - UPDATE_TABLE(motion_val_buf[i]); - UPDATE_TABLE(ref_index_buf[i]); + ret |= av_buffer_replace(&dst->motion_val_buf[i], src->motion_val_buf[i]); + ret |= av_buffer_replace(&dst->ref_index_buf[i], src->ref_index_buf[i]); + } + + if (ret < 0) { + ff_free_picture_tables(dst); + return ret; } dst->mb_var = src->mb_var; From patchwork Fri Jun 5 10:02:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 20155 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 005D144AC59 for ; Fri, 5 Jun 2020 13:02:40 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DB63D68B0C7; Fri, 5 Jun 2020 13:02:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.red.khirnov.net (unknown [176.97.15.10]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4550D68B0B2 for ; Fri, 5 Jun 2020 13:02:33 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail.red.khirnov.net (Postfix) with ESMTP id C79B828A945 for ; Fri, 5 Jun 2020 12:02:32 +0200 (CEST) Received: from mail.red.khirnov.net ([IPv6:::1]) by localhost (mail.red.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Gt2mW4YZLBWz for ; Fri, 5 Jun 2020 12:02:29 +0200 (CEST) Received: from quelana.khirnov.net (quelana.khirnov.net [IPv6:2a00:c500:561:200::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) client-signature RSA-PSS (2048 bits)) (Client CN "quelana.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail.red.khirnov.net (Postfix) with ESMTPS id 1D0FE28A956 for ; Fri, 5 Jun 2020 12:02:27 +0200 (CEST) Received: from localhost (quelana.khirnov.net [IPv6:::1]) by quelana.khirnov.net (Postfix) with ESMTP id E8C7C20278 for ; Fri, 5 Jun 2020 12:02:26 +0200 (CEST) Received: from quelana.khirnov.net ([IPv6:::1]) by localhost (quelana.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id uL5x30jOz2Sz for ; Fri, 5 Jun 2020 12:02:26 +0200 (CEST) Received: from libav.daenerys.khirnov.net (libav.daenerys.khirnov.net [IPv6:2a00:c500:561:201::7]) by quelana.khirnov.net (Postfix) with ESMTP id 1E3B322E26 for ; Fri, 5 Jun 2020 12:02:24 +0200 (CEST) Received: by libav.daenerys.khirnov.net (Postfix, from userid 1000) id F239D20E00E7; Fri, 5 Jun 2020 12:02:22 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Fri, 5 Jun 2020 12:02:19 +0200 Message-Id: <20200605100219.14930-4-anton@khirnov.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200605100219.14930-1-anton@khirnov.net> References: <20200605100219.14930-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/4] pthread_frame: use av_buffer_replace() to simplify code X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavcodec/pthread_frame.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 601f170447..3626e745f5 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -297,16 +297,9 @@ static int update_context_from_thread(AVCodecContext *dst, AVCodecContext *src, dst->hwaccel_flags = src->hwaccel_flags; - if (!!dst->internal->pool != !!src->internal->pool || - (dst->internal->pool && dst->internal->pool->data != src->internal->pool->data)) { - av_buffer_unref(&dst->internal->pool); - - if (src->internal->pool) { - dst->internal->pool = av_buffer_ref(src->internal->pool); - if (!dst->internal->pool) - return AVERROR(ENOMEM); - } - } + err = av_buffer_replace(&dst->internal->pool, src->internal->pool); + if (err < 0) + return err; } if (for_user) {