Java Code Examples for com.google.android.exoplayer2.util.XmlPullParserUtil#isEndTag()

The following examples show how to use com.google.android.exoplayer2.util.XmlPullParserUtil#isEndTag() . 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 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 2
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 3
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 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<>();
  List<EventStream> eventStreams = 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, "EventStream")) {
      eventStreams.add(parseEventStream(xpp));
    } 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, eventStreams), durationMs);
}
 
Example 4
Source File: DashManifestParser.java    From Telegram-FOSS 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 5
Source File: DashManifestParser.java    From Telegram-FOSS with GNU General Public License v2.0 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<>();
  List<EventStream> eventStreams = 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, "EventStream")) {
      eventStreams.add(parseEventStream(xpp));
    } 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, Collections.emptyList());
    } else {
      maybeSkipTag(xpp);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "Period"));

  return Pair.create(buildPeriod(id, startMs, adaptationSets, eventStreams), durationMs);
}
 
Example 6
Source File: DashManifestParser.java    From MediaSDK with Apache License 2.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 7
Source File: DashManifestParser.java    From MediaSDK with Apache License 2.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 8
Source File: TtmlDecoder.java    From Telegram-FOSS 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 9
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 10
Source File: TtmlDecoder.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private Map<String, TtmlStyle> parseHeader(
    XmlPullParser xmlParser,
    Map<String, TtmlStyle> globalStyles,
    Map<String, TtmlRegion> globalRegions,
    CellResolution cellResolution)
    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)) {
      TtmlRegion ttmlRegion = parseRegionAttributes(xmlParser, cellResolution);
      if (ttmlRegion != null) {
        globalRegions.put(ttmlRegion.id, ttmlRegion);
      }
    }
  } while (!XmlPullParserUtil.isEndTag(xmlParser, TtmlNode.TAG_HEAD));
  return globalStyles;
}
 
Example 11
Source File: DashManifestParser.java    From Telegram 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 12
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 13
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 14
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 15
Source File: TtmlDecoder.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private Map<String, TtmlStyle> parseHeader(
    XmlPullParser xmlParser,
    Map<String, TtmlStyle> globalStyles,
    CellResolution cellResolution,
    TtsExtent ttsExtent,
    Map<String, TtmlRegion> globalRegions,
    Map<String, String> imageMap)
    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)) {
      TtmlRegion ttmlRegion = parseRegionAttributes(xmlParser, cellResolution, ttsExtent);
      if (ttmlRegion != null) {
        globalRegions.put(ttmlRegion.id, ttmlRegion);
      }
    } else if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_METADATA)) {
      parseMetadata(xmlParser, imageMap);
    }
  } while (!XmlPullParserUtil.isEndTag(xmlParser, TtmlNode.TAG_HEAD));
  return globalStyles;
}
 
Example 16
Source File: DashManifestParser.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
/**
 * Parses an event object.
 *
 * @param xpp The current xml parser.
 * @param scratchOutputStream A {@link ByteArrayOutputStream} that's used when parsing the object.
 * @return The serialized byte array.
 * @throws XmlPullParserException If there is any error parsing this node.
 * @throws IOException If there is any error reading from the underlying input stream.
 */
