Skip to content

Commit

Permalink
Merge pull request #95 from soldiermoth/key-method-none
Browse files Browse the repository at this point in the history
Omit URI for Key method NONE
  • Loading branch information
bradleyfalzon authored Aug 12, 2017
2 parents e911eb7 + af566d6 commit d137fcd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 30 deletions.
64 changes: 34 additions & 30 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,22 +342,24 @@ func (p *MediaPlaylist) Encode() *bytes.Buffer {
p.buf.WriteString("#EXT-X-KEY:")
p.buf.WriteString("METHOD=")
p.buf.WriteString(p.Key.Method)
p.buf.WriteString(",URI=\"")
p.buf.WriteString(p.Key.URI)
p.buf.WriteRune('"')
if p.Key.IV != "" {
p.buf.WriteString(",IV=")
p.buf.WriteString(p.Key.IV)
}
if p.Key.Keyformat != "" {
p.buf.WriteString(",KEYFORMAT=\"")
p.buf.WriteString(p.Key.Keyformat)
p.buf.WriteRune('"')
}
if p.Key.Keyformatversions != "" {
p.buf.WriteString(",KEYFORMATVERSIONS=\"")
p.buf.WriteString(p.Key.Keyformatversions)
if p.Key.Method != "NONE" {
p.buf.WriteString(",URI=\"")
p.buf.WriteString(p.Key.URI)
p.buf.WriteRune('"')
if p.Key.IV != "" {
p.buf.WriteString(",IV=")
p.buf.WriteString(p.Key.IV)
}
if p.Key.Keyformat != "" {
p.buf.WriteString(",KEYFORMAT=\"")
p.buf.WriteString(p.Key.Keyformat)
p.buf.WriteRune('"')
}
if p.Key.Keyformatversions != "" {
p.buf.WriteString(",KEYFORMATVERSIONS=\"")
p.buf.WriteString(p.Key.Keyformatversions)
p.buf.WriteRune('"')
}
}
p.buf.WriteRune('\n')
}
Expand Down Expand Up @@ -524,22 +526,24 @@ func (p *MediaPlaylist) Encode() *bytes.Buffer {
p.buf.WriteString("#EXT-X-KEY:")
p.buf.WriteString("METHOD=")
p.buf.WriteString(seg.Key.Method)
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)
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')
}
Expand Down
17 changes: 17 additions & 0 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,23 @@ func TestEncryptionKeysInMediaPlaylist(t *testing.T) {
}
}

func TestEncryptionKeyMethodNoneInMediaPlaylist(t *testing.T) {
p, e := NewMediaPlaylist(5, 5)
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`
if !strings.Contains(p.String(), expected) {
t.Errorf("Manifest %+v did not contain expected %+v", p, expected)
}
}

// Create new media playlist
// Add 10 segments to media playlist
// Encode structure to HLS with integer target durations
Expand Down

0 comments on commit d137fcd

Please sign in to comment.