libs/gst/base/gstbasesink.c: Don't accept anything after an EOS, return UNEXPECTED instead.

Original commit message from CVS:
* libs/gst/base/gstbasesink.c:
(gst_base_sink_queue_object_unlocked), (gst_base_sink_event),
(gst_base_sink_change_state):
Don't accept anything after an EOS, return UNEXPECTED instead.
* tests/check/elements/fakesink.c: (GST_START_TEST),
(fakesink_suite):
Unit test for new EOS behaviour.
This commit is contained in:
Wim Taymans 2007-04-05 10:10:08 +00:00
parent bcc9fc59a9
commit cc82861367
3 changed files with 201 additions and 12 deletions

View file

@ -1,3 +1,14 @@
2007-04-05 Wim Taymans <wim@fluendo.com>
* libs/gst/base/gstbasesink.c:
(gst_base_sink_queue_object_unlocked), (gst_base_sink_event),
(gst_base_sink_change_state):
Don't accept anything after an EOS, return UNEXPECTED instead.
* tests/check/elements/fakesink.c: (GST_START_TEST),
(fakesink_suite):
Unit test for new EOS behaviour.
2007-04-05 Wim Taymans <wim@fluendo.com>
* gst/gstelement.c: (gst_element_get_request_pad):

View file

@ -193,7 +193,11 @@ struct _GstBaseSinkPrivate
/* latency stuff */
GstClockTime latency;
/* if we already commited the state */
gboolean commited;
/* when we received EOS */
gboolean received_eos;
};
#define DO_RUNNING_AVG(avg,val,size) (((val) + ((size)-1) * (avg)) / (size))
@ -1825,6 +1829,9 @@ gst_base_sink_queue_object_unlocked (GstBaseSink * basesink, GstPad * pad,
gint length;
GQueue *q;
if (G_UNLIKELY (basesink->priv->received_eos))
goto was_eos;
if (G_UNLIKELY (basesink->need_preroll)) {
if (G_LIKELY (prerollable))
basesink->preroll_queued++;
@ -1870,6 +1877,12 @@ gst_base_sink_queue_object_unlocked (GstBaseSink * basesink, GstPad * pad,
return ret;
/* special cases */
was_eos:
{
GST_DEBUG_OBJECT (basesink, "we are EOS");
gst_mini_object_unref (obj);
return GST_FLOW_UNEXPECTED;
}
preroll_failed:
{
GST_DEBUG_OBJECT (basesink, "preroll failed, reason %s",
@ -1952,6 +1965,9 @@ gst_base_sink_event (GstPad * pad, GstEvent * event)
if (G_UNLIKELY (ret != GST_FLOW_OK))
result = FALSE;
else
/* we are now EOS, and refuse more buffers */
basesink->priv->received_eos = TRUE;
break;
}
case GST_EVENT_NEWSEGMENT:
@ -1960,19 +1976,24 @@ gst_base_sink_event (GstPad * pad, GstEvent * event)
GST_DEBUG_OBJECT (basesink, "newsegment %p", event);
basesink->have_newsegment = TRUE;
/* the new segment is a non prerollable item and does not block anything,
* we need to configure the current clipping segment and insert the event
* in the queue to serialize it with the buffers for rendering. */
gst_base_sink_configure_segment (basesink, pad, event,
basesink->abidata.ABI.clip_segment);
ret =
gst_base_sink_queue_object (basesink, pad,
GST_MINI_OBJECT_CAST (event), FALSE);
if (G_UNLIKELY (ret != GST_FLOW_OK))
if (G_UNLIKELY (basesink->priv->received_eos))
/* we can't accept anything when we are EOS */
result = FALSE;
else {
/* the new segment is a non prerollable item and does not block anything,
* we need to configure the current clipping segment and insert the event
* in the queue to serialize it with the buffers for rendering. */
gst_base_sink_configure_segment (basesink, pad, event,
basesink->abidata.ABI.clip_segment);
ret =
gst_base_sink_queue_object (basesink, pad,
GST_MINI_OBJECT_CAST (event), FALSE);
if (G_UNLIKELY (ret != GST_FLOW_OK))
result = FALSE;
else
basesink->have_newsegment = TRUE;
}
break;
}
case GST_EVENT_FLUSH_START:
@ -2012,6 +2033,8 @@ gst_base_sink_event (GstPad * pad, GstEvent * event)
gst_segment_init (basesink->abidata.ABI.clip_segment,
GST_FORMAT_UNDEFINED);
basesink->have_newsegment = FALSE;
/* we flush out the EOS event as well now */
basesink->priv->received_eos = FALSE;
gst_event_unref (event);
break;
@ -2814,6 +2837,7 @@ gst_base_sink_change_state (GstElement * element, GstStateChange transition)
basesink->priv->eos_rtime = -1;
basesink->priv->latency = 0;
basesink->eos = FALSE;
basesink->priv->received_eos = FALSE;
gst_base_sink_reset_qos (basesink);
basesink->priv->commited = FALSE;
ret = GST_STATE_CHANGE_ASYNC;

View file

@ -3,6 +3,7 @@
* unit test for fakesink
*
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
* <2007> Wim Taymans <wim@fluendo.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -292,6 +293,158 @@ GST_START_TEST (test_preroll_sync)
GST_END_TEST;
/* after EOS, we refuse everything */
GST_START_TEST (test_eos)
{
GstElement *pipeline, *sink;
GstPad *sinkpad;
GstStateChangeReturn ret;
GstMessage *message;
GstBus *bus;
/* create sink */
pipeline = gst_pipeline_new ("pipeline");
fail_if (pipeline == NULL);
bus = gst_pipeline_get_bus (GST_PIPELINE_CAST (pipeline));
fail_if (bus == NULL);
sink = gst_element_factory_make ("fakesink", "sink");
fail_if (sink == NULL);
g_object_set (G_OBJECT (sink), "sync", TRUE, NULL);
gst_bin_add (GST_BIN (pipeline), sink);
sinkpad = gst_element_get_pad (sink, "sink");
fail_if (sinkpad == NULL);
/* make pipeline and element ready to accept data */
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
fail_unless (ret == GST_STATE_CHANGE_ASYNC);
/* send EOS, this should work fine */
{
GstEvent *eos;
gboolean eret;
GST_DEBUG ("sending EOS");
eos = gst_event_new_eos ();
eret = gst_pad_send_event (sinkpad, eos);
fail_if (eret == FALSE);
}
/* wait for preroll */
gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
/* EOS should be on the bus at some point */
while (TRUE) {
GstMessageType type;
/* blocking wait for messages */
message = gst_bus_timed_pop (bus, GST_CLOCK_TIME_NONE);
type = GST_MESSAGE_TYPE (message);
gst_message_unref (message);
GST_DEBUG ("got message %s", gst_message_type_get_name (type));
if (type == GST_MESSAGE_EOS)
break;
}
/* send another EOS, this should fail */
{
GstEvent *eos;
gboolean eret;
GST_DEBUG ("sending second EOS");
eos = gst_event_new_eos ();
eret = gst_pad_send_event (sinkpad, eos);
fail_if (eret == TRUE);
}
/* send segment, this should fail */
{
GstEvent *segment;
gboolean eret;
GST_DEBUG ("sending segment");
segment = gst_event_new_new_segment (FALSE,
1.0, GST_FORMAT_TIME, 0 * GST_SECOND, 2 * GST_SECOND, 0 * GST_SECOND);
eret = gst_pad_send_event (sinkpad, segment);
fail_if (eret == TRUE);
}
/* send buffer that should fail after EOS */
{
GstBuffer *buffer;
GstFlowReturn fret;
buffer = gst_buffer_new ();
GST_BUFFER_TIMESTAMP (buffer) = 1 * GST_SECOND;
GST_BUFFER_DURATION (buffer) = 1 * GST_SECOND;
GST_DEBUG ("sending buffer");
/* buffer after EOS is not UNEXPECTED */
fret = gst_pad_chain (sinkpad, buffer);
fail_unless (fret == GST_FLOW_UNEXPECTED);
}
/* flush, EOS state is flushed again. */
{
GstEvent *event;
gboolean eret;
GST_DEBUG ("sending FLUSH_START");
event = gst_event_new_flush_start ();
eret = gst_pad_send_event (sinkpad, event);
fail_unless (eret == TRUE);
GST_DEBUG ("sending FLUSH_STOP");
event = gst_event_new_flush_stop ();
eret = gst_pad_send_event (sinkpad, event);
fail_unless (eret == TRUE);
}
/* send segment, this should now work again */
{
GstEvent *segment;
gboolean eret;
GST_DEBUG ("sending segment");
segment = gst_event_new_new_segment (FALSE,
1.0, GST_FORMAT_TIME, 0 * GST_SECOND, 2 * GST_SECOND, 0 * GST_SECOND);
eret = gst_pad_send_event (sinkpad, segment);
fail_unless (eret == TRUE);
}
/* send buffer that should work and block */
{
GstBuffer *buffer;
GstFlowReturn fret;
buffer = gst_buffer_new ();
GST_BUFFER_TIMESTAMP (buffer) = 1 * GST_SECOND;
GST_BUFFER_DURATION (buffer) = 1 * GST_SECOND;
GST_DEBUG ("sending buffer");
fret = gst_pad_chain (sinkpad, buffer);
fail_unless (fret == GST_FLOW_OK);
}
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
gst_object_unref (sinkpad);
gst_object_unref (pipeline);
}
GST_END_TEST;
Suite *
fakesink_suite (void)
{
@ -301,6 +454,7 @@ fakesink_suite (void)
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_clipping);
tcase_add_test (tc_chain, test_preroll_sync);
tcase_add_test (tc_chain, test_eos);
return s;
}