protected byte[] parseEventObject(XmlPullParser xpp, ByteArrayOutputStream scratchOutputStream)
    throws XmlPullParserException, IOException {
  scratchOutputStream.reset();
  XmlSerializer xmlSerializer = Xml.newSerializer();
  xmlSerializer.setOutput(scratchOutputStream, C.UTF8_NAME);
  // Start reading everything between <Event> and </Event>, and serialize them into an Xml
  // byte array.
  xpp.nextToken();
  while (!XmlPullParserUtil.isEndTag(xpp, "Event")) {
    switch (xpp.getEventType()) {
      case (XmlPullParser.START_DOCUMENT):
        xmlSerializer.startDocument(null, false);
        break;
      case (XmlPullParser.END_DOCUMENT):
        xmlSerializer.endDocument();
        break;
      case (XmlPullParser.START_TAG):
        xmlSerializer.startTag(xpp.getNamespace(), xpp.getName());
        for (int i = 0; i < xpp.getAttributeCount(); i++) {
          xmlSerializer.attribute(xpp.getAttributeNamespace(i), xpp.getAttributeName(i),
              xpp.getAttributeValue(i));
        }
        break;
      case (XmlPullParser.END_TAG):
        xmlSerializer.endTag(xpp.getNamespace(), xpp.getName());
        break;
      case (XmlPullParser.TEXT):
        xmlSerializer.text(xpp.getText());
        break;
      case (XmlPullParser.CDSECT):
        xmlSerializer.cdsect(xpp.getText());
        break;
      case (XmlPullParser.ENTITY_REF):
        xmlSerializer.entityRef(xpp.getText());
        break;
      case (XmlPullParser.IGNORABLE_WHITESPACE):
        xmlSerializer.ignorableWhitespace(xpp.getText());
        break;
      case (XmlPullParser.PROCESSING_INSTRUCTION):
        xmlSerializer.processingInstruction(xpp.getText());
        break;
      case (XmlPullParser.COMMENT):
        xmlSerializer.comment(xpp.getText());
        break;
      case (XmlPullParser.DOCDECL):
        xmlSerializer.docdecl(xpp.getText());
        break;
      default: // fall out
    }
    xpp.nextToken();
  }
  xmlSerializer.flush();
  return scratchOutputStream.toByteArray();
}
 
Example 17
Source File: DashManifestParser.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
protected SegmentTemplate parseSegmentTemplate(
    XmlPullParser xpp,
    @Nullable SegmentTemplate parent,
    List<Descriptor> adaptationSetSupplementalProperties,
    long periodDurationMs)
    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);
  long endNumber =
      parseLastSegmentNumberSupplementalProperty(adaptationSetSupplementalProperties);

  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, timescale, periodDurationMs);
    } else {
      maybeSkipTag(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,
      endNumber,
      duration,
      timeline,
      initializationTemplate,
      mediaTemplate);
}
 
Example 18
Source File: DashManifestParser.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
protected SegmentTemplate parseSegmentTemplate(
    XmlPullParser xpp,
    SegmentTemplate parent,
    List<Descriptor> adaptationSetSupplementalProperties)
    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);
  long endNumber =
      parseLastSegmentNumberSupplementalProperty(adaptationSetSupplementalProperties);

  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);
    } else {
      maybeSkipTag(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,
      endNumber,
      duration,
      timeline,
      initializationTemplate,
      mediaTemplate);
}
 
