Files
ladybird/Libraries/LibMedia/Audio/PlaybackStreamWasapi.h
R-Goc 1f3e20cebf LibMedia: Add a WASAPI playback stream for Windows
Implement PlaybackStream using WASAPI. The design is similar to
PlaybackStreamAudioUnit in that it uses a task queue. A high priority
thread is used to render the stream. All the stream controls save for
the exit being requested which happens on destruction of the stream are
managed by the render thread.

Due to the design of the windows audio mixer the audio we receive must
be resampled to match the sample rate of the mixer. We use a float based
interleaved PCM stream which matches both our existing code and the
audio mixer which internally usues floats.

Having to use a mutex around a queue for the task queue is suboptimal,
in a future PR a MPSC queue could be added to AK and used instead.
2025-12-29 18:02:02 -06:00

42 lines
1.3 KiB
C++

/*
* Copyright (c) 2025, Ryszard Goc <ryszardgoc@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include "PlaybackStream.h"
#include <AK/Error.h>
#include <AK/NonnullRefPtr.h>
namespace Audio {
class PlaybackStreamWASAPI final : public PlaybackStream {
public:
static ErrorOr<NonnullRefPtr<PlaybackStream>> create(OutputState initial_output_state, u32 target_latency_ms, SampleSpecificationCallback&&, AudioDataRequestCallback&&);
// The overrun callback must be realtime safe. The buffer size might be small.
virtual void set_underrun_callback(Function<void()>) 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 AK::Duration total_time_played() const override;
virtual NonnullRefPtr<Core::ThreadedPromise<void>> set_volume(double) override;
private:
struct AudioState;
explicit PlaybackStreamWASAPI(NonnullRefPtr<AudioState>);
static ALWAYS_INLINE AK::Duration total_time_played_with_com_initialized(AudioState& state);
~PlaybackStreamWASAPI();
NonnullRefPtr<AudioState> m_state;
};
}