com.google.android.exoplayer2.util.XmlPullParserUtil Java Examples

The following examples show how to use com.google.android.exoplayer2.util.XmlPullParserUtil. 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: DashManifestParser.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
protected ProgramInformation parseProgramInformation(XmlPullParser xpp)
    throws IOException, XmlPullParserException {
  String title = null;
  String source = null;
  String copyright = null;
  String moreInformationURL = parseString(xpp, "moreInformationURL", null);
  String lang = parseString(xpp, "lang", null);
  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "Title")) {
      title = xpp.nextText();
    } else if (XmlPullParserUtil.isStartTag(xpp, "Source")) {
      source = xpp.nextText();
    } else if (XmlPullParserUtil.isStartTag(xpp, "Copyright")) {
      copyright = xpp.nextText();
    } else {
      maybeSkipTag(xpp);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "ProgramInformation"));
  return new ProgramInformation(title, source, copyright, moreInformationURL, lang);
}
 
Example #2
Source File: DashManifestParser.java    From K-Sonic with MIT License 6 votes vote down vote up
protected List<SegmentTimelineElement> parseSegmentTimeline(XmlPullParser xpp)
    throws XmlPullParserException, IOException {
  List<SegmentTimelineElement> segmentTimeline = new ArrayList<>();
  long elapsedTime = 0;
  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "S")) {
      elapsedTime = parseLong(xpp, "t", elapsedTime);
      long duration = parseLong(xpp, "d", C.TIME_UNSET);
      int count = 1 + parseInt(xpp, "r", 0);
      for (int i = 0; i < count; i++) {
        segmentTimeline.add(buildSegmentTimelineElement(elapsedTime, duration));
        elapsedTime += duration;
      }
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "SegmentTimeline"));
  return segmentTimeline;
}
 
Example #3
Source File: TtmlDecoder.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private TtsExtent parseTtsExtent(XmlPullParser xmlParser) {
  String ttsExtent = XmlPullParserUtil.getAttributeValue(xmlParser, TtmlNode.ATTR_TTS_EXTENT);
  if (ttsExtent == null) {
    return null;
  }

  Matcher extentMatcher = PIXEL_COORDINATES.matcher(ttsExtent);
  if (!extentMatcher.matches()) {
    Log.w(TAG, "Ignoring non-pixel tts extent: " + ttsExtent);
    return null;
  }
  try {
    int width = Integer.parseInt(extentMatcher.group(1));
    int height = Integer.parseInt(extentMatcher.group(2));
    return new TtsExtent(width, height);
  } catch (NumberFormatException e) {
    Log.w(TAG, "Ignoring malformed tts extent: " + ttsExtent);
    return null;
  }
}
 
Example #4
Source File: TtmlDecoder.java    From K-Sonic with MIT License 6 votes vote down vote up
private Map<String, TtmlStyle> parseHeader(XmlPullParser xmlParser,
    Map<String, TtmlStyle> globalStyles, Map<String, TtmlRegion> globalRegions)
    throws IOException, XmlPullParserException {
  do {
    xmlParser.next();
    if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_STYLE)) {
      String parentStyleId = XmlPullParserUtil.getAttributeValue(xmlParser, ATTR_STYLE);
      TtmlStyle style = parseStyleAttributes(xmlParser, new TtmlStyle());
      if (parentStyleId != null) {
        for (String id : parseStyleIds(parentStyleId)) {
          style.chain(globalStyles.get(id));
        }
      }
      if (style.getId() != null) {
        globalStyles.put(style.getId(), style);
      }
    } else if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_REGION)) {
      Pair<String, TtmlRegion> ttmlRegionInfo = parseRegionAttributes(xmlParser);
      if (ttmlRegionInfo != null) {
        globalRegions.put(ttmlRegionInfo.first, ttmlRegionInfo.second);
      }
    }
  } while (!XmlPullParserUtil.isEndTag(xmlParser, TtmlNode.TAG_HEAD));
  return globalStyles;
}
 
Example #5
Source File: DashManifestParser.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
protected ProgramInformation parseProgramInformation(XmlPullParser xpp)
    throws IOException, XmlPullParserException {
  String title = null;
  String source = null;
  String copyright = null;
  String moreInformationURL = parseString(xpp, "moreInformationURL", null);
  String lang = parseString(xpp, "lang", null);
  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "Title")) {
      title = xpp.nextText();
    } else if (XmlPullParserUtil.isStartTag(xpp, "Source")) {
      source = xpp.nextText();
    } else if (XmlPullParserUtil.isStartTag(xpp, "Copyright")) {
      copyright = xpp.nextText();
    } else {
      maybeSkipTag(xpp);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "ProgramInformation"));
  return new ProgramInformation(title, source, copyright, moreInformationURL, lang);
}
 
Example #6
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
protected List<SegmentTimelineElement> parseSegmentTimeline(XmlPullParser xpp)
    throws XmlPullParserException, IOException {
  List<SegmentTimelineElement> segmentTimeline = new ArrayList<>();
  long elapsedTime = 0;
  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "S")) {
      elapsedTime = parseLong(xpp, "t", elapsedTime);
      long duration = parseLong(xpp, "d", C.TIME_UNSET);
      int count = 1 + parseInt(xpp, "r", 0);
      for (int i = 0; i < count; i++) {
        segmentTimeline.add(buildSegmentTimelineElement(elapsedTime, duration));
        elapsedTime += duration;
      }
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "SegmentTimeline"));
  return segmentTimeline;
}
 
Example #7
Source File: DashManifestParser.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
protected List<SegmentTimelineElement> parseSegmentTimeline(XmlPullParser xpp)
    throws XmlPullParserException, IOException {
  List<SegmentTimelineElement> segmentTimeline = new ArrayList<>();
  long elapsedTime = 0;
  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "S")) {
      elapsedTime = parseLong(xpp, "t", elapsedTime);
      long duration = parseLong(xpp, "d", C.TIME_UNSET);
      int count = 1 + parseInt(xpp, "r", 0);
      for (int i = 0; i < count; i++) {
        segmentTimeline.add(buildSegmentTimelineElement(elapsedTime, duration));
        elapsedTime += duration;
      }
    } else {
      maybeSkipTag(xpp);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "SegmentTimeline"));
  return segmentTimeline;
}
 
Example #8
Source File: DashManifestParser.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
protected ProgramInformation parseProgramInformation(XmlPullParser xpp)
    throws IOException, XmlPullParserException {
  String title = null;
  String source = null;
  String copyright = null;
  String moreInformationURL = parseString(xpp, "moreInformationURL", null);
  String lang = parseString(xpp, "lang", null);
  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "Title")) {
      title = xpp.nextText();
    } else if (XmlPullParserUtil.isStartTag(xpp, "Source")) {
      source = xpp.nextText();
    } else if (XmlPullParserUtil.isStartTag(xpp, "Copyright")) {
      copyright = xpp.nextText();
    } else {
      maybeSkipTag(xpp);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "ProgramInformation"));
  return new ProgramInformation(title, source, copyright, moreInformationURL, lang);
}
 
Example #9
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
protected List<SegmentTimelineElement> parseSegmentTimeline(XmlPullParser xpp)
    throws XmlPullParserException, IOException {
  List<SegmentTimelineElement> segmentTimeline = new ArrayList<>();
  long elapsedTime = 0;
  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "S")) {
      elapsedTime = parseLong(xpp, "t", elapsedTime);
      long duration = parseLong(xpp, "d", C.TIME_UNSET);
      int count = 1 + parseInt(xpp, "r", 0);
      for (int i = 0; i < count; i++) {
        segmentTimeline.add(buildSegmentTimelineElement(elapsedTime, duration));
        elapsedTime += duration;
      }
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "SegmentTimeline"));
  return segmentTimeline;
}
 
Example #10
Source File: TtmlDecoder.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private TtsExtent parseTtsExtent(XmlPullParser xmlParser) {
  String ttsExtent = XmlPullParserUtil.getAttributeValue(xmlParser, TtmlNode.ATTR_TTS_EXTENT);
  if (ttsExtent == null) {
    return null;
  }

  Matcher extentMatcher = PIXEL_COORDINATES.matcher(ttsExtent);
  if (!extentMatcher.matches()) {
    Log.w(TAG, "Ignoring non-pixel tts extent: " + ttsExtent);
    return null;
  }
  try {
    int width = Integer.parseInt(extentMatcher.group(1));
    int height = Integer.parseInt(extentMatcher.group(2));
    return new TtsExtent(width, height);
  } catch (NumberFormatException e) {
    Log.w(TAG, "Ignoring malformed tts extent: " + ttsExtent);
    return null;
  }
}
 
Example #11
Source File: TtmlDecoder.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private TtsExtent parseTtsExtent(XmlPullParser xmlParser) {
  String ttsExtent = XmlPullParserUtil.getAttributeValue(xmlParser, TtmlNode.ATTR_TTS_EXTENT);
  if (ttsExtent == null) {
    return null;
  }

  Matcher extentMatcher = PIXEL_COORDINATES.matcher(ttsExtent);
  if (!extentMatcher.matches()) {
    Log.w(TAG, "Ignoring non-pixel tts extent: " + ttsExtent);
    return null;
  }
  try {
    int width = Integer.parseInt(extentMatcher.group(1));
    int height = Integer.parseInt(extentMatcher.group(2));
    return new TtsExtent(width, height);
  } catch (NumberFormatException e) {
    Log.w(TAG, "Ignoring malformed tts extent: " + ttsExtent);
    return null;
  }
}
 
Example #12
Source File: DashManifestParser.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * If the provided {@link XmlPullParser} is currently positioned at the start of a tag, skips
 * forward to the end of that tag.
 *
 * @param xpp The {@link XmlPullParser}.
 * @throws XmlPullParserException If an error occurs parsing the stream.
 * @throws IOException If an error occurs reading the stream.
 */
public static void maybeSkipTag(XmlPullParser xpp) throws IOException, XmlPullParserException {
  if (!XmlPullParserUtil.isStartTag(xpp)) {
    return;
  }
  int depth = 1;
  while (depth != 0) {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp)) {
      depth++;
    } else if (XmlPullParserUtil.isEndTag(xpp)) {
      depth--;
    }
  }
}
 
Example #13
Source File: DashManifestParser.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
protected int parseAudioChannelConfiguration(XmlPullParser xpp)
    throws XmlPullParserException, IOException {
  String schemeIdUri = parseString(xpp, "schemeIdUri", null);
  int audioChannels =
      "urn:mpeg:dash:23003:3:audio_channel_configuration:2011".equals(schemeIdUri)
          ? parseInt(xpp, "value", Format.NO_VALUE)
          : ("tag:dolby.com,2014:dash:audio_channel_configuration:2011".equals(schemeIdUri)
                  || "urn:dolby:dash:audio_channel_configuration:2011".equals(schemeIdUri)
              ? parseDolbyChannelConfiguration(xpp)
              : Format.NO_VALUE);
  do {
    xpp.next();
  } while (!XmlPullParserUtil.isEndTag(xpp, "AudioChannelConfiguration"));
  return audioChannels;
}
 
Example #14
Source File: DashManifestParser.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
protected SingleSegmentBase parseSegmentBase(XmlPullParser xpp, SingleSegmentBase parent)
    throws XmlPullParserException, IOException {

  long timescale = parseLong(xpp, "timescale", parent != null ? parent.timescale : 1);
  long presentationTimeOffset = parseLong(xpp, "presentationTimeOffset",
      parent != null ? parent.presentationTimeOffset : 0);

  long indexStart = parent != null ? parent.indexStart : 0;
  long indexLength = parent != null ? parent.indexLength : 0;
  String indexRangeText = xpp.getAttributeValue(null, "indexRange");
  if (indexRangeText != null) {
    String[] indexRange = indexRangeText.split("-");
    indexStart = Long.parseLong(indexRange[0]);
    indexLength = Long.parseLong(indexRange[1]) - indexStart + 1;
  }

  RangedUri initialization = parent != null ? parent.initialization : null;
  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "Initialization")) {
      initialization = parseInitialization(xpp);
    } else {
      maybeSkipTag(xpp);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "SegmentBase"));

  return buildSingleSegmentBase(initialization, timescale, presentationTimeOffset, indexStart,
      indexLength);
}
 
Example #15
Source File: DashManifestParser.java    From K-Sonic with MIT License 5 votes vote down vote up
protected int parseAudioChannelConfiguration(XmlPullParser xpp)
    throws XmlPullParserException, IOException {
  String schemeIdUri = parseString(xpp, "schemeIdUri", null);
  int audioChannels = "urn:mpeg:dash:23003:3:audio_channel_configuration:2011".equals(schemeIdUri)
      ? parseInt(xpp, "value", Format.NO_VALUE) : Format.NO_VALUE;
  do {
    xpp.next();
  } while (!XmlPullParserUtil.isEndTag(xpp, "AudioChannelConfiguration"));
  return audioChannels;
}
 
Example #16
Source File: DashManifestParser.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
protected static String parseText(XmlPullParser xpp, String label)
    throws XmlPullParserException, IOException {
  String text = "";
  do {
    xpp.next();
    if (xpp.getEventType() == XmlPullParser.TEXT) {
      text = xpp.getText();
    } else {
      maybeSkipTag(xpp);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, label));
  return text;
}
 
Example #17
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a Role 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 C.SelectionFlags} parsed from the element.
 */
protected int parseRole(XmlPullParser xpp) throws XmlPullParserException, IOException {
  String schemeIdUri = parseString(xpp, "schemeIdUri", null);
  String value = parseString(xpp, "value", null);
  do {
    xpp.next();
  } while (!XmlPullParserUtil.isEndTag(xpp, "Role"));
  return "urn:mpeg:dash:role:2011".equals(schemeIdUri) && "main".equals(value)
      ? C.SELECTION_FLAG_DEFAULT : 0;
}
 
Example #18
Source File: DashManifestParser.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
protected SegmentList parseSegmentList(XmlPullParser xpp, SegmentList parent)
    throws XmlPullParserException, IOException {

  long timescale = parseLong(xpp, "timescale", parent != null ? parent.timescale : 1);
  long presentationTimeOffset = parseLong(xpp, "presentationTimeOffset",
      parent != null ? parent.presentationTimeOffset : 0);
  long duration = parseLong(xpp, "duration", parent != null ? parent.duration : C.TIME_UNSET);
  long startNumber = parseLong(xpp, "startNumber", parent != null ? parent.startNumber : 1);

  RangedUri initialization = null;
  List<SegmentTimelineElement> timeline = null;
  List<RangedUri> segments = null;

  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "Initialization")) {
      initialization = parseInitialization(xpp);
    } else if (XmlPullParserUtil.isStartTag(xpp, "SegmentTimeline")) {
      timeline = parseSegmentTimeline(xpp);
    } else if (XmlPullParserUtil.isStartTag(xpp, "SegmentURL")) {
      if (segments == null) {
        segments = new ArrayList<>();
      }
      segments.add(parseSegmentUrl(xpp));
    } else {
      maybeSkipTag(xpp);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "SegmentList"));

  if (parent != null) {
    initialization = initialization != null ? initialization : parent.initialization;
    timeline = timeline != null ? timeline : parent.segmentTimeline;
    segments = segments != null ? segments : parent.mediaSegments;
  }

  return buildSegmentList(initialization, timescale, presentationTimeOffset,
      startNumber, duration, timeline, segments);
}
 
Example #19
Source File: TtmlDecoder.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void parseMetadata(XmlPullParser xmlParser, Map<String, String> imageMap)
    throws IOException, XmlPullParserException {
  do {
    xmlParser.next();
    if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_IMAGE)) {
      String id = XmlPullParserUtil.getAttributeValue(xmlParser, "id");
      if (id != null) {
        String encodedBitmapData = xmlParser.nextText();
        imageMap.put(id, encodedBitmapData);
      }
    }
  } while (!XmlPullParserUtil.isEndTag(xmlParser, TtmlNode.TAG_METADATA));
}
 
Example #20
Source File: DashManifestParser.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Parses a {@link SchemeValuePair} from an element.
 *
 * @param xpp The parser from which to read.
 * @param tag The tag of the element being parsed.
 * @throws XmlPullParserException If an error occurs parsing the element.
 * @throws IOException If an error occurs reading the element.
 * @return The parsed {@link SchemeValuePair}.
 */
protected static SchemeValuePair parseSchemeValuePair(XmlPullParser xpp, String tag)
    throws XmlPullParserException, IOException {
  String schemeIdUri = parseString(xpp, "schemeIdUri", null);
  String value = parseString(xpp, "value", null);
  do {
    xpp.next();
  } while (!XmlPullParserUtil.isEndTag(xpp, tag));
  return new SchemeValuePair(schemeIdUri, value);
}
 
Example #21
Source File: DashManifestParser.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
protected SegmentList parseSegmentList(XmlPullParser xpp, SegmentList parent)
    throws XmlPullParserException, IOException {

  long timescale = parseLong(xpp, "timescale", parent != null ? parent.timescale : 1);
  long presentationTimeOffset = parseLong(xpp, "presentationTimeOffset",
      parent != null ? parent.presentationTimeOffset : 0);
  long duration = parseLong(xpp, "duration", parent != null ? parent.duration : C.TIME_UNSET);
  long startNumber = parseLong(xpp, "startNumber", parent != null ? parent.startNumber : 1);

  RangedUri initialization = null;
  List<SegmentTimelineElement> timeline = null;
  List<RangedUri> segments = null;

  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "Initialization")) {
      initialization = parseInitialization(xpp);
    } else if (XmlPullParserUtil.isStartTag(xpp, "SegmentTimeline")) {
      timeline = parseSegmentTimeline(xpp);
    } else if (XmlPullParserUtil.isStartTag(xpp, "SegmentURL")) {
      if (segments == null) {
        segments = new ArrayList<>();
      }
      segments.add(parseSegmentUrl(xpp));
    } else {
      maybeSkipTag(xpp);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "SegmentList"));

  if (parent != null) {
    initialization = initialization != null ? initialization : parent.initialization;
    timeline = timeline != null ? timeline : parent.segmentTimeline;
    segments = segments != null ? segments : parent.mediaSegments;
  }

  return buildSegmentList(initialization, timescale, presentationTimeOffset,
      startNumber, duration, timeline, segments);
}
 
Example #22
Source File: DashManifestParser.java    From K-Sonic with MIT License 5 votes vote down vote up
protected SingleSegmentBase parseSegmentBase(XmlPullParser xpp, SingleSegmentBase parent)
    throws XmlPullParserException, IOException {

  long timescale = parseLong(xpp, "timescale", parent != null ? parent.timescale : 1);
  long presentationTimeOffset = parseLong(xpp, "presentationTimeOffset",
      parent != null ? parent.presentationTimeOffset : 0);

  long indexStart = parent != null ? parent.indexStart : 0;
  long indexLength = parent != null ? parent.indexLength : 0;
  String indexRangeText = xpp.getAttributeValue(null, "indexRange");
  if (indexRangeText != null) {
    String[] indexRange = indexRangeText.split("-");
    indexStart = Long.parseLong(indexRange[0]);
    indexLength = Long.parseLong(indexRange[1]) - indexStart + 1;
  }

  RangedUri initialization = parent != null ? parent.initialization : null;
  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "Initialization")) {
      initialization = parseInitialization(xpp);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "SegmentBase"));

  return buildSingleSegmentBase(initialization, timescale, presentationTimeOffset, indexStart,
      indexLength);
}
 
Example #23
Source File: DashManifestParser.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Parses a Role 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 C.SelectionFlags} parsed from the element.
 */
protected int parseRole(XmlPullParser xpp) throws XmlPullParserException, IOException {
  String schemeIdUri = parseString(xpp, "schemeIdUri", null);
  String value = parseString(xpp, "value", null);
  do {
    xpp.next();
  } while (!XmlPullParserUtil.isEndTag(xpp, "Role"));
  return "urn:mpeg:dash:role:2011".equals(schemeIdUri) && "main".equals(value)
      ? C.SELECTION_FLAG_DEFAULT : 0;
}
 
Example #24
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 #25
Source File: DashManifestParser.java    From K-Sonic with MIT License 5 votes vote down vote up
protected Pair<Period, Long> parsePeriod(XmlPullParser xpp, String baseUrl, long defaultStartMs)
    throws XmlPullParserException, IOException {
  String id = xpp.getAttributeValue(null, "id");
  long startMs = parseDuration(xpp, "start", defaultStartMs);
  long durationMs = parseDuration(xpp, "duration", C.TIME_UNSET);
  SegmentBase segmentBase = null;
  List<AdaptationSet> adaptationSets = new ArrayList<>();
  boolean seenFirstBaseUrl = false;
  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "BaseURL")) {
      if (!seenFirstBaseUrl) {
        baseUrl = parseBaseUrl(xpp, baseUrl);
        seenFirstBaseUrl = true;
      }
    } else if (XmlPullParserUtil.isStartTag(xpp, "AdaptationSet")) {
      adaptationSets.add(parseAdaptationSet(xpp, baseUrl, segmentBase));
    } else if (XmlPullParserUtil.isStartTag(xpp, "SegmentBase")) {
      segmentBase = parseSegmentBase(xpp, null);
    } else if (XmlPullParserUtil.isStartTag(xpp, "SegmentList")) {
      segmentBase = parseSegmentList(xpp, null);
    } else if (XmlPullParserUtil.isStartTag(xpp, "SegmentTemplate")) {
      segmentBase = parseSegmentTemplate(xpp, null);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "Period"));

  return Pair.create(buildPeriod(id, startMs, adaptationSets), durationMs);
}
 
Example #26
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Parses a {@link Descriptor} from an element.
 *
 * @param xpp The parser from which to read.
 * @param tag The tag of the element being parsed.
 * @throws XmlPullParserException If an error occurs parsing the element.
 * @throws IOException If an error occurs reading the element.
 * @return The parsed {@link Descriptor}.
 */
protected static Descriptor parseDescriptor(XmlPullParser xpp, String tag)
    throws XmlPullParserException, IOException {
  String schemeIdUri = parseString(xpp, "schemeIdUri", "");
  String value = parseString(xpp, "value", null);
  String id = parseString(xpp, "id", null);
  do {
    xpp.next();
  } while (!XmlPullParserUtil.isEndTag(xpp, tag));
  return new Descriptor(schemeIdUri, value, id);
}
 
Example #27
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
protected int parseAudioChannelConfiguration(XmlPullParser xpp)
    throws XmlPullParserException, IOException {
  String schemeIdUri = parseString(xpp, "schemeIdUri", null);
  int audioChannels = "urn:mpeg:dash:23003:3:audio_channel_configuration:2011".equals(schemeIdUri)
      ? parseInt(xpp, "value", Format.NO_VALUE)
      : ("tag:dolby.com,2014:dash:audio_channel_configuration:2011".equals(schemeIdUri)
      ? parseDolbyChannelConfiguration(xpp) : Format.NO_VALUE);
  do {
    xpp.next();
  } while (!XmlPullParserUtil.isEndTag(xpp, "AudioChannelConfiguration"));
  return audioChannels;
}
 