Example 19
Source File: DashManifestParser.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
protected AdaptationSet parseAdaptationSet(XmlPullParser xpp, String baseUrl,
    SegmentBase segmentBase) throws XmlPullParserException, IOException {
  int id = parseInt(xpp, "id", AdaptationSet.ID_UNSET);
  int contentType = parseContentType(xpp);

  String mimeType = xpp.getAttributeValue(null, "mimeType");
  String codecs = xpp.getAttributeValue(null, "codecs");
  int width = parseInt(xpp, "width", Format.NO_VALUE);
  int height = parseInt(xpp, "height", Format.NO_VALUE);
  float frameRate = parseFrameRate(xpp, Format.NO_VALUE);
  int audioChannels = Format.NO_VALUE;
  int audioSamplingRate = parseInt(xpp, "audioSamplingRate", Format.NO_VALUE);
  String language = xpp.getAttributeValue(null, "lang");
  String label = xpp.getAttributeValue(null, "label");
  String drmSchemeType = null;
  ArrayList<SchemeData> drmSchemeDatas = new ArrayList<>();
  ArrayList<Descriptor> inbandEventStreams = new ArrayList<>();
  ArrayList<Descriptor> accessibilityDescriptors = new ArrayList<>();
  ArrayList<Descriptor> roleDescriptors = new ArrayList<>();
  ArrayList<Descriptor> supplementalProperties = new ArrayList<>();
  List<RepresentationInfo> representationInfos = 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, "ContentProtection")) {
      Pair<String, SchemeData> contentProtection = parseContentProtection(xpp);
      if (contentProtection.first != null) {
        drmSchemeType = contentProtection.first;
      }
      if (contentProtection.second != null) {
        drmSchemeDatas.add(contentProtection.second);
      }
    } else if (XmlPullParserUtil.isStartTag(xpp, "ContentComponent")) {
      language = checkLanguageConsistency(language, xpp.getAttributeValue(null, "lang"));
      contentType = checkContentTypeConsistency(contentType, parseContentType(xpp));
    } else if (XmlPullParserUtil.isStartTag(xpp, "Role")) {
      roleDescriptors.add(parseDescriptor(xpp, "Role"));
    } else if (XmlPullParserUtil.isStartTag(xpp, "AudioChannelConfiguration")) {
      audioChannels = parseAudioChannelConfiguration(xpp);
    } else if (XmlPullParserUtil.isStartTag(xpp, "Accessibility")) {
      accessibilityDescriptors.add(parseDescriptor(xpp, "Accessibility"));
    } else if (XmlPullParserUtil.isStartTag(xpp, "SupplementalProperty")) {
      supplementalProperties.add(parseDescriptor(xpp, "SupplementalProperty"));
    } else if (XmlPullParserUtil.isStartTag(xpp, "Representation")) {
      RepresentationInfo representationInfo =
          parseRepresentation(
              xpp,
              baseUrl,
              mimeType,
              codecs,
              width,
              height,
              frameRate,
              audioChannels,
              audioSamplingRate,
              language,
              roleDescriptors,
              accessibilityDescriptors,
              supplementalProperties,
              segmentBase);
      contentType = checkContentTypeConsistency(contentType,
          getContentType(representationInfo.format));
      representationInfos.add(representationInfo);
    } else if (XmlPullParserUtil.isStartTag(xpp, "SegmentBase")) {
      segmentBase = parseSegmentBase(xpp, (SingleSegmentBase) segmentBase);
    } else if (XmlPullParserUtil.isStartTag(xpp, "SegmentList")) {
      segmentBase = parseSegmentList(xpp, (SegmentList) segmentBase);
    } else if (XmlPullParserUtil.isStartTag(xpp, "SegmentTemplate")) {
      segmentBase =
          parseSegmentTemplate(xpp, (SegmentTemplate) segmentBase, supplementalProperties);
    } else if (XmlPullParserUtil.isStartTag(xpp, "InbandEventStream")) {
      inbandEventStreams.add(parseDescriptor(xpp, "InbandEventStream"));
    } else if (XmlPullParserUtil.isStartTag(xpp, "Label")) {
      label = parseLabel(xpp);
    } else if (XmlPullParserUtil.isStartTag(xpp)) {
      parseAdaptationSetChild(xpp);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "AdaptationSet"));

  // Build the representations.
  List<Representation> representations = new ArrayList<>(representationInfos.size());
  for (int i = 0; i < representationInfos.size(); i++) {
    representations.add(
        buildRepresentation(
            representationInfos.get(i),
            label,
            drmSchemeType,
            drmSchemeDatas,
            inbandEventStreams));
  }

  return buildAdaptationSet(id, contentType, representations, accessibilityDescriptors,
      supplementalProperties);
}
 
Example 20
Source File: DashManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
protected AdaptationSet parseAdaptationSet(XmlPullParser xpp, String baseUrl,
    SegmentBase segmentBase) throws XmlPullParserException, IOException {
  int id = parseInt(xpp, "id", AdaptationSet.ID_UNSET);
  int contentType = parseContentType(xpp);

  String mimeType = xpp.getAttributeValue(null, "mimeType");
  String codecs = xpp.getAttributeValue(null, "codecs");
  int width = parseInt(xpp, "width", Format.NO_VALUE);
  int height = parseInt(xpp, "height", Format.NO_VALUE);
  float frameRate = parseFrameRate(xpp, Format.NO_VALUE);
  int audioChannels = Format.NO_VALUE;
  int audioSamplingRate = parseInt(xpp, "audioSamplingRate", Format.NO_VALUE);
  String language = xpp.getAttributeValue(null, "lang");
  String label = xpp.getAttributeValue(null, "label");
  String drmSchemeType = null;
  ArrayList<SchemeData> drmSchemeDatas = new ArrayList<>();
  ArrayList<Descriptor> inbandEventStreams = new ArrayList<>();
  ArrayList<Descriptor> accessibilityDescriptors = new ArrayList<>();
  ArrayList<Descriptor> supplementalProperties = new ArrayList<>();
  List<RepresentationInfo> representationInfos = new ArrayList<>();
  @C.SelectionFlags int selectionFlags = 0;

  boolean seenFirstBaseUrl = false;
  do {
    xpp.next();
    if (XmlPullParserUtil.isStartTag(xpp, "BaseURL")) {
      if (!seenFirstBaseUrl) {
        baseUrl = parseBaseUrl(xpp, baseUrl);
        seenFirstBaseUrl = true;
      }
    } else if (XmlPullParserUtil.isStartTag(xpp, "ContentProtection")) {
      Pair<String, SchemeData> contentProtection = parseContentProtection(xpp);
      if (contentProtection.first != null) {
        drmSchemeType = contentProtection.first;
      }
      if (contentProtection.second != null) {
        drmSchemeDatas.add(contentProtection.second);
      }
    } else if (XmlPullParserUtil.isStartTag(xpp, "ContentComponent")) {
      language = checkLanguageConsistency(language, xpp.getAttributeValue(null, "lang"));
      contentType = checkContentTypeConsistency(contentType, parseContentType(xpp));
    } else if (XmlPullParserUtil.isStartTag(xpp, "Role")) {
      selectionFlags |= parseRole(xpp);
    } else if (XmlPullParserUtil.isStartTag(xpp, "AudioChannelConfiguration")) {
      audioChannels = parseAudioChannelConfiguration(xpp);
    } else if (XmlPullParserUtil.isStartTag(xpp, "Accessibility")) {
      accessibilityDescriptors.add(parseDescriptor(xpp, "Accessibility"));
    } else if (XmlPullParserUtil.isStartTag(xpp, "SupplementalProperty")) {
      supplementalProperties.add(parseDescriptor(xpp, "SupplementalProperty"));
    } else if (XmlPullParserUtil.isStartTag(xpp, "Representation")) {
      RepresentationInfo representationInfo =
          parseRepresentation(
              xpp,
              baseUrl,
              label,
              mimeType,
              codecs,
              width,
              height,
              frameRate,
              audioChannels,
              audioSamplingRate,
              language,
              selectionFlags,
              accessibilityDescriptors,
              segmentBase);
      contentType = checkContentTypeConsistency(contentType,
          getContentType(representationInfo.format));
      representationInfos.add(representationInfo);
    } else if (XmlPullParserUtil.isStartTag(xpp, "SegmentBase")) {
      segmentBase = parseSegmentBase(xpp, (SingleSegmentBase) segmentBase);
    } else if (XmlPullParserUtil.isStartTag(xpp, "SegmentList")) {
      segmentBase = parseSegmentList(xpp, (SegmentList) segmentBase);
    } else if (XmlPullParserUtil.isStartTag(xpp, "SegmentTemplate")) {
      segmentBase = parseSegmentTemplate(xpp, (SegmentTemplate) segmentBase);
    } else if (XmlPullParserUtil.isStartTag(xpp, "InbandEventStream")) {
      inbandEventStreams.add(parseDescriptor(xpp, "InbandEventStream"));
    } else if (XmlPullParserUtil.isStartTag(xpp)) {
      parseAdaptationSetChild(xpp);
    }
  } while (!XmlPullParserUtil.isEndTag(xpp, "AdaptationSet"));

  // Build the representations.
  List<Representation> representations = new ArrayList<>(representationInfos.size());
  for (int i = 0; i < representationInfos.size(); i++) {
    representations.add(buildRepresentation(representationInfos.get(i), contentId,
        drmSchemeType, drmSchemeDatas, inbandEventStreams));
  }

  return buildAdaptationSet(id, contentType, representations, accessibilityDescriptors,
      supplementalProperties);
}