mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
lavc: replace AVCodecInternal.allocate_progress with an internal cap
This is a constant codec property, so a capability flag is more appropriate.
This commit is contained in:
parent
7385ffbd31
commit
665e5b0fba
@ -58,9 +58,10 @@ Add AV_CODEC_CAP_FRAME_THREADS to the codec capabilities. There will be very lit
|
||||
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
|
||||
|
@ -826,8 +826,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
|
||||
if ((ret = ff_ffv1_init_slice_contexts(f)) < 0)
|
||||
return ret;
|
||||
|
||||
avctx->internal->allocate_progress = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1094,5 +1092,5 @@ AVCodec ff_ffv1_decoder = {
|
||||
.update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
|
||||
.capabilities = AV_CODEC_CAP_DR1 /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/ |
|
||||
AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS,
|
||||
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP
|
||||
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_ALLOCATE_PROGRESS,
|
||||
};
|
||||
|
@ -424,8 +424,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;
|
||||
|
||||
ff_h264_flush_change(h);
|
||||
|
||||
if (h->enable_er < 0 && (avctx->active_thread_type & FF_THREAD_SLICE))
|
||||
@ -1080,7 +1078,8 @@ AVCodec ff_h264_decoder = {
|
||||
#endif
|
||||
NULL
|
||||
},
|
||||
.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),
|
||||
|
@ -3491,8 +3491,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;
|
||||
@ -3582,7 +3580,8 @@ AVCodec ff_hevc_decoder = {
|
||||
.init_thread_copy = ONLY_IF_THREADS_ENABLED(hevc_init_thread_copy),
|
||||
.capabilities = 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,
|
||||
.profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles),
|
||||
.hw_configs = (const AVCodecHWConfigInternal*[]) {
|
||||
#if CONFIG_HEVC_DXVA2_HWACCEL
|
||||
|
@ -68,6 +68,11 @@
|
||||
* Codec initializes slice-based threading with a main function
|
||||
*/
|
||||
#define FF_CODEC_CAP_SLICE_THREAD_HAS_MF (1 << 5)
|
||||
/*
|
||||
* 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)
|
||||
|
||||
/**
|
||||
* AVCodec.codec_tags termination value
|
||||
@ -141,21 +146,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.
|
||||
|
@ -139,8 +139,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;
|
||||
|
||||
@ -481,4 +479,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,
|
||||
};
|
||||
|
@ -3550,7 +3550,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;
|
||||
}
|
||||
@ -3596,7 +3595,8 @@ AVCodec ff_mpeg4_decoder = {
|
||||
.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
|
||||
AV_CODEC_CAP_TRUNCATED | AV_CODEC_CAP_DELAY |
|
||||
AV_CODEC_CAP_FRAME_THREADS,
|
||||
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
|
||||
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM |
|
||||
FF_CODEC_CAP_ALLOCATE_PROGRESS,
|
||||
.flush = ff_mpeg_flush,
|
||||
.max_lowres = 3,
|
||||
.pix_fmts = ff_h263_hwaccel_pixfmt_list_420,
|
||||
|
@ -1772,7 +1772,6 @@ static av_cold int png_dec_init(AVCodecContext *avctx)
|
||||
}
|
||||
|
||||
if (!avctx->internal->is_copy) {
|
||||
avctx->internal->allocate_progress = 1;
|
||||
ff_pngdsp_init(&s->dsp);
|
||||
}
|
||||
|
||||
@ -1812,7 +1811,8 @@ AVCodec ff_apng_decoder = {
|
||||
.init_thread_copy = ONLY_IF_THREADS_ENABLED(png_dec_init),
|
||||
.update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
|
||||
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/,
|
||||
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
|
||||
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
|
||||
FF_CODEC_CAP_ALLOCATE_PROGRESS,
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -1829,7 +1829,8 @@ AVCodec ff_png_decoder = {
|
||||
.init_thread_copy = ONLY_IF_THREADS_ENABLED(png_dec_init),
|
||||
.update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
|
||||
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/,
|
||||
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_INIT_THREADSAFE,
|
||||
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_INIT_THREADSAFE |
|
||||
FF_CODEC_CAP_ALLOCATE_PROGRESS,
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -1845,6 +1846,7 @@ AVCodec ff_lscr_decoder = {
|
||||
.decode = decode_frame_lscr,
|
||||
.flush = decode_flush,
|
||||
.capabilities = AV_CODEC_CAP_DR1 /*| AV_CODEC_CAP_DRAW_HORIZ_BAND*/,
|
||||
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_INIT_THREADSAFE,
|
||||
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_INIT_THREADSAFE |
|
||||
FF_CODEC_CAP_ALLOCATE_PROGRESS,
|
||||
};
|
||||
#endif
|
||||
|
@ -201,7 +201,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);
|
||||
@ -903,7 +903,7 @@ static int thread_get_buffer_internal(AVCodecContext *avctx, ThreadFrame *f, int
|
||||
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) {
|
||||
|
@ -306,4 +306,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,
|
||||
};
|
||||
|
@ -1526,8 +1526,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;
|
||||
}
|
||||
|
||||
|
@ -585,4 +585,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,
|
||||
};
|
||||
|
@ -2330,8 +2330,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', '4', '0'))
|
||||
s->version = 3;
|
||||
else if (avctx->codec_tag == MKTAG('V', 'P', '3', '0'))
|
||||
@ -3266,7 +3264,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
|
||||
|
||||
@ -3284,6 +3282,7 @@ 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,
|
||||
};
|
||||
|
||||
#if CONFIG_VP4_DECODER
|
||||
@ -3301,5 +3300,6 @@ AVCodec ff_vp4_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,
|
||||
};
|
||||
#endif
|
||||
|
@ -2853,7 +2853,6 @@ int vp78_decode_init(AVCodecContext *avctx, int is_vp7)
|
||||
s->vp7 = avctx->codec->id == AV_CODEC_ID_VP7;
|
||||
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);
|
||||
|
||||
@ -2988,5 +2987,6 @@ AVCodec ff_vp8_decoder = {
|
||||
#endif
|
||||
NULL
|
||||
},
|
||||
.caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS,
|
||||
};
|
||||
#endif /* CONFIG_VP7_DECODER */
|
||||
|
@ -1741,7 +1741,6 @@ static av_cold int vp9_decode_init(AVCodecContext *avctx)
|
||||
{
|
||||
VP9Context *s = avctx->priv_data;
|
||||
|
||||
avctx->internal->allocate_progress = 1;
|
||||
s->last_bpp = 0;
|
||||
s->s.h.filter.sharpness = -1;
|
||||
|
||||
@ -1810,7 +1809,8 @@ AVCodec ff_vp9_decoder = {
|
||||
.close = vp9_decode_free,
|
||||
.decode = vp9_decode_frame,
|
||||
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS,
|
||||
.caps_internal = FF_CODEC_CAP_SLICE_THREAD_HAS_MF,
|
||||
.caps_internal = FF_CODEC_CAP_SLICE_THREAD_HAS_MF |
|
||||
FF_CODEC_CAP_ALLOCATE_PROGRESS,
|
||||
.flush = vp9_decode_flush,
|
||||
.init_thread_copy = ONLY_IF_THREADS_ENABLED(vp9_decode_init_thread_copy),
|
||||
.update_thread_context = ONLY_IF_THREADS_ENABLED(vp9_decode_update_thread_context),
|
||||
|
@ -1061,8 +1061,6 @@ static av_cold int wavpack_decode_init(AVCodecContext *avctx)
|
||||
|
||||
s->fdec_num = 0;
|
||||
|
||||
avctx->internal->allocate_progress = 1;
|
||||
|
||||
s->curr_frame.f = av_frame_alloc();
|
||||
s->prev_frame.f = av_frame_alloc();
|
||||
|
||||
@ -1719,5 +1717,6 @@ AVCodec ff_wavpack_decoder = {
|
||||
.init_thread_copy = ONLY_IF_THREADS_ENABLED(init_thread_copy),
|
||||
.update_thread_context = ONLY_IF_THREADS_ENABLED(update_thread_context),
|
||||
.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
|
||||
AV_CODEC_CAP_SLICE_THREADS
|
||||
AV_CODEC_CAP_SLICE_THREADS,
|
||||
.caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user