mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	module-rtp: Reset ring buffer contents when stream starts
This commit is contained in:
		
							parent
							
								
									c9a8b8629f
								
							
						
					
					
						commit
						97a1609b29
					
				
					 2 changed files with 17 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -337,7 +337,7 @@ static int rtp_audio_receive(struct impl *impl, uint8_t *buffer, ssize_t len)
 | 
			
		|||
		 *
 | 
			
		||||
		 * (Note that this write index update is only important if
 | 
			
		||||
		 * the constant delay mode is active, or if no spa_io_position
 | 
			
		||||
		 * was provided yet. See the rtp_audio_process_playback()
 | 
			
		||||
		 * was not provided yet. See the rtp_audio_process_playback()
 | 
			
		||||
		 * code for more about this.) */
 | 
			
		||||
		if (expected_write < (write + samples)) {
 | 
			
		||||
			write += samples;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -104,6 +104,13 @@ struct impl {
 | 
			
		|||
	bool timer_running;
 | 
			
		||||
 | 
			
		||||
	int (*receive_rtp)(struct impl *impl, uint8_t *buffer, ssize_t len);
 | 
			
		||||
	/* Used for resetting the ring buffer before the stream starts, to prevent
 | 
			
		||||
	 * reading from uninitialized memory. This can otherwise happen in direct
 | 
			
		||||
	 * timestamp mode when the read index is set to an uninitialized location.
 | 
			
		||||
	 * This is a function pointer to allow customizations in case resetting
 | 
			
		||||
	 * requires filling the ring buffer with something other than nullbytes
 | 
			
		||||
	 * (this can happen with DSD for example). */
 | 
			
		||||
	void (*reset_ringbuffer)(struct impl *impl);
 | 
			
		||||
	void (*flush_timeout)(struct impl *impl, uint64_t expirations);
 | 
			
		||||
	void (*deinit)(struct impl *impl, enum spa_direction direction);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -188,6 +195,8 @@ static int stream_start(struct impl *impl)
 | 
			
		|||
 | 
			
		||||
	impl->first = true;
 | 
			
		||||
 | 
			
		||||
	impl->reset_ringbuffer(impl);
 | 
			
		||||
 | 
			
		||||
	rtp_stream_emit_state_changed(impl, true, NULL);
 | 
			
		||||
 | 
			
		||||
	if (impl->separate_sender) {
 | 
			
		||||
| 
						 | 
				
			
			@ -306,6 +315,11 @@ static void on_flush_timeout(void *d, uint64_t expirations)
 | 
			
		|||
	impl->flush_timeout(d, expirations);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void default_reset_ringbuffer(struct impl *impl)
 | 
			
		||||
{
 | 
			
		||||
	spa_memzero(impl->buffer, sizeof(impl->buffer));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct rtp_stream *rtp_stream_new(struct pw_core *core,
 | 
			
		||||
		enum spa_direction direction, struct pw_properties *props,
 | 
			
		||||
		const struct rtp_stream_events *events, void *data)
 | 
			
		||||
| 
						 | 
				
			
			@ -341,6 +355,8 @@ struct rtp_stream *rtp_stream_new(struct pw_core *core,
 | 
			
		|||
		goto out;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	impl->reset_ringbuffer = default_reset_ringbuffer;
 | 
			
		||||
 | 
			
		||||
	if ((str = pw_properties_get(props, "sess.media")) == NULL)
 | 
			
		||||
		str = "audio";
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue