From 657e529408fecc5a7e877e78fef80c541c8820c1 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 24 Jun 2022 09:04:51 +0700 Subject: [PATCH 1/7] change to compare value of the key --- writer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/writer.go b/writer.go index dec3690c..7f3ce004 100644 --- a/writer.go +++ b/writer.go @@ -615,7 +615,7 @@ func (p *MediaPlaylist) Encode() *bytes.Buffer { } } // check for key change - if seg.Key != nil && p.Key != seg.Key { + 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) From 98b1a956a5b87ad4558a14f55bdb43166c115685 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 24 Jun 2022 09:59:17 +0700 Subject: [PATCH 2/7] Unittest change key NONE in header of the mediaplaylist --- writer_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/writer_test.go b/writer_test.go index b4281331..3448f9fa 100644 --- a/writer_test.go +++ b/writer_test.go @@ -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) } From f4fdddac1fa9bf966d18363cb28fe765ccd297de Mon Sep 17 00:00:00 2001 From: david Date: Fri, 24 Jun 2022 10:10:36 +0700 Subject: [PATCH 3/7] change lowercase name --- writer_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/writer_test.go b/writer_test.go index 3448f9fa..fcb04ef0 100644 --- a/writer_test.go +++ b/writer_test.go @@ -970,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, "") @@ -989,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, "") From d30ed70df7b72f71c9818246c001bacb05411e2b Mon Sep 17 00:00:00 2001 From: david Date: Fri, 24 Jun 2022 10:16:31 +0700 Subject: [PATCH 4/7] combined params --- writer.go | 10 +++++----- writer_test.go | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/writer.go b/writer.go index 7f3ce004..9525da7c 100644 --- a/writer.go +++ b/writer.go @@ -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 @@ -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(ok bool) { + if ok { // duration must be integers if protocol version is less than 3 version(&p.ver, 3) } - p.durationAsInt = yes + p.durationAsInt = ok } // Count tells us the number of items that are currently in the media @@ -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}) } diff --git a/writer_test.go b/writer_test.go index fcb04ef0..e2d59a30 100644 --- a/writer_test.go +++ b/writer_test.go @@ -816,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) { @@ -825,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()) From 450cbd136286c044f2216aef951a20ce4dad13a1 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 24 Jun 2022 10:21:32 +0700 Subject: [PATCH 5/7] avoid using ok, yes.. in param --- writer.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/writer.go b/writer.go index 9525da7c..e374ac44 100644 --- a/writer.go +++ b/writer.go @@ -717,12 +717,12 @@ func (p *MediaPlaylist) String() string { } // DurationAsInt represents the duration as the integer in encoded playlist. -func (p *MediaPlaylist) DurationAsInt(ok bool) { - if ok { +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 = ok + p.durationAsInt = isDurationasInt } // Count tells us the number of items that are currently in the media From b6dea82abcba6320d5855c69966486114af015ff Mon Sep 17 00:00:00 2001 From: david Date: Fri, 24 Jun 2022 16:53:21 +0700 Subject: [PATCH 6/7] targetDuration change math.Ceil to math.Round --- writer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/writer.go b/writer.go index e374ac44..a9f73545 100644 --- a/writer.go +++ b/writer.go @@ -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 From 71b018a76411ec1f903a32ee57bc995941579540 Mon Sep 17 00:00:00 2001 From: david Date: Mon, 27 Jun 2022 00:44:40 +0700 Subject: [PATCH 7/7] no need seg key change --- writer.go | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/writer.go b/writer.go index a9f73545..6109cd27 100644 --- a/writer.go +++ b/writer.go @@ -614,32 +614,32 @@ func (p *MediaPlaylist) Encode() *bytes.Buffer { } } } - // check for key change - 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') - } + // 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") }