Esempio n. 1
0
 public override void write(TagWriter tagWriter, Playlist playlist)
 {
     if (playlist.hasMasterPlaylist())
     {
         doWrite(tagWriter, playlist, playlist.getMasterPlaylist());
     }
 }
Esempio n. 2
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());
        }
Esempio n. 3
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));
        }
Esempio n. 4
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);
                }
            }
Esempio n. 5
0
        public void testParseMaster()
        {
            List <MediaData> expectedMediaData = new List <MediaData>();

            expectedMediaData.Add(new MediaData.Builder()
                                  .withType(MediaType.AUDIO)
                                  .withGroupId("1234")
                                  .withName("Foo")
                                  .build());

            StreamInfo expectedStreamInfo = new StreamInfo.Builder()
                                            .withBandwidth(500)
                                            .build();

            String validData =
                "#EXTM3U\n" +
                "#EXT-X-VERSION:2\n" +
                "#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID=\"1234\",NAME=\"Foo\"\n" +
                "#EXT-X-STREAM-INF:BANDWIDTH=500\n" +
                "http://foo.bar.com/\n" +
                "\n";

            Stream            inputStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(validData));
            ExtendedM3uParser parser      = new ExtendedM3uParser(inputStream, Encoding.UTF_8, ParsingMode.STRICT);

            Assert.True(parser.isAvailable());

            Playlist playlist = parser.parse();

            Assert.False(parser.isAvailable());
            Assert.True(playlist.isExtended());
            Assert.Equal(2, playlist.getCompatibilityVersion());
            Assert.True(playlist.hasMasterPlaylist());
            Assert.Equal(expectedMediaData, playlist.getMasterPlaylist().getMediaData());
            Assert.Equal(expectedStreamInfo, playlist.getMasterPlaylist().getPlaylists()[0].getStreamInfo());
        }
Esempio n. 6
0
        public void masterPlaylistWithIFrames()
        {
            Playlist playlist = readPlaylist("masterPlaylistWithIFrames.m3u8");

            Assert.True(playlist.hasMasterPlaylist());

            MasterPlaylist masterPlaylist = playlist.getMasterPlaylist();

            Assert.NotNull(masterPlaylist);

            List <PlaylistData>     playlistDatas = masterPlaylist.getPlaylists();
            List <IFrameStreamInfo> iFrameInfo    = masterPlaylist.getIFramePlaylists();

            Assert.NotNull(playlistDatas);
            Assert.NotNull(iFrameInfo);
            Assert.Equal(4, playlistDatas.Count);
            Assert.Equal(3, iFrameInfo.Count);

            PlaylistData lowXStreamInf = playlistDatas[0];

            Assert.NotNull(lowXStreamInf);
            Assert.NotNull(lowXStreamInf.getStreamInfo());
            Assert.Equal(1280000, lowXStreamInf.getStreamInfo().getBandwidth());
            Assert.Equal("low/audio-video.m3u8", lowXStreamInf.getUri());

            PlaylistData midXStreamInf = playlistDatas[1];

            Assert.NotNull(midXStreamInf);
            Assert.NotNull(midXStreamInf.getStreamInfo());
            Assert.Equal(2560000, midXStreamInf.getStreamInfo().getBandwidth());
            Assert.Equal("mid/audio-video.m3u8", midXStreamInf.getUri());

            PlaylistData hiXStreamInf = playlistDatas[2];

            Assert.NotNull(hiXStreamInf);
            Assert.NotNull(hiXStreamInf.getStreamInfo());
            Assert.Equal(7680000, hiXStreamInf.getStreamInfo().getBandwidth());
            Assert.Equal("hi/audio-video.m3u8", hiXStreamInf.getUri());

            PlaylistData audioXStreamInf = playlistDatas[3];

            Assert.NotNull(audioXStreamInf);
            Assert.NotNull(audioXStreamInf.getStreamInfo());
            Assert.Equal(65000, audioXStreamInf.getStreamInfo().getBandwidth());
            Assert.NotNull(audioXStreamInf.getStreamInfo().getCodecs());
            Assert.Single(audioXStreamInf.getStreamInfo().getCodecs());
            Assert.Equal("mp4a.40.5", audioXStreamInf.getStreamInfo().getCodecs()[0]);
            Assert.Equal("audio-only.m3u8", audioXStreamInf.getUri());

            IFrameStreamInfo lowXIFrameStreamInf = iFrameInfo[0];

            Assert.NotNull(lowXIFrameStreamInf);
            Assert.Equal(86000, lowXIFrameStreamInf.getBandwidth());
            Assert.Equal("low/iframe.m3u8", lowXIFrameStreamInf.getUri());

            IFrameStreamInfo midXIFrameStreamInf = iFrameInfo[1];

            Assert.NotNull(midXIFrameStreamInf);
            Assert.Equal(150000, midXIFrameStreamInf.getBandwidth());
            Assert.Equal("mid/iframe.m3u8", midXIFrameStreamInf.getUri());

            IFrameStreamInfo hiXIFrameStreamInf = iFrameInfo[2];

            Assert.NotNull(hiXIFrameStreamInf);
            Assert.Equal(550000, hiXIFrameStreamInf.getBandwidth());
            Assert.Equal("hi/iframe.m3u8", hiXIFrameStreamInf.getUri());

            String writtenPlaylist = writePlaylist(playlist);

            Assert.Equal(
                "#EXTM3U\n" +
                "#EXT-X-VERSION:1\n" +
                "#EXT-X-STREAM-INF:BANDWIDTH=1280000\n" +
                "low/audio-video.m3u8\n" +
                "#EXT-X-STREAM-INF:BANDWIDTH=2560000\n" +
                "mid/audio-video.m3u8\n" +
                "#EXT-X-STREAM-INF:BANDWIDTH=7680000\n" +
                "hi/audio-video.m3u8\n" +
                "#EXT-X-STREAM-INF:CODECS=\"mp4a.40.5\",BANDWIDTH=65000\n" +
                "audio-only.m3u8\n" +
                "#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=86000,URI=\"low/iframe.m3u8\"\n" +
                "#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=150000,URI=\"mid/iframe.m3u8\"\n" +
                "#EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=550000,URI=\"hi/iframe.m3u8\"\n",
                writtenPlaylist);
        }
Esempio n. 7
0
 private static bool hasBothPlaylistTypes(Playlist playlist)
 {
     return(playlist.hasMasterPlaylist() && playlist.hasMediaPlaylist());
 }
Esempio n. 8
0
 private static bool hasNoPlaylistTypes(Playlist playlist)
 {
     return(!(playlist.hasMasterPlaylist() || playlist.hasMediaPlaylist()));
 }