[FFmpeg-cvslog] mt: proper locking around release_buffer calls.

Ronald S. Bultje git at videolan.org
Wed Jul 27 12:49:44 CEST 2011


ffmpeg | branch: release/0.7 | Ronald S. Bultje <rsbultje at gmail.com> | Sun Jul 10 17:28:28 2011 -0700| [5e3578893a06644e226bcfefc726b60e2d75a890] | committer: Reinhard Tartler

mt: proper locking around release_buffer calls.

This fixes a crash when seeking in some webm files with many
threads (e.g. 8).
(cherry picked from commit 5eafc8b46644764f8aef1b7b2ecae53ee8034822)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5e3578893a06644e226bcfefc726b60e2d75a890
---

 libavcodec/pthread.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
index 9fea9a0..e546c21 100644
--- a/libavcodec/pthread.c
+++ b/libavcodec/pthread.c
@@ -408,9 +408,10 @@ static void release_delayed_buffers(PerThreadContext *p)
     FrameThreadContext *fctx = p->parent;
 
     while (p->num_released_buffers > 0) {
-        AVFrame *f = &p->released_buffers[--p->num_released_buffers];
+        AVFrame *f;
 
         pthread_mutex_lock(&fctx->buffer_mutex);
+        f = &p->released_buffers[--p->num_released_buffers];
         free_progress(f);
         f->thread_opaque = NULL;
 
@@ -839,6 +840,7 @@ int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f)
 void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f)
 {
     PerThreadContext *p = avctx->thread_opaque;
+    FrameThreadContext *fctx;
 
     if (!(avctx->active_thread_type&FF_THREAD_FRAME)) {
         avctx->release_buffer(avctx, f);
@@ -854,7 +856,10 @@ void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f)
         av_log(avctx, AV_LOG_DEBUG, "thread_release_buffer called on pic %p, %d buffers used\n",
                                     f, f->owner->internal_buffer_count);
 
+    fctx = p->parent;
+    pthread_mutex_lock(&fctx->buffer_mutex);
     p->released_buffers[p->num_released_buffers++] = *f;
+    pthread_mutex_unlock(&fctx->buffer_mutex);
     memset(f->data, 0, sizeof(f->data));
 }
 



More information about the ffmpeg-cvslog mailing list