Commit 1624135c by mishragaurav Committed by Oliver Woodman

Parse widevine tag in manifest for secure decryption.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=128345063
parent abcd1051
Showing with 73 additions and 100 deletions
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/raw
maxInputSize = -1
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/raw
maxInputSize = -1
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/raw
maxInputSize = -1
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/raw
maxInputSize = -1
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 8:
containerMimeType = null
sampleMimeType = audio/mp4a-latm
maxInputSize = -1
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......@@ -215,7 +214,6 @@ track 9:
containerMimeType = null
sampleMimeType = video/avc
maxInputSize = -1
requiresSecureDecryption = false
width = 1080
height = 720
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 1:
containerMimeType = null
sampleMimeType = video/avc
maxInputSize = -1
requiresSecureDecryption = false
width = 1080
height = 720
frameRate = -1.0
......@@ -156,7 +155,6 @@ track 2:
containerMimeType = null
sampleMimeType = audio/ac3
maxInputSize = -1
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 1:
containerMimeType = null
sampleMimeType = video/avc
maxInputSize = -1
requiresSecureDecryption = false
width = 1080
height = 720
frameRate = -1.0
......@@ -124,7 +123,6 @@ track 2:
containerMimeType = null
sampleMimeType = audio/ac3
maxInputSize = -1
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 1:
containerMimeType = null
sampleMimeType = video/avc
maxInputSize = -1
requiresSecureDecryption = false
width = 1080
height = 720
frameRate = -1.0
......@@ -80,7 +79,6 @@ track 2:
containerMimeType = null
sampleMimeType = audio/ac3
maxInputSize = -1
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 1:
containerMimeType = null
sampleMimeType = video/avc
maxInputSize = -1
requiresSecureDecryption = false
width = 1080
height = 720
frameRate = -1.0
......@@ -36,7 +35,6 @@ track 2:
containerMimeType = null
sampleMimeType = audio/ac3
maxInputSize = -1
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/mpeg
maxInputSize = 4096
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/mpeg
maxInputSize = 4096
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/mpeg
maxInputSize = 4096
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/mpeg
maxInputSize = 4096
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = video/avc
maxInputSize = 36722
requiresSecureDecryption = false
width = 1080
height = 720
frameRate = -1.0
......@@ -156,7 +155,6 @@ track 1:
containerMimeType = null
sampleMimeType = audio/mp4a-latm
maxInputSize = 294
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = video/avc
maxInputSize = 36722
requiresSecureDecryption = false
width = 1080
height = 720
frameRate = -1.0
......@@ -156,7 +155,6 @@ track 1:
containerMimeType = null
sampleMimeType = audio/mp4a-latm
maxInputSize = 294
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = video/avc
maxInputSize = 36722
requiresSecureDecryption = false
width = 1080
height = 720
frameRate = -1.0
......@@ -156,7 +155,6 @@ track 1:
containerMimeType = null
sampleMimeType = audio/mp4a-latm
maxInputSize = 294
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = video/avc
maxInputSize = 36722
requiresSecureDecryption = false
width = 1080
height = 720
frameRate = -1.0
......@@ -156,7 +155,6 @@ track 1:
containerMimeType = null
sampleMimeType = audio/mp4a-latm
maxInputSize = 294
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = video/avc
maxInputSize = -1
requiresSecureDecryption = false
width = 1080
height = 720
frameRate = -1.0
......@@ -156,7 +155,6 @@ track 1:
containerMimeType = null
sampleMimeType = audio/mp4a-latm
maxInputSize = -1
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/opus
maxInputSize = -1
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/opus
maxInputSize = -1
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/opus
maxInputSize = -1
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/opus
maxInputSize = -1
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/opus
maxInputSize = -1
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/x-flac
maxInputSize = 768000
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/x-flac
maxInputSize = 768000
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/x-flac
maxInputSize = 768000
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/x-flac
maxInputSize = 768000
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/x-flac
maxInputSize = 768000
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/x-flac
maxInputSize = 768000
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/x-flac
maxInputSize = 768000
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/x-flac
maxInputSize = 768000
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/x-flac
maxInputSize = 768000
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/x-flac
maxInputSize = 768000
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/vorbis
maxInputSize = 65025
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/vorbis
maxInputSize = 65025
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/vorbis
maxInputSize = 65025
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/vorbis
maxInputSize = 65025
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/vorbis
maxInputSize = 65025
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/mp4a-latm
maxInputSize = -1
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......@@ -611,7 +610,6 @@ track 1:
containerMimeType = null
sampleMimeType = application/id3
maxInputSize = -1
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 192:
containerMimeType = null
sampleMimeType = audio/mpeg-L2
maxInputSize = 4096
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......@@ -50,7 +49,6 @@ track 224:
containerMimeType = null
sampleMimeType = video/mpeg2
maxInputSize = -1
requiresSecureDecryption = false
width = 640
height = 426
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 2:
containerMimeType = null
sampleMimeType = video/mpeg2
maxInputSize = -1
requiresSecureDecryption = false
width = 640
height = 426
frameRate = -1.0
......@@ -43,7 +42,6 @@ track 3:
containerMimeType = null
sampleMimeType = audio/mpeg-L2
maxInputSize = 4096
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......@@ -83,7 +81,6 @@ track 21:
containerMimeType = null
sampleMimeType = application/id3
maxInputSize = -1
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/raw
maxInputSize = 32768
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/raw
maxInputSize = 32768
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/raw
maxInputSize = 32768
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -10,7 +10,6 @@ track 0:
containerMimeType = null
sampleMimeType = audio/raw
maxInputSize = 32768
requiresSecureDecryption = false
width = -1
height = -1
frameRate = -1.0
......
......@@ -61,7 +61,7 @@ public final class FormatTest extends TestCase {
Format formatToParcel = new Format("id", MimeTypes.VIDEO_MP4, MimeTypes.VIDEO_H264, null,
1024, 2048, 1920, 1080, 24, 90, 2, 6, 44100, C.ENCODING_PCM_24BIT, 1001, 1002, 0, "und",
Format.OFFSET_SAMPLE_RELATIVE, INIT_DATA, drmInitData, false);
Format.OFFSET_SAMPLE_RELATIVE, INIT_DATA, drmInitData);
Parcel parcel = Parcel.obtain();
formatToParcel.writeToParcel(parcel, 0);
......
......@@ -148,8 +148,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
if (allowPassthrough(mimeType) && mediaCodecSelector.getPassthroughDecoderInfo() != null) {
return ADAPTIVE_NOT_SEAMLESS | FORMAT_HANDLED;
}
MediaCodecInfo decoderInfo = mediaCodecSelector.getDecoderInfo(mimeType,
format.requiresSecureDecryption);
MediaCodecInfo decoderInfo = mediaCodecSelector.getDecoderInfo(mimeType, false);
if (decoderInfo == null) {
return FORMAT_UNSUPPORTED_SUBTYPE;
}
......
......@@ -39,6 +39,11 @@ public final class DrmInitData implements Comparator<SchemeData>, Parcelable {
private int hashCode;
/**
* Number of {@link SchemeData}s.
*/
public final int schemeDataCount;
/**
* @param schemeDatas Scheme initialization data for possibly multiple DRM schemes.
*/
public DrmInitData(List<SchemeData> schemeDatas) {
......@@ -66,10 +71,12 @@ public final class DrmInitData implements Comparator<SchemeData>, Parcelable {
}
}
this.schemeDatas = schemeDatas;
schemeDataCount = schemeDatas.length;
}
/* package */ DrmInitData(Parcel in) {
schemeDatas = in.createTypedArray(SchemeData.CREATOR);
schemeDataCount = schemeDatas.length;
}
/**
......@@ -87,6 +94,16 @@ public final class DrmInitData implements Comparator<SchemeData>, Parcelable {
return null;
}
/**
* Retrieves the {@link SchemeData} at a given index.
*
* @param index index of the scheme to return.
* @return The {@link SchemeData} at the index.
*/
public SchemeData get(int index) {
return schemeDatas[index];
}
@Override
public int hashCode() {
if (hashCode == 0) {
......@@ -160,6 +177,10 @@ public final class DrmInitData implements Comparator<SchemeData>, Parcelable {
* The initialization data.
*/
public final byte[] data;
/**
* Whether secure decryption is required.
*/
public final boolean requiresSecureDecryption;
/**
* @param uuid The {@link UUID} of the DRM scheme, or {@link C#UUID_NIL} if the data is
......@@ -168,15 +189,28 @@ public final class DrmInitData implements Comparator<SchemeData>, Parcelable {
* @param data The initialization data.
*/
public SchemeData(UUID uuid, String mimeType, byte[] data) {
this(uuid, mimeType, data, false);
}
/**
* @param uuid The {@link UUID} of the DRM scheme, or {@link C#UUID_NIL} if the data is
* universal (i.e. applies to all schemes).
* @param mimeType The mimeType of the initialization data.
* @param data The initialization data.
* @param requiresSecureDecryption Whether secure decryption is required.
*/
public SchemeData(UUID uuid, String mimeType, byte[] data, boolean requiresSecureDecryption) {
this.uuid = Assertions.checkNotNull(uuid);
this.mimeType = Assertions.checkNotNull(mimeType);
this.data = Assertions.checkNotNull(data);
this.requiresSecureDecryption = requiresSecureDecryption;
}
/* package */ SchemeData(Parcel in) {
uuid = new UUID(in.readLong(), in.readLong());
mimeType = in.readString();
data = in.createByteArray();
requiresSecureDecryption = in.readByte() != 0;
}
/**
......@@ -226,6 +260,7 @@ public final class DrmInitData implements Comparator<SchemeData>, Parcelable {
dest.writeLong(uuid.getLeastSignificantBits());
dest.writeString(mimeType);
dest.writeByteArray(data);
dest.writeByte((byte) (requiresSecureDecryption ? 1 : 0));
}
@SuppressWarnings("hiding")
......
......@@ -315,25 +315,30 @@ public class DashManifestParser extends DefaultHandler
**/
protected SchemeData parseContentProtection(XmlPullParser xpp)
throws XmlPullParserException, IOException {
SchemeData schemeData = null;
byte[] data = null;
UUID uuid = null;
boolean seenPsshElement = false;
boolean requiresSecureDecoder = false;
do {
xpp.next();
// The cenc:pssh element is defined in 23001-7:2015.
if (XmlPullParserUtil.isStartTag(xpp, "cenc:pssh") && xpp.next() == XmlPullParser.TEXT) {
seenPsshElement = true;
byte[] data = Base64.decode(xpp.getText(), Base64.DEFAULT);
UUID uuid = PsshAtomUtil.parseUuid(data);
if (uuid != null) {
schemeData = new SchemeData(uuid, MimeTypes.VIDEO_MP4, data);
}
data = Base64.decode(xpp.getText(), Base64.DEFAULT);
uuid = PsshAtomUtil.parseUuid(data);
} else if (XmlPullParserUtil.isStartTag(xpp, "widevine:license")) {
String robustnessLevel = xpp.getAttributeValue(null, "robustness_level");
requiresSecureDecoder = robustnessLevel != null && robustnessLevel.startsWith("HW");
}
} while (!XmlPullParserUtil.isEndTag(xpp, "ContentProtection"));
if (seenPsshElement && schemeData == null) {
if (!seenPsshElement) {
return null;
} else if (uuid != null) {
return new SchemeData(uuid, MimeTypes.VIDEO_MP4, data, requiresSecureDecoder);
} else {
Log.w(TAG, "Skipped unsupported ContentProtection element");
return null;
}
return schemeData;
}
/**
......
......@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.video;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.drm.DrmInitData;
import com.google.android.exoplayer2.drm.DrmSessionManager;
import com.google.android.exoplayer2.mediacodec.MediaCodecInfo;
import com.google.android.exoplayer2.mediacodec.MediaCodecRenderer;
......@@ -175,8 +176,13 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
if (!MimeTypes.isVideo(mimeType)) {
return FORMAT_UNSUPPORTED_TYPE;
}
DrmInitData drmInitData = format.drmInitData;
boolean requiresSecureDecryption = false;
for (int i = 0; i < drmInitData.schemeDataCount; i++) {
requiresSecureDecryption |= drmInitData.get(i).requiresSecureDecryption;
}
MediaCodecInfo decoderInfo = mediaCodecSelector.getDecoderInfo(mimeType,
format.requiresSecureDecryption);
requiresSecureDecryption);
if (decoderInfo == null) {
return FORMAT_UNSUPPORTED_SUBTYPE;
}
......
......@@ -145,7 +145,6 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
.add("containerMimeType", format.containerMimeType)
.add("sampleMimeType", format.sampleMimeType)
.add("maxInputSize", format.maxInputSize)
.add("requiresSecureDecryption", format.requiresSecureDecryption)
.add("width", format.width)
.add("height", format.height)
.add("frameRate", format.frameRate)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment