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

Support Name attribute in #EXT-X-STREAM-INF tag #30

Merged
merged 1 commit into from
Oct 17, 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
2 changes: 2 additions & 0 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ func decodeLineOfMasterPlaylist(p *MasterPlaylist, state *decodingState, line st
state.variant.Subtitles = v
case "CLOSED-CAPTIONS":
state.variant.Captions = v
case "NAME":
state.variant.Name = v
}
}
case state.tagStreamInf && !strings.HasPrefix(line, "#"):
Expand Down
18 changes: 18 additions & 0 deletions reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,24 @@ func TestDecodeMasterPlaylistWithAlternatives(t *testing.T) {
//fmt.Println(p.Encode().String())
}

// Decode a master playlist with Name tag in EXT-X-STREAM-INF
func TestDecodeMasterPlaylistWithStreamInfName(t *testing.T) {
f, err := os.Open("sample-playlists/master-with-stream-inf-name.m3u8")
if err != nil {
t.Fatal(err)
}
p := NewMasterPlaylist()
err = p.DecodeFrom(bufio.NewReader(f), false)
if err != nil {
t.Fatal(err)
}
for _, variant := range p.Variants {
if variant.Name == "" {
t.Errorf("Empty name tag on variant URI: %s", variant.URI)
}
}
}

func TestDecodeMediaPlaylist(t *testing.T) {
f, err := os.Open("sample-playlists/wowza-vod-chunklist.m3u8")
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions sample-playlists/master-with-stream-inf-name.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1828000,NAME="3 high",RESOLUTION=896x504
chunklist_b1828000_t64NCBoaWdo.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=678000,NAME="2 med",RESOLUTION=512x288
chunklist_b678000_t64MiBtZWQ=.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=438000,NAME="1 low",RESOLUTION=384x216
chunklist_b438000_t64MSBsb3c=.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=128000,NAME="0 audio"
chunklist_b128000_t64MCBhdWRpbw==.m3u8
1 change: 1 addition & 0 deletions structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ type VariantParams struct {
Video string
Subtitles string // EXT-X-STREAM-INF only
Captions string // EXT-X-STREAM-INF only
Name string // EXT-X-STREAM-INF only (non standard Wowza/JWPlayer extension to name the variant/quality in UA)
Iframe bool // EXT-X-I-FRAME-STREAM-INF
Alternatives []*Alternative
}
Expand Down
5 changes: 5 additions & 0 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ func (p *MasterPlaylist) Encode() *bytes.Buffer {
p.buf.WriteString(pl.Subtitles)
p.buf.WriteRune('"')
}
if pl.Name != "" {
p.buf.WriteString(",NAME=\"")
p.buf.WriteString(pl.Name)
p.buf.WriteRune('"')
}
p.buf.WriteRune('\n')
p.buf.WriteString(pl.URI)
if p.Args != "" {
Expand Down
24 changes: 24 additions & 0 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package m3u8

import (
"fmt"
"strings"
"testing"
"time"
)
Expand Down Expand Up @@ -446,6 +447,29 @@ func TestEncodeMasterPlaylist(t *testing.T) {
m.Append("chunklist2.m3u8", p, VariantParams{ProgramId: 123, Bandwidth: 1500000, Resolution: "576x480"})
}

// Create new master playlist with Name tag in EXT-X-STREAM-INF
func TestEncodeMasterPlaylistWithStreamInfName(t *testing.T) {
m := NewMasterPlaylist()
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{ProgramId: 123, Bandwidth: 3000000, Resolution: "1152x960", Name: "HD 960p"})

if m.Variants[0].Name != "HD 960p" {
t.Fatalf("Create master with Name in EXT-X-STREAM-INF failed")
}
if !strings.Contains(m.String(), "NAME=\"HD 960p\"") {
t.Fatalf("Encode master with Name in EXT-X-STREAM-INF failed")
}
}

/******************************
* Code generation examples *
******************************/
Expand Down