appsink: Only emit EOS signal after all buffers are consumed

Otherwise the application will possibly shut down the pipeline already
because EOS is received, while there are still some buffers pending.
This commit is contained in:
Sebastian Dröge 2015-01-20 19:14:21 +01:00
parent 661588b150
commit ce8d261cd6

View file

@ -571,20 +571,36 @@ gst_app_sink_event (GstBaseSink * sink, GstEvent * event)
g_queue_push_tail (priv->queue, gst_event_ref (event)); g_queue_push_tail (priv->queue, gst_event_ref (event));
g_mutex_unlock (&priv->mutex); g_mutex_unlock (&priv->mutex);
break; break;
case GST_EVENT_EOS: case GST_EVENT_EOS:{
gboolean emit = TRUE;
g_mutex_lock (&priv->mutex); g_mutex_lock (&priv->mutex);
GST_DEBUG_OBJECT (appsink, "receiving EOS"); GST_DEBUG_OBJECT (appsink, "receiving EOS");
priv->is_eos = TRUE; priv->is_eos = TRUE;
g_cond_signal (&priv->cond); g_cond_signal (&priv->cond);
g_mutex_unlock (&priv->mutex); g_mutex_unlock (&priv->mutex);
/* emit EOS now */ g_mutex_lock (&priv->mutex);
if (priv->callbacks.eos) /* wait until all buffers are consumed or we're flushing.
priv->callbacks.eos (appsink, priv->user_data); * Otherwise we might signal EOS before all buffers are
else * consumed, which is a bit confusing for the application
g_signal_emit (appsink, gst_app_sink_signals[SIGNAL_EOS], 0); */
while (priv->num_buffers > 0 && !priv->flushing)
g_cond_wait (&priv->cond, &priv->mutex);
if (priv->flushing)
emit = FALSE;
g_mutex_unlock (&priv->mutex);
if (emit) {
/* emit EOS now */
if (priv->callbacks.eos)
priv->callbacks.eos (appsink, priv->user_data);
else
g_signal_emit (appsink, gst_app_sink_signals[SIGNAL_EOS], 0);
}
break; break;
}
case GST_EVENT_FLUSH_START: case GST_EVENT_FLUSH_START:
/* we don't have to do anything here, the base class will call unlock /* we don't have to do anything here, the base class will call unlock
* which will make sure we exit the _render method */ * which will make sure we exit the _render method */