Skip to content

player: playback speed (0.5x-2x), done in the app - #805

Merged
GLinnik21 merged 10 commits into
plxnative:mainfrom
dimitrije83:speed-pr
Oct 24, 2026
Merged

GLinnik21 merged 10 commits into
plxnative:mainfrom
dimitrije83:speed-pr

Conversation

@dimitrije83

Copy link
Copy Markdown
Contributor

Adds a Playback speed row to the player's … menu, with Plex Web's speeds: 0.5×, 0.75×, Normal, 1.25×, 1.5×, 1.75× and 2×.

Why it's done in the app, not with LG's SetPlayRate

StarfishMediaAPIs::SetPlayRate exists on firmware 1.2–11.2, but it can't drive the buffer-feed pipeline. I tried it on webOS 3.9.3:

  • Set at load: it returns 1, but the source's next SEGMENT event resets it to 1×. CustomPipeline::sendSegmentEvent hard-codes rate 1.0.
  • Set mid-play: about half a second of sped-up video, then a permanent freeze. It ends in gst_element_seek(rate, FLUSH|KEY_UNIT, …) against our appsrc.
  • Off 1×, libpf mutes the audio (setAudioForTrickPlay).

So the speed is done the way a browser does it:

  • Timestamps. Every timestamp sent to the pipeline is divided by the speed (player::to_sink_ns), and every presented one is multiplied back. The pipeline plays at its own 1×, the app stays in film time, and the Load declares the frame rate it is actually fed.
  • Audio. The Load declares PCM (contents.pcmInfo). Note that sampleRate is in kHz: libpf matches 48, not 48000, and 48000 falls back to 44.1 with drift. ff::SpeedDecoder decodes the audio with the bundled FFmpeg (audio decoders added to ci/build-ffmpeg.sh). speed_audio then downmixes to stereo, resamples to 48 kHz, and time-stretches with WSOLA so the pitch is kept. Audio is stereo while sped up.
  • Applying a change. The speed is fixed per Load, so changing it reloads at the viewer's position.

Where the row is offered

The row appears only where the playback can play the speed: not for segmented HLS, not for previews, only when the audio is decodable, and only speeds that keep the fed rate at or under 60 fps.

A safety net reloads at 1× and turns speed off for the session in two cases: the pipeline's audio report isn't the declared 48 kHz stereo, or no report arrives within 8 s of loadCompleted.

Stats for nerds gets a speed suffix on the Audio row, for example speed 1.5x pcm 48 khz stereo ok.

Tested

  • TV: on an LG OLED55B7V-Z, webOS 3.9.3 only, with E-AC-3 film content at 0.5×–2×. At 1.5× the TV reported audio/x-raw 48 kHz x2 -> ok, and the Audio row read speed 1.5x pcm 48 khz stereo ok. At 0.5×, 24p film shows 12 fps, which is inherent.
  • Checks: make check passes (16,390 tests, 0 failed), and so does cargo +nightly check --lib --no-default-features.

Translations

The be, fr, es and it strings (2 each) are my drafts, not reviewed by a native speaker. Per CONTRIBUTING, hold them until someone reviews them, or drop them and let those locales fall back to English.

dimitrije83 and others added 3 commits October 15, 2026 22:40
A Playback speed row in the … menu, onto Plex Web's speeds, offered only
where the playback can play them (not segmented HLS, not a preview, the
audio decodable, never more than 60 fps fed). A speed is fixed per Load;
a change reloads at the viewer's position.

LG's SetPlayRate cannot drive the buffer-feed pipeline (tried on 3.9.3:
reset to 1x by the source's next SEGMENT when set at load, a permanent
freeze when set mid-play, and libpf mutes audio off 1x), so the speed is
done the way a browser does it:

- every timestamp crossing to the pipeline is divided by the speed
  (player::to_sink_ns) and every presented one multiplied back, so the
  pipeline plays at its own 1x and the app stays in film time; the Load
  declares the fed frame rate;
- the Load declares PCM (contents.pcmInfo; sampleRate is kHz, libpf
  matches 48 not 48000), ff::SpeedDecoder decodes the audio with the
  bundled FFmpeg (audio decoders added to ci/build-ffmpeg.sh), and
  speed_audio downmixes to stereo, resamples to 48 kHz and WSOLA
  time-stretches it with pitch preserved;
