summaryrefslogtreecommitdiff
path: root/libavcodec/pthread_frame.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2017-01-09 18:04:42 +0100
committerAnton Khirnov <anton@khirnov.net>2020-04-10 15:24:54 +0200
commit1f4cf92cfbd3accbae582ac63126ed5570ddfd37 (patch)
tree0d08c281a748689d53350a929fb0df022dc6ef2c /libavcodec/pthread_frame.c
parent665e5b0fba41a8bae2269d9ce8929a24002e5907 (diff)
pthread_frame: merge the functionality for normal decoder init and init_thread_copy
The current design, where - proper init is called for the first per-thread context - first thread's private data is copied into private data for all the other threads - a "fixup" function is called for all the other threads to e.g. allocate dynamically allocated data is very fragile and hard to follow, so it is abandoned. Instead, the same init function is used to init each per-thread context. Where necessary, AVCodecInternal.is_copy can be used to differentiate between the first thread and the other ones (e.g. for decoding the extradata just once).
Diffstat (limited to 'libavcodec/pthread_frame.c')
-rw-r--r--libavcodec/pthread_frame.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index f078790737..69671c90fb 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -703,7 +703,10 @@ void ff_frame_thread_free(AVCodecContext *avctx, int thread_count)
av_freep(&p->released_buffers);
if (i && p->avctx) {
+ if (codec->priv_class)
+ av_opt_free(p->avctx->priv_data);
av_freep(&p->avctx->priv_data);
+
av_freep(&p->avctx->slice_offset);
}
@@ -809,28 +812,30 @@ int ff_frame_thread_init(AVCodecContext *avctx)
copy->internal->thread_ctx = p;
copy->internal->last_pkt_props = &p->avpkt;
- if (!i) {
- src = copy;
-
- if (codec->init)
- err = codec->init(copy);
-
- update_context_from_thread(avctx, copy, 1);
- } else {
- copy->priv_data = av_malloc(codec->priv_data_size);
+ if (i) {
+ copy->priv_data = av_mallocz(codec->priv_data_size);
if (!copy->priv_data) {
err = AVERROR(ENOMEM);
goto error;
}
- memcpy(copy->priv_data, src->priv_data, codec->priv_data_size);
- copy->internal->is_copy = 1;
- if (codec->init_thread_copy)
- err = codec->init_thread_copy(copy);
+ if (codec->priv_class) {
+ *(const AVClass **)copy->priv_data = codec->priv_class;
+ err = av_opt_copy(copy->priv_data, src->priv_data);
+ if (err < 0)
+ goto error;
+ }
+ copy->internal->is_copy = 1;
}
+ if (codec->init)
+ err = codec->init(copy);
+
if (err) goto error;
+ if (!i)
+ update_context_from_thread(avctx, copy, 1);
+
atomic_init(&p->debug_threads, (copy->debug & FF_DEBUG_THREADS) != 0);
err = AVERROR(pthread_create(&p->thread, NULL, frame_worker_thread, p));