mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-27 18:50:48 +00:00
systemclock: Add gst_system_clock_set_default
Used for setting the default system clock that is obtained through gst_system_clock_obtain(), which is sometimes needed for unit testing. Fixes https://bugzilla.gnome.org/show_bug.cgi?id=711269
This commit is contained in:
parent
24c741554c
commit
02b64ee03b
5 changed files with 75 additions and 0 deletions
|
@ -2552,6 +2552,7 @@ gst_structure_get_type
|
|||
GstClockType
|
||||
GstSystemClock
|
||||
gst_system_clock_obtain
|
||||
gst_system_clock_set_default
|
||||
<SUBSECTION Standard>
|
||||
GstSystemClockClass
|
||||
GstSystemClockPrivate
|
||||
|
|
|
@ -112,6 +112,7 @@ enum
|
|||
|
||||
/* the one instance of the systemclock */
|
||||
static GstClock *_the_system_clock = NULL;
|
||||
static gboolean _external_default_clock = FALSE;
|
||||
|
||||
static void gst_system_clock_dispose (GObject * object);
|
||||
static void gst_system_clock_set_property (GObject * object, guint prop_id,
|
||||
|
@ -280,6 +281,43 @@ gst_system_clock_get_property (GObject * object, guint prop_id, GValue * value,
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_system_clock_set_default:
|
||||
* @new_clock: a #GstClock
|
||||
*
|
||||
* Sets the default system clock that can be obtained with
|
||||
* gst_system_clock_obtain.
|
||||
*
|
||||
* This is mostly used for testing and debugging purposes when you
|
||||
* want to have control over the time reported by the default system
|
||||
* clock.
|
||||
*
|
||||
* MT safe.
|
||||
*/
|
||||
void
|
||||
gst_system_clock_set_default (GstClock * new_clock)
|
||||
{
|
||||
GstClock *clock;
|
||||
|
||||
g_mutex_lock (&_gst_sysclock_mutex);
|
||||
clock = _the_system_clock;
|
||||
|
||||
if (clock != NULL)
|
||||
g_object_unref (clock);
|
||||
|
||||
if (new_clock == NULL) {
|
||||
GST_CAT_DEBUG (GST_CAT_CLOCK, "resetting default system clock");
|
||||
_external_default_clock = FALSE;
|
||||
} else {
|
||||
GST_CAT_DEBUG (GST_CAT_CLOCK, "setting new default system clock to %p",
|
||||
new_clock);
|
||||
_external_default_clock = TRUE;
|
||||
g_object_ref (new_clock);
|
||||
}
|
||||
_the_system_clock = new_clock;
|
||||
g_mutex_unlock (&_gst_sysclock_mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_system_clock_obtain:
|
||||
*
|
||||
|
@ -301,6 +339,7 @@ gst_system_clock_obtain (void)
|
|||
|
||||
if (clock == NULL) {
|
||||
GST_CAT_DEBUG (GST_CAT_CLOCK, "creating new static system clock");
|
||||
g_assert (_external_default_clock == FALSE);
|
||||
clock = g_object_new (GST_TYPE_SYSTEM_CLOCK,
|
||||
"name", "GstSystemClock", NULL);
|
||||
|
||||
|
|
|
@ -81,6 +81,7 @@ struct _GstSystemClockClass {
|
|||
GType gst_system_clock_get_type (void);
|
||||
|
||||
GstClock* gst_system_clock_obtain (void);
|
||||
void gst_system_clock_set_default (GstClock *new_clock);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -117,6 +117,38 @@ notify_callback (GstClock * clock, GstClockTime time,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
GST_START_TEST (test_set_default)
|
||||
{
|
||||
GstClock *clock, *static_clock;
|
||||
|
||||
/* obtain the default system clock, which keeps a static ref and bumps the
|
||||
* refcount before returning */
|
||||
static_clock = gst_system_clock_obtain ();
|
||||
fail_unless (static_clock != NULL, "Could not create default system clock");
|
||||
g_assert_cmpint (GST_OBJECT_REFCOUNT (static_clock), ==, 2);
|
||||
|
||||
/* set a new default clock to a different instance which should replace the
|
||||
* static clock with this one, and unref the static clock */
|
||||
clock = g_object_new (GST_TYPE_SYSTEM_CLOCK, "name", "TestClock", NULL);
|
||||
gst_system_clock_set_default (clock);
|
||||
g_assert_cmpint (GST_OBJECT_REFCOUNT (static_clock), ==, 1);
|
||||
static_clock = gst_system_clock_obtain ();
|
||||
fail_unless (static_clock == clock);
|
||||
g_assert_cmpint (GST_OBJECT_REFCOUNT (clock), ==, 3);
|
||||
g_object_unref (static_clock);
|
||||
|
||||
/* Reset the default clock to the static one */
|
||||
gst_system_clock_set_default (NULL);
|
||||
static_clock = gst_system_clock_obtain ();
|
||||
fail_unless (static_clock != clock);
|
||||
g_assert_cmpint (GST_OBJECT_REFCOUNT (clock), ==, 1);
|
||||
g_assert_cmpint (GST_OBJECT_REFCOUNT (static_clock), ==, 2);
|
||||
g_object_unref (clock);
|
||||
g_object_unref (static_clock);
|
||||
}
|
||||
|
||||
GST_END_TEST;
|
||||
|
||||
GST_START_TEST (test_single_shot)
|
||||
{
|
||||
GstClock *clock;
|
||||
|
@ -654,6 +686,7 @@ gst_systemclock_suite (void)
|
|||
tcase_add_test (tc_chain, test_diff);
|
||||
tcase_add_test (tc_chain, test_mixed);
|
||||
tcase_add_test (tc_chain, test_async_full);
|
||||
tcase_add_test (tc_chain, test_set_default);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
|
|
@ -1127,6 +1127,7 @@ EXPORTS
|
|||
gst_structure_to_string
|
||||
gst_system_clock_get_type
|
||||
gst_system_clock_obtain
|
||||
gst_system_clock_set_default
|
||||
gst_tag_exists
|
||||
gst_tag_flag_get_type
|
||||
gst_tag_get_description
|
||||
|
|
Loading…
Reference in a new issue