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 #17 from zshenker/fix-encode-audio-group
Browse files Browse the repository at this point in the history
Fix Audio group name being incorrectly set to the Video group name

Also fixes:
* When using Alternatives (which writes an EXT-X-MEDIA-TAG, master manifest version should be 4 (not let at the default of 3)
* RESOLUTION should not be in quotes (mediastreamvalidator will complain about this, and some players will have issues)
* LANGUAGE was not being included in the EXT-X-MEDIA tag
* TYPE & AUTOSELECT should not be quoted, they are considered enums
  • Loading branch information
grafov committed Apr 5, 2015
2 parents d441909 + a848f95 commit 09b6833
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
22 changes: 13 additions & 9 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func (p *MasterPlaylist) Append(uri string, chunklist *MediaPlaylist, params Var
v.Chunklist = chunklist
v.VariantParams = params
p.Variants = append(p.Variants, v)
if len(v.Alternatives) > 0 {
p.ver = 4 // As per 3.3.9
}
p.buf.Reset()
}

Expand All @@ -78,9 +81,8 @@ func (p *MasterPlaylist) Encode() *bytes.Buffer {
for _, alt := range pl.Alternatives {
p.buf.WriteString("#EXT-X-MEDIA:")
if alt.Type != "" {
p.buf.WriteString("TYPE=\"")
p.buf.WriteString("TYPE=") // Type should not be quoted
p.buf.WriteString(alt.Type)
p.buf.WriteRune('"')
}
if alt.GroupId != "" {
p.buf.WriteString(",GROUP-ID=\"")
Expand All @@ -99,8 +101,12 @@ func (p *MasterPlaylist) Encode() *bytes.Buffer {
p.buf.WriteString("NO")
}
if alt.Autoselect != "" {
p.buf.WriteString(",AUTOSELECT=\"")
p.buf.WriteString(",AUTOSELECT=")
p.buf.WriteString(alt.Autoselect)
}
if alt.Language != "" {
p.buf.WriteString(",LANGUAGE=\"")
p.buf.WriteString(alt.Language)
p.buf.WriteRune('"')
}
if alt.Forced != "" {
Expand Down Expand Up @@ -137,9 +143,8 @@ func (p *MasterPlaylist) Encode() *bytes.Buffer {
p.buf.WriteRune('"')
}
if pl.Resolution != "" {
p.buf.WriteString(",RESOLUTION=\"")
p.buf.WriteString(",RESOLUTION=") // Resolution should not be quoted
p.buf.WriteString(pl.Resolution)
p.buf.WriteRune('"')
}
if pl.Video != "" {
p.buf.WriteString(",VIDEO=\"")
Expand All @@ -163,13 +168,12 @@ func (p *MasterPlaylist) Encode() *bytes.Buffer {
p.buf.WriteRune('"')
}
if pl.Resolution != "" {
p.buf.WriteString(",RESOLUTION=\"")
p.buf.WriteString(",RESOLUTION=") // Resolution should not be quoted
p.buf.WriteString(pl.Resolution)
p.buf.WriteRune('"')
}
if pl.Audio != "" {
p.buf.WriteString(",AUDIO=\"")
p.buf.WriteString(pl.Video)
p.buf.WriteString(pl.Audio)
p.buf.WriteRune('"')
}
if pl.Video != "" {
Expand Down Expand Up @@ -474,7 +478,7 @@ func (p *MediaPlaylist) DurationAsInt(yes bool) {
}

// Count tells us the number of items that are currently in the media playlist
func (p *MediaPlaylist) Count() (uint) {
func (p *MediaPlaylist) Count() uint {
return p.count
}

Expand Down
35 changes: 33 additions & 2 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,37 @@ func TestNewMasterPlaylist(t *testing.T) {
m.Append("chunklist1.m3u8", p, VariantParams{})
}

// Create new master playlist without params
// Add media playlist with Alternatives
func TestNewMasterPlaylistWithAlternatives(t *testing.T) {
m := NewMasterPlaylist()
audioUri := fmt.Sprintf("%s/rendition.m3u8", "800")
audioAlt := &Alternative{
GroupId: "audio",
URI: audioUri,
Type: "AUDIO",
Name: "main",
Default: true,
Autoselect: "YES",
Language: "english",
}
p, e := NewMediaPlaylist(3, 5)
if e != nil {
t.Fatalf("Create media playlist failed: %s", e)
}
for i := 0; i < 5; i++ {
e = p.Append(fmt.Sprintf("test%d.ts", i), 5.0, "")
if e != nil {
t.Errorf("Add segment #%d to a media playlist failed: %s", i, e)
}
}
m.Append("chunklist1.m3u8", p, VariantParams{Alternatives: []*Alternative{audioAlt}})

if m.ver != 4 {
t.Fatalf("Expected version 4, actual, %d", m.ver)
}
}

// Create new master playlist with params
// Add media playlist
func TestNewMasterPlaylistWithParams(t *testing.T) {
Expand Down Expand Up @@ -423,8 +454,8 @@ func ExampleMasterPlaylist_String() {
// Output:
// #EXTM3U
// #EXT-X-VERSION:3
// #EXT-X-STREAM-INF:PROGRAM-ID=123,BANDWIDTH=1500000,RESOLUTION="576x480"
// #EXT-X-STREAM-INF:PROGRAM-ID=123,BANDWIDTH=1500000,RESOLUTION=576x480
// chunklist1.m3u8
// #EXT-X-STREAM-INF:PROGRAM-ID=123,BANDWIDTH=1500000,RESOLUTION="576x480"
// #EXT-X-STREAM-INF:PROGRAM-ID=123,BANDWIDTH=1500000,RESOLUTION=576x480
// chunklist2.m3u8
}

0 comments on commit 09b6833

Please sign in to comment.