2023-06-12 17:44:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2023-08-02 18:01:17 +00:00
|
|
|
#include "AudioCodecPluginQt.h"
|
2023-06-27 01:14:40 +00:00
|
|
|
#include "AudioThread.h"
|
2023-06-20 16:43:04 +00:00
|
|
|
#include <LibAudio/Loader.h>
|
2023-06-12 17:44:10 +00:00
|
|
|
|
|
|
|
namespace Ladybird {
|
|
|
|
|
2023-08-02 18:01:17 +00:00
|
|
|
ErrorOr<NonnullOwnPtr<AudioCodecPluginQt>> AudioCodecPluginQt::create(NonnullRefPtr<Audio::Loader> loader)
|
2023-06-20 16:43:04 +00:00
|
|
|
{
|
|
|
|
auto audio_thread = TRY(AudioThread::create(move(loader)));
|
|
|
|
audio_thread->start();
|
|
|
|
|
2023-08-02 18:01:17 +00:00
|
|
|
return adopt_nonnull_own_or_enomem(new (nothrow) AudioCodecPluginQt(move(audio_thread)));
|
2023-06-12 17:44:10 +00:00
|
|
|
}
|
|
|
|
|
2023-08-02 18:01:17 +00:00
|
|
|
AudioCodecPluginQt::AudioCodecPluginQt(NonnullOwnPtr<AudioThread> audio_thread)
|
2023-06-20 16:43:04 +00:00
|
|
|
: m_audio_thread(move(audio_thread))
|
2023-06-12 17:44:10 +00:00
|
|
|
{
|
2023-06-20 16:43:04 +00:00
|
|
|
connect(m_audio_thread, &AudioThread::playback_position_updated, this, [this](auto position) {
|
|
|
|
if (on_playback_position_updated)
|
|
|
|
on_playback_position_updated(position);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-08-02 18:01:17 +00:00
|
|
|
AudioCodecPluginQt::~AudioCodecPluginQt()
|
2023-06-20 16:43:04 +00:00
|
|
|
{
|
|
|
|
m_audio_thread->stop().release_value_but_fixme_should_propagate_errors();
|
2023-06-12 17:44:10 +00:00
|
|
|
}
|
|
|
|
|
2023-08-02 18:01:17 +00:00
|
|
|
void AudioCodecPluginQt::resume_playback()
|
2023-06-12 17:44:10 +00:00
|
|
|
{
|
2023-06-20 16:43:04 +00:00
|
|
|
m_audio_thread->queue_task({ AudioTask::Type::Play }).release_value_but_fixme_should_propagate_errors();
|
2023-06-12 17:44:10 +00:00
|
|
|
}
|
|
|
|
|
2023-08-02 18:01:17 +00:00
|
|
|
void AudioCodecPluginQt::pause_playback()
|
2023-06-12 17:44:10 +00:00
|
|
|
{
|
2023-06-20 16:43:04 +00:00
|
|
|
m_audio_thread->queue_task({ AudioTask::Type::Pause }).release_value_but_fixme_should_propagate_errors();
|
|
|
|
}
|
|
|
|
|
2023-08-02 18:01:17 +00:00
|
|
|
void AudioCodecPluginQt::set_volume(double volume)
|
2023-06-20 16:43:04 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
AudioTask task { AudioTask::Type::Volume };
|
|
|
|
task.data = volume;
|
|
|
|
|
|
|
|
m_audio_thread->queue_task(move(task)).release_value_but_fixme_should_propagate_errors();
|
2023-06-12 17:44:10 +00:00
|
|
|
}
|
|
|
|
|
2023-08-02 18:01:17 +00:00
|
|
|
void AudioCodecPluginQt::seek(double position)
|
2023-06-12 17:44:10 +00:00
|
|
|
{
|
2023-06-20 16:43:04 +00:00
|
|
|
AudioTask task { AudioTask::Type::Seek };
|
|
|
|
task.data = position;
|
|
|
|
|
|
|
|
m_audio_thread->queue_task(move(task)).release_value_but_fixme_should_propagate_errors();
|
2023-06-12 17:44:10 +00:00
|
|
|
}
|
|
|
|
|
2023-08-02 18:01:17 +00:00
|
|
|
Duration AudioCodecPluginQt::duration()
|
2023-06-14 16:59:22 +00:00
|
|
|
{
|
2023-06-20 16:43:04 +00:00
|
|
|
return m_audio_thread->duration();
|
2023-06-14 16:59:22 +00:00
|
|
|
}
|
|
|
|
|
2023-06-12 17:44:10 +00:00
|
|
|
}
|