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

Commit

Permalink
Fix #7 EXT-X-DISCONTINUITY parsing error
Browse files Browse the repository at this point in the history
It also apply to EXT-X-PROGRAM-DATE-TIME parsing.
Unit tests updated.
  • Loading branch information
grafov committed Feb 1, 2015
1 parent 404f61e commit 6732a16
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
6 changes: 4 additions & 2 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,14 @@ func decodeLineOfMediaPlaylist(p *MediaPlaylist, wv *WV, state *decodingState, l
return err
}
state.tagRange = false
} else if state.tagDiscontinuity {
}
if state.tagDiscontinuity {
state.tagDiscontinuity = false
if err = p.SetDiscontinuity(); strict && err != nil {
return err
}
} else if state.tagProgramDateTime {
}
if state.tagProgramDateTime {
state.tagProgramDateTime = false
if err = p.SetProgramDateTime(state.programDateTime); strict && err != nil {
return err
Expand Down
28 changes: 28 additions & 0 deletions reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package m3u8

import (
"bufio"
"fmt"
"os"
"testing"
)
Expand Down Expand Up @@ -169,3 +170,30 @@ func TestDecodeMediaPlaylistWithAutodetection(t *testing.T) {
// TODO check other values…
// fmt.Println(pp.Encode().String())
}

/***************************
* Code parsing examples *
***************************/

// Parse playlist with EXT-X-DISCONTINUITY tag
func ExampleDecodeMediaPlaylistWithDiscontinuity() {
f, _ := os.Open("sample-playlists/media-playlist-with-discontinuity.m3u8")
p, _, _ := DecodeFrom(bufio.NewReader(f), true)
pp := p.(*MediaPlaylist)
pp.DurationAsInt(true)
fmt.Printf("%s", pp)
// Output:
// #EXTM3U
// #EXT-X-VERSION:3
// #EXT-X-MEDIA-SEQUENCE:1
// #EXT-X-TARGETDURATION:10
// #EXTINF:10,
// ad0.ts
// #EXTINF:8,
// ad1.ts
// #EXT-X-DISCONTINUITY
// #EXTINF:10,
// movieA.ts
// #EXTINF:10,
// movieB.ts
}
15 changes: 15 additions & 0 deletions sample-playlists/media-playlist-with-discontinuity.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# https://developer.apple.com/library/ios/technotes/tn2288/_index.html
#
#EXTM3U
#EXT-X-TARGETDURATION:10
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:10.0,
ad0.ts
#EXTINF:8.0,
ad1.ts
#EXT-X-DISCONTINUITY
#EXTINF:10.0,
movieA.ts
#EXTINF:10.0,
movieB.ts
8 changes: 4 additions & 4 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ func TestEncodeMasterPlaylist(t *testing.T) {
m.Append("chunklist2.m3u8", p, VariantParams{ProgramId: 123, Bandwidth: 1500000, Resolution: "576x480"})
}

/*******************
* Code examples *
*******************/
/******************************
* Code generation examples *
******************************/

// Create new media playlist
// Add two segments to media playlist
Expand All @@ -404,7 +404,7 @@ func ExampleMediaPlaylist_String() {
// #EXT-X-VERSION:3
// #EXT-X-MEDIA-SEQUENCE:1
// #EXT-X-TARGETDURATION:6
// #EXTINF:5,
// #EXTINF:5.000,
// test01.ts
}

Expand Down

0 comments on commit 6732a16

Please sign in to comment.