com.google.android.exoplayer2.drm.DrmInitData.SchemeData Java Examples

The following examples show how to use com.google.android.exoplayer2.drm.DrmInitData.SchemeData. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FragmentedMp4Extractor.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/** 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);
}
 
Example #2
Source File: HlsPlaylistParser.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private static SchemeData parseWidevineSchemeData(String line, String keyFormat)
    throws ParserException {
  if (KEYFORMAT_WIDEVINE_PSSH_BINARY.equals(keyFormat)) {
   String uriString = parseStringAttr(line, REGEX_URI);
   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;
}
 
Example #3
Source File: FragmentedMp4Extractor.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/** 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);
}
 
Example #4
Source File: FragmentedMp4Extractor.java    From K-Sonic with MIT License 6 votes vote down vote up
/** 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);
}
 
Example #5
Source File: DashManifestParser.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Removes unnecessary {@link SchemeData}s with null {@link SchemeData#data}.
 */
private static void filterRedundantIncompleteSchemeDatas(ArrayList<SchemeData> schemeDatas) {
  for (int i = schemeDatas.size() - 1; i >= 0; i--) {
    SchemeData schemeData = schemeDatas.get(i);
    if (!schemeData.hasData()) {
      for (int j = 0; j < schemeDatas.size(); j++) {
        if (schemeDatas.get(j).canReplace(schemeData)) {
          // schemeData is incomplete, but there is another matching SchemeData which does contain
          // data, so we remove the incomplete one.
          schemeDatas.remove(i);
          break;
        }
      }
    }
  }
}
 
Example #6
Source File: SsManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@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) {
      for (int i = 0; i < streamElement.formats.length; i++) {
        streamElement.formats[i] = streamElement.formats[i].copyWithDrmInitData(drmInitData);
      }
    }
  }
  return new SsManifest(majorVersion, minorVersion, timescale, duration, dvrWindowLength,
      lookAheadCount, isLive, protectionElement, streamElementArray);
}
 
Example #7
Source File: SsManifestParser.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example #8
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
protected Representation buildRepresentation(RepresentationInfo representationInfo,
    String contentId, String extraDrmSchemeType, ArrayList<SchemeData> extraDrmSchemeDatas,
    ArrayList<Descriptor> extraInbandEventStreams) {
  Format format = representationInfo.format;
  String drmSchemeType = representationInfo.drmSchemeType != null
      ? representationInfo.drmSchemeType : extraDrmSchemeType;
  ArrayList<SchemeData> drmSchemeDatas = representationInfo.drmSchemeDatas;
  drmSchemeDatas.addAll(extraDrmSchemeDatas);
  if (!drmSchemeDatas.isEmpty()) {
    filterRedundantIncompleteSchemeDatas(drmSchemeDatas);
    DrmInitData drmInitData = new DrmInitData(drmSchemeType, drmSchemeDatas);
    format = format.copyWithDrmInitData(drmInitData);
  }
  ArrayList<Descriptor> inbandEventStreams = representationInfo.inbandEventStreams;
  inbandEventStreams.addAll(extraInbandEventStreams);
  return Representation.newInstance(contentId, representationInfo.revisionId, format,
      representationInfo.baseUrl, representationInfo.segmentBase, inbandEventStreams);
}
 
Example #9
Source File: SsManifestParser.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #10
Source File: SsManifestParser.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example #11
Source File: SsManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@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) {
      for (int i = 0; i < streamElement.formats.length; i++) {
        streamElement.formats[i] = streamElement.formats[i].copyWithDrmInitData(drmInitData);
      }
    }
  }
  return new SsManifest(majorVersion, minorVersion, timescale, duration, dvrWindowLength,
      lookAheadCount, isLive, protectionElement, streamElementArray);
}
 
Example #12
Source File: DashManifestParser.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public RepresentationInfo(Format format, String baseUrl, SegmentBase segmentBase,
    String drmSchemeType, ArrayList<SchemeData> drmSchemeDatas,
    ArrayList<Descriptor> inbandEventStreams, long revisionId) {
  this.format = format;
  this.baseUrl = baseUrl;
  this.segmentBase = segmentBase;
  this.drmSchemeType = drmSchemeType;
  this.drmSchemeDatas = drmSchemeDatas;
  this.inbandEventStreams = inbandEventStreams;
  this.revisionId = revisionId;
}
 
Example #13
Source File: DrmInitData.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(@Nullable Object obj) {
  if (!(obj instanceof SchemeData)) {
    return false;
  }
  if (obj == this) {
    return true;
  }
  SchemeData other = (SchemeData) obj;
  return Util.areEqual(licenseServerUrl, other.licenseServerUrl)
      && Util.areEqual(mimeType, other.mimeType)
      && Util.areEqual(uuid, other.uuid)
      && Arrays.equals(data, other.data);
}
 
