private static @Nullable SchemeData parsePlayReadySchemeData( String line, Map<String, String> variableDefinitions) throws ParserException { String keyFormatVersions = parseOptionalStringAttr(line, REGEX_KEYFORMATVERSIONS, "1", variableDefinitions); if (!"1".equals(keyFormatVersions)) { // Not supported. return null; } String uriString = parseStringAttr(line, REGEX_URI, variableDefinitions); byte[] data = Base64.decode(uriString.substring(uriString.indexOf(',')), Base64.DEFAULT); byte[] psshData = PsshAtomUtil.buildPsshAtom(C.PLAYREADY_UUID, data); return new SchemeData(C.PLAYREADY_UUID, MimeTypes.VIDEO_MP4, psshData); }
/** * Returns a copy of this instance with the specified data. * * @param data The data to include in the copy. * @return The new instance. */ public SchemeData copyWithData(@Nullable byte[] data) { return new SchemeData(uuid, licenseServerUrl, mimeType, data, requiresSecureDecryption); }
private static @Nullable SchemeData parseWidevineSchemeData( String line, String keyFormat, Map<String, String> variableDefinitions) throws ParserException { if (KEYFORMAT_WIDEVINE_PSSH_BINARY.equals(keyFormat)) { String uriString = parseStringAttr(line, REGEX_URI, variableDefinitions); return new SchemeData( C.WIDEVINE_UUID, MimeTypes.VIDEO_MP4, Base64.decode(uriString.substring(uriString.indexOf(',')), Base64.DEFAULT)); } if (KEYFORMAT_WIDEVINE_PSSH_JSON.equals(keyFormat)) { try { return new SchemeData(C.WIDEVINE_UUID, "hls", line.getBytes(C.UTF8_NAME)); } catch (UnsupportedEncodingException e) { throw new ParserException(e); } } return null; }
@Test public void givenDrmDataContainsDrmScheme_whenCheckingCanAcquireSession_thenReturnsTrue() { DrmInitData.SchemeData recognisedSchemeData = new DrmInitData.SchemeData( DRM_SCHEME, "ANY_MIME_TYPE", new byte[]{} ); DrmInitData drmInitData = new DrmInitData(Collections.singletonList(recognisedSchemeData)); boolean canAcquireSession = localDrmSessionManager.canAcquireSession(drmInitData); assertThat(canAcquireSession).isTrue(); }
@Test public void givenDrmDataDoesNotContainDrmScheme_whenCheckingCanAcquireSession_thenReturnsFalse() { DrmInitData.SchemeData unrecognisedSchemeData = new DrmInitData.SchemeData( UUID.randomUUID(), "ANY_MIME_TYPE", new byte[]{} ); DrmInitData drmInitData = new DrmInitData(Collections.singletonList(unrecognisedSchemeData)); boolean canAcquireSession = localDrmSessionManager.canAcquireSession(drmInitData); assertThat(canAcquireSession).isFalse(); }
SchemeData schemeData = uuid != null ? new SchemeData( uuid, licenseServerUrl, MimeTypes.VIDEO_MP4, data, requiresSecureDecoder) : null;
throw new ParserException("Encrypted Track found but ContentEncKeyID was not found"); currentTrack.drmInitData = new DrmInitData(new SchemeData(C.UUID_NIL, MimeTypes.VIDEO_WEBM, currentTrack.cryptoData.encryptionKey));
@Test public void testParcelable() { DrmInitData.SchemeData drmData1 = new DrmInitData.SchemeData(WIDEVINE_UUID, VIDEO_MP4, TestUtil.buildTestData(128, 1 /* data seed */)); DrmInitData.SchemeData drmData2 = new DrmInitData.SchemeData(C.UUID_NIL, VIDEO_WEBM, TestUtil.buildTestData(128, 1 /* data seed */)); DrmInitData drmInitData = new DrmInitData(drmData1, drmData2);
/** Returns DrmInitData from leaf atoms. */ private static DrmInitData getDrmInitDataFromAtoms(List<Atom.LeafAtom> leafChildren) { ArrayList<SchemeData> schemeDatas = null; int leafChildrenSize = leafChildren.size(); for (int i = 0; i < leafChildrenSize; i++) { LeafAtom child = leafChildren.get(i); if (child.type == Atom.TYPE_pssh) { if (schemeDatas == null) { schemeDatas = new ArrayList<>(); } byte[] psshData = child.data.data; UUID uuid = PsshAtomUtil.parseUuid(psshData); if (uuid == null) { Log.w(TAG, "Skipped pssh atom (failed to extract uuid)"); } else { schemeDatas.add(new SchemeData(uuid, MimeTypes.VIDEO_MP4, psshData)); } } } return schemeDatas == null ? null : new DrmInitData(schemeDatas); }
@Override public Object build() { StreamElement[] streamElementArray = new StreamElement[streamElements.size()]; streamElements.toArray(streamElementArray); if (protectionElement != null) { DrmInitData drmInitData = new DrmInitData(new SchemeData(protectionElement.uuid, MimeTypes.VIDEO_MP4, protectionElement.data)); for (StreamElement streamElement : streamElementArray) { int type = streamElement.type; if (type == C.TRACK_TYPE_VIDEO || type == C.TRACK_TYPE_AUDIO) { Format[] formats = streamElement.formats; for (int i = 0; i < formats.length; i++) { formats[i] = formats[i].copyWithDrmInitData(drmInitData); } } } } return new SsManifest(majorVersion, minorVersion, timescale, duration, dvrWindowLength, lookAheadCount, isLive, protectionElement, streamElementArray); }
private static DrmInitData newDrmInitData() { return new DrmInitData( new SchemeData(C.WIDEVINE_UUID, "mimeType", new byte[] {1, 4, 7, 0, 3, 6})); } }
private static DrmInitData newDrmInitData() { return new DrmInitData( new SchemeData(C.WIDEVINE_UUID, "mimeType", new byte[] {1, 4, 7, 0, 3, 6})); } }