Skip to content

Commit

Permalink
fix: Multiple keys are supported
Browse files Browse the repository at this point in the history
  • Loading branch information
吴坚强 committed Nov 13, 2023
1 parent 494bd27 commit f6fb064
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
16 changes: 2 additions & 14 deletions reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func TestDecodeMediaPlaylist(t *testing.T) {
if err != nil {
t.Fatal(err)
}
//fmt.Printf("Playlist object: %+v\n", p)

// check parsed values
if p.ver != 3 {
t.Errorf("Version of parsed playlist = %d (must = 3)", p.ver)
Expand Down Expand Up @@ -402,17 +402,14 @@ func TestDecodeMediaPlaylistWithWidevine(t *testing.T) {
if err != nil {
t.Fatal(err)
}
//fmt.Printf("Playlist object: %+v\n", p)
// check parsed values
if p.ver != 2 {
t.Errorf("Version of parsed playlist = %d (must = 2)", p.ver)
}
if p.TargetDuration != 9 {
t.Errorf("TargetDuration of parsed playlist = %f (must = 9.0)", p.TargetDuration)
}
// TODO check other values…
//fmt.Printf("%+v\n", p.Key)
//fmt.Println(p.Encode().String())

}

// https://datatracker.ietf.org/doc/html/rfc8216#section-4.3.2.4
Expand All @@ -429,7 +426,6 @@ func TestDecodeMediaPlaylistWithMutipleKeys(t *testing.T) {
if err != nil {
t.Fatal(err)
}
//fmt.Printf("Playlist object: %+v\n", p)
// check parsed values
if p.ver != 2 {
t.Errorf("Version of parsed playlist = %d (must = 2)", p.ver)
Expand All @@ -441,9 +437,6 @@ func TestDecodeMediaPlaylistWithMutipleKeys(t *testing.T) {
if len(p.Keys) != 2 {
t.Errorf("Number of keys = %d (must = 2)", len(p.Keys))
}
// TODO check other values…
//fmt.Printf("%+v\n", p.Key)
//fmt.Println(p.Encode().String())
}

func TestDecodeMasterPlaylistWithAutodetection(t *testing.T) {
Expand All @@ -459,11 +452,6 @@ func TestDecodeMasterPlaylistWithAutodetection(t *testing.T) {
t.Error("Sample not recognized as master playlist.")
}
mp := m.(*MasterPlaylist)
// fmt.Printf(">%+v\n", mp)
// for _, v := range mp.Variants {
// fmt.Printf(">>%+v +v\n", v)
// }
//fmt.Println("Type below must be MasterPlaylist:")
CheckType(t, mp)
}

Expand Down
9 changes: 4 additions & 5 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func version(ver *uint8, newver uint8) {
func strver(ver uint8) string {
return strconv.FormatUint(uint64(ver), 10)
}
func equal(a, b []*Key) bool {
return reflect.DeepEqual(a, b)
}

// NewMasterPlaylist creates a new empty master playlist. Master
// playlist consists of variants.
Expand Down Expand Up @@ -625,7 +628,7 @@ func (p *MediaPlaylist) Encode() *bytes.Buffer {
}
}
// check for key change
if (seg.Keys != nil && !p.Equal(p.Keys, seg.Keys)) && !p.Equal(p.Segments[head-2].Keys, seg.Keys) {
if (seg.Keys != nil && !equal(p.Keys, seg.Keys)) && !equal(p.Segments[head-2].Keys, seg.Keys) {
for _, key := range seg.Keys {
p.buf.WriteString("#EXT-X-KEY:")
p.buf.WriteString("METHOD=")
Expand Down Expand Up @@ -950,7 +953,3 @@ func (p *MediaPlaylist) GetAllSegments() []*MediaSegment {
}
return buf
}

func (p *MediaPlaylist) Equal(a, b []*Key) bool {
return reflect.DeepEqual(a, b)
}

0 comments on commit f6fb064

Please sign in to comment.