Skip to content

Commit

Permalink
Add CLOSED-CAPTIONS= to writer for (STREAM-INF) (grafov#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbowBC authored and bradleyfalzon committed Mar 7, 2017
1 parent ec85e01 commit e521730
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
21 changes: 21 additions & 0 deletions reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ func TestDecodeMasterPlaylistWithAlternatives(t *testing.T) {
// fmt.Println(p.Encode().String())
}

func TestDecodeMasterPlaylistWithClosedCaptionEqNone(t *testing.T) {
f, err := os.Open("sample-playlists/master-with-closed-captions-eq-none.m3u8")
if err != nil {
t.Fatal(err)
}
p := NewMasterPlaylist()
err = p.DecodeFrom(bufio.NewReader(f), false)
if err != nil {
t.Fatal(err)
}

if len(p.Variants) != 3 {
t.Fatal("not all variants in master playlist parsed")
}
for _, v := range p.Variants {
if v.Captions != "NONE" {
t.Fatal("variant field for CLOSED-CAPTIONS should be equal to NONE but it equals", v.Captions)
}
}
}

// 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")
Expand Down
13 changes: 13 additions & 0 deletions sample-playlists/master-with-closed-captions-eq-none.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#EXTM3U
#EXT-X-VERSION:4
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio0",NAME="fra",DEFAULT=YES,AUTOSELECT=YES,LANGUAGE="fra",URI="audio_64_fra_rendition.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio1",NAME="fra",DEFAULT=YES,AUTOSELECT=YES,LANGUAGE="fra",URI="audio_128_fra_rendition.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio0",NAME="eng",DEFAULT=NO,AUTOSELECT=YES,LANGUAGE="eng",URI="audio_64_eng_rendition.m3u8"
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio1",NAME="eng",DEFAULT=NO,AUTOSELECT=YES,LANGUAGE="eng",URI="audio_128_eng_rendition.m3u8"
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subtitles0",NAME="eng_subtitle",DEFAULT=NO,AUTOSELECT=YES,LANGUAGE="eng",URI="subtitle_eng_rendition.m3u8"
#EXT-X-STREAM-INF:PROGRAM-ID=0,BANDWIDTH=1170400,CODECS="avc1",RESOLUTION=320x240,AUDIO="audio0",CLOSED-CAPTIONS="NONE",SUBTITLES="subtitles0"
1_rendition.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=0,BANDWIDTH=3630000,CODECS="avc1",RESOLUTION=854x480,AUDIO="audio1",CLOSED-CAPTIONS="NONE",SUBTITLES="subtitles0"
2_rendition.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=0,BANDWIDTH=6380000,CODECS="avc1",RESOLUTION=1920x1080,AUDIO="audio1",CLOSED-CAPTIONS="NONE",SUBTITLES="subtitles0"
3_rendition.m3u8
5 changes: 5 additions & 0 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ func (p *MasterPlaylist) Encode() *bytes.Buffer {
p.buf.WriteString(pl.Video)
p.buf.WriteRune('"')
}
if pl.Captions != "" {
p.buf.WriteString(",CLOSED-CAPTIONS=\"")
p.buf.WriteString(pl.Captions)
p.buf.WriteRune('"')
}
if pl.Subtitles != "" {
p.buf.WriteString(",SUBTITLES=\"")
p.buf.WriteString(pl.Subtitles)
Expand Down
26 changes: 26 additions & 0 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,32 @@ func TestNewMasterPlaylistWithAlternatives(t *testing.T) {
if m.ver != 4 {
t.Fatalf("Expected version 4, actual, %d", m.ver)
}
fmt.Printf("%v\n", m)
}

// Create new master playlist supporting closed-caption=none
func TestNewMasterPlaylistWithClosedCaptionEqNone(t *testing.T) {
m := NewMasterPlaylist()

vp := &VariantParams{
ProgramId: 0,
Bandwidth: 8000,
Codecs: "avc1",
Resolution: "1280x720",
Audio: "audio0",
Captions: "NONE",
}

p, err := NewMediaPlaylist(1, 1)
if err != nil {
t.Fatalf("Create media playlist failed: %s", err)
}
m.Append(fmt.Sprintf("eng_rendition_rendition.m3u8"), p, *vp)

expected := `CLOSED-CAPTIONS="NONE"`
if !strings.Contains(m.String(), expected) {
t.Fatalf("Master playlist did not contain: %s, \nMaster Playlist: \n%v", expected, m.String())
}
}

// Create new master playlist with params
Expand Down

0 comments on commit e521730

Please sign in to comment.