From e51fe6c1814c6048fd46e93b917bcf054aba3c31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 20 Aug 2010 10:24:33 +0200 Subject: [PATCH] imagefreeze: Protect the flushing-seek variable by the srcpad's stream lock This fixes a subtle race condition, that caused bufferalloc to fail with wrong-state due to a seek but caused it to be not retried as it should. --- gst/imagefreeze/gstimagefreeze.c | 9 ++++++++- gst/imagefreeze/gstimagefreeze.h | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/gst/imagefreeze/gstimagefreeze.c b/gst/imagefreeze/gstimagefreeze.c index 2b21906d9a..b8e99772c9 100644 --- a/gst/imagefreeze/gstimagefreeze.c +++ b/gst/imagefreeze/gstimagefreeze.c @@ -329,9 +329,16 @@ gst_image_freeze_sink_bufferalloc (GstPad * pad, guint64 offset, guint size, GST_OBJECT_UNLOCK (self); if (do_alloc) { + gboolean seeking = FALSE; + do { + GST_PAD_STREAM_LOCK (self->srcpad); ret = gst_pad_alloc_buffer (self->srcpad, offset, size, caps, buf); - } while (ret == GST_FLOW_WRONG_STATE && g_atomic_int_get (&self->seeking)); + + seeking = ret == GST_FLOW_WRONG_STATE + && g_atomic_int_get (&self->seeking); + GST_PAD_STREAM_UNLOCK (self->srcpad); + } while (seeking); if (G_UNLIKELY (ret != GST_FLOW_OK)) GST_ERROR_OBJECT (pad, "Allocating buffer failed: %s", diff --git a/gst/imagefreeze/gstimagefreeze.h b/gst/imagefreeze/gstimagefreeze.h index b9bc53f39c..fff8c2ea3e 100644 --- a/gst/imagefreeze/gstimagefreeze.h +++ b/gst/imagefreeze/gstimagefreeze.h @@ -56,7 +56,8 @@ struct _GstImageFreeze guint64 offset; - /* TRUE if currently doing a flushing seek */ + /* TRUE if currently doing a flushing seek, protected + * by srcpad's stream lock */ gint seeking; };