Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/libavcodec/utils.c b/libavcodec/utils.c
- index 0226e36ee7..bb9c28d8f7 100644
- --- a/libavcodec/utils.c
- +++ b/libavcodec/utils.c
- @@ -25,6 +25,8 @@
- * utils.
- */
- +
- +#include <pthread.h>
- #include "config.h"
- #include "libavutil/attributes.h"
- #include "libavutil/avassert.h"
- @@ -535,7 +537,7 @@ static void ff_unlock_avcodec(const AVCodec *codec)
- ff_mutex_unlock(&codec_mutex);
- }
- -int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *cod
- ec, AVDictionary **options)
- +static int attribute_align_arg avcodec_open2_internal(AVCodecContext *avctx, co
- nst AVCodec *codec, AVDictionary **options)
- {
- int ret = 0;
- int codec_init_ok = 0;
- @@ -1076,6 +1078,42 @@ FF_ENABLE_DEPRECATION_WARNINGS
- goto end;
- }
- +typedef struct ThreadData {
- + AVCodecContext *ctx;
- + const AVCodec *codec;
- + AVDictionary *options;
- + int ret;
- +} ThreadData;
- +
- +static void *test_thread(void *arg)
- +{
- + ThreadData *td = arg;
- + td->ret = avcodec_open2_internal(td->ctx, td->codec, &td->options);
- + avcodec_free_context(&td->ctx);
- + av_opt_free(&td->options);
- + return NULL;
- +}
- +
- +int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
- +{
- + ThreadData td = {
- + .ctx = avcodec_alloc_context3(codec ? codec : avctx->codec),
- + .codec = codec,
- + };
- + pthread_t t;
- + int ret;
- +
- + av_assert0(td.ctx);
- + if (options)
- + av_assert0(!av_dict_copy(&td.options, *options, 0));
- + av_assert0(!avcodec_copy_context(td.ctx, avctx));
- + pthread_create(&t, NULL, test_thread, &td);
- + ret = avcodec_open2_internal(avctx, codec, options);
- + pthread_join(t, NULL);
- + av_assert0(ret == td.ret);
- + return ret;
- +}
- +
- void avcodec_flush_buffers(AVCodecContext *avctx)
- {
- AVCodecInternal *avci = avctx->internal;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement