Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

change to compare value of the key #190

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func (p *MasterPlaylist) String() string {
// NewMediaPlaylist creates a new media playlist structure. Winsize
// defines how much items will displayed on playlist generation.
// Capacity is total size of a playlist.
func NewMediaPlaylist(winsize uint, capacity uint) (*MediaPlaylist, error) {
func NewMediaPlaylist(winsize, capacity uint) (*MediaPlaylist, error) {
p := new(MediaPlaylist)
p.ver = minver
p.capacity = capacity
Expand Down Expand Up @@ -373,7 +373,7 @@ func (p *MediaPlaylist) AppendSegment(seg *MediaSegment) error {
p.tail = (p.tail + 1) % p.capacity
p.count++
if p.TargetDuration < seg.Duration {
p.TargetDuration = math.Ceil(seg.Duration)
p.TargetDuration = math.Round(seg.Duration)
}
p.buf.Reset()
return nil
Expand Down Expand Up @@ -614,32 +614,32 @@ func (p *MediaPlaylist) Encode() *bytes.Buffer {
}
}
}
// check for key change
if seg.Key != nil && p.Key != seg.Key {
p.buf.WriteString("#EXT-X-KEY:")
p.buf.WriteString("METHOD=")
p.buf.WriteString(seg.Key.Method)
if seg.Key.Method != "NONE" {
p.buf.WriteString(",URI=\"")
p.buf.WriteString(seg.Key.URI)
p.buf.WriteRune('"')
if seg.Key.IV != "" {
p.buf.WriteString(",IV=")
p.buf.WriteString(seg.Key.IV)
}
if seg.Key.Keyformat != "" {
p.buf.WriteString(",KEYFORMAT=\"")
p.buf.WriteString(seg.Key.Keyformat)
p.buf.WriteRune('"')
}
if seg.Key.Keyformatversions != "" {
p.buf.WriteString(",KEYFORMATVERSIONS=\"")
p.buf.WriteString(seg.Key.Keyformatversions)
p.buf.WriteRune('"')
}
}
p.buf.WriteRune('\n')
}
// check for key seg change then change global key as well, but we no need it so comment first
// if seg.Key != nil && p.Key != nil && *p.Key != *seg.Key {
// p.buf.WriteString("#EXT-X-KEY:")
// p.buf.WriteString("METHOD=")
// p.buf.WriteString(seg.Key.Method)
// if seg.Key.Method != "NONE" {
// p.buf.WriteString(",URI=\"")
// p.buf.WriteString(seg.Key.URI)
// p.buf.WriteRune('"')
// if seg.Key.IV != "" {
// p.buf.WriteString(",IV=")
// p.buf.WriteString(seg.Key.IV)
// }
// if seg.Key.Keyformat != "" {
// p.buf.WriteString(",KEYFORMAT=\"")
// p.buf.WriteString(seg.Key.Keyformat)
// p.buf.WriteRune('"')
// }
// if seg.Key.Keyformatversions != "" {
// p.buf.WriteString(",KEYFORMATVERSIONS=\"")
// p.buf.WriteString(seg.Key.Keyformatversions)
// p.buf.WriteRune('"')
// }
// }
// p.buf.WriteRune('\n')
// }
if seg.Discontinuity {
p.buf.WriteString("#EXT-X-DISCONTINUITY\n")
}
Expand Down Expand Up @@ -717,12 +717,12 @@ func (p *MediaPlaylist) String() string {
}

// DurationAsInt represents the duration as the integer in encoded playlist.
func (p *MediaPlaylist) DurationAsInt(yes bool) {
if yes {
func (p *MediaPlaylist) DurationAsInt(isDurationasInt bool) {
if isDurationasInt {
// duration must be integers if protocol version is less than 3
version(&p.ver, 3)
}
p.durationAsInt = yes
p.durationAsInt = isDurationasInt
}

// Count tells us the number of items that are currently in the media
Expand Down Expand Up @@ -813,7 +813,7 @@ func (p *MediaPlaylist) SetRange(limit, offset int64) error {
// SetSCTE sets the SCTE cue format for the current media segment.
//
// Deprecated: Use SetSCTE35 instead.
func (p *MediaPlaylist) SetSCTE(cue string, id string, time float64) error {
func (p *MediaPlaylist) SetSCTE(cue, id string, time float64) error {
return p.SetSCTE35(&SCTE{Syntax: SCTE35_67_2014, Cue: cue, ID: id, Time: time})
}

Expand Down
19 changes: 9 additions & 10 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,18 +498,17 @@ func TestEncryptionKeysInMediaPlaylist(t *testing.T) {
}
}

func TestEncryptionKeyMethodNoneInMediaPlaylist(t *testing.T) {
func TestEncryptionKeyMethodNoneInHeaderOfMediaPlaylist(t *testing.T) {
p, e := NewMediaPlaylist(5, 5)
p.SetDefaultKey("AES-128", "key-uri", "iv", "identity", "1")
if e != nil {
t.Fatalf("Create media playlist failed: %s", e)
}
p.Append("segment-1.ts", 4, "")
p.SetKey("AES-128", "key-uri", "iv", "identity", "1")
p.Append("segment-2.ts", 4, "")
p.SetKey("NONE", "", "", "", "")
expected := `#EXT-X-KEY:METHOD=NONE
#EXTINF:4.000,
segment-2.ts`
p.SetDefaultKey("NONE", "key-uri", "iv", "identity", "1")
expected := `#EXT-X-VERSION:5
#EXT-X-KEY:METHOD=NONE`
if !strings.Contains(p.String(), expected) {
t.Errorf("Manifest %+v did not contain expected %+v", p, expected)
}
Expand Down Expand Up @@ -817,7 +816,7 @@ func TestNewMasterPlaylistWithClosedCaptionEqNone(t *testing.T) {
if err != nil {
t.Fatalf("Create media playlist failed: %s", err)
}
m.Append(fmt.Sprintf("eng_rendition_rendition.m3u8"), p, *vp)
m.Append("eng_rendition_rendition.m3u8", p, *vp)

expected := "CLOSED-CAPTIONS=NONE"
if !strings.Contains(m.String(), expected) {
Expand All @@ -826,7 +825,7 @@ func TestNewMasterPlaylistWithClosedCaptionEqNone(t *testing.T) {
// quotes need to be include if not eq NONE
vp.Captions = "CC1"
m2 := NewMasterPlaylist()
m2.Append(fmt.Sprintf("eng_rendition_rendition.m3u8"), p, *vp)
m2.Append("eng_rendition_rendition.m3u8", p, *vp)
expected = `CLOSED-CAPTIONS="CC1"`
if !strings.Contains(m2.String(), expected) {
t.Fatalf("Master playlist did not contain: %s\nMaster Playlist:\n%v", expected, m2.String())
Expand Down Expand Up @@ -971,7 +970,7 @@ func ExampleMediaPlaylist_String() {
// Create new media playlist
// Add two segments to media playlist
// Print it
func ExampleMediaPlaylist_String_Winsize0() {
func ExampleMediaPlaylist_winsize0() {
p, _ := NewMediaPlaylist(0, 2)
p.Append("test01.ts", 5.0, "")
p.Append("test02.ts", 6.0, "")
Expand All @@ -990,7 +989,7 @@ func ExampleMediaPlaylist_String_Winsize0() {
// Create new media playlist
// Add two segments to media playlist
// Print it
func ExampleMediaPlaylist_String_Winsize0_VOD() {
func ExampleMediaPlaylist_winsize0_vod() {
p, _ := NewMediaPlaylist(0, 2)
p.Append("test01.ts", 5.0, "")
p.Append("test02.ts", 6.0, "")
Expand Down