Otherwise it isn't actually protecting anything...
---
libavcodec/pthread.c | 18 ++++++++++--------
1 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
index 042a1c2..56d6124 100644
--- a/libavcodec/pthread.c
+++ b/libavcodec/pthread.c
@@ -54,7 +54,6 @@ typedef struct PerThreadContext {
pthread_mutex_t mutex; ///< Mutex used to protect the contents of the PerThreadContext.
pthread_mutex_t progress_mutex; ///< Mutex used to protect frame progress values and progress_cond.
- pthread_mutex_t buffer_mutex; ///< Mutex used to protect get/release_buffer().
AVCodecContext *avctx; ///< Context used to decode frames passed to this thread.
@@ -97,6 +96,8 @@ typedef struct FrameThreadContext {
* While it is set, ff_en/decode_frame_threaded won't return any results.
*/
+ pthread_mutex_t buffer_mutex; ///< Mutex used to protect get/release_buffer().
+
int die; ///< Set to cause threads to exit.
} FrameThreadContext;
@@ -281,6 +282,7 @@ static int frame_thread_init(AVCodecContext *avctx)
avctx->thread_opaque = fctx = av_mallocz(sizeof(FrameThreadContext));
fctx->delaying = 1;
+ pthread_mutex_init(&fctx->buffer_mutex, NULL);
fctx->threads = av_mallocz(sizeof(PerThreadContext) * thread_count);
@@ -290,7 +292,6 @@ static int frame_thread_init(AVCodecContext *avctx)
pthread_mutex_init(&p->mutex, NULL);
pthread_mutex_init(&p->progress_mutex, NULL);
- pthread_mutex_init(&p->buffer_mutex, NULL);
pthread_cond_init(&p->input_cond, NULL);
pthread_cond_init(&p->progress_cond, NULL);
pthread_cond_init(&p->output_cond, NULL);
@@ -386,15 +387,16 @@ static void update_context_from_user(AVCodecContext *dst, AVCodecContext *src)
/// Release all frames passed to ff_release_buffer()
static void handle_delayed_releases(PerThreadContext *p)
{
+ FrameThreadContext *fctx = p->parent;
+
while (p->num_released_buffers > 0) {
AVFrame *f = &p->released_buffers[--p->num_released_buffers];
- PerThreadContext *owner = f->owner->thread_opaque;
av_freep(&f->thread_opaque);
- pthread_mutex_lock(&owner->buffer_mutex);
+ pthread_mutex_lock(&fctx->buffer_mutex);
f->owner->release_buffer(f->owner, f);
- pthread_mutex_unlock(&owner->buffer_mutex);
+ pthread_mutex_unlock(&fctx->buffer_mutex);
}
}
@@ -588,7 +590,6 @@ static void frame_thread_free(AVCodecContext *avctx)
pthread_mutex_destroy(&p->mutex);
pthread_mutex_destroy(&p->progress_mutex);
- pthread_mutex_destroy(&p->buffer_mutex);
pthread_cond_destroy(&p->input_cond);
pthread_cond_destroy(&p->progress_cond);
pthread_cond_destroy(&p->output_cond);
@@ -601,6 +602,7 @@ static void frame_thread_free(AVCodecContext *avctx)
}
av_freep(&fctx->threads);
+ pthread_mutex_destroy(&fctx->buffer_mutex);
av_freep(&avctx->thread_opaque);
}
@@ -635,9 +637,9 @@ int ff_get_buffer(AVCodecContext *avctx, AVFrame *f)
progress[0] =
progress[1] = -1;
- pthread_mutex_lock(&p->buffer_mutex);
+ pthread_mutex_lock(&p->parent->buffer_mutex);
ret = avctx->get_buffer(avctx, f);
- pthread_mutex_unlock(&p->buffer_mutex);
+ pthread_mutex_unlock(&p->parent->buffer_mutex);
/*
* The buffer list isn't shared between threads,
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc