mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	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:
		
							parent
							
								
									21a79241ed
								
							
						
					
					
						commit
						f0a1ab993f
					
				
					 4 changed files with 19 additions and 10 deletions
				
			
		| 
						 | 
					@ -31,12 +31,13 @@ GST_DEBUG_CATEGORY_STATIC (gst_pipewire_clock_debug_category);
 | 
				
			||||||
G_DEFINE_TYPE (GstPipeWireClock, gst_pipewire_clock, GST_TYPE_SYSTEM_CLOCK);
 | 
					G_DEFINE_TYPE (GstPipeWireClock, gst_pipewire_clock, GST_TYPE_SYSTEM_CLOCK);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GstClock *
 | 
					GstClock *
 | 
				
			||||||
gst_pipewire_clock_new (struct pw_stream *stream)
 | 
					gst_pipewire_clock_new (struct pw_stream *stream, GstClockTime last_time)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  GstPipeWireClock *clock;
 | 
					  GstPipeWireClock *clock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  clock = g_object_new (GST_TYPE_PIPEWIRE_CLOCK, NULL);
 | 
					  clock = g_object_new (GST_TYPE_PIPEWIRE_CLOCK, NULL);
 | 
				
			||||||
  clock->stream = stream;
 | 
					  clock->stream = stream;
 | 
				
			||||||
 | 
					  clock->last_time = last_time;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return GST_CLOCK_CAST (clock);
 | 
					  return GST_CLOCK_CAST (clock);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -48,14 +49,14 @@ gst_pipewire_clock_get_internal_time (GstClock * clock)
 | 
				
			||||||
  GstClockTime result;
 | 
					  GstClockTime result;
 | 
				
			||||||
  struct pw_time t;
 | 
					  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);
 | 
				
			||||||
    result = gst_util_uint64_scale_int (t.ticks, GST_SECOND * t.rate.num, t.rate.denom);
 | 
					 | 
				
			||||||
  else
 | 
					 | 
				
			||||||
    result = GST_CLOCK_TIME_NONE;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  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;
 | 
					  return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,6 +46,7 @@ struct _GstPipeWireClock {
 | 
				
			||||||
  GstSystemClock parent;
 | 
					  GstSystemClock parent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  struct pw_stream *stream;
 | 
					  struct pw_stream *stream;
 | 
				
			||||||
 | 
					  GstClockTime last_time;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct _GstPipeWireClockClass {
 | 
					struct _GstPipeWireClockClass {
 | 
				
			||||||
| 
						 | 
					@ -54,8 +55,8 @@ struct _GstPipeWireClockClass {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GType gst_pipewire_clock_get_type (void);
 | 
					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
 | 
					G_END_DECLS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1028,7 +1028,7 @@ gst_pipewire_src_open (GstPipeWireSrc * pwsrc)
 | 
				
			||||||
			 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);
 | 
					  pw_thread_loop_unlock (pwsrc->main_loop);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return TRUE;
 | 
					  return TRUE;
 | 
				
			||||||
| 
						 | 
					@ -1071,7 +1071,13 @@ gst_pipewire_src_close (GstPipeWireSrc * pwsrc)
 | 
				
			||||||
  pw_remote_destroy (pwsrc->remote);
 | 
					  pw_remote_destroy (pwsrc->remote);
 | 
				
			||||||
  pwsrc->remote = NULL;
 | 
					  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_OBJECT_LOCK (pwsrc);
 | 
				
			||||||
 | 
					  GST_PIPEWIRE_CLOCK (pwsrc->clock)->stream = NULL;
 | 
				
			||||||
  g_clear_object (&pwsrc->clock);
 | 
					  g_clear_object (&pwsrc->clock);
 | 
				
			||||||
  GST_OBJECT_UNLOCK (pwsrc);
 | 
					  GST_OBJECT_UNLOCK (pwsrc);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -82,6 +82,7 @@ struct _GstPipeWireSrc {
 | 
				
			||||||
  GstPipeWirePool *pool;
 | 
					  GstPipeWirePool *pool;
 | 
				
			||||||
  GQueue queue;
 | 
					  GQueue queue;
 | 
				
			||||||
  GstClock *clock;
 | 
					  GstClock *clock;
 | 
				
			||||||
 | 
					  GstClockTime last_time;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct _GstPipeWireSrcClass {
 | 
					struct _GstPipeWireSrcClass {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue