1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

avcodec/codec_internal: Remove FF_CODEC_CAP_ALLOCATE_PROGRESS

Before commit f025b8e110,
every frame-threaded decoder used ThreadFrames, even when
they did not have any inter-frame dependencies at all.
In order to distinguish those decoders that need the AVBuffer
for progress communication from those that do not (to avoid
the allocation for the latter), the former decoders were marked
with the FF_CODEC_CAP_ALLOCATE_PROGRESS internal codec cap.

Yet distinguishing these two can be done in a more natural way:
Don't use ThreadFrames when not needed and split ff_thread_get_buffer()
into a core function that calls the user's get_buffer2 callback
and a wrapper around it that also allocates the progress AVBuffer.
This has been done in 02220b88fc
and since that commit the ALLOCATE_PROGRESS cap was nearly redundant.

The only exception was WebP and VP8. WebP can contain VP8
and uses the VP8 decoder directly (i.e. they share the same
AVCodecContext). Both decoders are frame-threaded and VP8
has inter-frame dependencies (in general, not in valid WebP)
and therefore the ALLOCATE_PROGRESS cap. In order to avoid
allocating progress in case of a frame-threaded WebP decoder
the cap and the check for the cap has been kept in place.

Yet now the VP8 decoder has been switched to use ProgressFrames
and therefore there is just no reason any more for this check
and the cap. This commit therefore removes both.

Also change the value of FF_CODEC_CAP_USES_PROGRESSFRAMES
to leave no gaps.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2023-09-19 01:43:29 +02:00
parent d7374ac713
commit 2b46ae6407
11 changed files with 18 additions and 36 deletions

View File

@ -36,9 +36,9 @@ Frame threading -
* Codecs similar to ffv1, whose streams don't reset across frames,
will not work because their bitstreams cannot be decoded in parallel.
* The contents of buffers must not be read before ff_thread_await_progress()
* The contents of buffers must not be read before ff_progress_frame_await()
has been called on them. reget_buffer() and buffer age optimizations no longer work.
* The contents of buffers must not be written to after ff_thread_report_progress()
* The contents of buffers must not be written to after ff_progress_frame_report()
has been called on them. This includes draw_edges().
Porting codecs to frame threading
@ -53,14 +53,13 @@ thread.
Add AV_CODEC_CAP_FRAME_THREADS to the codec capabilities. There will be very little
speed gain at this point but it should work.
If there are inter-frame dependencies, so the codec calls
ff_thread_report/await_progress(), set FF_CODEC_CAP_ALLOCATE_PROGRESS in
FFCodec.caps_internal and use ff_thread_get_buffer() to allocate frames.
Otherwise decode directly into the user-supplied frames.
Use ff_thread_get_buffer() (or ff_progress_frame_get_buffer()
in case you have inter-frame dependencies and use the ProgressFrame API)
to allocate frame buffers.
Call ff_thread_report_progress() after some part of the current picture has decoded.
Call ff_progress_frame_report() after some part of the current picture has decoded.
A good place to put this is where draw_horiz_band() is called - add this if it isn't
called anywhere, as it's useful too and the implementation is trivial when you're
doing this. Note that draw_edges() needs to be called before reporting progress.
Before accessing a reference frame or its MVs, call ff_thread_await_progress().
Before accessing a reference frame or its MVs, call ff_progress_frame_await().

View File

@ -65,12 +65,7 @@
/**
* The decoder might make use of the ProgressFrame API.
*/
#define FF_CODEC_CAP_USES_PROGRESSFRAMES (1 << 11)
/*
* The codec supports frame threading and has inter-frame dependencies, so it
* uses ff_thread_report/await_progress().
*/
#define FF_CODEC_CAP_ALLOCATE_PROGRESS (1 << 6)
#define FF_CODEC_CAP_USES_PROGRESSFRAMES (1 << 6)
/**
* Codec handles avctx->thread_count == 0 (auto) internally.
*/

View File

@ -1129,6 +1129,5 @@ const FFCodec ff_ffv1_decoder = {
UPDATE_THREAD_CONTEXT(update_thread_context),
.p.capabilities = AV_CODEC_CAP_DR1 |
AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
FF_CODEC_CAP_ALLOCATE_PROGRESS,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
};

View File

