Repository navigation
Description
On Android TV, direct play of a high-bitrate file buffers far less video than the player asks for, and those plays stall more often. The limit is memory. I'd like to buffer ahead on disk instead, and I'd like other developers to tell me whether that is the right approach before anyone writes it.
What happens today
PlaybackBufferPolicy asks for 180 s of forward buffer. SiloLoadControl turns that into a byte target and clamps it to half the app heap (memoryClass / 2), capped at 192 MiB. Media3 keeps that buffer in the Java heap.
At low bitrates, the time target is what binds. At high bitrates, the byte cap does:
| Heap budget | Seconds buffered at 20 Mbps | At 35 Mbps |
|---|---|---|
96 MiB (Shield: memoryClass 192) |
~40 s | ~23 s |
192 MiB (Google TV Streamer: memoryClass 384) |
~80 s | ~46 s |
| 24 MiB (low-RAM fallback) | ~10 s | ~6 s |
Any network dip longer than the buffer becomes a visible stall.
What we measured on a production server
We estimated each client's buffer from the server side, as bytes delivered minus media time played, and counted stalls of 15 s or longer. This covers direct play over a couple of weeks.
- Under 12 Mbps: Android TV devices hold about 200–260 s ahead, which matches the 180 s target plus the load-control idle window.
- 12–25 Mbps: the same devices hold about 40 s. The stall rate rose about 2–4× on a Shield and a Fire TV 4K stick, and much more on some cheaper boxes.
- Apple TV: in the same 12–25 Mbps band its buffer is much deeper, and its stall rate stays close to its low-bitrate rate.
- Above about 25 Mbps: every client stalls, Apple included. The link itself can't keep up there, so a bigger buffer won't fix that range.
- One connection is enough. On the stalling plays, a single connection usually reached 1.2–7× the file's bitrate at some point. So the stalls come from dips that outlast the buffer, not from a per-connection speed limit, and opening more connections wouldn't help.
There are two caveats. Far fewer high-bitrate plays were sampled than low-bitrate ones, because the server transcodes many of them, so treat the 12–25 Mbps numbers as a direction rather than proof. And the app doesn't report memoryClass to the server, so the heap sizes come from device model, not from measurement.
Proposal
For direct play (progressive, not HLS) where the byte cap would leave the buffer well under the 180 s target, run a read-ahead to disk:
- A
SimpleCachein the app's cache dir, with an LRU evictor sized from free space. - The player reads through
CacheDataSource, so it reads from disk whenever the range is already cached. - A background writer (
CacheWriteror similar) fetches the range ahead of the playhead on its own connection, up to roughly the 180 s target. On a seek it restarts at the new position. When playback stops, it stops. - The in-heap Media3 buffer stays at its current size. The disk holds the rest.
CacheDataSource on its own only caches what the player already read, so the separate writer is the part that adds buffer depth.
Questions for reviewers
- Is a disk read-ahead the right tool here? Or should we first try something cheaper, such as
android:largeHeap="true"? The app doesn't set it today. On many TV deviceslargeMemoryClassis several timesmemoryClass, which might be enough for 12–25 Mbps, though it trades away memory headroom and GC behaviour. - Storage: many sticks ship with 8 GB of eMMC and little free space. Three minutes at 25 Mbps is about 560 MB. What floor and ceiling should the cache use, and should we skip the read-ahead below some free-space threshold?
- Flash wear and I/O speed: cheap eMMC can be slow and wears with repeated writes. Is writing a few hundred MB per film acceptable? Can a slow disk end up stalling playback?
- Interaction with existing behaviour: retries (
MediaLoadRetryPolicy), the 15 s load-idle window that keeps proxies from closing idle connections, stream-token refresh, and replans that change the URL mid-play. - Server side: the server already accepts parallel range requests for one session. Does anyone see a reason the second connection would cause trouble with reverse proxies or CDNs that meter requests?
- Anything already in Media3 that does this and that we should use instead?
If this direction holds up, the server side can then let more 12–25 Mbps files play without transcoding on Android TV.
Activity
feardubin commentedon Nov 10, 2026
Adding field data from a production server in support of this, plus a request about the Dolby Vision halving in
playbackBufferBudgetBytes.What we see
Direct-play sessions (>60 s played) since 2026-11-01, from
plan_summaryroute events:Stalls on Android TV happen at all hours, including sessions where the bandwidth estimate was 164–289 Mbit/s. Typical stalls are 1–8 s each, several per episode.
Why
SiloLoadControlcaps the forward buffer atmemoryClass / 2(max 192 MiB) andplaybackBufferBudgetByteshalves it again for Dolby Vision. For a typical 4K DV remux (~64 Mbit/s average), that is roughly 6–13 s of media on 192–384 MB heaps, against a 180 sMAX_DEPTH_MStarget. Remux bitrate is far from flat. One episode we measured from its MKV cues averages 63.6 Mbit/s, but its worst 10 s window is 105 Mbit/s, its worst 30 s window is 99 Mbit/s, and a third of all 10 s windows exceed 70 Mbit/s.So any upstream hiccup longer than a few seconds becomes a visible stall. We caught one live: the origin's storage read for one stream hung for ~45 s while every other stream and the network path were healthy. The player had 13–24 s buffered and stalled for 33 s. With a buffer of a minute or more, as other clients effectively have, short storage or network hiccups would be invisible.
Asks
target_bytes/depth_msin the diagnostics bundle. Right now they only go to logcat, so admins can't see them.Happy to provide more data if useful.
weswhet commentedon Nov 13, 2026
On an NVIDIA Shield, setting
android:largeHeap="true"and removing the Dolby Vision halving stopped the stalls in a high-bitrate Dolby Vision remux. The stock app stalled repeatedly with about 4 seconds of buffer. The test build played about 50 minutes with no stalls, held 13–26 seconds of buffer, and stayed well within the larger heap. @Quick104, this result bears on the halving inplaybackBufferBudgetBytes, and it answers question 1 in this issue for one device.Test setup
client_dv7_to_dv81transformation.android:largeHeap="true"in the TV manifest.Runtime.getRuntime().maxMemory()instead ofActivityManager.memoryClass. The stock code readsmemoryClass, which doesn't change withlargeHeap, so the manifest change alone doesn't raise the budget.Results
target_bytes/budget_bytesbuffering_quality event=waiting cause=networkOutOfMemoryErrorWhy the network isn't the cause
Suggestions
playbackBufferBudgetBytescites a 96 MiB target that exhausted a 192 MiB heap during a Dolby Vision profile 5 stream. In this test, a 138 MiB target in a 512 MiB heap left more than 300 MiB free. The risk appears to depend on the buffer's share of the heap rather than on Dolby Vision itself. Applying the halving only on small heaps, or not at all whenlargeHeapis set, keeps the original protection where it's needed.target_bytesstayed at 138 MiB of a 256 MiB budget becauseselectBufferSizingBitrateBpsuses the file's bitrate metadata, which appears to understate this remux.target_bytes,budget_bytes, and the buffered-ahead time in the diagnostics bundle; today they appear only in logcat. In the test build, I added them as live rows on the player's Stats tab, which made the results easy to check on the device.Unrelated finding
Seeking to the last few seconds of the file logged
failure=dv7_transform_stalland quarantinedclient_dv7_to_dv81for the rest of the session. This looks like end-of-stream handling rather than an actual transformation stall.Limitations
These results come from one device and one title. They support trying
largeHeapfirst but don't prove it's safe on every device. I can run a specific variant on the same Shield and title if that helps.