- a safety net reloads at 1x and turns speed off if the pipeline's audio
  report is not the declared 48 kHz stereo, or never arrives.

Verified on an OLED55B7V-Z (webOS 3.9.3) only.

Signed-off-by: Dimitrije Juras <[email protected]>
@GLinnik21

Copy link
Copy Markdown
Collaborator

Sorry for the delay. I want to keep this feature for the next release, so I'll get back to this PR after the 0.9.0 release

GLinnik21 and others added 6 commits October 24, 2026 19:37
Conflicts resolved: both sides' catalog entries kept (list-caps, widgets locales; it
follows main's flat format, de/hu/pt gain the speed rows); the More menu root keeps the
Quality readout and the Playback speed row; the speed audio push goes through main's
audio_push_gate.
…ured decoder row can be fed

The noaudio trigger was a stat(2) per call at three sites (speed_offer every frame while the
More menu is open, the pump's speed check every tick, the Load): one latched flag now.

speed_offer filtered by a flat 60.5 fps, but the Load clamps the declared rate to the device's
measured decoder row, so on a 4K@30 H.264 set a 24p stream at 1.5x was offered and fed at
36 fps. The ceiling now comes from the same row (decoder_row, shared with sink_envelope).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@GLinnik21
GLinnik21 enabled auto-merge (squash) October 24, 2026 18:42
@GLinnik21
GLinnik21 disabled auto-merge October 24, 2026 18:45
@GLinnik21
GLinnik21 enabled auto-merge (squash) October 24, 2026 18:45

@GLinnik21 GLinnik21 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on our 4.5 set: 0.5x-2x played at the right rate on E-AC-3, DTS, AAC and 4K H.264, seek/pause/EOS fine. I merged main and pushed small fixes to your branch: noaudio latched, the speed offer follows the measured decoder row, the nits, plus speed strings for the new de/hu/pt locales. Main ask is the reload going through the route controller.

if !is_started() {
return true; // nothing on screen: the next Load applies it
}
SHARED.rate_reload.store(true, Relaxed);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this use request_user_route_intent like the audio switch? The stuck-seek retry at pump.rs:1632 can eat this seek.

let offer = speed_offer(ps);
let rate = session_rate(want, &offer);
if rate != want {
SHARED.play_rate_permille.store(RATE_NORMAL, Relaxed);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather not overwrite the viewer's pick here. Show the applied rate instead?

/// so every timestamp the app hands it — a fed AU, a seek or decode position — is divided by `r`;
/// the frames then arrive `r` times closer together and the picture runs `r` times faster.
/// Identity at 1x, which is every playback that has not picked a speed.
pub fn to_sink_ns(ns: i64) -> i64 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the sink seam own the rate instead of 5 call sites + a global?

}

/// Content time of output frame `n`: each output frame stands for `speed` input frames.
fn content_pts(&self, n: u64) -> i64 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pts_ns is ignored after the first push, so a gap drifts until the next seek. Re-anchor?

static FORCE_SPEED_DECODER: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
#[cfg(any(test, feature = "test-support"))]
pub fn force_speed_decoder_for_test(on: bool) {
FORCE_SPEED_DECODER.store(on, Ordering::Relaxed);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set in ~30 tests, reset in one, so order-dependent. Pass the offer to the menu as a value?

@GLinnik21
GLinnik21 merged commit 4a551d0 into plxnative:main Oct 24, 2026
13 checks passed
GLinnik21 added a commit that referenced this pull request Oct 24, 2026
Brings in #805 (player playback speed); no file it touches is one this lane
changed.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
paulorichards added a commit to paulorichards/plx-native that referenced this pull request Oct 25, 2026
libpf matches pcmInfo.sampleRate against a kilohertz table (plxnative#805). The
FLAC node stated hertz, so every FLAC played at the 44.1 kHz fallback:
on an OLED55B8 (webOS 4.4.3) a 1 kHz tone came back at 918.8 Hz from a
48 kHz file, 1378 Hz from 32 kHz and about 2006 Hz from 22.05 kHz.
Declared in kHz, all four rates play at 1000 Hz and the pipeline reports
the declared rate.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BNxR112kqmb5uZjUzXgND1
Signed-off-by: Paulo Richards <[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