This is a constant codec property, so a capability flag is more appropriate. --- doc/multithreading.txt | 5 +++-- libavcodec/h264dec.c | 5 ++--- libavcodec/hevcdec.c | 5 ++--- libavcodec/internal.h | 20 +++++--------------- libavcodec/mimic.c | 3 +-- libavcodec/mpeg4videodec.c | 2 +- libavcodec/pthread_frame.c | 4 ++-- libavcodec/rv30.c | 1 + libavcodec/rv34.c | 2 -- libavcodec/rv40.c | 1 + libavcodec/vp3.c | 5 ++--- libavcodec/vp8.c | 2 +- libavcodec/vp9.c | 3 +-- 13 files changed, 22 insertions(+), 36 deletions(-)
diff --git a/doc/multithreading.txt b/doc/multithreading.txt index 9b27b10..df9cd4e 100644 --- a/doc/multithreading.txt +++ b/doc/multithreading.txt @@ -58,9 +58,10 @@ Add 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 AVCodecInternal.allocate_progress. The +ff_thread_report/await_progress(), set FF_CODEC_CAP_ALLOCATE_PROGRESS in +AVCodec.caps_internal and use ff_thread_get_buffer() to allocate frames. The frames must then be freed with ff_thread_release_buffer(). -Otherwise leave it at zero and decode directly into the user-supplied frames. +Otherwise decode directly into the user-supplied frames. Call ff_thread_report_progress() 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 diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index 5137039..b27aa54 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -398,8 +398,6 @@ static av_cold int h264_decode_init(AVCodecContext *avctx) h->avctx->has_b_frames = h->ps.sps->num_reorder_frames; } - avctx->internal->allocate_progress = 1; - if (h->enable_er) { av_log(avctx, AV_LOG_WARNING, "Error resilience is enabled. It is unsafe and unsupported and may crash. " @@ -784,7 +782,8 @@ AVCodec ff_h264_decoder = { .capabilities = /*AV_CODEC_CAP_DRAW_HORIZ_BAND |*/ AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS, - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_EXPORTS_CROPPING, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_EXPORTS_CROPPING | + FF_CODEC_CAP_ALLOCATE_PROGRESS, .flush = flush_dpb, .init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy), .update_thread_context = ONLY_IF_THREADS_ENABLED(ff_h264_update_thread_context), diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index e24ce1e..110b28a 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -3022,8 +3022,6 @@ static av_cold int hevc_decode_init(AVCodecContext *avctx) HEVCContext *s = avctx->priv_data; int ret; - avctx->internal->allocate_progress = 1; - ret = hevc_init_context(avctx); if (ret < 0) return ret; @@ -3092,5 +3090,6 @@ AVCodec ff_hevc_decoder = { .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_FRAME_THREADS, .profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles), - .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | FF_CODEC_CAP_INIT_THREADSAFE, + .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | FF_CODEC_CAP_INIT_THREADSAFE | + FF_CODEC_CAP_ALLOCATE_PROGRESS, }; diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 5b82504..f302f86 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -59,6 +59,11 @@ * dimensions to coded rather than display values. */ #define FF_CODEC_CAP_EXPORTS_CROPPING (1 << 3) +/* + * 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 << 4) #ifdef DEBUG # define ff_dlog(ctx, ...) av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__) @@ -120,21 +125,6 @@ typedef struct AVCodecInternal { int is_copy; /** - * Whether to allocate progress for frame threading. - * - * The codec must set it to 1 if it uses ff_thread_await/report_progress(), - * then progress will be allocated in ff_thread_get_buffer(). The frames - * then MUST be freed with ff_thread_release_buffer(). - * - * If the codec does not need to call the progress functions (there are no - * dependencies between the frames), it should leave this at 0. Then it can - * decode straight to the user-provided frames (which the user will then - * free with av_frame_unref()), there is no need to call - * ff_thread_release_buffer(). - */ - int allocate_progress; - - /** * An audio frame with less than required samples has been submitted and * padded with silence. Reject all subsequent frames. */ diff --git a/libavcodec/mimic.c b/libavcodec/mimic.c index 34d2587..460debc 100644 --- a/libavcodec/mimic.c +++ b/libavcodec/mimic.c @@ -138,8 +138,6 @@ static av_cold int mimic_decode_init(AVCodecContext *avctx) MimicContext *ctx = avctx->priv_data; int ret, i; - avctx->internal->allocate_progress = 1; - ctx->prev_index = 0; ctx->cur_index = 15; @@ -476,4 +474,5 @@ AVCodec ff_mimic_decoder = { .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, .update_thread_context = ONLY_IF_THREADS_ENABLED(mimic_decode_update_thread_context), .init_thread_copy = ONLY_IF_THREADS_ENABLED(mimic_init_thread_copy), + .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS, }; diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c index e16d482..165f1de 100644 --- a/libavcodec/mpeg4videodec.c +++ b/libavcodec/mpeg4videodec.c @@ -2604,7 +2604,6 @@ static av_cold int decode_init(AVCodecContext *avctx) ctx->time_increment_bits = 4; /* default value for broken headers */ avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; - avctx->internal->allocate_progress = 1; return 0; } @@ -2625,4 +2624,5 @@ AVCodec ff_mpeg4_decoder = { .pix_fmts = ff_h263_hwaccel_pixfmt_list_420, .profiles = NULL_IF_CONFIG_SMALL(ff_mpeg4_video_profiles), .update_thread_context = ONLY_IF_THREADS_ENABLED(mpeg4_update_thread_context), + .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS, }; diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index f3a74c0..f511e7b 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -180,7 +180,7 @@ static attribute_align_arg void *frame_worker_thread(void *arg) p->result = codec->decode(avctx, p->frame, &p->got_frame, &p->avpkt); if ((p->result < 0 || !p->got_frame) && p->frame->buf[0]) { - if (avctx->internal->allocate_progress) + if (avctx->codec->caps_internal & FF_CODEC_CAP_ALLOCATE_PROGRESS) av_log(avctx, AV_LOG_ERROR, "A frame threaded decoder did not " "free the frame on failure. This is a bug, please report it.\n"); av_frame_unref(p->frame); @@ -812,7 +812,7 @@ int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags) return -1; } - if (avctx->internal->allocate_progress) { + if (avctx->codec->caps_internal & FF_CODEC_CAP_ALLOCATE_PROGRESS) { atomic_int *progress; f->progress = av_buffer_alloc(2 * sizeof(*progress)); if (!f->progress) { diff --git a/libavcodec/rv30.c b/libavcodec/rv30.c index 77e875b..acda330 100644 --- a/libavcodec/rv30.c +++ b/libavcodec/rv30.c @@ -291,4 +291,5 @@ AVCodec ff_rv30_decoder = { }, .init_thread_copy = ONLY_IF_THREADS_ENABLED(ff_rv34_decode_init_thread_copy), .update_thread_context = ONLY_IF_THREADS_ENABLED(ff_rv34_decode_update_thread_context), + .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS, }; diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c index 9fb0760..b777bcf 100644 --- a/libavcodec/rv34.c +++ b/libavcodec/rv34.c @@ -1511,8 +1511,6 @@ av_cold int ff_rv34_decode_init(AVCodecContext *avctx) if(!intra_vlcs[0].cbppattern[0].bits) rv34_init_tables(); - avctx->internal->allocate_progress = 1; - return 0; } diff --git a/libavcodec/rv40.c b/libavcodec/rv40.c index d46a44a..a9c82a5 100644 --- a/libavcodec/rv40.c +++ b/libavcodec/rv40.c @@ -580,4 +580,5 @@ AVCodec ff_rv40_decoder = { }, .init_thread_copy = ONLY_IF_THREADS_ENABLED(ff_rv34_decode_init_thread_copy), .update_thread_context = ONLY_IF_THREADS_ENABLED(ff_rv34_decode_update_thread_context), + .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS, }; diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c index cb8925b..c3c0e86 100644 --- a/libavcodec/vp3.c +++ b/libavcodec/vp3.c @@ -1715,8 +1715,6 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx) if (ret < 0) return ret; - avctx->internal->allocate_progress = 1; - if (avctx->codec_tag == MKTAG('V', 'P', '3', '0')) s->version = 0; else @@ -2494,7 +2492,7 @@ AVCodec ff_theora_decoder = { .flush = vp3_decode_flush, .init_thread_copy = ONLY_IF_THREADS_ENABLED(vp3_init_thread_copy), .update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context), - .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING, + .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | FF_CODEC_CAP_ALLOCATE_PROGRESS, }; #endif @@ -2512,4 +2510,5 @@ AVCodec ff_vp3_decoder = { .flush = vp3_decode_flush, .init_thread_copy = ONLY_IF_THREADS_ENABLED(vp3_init_thread_copy), .update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context), + .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS, }; diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c index bf1b03e..e97933e 100644 --- a/libavcodec/vp8.c +++ b/libavcodec/vp8.c @@ -2735,7 +2735,6 @@ int vp78_decode_init(AVCodecContext *avctx, int is_vp7) s->avctx = avctx; s->pix_fmt = AV_PIX_FMT_NONE; avctx->pix_fmt = AV_PIX_FMT_YUV420P; - avctx->internal->allocate_progress = 1; ff_videodsp_init(&s->vdsp, 8); @@ -2854,5 +2853,6 @@ AVCodec ff_vp8_decoder = { .flush = vp8_decode_flush, .init_thread_copy = ONLY_IF_THREADS_ENABLED(vp8_decode_init_thread_copy), .update_thread_context = ONLY_IF_THREADS_ENABLED(vp8_decode_update_thread_context), + .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS, }; #endif /* CONFIG_VP7_DECODER */ diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 48f8afe..1fb3288 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -1465,8 +1465,6 @@ static av_cold int vp9_decode_init(AVCodecContext *avctx) memset(s, 0, sizeof(*s)); - avctx->internal->allocate_progress = 1; - avctx->pix_fmt = AV_PIX_FMT_YUV420P; ff_vp9dsp_init(&s->dsp); @@ -1548,4 +1546,5 @@ AVCodec ff_vp9_decoder = { .init_thread_copy = vp9_decode_init, .update_thread_context = vp9_decode_update_thread_context, .bsfs = "vp9_superframe_split", + .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS, }; -- 2.0.0 _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel