mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	module-rtp: add timer for ck requests
Scale RTP timestamps against the clock, allow some jitter. Make method to query current RTP timestamps.
This commit is contained in:
		
							parent
							
								
									8e5b9da177
								
							
						
					
					
						commit
						c5effbd979
					
				
					 5 changed files with 181 additions and 25 deletions
				
			
		| 
						 | 
				
			
			@ -266,13 +266,14 @@ static void process_audio_capture(void *data)
 | 
			
		|||
	wanted = size / stride;
 | 
			
		||||
 | 
			
		||||
	filled = spa_ringbuffer_get_write_index(&impl->ring, &expected_timestamp);
 | 
			
		||||
	if (SPA_LIKELY(impl->io_position))
 | 
			
		||||
		timestamp = impl->io_position->clock.position;
 | 
			
		||||
	else
 | 
			
		||||
	if (SPA_LIKELY(impl->io_position)) {
 | 
			
		||||
		uint32_t rate = impl->io_position->clock.rate.denom;
 | 
			
		||||
		timestamp = impl->io_position->clock.position * impl->rate / rate;
 | 
			
		||||
	} else
 | 
			
		||||
		timestamp = expected_timestamp;
 | 
			
		||||
 | 
			
		||||
	if (impl->have_sync) {
 | 
			
		||||
		if (expected_timestamp != timestamp) {
 | 
			
		||||
		if (SPA_ABS((int32_t)expected_timestamp - (int32_t)timestamp) > 32) {
 | 
			
		||||
			pw_log_warn("expected %u != timestamp %u", expected_timestamp, timestamp);
 | 
			
		||||
			impl->have_sync = false;
 | 
			
		||||
		} else if (filled + wanted > (int32_t)(BUFFER_SIZE / stride)) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -466,3 +466,16 @@ int rtp_stream_receive_packet(struct rtp_stream *s, uint8_t *buffer, size_t len)
 | 
			
		|||
	struct impl *impl = (struct impl*)s;
 | 
			
		||||
	return impl->receive_rtp(impl, buffer, len);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint64_t rtp_stream_get_time(struct rtp_stream *s, uint64_t *rate)
 | 
			
		||||
{
 | 
			
		||||
	struct impl *impl = (struct impl*)s;
 | 
			
		||||
	struct spa_io_position *pos = impl->io_position;
 | 
			
		||||
 | 
			
		||||
	if (pos == NULL)
 | 
			
		||||
		return -EIO;
 | 
			
		||||
 | 
			
		||||
	*rate = impl->rate;
 | 
			
		||||
	return pos->clock.position * impl->rate *
 | 
			
		||||
		pos->clock.rate.num / pos->clock.rate.denom;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -42,6 +42,8 @@ void rtp_stream_destroy(struct rtp_stream *s);
 | 
			
		|||
 | 
			
		||||
int rtp_stream_receive_packet(struct rtp_stream *s, uint8_t *buffer, size_t len);
 | 
			
		||||
 | 
			
		||||
uint64_t rtp_stream_get_time(struct rtp_stream *s, uint64_t *rate);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue