Java Code Examples for com.google.android.exoplayer2.C#WIDEVINE_UUID

The following examples show how to use com.google.android.exoplayer2.C#WIDEVINE_UUID . 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: Util.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Derives a DRM {@link UUID} from {@code drmScheme}.
 *
 * @param drmScheme A UUID string, or {@code "widevine"}, {@code "playready"} or {@code
 *     "clearkey"}.
 * @return The derived {@link UUID}, or {@code null} if one could not be derived.
 */
public static @Nullable UUID getDrmUuid(String drmScheme) {
  switch (toLowerInvariant(drmScheme)) {
    case "widevine":
      return C.WIDEVINE_UUID;
    case "playready":
      return C.PLAYREADY_UUID;
    case "clearkey":
      return C.CLEARKEY_UUID;
    default:
      try {
        return UUID.fromString(drmScheme);
      } catch (RuntimeException e) {
        return null;
      }
  }
}
 
Example 2
Source File: Util.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Derives a DRM {@link UUID} from {@code drmScheme}.
 *
 * @param drmScheme A UUID string, or {@code "widevine"}, {@code "playready"} or {@code
 *     "clearkey"}.
 * @return The derived {@link UUID}, or {@code null} if one could not be derived.
 */
public static @Nullable UUID getDrmUuid(String drmScheme) {
  switch (toLowerInvariant(drmScheme)) {
    case "widevine":
      return C.WIDEVINE_UUID;
    case "playready":
      return C.PLAYREADY_UUID;
    case "clearkey":
      return C.CLEARKEY_UUID;
    default:
      try {
        return UUID.fromString(drmScheme);
      } catch (RuntimeException e) {
        return null;
      }
  }
}
 
Example 3
Source File: Util.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Derives a DRM {@link UUID} from {@code drmScheme}.
 *
 * @param drmScheme A UUID string, or {@code "widevine"}, {@code "playready"} or {@code
 *     "clearkey"}.
 * @return The derived {@link UUID}, or {@code null} if one could not be derived.
 */
public static @Nullable UUID getDrmUuid(String drmScheme) {
  switch (toLowerInvariant(drmScheme)) {
    case "widevine":
      return C.WIDEVINE_UUID;
    case "playready":
      return C.PLAYREADY_UUID;
    case "clearkey":
      return C.CLEARKEY_UUID;
    default:
      try {
        return UUID.fromString(drmScheme);
      } catch (RuntimeException e) {
        return null;
      }
  }
}
 
Example 4
Source File: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
/**
 * Generates the {@link DrmSessionManager} to use with the {@link RendererProvider}. This will
 * return null on API's < {@value Build.VERSION_CODES#JELLY_BEAN_MR2}
 *
 * @return The {@link DrmSessionManager} to use or <code>null</code>
 */
@Nullable
protected DrmSessionManager<FrameworkMediaCrypto> generateDrmSessionManager() {
    // DRM is only supported on API 18 + in the ExoPlayer
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
        return null;
    }

    // Widevine will capture the majority of use cases however playready is supported on all AndroidTV devices
    UUID uuid = C.WIDEVINE_UUID;

    try {
        DefaultDrmSessionManager<FrameworkMediaCrypto> sessionManager = new DefaultDrmSessionManager<>(uuid, FrameworkMediaDrm.newInstance(uuid), new DelegatedMediaDrmCallback(), null);
        sessionManager.addListener(mainHandler, capabilitiesListener);

        return sessionManager;
    } catch (Exception e) {
        Log.d(TAG, "Unable to create a DrmSessionManager due to an exception", e);
        return null;
    }
}
 
Example 5
Source File: Util.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Derives a DRM {@link UUID} from {@code drmScheme}.
 *
 * @param drmScheme A UUID string, or {@code "widevine"}, {@code "playready"} or {@code
 *     "clearkey"}.
 * @return The derived {@link UUID}, or {@code null} if one could not be derived.
 */
public static @Nullable UUID getDrmUuid(String drmScheme) {
  switch (Util.toLowerInvariant(drmScheme)) {
    case "widevine":
      return C.WIDEVINE_UUID;
    case "playready":
      return C.PLAYREADY_UUID;
    case "clearkey":
      return C.CLEARKEY_UUID;
    default:
      try {
        return UUID.fromString(drmScheme);
      } catch (RuntimeException e) {
        return null;
      }
  }
}
 
Example 6
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 7
Source File: Util.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Derives a DRM {@link UUID} from {@code drmScheme}.
 *
 * @param drmScheme A UUID string, or {@code "widevine"}, {@code "playready"} or {@code
 *     "clearkey"}.
 * @return The derived {@link UUID}, or {@code null} if one could not be derived.
 */
public static @Nullable UUID getDrmUuid(String drmScheme) {
  switch (Util.toLowerInvariant(drmScheme)) {
    case "widevine":
      return C.WIDEVINE_UUID;
    case "playready":
      return C.PLAYREADY_UUID;
    case "clearkey":
      return C.CLEARKEY_UUID;
    default:
      try {
        return UUID.fromString(drmScheme);
      } catch (RuntimeException e) {
        return null;
      }
  }
}
 
Example 8
Source File: OfflineLicenseHelper.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Constructs an instance. Call {@link #releaseResources()} when you're done with it.
 *
 * @param mediaDrm An underlying {@link ExoMediaDrm} for use by the manager.
 * @param callback Performs key and provisioning requests.
 * @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument
 *     to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null.
 * @see DefaultDrmSessionManager#DefaultDrmSessionManager(java.util.UUID, ExoMediaDrm,
 *     MediaDrmCallback, HashMap, Handler, EventListener)
 */
public OfflineLicenseHelper(ExoMediaDrm<T> mediaDrm, MediaDrmCallback callback,
    HashMap<String, String> optionalKeyRequestParameters) {
  handlerThread = new HandlerThread("OfflineLicenseHelper");
  handlerThread.start();

  conditionVariable = new ConditionVariable();
  EventListener eventListener = new EventListener() {
    @Override
    public void onDrmKeysLoaded() {
      conditionVariable.open();
    }

    @Override
    public void onDrmSessionManagerError(Exception e) {
      conditionVariable.open();
    }

    @Override
    public void onDrmKeysRestored() {
      conditionVariable.open();
    }

    @Override
    public void onDrmKeysRemoved() {
      conditionVariable.open();
    }
  };
  drmSessionManager = new DefaultDrmSessionManager<>(C.WIDEVINE_UUID, mediaDrm, callback,
      optionalKeyRequestParameters, new Handler(handlerThread.getLooper()), eventListener);
}
 
Example 9
Source File: SampleChooserActivity.java    From ExoPlayer-Offline with Apache License 2.0 5 votes vote down vote up
private UUID getDrmUuid(String typeString) throws ParserException {
  switch (typeString.toLowerCase()) {
    case "widevine":
      return C.WIDEVINE_UUID;
    case "playready":
      return C.PLAYREADY_UUID;
    default:
      try {
        return UUID.fromString(typeString);
      } catch (RuntimeException e) {
        throw new ParserException("Unsupported drm type: " + typeString);
      }
  }
}
 
Example 10
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 4 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 The scheme type and/or {@link SchemeData} parsed from the ContentProtection element.
 *     Either or both may be null, depending on the ContentProtection element being parsed.
 */
protected Pair<String, SchemeData> parseContentProtection(XmlPullParser xpp)
    throws XmlPullParserException, IOException {
  String schemeType = null;
  String licenseServerUrl = null;
  byte[] data = null;
  UUID uuid = null;
  boolean requiresSecureDecoder = false;

  String schemeIdUri = xpp.getAttributeValue(null, "schemeIdUri");
  if (schemeIdUri != null) {
    switch (Util.toLowerInvariant(schemeIdUri)) {
      case "urn:mpeg:dash:mp4protection:2011":
        schemeType = xpp.getAttributeValue(null, "value");
        String defaultKid = xpp.getAttributeValue(null, "cenc:default_KID");
        if (!TextUtils.isEmpty(defaultKid)
            && !"00000000-0000-0000-0000-000000000000".equals(defaultKid)) {
          String[] defaultKidStrings = defaultKid.split("\\s+");
          UUID[] defaultKids = new UUID[defaultKidStrings.length];
          for (int i = 0; i < defaultKidStrings.length; i++) {
            defaultKids[i] = UUID.fromString(defaultKidStrings[i]);
          }
          data = PsshAtomUtil.buildPsshAtom(C.COMMON_PSSH_UUID, defaultKids, null);
          uuid = C.COMMON_PSSH_UUID;
        }
        break;
      case "urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95":
        uuid = C.PLAYREADY_UUID;
        break;
      case "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed":
        uuid = C.WIDEVINE_UUID;
        break;
      default:
        break;
    }
  }

  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "ms:laurl")) {
      licenseServerUrl = xpp.getAttributeValue(null, "licenseUrl");
    } else if (XmlPullParserUtil.isStartTag(xpp, "widevine:license")) {
      String robustnessLevel = xpp.getAttributeValue(null, "robustness_level");
      requiresSecureDecoder = robustnessLevel != null && robustnessLevel.startsWith("HW");
    } else if (data == null) {
      if (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 (C.PLAYREADY_UUID.equals(uuid) && 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));
      }
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "ContentProtection"));
  SchemeData schemeData =
      uuid != null
          ? new SchemeData(
              uuid, licenseServerUrl, MimeTypes.VIDEO_MP4, data, requiresSecureDecoder)
          : null;
  return Pair.create(schemeType, schemeData);
}
 
Example 11
Source File: DashManifestParser.java    From Telegram with GNU General Public License v2.0 4 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 The scheme type and/or {@link SchemeData} parsed from the ContentProtection element.
 *     Either or both may be null, depending on the ContentProtection element being parsed.
 */
protected Pair<String, SchemeData> parseContentProtection(XmlPullParser xpp)
    throws XmlPullParserException, IOException {
  String schemeType = null;
  String licenseServerUrl = null;
  byte[] data = null;
  UUID uuid = null;
  boolean requiresSecureDecoder = false;

  String schemeIdUri = xpp.getAttributeValue(null, "schemeIdUri");
  if (schemeIdUri != null) {
    switch (Util.toLowerInvariant(schemeIdUri)) {
      case "urn:mpeg:dash:mp4protection:2011":
        schemeType = xpp.getAttributeValue(null, "value");
        String defaultKid = XmlPullParserUtil.getAttributeValueIgnorePrefix(xpp, "default_KID");
        if (!TextUtils.isEmpty(defaultKid)
            && !"00000000-0000-0000-0000-000000000000".equals(defaultKid)) {
          String[] defaultKidStrings = defaultKid.split("\\s+");
          UUID[] defaultKids = new UUID[defaultKidStrings.length];
          for (int i = 0; i < defaultKidStrings.length; i++) {
            defaultKids[i] = UUID.fromString(defaultKidStrings[i]);
          }
          data = PsshAtomUtil.buildPsshAtom(C.COMMON_PSSH_UUID, defaultKids, null);
          uuid = C.COMMON_PSSH_UUID;
        }
        break;
      case "urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95":
        uuid = C.PLAYREADY_UUID;
        break;
      case "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed":
        uuid = C.WIDEVINE_UUID;
        break;
      default:
        break;
    }
  }

  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "ms:laurl")) {
      licenseServerUrl = xpp.getAttributeValue(null, "licenseUrl");
    } else if (XmlPullParserUtil.isStartTag(xpp, "widevine:license")) {
      String robustnessLevel = xpp.getAttributeValue(null, "robustness_level");
      requiresSecureDecoder = robustnessLevel != null && robustnessLevel.startsWith("HW");
    } else if (data == null
        && XmlPullParserUtil.isStartTagIgnorePrefix(xpp, "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
        && C.PLAYREADY_UUID.equals(uuid)
        && 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));
    } else {
      maybeSkipTag(xpp);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "ContentProtection"));
  SchemeData schemeData =
      uuid != null
          ? new SchemeData(
              uuid, licenseServerUrl, MimeTypes.VIDEO_MP4, data, requiresSecureDecoder)
          : null;
  return Pair.create(schemeType, schemeData);
}
 
Example 12
Source File: DashManifestParser.java    From Telegram-FOSS with GNU General Public License v2.0 4 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 The scheme type and/or {@link SchemeData} parsed from the ContentProtection element.
 *     Either or both may be null, depending on the ContentProtection element being parsed.
 */
protected Pair<String, SchemeData> parseContentProtection(XmlPullParser xpp)
    throws XmlPullParserException, IOException {
  String schemeType = null;
  String licenseServerUrl = null;
  byte[] data = null;
  UUID uuid = null;
  boolean requiresSecureDecoder = false;

  String schemeIdUri = xpp.getAttributeValue(null, "schemeIdUri");
  if (schemeIdUri != null) {
    switch (Util.toLowerInvariant(schemeIdUri)) {
      case "urn:mpeg:dash:mp4protection:2011":
        schemeType = xpp.getAttributeValue(null, "value");
        String defaultKid = XmlPullParserUtil.getAttributeValueIgnorePrefix(xpp, "default_KID");
        if (!TextUtils.isEmpty(defaultKid)
            && !"00000000-0000-0000-0000-000000000000".equals(defaultKid)) {
          String[] defaultKidStrings = defaultKid.split("\\s+");
          UUID[] defaultKids = new UUID[defaultKidStrings.length];
          for (int i = 0; i < defaultKidStrings.length; i++) {
            defaultKids[i] = UUID.fromString(defaultKidStrings[i]);
          }
          data = PsshAtomUtil.buildPsshAtom(C.COMMON_PSSH_UUID, defaultKids, null);
          uuid = C.COMMON_PSSH_UUID;
        }
        break;
      case "urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95":
        uuid = C.PLAYREADY_UUID;
        break;
      case "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed":
        uuid = C.WIDEVINE_UUID;
        break;
      default:
        break;
    }
  }

  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "ms:laurl")) {
      licenseServerUrl = xpp.getAttributeValue(null, "licenseUrl");
    } else if (XmlPullParserUtil.isStartTag(xpp, "widevine:license")) {
      String robustnessLevel = xpp.getAttributeValue(null, "robustness_level");
      requiresSecureDecoder = robustnessLevel != null && robustnessLevel.startsWith("HW");
    } else if (data == null
        && XmlPullParserUtil.isStartTagIgnorePrefix(xpp, "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
        && C.PLAYREADY_UUID.equals(uuid)
        && 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));
    } else {
      maybeSkipTag(xpp);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "ContentProtection"));
  SchemeData schemeData =
      uuid != null
          ? new SchemeData(
              uuid, licenseServerUrl, MimeTypes.VIDEO_MP4, data, requiresSecureDecoder)
          : null;
  return Pair.create(schemeType, schemeData);
}
 
Example 13
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 4 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 The scheme type and/or {@link SchemeData} parsed from the ContentProtection element.
 *     Either or both may be null, depending on the ContentProtection element being parsed.
 */
protected Pair<String, SchemeData> parseContentProtection(XmlPullParser xpp)
    throws XmlPullParserException, IOException {
  String schemeType = null;
  String licenseServerUrl = null;
  byte[] data = null;
  UUID uuid = null;
  boolean requiresSecureDecoder = false;

  String schemeIdUri = xpp.getAttributeValue(null, "schemeIdUri");
  if (schemeIdUri != null) {
    switch (Util.toLowerInvariant(schemeIdUri)) {
      case "urn:mpeg:dash:mp4protection:2011":
        schemeType = xpp.getAttributeValue(null, "value");
        String defaultKid = xpp.getAttributeValue(null, "cenc:default_KID");
        if (!TextUtils.isEmpty(defaultKid)
            && !"00000000-0000-0000-0000-000000000000".equals(defaultKid)) {
          String[] defaultKidStrings = defaultKid.split("\\s+");
          UUID[] defaultKids = new UUID[defaultKidStrings.length];
          for (int i = 0; i < defaultKidStrings.length; i++) {
            defaultKids[i] = UUID.fromString(defaultKidStrings[i]);
          }
          data = PsshAtomUtil.buildPsshAtom(C.COMMON_PSSH_UUID, defaultKids, null);
          uuid = C.COMMON_PSSH_UUID;
        }
        break;
      case "urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95":
        uuid = C.PLAYREADY_UUID;
        break;
      case "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed":
        uuid = C.WIDEVINE_UUID;
        break;
      default:
        break;
    }
  }

  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "ms:laurl")) {
      licenseServerUrl = xpp.getAttributeValue(null, "licenseUrl");
    } else if (XmlPullParserUtil.isStartTag(xpp, "widevine:license")) {
      String robustnessLevel = xpp.getAttributeValue(null, "robustness_level");
      requiresSecureDecoder = robustnessLevel != null && robustnessLevel.startsWith("HW");
    } else if (data == null) {
      if (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 (C.PLAYREADY_UUID.equals(uuid) && 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));
      }
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "ContentProtection"));
  SchemeData schemeData =
      uuid != null
          ? new SchemeData(
              uuid, licenseServerUrl, MimeTypes.VIDEO_MP4, data, requiresSecureDecoder)
          : null;
  return Pair.create(schemeType, schemeData);
}
 
