mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
gst: handle clock reset
The clock time is reset to 0 after a new format is negotiated. Make sure the time reported by the gstreamer clock is increasing in this case.
This commit is contained in:
parent
8591d85710
commit
4faa28fd96
4 changed files with 31 additions and 2 deletions
|
|
@ -43,6 +43,7 @@ gst_pipewire_clock_new (struct pw_stream *stream, GstClockTime last_time)
|
|||
clock = g_object_new (GST_TYPE_PIPEWIRE_CLOCK, NULL);
|
||||
clock->stream = stream;
|
||||
clock->last_time = last_time;
|
||||
clock->time_offset = last_time;
|
||||
|
||||
return GST_CLOCK_CAST (clock);
|
||||
}
|
||||
|
|
@ -64,13 +65,15 @@ gst_pipewire_clock_get_internal_time (GstClock * clock)
|
|||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
result += SPA_TIMESPEC_TO_NSEC(&ts) - t.now;
|
||||
|
||||
result += pclock->time_offset;
|
||||
pclock->last_time = result;
|
||||
|
||||
GST_DEBUG ("%"PRId64", %d/%d %"PRId64" %"PRId64,
|
||||
t.ticks, t.rate.num, t.rate.denom, t.now, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gst_pipewire_clock_finalize (GObject * object)
|
||||
{
|
||||
|
|
@ -100,3 +103,21 @@ gst_pipewire_clock_init (GstPipeWireClock * clock)
|
|||
{
|
||||
GST_OBJECT_FLAG_SET (clock, GST_CLOCK_FLAG_CAN_SET_MASTER);
|
||||
}
|
||||
|
||||
void
|
||||
gst_pipewire_clock_reset (GstPipeWireClock * clock, GstClockTime time)
|
||||
{
|
||||
GstClockTimeDiff time_offset;
|
||||
|
||||
if (clock->last_time >= time)
|
||||
time_offset = clock->last_time - time;
|
||||
else
|
||||
time_offset = -(time - clock->last_time);
|
||||
|
||||
clock->time_offset = time_offset;
|
||||
|
||||
GST_DEBUG_OBJECT (clock,
|
||||
"reset clock to %" GST_TIME_FORMAT ", last %" GST_TIME_FORMAT
|
||||
", offset %" GST_STIME_FORMAT, GST_TIME_ARGS (time),
|
||||
GST_TIME_ARGS (clock->last_time), GST_STIME_ARGS (time_offset));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ struct _GstPipeWireClock {
|
|||
|
||||
struct pw_stream *stream;
|
||||
GstClockTime last_time;
|
||||
GstClockTimeDiff time_offset;
|
||||
};
|
||||
|
||||
struct _GstPipeWireClockClass {
|
||||
|
|
@ -62,6 +63,8 @@ GType gst_pipewire_clock_get_type (void);
|
|||
|
||||
GstClock * gst_pipewire_clock_new (struct pw_stream *stream,
|
||||
GstClockTime last_time);
|
||||
void gst_pipewire_clock_reset (GstPipeWireClock *clock,
|
||||
GstClockTime time);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
|
|
@ -502,6 +502,9 @@ on_format_changed (void *data, const struct spa_pod *format)
|
|||
{
|
||||
GstPipeWireSink *pwsink = data;
|
||||
|
||||
if (format == NULL)
|
||||
return;
|
||||
|
||||
if (gst_buffer_pool_is_active (GST_BUFFER_POOL_CAST (pwsink->pool)))
|
||||
pool_activated (pwsink->pool, pwsink);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -416,7 +416,7 @@ on_process (void *_data)
|
|||
GST_INFO ("pts %" G_GUINT64_FORMAT ", dts_offset %"G_GUINT64_FORMAT, h->pts, h->dts_offset);
|
||||
|
||||
if (GST_CLOCK_TIME_IS_VALID (h->pts)) {
|
||||
GST_BUFFER_PTS (buf) = h->pts;
|
||||
GST_BUFFER_PTS (buf) = h->pts + GST_PIPEWIRE_CLOCK (pwsrc->clock)->time_offset;
|
||||
if (GST_BUFFER_PTS (buf) + h->dts_offset > 0)
|
||||
GST_BUFFER_DTS (buf) = GST_BUFFER_PTS (buf) + h->dts_offset;
|
||||
}
|
||||
|
|
@ -694,6 +694,8 @@ on_format_changed (void *data,
|
|||
return;
|
||||
}
|
||||
|
||||
gst_pipewire_clock_reset (GST_PIPEWIRE_CLOCK (pwsrc->clock), 0);
|
||||
|
||||
caps = gst_caps_from_format (format);
|
||||
GST_DEBUG_OBJECT (pwsrc, "we got format %" GST_PTR_FORMAT, caps);
|
||||
res = gst_base_src_set_caps (GST_BASE_SRC (pwsrc), caps);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue