History

avcodec/codec_internal: Remove FF_CODEC_CAP_ALLOCATE_PROGRESS

Before commit f025b8e110b36c1cdb4fb56c4cd57aeca1767b5b, 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 02220b88fc38ef9dd4f2d519f5d3e4151258b60c 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.

Andreas Rheinhardt committed 3 years ago

Commit 2b46ae61 parent d7374ac11 files · +18 −36Browse files

Unified · Split

11 files
  1. doc/multithreading.txt +7 −8
  2. libavcodec/codec_internal.h +1 −6
  3. libavcodec/ffv1dec.c +1 −2
  4. libavcodec/h264dec.c +1 −1
  5. libavcodec/hevcdec.c +1 −1
  6. libavcodec/mpeg4videodec.c +1 −2
  7. libavcodec/pngdec.c +1 −2
  8. libavcodec/pthread_frame.c +5 −7
  9. libavcodec/rv30.c +0 −1
  10. libavcodec/rv40.c +0 −1
  11. libavcodec/tests/avcodec.c +0 −5
doc/multithreading.txt+7−8
@@ -36,9 +36,9 @@ Frame threading - · 35 unmodified lines
36* Codecs similar to ffv1, whose streams don't reset across frames,36* Codecs similar to ffv1, whose streams don't reset across frames,
37 will not work because their bitstreams cannot be decoded in parallel.37 will not work because their bitstreams cannot be decoded in parallel.
38 38
39* The contents of buffers must not be read before ff_thread_await_progress()39* The contents of buffers must not be read before ff_progress_frame_await()
40 has been called on them. reget_buffer() and buffer age optimizations no longer work.40 has been called on them. reget_buffer() and buffer age optimizations no longer work.
41* The contents of buffers must not be written to after ff_thread_report_progress()41* The contents of buffers must not be written to after ff_progress_frame_report()
42 has been called on them. This includes draw_edges().42 has been called on them. This includes draw_edges().
43 43
44Porting codecs to frame threading44Porting codecs to frame threading
@@ -53,14 +53,13 @@ thread. · 8 unmodified lines
53Add AV_CODEC_CAP_FRAME_THREADS to the codec capabilities. There will be very little53Add AV_CODEC_CAP_FRAME_THREADS to the codec capabilities. There will be very little
54speed gain at this point but it should work.54speed gain at this point but it should work.
55 55
56If there are inter-frame dependencies, so the codec calls56Use ff_thread_get_buffer() (or ff_progress_frame_get_buffer()
57ff_thread_report/await_progress(), set FF_CODEC_CAP_ALLOCATE_PROGRESS in57in case you have inter-frame dependencies and use the ProgressFrame API)
58FFCodec.caps_internal and use ff_thread_get_buffer() to allocate frames.58to allocate frame buffers.
59Otherwise decode directly into the user-supplied frames.
60 59
61Call ff_thread_report_progress() after some part of the current picture has decoded.60Call ff_progress_frame_report() after some part of the current picture has decoded.
62A good place to put this is where draw_horiz_band() is called - add this if it isn't61A good place to put this is where draw_horiz_band() is called - add this if it isn't
63called anywhere, as it's useful too and the implementation is trivial when you're62called anywhere, as it's useful too and the implementation is trivial when you're
64doing this. Note that draw_edges() needs to be called before reporting progress.63doing this. Note that draw_edges() needs to be called before reporting progress.
65 64
66Before accessing a reference frame or its MVs, call ff_thread_await_progress().65Before accessing a reference frame or its MVs, call ff_progress_frame_await().
libavcodec/codec_internal.h+1−6
@@ -65,12 +65,7 @@ · 64 unmodified lines
65/**65/**
66 * The decoder might make use of the ProgressFrame API.66 * The decoder might make use of the ProgressFrame API.
67 */67 */
68#define FF_CODEC_CAP_USES_PROGRESSFRAMES (1 << 11)68#define FF_CODEC_CAP_USES_PROGRESSFRAMES (1 << 6)
69/*
70 * The codec supports frame threading and has inter-frame dependencies, so it
71 * uses ff_thread_report/await_progress().
72 */
73#define FF_CODEC_CAP_ALLOCATE_PROGRESS (1 << 6)
74/**69/**
75 * Codec handles avctx->thread_count == 0 (auto) internally.70 * Codec handles avctx->thread_count == 0 (auto) internally.
76 */71 */
libavcodec/ffv1dec.c+1−2
@@ -1129,6 +1129,5 @@ const FFCodec ff_ffv1_decoder = { · 1128 unmodified lines
1129 UPDATE_THREAD_CONTEXT(update_thread_context),1129 UPDATE_THREAD_CONTEXT(update_thread_context),
1130 .p.capabilities = AV_CODEC_CAP_DR1 |1130 .p.capabilities = AV_CODEC_CAP_DR1 |
1131 AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS,1131 AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS,
1132 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |1132 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1133 FF_CODEC_CAP_ALLOCATE_PROGRESS,
1134};1133};
libavcodec/h264dec.c+1−1
@@ -1164,7 +1164,7 @@ const FFCodec ff_h264_decoder = { · 1163 unmodified lines
1164 NULL1164 NULL
1165 },1165 },
1166 .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING |1166 .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING |
1167 FF_CODEC_CAP_ALLOCATE_PROGRESS | FF_CODEC_CAP_INIT_CLEANUP,1167 FF_CODEC_CAP_INIT_CLEANUP,
1168 .flush = h264_decode_flush,1168 .flush = h264_decode_flush,
1169 UPDATE_THREAD_CONTEXT(ff_h264_update_thread_context),1169 UPDATE_THREAD_CONTEXT(ff_h264_update_thread_context),
1170 UPDATE_THREAD_CONTEXT_FOR_USER(ff_h264_update_thread_context_for_user),1170 UPDATE_THREAD_CONTEXT_FOR_USER(ff_h264_update_thread_context_for_user),
libavcodec/hevcdec.c+1−1
@@ -3720,7 +3720,7 @@ const FFCodec ff_hevc_decoder = { · 3719 unmodified lines
3720 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |3720 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
3721 AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS,3721 AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS,
3722 .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING |3722 .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING |
3723 FF_CODEC_CAP_ALLOCATE_PROGRESS | FF_CODEC_CAP_INIT_CLEANUP,3723 FF_CODEC_CAP_INIT_CLEANUP,
3724 .p.profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles),3724 .p.profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles),
3725 .hw_configs = (const AVCodecHWConfigInternal *const []) {3725 .hw_configs = (const AVCodecHWConfigInternal *const []) {
3726#if CONFIG_HEVC_DXVA2_HWACCEL3726#if CONFIG_HEVC_DXVA2_HWACCEL
libavcodec/mpeg4videodec.c+1−2
@@ -3861,8 +3861,7 @@ const FFCodec ff_mpeg4_decoder = { · 3860 unmodified lines
3861 FF_CODEC_DECODE_CB(ff_h263_decode_frame),3861 FF_CODEC_DECODE_CB(ff_h263_decode_frame),
3862 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |3862 .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
3863 AV_CODEC_CAP_DELAY | AV_CODEC_CAP_FRAME_THREADS,3863 AV_CODEC_CAP_DELAY | AV_CODEC_CAP_FRAME_THREADS,
3864 .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |3864 .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
3865 FF_CODEC_CAP_ALLOCATE_PROGRESS,
3866 .flush = ff_mpeg_flush,3865 .flush = ff_mpeg_flush,
3867 .p.max_lowres = 3,3866 .p.max_lowres = 3,
3868 .p.profiles = NULL_IF_CONFIG_SMALL(ff_mpeg4_video_profiles),3867 .p.profiles = NULL_IF_CONFIG_SMALL(ff_mpeg4_video_profiles),
libavcodec/pngdec.c+1−2
@@ -1940,7 +1940,6 @@ const FFCodec ff_apng_decoder = { · 1939 unmodified lines
1940 UPDATE_THREAD_CONTEXT(update_thread_context),1940 UPDATE_THREAD_CONTEXT(update_thread_context),
1941 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,1941 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
1942 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |1942 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
1943 FF_CODEC_CAP_ALLOCATE_PROGRESS |
1944 FF_CODEC_CAP_ICC_PROFILES,1943 FF_CODEC_CAP_ICC_PROFILES,
1945};1944};
1946#endif1945#endif
@@ -1958,7 +1957,7 @@ const FFCodec ff_png_decoder = { · 11 unmodified lines
1958 UPDATE_THREAD_CONTEXT(update_thread_context),1957 UPDATE_THREAD_CONTEXT(update_thread_context),
1959 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,1958 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
1960 .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |1959 .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
1961 FF_CODEC_CAP_ALLOCATE_PROGRESS | FF_CODEC_CAP_INIT_CLEANUP |1960 FF_CODEC_CAP_INIT_CLEANUP |
1962 FF_CODEC_CAP_ICC_PROFILES,1961 FF_CODEC_CAP_ICC_PROFILES,
1963};1962};
1964#endif1963#endif
libavcodec/pthread_frame.c+5−7
@@ -991,14 +991,12 @@ int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags) · 990 unmodified lines
991 if (!(avctx->active_thread_type & FF_THREAD_FRAME))991 if (!(avctx->active_thread_type & FF_THREAD_FRAME))
992 return ff_get_buffer(avctx, f->f, flags);992 return ff_get_buffer(avctx, f->f, flags);
993 993
994 if (ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_ALLOCATE_PROGRESS) {994 f->progress = ff_refstruct_allocz(sizeof(*f->progress));
995 f->progress = ff_refstruct_allocz(sizeof(*f->progress));995 if (!f->progress)
996 if (!f->progress)996 return AVERROR(ENOMEM);
997 return AVERROR(ENOMEM);
998 997
999 atomic_init(&f->progress->progress[0], -1);998 atomic_init(&f->progress->progress[0], -1);
1000 atomic_init(&f->progress->progress[1], -1);999 atomic_init(&f->progress->progress[1], -1);
1001 }
1002 1000
1003 ret = ff_thread_get_buffer(avctx, f->f, flags);1001 ret = ff_thread_get_buffer(avctx, f->f, flags);
1004 if (ret)1002 if (ret)
libavcodec/rv30.c+0−1
@@ -304,5 +304,4 @@ const FFCodec ff_rv30_decoder = { · 303 unmodified lines
304 AV_CODEC_CAP_FRAME_THREADS,304 AV_CODEC_CAP_FRAME_THREADS,
305 .flush = ff_mpeg_flush,305 .flush = ff_mpeg_flush,
306 UPDATE_THREAD_CONTEXT(ff_rv34_decode_update_thread_context),306 UPDATE_THREAD_CONTEXT(ff_rv34_decode_update_thread_context),
307 .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS,
308};307};
libavcodec/rv40.c+0−1
@@ -582,5 +582,4 @@ const FFCodec ff_rv40_decoder = { · 581 unmodified lines
582 AV_CODEC_CAP_FRAME_THREADS,582 AV_CODEC_CAP_FRAME_THREADS,
583 .flush = ff_mpeg_flush,583 .flush = ff_mpeg_flush,
584 UPDATE_THREAD_CONTEXT(ff_rv34_decode_update_thread_context),584 UPDATE_THREAD_CONTEXT(ff_rv34_decode_update_thread_context),
585 .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS,
586};585};
libavcodec/tests/avcodec.c+0−5
@@ -142,7 +142,6 @@ int main(void){ · 141 unmodified lines
142 }142 }
143 }143 }
144 if (codec2->caps_internal & (FF_CODEC_CAP_USES_PROGRESSFRAMES |144 if (codec2->caps_internal & (FF_CODEC_CAP_USES_PROGRESSFRAMES |
145 FF_CODEC_CAP_ALLOCATE_PROGRESS |
146 FF_CODEC_CAP_SETS_PKT_DTS |145 FF_CODEC_CAP_SETS_PKT_DTS |
147 FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |146 FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
148 FF_CODEC_CAP_EXPORTS_CROPPING |147 FF_CODEC_CAP_EXPORTS_CROPPING |
@@ -172,10 +171,6 @@ int main(void){ · 23 unmodified lines
172 AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |171 AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE |
173 AV_CODEC_CAP_ENCODER_FLUSH))172 AV_CODEC_CAP_ENCODER_FLUSH))
174 ERR("Decoder %s has encoder-only capabilities\n");173 ERR("Decoder %s has encoder-only capabilities\n");
175 if (codec2->caps_internal & FF_CODEC_CAP_ALLOCATE_PROGRESS &&
176 !(codec->capabilities & AV_CODEC_CAP_FRAME_THREADS))
177 ERR("Decoder %s wants allocated progress without supporting"
178 "frame threads\n");
179 if (codec2->cb_type != FF_CODEC_CB_TYPE_DECODE &&174 if (codec2->cb_type != FF_CODEC_CB_TYPE_DECODE &&
180 codec2->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS)175 codec2->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS)
181 ERR("Decoder %s is marked as setting pkt_dts when it doesn't have"176 ERR("Decoder %s is marked as setting pkt_dts when it doesn't have"

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t