Example 14
Source File: DashManifestParser.java    From MediaSDK with Apache License 2.0 4 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 The scheme type and/or {@link SchemeData} parsed from the ContentProtection element.
 *     Either or both may be null, depending on the ContentProtection element being parsed.
 */
protected Pair<@NullableType String, @NullableType SchemeData> parseContentProtection(
    XmlPullParser xpp) throws XmlPullParserException, IOException {
  String schemeType = null;
  String licenseServerUrl = null;
  byte[] data = null;
  UUID uuid = null;

  String schemeIdUri = xpp.getAttributeValue(null, "schemeIdUri");
  if (schemeIdUri != null) {
    switch (Util.toLowerInvariant(schemeIdUri)) {
      case "urn:mpeg:dash:mp4protection:2011":
        schemeType = xpp.getAttributeValue(null, "value");
        String defaultKid = XmlPullParserUtil.getAttributeValueIgnorePrefix(xpp, "default_KID");
        if (!TextUtils.isEmpty(defaultKid)
            && !"00000000-0000-0000-0000-000000000000".equals(defaultKid)) {
          String[] defaultKidStrings = defaultKid.split("\\s+");
          UUID[] defaultKids = new UUID[defaultKidStrings.length];
          for (int i = 0; i < defaultKidStrings.length; i++) {
            defaultKids[i] = UUID.fromString(defaultKidStrings[i]);
          }
          data = PsshAtomUtil.buildPsshAtom(C.COMMON_PSSH_UUID, defaultKids, null);
          uuid = C.COMMON_PSSH_UUID;
        }
        break;
      case "urn:uuid:9a04f079-9840-4286-ab92-e65be0885f95":
        uuid = C.PLAYREADY_UUID;
        break;
      case "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed":
        uuid = C.WIDEVINE_UUID;
        break;
      default:
        break;
    }
  }

  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "ms:laurl")) {
      licenseServerUrl = xpp.getAttributeValue(null, "licenseUrl");
    } else if (data == null
        && XmlPullParserUtil.isStartTagIgnorePrefix(xpp, "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
        && C.PLAYREADY_UUID.equals(uuid)
        && 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));
    } else {
      maybeSkipTag(xpp);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "ContentProtection"));
  SchemeData schemeData =
      uuid != null ? new SchemeData(uuid, licenseServerUrl, MimeTypes.VIDEO_MP4, data) : null;
  return Pair.create(schemeType, schemeData);
}
 
