AudioServer: Added ability to get count of samples in the buffer queue

Now the AClientConnection can get the count of samples still in the
buffer queue.
This commit is contained in:
Till Mayer 2019-10-19 19:10:53 +02:00 committed by Andreas Kling
parent 8bb919d1cc
commit 406aabff23
Notes: sideshowbarker 2024-07-19 11:38:01 +09:00
7 changed files with 28 additions and 0 deletions

View file

@ -41,3 +41,8 @@ void AClientConnection::set_main_mix_volume(int volume)
{
send_sync<AudioServer::SetMainMixVolume>(volume);
}
int AClientConnection::get_remaining_samples()
{
return send_sync<AudioServer::GetRemainingSamples>()->remaining_samples();
}

View file

@ -16,4 +16,6 @@ public:
int get_main_mix_volume();
void set_main_mix_volume(int);
int get_remaining_samples();
};

View file

@ -71,3 +71,12 @@ OwnPtr<AudioServer::EnqueueBufferResponse> ASClientConnection::handle(const Audi
m_queue->enqueue(ABuffer::create_with_shared_buffer(*shared_buffer, message.sample_count()));
return make<AudioServer::EnqueueBufferResponse>(true);
}
OwnPtr<AudioServer::GetRemainingSamplesResponse> ASClientConnection::handle(const AudioServer::GetRemainingSamples&)
{
int remaining = 0;
if(m_queue)
remaining = m_queue->get_remaining_samples();
return make<AudioServer::GetRemainingSamplesResponse>(remaining);
}

View file

@ -22,6 +22,7 @@ private:
virtual OwnPtr<AudioServer::GetMainMixVolumeResponse> handle(const AudioServer::GetMainMixVolume&) override;
virtual OwnPtr<AudioServer::SetMainMixVolumeResponse> handle(const AudioServer::SetMainMixVolume&) override;
virtual OwnPtr<AudioServer::EnqueueBufferResponse> handle(const AudioServer::EnqueueBuffer&) override;
virtual OwnPtr<AudioServer::GetRemainingSamplesResponse> handle(const AudioServer::GetRemainingSamples&) override;
ASMixer& m_mixer;
RefPtr<ASBufferQueue> m_queue;

View file

@ -100,5 +100,6 @@ ASBufferQueue::ASBufferQueue(ASClientConnection& client)
void ASBufferQueue::enqueue(NonnullRefPtr<ABuffer>&& buffer)
{
m_remaining_samples += buffer->sample_count();
m_queue.enqueue(move(buffer));
}

View file

@ -24,9 +24,13 @@ public:
{
while (!m_current && !m_queue.is_empty())
m_current = m_queue.dequeue();
if (!m_current)
return false;
sample = m_current->samples()[m_position++];
m_remaining_samples--;
if (m_position >= m_current->sample_count()) {
m_current = nullptr;
m_position = 0;
@ -35,16 +39,20 @@ public:
}
ASClientConnection* client() { return m_client.ptr(); }
void clear()
{
m_queue.clear();
m_position = 0;
}
int get_remaining_samples() const { return m_remaining_samples; }
private:
RefPtr<ABuffer> m_current;
Queue<NonnullRefPtr<ABuffer>> m_queue;
int m_position { 0 };
int m_remaining_samples { 0 };
WeakPtr<ASClientConnection> m_client;
};

View file

@ -9,4 +9,6 @@ endpoint AudioServer
// Buffer playback
EnqueueBuffer(i32 buffer_id, int sample_count) => (bool success)
GetRemainingSamples() => (int remaining_samples)
}