Commit graph

60 commits

Author SHA1 Message Date
Zaggy1024
e11da1f85f LibMedia: Store a name and language in Media::Track 2025-10-27 17:28:49 -07:00
Zaggy1024
e8238b4098 LibMedia: Replace FlyString with String for Matroska track attributes
The values stored by these are either going to be fairly unique or too
short to benefit from FlyString.
2025-10-27 17:28:49 -07:00
Zaggy1024
dfe59b8a4f LibMedia+LibWeb: Prefer MatroskaDemuxer for media playback
MatroskaDemuxer supports multiple streams already, and gives us a bit
more control over seeking.
2025-10-27 17:28:49 -07:00
Zaggy1024
0ff330c906 LibMedia: Play audio through PlaybackManager using Providers/Sinks
This commit implements the functionality to play back audio through
PlaybackManager.

To decode the audio data, AudioDataProviders are created for each track
in the provided media data. These providers will fill their audio block
queue, then sit idle until their corresponding tracks are enabled.

In order to output the audio, one AudioMixingSink is created which
manages a PlaybackStream which requests audio blocks from multiple
AudioDataProviders and mixes them into one buffer with sample-perfect
precision.
2025-10-27 17:28:49 -07:00
Zaggy1024
dd052832c1 LibMedia: Support the MP3 and AAC codecs in our demuxer 2025-10-27 17:28:49 -07:00
Zaggy1024
6b34003c2c LibMedia: Support coded audio frames in our demuxers
This adds a new variant of the metadata storage in CodedFrame for audio
frames, called CodedAudioFrameData.
2025-10-27 17:28:49 -07:00
Zaggy1024
6caa2f99aa LibMedia+LibWeb: Rewrite PlaybackManager using the provider/sink model
With this commit, all PlaybackManager can do is autoplay a file from
start to finish, with no pausing or seeking functionality.

All audio playback functionality has been removed from HTMLMediaElement
and HTMLAudioElement in anticipation of PlaybackManager taking that
over, for both audio-only and audio/video.
2025-10-27 17:28:49 -07:00
Zaggy1024
31b72c4799 LibMedia: Make Track::type() const 2025-10-27 17:28:49 -07:00
Zaggy1024
7e238cd724 LibMedia: Add separate classes managing decoding and displaying video
These are unused in this commit, but will later be used to output video
via PlaybackManager, or to decode video directly to some consumer.
2025-10-27 17:28:49 -07:00
Zaggy1024
dfbad09315 LibMedia: Set the time base in FFmpegVideoDecoder
Very minor change, which doesn't actually affect our output, since we
were already inputting and outputting microseconds, but it can't hurt
to give FFmpeg's decoder this information as well.
2025-10-27 17:28:49 -07:00
Zaggy1024
523e7e2ffa LibMedia: Make Demuxer atomically ref-counted
We'll need to share the demuxer between multiple decoder providers, and
those will hold references to the demuxer from their own decoder
threads.
2025-10-27 17:28:49 -07:00
Zaggy1024
27742ef26d LibMedia+LibWeb: Never return errors when getting PlaybackStream time
We should be fine to just fall back to zero or the last returned value
if we encounter an error in PlaybackStream::total_time_played(), and
this also simplifies the using code.
2025-10-27 17:28:49 -07:00
Zaggy1024
9cd0f9c445 LibMedia: Support BT.470 System B/G color primaries 2025-10-16 05:12:29 -05:00
Zaggy1024
b684bc0a9d LibMedia: Reorder the BT.2020 matrix to match previous lines 2025-10-16 05:12:29 -05:00
Zaggy1024
30d4810d70 LibMedia: Actually read Matroska tracks' CodecDelay elements 2025-10-02 11:03:26 +02:00
Zaggy1024
ce228663f1 LibMedia: Rename Matroska TRACK_CODEC_PRIVATE to TRACK_CODEC_PRIVATE_ID 2025-10-02 11:03:26 +02:00
Zaggy1024
2aaf53bd2c Everywhere: Use a forward declaration for pointers to Threading::Thread 2025-09-22 17:28:21 -05:00
Zaggy1024
319e381eb9 LibMedia: Mark FFmpegVideoDecoder functions with virtual override
The destructor lacked any of these specifiers, and others lacked the
virtual specifier.
2025-09-22 19:34:48 +02:00
Zaggy1024
fc1cc49d6a LibMedia: Remove an unused private function from FFmpegVideoDecoder 2025-09-22 12:04:29 -05:00
Zaggy1024
6cbe607ecf LibMedia+Tests: Call decoder input samples "coded data" for clarity
The word sample is very ambiguous in the realm of decoders, so let's
just make it abundantly clear what the decoder is receiving.
2025-09-22 12:04:29 -05:00
Zaggy1024
8d77e8b09d LibMedia: Refer to demuxer outputs as coded frames
This should be a clearer name, as "sample" is most often used to refer
to the output of a decoder.
2025-09-22 12:04:29 -05:00
Zaggy1024
7434c763d5 LibMedia: Remove default cases when converting CodecID for FFmpeg
This forces us to keep at least that conversion switch statement
up-to-date.
2025-09-19 13:01:00 +02:00
Zaggy1024
26a21f2070 LibMedia: Make MatroskaDemuxer::get_codec_id_for_string static 2025-09-12 11:23:47 +02:00
Zaggy1024
9077873803 LibMedia: Stop initializing an empty optional in MatroskaDemuxer
There was a warning for the Optional initializer having no effect, but
removing the initializer caused the call to add a track to the HashMap
to complain. A constructor looks a little nicer here anyway.
2025-09-12 11:23:47 +02:00
Zaggy1024
ae7f82591b LibMedia: Separate file duration from track duration in Demuxer
Most users will only care about the total file duration, and shouldn't
be required to determine the file duration from multiple track
durations. To facilitate that, add a total_duration() function that
returns the demuxer's duration not associated to any particular track.
2025-09-12 11:23:47 +02:00
Zaggy1024
6653b747ff LibMedia: Allow demuxers to specify a preferred track
...and return all tracks of a matching type from FFmpegDemuxer, rather
than only the single best one.
2025-09-12 11:23:47 +02:00
Zaggy1024
8d64e72655 LibMedia: Remove the duration field from Track::VideoData
Most demuxer users will only care about the whole file's duration
anyway, so this field doesn't really do us any good.
2025-09-12 11:23:47 +02:00
Zaggy1024
f9305e7e67 LibMedia: Format switch statements consistently in FFmpegVideoDecoder 2025-09-11 18:41:58 -05:00
Zaggy1024
924ba6c1f4 LibMedia: Use FFmpeg's info to tell us if YUVJ is full-range
It reports this correctly for the video linked in #4993, and likely any
other videos using the YUVJ format, so we don't need this extra check.
2025-09-11 18:41:58 -05:00
Zaggy1024
cae14c763d LibMedia: Convert FFmpeg time units to AK::Duration with integer math
The existing conversion was rounding to the nearest millisecond, which
is much less precision than most videos will want. Instead, use only
integer math to directly convert the presentation time to seconds and
nanoseconds for our AK::Duration to represent accurately.
2025-09-08 13:29:04 -05:00
Zaggy1024
7811c2e71b LibMedia: Ensure that the PulseAudioContext atexit() call succeeds 2025-09-04 19:37:56 +02:00
Zaggy1024
ee3c080fb5 LibMedia: Initialize Track's primitive fields to zero 2025-09-04 13:34:19 -04:00
Zaggy1024
33e97fa5d7 LibMedia: Note that PlaybackStream callbacks cannot run simultaneously
This is a requirement of implementations of PlaybackStream, so we
should have a little comment about it. Otherwise, we may encounter data
races later.
2025-09-04 13:29:18 -04:00
Ali Mohammad Pur
4462348916 Everywhere: Slap some [[clang::lifetimebound]] where appropriate
This first pass only applies to the following two cases:
- Public functions returning a view type into an object they own
- Public ctors storing a view type

