Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.88 KB | None | 0 0
  1. diff --git a/libavcodec/utils.c b/libavcodec/utils.c
  2. index 0226e36ee7..bb9c28d8f7 100644
  3. --- a/libavcodec/utils.c
  4. +++ b/libavcodec/utils.c
  5. @@ -25,6 +25,8 @@
  6.   * utils.
  7.   */
  8.  
  9. +
  10. +#include <pthread.h>
  11.  #include "config.h"
  12.  #include "libavutil/attributes.h"
  13.  #include "libavutil/avassert.h"
  14. @@ -535,7 +537,7 @@ static void ff_unlock_avcodec(const AVCodec *codec)
  15.          ff_mutex_unlock(&codec_mutex);
  16.  }
  17.  
  18. -int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *cod
  19. ec, AVDictionary **options)
  20. +static int attribute_align_arg avcodec_open2_internal(AVCodecContext *avctx, co
  21. nst AVCodec *codec, AVDictionary **options)
  22.  {
  23.      int ret = 0;
  24.      int codec_init_ok = 0;
  25. @@ -1076,6 +1078,42 @@ FF_ENABLE_DEPRECATION_WARNINGS
  26.      goto end;
  27.  }
  28.  
  29. +typedef struct ThreadData {
  30. +    AVCodecContext *ctx;
  31. +    const AVCodec *codec;
  32. +    AVDictionary *options;
  33. +    int ret;
  34. +} ThreadData;
  35. +
  36. +static void *test_thread(void *arg)
  37. +{
  38. +    ThreadData *td = arg;
  39. +    td->ret = avcodec_open2_internal(td->ctx, td->codec, &td->options);
  40. +    avcodec_free_context(&td->ctx);
  41. +    av_opt_free(&td->options);
  42. +    return NULL;
  43. +}
  44. +
  45. +int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
  46. +{
  47. +    ThreadData td = {
  48. +        .ctx   = avcodec_alloc_context3(codec ? codec : avctx->codec),
  49. +        .codec = codec,
  50. +    };
  51. +    pthread_t t;
  52. +    int ret;
  53. +
  54. +    av_assert0(td.ctx);
  55. +    if (options)
  56. +        av_assert0(!av_dict_copy(&td.options, *options, 0));
  57. +    av_assert0(!avcodec_copy_context(td.ctx, avctx));
  58. +    pthread_create(&t, NULL, test_thread, &td);
  59. +    ret = avcodec_open2_internal(avctx, codec, options);
  60. +    pthread_join(t, NULL);
  61. +    av_assert0(ret == td.ret);
  62. +    return ret;
  63. +}
  64. +
  65.  void avcodec_flush_buffers(AVCodecContext *avctx)
  66.  {
  67.      AVCodecInternal *avci = avctx->internal;
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement