Beispiel #1
0
            public void parse(String line, ParseState state)
            {
                lineParser.parse(line, state);

                Match match = ParseUtil.match(Constants.EXT_X_VERSION_PATTERN, line, getTag());

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

                int compatibilityVersion = ParseUtil.parseInt(match.Groups[1].Value, 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);
            }
Beispiel #2
0
        protected void writeAttributes <T>(TagWriter tagWriter, T attributes, Dictionary <String, AttributeWriter <T> > attributeWriters)
        {
            StringBuilder sb = new StringBuilder();

            foreach (KeyValuePair <String, AttributeWriter <T> > entry in attributeWriters)
            {
                AttributeWriter <T> handler = entry.Value;
                String attribute            = entry.Key;
                if (handler.containsAttribute(attributes))
                {
                    String value = null;
                    try
                    {
                        value = handler.write(attributes);
                    }
                    catch (ParseException ex)
                    {
                        throw ParseException.create(ex.type, getTag(), ex.getMessageSuffix());
                    }
                    sb.Append(attribute).Append(Constants.ATTRIBUTE_SEPARATOR).Append(value);
                    sb.Append(Constants.ATTRIBUTE_LIST_SEPARATOR);
                }
            }
            sb.Remove(sb.Length - 1, 1);

            tagWriter.writeTag(getTag(), sb.ToString());
        }
Beispiel #3
0
        public void parse(String line, ParseState state)
        {
            TrackData.Builder builder    = new TrackData.Builder();
            MediaParseState   mediaState = state.getMedia();

            if (state.isExtended() && mediaState.trackInfo == null)
            {
                throw ParseException.create(ParseExceptionType.MISSING_TRACK_INFO, line);
            }

            mediaState.tracks.Add(builder
                                  .withUri(line)
                                  .withTrackInfo(mediaState.trackInfo)
                                  .withEncryptionData(mediaState.encryptionData)
                                  .withProgramDateTime(mediaState.programDateTime)
                                  .withDiscontinuity(mediaState.hasDiscontinuity)
                                  .withMapInfo(mediaState.mapInfo)
                                  .withByteRange(mediaState.byteRange)
                                  .build());

            mediaState.trackInfo        = null;
            mediaState.programDateTime  = null;
            mediaState.hasDiscontinuity = false;
            mediaState.mapInfo          = null;
            mediaState.byteRange        = null;
        }
Beispiel #4
0
        public static List <Byte> parseHexadecimal(String hexString, String tag = null)
        {
            List <Byte> bytes = new List <Byte>();
            Match       match = Constants.HEXADECIMAL_PATTERN.Match(hexString.ToUpper(CultureInfo.CurrentCulture));

            if (match.Success)
            {
                String valueString = match.Groups[1].Value;
                if (valueString.Length % 2 != 0)
                {
                    throw ParseException.create(ParseExceptionType.INVALID_HEXADECIMAL_STRING, tag, hexString);
                }

                for (int i = 0; i < valueString.Length; i += 2)
                {
                    bytes.Add((byte)(Convert.ToInt16(valueString.Substring(i, 2), 16) & 0xFF));
                }

                return(bytes);
            }
            else
            {
                throw ParseException.create(ParseExceptionType.INVALID_HEXADECIMAL_STRING, tag, hexString);
            }
        }
Beispiel #5
0
            public void parse(String line, ParseState state)
            {
                if (state.isExtended())
                {
                    throw ParseException.create(ParseExceptionType.MULTIPLE_EXT_TAG_INSTANCES, getTag(), line);
                }

                state.setExtended();
            }
Beispiel #6
0
 public void parse(String line, ParseState state)
 {
     if (mTagParser.hasData())
     {
         if (line.IndexOf(Constants.EXT_TAG_END) != mTagParser.getTag().Length + 1)
         {
             throw ParseException.create(ParseExceptionType.MISSING_EXT_TAG_SEPARATOR, mTagParser.getTag(), line);
         }
     }
 }
        public void parse(String line, ParseState state)
        {
            if (state.isMaster())
            {
                throw ParseException.create(ParseExceptionType.MEDIA_IN_MASTER, tagParser.getTag());
            }

            state.setMedia();
            lineParser.parse(line, state);
        }
Beispiel #8
0
 private void checkWhitespace(String line)
 {
     if (!isComment(line))
     {
         if (line.Length != line.Trim().Length)
         {
             throw ParseException.create(ParseExceptionType.WHITESPACE_IN_TRACK, line);
         }
     }
 }
Beispiel #9
0
 private void validateLine(String line)
 {
     if (!isComment(line))
     {
         if (line.Length != line.Trim().Length)
         {
             throw ParseException.create(ParseExceptionType.WHITESPACE_IN_TRACK, line, "" + line.Length);
         }
     }
 }
Beispiel #10
0
 public static float parseFloat(String str, String tag = null)
 {
     try
     {
         return(float.Parse(str));
     }
     catch (FormatException)
     {
         throw ParseException.create(ParseExceptionType.NOT_JAVA_FLOAT, tag, str);
     }
 }
Beispiel #11
0
 public static int parseInt(String str, String tag = null)
 {
     try
     {
         return(Int32.Parse(str));
     }
     catch (FormatException)
     {
         throw ParseException.create(ParseExceptionType.NOT_JAVA_INTEGER, tag, str);
     }
 }
                public void parse(Attribute attribute, MapInfo.Builder builder, ParseState state)
                {
                    Match match = Constants.EXT_X_BYTERANGE_VALUE_PATTERN.Match(ParseUtil.parseQuotedString(attribute.value));

                    if (!match.Success)
                    {
                        throw ParseException.create(ParseExceptionType.INVALID_BYTERANGE_FORMAT, tag: null, context: attribute.ToString());
                    }

                    builder.withByteRange(ParseUtil.matchByteRange(match));
                }
Beispiel #13
0
        public static Match match(Regex pattern, String line, String tag = null)
        {
            Match match = pattern.Match(line);

            if (!match.Success)
            {
                throw ParseException.create(ParseExceptionType.BAD_EXT_TAG_FORMAT, tag, line);
            }

            return(match);
        }
                public void parse(Attribute attribute, MediaData.Builder builder, ParseState state)
                {
                    bool isAutoSelect = ParseUtil.parseYesNo(attribute);

                    builder.withAutoSelect(isAutoSelect);
                    state.getMaster().isNotAutoSelect = !isAutoSelect;

                    if (state.getMaster().isDefault&& !isAutoSelect)
                    {
                        throw ParseException.create(ParseExceptionType.AUTO_SELECT_DISABLED_FOR_DEFAULT, tag: null, context: attribute.ToString());
                    }
                }
                public void parse(Attribute attribute, EncryptionData.Builder builder, ParseState state)
                {
                    List <Byte> initializationVector = ParseUtil.parseHexadecimal(attribute.value);

                    if ((initializationVector.Count != Constants.IV_SIZE) &&
                        (initializationVector.Count != Constants.IV_SIZE_ALTERNATIVE))
                    {
                        throw ParseException.create(ParseExceptionType.INVALID_IV_SIZE, tag: null, context: attribute.ToString());
                    }

                    builder.withInitializationVector(initializationVector);
                }
                public void parse(Attribute attribute, EncryptionData.Builder builder, ParseState state)
                {
                    EncryptionMethod method = EncryptionMethod.fromValue(attribute.value);

                    if (method == null)
                    {
                        throw ParseException.create(ParseExceptionType.INVALID_ENCRYPTION_METHOD, tag: null, context: attribute.ToString());
                    }
                    else
                    {
                        builder.withMethod(method);
                    }
                }
            public void parse(String line, ParseState state)
            {
                lineParser.parse(line, state);

                Match match = ParseUtil.match(Constants.EXT_X_MEDIA_SEQUENCE_PATTERN, line, getTag());

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

                state.getMedia().mediaSequenceNumber = ParseUtil.parseInt(match.Groups[1].Value, getTag());
            }
            public void parse(String line, ParseState state)
            {
                lineParser.parse(line, state);

                Match match = ParseUtil.match(Constants.EXT_X_TARGETDURATION_PATTERN, line, getTag());

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

                state.getMedia().targetDuration = ParseUtil.parseInt(match.Groups[1].Value, getTag());
            }
            public void parse(String line, ParseState state)
            {
                lineParser.parse(line, state);

                Match match = ParseUtil.match(Constants.EXT_X_PROGRAM_DATE_TIME_PATTERN, line, getTag());

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

                state.getMedia().programDateTime = ParseUtil.parseDateTime(line, getTag());
            }
                public void parse(Attribute attribute, MediaData.Builder builder, ParseState state)
                {
                    String groupId = ParseUtil.parseQuotedString(attribute.value);

                    if (groupId.isEmpty())
                    {
                        throw ParseException.create(ParseExceptionType.EMPTY_MEDIA_GROUP_ID, tag: null, context: attribute.ToString());
                    }
                    else
                    {
                        builder.withGroupId(groupId);
                    }
                }
                public void parse(Attribute attribute, MediaData.Builder builder, ParseState state)
                {
                    MediaType type = MediaType.fromValue(attribute.value);

                    if (type == null)
                    {
                        throw ParseException.create(ParseExceptionType.INVALID_MEDIA_TYPE, tag: null, context: attribute.ToString());
                    }
                    else
                    {
                        builder.withType(type);
                    }
                }
                public void parse(Attribute attribute, MediaData.Builder builder, ParseState state)
                {
                    String[] characteristicStrings = ParseUtil.parseQuotedString(attribute.value).Split(Constants.COMMA_CHAR);

                    if (characteristicStrings.Length == 0)
                    {
                        throw ParseException.create(ParseExceptionType.EMPTY_MEDIA_CHARACTERISTICS, tag: null, context: attribute.ToString());
                    }
                    else
                    {
                        builder.withCharacteristics(characteristicStrings.ToList());
                    }
                }
                public void parse(Attribute attribute, MediaData.Builder builder, ParseState state)
                {
                    String inStreamId = ParseUtil.parseQuotedString(attribute.value);

                    if (Constants.EXT_X_MEDIA_IN_STREAM_ID_PATTERN.Match(inStreamId).Success)
                    {
                        builder.withInStreamId(inStreamId);
                    }
                    else
                    {
                        throw ParseException.create(ParseExceptionType.INVALID_MEDIA_IN_STREAM_ID, tag: null, context: attribute.ToString());
                    }
                }
Beispiel #24
0
            public void parse(String line, ParseState state)
            {
                if (state.startData != null)
                {
                    throw ParseException.create(ParseExceptionType.MULTIPLE_EXT_TAG_INSTANCES, getTag(), line);
                }

                StartData.Builder builder = new StartData.Builder();

                lineParser.parse(line, state);
                ParseUtil.parseAttributes(line, builder, state, HANDLERS, getTag());
                state.startData = builder.build();
            }
                public void parse(Attribute attribute, MediaData.Builder builder, ParseState state)
                {
                    String name = ParseUtil.parseQuotedString(attribute.value);

                    if (name.isEmpty())
                    {
                        throw ParseException.create(ParseExceptionType.EMPTY_MEDIA_NAME, tag: null, context: attribute.ToString());
                    }
                    else
                    {
                        builder.withName(name);
                    }
                }
            public void parse(String line, ParseState state)
            {
                lineParser.parse(line, state);

                ParseUtil.match(Constants.EXT_X_I_FRAMES_ONLY_PATTERN, line, getTag());

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

                state.setIsIframesOnly();
            }
                public void parse(Attribute attribute, MediaData.Builder builder, ParseState state)
                {
                    String[] channelsStrings = ParseUtil.parseQuotedString(attribute.value).Split(Constants.LIST_SEPARATOR);

                    if (channelsStrings.Length == 0 || channelsStrings[0].isEmpty())
                    {
                        throw ParseException.create(ParseExceptionType.EMPTY_MEDIA_CHANNELS, tag: null, context: attribute.ToString());
                    }
                    else
                    {
                        int channelsCount = ParseUtil.parseInt(channelsStrings[0]);
                        builder.withChannels(channelsCount);
                    }
                }
            public void parse(String line, ParseState state)
            {
                lineParser.parse(line, state);

                Match match = ParseUtil.match(Constants.EXT_X_PLAYLIST_TYPE_PATTERN, line, getTag());

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

                //state.getMedia().playlistType = ParseUtil.parseEnum(match.Groups[1].Value, typeof(PlaylistType), getTag());
                state.getMedia().playlistType = PlaylistType.fromValue(match.Groups[1].Value);
            }
Beispiel #29
0
 public static bool parseYesNo(Attribute attribute, String tag = null)
 {
     if (attribute.value.Equals(Constants.YES))
     {
         return(true);
     }
     else if (attribute.value.Equals(Constants.NO))
     {
         return(false);
     }
     else
     {
         throw ParseException.create(ParseExceptionType.NOT_YES_OR_NO, tag, attribute.ToString());
     }
 }
            public void parse(String line, ParseState state)
            {
                lineParser.parse(line, state);

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

                ParseUtil.parseAttributes(line, builder, state, HANDLERS, getTag());

                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;
            }