summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFlorin Apostol <florin.apostol@oregan.net>2016-02-16 14:44:39 +0000
committerThiago Santos <thiagoss@osg.samsung.com>2016-04-21 16:46:09 -0300
commite86e08b4ac9a939393353729e0ae598ea2ea4fc4 (patch)
tree5e2a732054147c79ea9306350408f954148c1e21 /tests
parentaa58a70d6676f9bc394780a90a39ff47d538fa68 (diff)
downloadgstreamer-plugins-bad-e86e08b4ac9a939393353729e0ae598ea2ea4fc4.tar.gz
adaptivedemux: tests: use a GstTestClock as the system clock
To allow the adaptivedemux live stream tests to run in non-realtime, use a GstTestClock as the system clock. This allows the unit tests to complete more quickly than if they had to complete in real time. https://bugzilla.gnome.org/show_bug.cgi?id=762147
Diffstat (limited to 'tests')
-rw-r--r--tests/check/elements/adaptive_demux_engine.c51
-rw-r--r--tests/check/elements/adaptive_demux_engine.h1
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/check/elements/adaptive_demux_engine.c b/tests/check/elements/adaptive_demux_engine.c
index b571fe336..70f94cd38 100644
--- a/tests/check/elements/adaptive_demux_engine.c
+++ b/tests/check/elements/adaptive_demux_engine.c
@@ -19,6 +19,7 @@
*/
#include <gst/check/gstcheck.h>
+#include <gst/check/gsttestclock.h>
#include "adaptive_demux_engine.h"
typedef struct _GstAdaptiveDemuxTestEnginePrivate
@@ -26,6 +27,7 @@ typedef struct _GstAdaptiveDemuxTestEnginePrivate
GstAdaptiveDemuxTestEngine engine;
const GstAdaptiveDemuxTestCallbacks *callbacks;
gpointer user_data;
+ guint clock_update_id;
} GstAdaptiveDemuxTestEnginePrivate;
@@ -399,6 +401,38 @@ on_ErrorMessageOnBus (GstBus * bus, GstMessage * msg, gpointer user_data)
}
static gboolean
+gst_adaptive_demux_update_test_clock (gpointer user_data)
+{
+ GstAdaptiveDemuxTestEnginePrivate *priv =
+ (GstAdaptiveDemuxTestEnginePrivate *) user_data;
+ GstClockID id;
+ GstClockTime next_entry;
+ GstTestClock *clock = GST_TEST_CLOCK (priv->engine.clock);
+
+ fail_unless (clock != NULL);
+ next_entry = gst_test_clock_get_next_entry_time (clock);
+ if (next_entry != GST_CLOCK_TIME_NONE) {
+ /* tests that do not want the manifest to update will set the update period
+ * to a big value, eg 500s. The manifest update task will register an alarm
+ * for that value.
+ * We do not want the clock to jump to that. If it does, the manifest update
+ * task will keep scheduling and use all the cpu power, starving the other
+ * threads.
+ * Usually the test require the clock to update with approx 3s, so we will
+ * allow only updates smaller than 100s
+ */
+ GstClockTime curr_time = gst_clock_get_time (GST_CLOCK (clock));
+ if (next_entry - curr_time < 100 * GST_SECOND) {
+ gst_test_clock_set_time (clock, next_entry);
+ id = gst_test_clock_process_next_clock_id (clock);
+ fail_unless (id != NULL);
+ gst_clock_id_unref (id);
+ }
+ }
+ return TRUE;
+}
+
+static gboolean
start_pipeline_playing (gpointer user_data)
{
GstAdaptiveDemuxTestEnginePrivate *priv =
@@ -473,6 +507,20 @@ gst_adaptive_demux_test_run (const gchar * element_name,
ret = gst_element_link (manifest_source, demux);
fail_unless_equals_int (ret, TRUE);
+ priv->engine.clock = gst_system_clock_obtain ();
+ if (GST_IS_TEST_CLOCK (priv->engine.clock)) {
+ /*
+ * live tests will want to manipulate the clock, so they will register a
+ * gst_test_clock as the system clock.
+ * The on demand tests do not care about the clock, so they will let the
+ * system clock to the default one.
+ * If a gst_test_clock was installed as system clock, we register a
+ * periodic callback to update its value.
+ */
+ priv->clock_update_id =
+ g_timeout_add (100, gst_adaptive_demux_update_test_clock, priv);
+ }
+
/* call a test callback before we start the pipeline */
if (callbacks->pre_test)
(*callbacks->pre_test) (&priv->engine, priv->user_data);
@@ -514,6 +562,9 @@ gst_adaptive_demux_test_run (const gchar * element_name,
priv);
GST_DEBUG ("main thread pipeline stopped");
+ if (priv->clock_update_id != 0)
+ g_source_remove (priv->clock_update_id);
+ gst_object_unref (priv->engine.clock);
gst_object_unref (priv->engine.pipeline);
priv->engine.pipeline = NULL;
g_main_loop_unref (priv->engine.loop);
diff --git a/tests/check/elements/adaptive_demux_engine.h b/tests/check/elements/adaptive_demux_engine.h
index f715ecb23..3eb553dfc 100644
--- a/tests/check/elements/adaptive_demux_engine.h
+++ b/tests/check/elements/adaptive_demux_engine.h
@@ -154,6 +154,7 @@ typedef struct _GstAdaptiveDemuxTestCallbacks
struct _GstAdaptiveDemuxTestEngine
{
GstElement *pipeline;
+ GstClock *clock;
GstElement *demux;
GstElement *manifest_source;
GMainLoop *loop;