summaryrefslogtreecommitdiff
path: root/Servers
diff options
context:
space:
mode:
Diffstat (limited to 'Servers')
-rw-r--r--Servers/AudioServer/ASClientConnection.cpp15
-rw-r--r--Servers/AudioServer/ASMixer.cpp18
-rw-r--r--Servers/AudioServer/ASMixer.h5
3 files changed, 16 insertions, 22 deletions
diff --git a/Servers/AudioServer/ASClientConnection.cpp b/Servers/AudioServer/ASClientConnection.cpp
index 91351e6210..e70eb91fa1 100644
--- a/Servers/AudioServer/ASClientConnection.cpp
+++ b/Servers/AudioServer/ASClientConnection.cpp
@@ -40,16 +40,11 @@ bool ASClientConnection::handle_message(const ASAPI_ClientMessage& message, cons
break;
case ASAPI_ClientMessage::Type::PlayBuffer: {
// ### ensure that the size is that of a Vector<ASample>
- Vector<ASample> samples;
- {
- const auto& shared_buf = SharedBuffer::create_from_shared_buffer_id(message.play_buffer.buffer_id);
- if (!shared_buf) {
- did_misbehave();
- return false;
- }
- samples.resize(shared_buf->size() / sizeof(ASample));
- memcpy(samples.data(), shared_buf->data(), shared_buf->size());
+ auto shared_buffer = SharedBuffer::create_from_shared_buffer_id(message.play_buffer.buffer_id);
+ if (!shared_buffer) {
+ did_misbehave();
+ return false;
}
// we no longer need the buffer, so acknowledge that it's playing
@@ -59,7 +54,7 @@ bool ASClientConnection::handle_message(const ASAPI_ClientMessage& message, cons
reply.playing_buffer.buffer_id = message.play_buffer.buffer_id;
post_message(reply);
- m_mixer.queue(*this, ABuffer::create_with_samples(move(samples)), message.play_buffer.buffer_id);
+ m_mixer.queue(*this, ABuffer::create_with_shared_buffer(*shared_buffer));
break;
}
case ASAPI_ClientMessage::Type::Invalid:
diff --git a/Servers/AudioServer/ASMixer.cpp b/Servers/AudioServer/ASMixer.cpp
index 81d3180016..e4b618adc0 100644
--- a/Servers/AudioServer/ASMixer.cpp
+++ b/Servers/AudioServer/ASMixer.cpp
@@ -20,11 +20,11 @@ ASMixer::ASMixer()
}, this);
}
-void ASMixer::queue(ASClientConnection& client, const ABuffer& buffer, int buffer_id)
+void ASMixer::queue(ASClientConnection& client, const ABuffer& buffer)
{
ASSERT(buffer.size_in_bytes());
CLocker lock(m_lock);
- m_pending_mixing.append(ASMixerBuffer(buffer, client, buffer_id));
+ m_pending_mixing.append(ASMixerBuffer(buffer, client));
}
void ASMixer::mix()
@@ -68,19 +68,20 @@ void ASMixer::mix()
for (auto& buffer : active_mix_buffers) {
if (buffer.done)
continue;
- auto& samples = buffer.buffer->samples();
+ auto* samples = buffer.buffer->samples();
+ auto sample_count = buffer.buffer->sample_count();
- for (int i = 0; i < max_size && buffer.pos < samples.size(); ++buffer.pos, ++i) {
+ for (int i = 0; i < max_size && buffer.pos < sample_count; ++buffer.pos, ++i) {
auto& mixed_sample = mixed_buffer[i];
mixed_sample += samples[buffer.pos];
}
// clear it later
- if (buffer.pos == samples.size()) {
- if (buffer.m_buffer_id && buffer.m_client) {
+ if (buffer.pos == sample_count) {
+ if (buffer.m_client) {
ASAPI_ServerMessage reply;
reply.type = ASAPI_ServerMessage::Type::FinishedPlayingBuffer;
- reply.playing_buffer.buffer_id = buffer.m_buffer_id;
+ reply.playing_buffer.buffer_id = buffer.buffer->shared_buffer_id();
buffer.m_client->post_message(reply);
}
buffer.done = true;
@@ -118,9 +119,8 @@ void ASMixer::mix()
}
}
-ASMixer::ASMixerBuffer::ASMixerBuffer(const NonnullRefPtr<ABuffer>& buf, ASClientConnection& client, int buffer_id)
+ASMixer::ASMixerBuffer::ASMixerBuffer(const NonnullRefPtr<ABuffer>& buf, ASClientConnection& client)
: buffer(buf)
, m_client(client.make_weak_ptr())
- , m_buffer_id(buffer_id)
{
}
diff --git a/Servers/AudioServer/ASMixer.h b/Servers/AudioServer/ASMixer.h
index 8f39f42668..253f3dfc8e 100644
--- a/Servers/AudioServer/ASMixer.h
+++ b/Servers/AudioServer/ASMixer.h
@@ -14,16 +14,15 @@ class ASMixer : public RefCounted<ASMixer> {
public:
ASMixer();
- void queue(ASClientConnection&, const ABuffer&, int buffer_id);
+ void queue(ASClientConnection&, const ABuffer&);
private:
struct ASMixerBuffer {
- ASMixerBuffer(const NonnullRefPtr<ABuffer>&, ASClientConnection&, int buffer_id = -1);
+ ASMixerBuffer(const NonnullRefPtr<ABuffer>&, ASClientConnection&);
NonnullRefPtr<ABuffer> buffer;
int pos { 0 };
bool done { false };
WeakPtr<ASClientConnection> m_client;
- int m_buffer_id { -1 };
};
Vector<ASMixerBuffer> m_pending_mixing;