androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.67k stars 395 forks source link

Recover from DRM License request authentication error (401) #1810

Open stevemayhew opened 1 week ago

stevemayhew commented 1 week ago

Use case description

Access to MultiDRM license servers is prudently protected by client authentication headers. With Widevine Proxy server the proxy is able to authenticate the caller and reject it or respond by forwarding the request to Google's widevine server. One common use case would be signaling a HTTP 401 status.

ExoPlayer provides for error recovery via the LoadErrorHandlingPolicy, calling the getRetryDelayMsFor() when the request fails, however there is no provision for returning anything other than a delay value.

Note this license request is often issued while there is significant buffered content, so being able to recover in-place saves a lot of time.

Proposed solution

Add an optional method to LoadErrorHandlingPolicy interface, like:

  /**
   * Updates the request properties, if required.  Returns true if updated
   */
  boolean updateRequestPropertiesForError(LoadErrorInfo loadErrorInfo, HashMap<String, String> keyRequestParameters) { return false; }

This would be used, for example to update any short-lived login token in the request headers. Obviously this is just an idea to riff on, as the ultimate source of the header values is the MediaItem.DrmConfiguration. The MediaItem is far distanced from the point of the load error detection

Alternatives considered

The only alternative with the current code base (that I can see) is to not retry, and completely restart playback with an updated MediaItem from outside of ExoPlayer code.

stevemayhew commented 8 hours ago

Note, the API would allow the MultiDRM License Server to implement an HTTP Challenge like scheme for authentication

FWIW Shaka Player provides this via a relatively low level API, Shaka License Server Authentication. It should be possible to do something in ExoPlayer's HttpMediaDrmCallback that is as versatile without being as invasive.