mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 09:46:04 -05:00
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:
parent
8bb919d1cc
commit
406aabff23
Notes:
sideshowbarker
2024-07-19 11:38:01 +09:00
Author: https://github.com/tlmrgvf Commit: https://github.com/SerenityOS/serenity/commit/406aabff233 Pull-request: https://github.com/SerenityOS/serenity/pull/672
7 changed files with 28 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -16,4 +16,6 @@ public:
|
|||
|
||||
int get_main_mix_volume();
|
||||
void set_main_mix_volume(int);
|
||||
|
||||
int get_remaining_samples();
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -9,4 +9,6 @@ endpoint AudioServer
|
|||
|
||||
// Buffer playback
|
||||
EnqueueBuffer(i32 buffer_id, int sample_count) => (bool success)
|
||||
|
||||
GetRemainingSamples() => (int remaining_samples)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue