Skip to content

Commit

Permalink
Test case for SCTE35 in DATERANGE tags
Browse files Browse the repository at this point in the history
  • Loading branch information
NhanNguyen700 committed Feb 7, 2024
1 parent b129c8e commit cc957c1
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 5 deletions.
65 changes: 60 additions & 5 deletions reader_test.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 21 additions & 0 deletions sample-playlists/media-playlist-with-scte35-daterange.m3u8
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cc957c1

Please sign in to comment.