Skip to content

Commit

Permalink
Implement multi session to support DRM key rotation.
Browse files Browse the repository at this point in the history
Spec: https://storage.googleapis.com/wvdocs/Widevine_DRM_Android_Using_Key_Rotation.pdf

1. Implement multisession to support drm key rotation
2. Put MediaDrmEventListener back to manager since this is a per mediaDrm thing.
3. It seems diffrenciate between single/multi session is unnecessary.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=167602965
  • Loading branch information
zhihuichen authored and ojw28 committed Sep 6, 2017
1 parent e16610a commit b62eab6
Show file tree
Hide file tree
Showing 4 changed files with 301 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public class PlayerActivity extends Activity implements OnClickListener, EventLi
public static final String DRM_SCHEME_UUID_EXTRA = "drm_scheme_uuid";
public static final String DRM_LICENSE_URL = "drm_license_url";
public static final String DRM_KEY_REQUEST_PROPERTIES = "drm_key_request_properties";
public static final String DRM_MULTI_SESSION = "drm_multi_session";
public static final String PREFER_EXTENSION_DECODERS = "prefer_extension_decoders";

public static final String ACTION_VIEW = "com.google.android.exoplayer.demo.action.VIEW";
Expand Down Expand Up @@ -264,13 +265,14 @@ private void initializePlayer() {
if (drmSchemeUuid != null) {
String drmLicenseUrl = intent.getStringExtra(DRM_LICENSE_URL);
String[] keyRequestPropertiesArray = intent.getStringArrayExtra(DRM_KEY_REQUEST_PROPERTIES);
boolean multiSession = intent.getBooleanExtra(DRM_MULTI_SESSION, false);
int errorStringId = R.string.error_drm_unknown;
if (Util.SDK_INT < 18) {
errorStringId = R.string.error_drm_not_supported;
} else {
try {
drmSessionManager = buildDrmSessionManagerV18(drmSchemeUuid, drmLicenseUrl,
keyRequestPropertiesArray);
keyRequestPropertiesArray, multiSession);
} catch (UnsupportedDrmException e) {
errorStringId = e.reason == UnsupportedDrmException.REASON_UNSUPPORTED_SCHEME
? R.string.error_drm_unsupported_scheme : R.string.error_drm_unknown;
Expand Down Expand Up @@ -379,7 +381,8 @@ private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
}

private DrmSessionManager<FrameworkMediaCrypto> buildDrmSessionManagerV18(UUID uuid,
String licenseUrl, String[] keyRequestPropertiesArray) throws UnsupportedDrmException {
String licenseUrl, String[] keyRequestPropertiesArray, boolean multiSession)
throws UnsupportedDrmException {
HttpMediaDrmCallback drmCallback = new HttpMediaDrmCallback(licenseUrl,
buildHttpDataSourceFactory(false));
if (keyRequestPropertiesArray != null) {
Expand All @@ -389,7 +392,7 @@ private DrmSessionManager<FrameworkMediaCrypto> buildDrmSessionManagerV18(UUID u
}
}
return new DefaultDrmSessionManager<>(uuid, FrameworkMediaDrm.newInstance(uuid), drmCallback,
null, mainHandler, eventLogger);
null, mainHandler, eventLogger, multiSession);
}

private void releasePlayer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ private Sample readEntry(JsonReader reader, boolean insidePlaylist) throws IOExc
UUID drmUuid = null;
String drmLicenseUrl = null;
String[] drmKeyRequestProperties = null;
boolean drmMultiSession = false;
boolean preferExtensionDecoders = false;
ArrayList<UriSample> playlistSamples = null;
String adTagUri = null;
Expand Down Expand Up @@ -220,6 +221,9 @@ private Sample readEntry(JsonReader reader, boolean insidePlaylist) throws IOExc
reader.endObject();
drmKeyRequestProperties = drmKeyRequestPropertiesList.toArray(new String[0]);
break;
case "drm_multi_session":
drmMultiSession = reader.nextBoolean();
break;
case "prefer_extension_decoders":
Assertions.checkState(!insidePlaylist,
"Invalid attribute on nested item: prefer_extension_decoders");
Expand All @@ -242,15 +246,16 @@ private Sample readEntry(JsonReader reader, boolean insidePlaylist) throws IOExc
}
}
reader.endObject();

