LibAudio: Prefix AK::Duration with AK Namespace

This commit is contained in:
Andrew Kaster 2024-07-16 23:43:09 -06:00 committed by Sam Atkins
parent 7a1f3f7ae3
commit 6772d442e5
Notes: sideshowbarker 2024-07-18 23:46:59 +09:00
7 changed files with 24 additions and 24 deletions

View file

@ -52,7 +52,7 @@ public:
//
// The value provided to the promise resolution will match the `total_time_played()` at the exact moment that
// the stream was resumed.
virtual NonnullRefPtr<Core::ThreadedPromise<Duration>> resume() = 0;
virtual NonnullRefPtr<Core::ThreadedPromise<AK::Duration>> resume() = 0;
// Completes playback of any buffered audio data and then suspends playback and buffering.
virtual NonnullRefPtr<Core::ThreadedPromise<void>> drain_buffer_and_suspend() = 0;
// Drops any buffered audio data and then suspends playback and buffering. This can used be to stop playback
@ -64,7 +64,7 @@ public:
// whenever possible.
//
// This function should be able to run from any thread safely.
virtual ErrorOr<Duration> total_time_played() = 0;
virtual ErrorOr<AK::Duration> total_time_played() = 0;
virtual NonnullRefPtr<Core::ThreadedPromise<void>> set_volume(double volume) = 0;
};

View file

@ -42,14 +42,14 @@ struct AudioTask {
Volume,
};
void resolve(Duration time)
void resolve(AK::Duration time)
{
promise.visit(
[](Empty) { VERIFY_NOT_REACHED(); },
[&](NonnullRefPtr<Core::ThreadedPromise<void>>& promise) {
promise->resolve();
},
[&](NonnullRefPtr<Core::ThreadedPromise<Duration>>& promise) {
[&](NonnullRefPtr<Core::ThreadedPromise<AK::Duration>>& promise) {
promise->resolve(move(time));
});
}
@ -66,7 +66,7 @@ struct AudioTask {
}
Type type;
Variant<Empty, NonnullRefPtr<Core::ThreadedPromise<void>>, NonnullRefPtr<Core::ThreadedPromise<Duration>>> promise;
Variant<Empty, NonnullRefPtr<Core::ThreadedPromise<void>>, NonnullRefPtr<Core::ThreadedPromise<AK::Duration>>> promise;
Optional<double> data {};
};
@ -128,9 +128,9 @@ public:
});
}
Duration last_sample_time() const
AK::Duration last_sample_time() const
{
return Duration::from_milliseconds(m_last_sample_time.load());
return AK::Duration::from_milliseconds(m_last_sample_time.load());
}
private:
@ -182,7 +182,7 @@ private:
}
if (error == noErr)
task.resolve(Duration::from_milliseconds(last_sample_time));
task.resolve(AK::Duration::from_milliseconds(last_sample_time));
else
task.reject(error);
}
@ -248,9 +248,9 @@ void PlaybackStreamAudioUnit::set_underrun_callback(Function<void()>)
// FIXME: Implement this.
}
NonnullRefPtr<Core::ThreadedPromise<Duration>> PlaybackStreamAudioUnit::resume()
NonnullRefPtr<Core::ThreadedPromise<AK::Duration>> PlaybackStreamAudioUnit::resume()
{
auto promise = Core::ThreadedPromise<Duration>::create();
auto promise = Core::ThreadedPromise<AK::Duration>::create();
AudioTask task { AudioTask::Type::Play, promise };
if (auto result = m_state->queue_task(move(task)); result.is_error())
@ -281,7 +281,7 @@ NonnullRefPtr<Core::ThreadedPromise<void>> PlaybackStreamAudioUnit::discard_buff
return promise;
}
ErrorOr<Duration> PlaybackStreamAudioUnit::total_time_played()
ErrorOr<AK::Duration> PlaybackStreamAudioUnit::total_time_played()
{
return m_state->last_sample_time();
}

View file

