From patchwork Fri Dec 4 21:03:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 24346 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 DB61344A0E3 for ; Fri, 4 Dec 2020 23:04:51 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A71A368A5D3; Fri, 4 Dec 2020 23:04:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f65.google.com (mail-qv1-f65.google.com [209.85.219.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 06270689AA0 for ; Fri, 4 Dec 2020 23:04:45 +0200 (EET) Received: by mail-qv1-f65.google.com with SMTP id g19so3491784qvy.2 for ; Fri, 04 Dec 2020 13:04:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=G516YIFZjxAyFA6rPnLKz5INzuGiud5ts7gvhl98Tas=; b=MBmiXg9zHKfsOIXBtAMCIUAl+4VDcIebEhBQcVzHkW5fMST17/Ip9XMovhpKtEwt3E KRVv4CgM5jEhNlwTdfHTp67cZEiZn7donlR+Zs3UK5XHoVfNK2XnuEqCgfy880AYp6JF nsLj3D6MASUhUcrGdbt1ha5BacGgC3j47q2P7E6lmH8VVlBeegqOOD84NNSkKa0ZGVqS 45McAhDpAIQRHlqFt8JfMTaPzth+5Kot0oOLT7ewdk8ZjgJGgJ/oMFyv7wDucsUo8aSV 7oaMh+aM9n9IB6dgItHS9+IPTK8/kijdyv4ux84PX1tWdkqoPH3FVaw/jqp6wHLAXbHH EpWw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=G516YIFZjxAyFA6rPnLKz5INzuGiud5ts7gvhl98Tas=; b=P5brrVwUib82NPXJXsZoFy4bcJUqSPI5XLyPYiYbFjHoj5L7Rj3vsxtYDHb4prUCZ7 /16ExZYDlJ9gpBIiRIB+FK0EhTFLcSUblY+nI1MyjBCFA2FRuatqKKc0D4xytxu4pJmv 6Jl4ufM3l0RTViHXetoDoL2DKmkJEdx3SneZU3MTVATHx5QdhIUhtq2awGKhd24biorS zkDSCzqWLDWmz2v5p4FSho8nAe6TS4UMeYmRFA3kdXax9BlSnO6EiW7MLm/6U2Uq3VRM LPH1Y3M7xvTeyjhiDeqPKhwhnNxaOqQ0ZZbfcHlm5HBOkj+hUzFIbwxVAa3ilOpkGfby rGtw== X-Gm-Message-State: AOAM532nNsoeAzj8dPW+lCmVjQX4aK/MuRgfz6+Izeogi39PTUXqW0kB 5LdktIGvR28yJ1Ln5JvTq8G8ZdbojGw= X-Google-Smtp-Source: ABdhPJz7ojYpxFPGpbjA4n5j9oqVI6IYIts3WKoAbPf7DpoOV2nlLG1enNj5SMoWNx5fAshqpIjOfw== X-Received: by 2002:ad4:4e47:: with SMTP id eb7mr7663034qvb.39.1607115883018; Fri, 04 Dec 2020 13:04:43 -0800 (PST) Received: from localhost.localdomain ([181.23.80.53]) by smtp.gmail.com with ESMTPSA id o21sm6628916qko.9.2020.12.04.13.04.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 13:04:41 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 4 Dec 2020 18:03:50 -0300 Message-Id: <20201204210350.5720-1-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] 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 | 31 +++++++++++++++++++------------ libavcodec/internal.h | 4 ++-- libavcodec/utils.c | 26 +++++++++++++++++++++----- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 5a1849f944..68cdeccd06 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -147,20 +147,28 @@ fail2: static int extract_packet_props(AVCodecInternal *avci, AVPacket *pkt) { + AVPacket tmp; int ret = 0; - ret = avpriv_packet_list_put(&avci->pkt_props, &avci->pkt_props_tail, pkt, - av_packet_copy_props, 0); + if (av_fifo_space(avci->pkt_props) < sizeof(*pkt)) { + ret = av_fifo_grow(avci->pkt_props, sizeof(*pkt)); + if (ret < 0) + return ret; + } + + av_init_packet(&tmp); + ret = av_packet_copy_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(). + tmp.size = pkt->size; // HACK: Needed for ff_decode_frame_props(). + tmp.data = (void*)1; // HACK: Needed for IS_EMPTY(). + + ret = av_fifo_generic_write(avci->pkt_props, &tmp, sizeof(tmp), NULL); + av_assert0(ret == sizeof(tmp)); 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)); + ret = av_fifo_generic_read(avci->pkt_props, avci->last_pkt_props, + sizeof(*avci->last_pkt_props), NULL); } return ret; } @@ -1721,10 +1729,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 141f3fb88e..19c96d672c 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" @@ -145,8 +146,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 0226e36ee7..e156914af8 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -581,10 +581,12 @@ 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->compat_decode_frame || !avci->compat_encode_packet || !avci->buffer_frame || !avci->buffer_pkt || !avci->es.in_frame || !avci->ds.in_pkt || - !avci->to_free || !avci->last_pkt_props) { + !avci->to_free || !avci->last_pkt_props || + !avci->pkt_props) { ret = AVERROR(ENOMEM); goto free_and_end; } @@ -1064,6 +1066,7 @@ FF_ENABLE_DEPRECATION_WARNINGS av_packet_free(&avci->compat_encode_packet); 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); @@ -1104,8 +1107,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); @@ -1167,9 +1175,17 @@ av_cold int avcodec_close(AVCodecContext *avctx) av_frame_free(&avctx->internal->buffer_frame); av_packet_free(&avctx->internal->compat_encode_packet); 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);