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

Commit

Permalink
Merge pull request #24 from juliancooper/setdefault-key-version-fix
Browse files Browse the repository at this point in the history
Fix unnecessary playlist version change in SetDefaultKey
  • Loading branch information
grafov committed Aug 22, 2015
2 parents facecdd + 7052917 commit 8a35b4b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
11 changes: 9 additions & 2 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,16 @@ func (p *MediaPlaylist) Close() {
// Set encryption key appeared once in header of the playlist (pointer to MediaPlaylist.Key).
// It useful when keys not changed during playback.
// Set tag for the whole list.
func (p *MediaPlaylist) SetDefaultKey(method, uri, iv, keyformat, keyformatversions string) {
version(&p.ver, 5) // due section 7
func (p *MediaPlaylist) SetDefaultKey(method, uri, iv, keyformat, keyformatversions string) error {
// A Media Playlist MUST indicate a EXT-X-VERSION of 5 or higher if it
// contains:
// - The KEYFORMAT and KEYFORMATVERSIONS attributes of the EXT-X-KEY tag.
if keyformat != "" && keyformatversions != "" {
version(&p.ver, 5)
}
p.Key = &Key{method, uri, iv, keyformat, keyformatversions}

return nil
}

// Set map appeared once in header of the playlist (pointer to MediaPlaylist.Key).
Expand Down
27 changes: 27 additions & 0 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,33 @@ func TestSetKeyForMediaPlaylist(t *testing.T) {
}
}

// Create new media playlist
// Add segment to media playlist
// Set encryption key
func TestSetDefaultKeyForMediaPlaylist(t *testing.T) {
p, e := NewMediaPlaylist(3, 5)
if e != nil {
t.Fatalf("Create media playlist failed: %s", e)
}
e = p.SetDefaultKey("AES-128", "https://example.com", "iv", "", "")
if e != nil {
t.Errorf("Set default key to a media playlist failed: %s", e)
}
if p.ver != 3 {
t.Errorf("SetDefaultKey to a media playlist changed version unnecessarily")
}

// Test that using V5 features updates EXT-X-VERSION
e = p.SetDefaultKey("AES-128", "https://example.com", "iv", "format", "vers")
if e != nil {
t.Errorf("Set key to a media playlist failed: %s", e)
}
if p.ver != 5 {
t.Errorf("SetDefaultKey did not update version")
}

}

// Create new media playlist
// Add segment to media playlist
// Set map
Expand Down

0 comments on commit 8a35b4b

Please sign in to comment.