Commit Graph

14 Commits

Author SHA1 Message Date
Zaggy1024
d189be12ba Tests: Increase the TestPlaybackStream disconnection timeout
Apparently the queued task often takes longer than 100ms to finish,
and the stream is kept alive for the duration of its execution.
2026-03-30 20:57:04 -05:00
Zaggy1024
c77eae4a55 Tests: Only end TestPlaybackStream after the promise is resolved
Otherwise, the promise handlers may never be invoked, and we won't know
whether we're matching expectations.

Prior to 39d865b, this test did not actually check if the PulseAudio
stream was able to connect before passing the test. After that commit,
it would instead try to post the rejection to the main thread, which
would either lead to a crash preventing a use-after-free on the main
event loop, or in the more common case, the event loop would be freed
and never invoke the rejection callback.
2026-03-30 20:57:04 -05:00
Zaggy1024
39d865b403 LibMedia: Provide new PlaybackStreams through promises
This allows us to avoid returning a PlaybackStream in cases where the
async initialization fails.

This is a step towards more graceful fallbacks when audio fails in
AudioMixingSink.
2026-03-21 23:11:47 -05:00
Zaggy1024
744abc0c18 Tests: Use some tasks when testing PlaybackStream
This doesn't help to reproduce the potential UAF in the previous
commit, but it doesn't hurt to include this nonetheless.
2025-12-29 19:58:22 -06:00
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
ayeteadoe
ca5a321728 Tests/LibMedia: Avoid assertions that assume a valid PlaybackStream
Windows currently doesn't have a LADYBIRD_AUDIO_BACKEND set, this means
Audio::PlaybackStream::create() always returns an Error. We should not
perform assertions in TestPlaybackStream that assume an implementation
always exists.
2025-12-13 16:45:29 -06:00
Zaggy1024
c75284591f LibMedia: Make PlaybackStream use the output's sample specification
Instead of specifying the sample rate, channel count/map, etc. to the
PlaybackStream, we'll now use the output device's sample specification
whenever possible. If necessary, the stream will fall back to sane
default.

This hugely simplifies AudioMixingSink, since it no longer has to take
care of reinitializing the stream with a new sample specification when
it encounters a track with a higher sample rate or more channels. We
wouldn't be likely to benefit from this anyway, since it turns out that
at least Windows's virtual surround doesn't work through WASAPI at all,
and WASAPI likely wouldn't support downmixing.

This commit breaks playback of audio files that don't match the system
default audio device's sample rate and channel count. The next commit
introduces a converter into the pipeline to allow mixing of any sample
specification.
2025-12-13 08:58:26 +01:00
Zaggy1024
b2ab53fc84 Tests: Don't write any audio data in TestPlaybackStream
Also, ensure that the total time played reflects that.
2025-12-13 08:58:26 +01:00
Zaggy1024
5c9a34d84a LibMedia: Only use floats for audio data callbacks
We were already assuming that our streams were using floats, we may as
well hardcode this. If we ever encounter a platform API that doesn't
support or convert from float, we can always bring this back.

Also, since we don't support big-endian systems, remove that check in
PulseAudioWrappers.
2025-12-13 08:58:26 +01:00
Zaggy1024
6790a695da Tests: Wait for PulseAudio context destruction in TestPlaybackStream
The stream was being kept alive until the moment before we check if the
context is still alive. The stream's control thread holds a reference
to the PulseAudioContext, so that should almost never be destroyed
before the VERIFY in the test. Instead, wait at most 100ms for it to be
destroyed.
2025-11-25 13:13:32 -06:00
Zaggy1024
13cf0e72d8 LibMedia: Stop using threading-unsafe Weakable for PulseAudioContext
We can't control whether the instantiation mutex is held when
~Weakable() is called, so we need to implement this via a static raw
pointer instead to ensure that all operations on it are effectively
atomic.
2025-11-24 15:09:34 -06:00
ayeteadoe
94a3a7d9a1 Tests/LibMedia: Enable in Windows CI 2025-08-23 16:04:36 -06:00
Timothy Flynn
c51cd34bfb LibMedia: Remove outdated FIXME regarding Audio tests
This FIXME does not apply to Ladybird outside Serenity.
2024-12-25 12:00:43 +01:00
Jelle Raaijmakers
85fd2e281b LibMedia: Absorb LibAudio
LibMedia will be responsible for both audio and video decoding.
2024-09-12 10:01:19 +02:00