示例#1
0
 public override void write(TagWriter tagWriter, Playlist playlist)
 {
     if (playlist.hasMediaPlaylist())
     {
         doWrite(tagWriter, playlist, playlist.getMediaPlaylist());
     }
 }
示例#2
0
            public void write(TagWriter tagWriter, Playlist playlist)
            {
                if (playlist.hasMediaPlaylist())
                {
                    KeyWriter     keyWriter     = new KeyWriter();
                    MapInfoWriter mapInfoWriter = new MapInfoWriter();

                    foreach (TrackData trackData in playlist.getMediaPlaylist().getTracks())
                    {
                        if (trackData.hasDiscontinuity())
                        {
                            tagWriter.writeTag(Constants.EXT_X_DISCONTINUITY_TAG);
                        }

                        keyWriter.writeTrackData(tagWriter, playlist, trackData);
                        mapInfoWriter.writeTrackData(tagWriter, playlist, trackData);

                        if (trackData.hasByteRange())
                        {
                            writeByteRange(tagWriter, trackData.getByteRange());
                        }

                        writeExtinf(tagWriter, playlist, trackData);
                        tagWriter.writeLine(trackData.getUri());
                    }
                }
            }
示例#3
0
 public void testParsingByteOrderMark()
 {
     using (Stream inputStream = wrapWithByteOrderMark(TestUtil.inputStreamFromResource("simpleMediaPlaylist.m3u8")))
     {
         PlaylistParser playlistParser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8);
         Playlist       playlist       = playlistParser.parse();
         Assert.Equal(10, playlist.getMediaPlaylist().getTargetDuration());
     }
 }
示例#4
0
        public void test()
        {
            Playlist      playlist      = TestUtil.parsePlaylistFromResource("mediaPlaylist.m3u8");
            MediaPlaylist mediaPlaylist = playlist.getMediaPlaylist();

            Assert.False(playlist.hasMasterPlaylist());
            Assert.True(playlist.hasMediaPlaylist());
            Assert.True(mediaPlaylist.hasStartData());
            Assert.Equal(-4.5, mediaPlaylist.getStartData().getTimeOffset(), 12);
            Assert.True(mediaPlaylist.getStartData().isPrecise());
            Assert.Equal(10, mediaPlaylist.getTargetDuration());
        }
示例#5
0
            public override void write(TagWriter tagWriter, Playlist playlist)
            {
                List <String> unknownTags;

                if (playlist.hasMasterPlaylist() && playlist.getMasterPlaylist().hasUnknownTags())
                {
                    unknownTags = playlist.getMasterPlaylist().getUnknownTags();
                }
                else if (playlist.getMediaPlaylist().hasUnknownTags())
                {
                    unknownTags = playlist.getMediaPlaylist().getUnknownTags();
                }
                else
                {
                    unknownTags = new List <String>();
                }
                foreach (String line in unknownTags)
                {
                    tagWriter.writeLine(line);
                }
            }
示例#6
0
        public static PlaylistValidation from(Playlist playlist, ParsingMode parsingMode)
        {
            HashSet <PlaylistError> errors = new HashSet <PlaylistError>();

            if (playlist == null)
            {
                errors.Add(PlaylistError.NO_PLAYLIST);
                return(new PlaylistValidation(errors));
            }

            if (playlist.getCompatibilityVersion() < Playlist.MIN_COMPATIBILITY_VERSION)
            {
                errors.Add(PlaylistError.COMPATIBILITY_TOO_LOW);
            }

            if (hasNoPlaylistTypes(playlist))
            {
                errors.Add(PlaylistError.NO_MASTER_OR_MEDIA);
            }
            else if (hasBothPlaylistTypes(playlist))
            {
                errors.Add(PlaylistError.BOTH_MASTER_AND_MEDIA);
            }

            if (playlist.hasMasterPlaylist())
            {
                if (!playlist.isExtended())
                {
                    errors.Add(PlaylistError.MASTER_NOT_EXTENDED);
                }

                addMasterPlaylistErrors(playlist.getMasterPlaylist(), errors);
            }

            if (playlist.hasMediaPlaylist())
            {
                addMediaPlaylistErrors(playlist.getMediaPlaylist(), errors, playlist.isExtended(), parsingMode);
            }

            return(new PlaylistValidation(errors));
        }
示例#7
0
        public void playlistWithByteRanges()
        {
            Playlist         playlist      = TestUtil.parsePlaylistFromResource("mediaPlaylistWithByteRanges.m3u8");
            MediaPlaylist    mediaPlaylist = playlist.getMediaPlaylist();
            List <ByteRange> byteRanges    = new List <ByteRange>();

            foreach (TrackData track in mediaPlaylist.getTracks())
            {
                Assert.True(track.hasByteRange());
                byteRanges.Add(track.getByteRange());
            }

            List <ByteRange> expectedRanges = new List <ByteRange>()
            {
                new ByteRange(0, 10),
                new ByteRange(20),
                new ByteRange(30)
            };

            Assert.Equal(expectedRanges, byteRanges);

            var writtenPlaylist = writePlaylist(playlist);

            Assert.Equal(
                "#EXTM3U\n" +
                "#EXT-X-VERSION:4\n" +
                "#EXT-X-TARGETDURATION:10\n" +
                "#EXT-X-MEDIA-SEQUENCE:0\n" +
                "#EXT-X-BYTERANGE:0@10\n" +
                "#EXTINF:9.009\n" +
                "http://media.example.com/first.ts\n" +
                "#EXT-X-BYTERANGE:20\n" +
                "#EXTINF:9.009\n" +
                "http://media.example.com/first.ts\n" +
                "#EXT-X-BYTERANGE:30\n" +
                "#EXTINF:3.003\n" +
                "http://media.example.com/first.ts\n" +
                "#EXT-X-ENDLIST\n",
                writtenPlaylist);
        }
示例#8
0
        public void testParsingMultiplePlaylists()
        {
            using (Stream inputStream = TestUtil.inputStreamFromResource("twoMediaPlaylists.m3u8"))
            {
                PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8);

                Assert.True(parser.isAvailable());

                Playlist playlist1 = parser.parse();

                Assert.True(parser.isAvailable());

                Playlist playlist2 = parser.parse();

                Assert.False(parser.isAvailable());

                List <TrackData> expected1 = new List <TrackData>()
                {
                    makeTrackData("http://media.example.com/first.ts", 9.009f),
                    makeTrackData("http://media.example.com/second.ts", 9.009f),
                    makeTrackData("http://media.example.com/third.ts", 3.003f)
                };

                var actual1 = playlist1.getMediaPlaylist().getTracks();
                Assert.Equal(
                    expected1,
                    actual1);

                Assert.Equal(
                    new List <TrackData>()
                {
                    makeTrackData("http://media.example.com/fourth.ts", 9.01f),
                    makeTrackData("http://media.example.com/fifth.ts", 9.011f)
                },
                    playlist2.getMediaPlaylist().getTracks());

                // Assert.Equal(0, inputStream.available()); // TODO: Why? And what's the c# equivalent
            }
        }