Example #28
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
protected SegmentList parseSegmentList(XmlPullParser xpp, SegmentList parent)
    throws XmlPullParserException, IOException {

  long timescale = parseLong(xpp, "timescale", parent != null ? parent.timescale : 1);
  long presentationTimeOffset = parseLong(xpp, "presentationTimeOffset",
      parent != null ? parent.presentationTimeOffset : 0);
  long duration = parseLong(xpp, "duration", parent != null ? parent.duration : C.TIME_UNSET);
  long startNumber = parseLong(xpp, "startNumber", parent != null ? parent.startNumber : 1);

  RangedUri initialization = null;
  List<SegmentTimelineElement> timeline = null;
  List<RangedUri> segments = null;

  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "Initialization")) {
      initialization = parseInitialization(xpp);
    } else if (XmlPullParserUtil.isStartTag(xpp, "SegmentTimeline")) {
      timeline = parseSegmentTimeline(xpp);
    } else if (XmlPullParserUtil.isStartTag(xpp, "SegmentURL")) {
      if (segments == null) {
        segments = new ArrayList<>();
      }
      segments.add(parseSegmentUrl(xpp));
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "SegmentList"));

  if (parent != null) {
    initialization = initialization != null ? initialization : parent.initialization;
    timeline = timeline != null ? timeline : parent.segmentTimeline;
    segments = segments != null ? segments : parent.mediaSegments;
  }

  return buildSegmentList(initialization, timescale, presentationTimeOffset,
      startNumber, duration, timeline, segments);
}
 
Example #29
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
protected SingleSegmentBase parseSegmentBase(XmlPullParser xpp, SingleSegmentBase parent)
    throws XmlPullParserException, IOException {

  long timescale = parseLong(xpp, "timescale", parent != null ? parent.timescale : 1);
  long presentationTimeOffset = parseLong(xpp, "presentationTimeOffset",
      parent != null ? parent.presentationTimeOffset : 0);

  long indexStart = parent != null ? parent.indexStart : 0;
  long indexLength = parent != null ? parent.indexLength : 0;
  String indexRangeText = xpp.getAttributeValue(null, "indexRange");
  if (indexRangeText != null) {
    String[] indexRange = indexRangeText.split("-");
    indexStart = Long.parseLong(indexRange[0]);
    indexLength = Long.parseLong(indexRange[1]) - indexStart + 1;
  }

  RangedUri initialization = parent != null ? parent.initialization : null;
  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "Initialization")) {
      initialization = parseInitialization(xpp);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "SegmentBase"));

  return buildSingleSegmentBase(initialization, timescale, presentationTimeOffset, indexStart,
      indexLength);
}
 
Example #30
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
protected SegmentTemplate parseSegmentTemplate(XmlPullParser xpp, SegmentTemplate parent)
    throws XmlPullParserException, IOException {
  long timescale = parseLong(xpp, "timescale", parent != null ? parent.timescale : 1);
  long presentationTimeOffset = parseLong(xpp, "presentationTimeOffset",
      parent != null ? parent.presentationTimeOffset : 0);
  long duration = parseLong(xpp, "duration", parent != null ? parent.duration : C.TIME_UNSET);
  long startNumber = parseLong(xpp, "startNumber", parent != null ? parent.startNumber : 1);
  UrlTemplate mediaTemplate = parseUrlTemplate(xpp, "media",
      parent != null ? parent.mediaTemplate : null);
  UrlTemplate initializationTemplate = parseUrlTemplate(xpp, "initialization",
      parent != null ? parent.initializationTemplate : null);

  RangedUri initialization = null;
  List<SegmentTimelineElement> timeline = null;

  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "Initialization")) {
      initialization = parseInitialization(xpp);
    } else if (XmlPullParserUtil.isStartTag(xpp, "SegmentTimeline")) {
      timeline = parseSegmentTimeline(xpp);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "SegmentTemplate"));

  if (parent != null) {
    initialization = initialization != null ? initialization : parent.initialization;
    timeline = timeline != null ? timeline : parent.segmentTimeline;
  }

  return buildSegmentTemplate(initialization, timescale, presentationTimeOffset,
      startNumber, duration, timeline, initializationTemplate, mediaTemplate);
}