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

Support for channels #1

Merged
merged 4 commits into from
Feb 1, 2022
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
6 changes: 6 additions & 0 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ func decodeLineOfMasterPlaylist(p *MasterPlaylist, state *decodingState, line st
alt.Subtitles = v
case "URI":
alt.URI = v
case "CHANNELS":
channels, err := strconv.Atoi(v)
if err != nil {
return fmt.Errorf("non-integer value %q for CHANNELS attribute", v)
}
alt.Channels = uint(channels)
}
}
state.alternatives = append(state.alternatives, &alt)
Expand Down
34 changes: 34 additions & 0 deletions reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,40 @@ func TestDecodeMediaPlaylistStartTime(t *testing.T) {
}
}

func TestDecodeMasterChannels(t *testing.T) {
f, err := os.Open("sample-playlists/master-with-channels.m3u8")
if err != nil {
t.Fatal(err)
}
p, listType, err := DecodeFrom(bufio.NewReader(f), true)
if err != nil {
t.Fatal(err)
}

if listType != MASTER {
t.Error("Input not recognized as master playlist.")
}
pp := p.(*MasterPlaylist)

alt0 := pp.Variants[0].Alternatives[0]
if alt0.Type != "AUDIO" {
t.Error("Expected AUDIO track in test input Alternatives[0]")
}

if alt0.Channels != 2 {
t.Error("Expected 2 channels track in test input Alternatives[0]")
}

alt1 := pp.Variants[0].Alternatives[1]
if alt1.Type != "AUDIO" {
t.Error("Expected AUDIO track in test input Alternatives[1]")
}

if alt1.Channels != 6 {
t.Error("Expected 6 channels track in test input Alternatives[1]")
}
}

/****************
* Benchmarks *
****************/
Expand Down
13 changes: 13 additions & 0 deletions sample-playlists/master-with-channels.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#EXTM3U
#EXT-X-VERSION:6
#EXT-X-INDEPENDENT-SEGMENTS


#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="a1",NAME="English",LANGUAGE="en-US",AUTOSELECT=YES,DEFAULT=YES,CHANNELS="2",URI="a1/prog_index.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="a2",NAME="English",LANGUAGE="en-US",AUTOSELECT=YES,DEFAULT=YES,CHANNELS="6",URI="a2/prog_index.m3u8"

#EXT-X-STREAM-INF:AVERAGE-BANDWIDTH=2190673,BANDWIDTH=2523597,CODECS="avc1.640020,mp4a.40.2",RESOLUTION=960x540,FRAME-RATE=60.000,AUDIO="a1"
v5/prog_index.m3u8
#EXT-X-STREAM-INF:AVERAGE-BANDWIDTH=8052613,BANDWIDTH=9873268,CODECS="avc1.64002a,mp4a.40.2",RESOLUTION=1920x1080,FRAME-RATE=60.000,AUDIO="a1"
v9/prog_index.m3u8

1 change: 1 addition & 0 deletions structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ type Alternative struct {
Forced string
Characteristics string
Subtitles string
Channels uint
}

// MediaSegment structure represents a media segment included in a
Expand Down
5 changes: 5 additions & 0 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ func (p *MasterPlaylist) Encode() *bytes.Buffer {
p.buf.WriteString(alt.URI)
p.buf.WriteRune('"')
}
if alt.Channels != 0 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must go before the newline just above.

p.buf.WriteString(",CHANNELS=\"")
p.buf.WriteString(strconv.FormatUint(uint64(alt.Channels), 10))
p.buf.WriteRune('"')
}
p.buf.WriteRune('\n')
}
}
Expand Down