From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH v2 19/27] avcodec/hevcdec: Switch to ProgressFrames Date: Mon, 8 Apr 2024 22:13:57 +0200 Message-ID: <GV1P250MB0737AEB02B9E8296B7CEF2CB8F002@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw) In-Reply-To: <GV1P250MB073755270DAD40B30BE913B78F002@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> Avoids implicit av_frame_ref() and therefore allocations and error checks. It also avoids explicitly allocating the AVFrames (done implicitly when getting the buffer). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/hevc_filter.c | 8 ++++---- libavcodec/hevc_mvs.c | 6 +++--- libavcodec/hevc_refs.c | 22 ++++++++++------------ libavcodec/hevcdec.c | 24 ++++++++++-------------- libavcodec/hevcdec.h | 4 ++-- 5 files changed, 29 insertions(+), 35 deletions(-) diff --git a/libavcodec/hevc_filter.c b/libavcodec/hevc_filter.c index 0c45310ea6..b1e2ea7a66 100644 --- a/libavcodec/hevc_filter.c +++ b/libavcodec/hevc_filter.c @@ -26,7 +26,7 @@ #include "libavutil/internal.h" #include "hevcdec.h" -#include "threadframe.h" +#include "progressframe.h" #define LUMA 0 #define CB 1 @@ -874,15 +874,15 @@ void ff_hevc_hls_filter(HEVCLocalContext *lc, int x, int y, int ctb_size) if (y && x_end) { sao_filter_CTB(lc, s, x, y - ctb_size); if (s->threads_type & FF_THREAD_FRAME ) - ff_thread_report_progress(&s->ref->tf, y, 0); + ff_progress_frame_report(&s->ref->tf, y); } if (x_end && y_end) { sao_filter_CTB(lc, s, x , y); if (s->threads_type & FF_THREAD_FRAME ) - ff_thread_report_progress(&s->ref->tf, y + ctb_size, 0); + ff_progress_frame_report(&s->ref->tf, y + ctb_size); } } else if (s->threads_type & FF_THREAD_FRAME && x_end) - ff_thread_report_progress(&s->ref->tf, y + ctb_size - 4, 0); + ff_progress_frame_report(&s->ref->tf, y + ctb_size - 4); } void ff_hevc_hls_filters(HEVCLocalContext *lc, int x_ctb, int y_ctb, int ctb_size) diff --git a/libavcodec/hevc_mvs.c b/libavcodec/hevc_mvs.c index 0a8cc2c43d..5591919e2e 100644 --- a/libavcodec/hevc_mvs.c +++ b/libavcodec/hevc_mvs.c @@ -23,7 +23,7 @@ #include "hevc.h" #include "hevcdec.h" -#include "threadframe.h" +#include "progressframe.h" static const uint8_t l0_l1_cand_idx[12][2] = { { 0, 1, }, @@ -248,7 +248,7 @@ static int temporal_luma_motion_vector(const HEVCContext *s, int x0, int y0, x &= ~15; y &= ~15; if (s->threads_type == FF_THREAD_FRAME) - ff_thread_await_progress(&ref->tf, y, 0); + ff_progress_frame_await(&ref->tf, y); x_pu = x >> s->ps.sps->log2_min_pu_size; y_pu = y >> s->ps.sps->log2_min_pu_size; temp_col = TAB_MVF(x_pu, y_pu); @@ -262,7 +262,7 @@ static int temporal_luma_motion_vector(const HEVCContext *s, int x0, int y0, x &= ~15; y &= ~15; if (s->threads_type == FF_THREAD_FRAME) - ff_thread_await_progress(&ref->tf, y, 0); + ff_progress_frame_await(&ref->tf, y); x_pu = x >> s->ps.sps->log2_min_pu_size; y_pu = y >> s->ps.sps->log2_min_pu_size; temp_col = TAB_MVF(x_pu, y_pu); diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c index aed649933d..192d311696 100644 --- a/libavcodec/hevc_refs.c +++ b/libavcodec/hevc_refs.c @@ -26,18 +26,15 @@ #include "decode.h" #include "hevc.h" #include "hevcdec.h" +#include "progressframe.h" #include "refstruct.h" -#include "threadframe.h" void ff_hevc_unref_frame(HEVCFrame *frame, int flags) { - /* frame->frame can be NULL if context init failed */ - if (!frame->frame || !frame->frame->buf[0]) - return; - frame->flags &= ~flags; if (!frame->flags) { - ff_thread_release_ext_buffer(&frame->tf); + ff_progress_frame_unref(&frame->tf); + frame->frame = NULL; av_frame_unref(frame->frame_grain); frame->needs_fg = 0; @@ -83,13 +80,14 @@ static HEVCFrame *alloc_frame(HEVCContext *s) int i, j, ret; for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { HEVCFrame *frame = &s->DPB[i]; - if (frame->frame->buf[0]) + if (frame->frame) continue; - ret = ff_thread_get_ext_buffer(s->avctx, &frame->tf, - AV_GET_BUFFER_FLAG_REF); + ret = ff_progress_frame_get_buffer(s->avctx, &frame->tf, + AV_GET_BUFFER_FLAG_REF); if (ret < 0) return NULL; + frame->frame = frame->tf.f; frame->rpl = ff_refstruct_allocz(s->pkt.nb_nals * sizeof(*frame->rpl)); if (!frame->rpl) @@ -135,7 +133,7 @@ int ff_hevc_set_new_ref(HEVCContext *s, AVFrame **frame, int poc) for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { HEVCFrame *frame = &s->DPB[i]; - if (frame->frame->buf[0] && frame->sequence == s->seq_decode && + if (frame->frame && frame->sequence == s->seq_decode && frame->poc == poc) { av_log(s->avctx, AV_LOG_ERROR, "Duplicate POC in a sequence: %d.\n", poc); @@ -394,7 +392,7 @@ static HEVCFrame *find_ref_idx(HEVCContext *s, int poc, uint8_t use_msb) for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { HEVCFrame *ref = &s->DPB[i]; - if (ref->frame->buf[0] && ref->sequence == s->seq_decode) { + if (ref->frame && ref->sequence == s->seq_decode) { if ((ref->poc & mask) == poc && (use_msb || ref->poc != s->poc)) return ref; } @@ -441,7 +439,7 @@ static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc) frame->flags = 0; if (s->threads_type == FF_THREAD_FRAME) - ff_thread_report_progress(&frame->tf, INT_MAX, 0); + ff_progress_frame_report(&frame->tf, INT_MAX); return frame; } diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index cedd09fe14..5f0f50adf1 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -49,9 +49,9 @@ #include "hwconfig.h" #include "internal.h" #include "profiles.h" +#include "progressframe.h" #include "refstruct.h" #include "thread.h" -#include "threadframe.h" static const uint8_t hevc_pel_weight[65] = { [2] = 0, [4] = 1, [6] = 2, [8] = 3, [12] = 4, [16] = 5, [24] = 6, [32] = 7, [48] = 8, [64] = 9 }; @@ -1867,7 +1867,7 @@ static void hevc_await_progress(const HEVCContext *s, const HEVCFrame *ref, if (s->threads_type == FF_THREAD_FRAME ) { int y = FFMAX(0, (mv->y >> 2) + y0 + height + 9); - ff_thread_await_progress(&ref->tf, y, 0); + ff_progress_frame_await(&ref->tf, y); } } @@ -3238,7 +3238,7 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length) fail: if (s->ref && s->threads_type == FF_THREAD_FRAME) - ff_thread_report_progress(&s->ref->tf, INT_MAX, 0); + ff_progress_frame_report(&s->ref->tf, INT_MAX); return ret; } @@ -3416,14 +3416,15 @@ static int hevc_ref_frame(HEVCFrame *dst, HEVCFrame *src) { int ret; - ret = ff_thread_ref_frame(&dst->tf, &src->tf); - if (ret < 0) - return ret; + ff_progress_frame_ref(&dst->tf, &src->tf); + dst->frame = dst->tf.f; if (src->needs_fg) { ret = av_frame_ref(dst->frame_grain, src->frame_grain); - if (ret < 0) + if (ret < 0) { + ff_hevc_unref_frame(dst, ~0); return ret; + } dst->needs_fg = 1; } @@ -3463,7 +3464,6 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx) for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { ff_hevc_unref_frame(&s->DPB[i], ~0); - av_frame_free(&s->DPB[i].frame); av_frame_free(&s->DPB[i].frame_grain); } @@ -3509,11 +3509,6 @@ static av_cold int hevc_init_context(AVCodecContext *avctx) return AVERROR(ENOMEM); for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { - s->DPB[i].frame = av_frame_alloc(); - if (!s->DPB[i].frame) - return AVERROR(ENOMEM); - s->DPB[i].tf.f = s->DPB[i].frame; - s->DPB[i].frame_grain = av_frame_alloc(); if (!s->DPB[i].frame_grain) return AVERROR(ENOMEM); @@ -3545,7 +3540,7 @@ static int hevc_update_thread_context(AVCodecContext *dst, for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { ff_hevc_unref_frame(&s->DPB[i], ~0); - if (s0->DPB[i].frame->buf[0]) { + if (s0->DPB[i].frame) { ret = hevc_ref_frame(&s->DPB[i], &s0->DPB[i]); if (ret < 0) return ret; @@ -3715,6 +3710,7 @@ const FFCodec ff_hevc_decoder = { .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS, .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | + FF_CODEC_CAP_USES_PROGRESSFRAMES | FF_CODEC_CAP_INIT_CLEANUP, .p.profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles), .hw_configs = (const AVCodecHWConfigInternal *const []) { diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h index e65a6180ca..24fcbf440a 100644 --- a/libavcodec/hevcdec.h +++ b/libavcodec/hevcdec.h @@ -40,7 +40,7 @@ #include "hevc_sei.h" #include "hevcdsp.h" #include "h274.h" -#include "threadframe.h" +#include "progressframe.h" #include "videodsp.h" #define SHIFT_CTB_WPP 2 @@ -354,7 +354,7 @@ typedef struct DBParams { typedef struct HEVCFrame { AVFrame *frame; AVFrame *frame_grain; - ThreadFrame tf; + ProgressFrame tf; int needs_fg; /* 1 if grain needs to be applied by the decoder */ MvField *tab_mvf; ///< RefStruct reference RefPicList *refPicList; -- 2.40.1 _______________________________________________ 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".
next prev parent reply other threads:[~2024-04-08 20:31 UTC|newest] Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-04-08 19:51 [FFmpeg-devel] [PATCH v2 01/27] avcodec/threadprogress: Add new API for frame-threaded progress Andreas Rheinhardt 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 02/27] avcodec/decode: Add new ProgressFrame API Andreas Rheinhardt 2024-04-09 1:40 ` Michael Niedermayer 2024-04-09 6:35 ` Andreas Rheinhardt 2024-04-10 7:01 ` Anton Khirnov 2024-04-10 7:09 ` Andreas Rheinhardt 2024-04-10 7:59 ` Anton Khirnov 2024-04-10 8:02 ` Andreas Rheinhardt 2024-04-10 8:06 ` Anton Khirnov 2024-04-10 8:09 ` Andreas Rheinhardt 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 03/27] avcodec/mimic: Switch to ProgressFrames Andreas Rheinhardt 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 04/27] avcodec/vp3: " Andreas Rheinhardt 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 05/27] avcodec/vp9: " Andreas Rheinhardt 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 06/27] avcodec/vp9: Fix race when attaching side-data for show-existing frame Andreas Rheinhardt 2024-04-10 7:06 ` Anton Khirnov 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 07/27] avcodec/vp9: Reduce wait times Andreas Rheinhardt 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 08/27] avcodec/vp9: Simplify replacing VP9Frame Andreas Rheinhardt 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 09/27] avcodec/vp9: Replace atomic_store() by atomic_init() Andreas Rheinhardt 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 10/27] avcodec/pthread_frame: Add API to share RefStruct refs just once Andreas Rheinhardt 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 11/27] avcodec/wavpack: Use ThreadProgress API Andreas Rheinhardt 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 12/27] avcodec/wavpack: Move initializing DSD data to a better place Andreas Rheinhardt 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 13/27] avcodec/wavpack: Only reset DSD context upon parameter change Andreas Rheinhardt 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 14/27] avcodec/wavpack: Optimize always-false comparison away Andreas Rheinhardt 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 15/27] avcodec/wavpack: Move transient variable from context to stack Andreas Rheinhardt 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 16/27] avcodec/vp8: Convert to ProgressFrame API Andreas Rheinhardt 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 17/27] avcodec/vp8: Mark flushing functions as av_cold Andreas Rheinhardt 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 18/27] avcodec/codec_internal: Remove FF_CODEC_CAP_ALLOCATE_PROGRESS Andreas Rheinhardt 2024-04-08 20:13 ` Andreas Rheinhardt [this message] 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 20/27] avcodec/pngdec: Switch to ProgressFrames Andreas Rheinhardt 2024-04-08 20:13 ` [FFmpeg-devel] [PATCH v2 21/27] avcodec/ffv1dec: " Andreas Rheinhardt 2024-04-08 20:14 ` [FFmpeg-devel] [PATCH v2 22/27] avcodec/qsv: Use RefStruct API for memory id (mids) array Andreas Rheinhardt 2024-04-08 20:14 ` [FFmpeg-devel] [PATCH v2 23/27] avcodec/rkmppdec: Fix double-free on error Andreas Rheinhardt 2024-04-08 20:14 ` [FFmpeg-devel] [PATCH v2 24/27] avcodec/rkmppdec: Check av_buffer_ref() Andreas Rheinhardt 2024-04-08 20:14 ` [FFmpeg-devel] [PATCH v2 25/27] avcodec/rkmppdec: Use RefStruct API for references to decoder itself Andreas Rheinhardt 2024-04-08 20:14 ` [FFmpeg-devel] [PATCH v2 26/27] avcodec/rkmppdec: Allocate AVDRMFrameDescriptor and frame ctx jointly Andreas Rheinhardt 2024-04-08 20:14 ` [FFmpeg-devel] [PATCH v2 27/27] avcodec/v4l2_(m2m|buffers): Use RefStruct API for context references Andreas Rheinhardt 2024-04-09 6:33 ` [FFmpeg-devel] [PATCH v3 01/27] avcodec/threadprogress: Add new API for frame-threaded progress Andreas Rheinhardt 2024-04-10 6:38 ` [FFmpeg-devel] [PATCH v2 " Anton Khirnov 2024-04-18 20:40 ` Andreas Rheinhardt 2024-04-18 21:30 ` epirat07
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=GV1P250MB0737AEB02B9E8296B7CEF2CB8F002@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM \ --to=andreas.rheinhardt@outlook.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git