blob: 1b52acc63ddb1eb556f2a75ccf9836df913ba62f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#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(server_pid(), 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();
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);
}
|