Skip to content

Make the media player API more statefull#467

Merged
jdm merged 1 commit intoservo:mainfrom
tharkum:gst-play-set-rate-validation
Dec 4, 2025
Merged

Make the media player API more statefull#467
jdm merged 1 commit intoservo:mainfrom
tharkum:gst-play-set-rate-validation

Conversation

@tharkum
Copy link
Copy Markdown
Contributor

@tharkum tharkum commented Nov 19, 2025

New media player APIs (paused, playback_rate, volume) were added to track the current associated state to
reduce overhead of the media backend state changes.

The setter methods will return Result<T, PlayerError> while the getter methods - T (default value on media error).

Note that handling the playback rate change it quite tricky for gsteamer backend (need to wait until GST_STATE_PAUSED).

The gst_play_set_rate function not only sets the playback rate property in GstPlay but also creates a new seek request with the current position, then fires seek done event afterwards and changes the state to PlayState::Paused.

There are client application requirement to send PlayerEvent::Paused event after receiving the initial metadata, so the send_paused_event workaround has been added to the gstreamer backend for other cases.
servo/servo#40740

@tharkum tharkum force-pushed the gst-play-set-rate-validation branch from 989137e to 647fefa Compare November 20, 2025 05:49
@tharkum tharkum changed the title Set playback rate with validation gst: Set playback rate with validation Nov 20, 2025
@tharkum
Copy link
Copy Markdown
Contributor Author

tharkum commented Nov 20, 2025

@jdm , @sdroege < Please take a look.

@tharkum tharkum changed the title gst: Set playback rate with validation gst: Set the playback rate with validation Nov 20, 2025
New media player APIs (`paused`, `playback_rate`, `volume`)
were added to track the current associated state to
reduce overhead of the media backend state changes.

The `setter` methods will return `Result<T, PlayerError>`
while the `getter` methods - T (default value on media error).

Note that handling the playback rate change it quite tricky
for gsteamer backend (need to wait until GST_STATE_PAUSED).

The `gst_play_set_rate` function not only sets the playback rate
property in GstPlay but also creates a new `seek` request with
the current position, then fires `seek done` event afterwards and
changes the state to `PlayState::Paused`.

There are client application requrement to send `PlayerEvent::Paused`
event after receiving the initial metadata, so the `send_paused_event`
workaround has been added to the gstreamer backend for other cases.
servo/servo#40740

Signed-off-by: Andrei Volykhin <[email protected]>
@tharkum tharkum force-pushed the gst-play-set-rate-validation branch from 647fefa to 9964323 Compare December 3, 2025 07:56
@tharkum tharkum changed the title gst: Set the playback rate with validation Make the media player API more statefull Dec 3, 2025
@tharkum tharkum requested a review from jdm December 3, 2025 07:58
@tharkum
Copy link
Copy Markdown
Contributor Author

tharkum commented Dec 3, 2025

Applied more global changes for the media player instead of just for the playback_rate property

tharkum added a commit to tharkum/servo that referenced this pull request Dec 3, 2025
It's important to check the media player's `paused` state to avoid
unnecessary changes to its internal state (via `play`, `pause`),
including configuration the `playback rate` and `volume` properties.

Depends on servo/media#467

Testing: The expected test results are unchanged because it is the
implicit performance improvements of the media stack, with the
exception of the following test, which is affected by the
`playback rate` state caching mechanism (the `seek` position is
not overridden for default playback rate (1.0)).
- html/semantics/embedded-content/media-elements/preserves-pitch.html

See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/4762

Signed-off-by: Andrei Volykhin <[email protected]>
tharkum added a commit to tharkum/servo that referenced this pull request Dec 3, 2025
It's important to check the media player's `paused` state to avoid
unnecessary changes to its internal state (via `play`, `pause`),
including configuration the `playback rate` and `volume` properties.

Depends on servo/media#467

Testing: The expected test results are unchanged because it is the
implicit performance improvements of the media stack, with the
exception of the following test, which is affected by the
`playback rate` state caching mechanism (the `seek` position is
not overridden for default playback rate (1.0)).
- html/semantics/embedded-content/media-elements/preserves-pitch.html

See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/4762

Signed-off-by: Andrei Volykhin <[email protected]>
@jdm jdm added this pull request to the merge queue Dec 4, 2025
Merged via the queue into servo:main with commit b0d3b74 Dec 4, 2025
3 checks passed
@tharkum tharkum deleted the gst-play-set-rate-validation branch December 4, 2025 05:48
tharkum added a commit to tharkum/servo that referenced this pull request Dec 4, 2025
It's important to check the media player's `paused` state to avoid
unnecessary changes to its internal state (via `play`, `pause`),
including configuration the `playback rate` and `volume` properties.

Depends on servo/media#467

Testing: The expected test results are unchanged because it is the
implicit performance improvements of the media stack, with the
exception of the following test, which is affected by the
`playback rate` state caching mechanism (the `seek` position is
not overridden for default playback rate (1.0)).
- html/semantics/embedded-content/media-elements/preserves-pitch.html

See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/4762

Signed-off-by: Andrei Volykhin <[email protected]>
tharkum added a commit to tharkum/servo that referenced this pull request Dec 4, 2025
It's important to check the media player's `paused` state to avoid
unnecessary changes to its internal state (via `play`, `pause`),
including configuration the `playback rate` and `volume` properties.

Depends on servo/media#467

Testing: The expected test results are unchanged because it is the
implicit performance improvements of the media stack, with the
exception of the following test, which is affected by the
`playback rate` state caching mechanism (the `seek` position is
not overridden for default playback rate (1.0)).
- html/semantics/embedded-content/media-elements/preserves-pitch.html

See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/4762

Signed-off-by: Andrei Volykhin <[email protected]>
github-merge-queue bot pushed a commit to servo/servo that referenced this pull request Dec 4, 2025
…ite (#41027)

It's important to check the media player's `paused` state to avoid
unnecessary changes to its internal state (via `play`, `pause`),
including configuration the `playback rate` and `volume` properties.

Depends on servo/media#467

Testing: The expected test results are unchanged because it is the
implicit performance improvements of the media stack, with the exception
of the following test, which is affected by the `playback rate` state
caching mechanism (the `seek` position is not overridden for default
playback rate (1.0)).
- html/semantics/embedded-content/media-elements/preserves-pitch.html

See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/4762

Signed-off-by: Andrei Volykhin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants