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

Stop timers in background #199

Closed
defagos opened this issue Jan 6, 2020 · 4 comments
Closed

Stop timers in background #199

defagos opened this issue Jan 6, 2020 · 4 comments

Comments

@defagos
Copy link
Member

defagos commented Jan 6, 2020

This is a follow-up of issue #182. Though some work has already been done to reduce background activity, there is a remaining issue with timers.

We do not use AVPlayer time observers in SRG Media Player so that updates are also received when playback is paused (mostly for DVR streams with a sliding window). We use NSTimer instead, but those are still active in background, unlike periodic time observers that are smarter:

  • They are active only when playback is active (which is good, except for the DVR case described above). Corollary: They only notify time updates.
  • They are not active in background if no playback is active. (Actually this is the same for NSTimer. If the app is sent to the background timers are suspended. An exception is if background audio is enabled and a content is being played, which is exactly like periodic time observers)
  • They are bound to the player.
  • They are called when playback jumps or stops, automatically.

I currently see two possibilities to solve this issue:

  • We implement our own periodic time observers, which are paused in background if no playback is active, and behave like usual AVPlayer time observers.
  • We can use standard periodic time observers, and KV-observe range changes for the DVR case.

In all cases, it might still be helpful to have a timer class which automatically pauses and resumes updates when the app moves to / from background. This way we could also eliminate all other background refreshes from Letterbox (e.g. metadata) and, more generally, from Play.

Such a timer could be part of another generic core library. We could also put common duplicate code there as well, offering a solution to #198.

@defagos
Copy link
Member Author

defagos commented Jan 6, 2020

It is possible to KV-observe the seekableTimeRanges property, which yield few updates for livestreams, (with or without DVR) and no updates for on-demand. Updates are also received when playback is paused.

This is probably an excellent approach.

@defagos
Copy link
Member Author

defagos commented Jan 8, 2020

Most of the involved work must be made in SRG Media Player, for which I created a dedicated issue.

@defagos
Copy link
Member Author

defagos commented Jan 9, 2020

I updated the following libraries on feature/energy-efficiency branches:

  • SRG Media Player
  • SRG Diagnostics
  • SRG Content Protection (+ Fake)
  • SRG Analytics
  • SRG Letterbox
  • SRG User Data (though not directly related to Letterbox)

For most of them, I only added a tolerance to timers by default (in all cases, we have no strict requirement about the execution timing and can let the system optimize timer execution).

@defagos
Copy link
Member Author

defagos commented Jan 9, 2020

Time updates (e.g. slider range) are more demanding for DVR streams than for on-demand ones, since the start and end window times change continuously. Previously, we were refreshing control center time range information with each chunk. Since partial MPNowPlayingInfo updates are not possible, we were reloading the information with each chunk, which was inefficient.

I removed such updates. With each Letterbox metadata periodic update, the information will be refreshed anyway. This greatly improves the activity profile of Letterbox and should therefore have a positive energy impact.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants