+
+/* This test checks that the pipeline does not wait for nothing after
+ * sending the non-flush seek event. */
+GST_START_TEST (test_loopback_1)
+{
+ GstMessage *msg;
+ GstElement *bin, *source, *parser, *sink;
+ gboolean res;
+ GstPad *sinkpad;
+ GstBus *bus;
+ guint seek_flags;
+
+ GST_INFO
+ ("construct the test pipeline fakesrc ! testparse ! fakesink sync=1");
+
+ bin = gst_pipeline_new ("pipeline");
+ bus = gst_element_get_bus (bin);
+ gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
+
+ source = gst_element_factory_make ("fakesrc", "source");
+ parser = g_object_new (dummy_parser_get_type (), "name", "testparse", NULL);
+ sink = gst_element_factory_make ("fakesink", "sink");
+
+ gst_bin_add_many (GST_BIN (bin), source, parser, sink, NULL);
+
+ res = gst_element_link (source, parser);
+ fail_unless (res == TRUE, NULL);
+ res = gst_element_link (parser, sink);
+ fail_unless (res == TRUE, NULL);
+
+ GST_INFO ("configure elements");
+
+ g_object_set (G_OBJECT (source),
+ "format", GST_FORMAT_BYTES,
+ "can-activate-pull", TRUE,
+ "can-activate-push", FALSE,
+ "is-live", FALSE,
+ "sizemax", 65536, "sizetype", 2 /* FAKE_SRC_SIZETYPE_FIXED */ ,
+ "num-buffers", 35, NULL);
+
+ /* Sync true is required for this test. */
+ g_object_set (G_OBJECT (sink), "sync", TRUE, NULL);
+
+ GST_INFO ("set paused state");
+
+ res = gst_element_set_state (bin, GST_STATE_PAUSED);
+ fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
+
+ GST_INFO ("wait for completion");
+
+ res =
+ gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
+ GST_CLOCK_TIME_NONE);
+ fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
+
+ GST_INFO ("paused state reached");
+
+ fail_unless (GST_BASE_SRC (source)->random_access);
+
+ sinkpad = gst_element_get_static_pad (parser, "sink");
+ fail_unless (GST_PAD_MODE (sinkpad) == GST_PAD_MODE_PULL);
+ gst_object_unref (sinkpad);
+
+ GST_INFO ("flush seek");
+
+ seek_flags =
+ GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE | GST_SEEK_FLAG_SEGMENT;
+
+ res = gst_element_seek (bin, 1.0, GST_FORMAT_TIME, seek_flags,
+ GST_SEEK_TYPE_SET, (GstClockTime) 0,
+ GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
+ fail_unless (res == TRUE, NULL);
+
+ GST_INFO ("set playing state");
+
+ res = gst_element_set_state (bin, GST_STATE_PLAYING);
+ fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
+
+ msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
+ GST_MESSAGE_SEGMENT_DONE | GST_MESSAGE_ERROR);
+ fail_unless_equals_string (GST_MESSAGE_TYPE_NAME (msg), "segment-done");
+ gst_message_unref (msg);
+
+ GST_INFO ("warm-up sequence done");
+
+ seek_flags &= ~GST_SEEK_FLAG_FLUSH;
+ fail_if (seek_flags & GST_SEEK_FLAG_FLUSH, NULL);
+
+ GST_INFO ("non-flush seek");
+
+ res =
+ gst_element_seek (bin, 1.0, GST_FORMAT_TIME, seek_flags,
+ GST_SEEK_TYPE_SET, (GstClockTime) 0, GST_SEEK_TYPE_SET,
+ (GstClockTime) 3 * GST_SECOND);
+ fail_unless (res == TRUE, NULL);
+
+ GST_INFO ("wait for segment done message");
+
+ msg = gst_bus_timed_pop_filtered (bus, (GstClockTime) 2 * GST_SECOND,
+ GST_MESSAGE_SEGMENT_DONE | GST_MESSAGE_ERROR);
+ /* Make sure the pipeline is not waiting for nothing because the base time is
+ * screwed up. */
+ fail_unless (msg, "no message within the timed window");
+ fail_unless_equals_string (GST_MESSAGE_TYPE_NAME (msg), "segment-done");
+
+ res = gst_element_set_state (bin, GST_STATE_NULL);
+ fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
+
+ /* cleanup */
+ gst_bus_remove_signal_watch (bus);
+ gst_object_unref (bus);
+ gst_object_unref (bin);
+}
+
+GST_END_TEST;
+
+/* This test checks that the pipeline does not play the media instantly
+ * after sending the non-flush seek event. */
+GST_START_TEST (test_loopback_2)
+{
+ GstMessage *msg;
+ GstElement *bin, *source, *parser, *sink;
+ gboolean res;
+ GstPad *sinkpad;
+ GstBus *bus;
+ guint seek_flags;
+ gint64 position = GST_CLOCK_TIME_NONE;
+ gint64 playback_duration = GST_CLOCK_TIME_NONE;
+ gint64 start_absolute_time = GST_CLOCK_TIME_NONE;
+
+ GST_INFO
+ ("construct the test pipeline fakesrc ! testparse ! fakesink sync=1");
+
+ bin = gst_pipeline_new ("pipeline");
+ bus = gst_element_get_bus (bin);
+ gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
+
+ source = gst_element_factory_make ("fakesrc", "source");
+ parser = g_object_new (dummy_parser_get_type (), "name", "testparse", NULL);
+ sink = gst_element_factory_make ("fakesink", "sink");
+
+ gst_bin_add_many (GST_BIN (bin), source, parser, sink, NULL);
+
+ res = gst_element_link (source, parser);
+ fail_unless (res == TRUE, NULL);
+ res = gst_element_link (parser, sink);
+ fail_unless (res == TRUE, NULL);
+
+ GST_INFO ("configure elements");
+
+ g_object_set (G_OBJECT (source),
+ "format", GST_FORMAT_BYTES,
+ "can-activate-pull", TRUE,
+ "can-activate-push", FALSE,
+ "is-live", FALSE,
+ "sizemax", 65536, "sizetype", 2 /* FAKE_SRC_SIZETYPE_FIXED */ ,
+ NULL);
+
+ /* Sync true is required for this test. */
+ g_object_set (G_OBJECT (sink), "sync", TRUE, NULL);
+
+ GST_INFO ("set paused state");
+
+ res = gst_element_set_state (bin, GST_STATE_PAUSED);
+ fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
+
+ GST_INFO ("wait for completion");
+
+ res =
+ gst_element_get_state (GST_ELEMENT (bin), NULL, NULL,
+ GST_CLOCK_TIME_NONE);
+ fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
+
+ GST_INFO ("paused state reached");
+
+ fail_unless (GST_BASE_SRC (source)->random_access);
+
+ sinkpad = gst_element_get_static_pad (parser, "sink");
+ fail_unless (GST_PAD_MODE (sinkpad) == GST_PAD_MODE_PULL);
+ gst_object_unref (sinkpad);
+
+ GST_INFO ("flush seek");
+
+ seek_flags =
+ GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE | GST_SEEK_FLAG_SEGMENT;
+
+ res = gst_element_seek (bin, 1.0, GST_FORMAT_TIME, seek_flags,
+ GST_SEEK_TYPE_SET, (GstClockTime) 0,
+ GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND);
+ fail_unless (res == TRUE, NULL);
+
+ GST_INFO ("set playing state");
+
+ res = gst_element_set_state (bin, GST_STATE_PLAYING);
+ fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
+
+ msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
+ GST_MESSAGE_SEGMENT_DONE | GST_MESSAGE_ERROR);
+ fail_unless_equals_string (GST_MESSAGE_TYPE_NAME (msg), "segment-done");
+ gst_message_unref (msg);
+
+ GST_INFO ("warm-up sequence done");
+
+ seek_flags &= ~GST_SEEK_FLAG_FLUSH;
+ fail_if (seek_flags & GST_SEEK_FLAG_FLUSH, NULL);
+
+ GST_INFO ("non-flush seek");
+
+ start_absolute_time = gst_clock_get_time (GST_ELEMENT_CLOCK (bin));
+
+ res =
+ gst_element_seek (bin, 1.0, GST_FORMAT_TIME, seek_flags,
+ GST_SEEK_TYPE_SET, (GstClockTime) 0, GST_SEEK_TYPE_SET,
+ (GstClockTime) 2 * GST_SECOND);
+ fail_unless (res == TRUE, NULL);
+
+ GST_INFO ("wait for segment done message");
+
+ msg = gst_bus_timed_pop_filtered (bus, (GstClockTime) 2 * GST_SECOND,
+ GST_MESSAGE_SEGMENT_DONE | GST_MESSAGE_ERROR);
+ fail_unless (msg, "no message within the timed window");
+ fail_unless_equals_string (GST_MESSAGE_TYPE_NAME (msg), "segment-done");
+
+ gst_message_parse_segment_done (msg, NULL, &position);
+ gst_message_unref (msg);
+
+ GST_INFO ("final position: %" G_GINT64_FORMAT, position);
+
+ fail_unless (position == 2 * GST_SECOND);
+
+ playback_duration =
+ GST_CLOCK_DIFF (start_absolute_time,
+ gst_clock_get_time (GST_ELEMENT_CLOCK (bin)));
+
+ GST_INFO ("test duration: %" G_GINT64_FORMAT, playback_duration);
+
+ fail_unless (playback_duration > GST_SECOND,
+ "playback duration should be near 2 seconds");
+
+ res = gst_element_set_state (bin, GST_STATE_NULL);
+ fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL);
+
+ /* cleanup */
+ gst_bus_remove_signal_watch (bus);
+ gst_object_unref (bus);
+ gst_object_unref (bin);
+}
+
+GST_END_TEST;
+