1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-17 16:05:07 +00:00
serenity/Libraries/LibAudio/AClientConnection.cpp
Robin Burchell b907608e46 SharedBuffer: Split the creation and share steps
This allows us to seal a buffer *before* anyone else has access to it
(well, ok, the creating process still does, but you can't win them all).

It also means that a SharedBuffer can be shared with multiple clients:
all you need is to have access to it to share it on again.
2019-07-18 10:06:20 +02:00

35 lines
1.1 KiB
C++

#include <SharedBuffer.h>
#include <LibAudio/ABuffer.h>
#include "AClientConnection.h"
AClientConnection::AClientConnection()
: Connection("/tmp/asportal")
{
}
void AClientConnection::handshake()
{
ASAPI_ClientMessage request;
request.type = ASAPI_ClientMessage::Type::Greeting;
request.greeting.client_pid = getpid();
auto response = sync_request(request, ASAPI_ServerMessage::Type::Greeting);
set_server_pid(response.greeting.server_pid);
set_my_client_id(response.greeting.your_client_id);
}
void AClientConnection::play(const ABuffer& buffer)
{
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());
ASAPI_ClientMessage request;
request.type = ASAPI_ClientMessage::Type::PlayBuffer;
request.play_buffer.buffer_id = shared_buf->shared_buffer_id();
sync_request(request, ASAPI_ServerMessage::Type::PlayingBuffer);
}