The cirros image was rebuilt against the 3.13.0-83 kernel, drivers e1000e, igbvf...
[packages/trusty/cirros-testvm.git] / cirros-testvm / src-cirros / buildroot-2015.05 / package / ffmpeg / 0014-fix-ff-thread-get-format.patch
1 From b52c216539bdbee830e0d306b372037d4e0cb35f Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= <Reimar.Doeffinger@gmx.de>
3 Date: Sun, 8 Mar 2015 19:44:12 +0100
4 Subject: [PATCH] pthread: Fix ff_thread_get_format issues when called outside
5  frame decode
6
7 Patch part of the XBMC patch set for ffmpeg, downloaded from
8 https://github.com/xbmc/FFmpeg/.
9
10 Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
11 ---
12  libavcodec/pthread_frame.c | 22 +++++++++++++++++++---
13  1 file changed, 19 insertions(+), 3 deletions(-)
14
15 diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
16 index 5a4ab84..c29d0a9 100644
17 --- a/libavcodec/pthread_frame.c
18 +++ b/libavcodec/pthread_frame.c
19 @@ -53,6 +53,7 @@
20   * Context used by codec threads and stored in their AVCodecInternal thread_ctx.
21   */
22  typedef struct PerThreadContext {
23 +    int main_thread;
24      struct FrameThreadContext *parent;
25  
26      pthread_t      thread;
27 @@ -83,7 +84,8 @@ typedef struct PerThreadContext {
28                                       * Set when the codec calls get_format().
29                                       * State is returned to STATE_SETTING_UP afterwards.
30                                       */
31 -        STATE_SETUP_FINISHED        ///< Set after the codec has called ff_thread_finish_setup().
32 +        STATE_SETUP_FINISHED,       ///< Set after the codec has called ff_thread_finish_setup().
33 +        STATE_UPDATE_CONTEXT,       ///< Main thread is updating its context
34      } state;
35  
36      /**
37 @@ -105,6 +107,7 @@ typedef struct PerThreadContext {
38   * Context stored in the client AVCodecInternal thread_ctx.
39   */
40  typedef struct FrameThreadContext {
41 +    int main_thread;
42      PerThreadContext *threads;     ///< The contexts for each thread.
43      PerThreadContext *prev_thread; ///< The last thread submit_packet() was called on.
44  
45 @@ -143,6 +146,7 @@ static attribute_align_arg void *frame_worker_thread(void *arg)
46      AVCodecContext *avctx = p->avctx;
47      const AVCodec *codec = avctx->codec;
48  
49 +    av_assert0(!p->main_thread);
50      pthread_mutex_lock(&p->mutex);
51      while (1) {
52              while (p->state == STATE_INPUT_READY && !fctx->die)
53 @@ -330,6 +334,8 @@ static int submit_packet(PerThreadContext *p, AVPacket *avpkt)
54  
55      pthread_mutex_lock(&p->mutex);
56  
57 +    p->state = STATE_UPDATE_CONTEXT;
58 +
59      release_delayed_buffers(p);
60  
61      if (prev_thread) {
62 @@ -408,6 +414,7 @@ int ff_thread_decode_frame(AVCodecContext *avctx,
63      int finished = fctx->next_finished;
64      PerThreadContext *p;
65      int err;
66 +    av_assert0(fctx->main_thread);
67  
68      /*
69       * Submit a packet to the next decoding thread.
70 @@ -515,6 +522,7 @@ void ff_thread_finish_setup(AVCodecContext *avctx) {
71  
72      if (!(avctx->active_thread_type&FF_THREAD_FRAME)) return;
73  
74 +    av_assert0(!p->main_thread);
75      if(p->state == STATE_SETUP_FINISHED){
76          av_log(avctx, AV_LOG_WARNING, "Multiple ff_thread_finish_setup() calls\n");
77      }
78 @@ -549,6 +557,7 @@ void ff_frame_thread_free(AVCodecContext *avctx, int thread_count)
79      const AVCodec *codec = avctx->codec;
80      int i;
81  
82 +    av_assert0(fctx->main_thread);
83      park_frame_worker_threads(fctx, thread_count);
84  
85      if (fctx->prev_thread && fctx->prev_thread != fctx->threads)
86 @@ -634,6 +643,7 @@ int ff_frame_thread_init(AVCodecContext *avctx)
87      }
88  
89      avctx->internal->thread_ctx = fctx = av_mallocz(sizeof(FrameThreadContext));
90 +    fctx->main_thread = 1;
91  
92      fctx->threads = av_mallocz_array(thread_count, sizeof(PerThreadContext));
93      pthread_mutex_init(&fctx->buffer_mutex, NULL);
94 @@ -718,6 +728,7 @@ void ff_thread_flush(AVCodecContext *avctx)
95  
96      if (!fctx) return;
97  
98 +    av_assert0(fctx->main_thread);
99      park_frame_worker_threads(fctx, avctx->thread_count);
100      if (fctx->prev_thread) {
101          if (fctx->prev_thread != &fctx->threads[0])
102 @@ -743,7 +754,10 @@ void ff_thread_flush(AVCodecContext *avctx)
103  int ff_thread_can_start_frame(AVCodecContext *avctx)
104  {
105      PerThreadContext *p = avctx->internal->thread_ctx;
106 -    if ((avctx->active_thread_type&FF_THREAD_FRAME) && p->state != STATE_SETTING_UP &&
107 +    if (!(avctx->active_thread_type&FF_THREAD_FRAME))
108 +        return 1;
109 +    av_assert0(!p->main_thread);
110 +    if (p->state != STATE_SETTING_UP &&
111          (avctx->codec->update_thread_context || !THREAD_SAFE_CALLBACKS(avctx))) {
112          return 0;
113      }
114 @@ -762,6 +776,7 @@ static int thread_get_buffer_internal(AVCodecContext *avctx, ThreadFrame *f, int
115      if (!(avctx->active_thread_type & FF_THREAD_FRAME))
116          return ff_get_buffer(avctx, f->f, flags);
117  
118 +    av_assert0(!p->main_thread);
119      if (p->state != STATE_SETTING_UP &&
120          (avctx->codec->update_thread_context || !THREAD_SAFE_CALLBACKS(avctx))) {
121          av_log(avctx, AV_LOG_ERROR, "get_buffer() cannot be called after ff_thread_finish_setup()\n");
122 @@ -819,7 +834,8 @@ enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixe
123      enum AVPixelFormat res;
124      PerThreadContext *p = avctx->internal->thread_ctx;
125      if (!(avctx->active_thread_type & FF_THREAD_FRAME) || avctx->thread_safe_callbacks ||
126 -        avctx->get_format == avcodec_default_get_format)
127 +        avctx->get_format == avcodec_default_get_format ||
128 +        p->main_thread || p->state == STATE_UPDATE_CONTEXT)
129          return ff_get_format(avctx, fmt);
130      if (p->state != STATE_SETTING_UP) {
131          av_log(avctx, AV_LOG_ERROR, "get_format() cannot be called after ff_thread_finish_setup()\n");