gst: keep track of clock time

Invalidate the clock when the stream is destroyed and let the new
clock take the time of previous clock when no timing info is
available.
This commit is contained in:
Wim Taymans 2018-08-13 15:19:20 +02:00
parent 5a3883509b
commit a2cfb0882b
4 changed files with 18 additions and 9 deletions

View file

@ -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,12 +49,12 @@ 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.num == 0)
return pclock->last_time;
if (t.rate.denom)
result = gst_util_uint64_scale_int (t.ticks, GST_SECOND * t.rate.denom, t.rate.num);
else
result = GST_CLOCK_TIME_NONE;
result = gst_util_uint64_scale_int (t.ticks, GST_SECOND * t.rate.denom, t.rate.num);
GST_DEBUG ("%"PRId64", %d/%d %"PRId64, t.ticks, t.rate.num, t.rate.denom, result);

View file

@ -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

View file

@ -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);
}

View file

@ -82,6 +82,7 @@ struct _GstPipeWireSrc {
GstPipeWirePool *pool;
GQueue queue;
GstClock *clock;
GstClockTime last_time;
};
struct _GstPipeWireSrcClass {