Truly independent web browser
LibAudio: Deliver captured frames to streams registered before the pop
Zaggy10243b016983d8c4
diff --git a/Libraries/LibAudio/ClientConnection.cpp b/Libraries/LibAudio/ClientConnection.cppindex ce801130884..338354f85a1 100644--- a/Libraries/LibAudio/ClientConnection.cpp+++ b/Libraries/LibAudio/ClientConnection.cpp@@ -407,21 +407,16 @@ void ClientConnection::pump_thread_main()MutexLocker locker(m_pump_mutex);while (!m_pump_should_exit) {streams.clear_with_capacity();- record_streams.clear_with_capacity();capture_rings.clear_with_capacity();for (auto* stream : m_streams) {if (stream->try_ref())streams.append(adopt_ref(*stream));}- for (auto* stream : m_record_streams) {- if (stream->try_ref())- record_streams.append(adopt_ref(*stream));- }for (auto& [stream_id, ring] : m_capture_rings)capture_rings.append({ .stream_id = stream_id, .ring = ring });m_pump_woken = false;- if (streams.is_empty() && record_streams.is_empty()) {+ if (streams.is_empty() && m_record_streams.is_empty()) {m_pump_condition.wait();continue;}@@ -437,14 +432,21 @@ void ClientConnection::pump_thread_main()scratch.resize(frames_available * ring.channel_count());auto frames_popped = ring.try_pop(scratch);auto samples = scratch.span().trim(frames_popped * ring.channel_count());- for (auto& stream : record_streams) {- if (stream->stream_id() == stream_id)- stream->deliver(samples);++ // The streams are gathered after the pop, so every stream registered before these frames were captured+ // receives them.+ locker.lock();+ for (auto* stream : m_record_streams) {+ if (stream->stream_id() == stream_id && stream->try_ref())+ record_streams.append(adopt_ref(*stream));}+ locker.unlock();+ for (auto& stream : record_streams)+ stream->deliver(samples);+ record_streams.clear_with_capacity();}// Drop the references before sleeping, so a stream's last reference does not idle here.streams.clear_with_capacity();- record_streams.clear_with_capacity();capture_rings.clear_with_capacity();locker.lock();