diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-07-28 18:27:32 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-28 18:27:32 +0200 |
commit | 7cabe6433eba86b50d7fbee89d59b2ab6bae7b50 (patch) | |
tree | ce60c44089d1aa02ffd2ee251c1c0c5c581ad090 /Libraries/LibAudio | |
parent | 7f82e86fb80ab9730b685b4fd5b916d2ff72e4bd (diff) | |
download | serenity-7cabe6433eba86b50d7fbee89d59b2ab6bae7b50.zip |
AudioServer: Add a buffer queue so we can buffer some sound.
The idea here is to keep a small number of sample buffers queued in the
AudioServer so we don't get caught without something to play.
Diffstat (limited to 'Libraries/LibAudio')
-rw-r--r-- | Libraries/LibAudio/AClientConnection.cpp | 15 | ||||
-rw-r--r-- | Libraries/LibAudio/AClientConnection.h | 1 | ||||
-rw-r--r-- | Libraries/LibAudio/ASAPI.h | 3 |
3 files changed, 19 insertions, 0 deletions
diff --git a/Libraries/LibAudio/AClientConnection.cpp b/Libraries/LibAudio/AClientConnection.cpp index 0cb64578b2..abe9a307c4 100644 --- a/Libraries/LibAudio/AClientConnection.cpp +++ b/Libraries/LibAudio/AClientConnection.cpp @@ -25,3 +25,18 @@ void AClientConnection::play(const ABuffer& buffer, bool block) request.play_buffer.buffer_id = buffer.shared_buffer_id(); sync_request(request, block ? ASAPI_ServerMessage::Type::FinishedPlayingBuffer : ASAPI_ServerMessage::Type::PlayingBuffer); } + +void AClientConnection::enqueue(const ABuffer& buffer) +{ + for (;;) { + const_cast<ABuffer&>(buffer).shared_buffer().share_with(server_pid()); + ASAPI_ClientMessage request; + request.type = ASAPI_ClientMessage::Type::EnqueueBuffer; + request.play_buffer.buffer_id = buffer.shared_buffer_id(); + auto response = sync_request(request, ASAPI_ServerMessage::Type::EnqueueBufferResponse); + if (response.success) + break; + dbg() << "EnqueueBuffer failed, retrying..."; + sleep(1); + } +} diff --git a/Libraries/LibAudio/AClientConnection.h b/Libraries/LibAudio/AClientConnection.h index 214af48bc0..2cc224353d 100644 --- a/Libraries/LibAudio/AClientConnection.h +++ b/Libraries/LibAudio/AClientConnection.h @@ -12,4 +12,5 @@ public: virtual void handshake() override; void play(const ABuffer&, bool block); + void enqueue(const ABuffer&); }; diff --git a/Libraries/LibAudio/ASAPI.h b/Libraries/LibAudio/ASAPI.h index 227aee1027..0dabd28c86 100644 --- a/Libraries/LibAudio/ASAPI.h +++ b/Libraries/LibAudio/ASAPI.h @@ -6,10 +6,12 @@ struct ASAPI_ServerMessage { Greeting, PlayingBuffer, FinishedPlayingBuffer, + EnqueueBufferResponse, }; Type type { Type::Invalid }; unsigned extra_size { 0 }; + bool success { true }; union { struct { @@ -27,6 +29,7 @@ struct ASAPI_ClientMessage { Invalid, Greeting, PlayBuffer, + EnqueueBuffer, }; Type type { Type::Invalid }; |