@ -1164,7 +1164,7 @@ const FFCodec ff_h264_decoder = {
NULL
},
.caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING |
FF_CODEC_CAP_ALLOCATE_PROGRESS | FF_CODEC_CAP_INIT_CLEANUP,
FF_CODEC_CAP_INIT_CLEANUP,
.flush = h264_decode_flush,
UPDATE_THREAD_CONTEXT(ff_h264_update_thread_context),
UPDATE_THREAD_CONTEXT_FOR_USER(ff_h264_update_thread_context_for_user),

View File

@ -3720,7 +3720,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_ALLOCATE_PROGRESS | FF_CODEC_CAP_INIT_CLEANUP,
FF_CODEC_CAP_INIT_CLEANUP,
.p.profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles),
.hw_configs = (const AVCodecHWConfigInternal *const []) {
#if CONFIG_HEVC_DXVA2_HWACCEL

View File

@ -3861,8 +3861,7 @@ const FFCodec ff_mpeg4_decoder = {
FF_CODEC_DECODE_CB(ff_h263_decode_frame),
.p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
AV_CODEC_CAP_DELAY | AV_CODEC_CAP_FRAME_THREADS,
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
FF_CODEC_CAP_ALLOCATE_PROGRESS,
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
.flush = ff_mpeg_flush,
.p.max_lowres = 3,
.p.profiles = NULL_IF_CONFIG_SMALL(ff_mpeg4_video_profiles),

View File

@ -1940,7 +1940,6 @@ const FFCodec ff_apng_decoder = {
UPDATE_THREAD_CONTEXT(update_thread_context),
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
FF_CODEC_CAP_ALLOCATE_PROGRESS |
FF_CODEC_CAP_ICC_PROFILES,
};
#endif
@ -1958,7 +1957,7 @@ const FFCodec ff_png_decoder = {
UPDATE_THREAD_CONTEXT(update_thread_context),
.p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
FF_CODEC_CAP_ALLOCATE_PROGRESS | FF_CODEC_CAP_INIT_CLEANUP |
FF_CODEC_CAP_INIT_CLEANUP |
FF_CODEC_CAP_ICC_PROFILES,
};
#endif

View File

@ -991,14 +991,12 @@ int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
if (!(avctx->active_thread_type & FF_THREAD_FRAME))
return ff_get_buffer(avctx, f->f, flags);
if (ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_ALLOCATE_PROGRESS) {
f->progress = ff_refstruct_allocz(sizeof(*f->progress));
if (!f->progress)
return AVERROR(ENOMEM);
f->progress = ff_refstruct_allocz(sizeof(*f->progress));
if (!f->progress)
return AVERROR(ENOMEM);
atomic_init(&f->progress->progress[0], -1);
atomic_init(&f->progress->progress[1], -1);
}
atomic_init(&f->progress->progress[0], -1);
atomic_init(&f->progress->progress[1], -1);
ret = ff_thread_get_buffer(avctx, f->f, flags);
if (ret)

View File

@ -304,5 +304,4 @@ const FFCodec ff_rv30_decoder = {
AV_CODEC_CAP_FRAME_THREADS,
.flush = ff_mpeg_flush,
UPDATE_THREAD_CONTEXT(ff_rv34_decode_update_thread_context),
.caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS,
};

View File

@ -582,5 +582,4 @@ const FFCodec ff_rv40_decoder = {
AV_CODEC_CAP_FRAME_THREADS,
.flush = ff_mpeg_flush,
UPDATE_THREAD_CONTEXT(ff_rv34_decode_update_thread_context),
.caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS,
};

View File

@ -142,7 +142,6 @@ int main(void){
}
}
if (codec2->caps_internal & (FF_CODEC_CAP_USES_PROGRESSFRAMES |
FF_CODEC_CAP_ALLOCATE_PROGRESS |
FF_CODEC_CAP_SETS_PKT_DTS |
FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
FF_CODEC_CAP_EXPORTS_CROPPING |
@ -172,10 +171,6 @@ int main(void){
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
AV_CODEC_CAP_ENCODER_FLUSH))
ERR("Decoder %s has encoder-only capabilities\n");
if (codec2->caps_internal & FF_CODEC_CAP_ALLOCATE_PROGRESS &&
!(codec->capabilities & AV_CODEC_CAP_FRAME_THREADS))
ERR("Decoder %s wants allocated progress without supporting"
"frame threads\n");
if (codec2->cb_type != FF_CODEC_CB_TYPE_DECODE &&
codec2->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS)
ERR("Decoder %s is marked as setting pkt_dts when it doesn't have"