This catches a grand total of one (1) issue, which is fixed in
the previous commit.
2025-09-01 11:11:38 +02:00
Ali Mohammad Pur
8b3e888920 LibMedia: Don't store view into deleted ByteString
DecoderError::formatted() made a ByteString, took a view into it,
dropped the ByteString, then propagated the (now invalid) view back to
the caller as an error.
Since the object has to keep the ByteString alive, keep it as a variant
to make sure the "happy" path with no alloc remains alloc-free.
2025-09-01 11:11:38 +02:00
ayeteadoe
8150fb4cbb LibMedia: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-24 12:58:27 -06:00
Arran Ireland
9a8599f265 LibGfx+LibMedia+LibWeb: Use new Matrix subscript operator 2025-07-28 09:15:23 +02:00
Olekoop
af2d46bd3d LibMedia+Meta: Enable FFmpeg under Android and remove the stubs
The licensing issue seems to be resolved (#2214).
The stubs are not longer necessary. Even if they were, they do not
compile properly.
2025-07-10 15:44:53 -06:00
ayeteadoe
25f5936dee CMake: Rename serenity_* helper functions/macros to ladybird_* 2025-07-03 23:19:41 +02:00
Jelle Raaijmakers
180bb0fc5d Everywhere: Remove LibRIFF 2025-07-02 12:01:12 +01:00
ayeteadoe
dbba6c0df9 LibWeb: Enable in Windows CI 2025-06-30 10:50:36 -06:00
Viktor Szépe
19f88f96dc Everywhere: Fix typos - act III 2025-06-16 14:20:48 +01:00
aplefull
c4fadc1abf LibMedia: Add support for YUVJ pixel formats in FFmpegVideoDecoder 2025-06-16 10:26:41 +02:00
Timothy Flynn
ad4634d0ed LibMedia: Use a simple locked vector to handle audio commands on macOS
The SharedSingleProducerCircularQueue used here has dubious value, This
queue is used to pass commands to the audio thread, such as play/pause/
seek/volume change/etc. We can make do with a simple locked vector, as
we were blocking to enqueue tasks anyways. We can also use an atomic
bool to tell the audio thread when it needs to take a lock on the task
queue, to keep the thread lock-free most of the time.
2025-05-25 08:45:50 -04:00
aplefull
68ddc7006d LibMedia: Implement conversion of BT601 primaries 2025-05-16 12:13:13 +01:00
Timothy Flynn
7280ed6312 Meta: Enforce newlines around namespaces
This has come up several times during code review, so let's just enforce
it using a new clang-format 20 option.
2025-05-14 02:01:59 -06:00
R-Goc
28d5d982ce Everywhere: Remove unused private fields
This commit removes the -Wno-unusued-private-field flag, thus
reenabling the warning. Unused field were either removed or marked
[[maybe_unused]] when unsure.
2025-04-04 12:40:07 +02:00
Tim Ledbetter
411cafa2a9 LibMedia: Add formatter for decoder errors
This is useful for print debugging.
2025-03-14 08:48:01 +01:00
Tim Ledbetter
c270241b09 LibMedia: Propagate errors if demuxer creation fails
Previously, the browser would crash if demuxer creation failed.
2025-03-14 08:48:01 +01:00
Luke Wilde
4df2de2f20 LibMedia/Audio: Use duration in the container if stream doesn't have one 2025-03-13 19:33:44 +01:00