DrmInfo drmInfo = drmUuid == null ? null : new DrmInfo(drmUuid, drmLicenseUrl,
drmKeyRequestProperties, drmMultiSession);
if (playlistSamples != null) {
UriSample[] playlistSamplesArray = playlistSamples.toArray(
new UriSample[playlistSamples.size()]);
return new PlaylistSample(sampleName, drmUuid, drmLicenseUrl, drmKeyRequestProperties,
preferExtensionDecoders, playlistSamplesArray);
return new PlaylistSample(sampleName, preferExtensionDecoders, drmInfo,
playlistSamplesArray);
} else {
return new UriSample(sampleName, drmUuid, drmLicenseUrl, drmKeyRequestProperties,
preferExtensionDecoders, uri, extension, adTagUri);
return new UriSample(sampleName, preferExtensionDecoders, drmInfo, uri, extension,
adTagUri);
}
}

Expand Down Expand Up @@ -372,31 +377,47 @@ public SampleGroup(String title) {

}

private abstract static class Sample {

public final String name;
public final boolean preferExtensionDecoders;
private static final class DrmInfo {
public final UUID drmSchemeUuid;
public final String drmLicenseUrl;
public final String[] drmKeyRequestProperties;
public final boolean drmMultiSession;

public Sample(String name, UUID drmSchemeUuid, String drmLicenseUrl,
String[] drmKeyRequestProperties, boolean preferExtensionDecoders) {
this.name = name;
public DrmInfo(UUID drmSchemeUuid, String drmLicenseUrl,
String[] drmKeyRequestProperties, boolean drmMultiSession) {
this.drmSchemeUuid = drmSchemeUuid;
this.drmLicenseUrl = drmLicenseUrl;
this.drmKeyRequestProperties = drmKeyRequestProperties;
this.drmMultiSession = drmMultiSession;
}

public void updateIntent(Intent intent) {
Assertions.checkNotNull(intent);
intent.putExtra(PlayerActivity.DRM_SCHEME_UUID_EXTRA, drmSchemeUuid.toString());
intent.putExtra(PlayerActivity.DRM_LICENSE_URL, drmLicenseUrl);
intent.putExtra(PlayerActivity.DRM_KEY_REQUEST_PROPERTIES, drmKeyRequestProperties);
intent.putExtra(PlayerActivity.DRM_MULTI_SESSION, drmMultiSession);
}
}

private abstract static class Sample {
public final String name;
public final boolean preferExtensionDecoders;
public final DrmInfo drmInfo;

public Sample(String name, boolean preferExtensionDecoders, DrmInfo drmInfo) {
this.name = name;
this.preferExtensionDecoders = preferExtensionDecoders;
this.drmInfo = drmInfo;
}

public Intent buildIntent(Context context) {
Intent intent = new Intent(context, PlayerActivity.class);
intent.putExtra(PlayerActivity.PREFER_EXTENSION_DECODERS, preferExtensionDecoders);
if (drmSchemeUuid != null) {
intent.putExtra(PlayerActivity.DRM_SCHEME_UUID_EXTRA, drmSchemeUuid.toString());
intent.putExtra(PlayerActivity.DRM_LICENSE_URL, drmLicenseUrl);
intent.putExtra(PlayerActivity.DRM_KEY_REQUEST_PROPERTIES, drmKeyRequestProperties);
if (drmInfo != null) {
drmInfo.updateIntent(intent);
}

return intent;
}

Expand All @@ -408,10 +429,9 @@ private static final class UriSample extends Sample {
public final String extension;
public final String adTagUri;

public UriSample(String name, UUID drmSchemeUuid, String drmLicenseUrl,
String[] drmKeyRequestProperties, boolean preferExtensionDecoders, String uri,
public UriSample(String name, boolean preferExtensionDecoders, DrmInfo drmInfo, String uri,
String extension, String adTagUri) {
super(name, drmSchemeUuid, drmLicenseUrl, drmKeyRequestProperties, preferExtensionDecoders);
super(name, preferExtensionDecoders, drmInfo);
this.uri = uri;
this.extension = extension;
this.adTagUri = adTagUri;
Expand All @@ -432,10 +452,9 @@ private static final class PlaylistSample extends Sample {

public final UriSample[] children;

public PlaylistSample(String name, UUID drmSchemeUuid, String drmLicenseUrl,
String[] drmKeyRequestProperties, boolean preferExtensionDecoders,
public PlaylistSample(String name, boolean preferExtensionDecoders, DrmInfo drmInfo,
UriSample... children) {
super(name, drmSchemeUuid, drmLicenseUrl, drmKeyRequestProperties, preferExtensionDecoders);
super(name, preferExtensionDecoders, drmInfo);
this.children = children;
}

Expand Down
Loading

0 comments on commit b62eab6

Please sign in to comment.