Skip to content

Commit

Permalink
Merge pull request #38 from hori-ryota/feature/bugfix-winsize-zero
Browse files Browse the repository at this point in the history
Fix bug of writing vod playlist when winsize=0
  • Loading branch information
grafov authored Jul 31, 2016
2 parents c438b64 + b76ffc1 commit 2244be1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func (p *MediaPlaylist) Encode() *bytes.Buffer {

head := p.head
count := p.count
for i := uint(0); i < p.winsize && count > 0; count-- {
for i := uint(0); (i < p.winsize || p.winsize == 0) && count > 0; count-- {
seg = p.Segments[head]
head = (head + 1) % p.capacity
if seg == nil { // protection from badly filled chunklists
Expand Down
40 changes: 40 additions & 0 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,46 @@ func ExampleMediaPlaylist_String() {
// test01.ts
}

// Create new media playlist
// Add two segments to media playlist
// Print it
func ExampleMediaPlaylist_String_Winsize0() {
p, _ := NewMediaPlaylist(0, 2)
p.Append("test01.ts", 5.0, "")
p.Append("test02.ts", 6.0, "")
fmt.Printf("%s\n", p)
// Output:
// #EXTM3U
// #EXT-X-VERSION:3
// #EXT-X-MEDIA-SEQUENCE:0
// #EXT-X-TARGETDURATION:6
// #EXTINF:5.000,
// test01.ts
// #EXTINF:6.000,
// test02.ts
}

// Create new media playlist
// Add two segments to media playlist
// Print it
func ExampleMediaPlaylist_String_Winsize0_VOD() {
p, _ := NewMediaPlaylist(0, 2)
p.Append("test01.ts", 5.0, "")
p.Append("test02.ts", 6.0, "")
p.Close()
fmt.Printf("%s\n", p)
// Output:
// #EXTM3U
// #EXT-X-VERSION:3
// #EXT-X-MEDIA-SEQUENCE:0
// #EXT-X-TARGETDURATION:6
// #EXTINF:5.000,
// test01.ts
// #EXTINF:6.000,
// test02.ts
// #EXT-X-ENDLIST
}

// Create new master playlist
// Add media playlist
// Encode structures to HLS
Expand Down

0 comments on commit 2244be1

Please sign in to comment.