From c477a458d7c50f45f55469b94af945cf7b83cf52 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Wed, 7 Sep 2005 10:06:56 +0000 Subject: [PATCH] gst/base/gstbasesink.c (gst_base_sink_activate_pull): Fix a race condition whereby the pad's task function is entered... Original commit message from CVS: 2005-09-07 Andy Wingo * gst/base/gstbasesink.c (gst_base_sink_activate_pull): Fix a race condition whereby the pad's task function is entered before the pad_mode variable was set. --- ChangeLog | 6 ++++++ gst/base/gstbasesink.c | 11 +++++++++-- libs/gst/base/gstbasesink.c | 11 +++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 11164559ba2..832edc69e24 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-09-07 Andy Wingo + + * gst/base/gstbasesink.c (gst_base_sink_activate_pull): Fix a race + condition whereby the pad's task function is entered before the + pad_mode variable was set. + 2005-09-07 Jan Schmidt * gst/gstpad.c: (gst_pad_alloc_buffer): diff --git a/gst/base/gstbasesink.c b/gst/base/gstbasesink.c index b8964c8013c..d3048cb3e06 100644 --- a/gst/base/gstbasesink.c +++ b/gst/base/gstbasesink.c @@ -1232,21 +1232,28 @@ gst_base_sink_activate_pull (GstPad * pad, gboolean active) if (G_UNLIKELY (peer == NULL)) { g_warning ("Trying to activate pad in pull mode, but no peer"); result = FALSE; + basesink->pad_mode = GST_ACTIVATE_NONE; } else { if (gst_pad_activate_pull (peer, TRUE)) { basesink->have_newsegment = TRUE; basesink->segment_start = basesink->segment_stop = 0; + + /* set the pad mode before starting the task so that it's in the + correct state for the new thread... */ + basesink->pad_mode = GST_ACTIVATE_PULL; result = gst_pad_start_task (pad, (GstTaskFunction) gst_base_sink_loop, pad); + /* but if starting the thread fails, set it back */ + if (!result) + basesink->pad_mode = GST_ACTIVATE_NONE; } else { GST_DEBUG_OBJECT (pad, "Failed to activate peer in pull mode"); result = FALSE; + basesink->pad_mode = GST_ACTIVATE_NONE; } gst_object_unref (peer); } - - basesink->pad_mode = result ? GST_ACTIVATE_PULL : GST_ACTIVATE_NONE; } } else { if (G_UNLIKELY (basesink->pad_mode != GST_ACTIVATE_PULL)) { diff --git a/libs/gst/base/gstbasesink.c b/libs/gst/base/gstbasesink.c index b8964c8013c..d3048cb3e06 100644 --- a/libs/gst/base/gstbasesink.c +++ b/libs/gst/base/gstbasesink.c @@ -1232,21 +1232,28 @@ gst_base_sink_activate_pull (GstPad * pad, gboolean active) if (G_UNLIKELY (peer == NULL)) { g_warning ("Trying to activate pad in pull mode, but no peer"); result = FALSE; + basesink->pad_mode = GST_ACTIVATE_NONE; } else { if (gst_pad_activate_pull (peer, TRUE)) { basesink->have_newsegment = TRUE; basesink->segment_start = basesink->segment_stop = 0; + + /* set the pad mode before starting the task so that it's in the + correct state for the new thread... */ + basesink->pad_mode = GST_ACTIVATE_PULL; result = gst_pad_start_task (pad, (GstTaskFunction) gst_base_sink_loop, pad); + /* but if starting the thread fails, set it back */ + if (!result) + basesink->pad_mode = GST_ACTIVATE_NONE; } else { GST_DEBUG_OBJECT (pad, "Failed to activate peer in pull mode"); result = FALSE; + basesink->pad_mode = GST_ACTIVATE_NONE; } gst_object_unref (peer); } - - basesink->pad_mode = result ? GST_ACTIVATE_PULL : GST_ACTIVATE_NONE; } } else { if (G_UNLIKELY (basesink->pad_mode != GST_ACTIVATE_PULL)) {