From e5e27010c8068debec558715f880cb033ca6f58a Mon Sep 17 00:00:00 2001 From: Bing Song Date: Mon, 2 Nov 2020 17:43:42 +0800 Subject: [PATCH] identity/clocksync: Also provide system clock if sync=false identity should provide when sync=true. Don't provide when sync=false. Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/630 Part-of: --- plugins/elements/gstclocksync.c | 27 ++++++++++++++++++++++++++- plugins/elements/gstidentity.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/plugins/elements/gstclocksync.c b/plugins/elements/gstclocksync.c index 2d479fc3bb..807c84265f 100644 --- a/plugins/elements/gstclocksync.c +++ b/plugins/elements/gstclocksync.c @@ -171,7 +171,6 @@ gst_clock_sync_init (GstClockSync * clocksync) clocksync->sync = DEFAULT_SYNC; g_cond_init (&clocksync->blocked_cond); - GST_OBJECT_FLAG_SET (clocksync, GST_ELEMENT_FLAG_PROVIDE_CLOCK); GST_OBJECT_FLAG_SET (clocksync, GST_ELEMENT_FLAG_REQUIRE_CLOCK); } @@ -180,10 +179,31 @@ gst_clock_sync_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GstClockSync *clocksync = GST_CLOCKSYNC (object); + GstMessage *clock_message = NULL; + gboolean sync; switch (prop_id) { case PROP_SYNC: clocksync->sync = g_value_get_boolean (value); + sync = g_value_get_boolean (value); + GST_OBJECT_LOCK (clocksync); + if (sync != clocksync->sync) { + clocksync->sync = sync; + if (sync) { + GST_OBJECT_FLAG_SET (clocksync, GST_ELEMENT_FLAG_PROVIDE_CLOCK); + clock_message = + gst_message_new_clock_provide (GST_OBJECT_CAST (clocksync), + gst_system_clock_obtain (), TRUE); + } else { + GST_OBJECT_FLAG_UNSET (clocksync, GST_ELEMENT_FLAG_PROVIDE_CLOCK); + clock_message = + gst_message_new_clock_lost (GST_OBJECT_CAST (clocksync), + gst_system_clock_obtain ()); + } + } + GST_OBJECT_UNLOCK (clocksync); + if (clock_message) + gst_element_post_message (GST_ELEMENT_CAST (clocksync), clock_message); break; case PROP_TS_OFFSET: clocksync->ts_offset = g_value_get_int64 (value); @@ -540,5 +560,10 @@ gst_clocksync_change_state (GstElement * element, GstStateChange transition) static GstClock * gst_clocksync_provide_clock (GstElement * element) { + GstClockSync *clocksync = GST_CLOCKSYNC (element); + + if (!clocksync->sync) + return NULL; + return gst_system_clock_obtain (); } diff --git a/plugins/elements/gstidentity.c b/plugins/elements/gstidentity.c index 1359c0e6ee..af477649d6 100644 --- a/plugins/elements/gstidentity.c +++ b/plugins/elements/gstidentity.c @@ -347,7 +347,6 @@ gst_identity_init (GstIdentity * identity) gst_base_transform_set_gap_aware (GST_BASE_TRANSFORM_CAST (identity), TRUE); - GST_OBJECT_FLAG_SET (identity, GST_ELEMENT_FLAG_PROVIDE_CLOCK); GST_OBJECT_FLAG_SET (identity, GST_ELEMENT_FLAG_REQUIRE_CLOCK); } @@ -860,6 +859,8 @@ gst_identity_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GstIdentity *identity; + GstMessage *clock_message = NULL; + gboolean sync; identity = GST_IDENTITY (object); @@ -889,7 +890,25 @@ gst_identity_set_property (GObject * object, guint prop_id, identity->datarate = g_value_get_int (value); break; case PROP_SYNC: - identity->sync = g_value_get_boolean (value); + sync = g_value_get_boolean (value); + GST_OBJECT_LOCK (identity); + if (sync != identity->sync) { + identity->sync = sync; + if (sync) { + GST_OBJECT_FLAG_SET (identity, GST_ELEMENT_FLAG_PROVIDE_CLOCK); + clock_message = + gst_message_new_clock_provide (GST_OBJECT_CAST (identity), + gst_system_clock_obtain (), TRUE); + } else { + GST_OBJECT_FLAG_UNSET (identity, GST_ELEMENT_FLAG_PROVIDE_CLOCK); + clock_message = + gst_message_new_clock_lost (GST_OBJECT_CAST (identity), + gst_system_clock_obtain ()); + } + } + GST_OBJECT_UNLOCK (identity); + if (clock_message) + gst_element_post_message (GST_ELEMENT_CAST (identity), clock_message); break; case PROP_TS_OFFSET: identity->ts_offset = g_value_get_int64 (value); @@ -1186,5 +1205,10 @@ gst_identity_change_state (GstElement * element, GstStateChange transition) static GstClock * gst_identity_provide_clock (GstElement * element) { + GstIdentity *identity = GST_IDENTITY (element); + + if (!identity->sync) + return NULL; + return gst_system_clock_obtain (); }