From cc957c12e4ab946e3de504838ebc86cf074171be Mon Sep 17 00:00:00 2001 From: Nhan Nguyen Date: Wed, 7 Feb 2024 15:40:04 +0700 Subject: [PATCH] Test case for SCTE35 in DATERANGE tags --- reader_test.go | 65 +++++++++++++++++-- .../media-playlist-with-scte35-daterange.m3u8 | 21 ++++++ 2 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 sample-playlists/media-playlist-with-scte35-daterange.m3u8 diff --git a/reader_test.go b/reader_test.go index 8bfed863..681f9350 100644 --- a/reader_test.go +++ b/reader_test.go @@ -1,11 +1,11 @@ /* - Playlist parsing tests. +Playlist parsing tests. - Copyright 2013-2019 The Project Developers. - See the AUTHORS and LICENSE files at the top-level directory of this distribution - and at https://github.com/grafov/m3u8/ +Copyright 2013-2019 The Project Developers. +See the AUTHORS and LICENSE files at the top-level directory of this distribution +and at https://github.com/grafov/m3u8/ - ॐ तारे तुत्तारे तुरे स्व +ॐ तारे तुत्तारे तुरे स्व */ package m3u8 @@ -564,6 +564,61 @@ func TestMediaPlaylistWithOATCLSSCTE35Tag(t *testing.T) { } } +func TestMediaPlaylistWithDateRangeSCTE35Tag(t *testing.T) { + f, err := os.Open("sample-playlists/media-playlist-with-scte35-daterange.m3u8") + if err != nil { + t.Fatal(err) + } + p, _, err := DecodeFrom(bufio.NewReader(f), true) + if err != nil { + t.Fatal(err) + } + pp := p.(*MediaPlaylist) + startDateOut, _ := time.Parse(DATETIME, "2014-03-05T11:15:00Z") + startDateIn, _ := time.Parse(DATETIME, "2014-03-05T11:16:00Z") + + ptr := func(f float64) *float64 { + return &f + } + + expect := map[int]*SCTE{ + 0: { + Syntax: SCTE35_DATERANGE, + CueType: SCTE35Cue_Start, + Cue: "/AAvAAAAAAD/AA==", + StartDate: &startDateOut, + Duration: ptr(60), + PlannedDuration: ptr(60), + ID: "splice-6FFFFFF0", + }, + 1: { + Syntax: SCTE35_DATERANGE, + CueType: SCTE35Cue_End, + Cue: "/AAvAAAAAAD/EA==", + StartDate: &startDateIn, + Duration: ptr(60), + PlannedDuration: ptr(60), + ID: "splice-6FFFFFF0", + }, + } + + actual := make([]*SCTE, 0, 2) + for i := 0; i < int(pp.Count()); i++ { + if pp.Segments[i].SCTE != nil { + actual = append(actual, pp.Segments[i].SCTE) + } + } + + for i := 0; i < len(expect); i++ { + if !reflect.DeepEqual(actual[i], expect[i]) { + t.Errorf("DATERANGE SCTE35 segment %v \ngot: %#v\nexp: %#v", + i, actual[i], expect[i], + ) + } + } + +} + func TestDecodeMediaPlaylistWithDiscontinuitySeq(t *testing.T) { f, err := os.Open("sample-playlists/media-playlist-with-discontinuity-seq.m3u8") if err != nil { diff --git a/sample-playlists/media-playlist-with-scte35-daterange.m3u8 b/sample-playlists/media-playlist-with-scte35-daterange.m3u8 new file mode 100644 index 00000000..c108cae2 --- /dev/null +++ b/sample-playlists/media-playlist-with-scte35-daterange.m3u8 @@ -0,0 +1,21 @@ +#EXTM3U +#EXT-X-VERSION:3 +#EXT-X-TARGETDURATION:10 +#EXT-X-MEDIA-SEQUENCE:0 +#EXTINF:10, +fileSequence0.ts +#EXTINF:10, +fileSequence1.ts +#EXT-X-DATERANGE:ID="splice-6FFFFFF0",START-DATE="2014-03-05T11:15:00Z",PLANNED-DURATION=60,DURATION=60,SCTE35-OUT=0xFC002F0000000000FF00 +#EXTINF:10, +fileSequence2.ts +#EXTINF:10, +fileSequence3.ts +#EXTINF:10, +fileSequence4.ts +#EXTINF:10, +fileSequence5.ts +#EXT-X-DATERANGE:ID="splice-6FFFFFF0",START-DATE="2014-03-05T11:16:00Z",PLANNED-DURATION=60,DURATION=60,SCTE35-IN=0xFC002F0000000000FF10 +#EXTINF:10, +fileSequence6.ts +#EXT-X-ENDLIST \ No newline at end of file