From 081eab52de61d353450c769cd54c26eafa3c31a5 Mon Sep 17 00:00:00 2001 From: Nikita Egorov Date: Wed, 4 Oct 2023 19:59:09 +0300 Subject: [PATCH 1/3] Test for descintionuity at begin of media playlist --- reader_test.go | 19 +++++++++++++++++++ .../media-with-discontinuity-at-start.m3u8 | 13 +++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 sample-playlists/media-with-discontinuity-at-start.m3u8 diff --git a/reader_test.go b/reader_test.go index 8d60b16c..d6630f6a 100644 --- a/reader_test.go +++ b/reader_test.go @@ -972,6 +972,25 @@ func TestDecodeMediaPlaylistStartTime(t *testing.T) { } } +func TestDecodeMediaPlaylistDicontinuityAtBegin(t *testing.T) { + f, err := os.Open("sample-playlists/media-with-discontinuity-at-start.m3u8") + if err != nil { + t.Fatal(err) + } + p, listType, err := DecodeFrom(bufio.NewReader(f), true) + if err != nil { + t.Fatal(err) + } + pp := p.(*MediaPlaylist) + CheckType(t, pp) + if listType != MEDIA { + t.Error("Sample not recognized as media playlist.") + } + if pp.StartTime != float64(0.0) { + t.Errorf("Media segment StartTime != 0: %f", pp.StartTime) + } +} + /**************** * Benchmarks * ****************/ diff --git a/sample-playlists/media-with-discontinuity-at-start.m3u8 b/sample-playlists/media-with-discontinuity-at-start.m3u8 new file mode 100644 index 00000000..6c2e50b7 --- /dev/null +++ b/sample-playlists/media-with-discontinuity-at-start.m3u8 @@ -0,0 +1,13 @@ +#EXTM3U +#EXT-X-VERSION:5 +#EXT-X-MEDIA-SEQUENCE:0 +#EXT-X-TARGETDURATION:7 +#EXT-X-PLAYLIST-TYPE:VOD +#EXT-X-KEY:METHOD=AES-128,URI="data:text/plain;charset=utf-8,a4cd9995a1aa91e1",IV=0x30303030303030303030303030303030 + +#EXT-X-DISCONTINUITY + +#EXT-X-PROGRAM-DATE-TIME:1979-05-02T13:33:23.089999973Z +#EXTINF:6.910, +294500000/294500000/6778687.ts +#EXT-X-ENDLIST \ No newline at end of file From 345ded1489a0b5d0745de0c16ba02f6546a8a5bf Mon Sep 17 00:00:00 2001 From: Nikita Egorov Date: Wed, 4 Oct 2023 20:00:29 +0300 Subject: [PATCH 2/3] Add skip for empty linse while decode playlists --- reader.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/reader.go b/reader.go index b19324eb..986bd381 100644 --- a/reader.go +++ b/reader.go @@ -272,6 +272,10 @@ func decodeLineOfMasterPlaylist(p *MasterPlaylist, state *decodingState, line st line = strings.TrimSpace(line) + if line == "" { + return nil + } + // check for custom tags first to allow custom parsing of existing tags if p.Custom != nil { for _, v := range p.customDecoders { @@ -451,6 +455,10 @@ func decodeLineOfMediaPlaylist(p *MediaPlaylist, wv *WV, state *decodingState, l line = strings.TrimSpace(line) + if line == "" { + return nil + } + // check for custom tags first to allow custom parsing of existing tags if p.Custom != nil { for _, v := range p.customDecoders { From f8dd1325e5030d098c5f9743f831290d3bc83d81 Mon Sep 17 00:00:00 2001 From: Nikita Egorov Date: Wed, 4 Oct 2023 20:02:54 +0300 Subject: [PATCH 3/3] Fix test for EXTINF check The empty segment uri is forbidden by RFC. I add something reasonable. --- reader_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/reader_test.go b/reader_test.go index d6630f6a..d9d42d2b 100644 --- a/reader_test.go +++ b/reader_test.go @@ -344,6 +344,7 @@ func TestDecodeMediaPlaylistExtInfNonStrict2(t *testing.T) { #EXT-X-VERSION:3 #EXT-X-MEDIA-SEQUENCE:0 %s +path ` tests := []struct { @@ -383,6 +384,7 @@ func TestDecodeMediaPlaylistExtInfNonStrict2(t *testing.T) { if err != nil { t.Errorf("unexpected error: %v", err) } + test.wantSegment.URI = "path" if !reflect.DeepEqual(p.Segments[0], test.wantSegment) { t.Errorf("\nhave: %+v\nwant: %+v", p.Segments[0], test.wantSegment) }