ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

Respecting presentation delay while buffering chunks in DASH Live playbacks

Open akavrt opened this issue 5 years ago • 3 comments

Lately we have been experimenting with DASH Live and encountered the following problem. Looks like ExoPlayer ignores presentation delay provided in the media manifest when it tries to load chunks to fill the buffer. This behavior results in many 404 errors on chunk load requests when CDN can't fulfill client requests for chunks that are yet to be created.

For example, presentation delay in the manifest is set to 30 seconds:

<MPD 
   ...
   suggestedPresentationDelay="PT30S"
   type="dynamic"
   maxSegmentDuration="PT4S" 
   minBufferTime="PT4S">
   
   ...
   
</MPD>

and the default configuration is used when player is instantiated, i.e. DefaultLoadControl's parameter maxBufferMs is set to 50 seconds. On a reliable connection after a few second of playback player will load all chunks available in that ~30 second window (duration of the presentation delay) and then it will try to fill the rest 20 seconds of the buffer but every such chunk request will fail with 404 error because requested chunks aren't available at this point of time. The video playback in general isn't affected apart from the fact that adaptive bitrate switching works somewhat unpredictable maybe because some chunks are blacklisted after those failed loads.

An obvious choice to prevent this behavior would be to limit DefaultLoadControl's parameter maxBufferMs in such a way that

maxBufferMs < MPD@suggestedPresentationDelay

but this approach isn't flexible enough because it requires to specify the value of the maxBufferMs parameter in advance when player is configured and instantiated: presentation delay isn't known at that point and theoretically it can be changed when playback is switched from one media to another.

Do we miss something in our manifest configuration or maybe there is a better way to configure ExoPlayer to prevent it from doing untimely chunk requests in aforementioned scenario?

akavrt avatar May 05 '21 11:05 akavrt

@tonihei any ideas on this?

One idea I can think of (not tested!) is passing a custom LoadControl instance on the player to do what you describe, i.e. prevent from loading if bufferedDuration is close to MPD@suggestedPresentationDelay. You cannot achieve that with the existing DefaultLoadControl, but you can create a subclass of it to override its shouldContinueLoading method, maybe something like

@Override
public boolean shouldContinueLoading(long playbackPositionUs, long bufferedDurationUs, float playbackSpeed) {
  if (bufferedDurationUs close to MPD@suggestedPresentationDelay) {
    return false;
  }
  return super.shouldContinueLoading(playbackPositionUs, bufferedDurationUs, playbackSpeed);
}

christosts avatar May 14 '21 12:05 christosts

I think the player is behaving as expected and the manifest/serving infrastructure is not set up correctly:

  • The manifest doesn't contain a timeShiftBufferDepth. This means the available live window starts in 1970 and (unsurprisingly) seeking backwards results in 404 status codes as the segments aren't actually available.
  • The available live window ends at the segment whose end time is less than the current real time (see here). However, requesting segments close to the current time, which should be available according to the spec, results in 404s as you noted in the issue description.
  • The suggestedPresentationDelay shouldn't have any influence on the segment availability and is really just what it says: the suggested delay for the player for playback. The player should be free to load all available segments. See here, in particular the segment marked as "Available, Not Presentable".

So instead of trying to convince the player to load fewer segments, you should probably look into fixing the manifest and/or segment creation instead to be spec-conformant. Otherwise you may run into similar issues with other players on other platforms for example.

tonihei avatar May 18 '21 15:05 tonihei

@christosts @tonihei Thanks a lot for your feedback! We will adjust our manifests as suggested.

akavrt avatar May 18 '21 15:05 akavrt