Commit Graph

72565 Commits

Author SHA1 Message Date
Zaggy1024
9c960c3307 LibMedia: Use integer math to calculate the FFmpeg seek target pts 2025-10-27 17:28:49 -07:00
Zaggy1024
e9495d0ba0 LibWeb: Implement media element seeking through PlaybackManager
Including the behavior to conditionally seek forward when fast seeking!
2025-10-27 17:28:49 -07:00
Zaggy1024
ccf4b3f6e9 LibMedia: Implement media seeking
This implementation allows:
- Accurate seeking to an exact timestamp
- Seeking to the keyframe before a timestamp
- Seeking to the keyframe after a timestamp
These three options will be used to satisfy the playback position
selection in the media element's seeking steps.
2025-10-27 17:28:49 -07:00
Zaggy1024
b1c9a872bc LibMedia: Return whether a demuxer seek moved the stream position
We no longer need to return a timestamp from the seek function, which
makes it much easier to implement backend-agnostically.
2025-10-27 17:28:49 -07:00
Zaggy1024
27ed536540 LibMedia: Give PlaybackManager a playback state getter 2025-10-27 17:28:49 -07:00
Zaggy1024
9117f661a8 LibMedia: Split some repeated code in VideoDataProvider to functions 2025-10-27 17:28:49 -07:00
Zaggy1024
e5a6b76a40 LibMedia: When reaching EOS, clear Matroska iterators' last timestamp
This ensures that if we're at EOS, we never skip a seek, so that
seeking to the end of a video always gets a frame.
2025-10-27 17:28:49 -07:00
Zaggy1024
86e236519d LibMedia: Give demuxer seeks an option to always seek to a keyframe
By default, MatroskaDemuxer chooses not to seek if the current frame
is closer to the seek target than the keyframe that precedes the seek
target. However, it can be desirable to seek to a keyframe anyway, so
let's allow that.
2025-10-27 17:28:49 -07:00
Zaggy1024
e94ab24e66 LibMedia: Don't assert when MatroskaDemuxer seeks near the start
Reader::seek_to_random_access_point() isn't actually guaranteed to
return a sample iterator that has already gotten a block timestamp.
This verify passes in almost every case, but if we happen to seek to a
timestamp before the second keyframe, we'd crash.
2025-10-27 17:28:49 -07:00
Zaggy1024
0a03cc1cf7 LibMedia: Store whether a CodedFrame is a keyframe 2025-10-27 17:28:49 -07:00
Zaggy1024
d52ceec1bf LibMedia: Take Track const& in Demuxer methods 2025-10-27 17:28:49 -07:00
Zaggy1024
aa8c28eb24 AK+Tests: Allow creating a Duration from 64-bit floating point seconds 2025-10-27 17:28:49 -07:00
Zaggy1024
d3941cd83d LibMedia: Support playing FLAC 2025-10-27 17:28:49 -07:00
Zaggy1024
6ff7e4bfac LibMedia: Implement basic playing/paused playback state handlers 2025-10-27 17:28:49 -07:00
Zaggy1024
8d9a493b1b LibMedia+LibWeb: Implement media volume/muting 2025-10-27 17:28:49 -07:00
Zaggy1024
e176249db8 LibMedia: Use AudioMixingSink as a time provider when it is available 2025-10-27 17:28:49 -07:00
Zaggy1024
ee587cfec4 LibMedia+LibWeb: Implement media pausing/resuming 2025-10-27 17:28:49 -07:00
Zaggy1024
3ebaa0cd3f LibMedia: Implement a generic MediaTimeProvider for video-only timing
This time provider can later be swapped out for the AudioMixingSink
when it implements the MediaTimeProvider interface, so that frame
timing can be driven by audio when it is present.
2025-10-27 17:28:49 -07:00
Zaggy1024
3d0b8cc30c LibWeb: Set AudioTrack and VideoTrack fields according to spec
The two classes now inherit from a common base MediaTrackBase, to
deduplicate the attributes that are shared between the two.

The integer ID from the container is used for each track's id
attribute.

The kind attribute is set to "main" or "translation" according to:
https://dev.w3.org/html5/html-sourcing-inband-tracks/

The label attribute is set to the human-readable name of the track, if
one is present.

