module-rtp: Reset ring buffer contents when stream starts

This commit is contained in:
Carlos Rafael Giani 2025-08-05 11:54:52 +02:00 committed by Wim Taymans
parent c9a8b8629f
commit 97a1609b29
2 changed files with 17 additions and 1 deletions

View file

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

View file

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