From 390515d40c115217d27be3f74c38d4d3eefde02b Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Sat, 25 Jan 2025 14:42:33 -0500 Subject: Discard packet_stream queue on demote - Cleanup some comments. Signed-off-by: Andrew Opalach --- src/buffer/audio.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/buffer') diff --git a/src/buffer/audio.c b/src/buffer/audio.c index ce027af..2e65a97 100644 --- a/src/buffer/audio.c +++ b/src/buffer/audio.c @@ -166,7 +166,7 @@ static bool push_internal(struct camu_audio_buffer *buf, f64 pts, u8 **data, s32 peak += have; if (peak >= buf->mark.min) { // If this happens the writer of this buffer is taking way too long to stop. - al_log_warn("audio_buffer", "Overrun likely, discarding peak buffer."); + al_log_warn("audio_buffer", "Overrun likely, discarding peak buffer (audio will be desynced)."); camu_peak_buffer_flush(&buf->peak); peak = 0; } @@ -256,8 +256,8 @@ void camu_audio_buffer_unpause(struct camu_audio_buffer *buf) al_atomic_add(s32)(&buf->unpause, 1, AL_ATOMIC_RELAXED); } -// PAUSE_PAUSED signifies that the last read was silence. Meaning we can skip -// around in the buffer without worrying about pops. +// PAUSE_PAUSED signifies that the last read was silence. +// This means we can skip around in the buffer without worrying about pops. ptrdiff_t camu_audio_buffer_read(struct camu_audio_buffer *buf, u8 *data, ptrdiff_t req) { if (al_atomic_load(s32)(&buf->volume.set, AL_ATOMIC_ACQUIRE) > 0) { @@ -317,6 +317,9 @@ ptrdiff_t camu_audio_buffer_read(struct camu_audio_buffer *buf, u8 *data, ptrdif else have -= buf->fade.offset; #endif + // @NOTE: We are not safe to increment buf->pts from a different thread. + // We would need to accumulate the difference and do an atomic add instead + // of the load/store we do here. f64 base_pts = al_atomic_load(f64)(&buf->pts, AL_ATOMIC_ACQUIRE); // Unpause and possibly attempt syncing to the clock. if (UNLIKELY(buf->pause == PAUSE_PAUSED)) { -- cgit v1.2.3-101-g0448