Skip to content

Commit

Permalink
VEX-5798: Implement DRM L1 to L3 fallback (24i#9)
Browse files Browse the repository at this point in the history
Add support for L1 to L3 Widevine fallback if playback fails initially.
  • Loading branch information
armands-malejevs authored Oct 13, 2021
1 parent 2fcc1de commit 3bcf2c6
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.drm.MediaDrmCallbackException;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.PlaybackParameters;
Expand Down Expand Up @@ -134,6 +135,7 @@ class ReactExoplayerView extends FrameLayout implements
private int minLoadRetryCount = 3;
private int maxBitRate = 0;
private long seekTime = C.TIME_UNSET;
private boolean hasDrmFailed = false;

private int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS;
private int maxBufferMs = DefaultLoadControl.DEFAULT_MAX_BUFFER_MS;
Expand Down Expand Up @@ -572,8 +574,13 @@ private DrmSessionManager buildDrmSessionManager(UUID uuid,
keyRequestPropertiesArray[i + 1]);
}
}
FrameworkMediaDrm mediaDrm = FrameworkMediaDrm.newInstance(uuid);
if (hasDrmFailed) {
// When DRM fails using L1 we want to switch to L3
mediaDrm.setPropertyString("securityLevel", "L3");
}
return new DefaultDrmSessionManager(uuid,
FrameworkMediaDrm.newInstance(uuid), drmCallback, null, false, 3);
mediaDrm, drmCallback, null, false, 3);
}

private MediaSource buildMediaSource(Uri uri, String overrideExtension, DrmSessionManager drmSessionManager) {
Expand Down Expand Up @@ -1029,6 +1036,7 @@ public void onPlaybackParametersChanged(PlaybackParameters params) {
public void onPlayerError(ExoPlaybackException e) {
String errorString = "ExoPlaybackException type : " + e.type;
String errorCode = "2001"; // Playback error code 2xxx (2001 - unknown playback exception)
boolean needsReInitialization = false;
Exception ex = e;
if (e.type == ExoPlaybackException.TYPE_RENDERER) {
Exception cause = e.getRendererException();
Expand Down Expand Up @@ -1057,6 +1065,9 @@ public void onPlayerError(ExoPlaybackException e) {
}
}
else if (e.type == ExoPlaybackException.TYPE_SOURCE) {
// Re-initialization improves recovery speed and properly resumes
needsReInitialization = true;
errorString = getResources().getString(R.string.unrecognized_media_format);
Exception cause = e.getSourceException();
if (cause instanceof DefaultDrmSessionManager.MissingSchemeDataException) {
errorCode = "3004";
Expand All @@ -1073,6 +1084,14 @@ else if (e.type == ExoPlaybackException.TYPE_SOURCE) {
if (rootCause instanceof MediaDrmCallbackException) {
errorCode = "3005";
errorString = getResources().getString(R.string.unrecognized_media_format);
if (!hasDrmFailed) {
// When DRM fails to reach the app level certificate server it will fail with a source error so we assume that it is DRM related and try one more time
hasDrmFailed = true;
playerNeedsSource = true;
updateResumePosition();
initializePlayer();
return;
}
}
}
}
Expand All @@ -1083,6 +1102,9 @@ else if (e.type == ExoPlaybackException.TYPE_SOURCE) {
initializePlayer();
} else {
updateResumePosition();
if (needsReInitialization) {
initializePlayer();
}
}
}

Expand Down

0 comments on commit 3bcf2c6

Please sign in to comment.