예제 #1
0
        @Override
        public void parse(String line, ParseState state) throws ParseException {
          super.parse(line, state);

          final Matcher matcher = match(Constants.EXT_X_VERSION_PATTERN, line);

          if (state.getCompatibilityVersion() != ParseState.NONE) {
            throw ParseException.create(
                ParseExceptionType.MULTIPLE_EXT_TAG_INSTANCES, getTag(), line);
          }

          final int compatibilityVersion = ParseUtil.parseInt(matcher.group(1), getTag());

          if (compatibilityVersion < Playlist.MIN_COMPATIBILITY_VERSION) {
            throw ParseException.create(
                ParseExceptionType.INVALID_COMPATIBILITY_VERSION, getTag(), line);
          }

          if (compatibilityVersion > Constants.MAX_COMPATIBILITY_VERSION) {
            throw ParseException.create(
                ParseExceptionType.UNSUPPORTED_COMPATIBILITY_VERSION, getTag(), line);
          }

          state.setCompatibilityVersion(compatibilityVersion);
        }
예제 #2
0
 @Override
 public void parse(String line, ParseState state) throws ParseException {
   if (hasData()) {
     if (line.indexOf(Constants.EXT_TAG_END) != getTag().length() + 1) {
       throw ParseException.create(ParseExceptionType.MISSING_EXT_TAG_SEPARATOR, getTag(), line);
     }
   }
 }
예제 #3
0
        @Override
        public void parse(String line, ParseState state) throws ParseException {
          if (state.isExtended()) {
            throw ParseException.create(
                ParseExceptionType.MULTIPLE_EXT_TAG_INSTANCES, getTag(), line);
          }

          state.setExtended();
        }
예제 #4
0
  Matcher match(Pattern pattern, String line) throws ParseException {
    final Matcher matcher = pattern.matcher(line);

    if (!matcher.matches()) {
      throw ParseException.create(ParseExceptionType.BAD_EXT_TAG_FORMAT, getTag(), line);
    }

    return matcher;
  }
예제 #5
0
 <T> void parseAttributes(
     String line, T builder, ParseState state, Map<String, ? extends AttributeParser<T>> handlers)
     throws ParseException {
   for (Attribute attribute : ParseUtil.parseAttributeList(line, getTag())) {
     if (handlers.containsKey(attribute.name)) {
       handlers.get(attribute.name).parse(attribute, builder, state);
     } else {
       throw ParseException.create(ParseExceptionType.INVALID_ATTRIBUTE_NAME, getTag(), line);
     }
   }
 }
        @Override
        public void parse(String line, ParseState state) throws ParseException {
          super.parse(line, state);

          match(Constants.EXT_X_I_FRAMES_ONLY_PATTERN, line);

          if (state.getCompatibilityVersion() < 4) {
            throw ParseException.create(
                ParseExceptionType.REQUIRES_PROTOCOL_VERSION_4_OR_HIGHER, getTag());
          }

          state.setIsIframesOnly();
        }
        @Override
        public void parse(String line, ParseState state) throws ParseException {
          super.parse(line, state);

          final Matcher matcher = match(Constants.EXT_X_MEDIA_SEQUENCE_PATTERN, line);

          if (state.getMedia().mediaSequenceNumber != null) {
            throw ParseException.create(
                ParseExceptionType.MULTIPLE_EXT_TAG_INSTANCES, getTag(), line);
          }

          state.getMedia().mediaSequenceNumber = ParseUtil.parseInt(matcher.group(1), getTag());
        }
        @Override
        public void parse(String line, ParseState state) throws ParseException {
          super.parse(line, state);

          final Matcher matcher = match(Constants.EXT_X_TARGETDURATION_PATTERN, line);

          if (state.getMedia().targetDuration != null) {
            throw ParseException.create(
                ParseExceptionType.MULTIPLE_EXT_TAG_INSTANCES, getTag(), line);
          }

          state.getMedia().targetDuration = ParseUtil.parseInt(matcher.group(1), getTag());
        }
        @Override
        public void parse(String line, ParseState state) throws ParseException {
          super.parse(line, state);

          final Matcher matcher = match(Constants.EXT_X_PLAYLIST_TYPE_PATTERN, line);

          if (state.getMedia().playlistType != null) {
            throw ParseException.create(
                ParseExceptionType.MULTIPLE_EXT_TAG_INSTANCES, getTag(), line);
          }

          state.getMedia().playlistType =
              ParseUtil.parseEnum(matcher.group(1), PlaylistType.class, getTag());
        }
예제 #10
0
        @Override
        public void parse(String line, ParseState state) throws ParseException {
          super.parse(line, state);

          final EncryptionData.Builder builder =
              new EncryptionData.Builder()
                  .withKeyFormat(Constants.DEFAULT_KEY_FORMAT)
                  .withKeyFormatVersions(Constants.DEFAULT_KEY_FORMAT_VERSIONS);

          parseAttributes(line, builder, state, HANDLERS);
          final EncryptionData encryptionData = builder.build();

          if (encryptionData.getMethod() != EncryptionMethod.NONE
              && encryptionData.getUri() == null) {
            throw ParseException.create(ParseExceptionType.MISSING_ENCRYPTION_URI, getTag(), line);
          }

          state.getMedia().encryptionData = encryptionData;
        }
예제 #11
0
 private void validateNotMaster(ParseState state) throws ParseException {
   if (state.isMaster()) {
     throw ParseException.create(ParseExceptionType.MEDIA_IN_MASTER, getTag());
   }
 }