The language attribute is set to a BCP 47 language tag, if one can be
parsed successfully.
2025-10-27 17:28:49 -07:00
Zaggy1024
29ab9c5fd5 LibMedia: Let the Matroska LanguageBCP47 element override Language
The Matroska spec indicates that this field should always override the
Language element when it is present.
2025-10-27 17:28:49 -07:00
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
5456072d48 LibWeb: Implement audio media data processing through PlaybackManager 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
0f9fa47352 LibWeb: Update media elements' page mute state via a for_each method 2025-10-27 17:28:49 -07:00
Zaggy1024
5e645929a7 LibWeb: Stop moving a GC::Ref in media elements' create_layout_node()s
The type is trivial, so this was causing a warning.
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
Tim Ledbetter
9da723b5c6 LibWeb: Ensure layout is up to date before resolving canvas colors 2025-10-27 16:56:01 -07:00
Jelle Raaijmakers
4dbae64dce LibWeb: Unify objectBoundingBox and userSpaceOnUse coord transformations
There's a fairly complicated interaction between an SVG gradient's paint
transformation and the gradient coordinate transformation required to
correctly draw gradient fills. This was especially noticeable when
scaling down an SVG, resulting in broken gradient coordinates and
graphical glitches.

This changes the objectBoundingBox units to immediately map to the
bounding box's coordinate system, so we can unify the gradient paint
transformation logic and make it a lot simpler. We only need to undo the
bounding box offset and apply the paint transformation to fix a lot of
gradient fill bugs.
2025-10-27 16:42:27 -07:00
Jelle Raaijmakers
beb1d60714 LibWeb: Simplify calculation of the SVG viewbox transform
We don't need to construct a new AffineTransform and multiply that by
yet another AffineTransform; we can simply translate and scale the
transform that's already in place. No functional changes.
2025-10-27 16:42:27 -07:00
Jelle Raaijmakers
6f50c35d68 LibWeb: Misc. cleanup of code
Some things I came across while working on a bugfix. No functional
changes.
2025-10-27 16:42:27 -07:00
Jelle Raaijmakers
e4de6c0d05 LibWeb: Return early if scroll offset is zero
No need to calculate scroll offsets and translate update list commands
if the cumulative offset was zero to begin with.
2025-10-27 16:42:27 -07:00
Jelle Raaijmakers
c0d08b68af LibWeb: Dump path_bounding_rect for FillPath
This makes it easier to differentiate between FillPath commands in the
display list output.
2025-10-27 16:42:27 -07:00
Tim Ledbetter
e1ff1e2095 LibWeb: Implement CanvasPattern.setTransform()
This method applies the given transformation matrix to a pattern.
2025-10-27 16:41:02 -07:00
Andreas Kling
9312a9f86f LibJS: Move InstantiateOrdinaryFunctionExpression into interpreter
This is execution time stuff and doesn't belong in the AST.
2025-10-27 21:14:33 +01:00
Andreas Kling
44fa9566a8 LibJS: Generate bytecode for the BlockDeclarationInstantiation AO
This necessitated adding some new instructions for creating mutable and
immutable bindings.
2025-10-27 21:14:33 +01:00
Andreas Kling
892c7d980e LibJS: Let JS::Script remember whether its code is strict mode
We don't want to rely on having the AST node just to answer the question
"is this script strict mode?"
2025-10-27 21:14:33 +01:00
Andreas Kling
b712caf855 LibJS: Move bytecode executable cache to SharedFunctionInstanceData
This shrinks every Statement and ECMAScriptFunctionObject by one
pointer, and puts the bytecode cache in the only place that actually
makes use of it anyway: functions.
2025-10-27 21:14:33 +01:00
Andreas Kling
3a38040c82 LibJS: Make SharedFunctionInstanceData GC-allocated 2025-10-27 21:14:33 +01:00
Tete17
b77f658c83 LibWeb: Add a bunch of new passing WPT tests 2025-10-27 16:14:20 +00:00
Tete17
c591f8c14f LibWeb: Amend DomParser to make it compatible with TrustedTypes 2025-10-27 16:14:20 +00:00
Tete17
33285467a8 LibWeb: Amend ShadowRoot to make it compatible with TrustedTypes 2025-10-27 16:14:20 +00:00