From patchwork Wed Feb 24 08:40:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 25937 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 1C02344ACB5 for ; Wed, 24 Feb 2021 10:41:08 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DF5C168A1EB; Wed, 24 Feb 2021 10:41:07 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 49DEC687F3C for ; Wed, 24 Feb 2021 10:41:01 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 91B99240684 for ; Wed, 24 Feb 2021 09:41:00 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id Z2NaUI9iwTEg for ; Wed, 24 Feb 2021 09:40:56 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (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 "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 48AD724048A for ; Wed, 24 Feb 2021 09:40:56 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 289213A01E6; Wed, 24 Feb 2021 09:40:54 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 24 Feb 2021 09:40:42 +0100 Message-Id: <20210224084042.16065-1-anton@khirnov.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] lavc/lscrdec: use ff_reget_buffer() 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" It is simpler and more efficient. Suggested-by: James Almer --- libavcodec/lscrdec.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/libavcodec/lscrdec.c b/libavcodec/lscrdec.c index d5388c22ac..e706dda9da 100644 --- a/libavcodec/lscrdec.c +++ b/libavcodec/lscrdec.c @@ -105,7 +105,7 @@ static int decode_frame_lscr(AVCodecContext *avctx, { LSCRContext *const s = avctx->priv_data; GetByteContext *gb = &s->gb; - AVFrame *frame = data; + AVFrame *frame = s->last_picture; int ret, nb_blocks, offset = 0; if (avpkt->size < 2) @@ -115,18 +115,14 @@ static int decode_frame_lscr(AVCodecContext *avctx, bytestream2_init(gb, avpkt->data, avpkt->size); - if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0) - return ret; - nb_blocks = bytestream2_get_le16(gb); if (bytestream2_get_bytes_left(gb) < 2 + nb_blocks * (12 + 8)) return AVERROR_INVALIDDATA; - if (s->last_picture->data[0]) { - ret = av_frame_copy(frame, s->last_picture); - if (ret < 0) - return ret; - } + ret = ff_reget_buffer(avctx, frame, + nb_blocks ? 0 : FF_REGET_BUFFER_FLAG_READONLY); + if (ret < 0) + return ret; for (int b = 0; b < nb_blocks; b++) { int x, y, x2, y2, w, h, left; @@ -216,8 +212,7 @@ static int decode_frame_lscr(AVCodecContext *avctx, frame->pict_type = frame->key_frame ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; - av_frame_unref(s->last_picture); - if ((ret = av_frame_ref(s->last_picture, frame)) < 0) + if ((ret = av_frame_ref(data, frame)) < 0) return ret; *got_frame = 1;