int requested_flags; ///< flags passed to get_buffer() for requested_frame
int die; ///< Set when the thread should exit.
+
+ int hwaccel_serializing;
} PerThreadContext;
/**
PerThreadContext *prev_thread; ///< The last thread submit_packet() was called on.
pthread_mutex_t buffer_mutex; ///< Mutex used to protect get/release_buffer().
+ /**
+ * This lock is used for ensuring threads run in serial when hwaccel
+ * is used.
+ */
+ pthread_mutex_t hwaccel_mutex;
int next_decoding; ///< The next context to submit a packet to.
int next_finished; ///< The next context to return output from.
ff_thread_finish_setup(avctx);
pthread_mutex_lock(&p->mutex);
+
+ /* If a decoder supports hwaccel, then it must call ff_get_format().
+ * Since that call must happen before ff_thread_finish_setup(), the
+ * decoder is required to implement update_thread_context() and call
+ * ff_thread_finish_setup() manually. Therefore the above
+ * ff_thread_finish_setup() call did not happen and hwaccel_serializing
+ * cannot be true here. */
+ av_assert0(!p->hwaccel_serializing);
+
+ /* if the previous thread uses hwaccel then we take the lock to ensure
+ * the threads don't run concurrently */
+ if (avctx->hwaccel) {
+ pthread_mutex_lock(&p->parent->hwaccel_mutex);
+ p->hwaccel_serializing = 1;
+ }
+
av_frame_unref(p->frame);
p->got_frame = 0;
p->result = codec->decode(avctx, p->frame, &p->got_frame, &p->avpkt);
if (atomic_load(&p->state) == STATE_SETTING_UP)
ff_thread_finish_setup(avctx);
+ if (p->hwaccel_serializing) {
+ p->hwaccel_serializing = 0;
+ pthread_mutex_unlock(&p->parent->hwaccel_mutex);
+ }
+
atomic_store(&p->state, STATE_INPUT_READY);
pthread_mutex_lock(&p->progress_mutex);
if (!(avctx->active_thread_type&FF_THREAD_FRAME)) return;
+ if (avctx->hwaccel && !p->hwaccel_serializing) {
+ pthread_mutex_lock(&p->parent->hwaccel_mutex);
+ p->hwaccel_serializing = 1;
+ }
+
pthread_mutex_lock(&p->progress_mutex);
atomic_store(&p->state, STATE_SETUP_FINISHED);
av_freep(&fctx->threads);
pthread_mutex_destroy(&fctx->buffer_mutex);
+ pthread_mutex_destroy(&fctx->hwaccel_mutex);
av_freep(&avctx->internal->thread_ctx);
}
}
pthread_mutex_init(&fctx->buffer_mutex, NULL);
+ pthread_mutex_init(&fctx->hwaccel_mutex, NULL);
fctx->delaying = 1;
for (i = 0; i < thread_count; i++) {