Skip to content

perf(sabr): hand segments to the player as soon as they arrive - #124

Open
Priveetee wants to merge 1 commit into
InfinityLoop1308:devfrom
Priveetee:perf/sabr-early-segment-handoff
Open

Priveetee wants to merge 1 commit into
InfinityLoop1308:devfrom
Priveetee:perf/sabr-early-segment-handoff

Conversation

@Priveetee

Copy link
Copy Markdown
Contributor

A SABR response carries about 20 s of audio and video (2 to 2.6 MB at 720p). The caller that sends the request waits for all of it: the media source is only created once the whole first response is read, and after a seek the player gets its first segment when the last one has arrived. On a good connection nobody notices, on a slow one it's the wait for 2.5 MB before the first frame.

Now the request runs on its own thread in SabrMediaBridge. Callers wait for what they asked for (the timelines, or one segment) and return as soon as it is there, while the rest of the response keeps streaming into the cache. Waiting callers are woken up instead of retrying every 100 ms.

A request is stopped when the caller it was started for is cancelled and nobody else waits, or when a segment is asked that it can't carry, so a seek still interrupts the response it makes useless, like before.

Validation, warm start of the same video:

  • slow connection: first frame after 17.3 / 17.6 s on dev, 5.0 / 5.9 s with this.
  • normal connection: 2.3 to 3.4 s against 2.9 to 5.0 s.
  • on a Pixel 8 (Android 17), together with my other pending changes: slow connection 8.7 / 9.2 s against 19.0 / 23.6 s, normal connection 4.7 to 4.9 s against 3.8 to 5.2 s.
  • single seek, 4 seeks 3 s apart, playback at 2x and resume from a saved position still work. I broke seeking twice while writing this (the audio and video loaders cancelling each other's request, and a request cancelled while still queued), it was a pain in the ass to track down. Both are fixed and I replayed the seek scenarios after that, slow and normal.
  • then a rougher pass on 7 videos from 18 s to 43 min (720p VP9 and AVC, one with dubbed audio): seeks to the middle, the end and the start, 8 seeks 1 s apart, 2x, pause, seek while paused, then play to the end. No error, no crash, every video reaches its end. The only long stalls (9 and 12 s) were refused PO tokens, and dev does the same on the same video (7.9 s).
  • quality change 720p to 360p, background player, two live streams, and switching the audio track to French then seeking: all fine. Captions not checked.

A SABR response carries about twenty seconds of audio and video, and
the caller that sent the request waited for all of it: the media source
was only created once the whole first response had been read, and after
a seek the player got its first segment when the last one had arrived.
On a slow connection that is the wait for a couple of megabytes before
the first frame.

Requests now run on their own thread. Callers wait for what they asked
for, the timelines or one segment, and return as soon as it is there
while the rest of the response keeps streaming into the cache. Waiting
callers are woken up instead of polling every 100 ms.

A request is stopped when the caller it was started for is cancelled
and nobody else waits, or when a segment is asked that it cannot carry,
so a seek still interrupts the response it makes useless.
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.

1 participant