From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 78771456AF for ; Sat, 20 May 2023 01:29:02 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6E96968C139; Sat, 20 May 2023 04:28:59 +0300 (EEST) Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4283F68C0B8 for ; Sat, 20 May 2023 04:28:52 +0300 (EEST) Received: by mail-ot1-f54.google.com with SMTP id 46e09a7af769-6ab087111faso1617667a34.3 for ; Fri, 19 May 2023 18:28:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684546130; x=1687138130; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=JgU0OFCCtRMjt/3pqQ1VqLNA2tI0vfKzkIQZvgy4MMQ=; b=NoJ8dQy1SLl5Y7lxa05dwsdulliTZddY9yT2FKc98w0K9IjtWyQVb6CDxCdkeVAq5v OUdo5/h1GhZH2B3VQsuH6mB8BWuxq2TZTLFp5OxBauF4F2er3+djNeKPZKBThe9LxpnY BHRG0elKoMzqPVShDVNoLQbA0NpJysz5a/d1YD8u1oc1wfpMiSfjlxN+gsLohl7BPNZo 50qtoO7tigUiSoMR/Vzo0GKc1ocPtMC/acTjsv3a8N0ngcZpLXk6WzyUtA6AcnH2w9C6 zl4BsHzn3q6sLSl8HGjNIH7Gv3t9NsYgP0eQkN8IuwIlETcf7fM8P5XYeTERON/zGAW0 2IOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684546130; x=1687138130; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JgU0OFCCtRMjt/3pqQ1VqLNA2tI0vfKzkIQZvgy4MMQ=; b=U/OOT97KCJmzIgm0MxQiSyGsp4+jByXXCti2a96zJTHwBevX9fdW1aH14aaQhLOTc2 c8NKzuK0gRbEBj3OXgRQBe7UFNnN3+wa+PrNp/SQMUSN3aPksCKiXWGw6amREqRZqDJH 0naWi5Ibzv1G/mEAiHuGiOblz40emWfaSnvuaeaWQfsw/srbQtWX4DoqJj+fAoAcqDfZ Edt9vRoWBONuKm7zlwyyZefSuyOAX9uOLMIxaJtyPGWcq58qwtJ13A3Y+7WuEY7exRgk KKSpsIVI6esGs5/CTckoxmKwrBz61kN/HEDssJ+OFerUvy6KgqahjU4Jm26mUgYAZcJw tvsQ== X-Gm-Message-State: AC+VfDxxphNTXKvjStKm7B+PtLGNvYCKxIM7CTKIrxaZaDl5rxh1rJiK UJ1upK0I6nzfojvGBFuh+3no097jy8M= X-Google-Smtp-Source: ACHHUZ7dWipAQD/kvTgbwp78FLDapTsg51PR2TlHBC/82plgrEV/p2tF8DIGy1dgOPvO0Qtopl35dQ== X-Received: by 2002:a05:6870:c804:b0:18e:e0bc:829 with SMTP id ee4-20020a056870c80400b0018ee0bc0829mr2098079oab.17.1684546129982; Fri, 19 May 2023 18:28:49 -0700 (PDT) Received: from [192.168.0.12] (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id ds12-20020a0568705b0c00b00199c3a06f7esm130865oab.51.2023.05.19.18.28.48 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 May 2023 18:28:49 -0700 (PDT) Message-ID: <0230cbdd-016a-37b7-145a-b14af3b6a86a@gmail.com> Date: Fri, 19 May 2023 22:29:03 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <20230519235907.4321-1-jamrial@gmail.com> From: James Almer In-Reply-To: Subject: Re: [FFmpeg-devel] [PATCH] avcodec/av1dec: convert to receive_frame() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 5/19/2023 10:01 PM, Andreas Rheinhardt wrote: > James Almer: >> Signed-off-by: James Almer >> --- >> libavcodec/av1dec.c | 75 +++++++++++++++++++++++++++++++++------------ >> libavcodec/av1dec.h | 4 +++ >> 2 files changed, 60 insertions(+), 19 deletions(-) >> >> diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c >> index d46ee48335..9344d4ff28 100644 >> --- a/libavcodec/av1dec.c >> +++ b/libavcodec/av1dec.c >> @@ -657,6 +657,7 @@ static av_cold int av1_decode_free(AVCodecContext *avctx) >> } >> av1_frame_unref(avctx, &s->cur_frame); >> av_frame_free(&s->cur_frame.f); >> + av_packet_free(&s->pkt); >> >> av_buffer_unref(&s->seq_ref); >> av_buffer_unref(&s->header_ref); >> @@ -767,6 +768,10 @@ static av_cold int av1_decode_init(AVCodecContext *avctx) >> s->avctx = avctx; >> s->pix_fmt = AV_PIX_FMT_NONE; >> >> + s->pkt = av_packet_alloc(); > > receive_frame decoders may use AVCodecInternal.in_pkt (this will also > make unreferencing this packet when flushing unnecessary). Good idea, thanks. > >> + if (!s->pkt) >> + return AVERROR(ENOMEM); >> + >> for (int i = 0; i < FF_ARRAY_ELEMS(s->ref); i++) { >> s->ref[i].f = av_frame_alloc(); >> if (!s->ref[i].f) { >> @@ -1042,7 +1047,7 @@ static int export_film_grain(AVCodecContext *avctx, AVFrame *frame) >> } >> >> static int set_output_frame(AVCodecContext *avctx, AVFrame *frame, >> - const AVPacket *pkt, int *got_frame) >> + const AVPacket *pkt) >> { >> AV1DecContext *s = avctx->priv_data; >> const AVFrame *srcframe = s->cur_frame.f; >> @@ -1079,8 +1084,6 @@ FF_DISABLE_DEPRECATION_WARNINGS >> FF_ENABLE_DEPRECATION_WARNINGS >> #endif >> >> - *got_frame = 1; >> - >> return 0; >> } >> >> @@ -1145,22 +1148,32 @@ static int get_current_frame(AVCodecContext *avctx) >> return ret; >> } >> >> -static int av1_decode_frame(AVCodecContext *avctx, AVFrame *frame, >> - int *got_frame, AVPacket *pkt) >> +static int av1_receive_frame(AVCodecContext *avctx, AVFrame *frame) >> { >> AV1DecContext *s = avctx->priv_data; >> AV1RawTileGroup *raw_tile_group = NULL; >> - int ret; >> + int i, ret; >> >> - ret = ff_cbs_read_packet(s->cbc, &s->current_obu, pkt); >> - if (ret < 0) { >> - av_log(avctx, AV_LOG_ERROR, "Failed to read packet.\n"); >> - goto end; >> +again: >> + if (!s->current_obu.nb_units) { >> + ret = ff_decode_get_packet(avctx, s->pkt); >> + if (ret < 0) >> + return ret; >> + >> + ret = ff_cbs_read_packet(s->cbc, &s->current_obu, s->pkt); >> + av_packet_unref(s->pkt); >> + if (ret < 0) { >> + av_log(avctx, AV_LOG_ERROR, "Failed to read packet.\n"); >> + goto end; >> + } >> + >> + s->nb_unit = 0; >> + >> + av_log(avctx, AV_LOG_DEBUG, "Total OBUs for this TU:%d.\n", >> + s->current_obu.nb_units); >> } >> - av_log(avctx, AV_LOG_DEBUG, "Total obu for this frame:%d.\n", >> - s->current_obu.nb_units); >> >> - for (int i = 0; i < s->current_obu.nb_units; i++) { >> + for (i = s->nb_unit; i < s->current_obu.nb_units; i++) { >> CodedBitstreamUnit *unit = &s->current_obu.units[i]; >> AV1RawOBU *obu = unit->content; >> const AV1RawOBUHeader *header; >> @@ -1168,6 +1181,7 @@ static int av1_decode_frame(AVCodecContext *avctx, AVFrame *frame, >> if (!obu) >> continue; >> >> + ret = 0; >> header = &obu->header; >> av_log(avctx, AV_LOG_DEBUG, "Obu idx:%d, obu type:%d.\n", i, unit->type); >> >> @@ -1251,13 +1265,15 @@ static int av1_decode_frame(AVCodecContext *avctx, AVFrame *frame, >> goto end; >> } >> >> + ret = 0; >> if (s->cur_frame.f->buf[0]) { >> - ret = set_output_frame(avctx, frame, pkt, got_frame); >> + ret = set_output_frame(avctx, frame, s->pkt); >> if (ret < 0) >> av_log(avctx, AV_LOG_ERROR, "Set output frame error.\n"); >> } >> >> s->raw_frame_header = NULL; >> + i++; >> >> goto end; >> } >> @@ -1361,6 +1377,7 @@ static int av1_decode_frame(AVCodecContext *avctx, AVFrame *frame, >> } >> >> if (raw_tile_group && (s->tile_num == raw_tile_group->tg_end + 1)) { >> + int show_frame = s->raw_frame_header->show_frame; >> if (avctx->hwaccel && s->cur_frame.f->buf[0]) { >> ret = avctx->hwaccel->end_frame(avctx); >> if (ret < 0) { >> @@ -1375,8 +1392,9 @@ static int av1_decode_frame(AVCodecContext *avctx, AVFrame *frame, >> goto end; >> } >> >> + ret = 0; >> if (s->raw_frame_header->show_frame && s->cur_frame.f->buf[0]) { >> - ret = set_output_frame(avctx, frame, pkt, got_frame); >> + ret = set_output_frame(avctx, frame, s->pkt); >> if (ret < 0) { >> av_log(avctx, AV_LOG_ERROR, "Set output frame error\n"); >> goto end; >> @@ -1384,13 +1402,30 @@ static int av1_decode_frame(AVCodecContext *avctx, AVFrame *frame, >> } >> raw_tile_group = NULL; >> s->raw_frame_header = NULL; >> + if (show_frame) { >> + i++; >> + goto end; >> + } >> } >> + ret = AVERROR(EAGAIN); >> } >> >> end: >> - ff_cbs_fragment_reset(&s->current_obu); >> - if (ret < 0) >> + av_assert0(i <= s->current_obu.nb_units); >> + s->nb_unit = i; >> + >> + if (s->current_obu.nb_units == i) { >> + ff_cbs_fragment_reset(&s->current_obu); >> + s->nb_unit = 0; >> + } >> + if (ret == AVERROR(EAGAIN)) >> + goto again; >> + if (ret < 0) { >> s->raw_frame_header = NULL; >> + ff_cbs_fragment_reset(&s->current_obu); >> + s->nb_unit = 0; >> + } >> + >> return ret; >> } >> >> @@ -1403,7 +1438,9 @@ static void av1_decode_flush(AVCodecContext *avctx) >> av1_frame_unref(avctx, &s->ref[i]); >> >> av1_frame_unref(avctx, &s->cur_frame); >> + av_packet_unref(s->pkt); >> s->operating_point_idc = 0; >> + s->nb_unit = 0; >> s->raw_frame_header = NULL; >> s->raw_seq = NULL; >> s->cll = NULL; >> @@ -1411,6 +1448,7 @@ static void av1_decode_flush(AVCodecContext *avctx) >> while (av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0) >> av_buffer_unref(&itut_t35.payload_ref); >> >> + ff_cbs_fragment_reset(&s->current_obu); >> ff_cbs_flush(s->cbc); >> } >> >> @@ -1437,14 +1475,13 @@ const FFCodec ff_av1_decoder = { >> .priv_data_size = sizeof(AV1DecContext), >> .init = av1_decode_init, >> .close = av1_decode_free, >> - FF_CODEC_DECODE_CB(av1_decode_frame), >> + FF_CODEC_RECEIVE_FRAME_CB(av1_receive_frame), >> .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_AVOID_PROBING, >> .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | >> FF_CODEC_CAP_SETS_PKT_DTS, >> .flush = av1_decode_flush, >> .p.profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles), >> .p.priv_class = &av1_class, >> - .bsfs = "av1_frame_split", >> .hw_configs = (const AVCodecHWConfigInternal *const []) { >> #if CONFIG_AV1_DXVA2_HWACCEL >> HWACCEL_DXVA2(av1), >> diff --git a/libavcodec/av1dec.h b/libavcodec/av1dec.h >> index cef899f81f..59ffed1d9b 100644 >> --- a/libavcodec/av1dec.h >> +++ b/libavcodec/av1dec.h >> @@ -28,6 +28,7 @@ >> #include "libavutil/frame.h" >> #include "libavutil/pixfmt.h" >> #include "avcodec.h" >> +#include "packet.h" >> #include "cbs.h" >> #include "cbs_av1.h" >> >> @@ -68,6 +69,7 @@ typedef struct AV1DecContext { >> enum AVPixelFormat pix_fmt; >> CodedBitstreamContext *cbc; >> CodedBitstreamFragment current_obu; >> + AVPacket *pkt; >> >> AVBufferRef *seq_ref; >> AV1RawSequenceHeader *raw_seq; >> @@ -90,6 +92,8 @@ typedef struct AV1DecContext { >> AV1Frame ref[AV1_NUM_REF_FRAMES]; >> AV1Frame cur_frame; >> >> + int nb_unit; >> + >> // AVOptions >> int operating_point; >> } AV1DecContext; > > What's the advantage? Removing the av1_frame_split bsf. > > - Andreas > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".