Skip to content

perf(playback): size the AudioTrack buffer for the speed in use - #750

Merged
Sahank29 merged 2 commits into
mainfrom
perf/audio-start-buffer
Nov 25, 2026
Merged

Sahank29 merged 2 commits into
mainfrom
perf/audio-start-buffer

Conversation

@Sahank29

Copy link
Copy Markdown
Contributor

Media3 sizes the AudioTrack for 8x speed when playback params are on: 2.6 s (6 s on Bluetooth). Android stays silent until that buffer is full, so every start and skip sat 600-800 ms after READY.

Size the buffer for the current speed (320 ms at 1x). The automix-standby-only override is removed since it's now the default.

Tested on OnePlus Pad 2, Fast start:

  • READY to audio: 600-800 ms -> ~180 ms
  • cold tap to first audio: 2.1-2.2 s -> 1.7 s
  • skip: 0.3-0.5 s
  • no underruns

Not tested: Bluetooth, USB DAC, changing speed above 1x mid-song.

Media3 sizes the AudioTrack for 8x speed once playback params are on
(2.6 s, 6 s over Bluetooth), and a normal AudioTrack stays silent until
that buffer is full. Every start and skip waited 600-800 ms after READY.
Size it for the current speed instead; the standby-only override is gone.
The 1 MiB probe past the first MiB ran before every first audio and took
0.25-2 s on songs the googlevideo edge hasn't cached. Playback resolves
now return the first candidate and probe 5 s later, once the player has
its first bytes (overlapping, the probe doubled the player's first-byte
time). A failed probe cools the client down so the player's retry, which
resumes at the same position, gets a fresh URL. Downloads and the
mid-stream URL refresh still probe before use.
@Sahank29

Copy link
Copy Markdown
Contributor Author

Added df68713: the 1 MiB stream probe no longer blocks first audio.

The probe reads 1 MiB past the first MiB before playing. On songs the googlevideo edge hasn't cached that took 0.25-2 s per tap. Playback now starts on the resolved URL and probes 5 s later; a failed probe cools that client down so the existing retry (resumes at the same position) picks a fresh URL. Downloads and the mid-stream URL refresh still probe first.

OnePlus Pad 2, in-app search taps:

  • stream resolve: 1.25-2.4 s -> 0.35-0.73 s
  • tap to sound, top result: 0.54-0.62 s (YT Music: 0.67-0.79 s)
  • tap to sound, lower rows: ~1.5-1.9 s (was 1.8-3.0 s)
  • ~30 starts, 0 player errors, all deferred probes valid

Not tested: downloads, a real bad-URL recovery.

@Sahank29
Sahank29 merged commit 1746018 into main Nov 25, 2026
2 checks passed
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