From patchwork Mon Mar 1 18:36:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 26049 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 EFCB544A55B for ; Mon, 1 Mar 2021 20:43:21 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C70C368A86F; Mon, 1 Mar 2021 20:43:21 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2A0A168A4A3 for ; Mon, 1 Mar 2021 20:43:16 +0200 (EET) Received: by mail-qk1-f176.google.com with SMTP id f17so17661069qkl.5 for ; Mon, 01 Mar 2021 10:43:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=iLe4BlzKdbptMs91AwL8r1x2xKKswJw2xt00bONM9WQ=; b=H5vh5tNOm9xqBkwk+tZIUy73NmuQHVY9R1hX3ZbXohGRPBw1OWfBb9yIUjDhotr7Vw rwB0BbJfWJ8gS0h3uV7JiHdeiWcsdRvgAWgW7ZBq83YCr7NBTmx/c5Y1RNef4LD217eQ 9cLacCrODgOxhGvidrdrQ9xLYmun/x3Un7Qc6lT2iWR7I4qQWCTyXd9o4RpDWgo0l5DM grFJP23e6o86tirrqjyY6hwDiPf32GhCs4AP9ciQk+q3C7cEbRSn2CVou+n1F/Ppp7uL 0QAhQcskktUSRq4E4omjq00lhdz3AS6DlBC2VOF7TxMPmTNdsq58PLfn05X4dR3Kjykq dxaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=iLe4BlzKdbptMs91AwL8r1x2xKKswJw2xt00bONM9WQ=; b=LRXHl/Ov8HKF/3Of7StD0RbtSDsn51bXEUd+Jycn4A0u4dcGmsZ7Ay1irZaYE5lOvt dhoDyFeRqxSYdL4k9Xx0KaIlmJkOS5UGMl1PGt41PoUDe/d2yxXN6xR7F8rG0XtTI8g9 wms0g476AAWPkU+QeHbQcyntObtI020TJ3tynqn9wrIqzBFu9l3TqLGy3oCHzVtBZU5p 8W11r+hFZUZKC9ov3qsopnWxMSk9Py51oUavHXwVJOsBXlZV9AZKobykos2flt7R86f8 NevSqF8/vC7x1n2jf+lkYXEVZWYhhIWm7w0DmvTM5FKHRf7625eP7ZuLyuCRb27YU5nO wx7g== X-Gm-Message-State: AOAM5310gyCKCRO0+Ca9IdYEQhTngota7SSbwS2XUbuqrnizI+BFKYQ3 NLa17is654Zl5yoc3YMLSJ245XTLpfrOfQ== X-Google-Smtp-Source: ABdhPJwEeUcYu1W4DoCGwWKBCQExgSQf4FFZ64VafDcOB7lThXQLWspMUvaAF9yWePkzhFKwpBZd8Q== X-Received: by 2002:a05:620a:b01:: with SMTP id t1mr9483622qkg.422.1614623869416; Mon, 01 Mar 2021 10:37:49 -0800 (PST) Received: from localhost.localdomain ([181.23.89.132]) by smtp.gmail.com with ESMTPSA id p12sm11499047qtw.27.2021.03.01.10.37.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 10:37:48 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 1 Mar 2021 15:36:56 -0300 Message-Id: <20210301183656.58276-1-jamrial@gmail.com> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] avcodec/decode: port last_pkt_props to AVFifoBuffer 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" Signed-off-by: James Almer --- libavcodec/decode.c | 49 ++++++++++++++++++++++++++++++------------- libavcodec/internal.h | 4 ++-- libavcodec/utils.c | 26 +++++++++++++++++------ 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 8086362eb2..9d7cc107ae 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -145,24 +145,44 @@ fail2: #define IS_EMPTY(pkt) (!(pkt)->data) +static int copy_packet_props(AVPacket *dst, AVPacket *src) +{ + int ret = av_packet_copy_props(dst, src); + if (ret < 0) + return ret; + + dst->size = src->size; // HACK: Needed for ff_decode_frame_props(). + dst->data = (void*)1; // HACK: Needed for IS_EMPTY(). + + return 0; +} + static int extract_packet_props(AVCodecInternal *avci, AVPacket *pkt) { + AVPacket tmp = { 0 }; int ret = 0; - ret = avpriv_packet_list_put(&avci->pkt_props, &avci->pkt_props_tail, pkt, - av_packet_copy_props, 0); + if (IS_EMPTY(avci->last_pkt_props)) { + if (av_fifo_size(avci->pkt_props) >= sizeof(*pkt)) { + av_fifo_generic_read(avci->pkt_props, avci->last_pkt_props, + sizeof(*avci->last_pkt_props), NULL); + } else + return copy_packet_props(avci->last_pkt_props, pkt); + } + + if (av_fifo_space(avci->pkt_props) < sizeof(*pkt)) { + ret = av_fifo_grow(avci->pkt_props, sizeof(*pkt)); + if (ret < 0) + return ret; + } + + ret = copy_packet_props(&tmp, pkt); if (ret < 0) return ret; - avci->pkt_props_tail->pkt.size = pkt->size; // HACK: Needed for ff_decode_frame_props(). - avci->pkt_props_tail->pkt.data = (void*)1; // HACK: Needed for IS_EMPTY(). - if (IS_EMPTY(avci->last_pkt_props)) { - ret = avpriv_packet_list_get(&avci->pkt_props, - &avci->pkt_props_tail, - avci->last_pkt_props); - av_assert0(ret != AVERROR(EAGAIN)); - } - return ret; + av_fifo_generic_write(avci->pkt_props, &tmp, sizeof(tmp), NULL); + + return 0; } int ff_decode_bsfs_init(AVCodecContext *avctx) @@ -1726,10 +1746,9 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame) { AV_PKT_DATA_S12M_TIMECODE, AV_FRAME_DATA_S12M_TIMECODE }, }; - if (IS_EMPTY(pkt)) - avpriv_packet_list_get(&avctx->internal->pkt_props, - &avctx->internal->pkt_props_tail, - pkt); + if (IS_EMPTY(pkt) && av_fifo_size(avctx->internal->pkt_props) >= sizeof(*pkt)) + av_fifo_generic_read(avctx->internal->pkt_props, + pkt, sizeof(*pkt), NULL); if (pkt) { frame->pts = pkt->pts; diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 65760368d6..400ea508ef 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -28,6 +28,7 @@ #include "libavutil/buffer.h" #include "libavutil/channel_layout.h" +#include "libavutil/fifo.h" #include "libavutil/mathematics.h" #include "libavutil/pixfmt.h" #include "avcodec.h" @@ -147,8 +148,7 @@ typedef struct AVCodecInternal { * for decoding. */ AVPacket *last_pkt_props; - AVPacketList *pkt_props; - AVPacketList *pkt_props_tail; + AVFifoBuffer *pkt_props; /** * temporary buffer used for encoders to store their bitstream diff --git a/libavcodec/utils.c b/libavcodec/utils.c index db6cd0cde8..32d0288faa 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -594,9 +594,10 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code avci->es.in_frame = av_frame_alloc(); avci->ds.in_pkt = av_packet_alloc(); avci->last_pkt_props = av_packet_alloc(); + avci->pkt_props = av_fifo_alloc(sizeof(*avci->last_pkt_props)); if (!avci->buffer_frame || !avci->buffer_pkt || !avci->es.in_frame || !avci->ds.in_pkt || - !avci->last_pkt_props) { + !avci->last_pkt_props || !avci->pkt_props) { ret = AVERROR(ENOMEM); goto free_and_end; } @@ -1077,7 +1078,7 @@ FF_ENABLE_DEPRECATION_WARNINGS #endif av_frame_free(&avci->buffer_frame); av_packet_free(&avci->buffer_pkt); - av_packet_free(&avci->last_pkt_props); + av_fifo_freep(&avci->pkt_props); av_packet_free(&avci->ds.in_pkt); av_frame_free(&avci->es.in_frame); @@ -1120,8 +1121,13 @@ void avcodec_flush_buffers(AVCodecContext *avctx) av_packet_unref(avci->buffer_pkt); av_packet_unref(avci->last_pkt_props); - avpriv_packet_list_free(&avci->pkt_props, - &avci->pkt_props_tail); + while (av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props)) { + av_fifo_generic_read(avci->pkt_props, + avci->last_pkt_props, sizeof(*avci->last_pkt_props), + NULL); + av_packet_unref(avci->last_pkt_props); + } + av_fifo_reset(avci->pkt_props); av_frame_unref(avci->es.in_frame); av_packet_unref(avci->ds.in_pkt); @@ -1189,9 +1195,17 @@ av_cold int avcodec_close(AVCodecContext *avctx) #endif av_frame_free(&avctx->internal->buffer_frame); av_packet_free(&avctx->internal->buffer_pkt); + av_packet_unref(avctx->internal->last_pkt_props); + while (av_fifo_size(avctx->internal->pkt_props) >= + sizeof(*avctx->internal->last_pkt_props)) { + av_fifo_generic_read(avctx->internal->pkt_props, + avctx->internal->last_pkt_props, + sizeof(*avctx->internal->last_pkt_props), + NULL); + av_packet_unref(avctx->internal->last_pkt_props); + } av_packet_free(&avctx->internal->last_pkt_props); - avpriv_packet_list_free(&avctx->internal->pkt_props, - &avctx->internal->pkt_props_tail); + av_fifo_freep(&avctx->internal->pkt_props); av_packet_free(&avctx->internal->ds.in_pkt); av_frame_free(&avctx->internal->es.in_frame);