You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[proposal] Android TV direct play: use bounded range requests so proxy reloads and idle timeouts stop interrupting playback
#980
On Android TV, progressive direct play reads the whole file through one open-ended HTTP request. That request stays open for the whole movie, including every time the player stops reading because its buffer is full. Any reverse proxy that closes a response which has been idle for a while, or that kills old workers after a config reload, cuts it in the middle.
The Apple apps don't have this problem behind the same proxy: they ask for 32 MiB ranges, each one finishes in about a second, and between two ranges there is nothing open to cut.
PR #99 and PR #147 already handle part of this (ranged resume, and a 15 s idle window that assumes a send_timeout of at least 60 s). This proposal goes one step further so the app no longer depends on proxy settings at all.
What we see
Setup: Silo server in Docker behind BunkerWeb 1.6.17 (nginx), HTTP/2 to clients, proxy_buffering off. Android TV app 1.2.0 (31). Server 247fec91 (self-built, with an unrelated patch).
Same proxy, last 72 hours:
App
Stream requests
Size per request
Apple (CFNetwork)
1185
32 MiB max
Browser
25
20 MB max
Android TV (okhttp)
a few long open-ended ranges per playback
up to 117 MB in that window; one request on 16/11 stayed open 1157 s and sent 1.6 GB
Case 1, idle timeout (fixed on our side, shown for the retry behaviour). TCL Smart TV Pro, Android 14, H.264 + AC3 direct play at about 8 Mbps. Our send_timeout was 10 s, below the 15 s idle window from PR #147:
18:36:36.975 progressive direct-play retry error=A: stream was reset: PROTOCOL_ERROR bytes_loaded=117565291 resume_offset=117571773 attempt=1 retry_delay_ms=1000
18:37:05.056 progressive direct-play retry error=A: stream was reset: PROTOCOL_ERROR bytes_loaded=25169967 resume_offset=142643525 attempt=2 retry_delay_ms=2000
18:38:51.743 progressive direct-play retry exhausted error=A: stream was reset: PROTOCOL_ERROR bytes_loaded=109054805 resume_offset=251698330 attempt=2
18:40:48.942 E playback player error
The proxy logged exactly the same byte counts (117467076, 25169967, 109054805) and the server logged direct stream ended outcome=client_gone. We raised send_timeout to 60 s for Silo and this stopped. The retry still gave up at attempt 2 even though 25 MB and then 109 MB had been loaded between the resets.
Case 2, proxy reload (still happening). Freebox Player POP, Android 10, Wi-Fi, H.264 + E-AC-3 5.1 direct play at about 11 Mbps. BunkerWeb reloads nginx about once an hour when its IP blacklists change. The old workers get 30 s to finish (worker_shutdown_timeout 30s) and are then killed: here the reload started at 23:11:49 and the old workers were killed at 23:14:59. At that moment every connection still open on the old workers is closed. Server log (local time):
The user saw a short buffering spinner there. Progress reports kept arriving every 10 s, so playback did not stop. The app did not just resume the media request at its byte offset: after the sockets dropped it read the watch state again and reopened the file from the start (no Range) and from the tail, like a fresh prepare. I could not check whether the 1157 s media request was cut by the reload itself or closed by the app afterwards, and we have no client report covering that minute.
Proposed change
1. Bounded range requests for progressive original-file playback
Wrap the existing authenticated data source so that every HTTP request asks for a fixed window instead of an open-ended range:
Request Range: bytes=P-(P+N-1) with N fixed, for example 16 MiB.
Read that response to the end, then open the next range at exactly P+N. Media3 still sees one continuous DataSource, so the extractor and load control don't change.
Open a range only when the buffer has room for the whole range, so the player never has to stop reading in the middle of one. That is why 16 MiB fits better than 32 MiB here: it fits the smallest buffer budgets on low-RAM TVs, and it finishes faster on slow links.
When the load control stops loading because the buffer is full, don't open the next range. No response is left open while the player is idle, so nothing can time out or be killed by a reload.
Never ask for bytes already received: the next range starts where the previous one ended. This avoids the overlap described for Apple in silo-apple#824.
Reuse the HTTP/2 connection, so a new range costs one request, not a new TLS handshake.
At 16 MiB a range takes about 1 to 2 s on a 80 to 100 Mbps link, so even a proxy with a short timeout never sees a long idle response.
2. Don't restart the player when the realtime sockets reconnect
When the events or playback control WebSocket closes, reconnect it in the background and leave the player alone. A media load that was cut at the same time should go through the normal ranged resume, not through a new prepare that throws away the buffer.
3. Reset the retry budget after real progress
If a retry loads new bytes before the next failure, start the retry count and the 90 s window again. In case 1 the stream was cut three times in about two minutes and the app gave up, even though it had loaded 25 MB and then 109 MB between the cuts.
Security
None of this needs a server change or a new endpoint, and none of it weakens the current checks:
Each range uses the same signed stream URL, session and TLS as today.
Keep If-Range with the ETag on every range. If the server answers 200 instead of 206, the file changed: take the existing entity-changed path instead of joining two different files.
I searched open and closed issues and PRs in Silo-Server for "PROTOCOL_ERROR", "stream was reset", "send_timeout", "retry exhausted", "progressive direct play", "chunked range", "bounded range requests", "nginx reload" and "32 MiB range" and found nothing asking for bounded ranges on Android.
Logs analysed and text drafted with an AI coding assistant; all numbers come from my own server and were checked.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Problem
On Android TV, progressive direct play reads the whole file through one open-ended HTTP request. That request stays open for the whole movie, including every time the player stops reading because its buffer is full. Any reverse proxy that closes a response which has been idle for a while, or that kills old workers after a config reload, cuts it in the middle.
The Apple apps don't have this problem behind the same proxy: they ask for 32 MiB ranges, each one finishes in about a second, and between two ranges there is nothing open to cut.
PR #99 and PR #147 already handle part of this (ranged resume, and a 15 s idle window that assumes a
send_timeoutof at least 60 s). This proposal goes one step further so the app no longer depends on proxy settings at all.What we see
Setup: Silo server in Docker behind BunkerWeb 1.6.17 (nginx), HTTP/2 to clients,
proxy_buffering off. Android TV app 1.2.0 (31). Server247fec91(self-built, with an unrelated patch).Same proxy, last 72 hours:
Case 1, idle timeout (fixed on our side, shown for the retry behaviour). TCL Smart TV Pro, Android 14, H.264 + AC3 direct play at about 8 Mbps. Our
send_timeoutwas 10 s, below the 15 s idle window from PR #147:The proxy logged exactly the same byte counts (117467076, 25169967, 109054805) and the server logged
direct stream ended outcome=client_gone. We raisedsend_timeoutto 60 s for Silo and this stopped. The retry still gave up at attempt 2 even though 25 MB and then 109 MB had been loaded between the resets.Case 2, proxy reload (still happening). Freebox Player POP, Android 10, Wi-Fi, H.264 + E-AC-3 5.1 direct play at about 11 Mbps. BunkerWeb reloads nginx about once an hour when its IP blacklists change. The old workers get 30 s to finish (
worker_shutdown_timeout 30s) and are then killed: here the reload started at 23:11:49 and the old workers were killed at 23:14:59. At that moment every connection still open on the old workers is closed. Server log (local time):The user saw a short buffering spinner there. Progress reports kept arriving every 10 s, so playback did not stop. The app did not just resume the media request at its byte offset: after the sockets dropped it read the watch state again and reopened the file from the start (no
Range) and from the tail, like a freshprepare. I could not check whether the 1157 s media request was cut by the reload itself or closed by the app afterwards, and we have no client report covering that minute.Proposed change
1. Bounded range requests for progressive original-file playback
Wrap the existing authenticated data source so that every HTTP request asks for a fixed window instead of an open-ended range:
Range: bytes=P-(P+N-1)with N fixed, for example 16 MiB.P+N. Media3 still sees one continuousDataSource, so the extractor and load control don't change.At 16 MiB a range takes about 1 to 2 s on a 80 to 100 Mbps link, so even a proxy with a short timeout never sees a long idle response.
2. Don't restart the player when the realtime sockets reconnect
When the events or playback control WebSocket closes, reconnect it in the background and leave the player alone. A media load that was cut at the same time should go through the normal ranged resume, not through a new
preparethat throws away the buffer.3. Reset the retry budget after real progress
If a retry loads new bytes before the next failure, start the retry count and the 90 s window again. In case 1 the stream was cut three times in about two minutes and the app gave up, even though it had loaded 25 MB and then 109 MB between the cuts.
Security
None of this needs a server change or a new endpoint, and none of it weakens the current checks:
If-Rangewith the ETag on every range. If the server answers 200 instead of 206, the file changed: take the existing entity-changed path instead of joining two different files.Related
I searched open and closed issues and PRs in Silo-Server for "PROTOCOL_ERROR", "stream was reset", "send_timeout", "retry exhausted", "progressive direct play", "chunked range", "bounded range requests", "nginx reload" and "32 MiB range" and found nothing asking for bounded ranges on Android.
Logs analysed and text drafted with an AI coding assistant; all numbers come from my own server and were checked.
All reactions