1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:47:35 +00:00

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.
This commit is contained in:
Andreas Kling 2019-07-28 18:27:32 +02:00
parent 7f82e86fb8
commit 7cabe6433e
6 changed files with 61 additions and 1 deletions

View file

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

View file

@ -12,4 +12,5 @@ public:
virtual void handshake() override;
void play(const ABuffer&, bool block);
void enqueue(const ABuffer&);
};

View file

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