Example #14
Source File: DrmInitData.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @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 licenseServerUrl See {@link #licenseServerUrl}.
 * @param mimeType See {@link #mimeType}.
 * @param data See {@link #data}.
 * @param requiresSecureDecryption See {@link #requiresSecureDecryption}.
 */
public SchemeData(
    UUID uuid,
    @Nullable String licenseServerUrl,
    String mimeType,
    @Nullable byte[] data,
    boolean requiresSecureDecryption) {
  this.uuid = Assertions.checkNotNull(uuid);
  this.licenseServerUrl = licenseServerUrl;
  this.mimeType = Assertions.checkNotNull(mimeType);
  this.data = data;
  this.requiresSecureDecryption = requiresSecureDecryption;
}
 
Example #15
Source File: DrmInitData.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an instance containing the {@link #schemeDatas} from both this and {@code other}. The
 * {@link #schemeType} of the instances being merged must either match, or at least one scheme
 * type must be {@code null}.
 *
 * @param drmInitData The instance to merge.
 * @return The merged result.
 */
public DrmInitData merge(DrmInitData drmInitData) {
  Assertions.checkState(
      schemeType == null
          || drmInitData.schemeType == null
          || TextUtils.equals(schemeType, drmInitData.schemeType));
  String mergedSchemeType = schemeType != null ? this.schemeType : drmInitData.schemeType;
  SchemeData[] mergedSchemeDatas =
      Util.nullSafeArrayConcatenation(schemeDatas, drmInitData.schemeDatas);
  return new DrmInitData(mergedSchemeType, mergedSchemeDatas);
}
 
Example #16
Source File: DefaultDrmSessionManager.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Extracts {@link SchemeData} instances suitable for the given DRM scheme {@link UUID}.
 *
 * @param drmInitData The {@link DrmInitData} from which to extract the {@link SchemeData}.
 * @param uuid The UUID.
 * @param allowMissingData Whether a {@link SchemeData} with null {@link SchemeData#data} may be
 *     returned.
 * @return The extracted {@link SchemeData} instances, or an empty list if no suitable data is
 *     present.
 */
private static List<SchemeData> getSchemeDatas(
    DrmInitData drmInitData, UUID uuid, boolean allowMissingData) {
  // Look for matching scheme data (matching the Common PSSH box for ClearKey).
  List<SchemeData> matchingSchemeDatas = new ArrayList<>(drmInitData.schemeDataCount);
  for (int i = 0; i < drmInitData.schemeDataCount; i++) {
    SchemeData schemeData = drmInitData.get(i);
    boolean uuidMatches = schemeData.matches(uuid)
        || (C.CLEARKEY_UUID.equals(uuid) && schemeData.matches(C.COMMON_PSSH_UUID));
    if (uuidMatches && (schemeData.data != null || allowMissingData)) {
      matchingSchemeDatas.add(schemeData);
    }
  }
  return matchingSchemeDatas;
}
 
Example #17
Source File: DrmInitData.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private DrmInitData(@Nullable String schemeType, boolean cloneSchemeDatas,
    SchemeData... schemeDatas) {
  this.schemeType = schemeType;
  if (cloneSchemeDatas) {
    schemeDatas = schemeDatas.clone();
  }
  this.schemeDatas = schemeDatas;
  schemeDataCount = schemeDatas.length;
  // Sorting ensures that universal scheme data (i.e. data that applies to all schemes) is matched
  // last. It's also required by the equals and hashcode implementations.
  Arrays.sort(this.schemeDatas, this);
}
 
Example #18
Source File: DrmInitData.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Retrieves data for a given DRM scheme, specified by its UUID.
 *
 * @deprecated Use {@link #get(int)} and {@link SchemeData#matches(UUID)} instead.
 * @param uuid The DRM scheme's UUID.
 * @return The initialization data for the scheme, or null if the scheme is not supported.
 */
@Deprecated
public SchemeData get(UUID uuid) {
  for (SchemeData schemeData : schemeDatas) {
    if (schemeData.matches(uuid)) {
      return schemeData;
    }
  }
  return null;
}
 
Example #19
Source File: DashManifestParser.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Parses a ContentProtection element.
 *
 * @param xpp The parser from which to read.
 * @throws XmlPullParserException If an error occurs parsing the element.
 * @throws IOException If an error occurs reading the element.
 * @return {@link SchemeData} parsed from the ContentProtection element, or null if the element is
 *     unsupported.
 */
protected SchemeData parseContentProtection(XmlPullParser xpp) throws XmlPullParserException,
    IOException {
  String schemeIdUri = xpp.getAttributeValue(null, "schemeIdUri");
  boolean isPlayReady = "urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95".equals(schemeIdUri);
  byte[] data = null;
  UUID uuid = null;
  boolean requiresSecureDecoder = false;
  do {
    xpp.next();
    if (data == null && XmlPullParserUtil.isStartTag(xpp, "cenc:pssh")
        && xpp.next() == XmlPullParser.TEXT) {
      // The cenc:pssh element is defined in 23001-7:2015.
      data = Base64.decode(xpp.getText(), Base64.DEFAULT);
      uuid = PsshAtomUtil.parseUuid(data);
      if (uuid == null) {
        Log.w(TAG, "Skipping malformed cenc:pssh data");
        data = null;
      }
    } else if (data == null && isPlayReady && XmlPullParserUtil.isStartTag(xpp, "mspr:pro")
        && xpp.next() == XmlPullParser.TEXT) {
      // The mspr:pro element is defined in DASH Content Protection using Microsoft PlayReady.
      data = PsshAtomUtil.buildPsshAtom(C.PLAYREADY_UUID,
          Base64.decode(xpp.getText(), Base64.DEFAULT));
      uuid = C.PLAYREADY_UUID;
    } 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"));
  return data != null ? new SchemeData(uuid, MimeTypes.VIDEO_MP4, data, requiresSecureDecoder)
      : null;
}
 
Example #20
Source File: DefaultDrmSession.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Instantiates a new DRM session.
 *
 * @param uuid The UUID of the drm scheme.
 * @param mediaDrm The media DRM.
 * @param provisioningManager The manager for provisioning.
 * @param schemeData The DRM data for this session, or null if a {@code offlineLicenseKeySetId} is
 *     provided.
 * @param mode The DRM mode.
 * @param offlineLicenseKeySetId The offline license key set identifier, or null when not using
 *     offline keys.
 * @param optionalKeyRequestParameters The optional key request parameters.
 * @param callback The media DRM callback.
 * @param playbackLooper The playback looper.
 * @param eventDispatcher The dispatcher for DRM session manager events.
 * @param initialDrmRequestRetryCount The number of times to retry for initial provisioning and
 *     key request before reporting error.
 */
public DefaultDrmSession(
    UUID uuid,
    ExoMediaDrm<T> mediaDrm,
    ProvisioningManager<T> provisioningManager,
    @Nullable SchemeData schemeData,
    @DefaultDrmSessionManager.Mode int mode,
    @Nullable byte[] offlineLicenseKeySetId,
    HashMap<String, String> optionalKeyRequestParameters,
    MediaDrmCallback callback,
    Looper playbackLooper,
    EventDispatcher<DefaultDrmSessionEventListener> eventDispatcher,
    int initialDrmRequestRetryCount) {
  this.uuid = uuid;
  this.provisioningManager = provisioningManager;
  this.mediaDrm = mediaDrm;
  this.mode = mode;
  this.offlineLicenseKeySetId = offlineLicenseKeySetId;
  this.schemeData = offlineLicenseKeySetId == null ? schemeData : null;
  this.optionalKeyRequestParameters = optionalKeyRequestParameters;
  this.callback = callback;
  this.initialDrmRequestRetryCount = initialDrmRequestRetryCount;
  this.eventDispatcher = eventDispatcher;
  state = STATE_OPENING;

  postResponseHandler = new PostResponseHandler(playbackLooper);
  requestHandlerThread = new HandlerThread("DrmRequestHandler");
  requestHandlerThread.start();
  postRequestHandler = new PostRequestHandler(requestHandlerThread.getLooper());
}
 
Example #21
Source File: DrmInitData.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(@Nullable Object obj) {
  if (!(obj instanceof SchemeData)) {
    return false;
  }
  if (obj == this) {
    return true;
  }
  SchemeData other = (SchemeData) obj;
  return Util.areEqual(licenseServerUrl, other.licenseServerUrl)
      && Util.areEqual(mimeType, other.mimeType)
      && Util.areEqual(uuid, other.uuid)
      && Arrays.equals(data, other.data);
}
 
Example #22
Source File: FrameworkMediaDrm.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public KeyRequest getKeyRequest(
    byte[] scope,
    @Nullable List<DrmInitData.SchemeData> schemeDatas,
    int keyType,
    @Nullable HashMap<String, String> optionalParameters)
    throws NotProvisionedException {
  SchemeData schemeData = null;
  byte[] initData = null;
  String mimeType = null;
  if (schemeDatas != null) {
    schemeData = getSchemeData(uuid, schemeDatas);
    initData = adjustRequestInitData(uuid, Assertions.checkNotNull(schemeData.data));
    mimeType = adjustRequestMimeType(uuid, schemeData.mimeType);
  }
  MediaDrm.KeyRequest request =
      mediaDrm.getKeyRequest(scope, initData, mimeType, keyType, optionalParameters);

  byte[] requestData = adjustRequestData(uuid, request.getData());

  String licenseServerUrl = request.getDefaultUrl();
  if (MOCK_LA_URL_VALUE.equals(licenseServerUrl)) {
    licenseServerUrl = "";
  }
  if (TextUtils.isEmpty(licenseServerUrl)
      && schemeData != null
      && !TextUtils.isEmpty(schemeData.licenseServerUrl)) {
    licenseServerUrl = schemeData.licenseServerUrl;
  }

  return new KeyRequest(requestData, licenseServerUrl);
}
 
Example #23
Source File: DefaultDrmSessionManager.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Extracts {@link SchemeData} instances suitable for the given DRM scheme {@link UUID}.
 *
 * @param drmInitData The {@link DrmInitData} from which to extract the {@link SchemeData}.
 * @param uuid The UUID.
 * @param allowMissingData Whether a {@link SchemeData} with null {@link SchemeData#data} may be
 *     returned.
 * @return The extracted {@link SchemeData} instances, or an empty list if no suitable data is
 *     present.
 */
private static List<SchemeData> getSchemeDatas(
    DrmInitData drmInitData, UUID uuid, boolean allowMissingData) {
  // Look for matching scheme data (matching the Common PSSH box for ClearKey).
  List<SchemeData> matchingSchemeDatas = new ArrayList<>(drmInitData.schemeDataCount);
  for (int i = 0; i < drmInitData.schemeDataCount; i++) {
    SchemeData schemeData = drmInitData.get(i);
    boolean uuidMatches = schemeData.matches(uuid)
        || (C.CLEARKEY_UUID.equals(uuid) && schemeData.matches(C.COMMON_PSSH_UUID));
    if (uuidMatches && (schemeData.data != null || allowMissingData)) {
      matchingSchemeDatas.add(schemeData);
    }
  }
  return matchingSchemeDatas;
}
 
Example #24
Source File: DefaultDrmSessionManager.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Extracts {@link SchemeData} suitable for the given DRM scheme {@link UUID}.
 *
 * @param drmInitData The {@link DrmInitData} from which to extract the {@link SchemeData}.
 * @param uuid The UUID.
 * @param allowMissingData Whether a {@link SchemeData} with null {@link SchemeData#data} may be
 *     returned.
 * @return The extracted {@link SchemeData}, or null if no suitable data is present.
 */
private static SchemeData getSchemeData(DrmInitData drmInitData, UUID uuid,
    boolean allowMissingData) {
  // Look for matching scheme data (matching the Common PSSH box for ClearKey).
  List<SchemeData> matchingSchemeDatas = new ArrayList<>(drmInitData.schemeDataCount);
  for (int i = 0; i < drmInitData.schemeDataCount; i++) {
    SchemeData schemeData = drmInitData.get(i);
    boolean uuidMatches = schemeData.matches(uuid)
        || (C.CLEARKEY_UUID.equals(uuid) && schemeData.matches(C.COMMON_PSSH_UUID));
    if (uuidMatches && (schemeData.data != null || allowMissingData)) {
      matchingSchemeDatas.add(schemeData);
    }
  }

  if (matchingSchemeDatas.isEmpty()) {
    return null;
  }

  // For Widevine PSSH boxes, prefer V1 boxes from API 23 and V0 before.
  if (C.WIDEVINE_UUID.equals(uuid)) {
    for (int i = 0; i < matchingSchemeDatas.size(); i++) {
      SchemeData matchingSchemeData = matchingSchemeDatas.get(i);
      int version = matchingSchemeData.hasData()
          ? PsshAtomUtil.parseVersion(matchingSchemeData.data) : -1;
      if (Util.SDK_INT < 23 && version == 0) {
        return matchingSchemeData;
      } else if (Util.SDK_INT >= 23 && version == 1) {
        return matchingSchemeData;
      }
    }
  }

  // If we don't have any special handling, prefer the first matching scheme data.
  return matchingSchemeDatas.get(0);
}
 
Example #25
Source File: DrmInitData.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an instance containing the {@link #schemeDatas} from both this and {@code other}. The
 * {@link #schemeType} of the instances being merged must either match, or at least one scheme
 * type must be {@code null}.
 *
 * @param drmInitData The instance to merge.
 * @return The merged result.
 */
public DrmInitData merge(DrmInitData drmInitData) {
  Assertions.checkState(
      schemeType == null
          || drmInitData.schemeType == null
          || TextUtils.equals(schemeType, drmInitData.schemeType));
  String mergedSchemeType = schemeType != null ? this.schemeType : drmInitData.schemeType;
  SchemeData[] mergedSchemeDatas =
      Util.nullSafeArrayConcatenation(schemeDatas, drmInitData.schemeDatas);
  return new DrmInitData(mergedSchemeType, mergedSchemeDatas);
}
 
Example #26
Source File: DrmInitData.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
SchemeData(Parcel in) {
  uuid = new UUID(in.readLong(), in.readLong());
  licenseServerUrl = in.readString();
  mimeType = Util.castNonNull(in.readString());
  data = in.createByteArray();
  requiresSecureDecryption = in.readByte() != 0;
}
 
Example #27
Source File: DrmInitData.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean equals(@Nullable Object obj) {
  if (!(obj instanceof SchemeData)) {
    return false;
  }
  if (obj == this) {
    return true;
  }
  SchemeData other = (SchemeData) obj;
  return Util.areEqual(licenseServerUrl, other.licenseServerUrl)
      && Util.areEqual(mimeType, other.mimeType)
      && Util.areEqual(uuid, other.uuid)
      && Arrays.equals(data, other.data);
}
 
Example #28
Source File: DefaultDrmSession.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Instantiates a new DRM session.
 *
 * @param uuid The UUID of the drm scheme.
 * @param mediaDrm The media DRM.
 * @param provisioningManager The manager for provisioning.
 * @param schemeDatas DRM scheme datas for this session, or null if an {@code
 *     offlineLicenseKeySetId} is provided.
 * @param mode The DRM mode.
 * @param offlineLicenseKeySetId The offline license key set identifier, or null when not using
 *     offline keys.
 * @param optionalKeyRequestParameters The optional key request parameters.
 * @param callback The media DRM callback.
 * @param playbackLooper The playback looper.
 * @param eventDispatcher The dispatcher for DRM session manager events.
 * @param initialDrmRequestRetryCount The number of times to retry for initial provisioning and
 *     key request before reporting error.
 */
public DefaultDrmSession(
    UUID uuid,
    ExoMediaDrm<T> mediaDrm,
    ProvisioningManager<T> provisioningManager,
    @Nullable List<SchemeData> schemeDatas,
    @DefaultDrmSessionManager.Mode int mode,
    @Nullable byte[] offlineLicenseKeySetId,
    @Nullable HashMap<String, String> optionalKeyRequestParameters,
    MediaDrmCallback callback,
    Looper playbackLooper,
    EventDispatcher<DefaultDrmSessionEventListener> eventDispatcher,
    int initialDrmRequestRetryCount) {
  if (mode == DefaultDrmSessionManager.MODE_QUERY
      || mode == DefaultDrmSessionManager.MODE_RELEASE) {
    Assertions.checkNotNull(offlineLicenseKeySetId);
  }
  this.uuid = uuid;
  this.provisioningManager = provisioningManager;
  this.mediaDrm = mediaDrm;
  this.mode = mode;
  if (offlineLicenseKeySetId != null) {
    this.offlineLicenseKeySetId = offlineLicenseKeySetId;
    this.schemeDatas = null;
  } else {
    this.schemeDatas = Collections.unmodifiableList(Assertions.checkNotNull(schemeDatas));
  }
  this.optionalKeyRequestParameters = optionalKeyRequestParameters;
  this.callback = callback;
  this.initialDrmRequestRetryCount = initialDrmRequestRetryCount;
  this.eventDispatcher = eventDispatcher;
  state = STATE_OPENING;

  postResponseHandler = new PostResponseHandler(playbackLooper);
  requestHandlerThread = new HandlerThread("DrmRequestHandler");
  requestHandlerThread.start();
  postRequestHandler = new PostRequestHandler(requestHandlerThread.getLooper());
}
 
Example #29
Source File: DrmInitData.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static boolean containsSchemeDataWithUuid(
    ArrayList<SchemeData> datas, int limit, UUID uuid) {
  for (int i = 0; i < limit; i++) {
    if (datas.get(i).uuid.equals(uuid)) {
      return true;
    }
  }
  return false;
}
 
Example #30
Source File: DrmInitData.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
SchemeData(Parcel in) {
  uuid = new UUID(in.readLong(), in.readLong());
  licenseServerUrl = in.readString();
  mimeType = in.readString();
  data = in.createByteArray();
  requiresSecureDecryption = in.readByte() != 0;
}