From 12df7fa49dffe45ffac9f4371e186575860344ba Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Mon, 14 Oct 2013 18:48:08 -0300 Subject: [PATCH] audiodecoder: Keep still meaningfull pending events on FLUSH_STOP Only EOS and segment should be deleted in that case. https://bugzilla.gnome.org/show_bug.cgi?id=709868 --- gst-libs/gst/audio/gstaudiodecoder.c | 23 +++++++- tests/check/libs/audiodecoder.c | 104 +++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 3 deletions(-) diff --git a/gst-libs/gst/audio/gstaudiodecoder.c b/gst-libs/gst/audio/gstaudiodecoder.c index fa9828b..0ded9a2 100644 --- a/gst-libs/gst/audio/gstaudiodecoder.c +++ b/gst-libs/gst/audio/gstaudiodecoder.c @@ -2000,6 +2000,24 @@ not_negotiated: } } +static GList * +_flush_events (GstPad * pad, GList * events) +{ + GList *tmp; + + for (tmp = events; tmp; tmp = tmp->next) { + if (GST_EVENT_TYPE (tmp->data) == GST_EVENT_EOS || + GST_EVENT_TYPE (tmp->data) == GST_EVENT_SEGMENT || + !GST_EVENT_IS_STICKY (tmp->data)) { + gst_event_unref (tmp->data); + } else { + gst_pad_store_sticky_event (pad, GST_EVENT_CAST (tmp->data)); + } + } + + return NULL; +} + static gboolean gst_audio_decoder_sink_eventfunc (GstAudioDecoder * dec, GstEvent * event) { @@ -2095,9 +2113,8 @@ gst_audio_decoder_sink_eventfunc (GstAudioDecoder * dec, GstEvent * event) /* prepare for fresh start */ gst_audio_decoder_flush (dec, TRUE); - g_list_foreach (dec->priv->pending_events, (GFunc) gst_event_unref, NULL); - g_list_free (dec->priv->pending_events); - dec->priv->pending_events = NULL; + dec->priv->pending_events = _flush_events (dec->srcpad, + dec->priv->pending_events); GST_AUDIO_DECODER_STREAM_UNLOCK (dec); /* Forward FLUSH_STOP, it is expected to be forwarded immediately diff --git a/tests/check/libs/audiodecoder.c b/tests/check/libs/audiodecoder.c index 52b6b12..b3f460a 100644 --- a/tests/check/libs/audiodecoder.c +++ b/tests/check/libs/audiodecoder.c @@ -415,6 +415,109 @@ GST_START_TEST (audiodecoder_delayed_negotiation_with_gap_event) GST_END_TEST; +GST_START_TEST (audiodecoder_flush_events) +{ + GstSegment segment; + GstBuffer *buffer; + guint64 i; + GList *events_iter; + + setup_audiodecodertester (); + + gst_pad_set_active (mysrcpad, TRUE); + gst_element_set_state (dec, GST_STATE_PLAYING); + gst_pad_set_active (mysinkpad, TRUE); + + send_startup_events (); + + /* push a new segment */ + gst_segment_init (&segment, GST_FORMAT_TIME); + fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_segment (&segment))); + + /* push buffers, the data is actually a number so we can track them */ + for (i = 0; i < NUM_BUFFERS; i++) { + if (i % 10 == 0) { + GstTagList *tags; + + tags = gst_tag_list_new (GST_TAG_TRACK_NUMBER, i, NULL); + fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_tag (tags))); + } else { + buffer = create_test_buffer (i); + + fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); + } + } + + fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ())); + + events_iter = events; + /* make sure the usual events have been received */ + { + GstEvent *sstart = events_iter->data; + fail_unless (GST_EVENT_TYPE (sstart) == GST_EVENT_STREAM_START); + events_iter = g_list_next (events_iter); + } + { + GstEvent *caps_event = events_iter->data; + fail_unless (GST_EVENT_TYPE (caps_event) == GST_EVENT_CAPS); + events_iter = g_list_next (events_iter); + } + { + GstEvent *segment_event = events_iter->data; + fail_unless (GST_EVENT_TYPE (segment_event) == GST_EVENT_SEGMENT); + events_iter = g_list_next (events_iter); + } + + /* check that EOS was received */ + fail_unless (GST_PAD_IS_EOS (mysrcpad)); + fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_flush_start ())); + fail_unless (GST_PAD_IS_EOS (mysrcpad)); + + /* Check that we have tags */ + { + GstEvent *tags = gst_pad_get_sticky_event (mysrcpad, GST_EVENT_TAG, 0); + + fail_unless (tags != NULL); + gst_event_unref (tags); + } + + /* Check that we still have a segment set */ + { + GstEvent *segment = + gst_pad_get_sticky_event (mysrcpad, GST_EVENT_SEGMENT, 0); + + fail_unless (segment != NULL); + gst_event_unref (segment); + } + + fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_flush_stop (TRUE))); + fail_if (GST_PAD_IS_EOS (mysrcpad)); + + /* Check that the segment was flushed on FLUSH_STOP */ + { + GstEvent *segment = + gst_pad_get_sticky_event (mysrcpad, GST_EVENT_SEGMENT, 0); + + fail_unless (segment == NULL); + } + + /* Check the tags were not lost on FLUSH_STOP */ + { + GstEvent *tags = gst_pad_get_sticky_event (mysrcpad, GST_EVENT_TAG, 0); + + fail_unless (tags != NULL); + gst_event_unref (tags); + + } + + g_list_free_full (buffers, (GDestroyNotify) gst_buffer_unref); + buffers = NULL; + + cleanup_audiodecodertest (); +} + +GST_END_TEST; + GST_START_TEST (audiodecoder_buffer_after_segment) { @@ -487,6 +590,7 @@ gst_audiodecoder_suite (void) suite_add_tcase (s, tc); tcase_add_test (tc, audiodecoder_playback); + tcase_add_test (tc, audiodecoder_flush_events); tcase_add_test (tc, audiodecoder_negotiation_with_buffer); tcase_add_test (tc, audiodecoder_negotiation_with_gap_event); tcase_add_test (tc, audiodecoder_delayed_negotiation_with_gap_event); -- 2.7.4