summaryrefslogtreecommitdiff
path: root/libavcodec/utils.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2017-01-17 16:28:30 +0100
committerAnton Khirnov <anton@khirnov.net>2020-04-10 15:47:30 +0200
commit9d6785d426be1ac045c0b6a13b7447459389c40b (patch)
tree34d9c009685787bab847808826e49c766fa632cd /libavcodec/utils.c
parent29445374305fcc422fb2abe55bb5a877b95c0ef2 (diff)
lavc: do not implicitly share the frame pool between threads
Currently the frame pool used by the default get_buffer2() implementation is a single struct, allocated when opening the decoder. A pointer to it is simply copied to each frame thread and we assume that no thread attempts to modify it at an unexpected time. This is rather fragile and potentially dangerous. With this commit, the frame pool is made refcounted, with the reference being propagated across threads along with other context variables. The frame pool is now also immutable - when the stream parameters change we drop the old reference and create a new one.
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r--libavcodec/utils.c13
1 files changed, 2 insertions, 11 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 4ab8cff4f5..26c038dfd9 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -583,12 +583,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
}
avctx->internal = avci;
- avci->pool = av_mallocz(sizeof(*avci->pool));
- if (!avci->pool) {
- ret = AVERROR(ENOMEM);
- goto free_and_end;
- }
-
avci->to_free = av_frame_alloc();
if (!avci->to_free) {
ret = AVERROR(ENOMEM);
@@ -1076,7 +1070,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
av_packet_free(&avci->ds.in_pkt);
ff_decode_bsfs_uninit(avctx);
- av_freep(&avci->pool);
+ av_buffer_unref(&avci->pool);
}
av_freep(&avci);
avctx->internal = NULL;
@@ -1111,7 +1105,6 @@ av_cold int avcodec_close(AVCodecContext *avctx)
return 0;
if (avcodec_is_open(avctx)) {
- FramePool *pool = avctx->internal->pool;
if (CONFIG_FRAME_THREAD_ENCODER &&
avctx->internal->frame_thread_encoder && avctx->thread_count > 1) {
ff_frame_thread_encoder_free(avctx);
@@ -1130,9 +1123,7 @@ av_cold int avcodec_close(AVCodecContext *avctx)
av_packet_free(&avctx->internal->ds.in_pkt);
- for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++)
- av_buffer_pool_uninit(&pool->pools[i]);
- av_freep(&avctx->internal->pool);
+ av_buffer_unref(&avctx->internal->pool);
if (avctx->hwaccel && avctx->hwaccel->uninit)
avctx->hwaccel->uninit(avctx);