diff --git a/src/gst/gstpipewireclock.c b/src/gst/gstpipewireclock.c index 4c4e47889..59e1e648d 100644 --- a/src/gst/gstpipewireclock.c +++ b/src/gst/gstpipewireclock.c @@ -31,12 +31,13 @@ GST_DEBUG_CATEGORY_STATIC (gst_pipewire_clock_debug_category); G_DEFINE_TYPE (GstPipeWireClock, gst_pipewire_clock, GST_TYPE_SYSTEM_CLOCK); GstClock * -gst_pipewire_clock_new (struct pw_stream *stream) +gst_pipewire_clock_new (struct pw_stream *stream, GstClockTime last_time) { GstPipeWireClock *clock; clock = g_object_new (GST_TYPE_PIPEWIRE_CLOCK, NULL); clock->stream = stream; + clock->last_time = last_time; return GST_CLOCK_CAST (clock); } @@ -48,14 +49,14 @@ gst_pipewire_clock_get_internal_time (GstClock * clock) GstClockTime result; struct pw_time t; - pw_stream_get_time (pclock->stream, &t); + if (pclock->stream == NULL || + pw_stream_get_time (pclock->stream, &t) < 0 || + t.rate.denom == 0) + return pclock->last_time; - if (t.rate.denom) - result = gst_util_uint64_scale_int (t.ticks, GST_SECOND * t.rate.num, t.rate.denom); - else - result = GST_CLOCK_TIME_NONE; + result = gst_util_uint64_scale_int (t.ticks, GST_SECOND * t.rate.num, t.rate.denom); - GST_DEBUG ("%"PRId64", %d %"PRId64, t.ticks, t.rate.denom, result); + GST_DEBUG ("%"PRId64", %d/%d %"PRId64, t.ticks, t.rate.num, t.rate.denom, result); return result; } diff --git a/src/gst/gstpipewireclock.h b/src/gst/gstpipewireclock.h index 3020c83c8..f847ce48b 100644 --- a/src/gst/gstpipewireclock.h +++ b/src/gst/gstpipewireclock.h @@ -46,6 +46,7 @@ struct _GstPipeWireClock { GstSystemClock parent; struct pw_stream *stream; + GstClockTime last_time; }; struct _GstPipeWireClockClass { @@ -54,8 +55,8 @@ struct _GstPipeWireClockClass { GType gst_pipewire_clock_get_type (void); -GstClock * gst_pipewire_clock_new (struct pw_stream *stream); - +GstClock * gst_pipewire_clock_new (struct pw_stream *stream, + GstClockTime last_time); G_END_DECLS diff --git a/src/gst/gstpipewiresrc.c b/src/gst/gstpipewiresrc.c index 18ba270ac..145fd584c 100644 --- a/src/gst/gstpipewiresrc.c +++ b/src/gst/gstpipewiresrc.c @@ -1028,7 +1028,7 @@ gst_pipewire_src_open (GstPipeWireSrc * pwsrc) pwsrc); - pwsrc->clock = gst_pipewire_clock_new (pwsrc->stream); + pwsrc->clock = gst_pipewire_clock_new (pwsrc->stream, pwsrc->last_time); pw_thread_loop_unlock (pwsrc->main_loop); return TRUE; @@ -1071,7 +1071,13 @@ gst_pipewire_src_close (GstPipeWireSrc * pwsrc) pw_remote_destroy (pwsrc->remote); pwsrc->remote = NULL; + pwsrc->last_time = gst_clock_get_time (pwsrc->clock); + + gst_element_post_message (GST_ELEMENT (pwsrc), + gst_message_new_clock_lost (GST_OBJECT_CAST (pwsrc), pwsrc->clock)); + GST_OBJECT_LOCK (pwsrc); + GST_PIPEWIRE_CLOCK (pwsrc->clock)->stream = NULL; g_clear_object (&pwsrc->clock); GST_OBJECT_UNLOCK (pwsrc); } diff --git a/src/gst/gstpipewiresrc.h b/src/gst/gstpipewiresrc.h index c8f718b91..613f888f0 100644 --- a/src/gst/gstpipewiresrc.h +++ b/src/gst/gstpipewiresrc.h @@ -82,6 +82,7 @@ struct _GstPipeWireSrc { GstPipeWirePool *pool; GQueue queue; GstClock *clock; + GstClockTime last_time; }; struct _GstPipeWireSrcClass {