From de3d1f2275ef5e3ad4d789666166942ae1a2f4f2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 27 Jul 2019 21:28:45 +0200 Subject: LibAudio: Remove an unnecessary copy of sample buffers before sending them. I missed this earlier, but *now* we're actually using the same SharedBuffer all the way from client-side WAV reading to server-side mixing. :^) --- Libraries/LibAudio/ABuffer.h | 1 + Libraries/LibAudio/AClientConnection.cpp | 12 ++---------- 2 files changed, 3 insertions(+), 10 deletions(-) (limited to 'Libraries/LibAudio') diff --git a/Libraries/LibAudio/ABuffer.h b/Libraries/LibAudio/ABuffer.h index 4aa23520cb..a8a7d2a580 100644 --- a/Libraries/LibAudio/ABuffer.h +++ b/Libraries/LibAudio/ABuffer.h @@ -68,6 +68,7 @@ public: const void* data() const { return m_buffer->data(); } int size_in_bytes() const { return m_buffer->size(); } int shared_buffer_id() const { return m_buffer->shared_buffer_id(); } + SharedBuffer& shared_buffer() { return *m_buffer; } private: explicit ABuffer(Vector&& samples) diff --git a/Libraries/LibAudio/AClientConnection.cpp b/Libraries/LibAudio/AClientConnection.cpp index 011f416172..0cb64578b2 100644 --- a/Libraries/LibAudio/AClientConnection.cpp +++ b/Libraries/LibAudio/AClientConnection.cpp @@ -19,17 +19,9 @@ void AClientConnection::handshake() void AClientConnection::play(const ABuffer& buffer, bool block) { - auto shared_buf = SharedBuffer::create_with_size(buffer.size_in_bytes()); - if (!shared_buf) { - dbg() << "Failed to create a shared buffer!"; - return; - } - - memcpy(shared_buf->data(), buffer.data(), buffer.size_in_bytes()); - shared_buf->seal(); - shared_buf->share_with(server_pid()); + const_cast(buffer).shared_buffer().share_with(server_pid()); ASAPI_ClientMessage request; request.type = ASAPI_ClientMessage::Type::PlayBuffer; - request.play_buffer.buffer_id = shared_buf->shared_buffer_id(); + request.play_buffer.buffer_id = buffer.shared_buffer_id(); sync_request(request, block ? ASAPI_ServerMessage::Type::FinishedPlayingBuffer : ASAPI_ServerMessage::Type::PlayingBuffer); } -- cgit v1.2.3