Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed unnecessary playlist version change in SetDefaultKey #24

Merged
merged 1 commit into from
Aug 22, 2015
Merged
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
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