Example 15
Source File: DefaultDrmSessionManager.java    From MediaSDK with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a builder with default values. The default values are:
 *
 * <ul>
 *   <li>{@link #setKeyRequestParameters keyRequestParameters}: An empty map.
 *   <li>{@link #setUuidAndExoMediaDrmProvider UUID}: {@link C#WIDEVINE_UUID}.
 *   <li>{@link #setUuidAndExoMediaDrmProvider ExoMediaDrm.Provider}: {@link
 *       FrameworkMediaDrm#DEFAULT_PROVIDER}.
 *   <li>{@link #setMultiSession multiSession}: {@code false}.
 *   <li>{@link #setUseDrmSessionsForClearContent useDrmSessionsForClearContent}: No tracks.
 *   <li>{@link #setPlayClearSamplesWithoutKeys playClearSamplesWithoutKeys}: {@code false}.
 *   <li>{@link #setLoadErrorHandlingPolicy LoadErrorHandlingPolicy}: {@link
 *       DefaultLoadErrorHandlingPolicy}.
 * </ul>
 */
@SuppressWarnings("unchecked")
public Builder() {
  keyRequestParameters = new HashMap<>();
  uuid = C.WIDEVINE_UUID;
  exoMediaDrmProvider = (ExoMediaDrm.Provider) FrameworkMediaDrm.DEFAULT_PROVIDER;
  loadErrorHandlingPolicy = new DefaultLoadErrorHandlingPolicy();
  useDrmSessionsForClearContentTrackTypes = new int[0];
}
 
Example 16
Source File: OfflineLicenseHelper.java    From TelePlus-Android with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiates a new instance which uses Widevine CDM. Call {@link #release()} when the instance
 * is no longer required.
 *
 * @param defaultLicenseUrl The default license URL. Used for key requests that do not specify
 *     their own license URL.
 * @param forceDefaultLicenseUrl Whether to use {@code defaultLicenseUrl} for key requests that
 *     include their own license URL.
 * @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument
 *     to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null.
 * @return A new instance which uses Widevine CDM.
 * @throws UnsupportedDrmException If the Widevine DRM scheme is unsupported or cannot be
 *     instantiated.
 * @see DefaultDrmSessionManager#DefaultDrmSessionManager(java.util.UUID, ExoMediaDrm,
 *     MediaDrmCallback, HashMap, Handler, DefaultDrmSessionEventListener)
 */
public static OfflineLicenseHelper<FrameworkMediaCrypto> newWidevineInstance(
    String defaultLicenseUrl,
    boolean forceDefaultLicenseUrl,
    Factory httpDataSourceFactory,
    HashMap<String, String> optionalKeyRequestParameters)
    throws UnsupportedDrmException {
  return new OfflineLicenseHelper<>(C.WIDEVINE_UUID,
      FrameworkMediaDrm.newInstance(C.WIDEVINE_UUID),
      new HttpMediaDrmCallback(defaultLicenseUrl, forceDefaultLicenseUrl, httpDataSourceFactory),
      optionalKeyRequestParameters);
}
 
Example 17
Source File: OfflineLicenseHelper.java    From Telegram-FOSS with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiates a new instance which uses Widevine CDM. Call {@link #release()} when the instance
 * is no longer required.
 *
 * @param defaultLicenseUrl The default license URL. Used for key requests that do not specify
 *     their own license URL.
 * @param forceDefaultLicenseUrl Whether to use {@code defaultLicenseUrl} for key requests that
 *     include their own license URL.
 * @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument
 *     to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null.
 * @return A new instance which uses Widevine CDM.
 * @throws UnsupportedDrmException If the Widevine DRM scheme is unsupported or cannot be
 *     instantiated.
 * @see DefaultDrmSessionManager#DefaultDrmSessionManager(java.util.UUID, ExoMediaDrm,
 *     MediaDrmCallback, HashMap)
 */
public static OfflineLicenseHelper<FrameworkMediaCrypto> newWidevineInstance(
    String defaultLicenseUrl,
    boolean forceDefaultLicenseUrl,
    Factory httpDataSourceFactory,
    @Nullable HashMap<String, String> optionalKeyRequestParameters)
    throws UnsupportedDrmException {
  return new OfflineLicenseHelper<>(C.WIDEVINE_UUID,
      FrameworkMediaDrm.newInstance(C.WIDEVINE_UUID),
      new HttpMediaDrmCallback(defaultLicenseUrl, forceDefaultLicenseUrl, httpDataSourceFactory),
      optionalKeyRequestParameters);
}
 
Example 18
Source File: OfflineLicenseHelper.java    From TelePlus-Android with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiates a new instance which uses Widevine CDM. Call {@link #release()} when the instance
 * is no longer required.
 *
 * @param defaultLicenseUrl The default license URL. Used for key requests that do not specify
 *     their own license URL.
 * @param forceDefaultLicenseUrl Whether to use {@code defaultLicenseUrl} for key requests that
 *     include their own license URL.
 * @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument
 *     to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null.
 * @return A new instance which uses Widevine CDM.
 * @throws UnsupportedDrmException If the Widevine DRM scheme is unsupported or cannot be
 *     instantiated.
 * @see DefaultDrmSessionManager#DefaultDrmSessionManager(java.util.UUID, ExoMediaDrm,
 *     MediaDrmCallback, HashMap, Handler, DefaultDrmSessionEventListener)
 */
public static OfflineLicenseHelper<FrameworkMediaCrypto> newWidevineInstance(
    String defaultLicenseUrl,
    boolean forceDefaultLicenseUrl,
    Factory httpDataSourceFactory,
    HashMap<String, String> optionalKeyRequestParameters)
    throws UnsupportedDrmException {
  return new OfflineLicenseHelper<>(C.WIDEVINE_UUID,
      FrameworkMediaDrm.newInstance(C.WIDEVINE_UUID),
      new HttpMediaDrmCallback(defaultLicenseUrl, forceDefaultLicenseUrl, httpDataSourceFactory),
      optionalKeyRequestParameters);
}
 
Example 19
Source File: OfflineLicenseHelper.java    From Telegram with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Instantiates a new instance which uses Widevine CDM. Call {@link #release()} when the instance
 * is no longer required.
 *
 * @param defaultLicenseUrl The default license URL. Used for key requests that do not specify
 *     their own license URL.
 * @param forceDefaultLicenseUrl Whether to use {@code defaultLicenseUrl} for key requests that
 *     include their own license URL.
 * @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument
 *     to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null.
 * @return A new instance which uses Widevine CDM.
 * @throws UnsupportedDrmException If the Widevine DRM scheme is unsupported or cannot be
 *     instantiated.
 * @see DefaultDrmSessionManager#DefaultDrmSessionManager(java.util.UUID, ExoMediaDrm,
 *     MediaDrmCallback, HashMap)
 */
public static OfflineLicenseHelper<FrameworkMediaCrypto> newWidevineInstance(
    String defaultLicenseUrl,
    boolean forceDefaultLicenseUrl,
    Factory httpDataSourceFactory,
    @Nullable HashMap<String, String> optionalKeyRequestParameters)
    throws UnsupportedDrmException {
  return new OfflineLicenseHelper<>(C.WIDEVINE_UUID,
      FrameworkMediaDrm.newInstance(C.WIDEVINE_UUID),
      new HttpMediaDrmCallback(defaultLicenseUrl, forceDefaultLicenseUrl, httpDataSourceFactory),
      optionalKeyRequestParameters);
}
 
Example 20
Source File: OfflineLicenseHelper.java    From MediaSDK with Apache License 2.0 3 votes vote down vote up
/**
 * Instantiates a new instance which uses Widevine CDM. Call {@link #release()} when the instance
 * is no longer required.
 *
 * @param defaultLicenseUrl The default license URL. Used for key requests that do not specify
 *     their own license URL.
 * @param forceDefaultLicenseUrl Whether to use {@code defaultLicenseUrl} for key requests that
 *     include their own license URL.
 * @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument
 *     to {@link MediaDrm#getKeyRequest}. May be null.
 * @return A new instance which uses Widevine CDM.
 * @throws UnsupportedDrmException If the Widevine DRM scheme is unsupported or cannot be
 *     instantiated.
 * @see DefaultDrmSessionManager.Builder
 */
public static OfflineLicenseHelper<FrameworkMediaCrypto> newWidevineInstance(
    String defaultLicenseUrl,
    boolean forceDefaultLicenseUrl,
    Factory httpDataSourceFactory,
    @Nullable Map<String, String> optionalKeyRequestParameters)
    throws UnsupportedDrmException {
  return new OfflineLicenseHelper<>(
      C.WIDEVINE_UUID,
      FrameworkMediaDrm.DEFAULT_PROVIDER,
      new HttpMediaDrmCallback(defaultLicenseUrl, forceDefaultLicenseUrl, httpDataSourceFactory),
      optionalKeyRequestParameters);
}