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.
Showing the changes to libavcodec (10 of 11 files). Show all
Unified · Split
| @@ -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 | */ |
| @@ -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 | }; |
| @@ -1164,7 +1164,7 @@ const FFCodec ff_h264_decoder = { · 1163 unmodified lines | |||
| 1164 | NULL | 1164 | 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), |
| @@ -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_HWACCEL | 3726 | #if CONFIG_HEVC_DXVA2_HWACCEL |
| @@ -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), |
| @@ -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 | #endif | 1945 | #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 | #endif | 1963 | #endif |
| @@ -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) |
| @@ -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 | }; |
| @@ -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 | }; |
| @@ -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" |