Close DataSource after some idle time (to avoid long-running connections for progressive media loads)
@tonihei is already working on this.
Since Oct 17, 2022.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 955
- Avg merge
- 12d 14h
- Merged PRs (30d)
- 2
Description
HttpDataSource remains open even after buffering the first 50 seconds, so it can be reused.
This works for mobile, but on Wear OS 3 devices the network connection might be requested from Wifi or Cell, and keeping the connection open drains battery. Instead the connection should be used for 5-10 seconds and then released.
From chat conversation
Yuri:
What is the expected behaviour between the Loader and the OkHttpDataSource? I see it prefetching content, presumably up to the 50 second buffer. But it seems like the Response isn't consumed fully and hangs around. Does ExoPlayer keep the request open and resume reading later? In my case, we might have made the request over a specifically requested high bandwidth network, say requesting LTE. So I'd like to ensure it's only open while we are actively loading.
Toni:
If we are talking about progressive streams that are not loaded in chunks, then this sounds like WAI. The connection is opened once and then kept open so that the player can read the data whenever needed. As pointed out above, keeping the connection open without reading is relatively cheap in general. The alternative would be to implement something like the custom DataSource Mitchell described above. What kind of timeout would you use for this case? If it's too small you may cause too many additional delays when reopening the source. If it's too big, you won't save much. If your class is general purpose and can work with any underlying HTTP source, it may be worth sending a PR for it.
A second problem, is on HTTP/2 it's possible that this unread data ends up blocking the entire connection (either on server or client end) and other requests (for example concurrent prefetching) may see timeouts.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.