Java Code Examples for com.google.android.exoplayer2.util.MimeTypes#VIDEO_MP4

The following examples show how to use com.google.android.exoplayer2.util.MimeTypes#VIDEO_MP4 . 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: 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 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: 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 4
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 5
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 6
Source File: SsManifestParser.java    From K-Sonic with MIT License 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-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 8
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 9
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 10
Source File: InMemoryTranscoder.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public @NonNull MediaStream transcode(@NonNull Progress progress,
                                      @Nullable CancelationSignal cancelationSignal)
    throws IOException, EncodingException, VideoSizeException
{
  if (memoryFile != null) throw new AssertionError("Not expecting to reuse transcoder");

  float durationSec = duration / 1000f;

  NumberFormat numberFormat = NumberFormat.getInstance(Locale.US);

  Log.i(TAG, String.format(Locale.US,
                           "Transcoding:\n" +
                           "Target bitrate : %s + %s = %s\n" +
                           "Target format  : %dp\n" +
                           "Video duration : %.1fs\n" +
                           "Size limit     : %s kB\n" +
                           "Estimate       : %s kB\n" +
                           "Input size     : %s kB\n" +
                           "Input bitrate  : %s bps",
                           numberFormat.format(targetVideoBitRate),
                           numberFormat.format(AUDIO_BITRATE),
                           numberFormat.format(targetVideoBitRate + AUDIO_BITRATE),
                           outputFormat,
                           durationSec,
                           numberFormat.format(upperSizeLimit / 1024),
                           numberFormat.format(fileSizeEstimate / 1024),
                           numberFormat.format(inSize / 1024),
                           numberFormat.format(inputBitRate)));

  if (fileSizeEstimate > upperSizeLimit) {
    throw new VideoSizeException("Size constraints could not be met!");
  }

  memoryFile = MemoryFileDescriptor.newMemoryFileDescriptor(context,
                                                            "TRANSCODE",
                                                            memoryFileEstimate);
  final long startTime = System.currentTimeMillis();

  final FileDescriptor memoryFileFileDescriptor = memoryFile.getFileDescriptor();

  final MediaConverter converter = new MediaConverter();

  converter.setInput(new MediaInput.MediaDataSourceMediaInput(dataSource));
  converter.setOutput(memoryFileFileDescriptor);
  converter.setVideoResolution(outputFormat);
  converter.setVideoBitrate(targetVideoBitRate);
  converter.setAudioBitrate(AUDIO_BITRATE);

  if (options != null) {
    if (options.endTimeUs > 0) {
      long timeFrom = options.startTimeUs / 1000;
      long timeTo   = options.endTimeUs   / 1000;
      converter.setTimeRange(timeFrom, timeTo);
      Log.i(TAG, String.format(Locale.US, "Trimming:\nTotal duration: %d\nKeeping: %d..%d\nFinal duration:(%d)", duration, timeFrom, timeTo, timeTo - timeFrom));
    }
  }

  converter.setListener(percent -> {
    progress.onProgress(percent);
    return cancelationSignal != null && cancelationSignal.isCanceled();
  });

  converter.convert();

  // output details of the transcoding
  long  outSize           = memoryFile.size();
  float encodeDurationSec = (System.currentTimeMillis() - startTime) / 1000f;

  Log.i(TAG, String.format(Locale.US,
                           "Transcoding complete:\n" +
                           "Transcode time : %.1fs (%.1fx)\n" +
                           "Output size    : %s kB\n" +
                           "  of Original  : %.1f%%\n" +
                           "  of Estimate  : %.1f%%\n" +
                           "  of Memory    : %.1f%%\n" +
                           "Output bitrate : %s bps",
                           encodeDurationSec,
                           durationSec / encodeDurationSec,
                           numberFormat.format(outSize / 1024),
                           (outSize * 100d) / inSize,
                           (outSize * 100d) / fileSizeEstimate,
                           (outSize * 100d) / memoryFileEstimate,
                           numberFormat.format(bitRate(outSize, duration))));

  if (outSize > upperSizeLimit) {
    throw new VideoSizeException("Size constraints could not be met!");
  }

  memoryFile.seek(0);

  return new MediaStream(new FileInputStream(memoryFileFileDescriptor), MimeTypes.VIDEO_MP4, 0, 0);
}
 
Example 11
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 12
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 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 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 15
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);
}