@ -21,11 +21,11 @@ public:
virtual void set_underrun_callback(Function<void()>) override;
virtual NonnullRefPtr<Core::ThreadedPromise<Duration>> resume() override;
virtual NonnullRefPtr<Core::ThreadedPromise<AK::Duration>> resume() override;
virtual NonnullRefPtr<Core::ThreadedPromise<void>> drain_buffer_and_suspend() override;
virtual NonnullRefPtr<Core::ThreadedPromise<void>> discard_buffer_and_suspend() override;
virtual ErrorOr<Duration> total_time_played() override;
virtual ErrorOr<AK::Duration> total_time_played() override;
virtual NonnullRefPtr<Core::ThreadedPromise<void>> set_volume(double) override;

View file

@ -77,9 +77,9 @@ void PlaybackStreamPulseAudio::set_underrun_callback(Function<void()> callback)
});
}
NonnullRefPtr<Core::ThreadedPromise<Duration>> PlaybackStreamPulseAudio::resume()
NonnullRefPtr<Core::ThreadedPromise<AK::Duration>> PlaybackStreamPulseAudio::resume()
{
auto promise = Core::ThreadedPromise<Duration>::create();
auto promise = Core::ThreadedPromise<AK::Duration>::create();
TRY_OR_REJECT(m_state->check_is_running(), promise);
m_state->enqueue([this, promise]() {
TRY_OR_REJECT(m_state->stream()->resume());
@ -110,11 +110,11 @@ NonnullRefPtr<Core::ThreadedPromise<void>> PlaybackStreamPulseAudio::discard_buf
return promise;
}
ErrorOr<Duration> PlaybackStreamPulseAudio::total_time_played()
ErrorOr<AK::Duration> PlaybackStreamPulseAudio::total_time_played()
{
if (m_state->stream() != nullptr)
return m_state->stream()->total_time_played();
return Duration::zero();
return AK::Duration::zero();
}
NonnullRefPtr<Core::ThreadedPromise<void>> PlaybackStreamPulseAudio::set_volume(double volume)

View file

@ -18,11 +18,11 @@ public:
virtual void set_underrun_callback(Function<void()>) override;
virtual NonnullRefPtr<Core::ThreadedPromise<Duration>> resume() override;
virtual NonnullRefPtr<Core::ThreadedPromise<AK::Duration>> resume() override;
virtual NonnullRefPtr<Core::ThreadedPromise<void>> drain_buffer_and_suspend() override;
virtual NonnullRefPtr<Core::ThreadedPromise<void>> discard_buffer_and_suspend() override;
virtual ErrorOr<Duration> total_time_played() override;
virtual ErrorOr<AK::Duration> total_time_played() override;
virtual NonnullRefPtr<Core::ThreadedPromise<void>> set_volume(double) override;

View file

@ -452,7 +452,7 @@ ErrorOr<void> PulseAudioStream::resume()
return {};
}
ErrorOr<Duration> PulseAudioStream::total_time_played()
ErrorOr<AK::Duration> PulseAudioStream::total_time_played()
{
auto locker = m_context->main_loop_locker();
@ -465,19 +465,19 @@ ErrorOr<Duration> PulseAudioStream::total_time_played()
// last-returned time. If we never call pa_stream_get_time() until after giving
// the stream its first samples, the issue never occurs.
if (!m_started_playback)
return Duration::zero();
return AK::Duration::zero();
pa_usec_t time = 0;
auto error = pa_stream_get_time(m_stream, &time);
if (error == -PA_ERR_NODATA)
return Duration::zero();
return AK::Duration::zero();
if (error != 0)
return Error::from_string_literal("Failed to get time from PulseAudio stream");
if (time > NumericLimits<i64>::max()) {
warnln("WARNING: Audio time is too large!");
time -= NumericLimits<i64>::max();
}
return Duration::from_microseconds(static_cast<i64>(time));
return AK::Duration::from_microseconds(static_cast<i64>(time));
}
ErrorOr<void> PulseAudioStream::set_volume(double volume)

View file

@ -118,7 +118,7 @@ public:
// Uncorks the stream and forces data to be written to the buffers to force playback to
// resume as soon as possible.
ErrorOr<void> resume();
ErrorOr<Duration> total_time_played();
ErrorOr<AK::Duration> total_time_played();
ErrorOr<void> set_volume(double volume);