mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-22 22:16:22 +00:00
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
This commit is contained in:
parent
aa58a70d66
commit
e86e08b4ac
2 changed files with 52 additions and 0 deletions
|
@ -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;
|
||||
|
||||
|
||||
|
@ -398,6 +400,38 @@ on_ErrorMessageOnBus (GstBus * bus, GstMessage * msg, gpointer user_data)
|
|||
GST_TEST_UNLOCK (priv);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
|
|
@ -154,6 +154,7 @@ typedef struct _GstAdaptiveDemuxTestCallbacks
|
|||
struct _GstAdaptiveDemuxTestEngine
|
||||
{
|
||||
GstElement *pipeline;
|
||||
GstClock *clock;
|
||||
GstElement *demux;
|
||||
GstElement *manifest_source;
|
||||
GMainLoop *loop;
|
||||
|
|
Loading…
Reference in a new issue