Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some limits on the background download threads while playing download thread is working #7588

Closed
Romantic-LiXuefeng opened this issue Jul 3, 2020 · 2 comments

Comments

@Romantic-LiXuefeng
Copy link

Romantic-LiXuefeng commented Jul 3, 2020

[REQUIRED] Question

According to the #5978, This is fully implemented the parallelize segment downloads. So recently I have done some tests about this feature with the dev-v2 branch's demo. It's amazing work. When parallelize segment downloads, the network can remain more fully utilized. But I may add some bad affect for smooth playback. Whether add some strategy to trade-off between download speed and smooth playback.

The specific user scenario is described as follows:
When the background is downloading video programs, if the user want to start playing other program, whether could add some restrictions to ensure the smooth playback of the program.
For example:

  • Whether can set the priority of the background download task. Only when the player is in the READY state , the background thread will start downloading.

  • Or set a bandwidth limit on the download task when the player is playing other program.

@ojw28
Copy link
Contributor

ojw28 commented Jul 3, 2020

Have you tried using PriorityTaskManager for this. It's not very obvious, but if you build your DownloadManager like this:

downloadManager =
          new DownloadManager(
              this,
              new DefaultDownloadIndex(databaseProvider),
              new DefaultDownloaderFactory(
                  new CacheDataSource.Factory()
                      .setCache(getDownloadCache())
                      .setUpstreamDataSourceFactory(buildHttpDataSourceFactory())
                      .setUpstreamPriorityTaskManager(getPriorityTaskManager()),
                  Executors.newFixedThreadPool(/* nThreads= */ 6)));

and set the same PriorityTaskManager instance on your player:

player.setPriorityTaskManager(getPriorityTaskManager());

then downloads will automatically stop/start internally when the player starts/stops buffering. Notes:

  • This will not be visible as the notification appearing and disappearing since this would be very noisy, but internally the downloads will be stopping and starting appropriately to avoid clashing with the player needing to buffer.
  • It's not perfect because I think it'll do this even if the player is buffering from local files, for which it's arguably unnecessary. But in practice it works pretty well.

If you want more fine-grained control, I think you can probably implement this by implementing either the Executor or the upstream DataSource.Factory that the DownloadManager uses to be more aware of playback. If you're reusing the same Executor that your app is using for other background downloads, then making the Executor playback aware may yield some additional benefits. I would envisage this type of integration would need to be done on an app specific basis.

Please let me know if PriorityTaskManager helps. If it does, we should probably document this at https://exoplayer.dev/downloading-media.html (and make it easier to build a DownloadManager that uses one).

@Romantic-LiXuefeng
Copy link
Author

Please let me know if PriorityTaskManager helps. If it does, we should probably document this at https://exoplayer.dev/downloading-media.html (and make it easier to build a DownloadManager that uses one).

@ojw28 Thanks for your detail answer. It helps.

@google google locked and limited conversation to collaborators Sep 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants