Skip to content

Commit

Permalink
VR-3886 HLS spec compliance: EXT-X-MAP is a quoted string
Browse files Browse the repository at this point in the history
  • Loading branch information
vish91 committed Jan 8, 2024
1 parent 7a67f19 commit 6eb11f8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#EXTM3U
#EXT-X-VERSION:5
#EXT-X-MAP:URI="https://example.com/content-init.mp4",BYTERANGE=1024000@1048576
#EXT-X-MAP:URI="https://example.com/content-init.mp4",BYTERANGE="1024000@1048576"
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-TARGETDURATION:6
#EXTINF:5.000,
test01.mp4
#EXT-X-DISCONTINUITY
#EXT-X-MAP:URI="https://segmentencoded.com/ad-init.mp4",BYTERANGE=1024000@1048576
#EXT-X-MAP:URI="https://segmentencoded.com/ad-init.mp4",BYTERANGE="1024000@1048576"
#EXTINF:6.000,
test02.mp4
#EXTINF:6.000,
test03.mp4
#EXT-X-DISCONTINUITY
#EXT-X-MAP:URI="https://example.com/content-init.mp4",BYTERANGE=1024000@1048576
#EXT-X-MAP:URI="https://example.com/content-init.mp4",BYTERANGE="1024000@1048576"
#EXTINF:6.000,
test04.mp4
#EXTINF:6.000,
Expand Down
2 changes: 1 addition & 1 deletion sample-playlists/master-playlist-with-maps.m3u8
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#EXTM3U
#EXT-X-VERSION:5
#EXT-X-MAP:URI="https://example.com/content-init.mp4",BYTERANGE=1024000@1048576
#EXT-X-MAP:URI="https://example.com/content-init.mp4",BYTERANGE="1024000@1048576"
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-TARGETDURATION:6
#EXTINF:6.000,
Expand Down
9 changes: 6 additions & 3 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,11 @@ func (p *MediaPlaylist) Encode() *bytes.Buffer {
p.buf.WriteString(p.Map.URI)
p.buf.WriteRune('"')
if p.Map.Limit > 0 {
p.buf.WriteString(",BYTERANGE=")
p.buf.WriteString(",BYTERANGE=\"")
p.buf.WriteString(strconv.FormatInt(p.Map.Limit, 10))
p.buf.WriteRune('@')
p.buf.WriteString(strconv.FormatInt(p.Map.Offset, 10))
p.buf.WriteRune('"')
}
p.buf.WriteRune('\n')
}
Expand Down Expand Up @@ -751,10 +752,11 @@ func (p *MediaPlaylist) Encode() *bytes.Buffer {
p.buf.WriteString(seg.Map.URI)
p.buf.WriteRune('"')
if seg.Map.Limit > 0 {
p.buf.WriteString(",BYTERANGE=")
p.buf.WriteString(",BYTERANGE=\"")
p.buf.WriteString(strconv.FormatInt(seg.Map.Limit, 10))
p.buf.WriteRune('@')
p.buf.WriteString(strconv.FormatInt(seg.Map.Offset, 10))
p.buf.WriteRune('"')
}
p.buf.WriteRune('\n')
}
Expand All @@ -765,10 +767,11 @@ func (p *MediaPlaylist) Encode() *bytes.Buffer {
p.buf.WriteString(seg.Map.URI)
p.buf.WriteRune('"')
if seg.Map.Limit > 0 {
p.buf.WriteString(",BYTERANGE=")
p.buf.WriteString(",BYTERANGE=\"")
p.buf.WriteString(strconv.FormatInt(seg.Map.Limit, 10))
p.buf.WriteRune('@')
p.buf.WriteString(strconv.FormatInt(seg.Map.Offset, 10))
p.buf.WriteRune('"')
}
p.buf.WriteRune('\n')
}
Expand Down
14 changes: 7 additions & 7 deletions writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ func TestSetDefaultMapForMediaPlaylist(t *testing.T) {
}
p.SetDefaultMap("https://example.com", 1000*1024, 1024*1024)

expected := `EXT-X-MAP:URI="https://example.com",BYTERANGE=1024000@1048576`
expected := `EXT-X-MAP:URI="https://example.com",BYTERANGE="1024000@1048576"`
if !strings.Contains(p.String(), expected) {
t.Fatalf("Media playlist did not contain: %s\nMedia Playlist:\n%v", expected, p.String())
}
Expand All @@ -338,7 +338,7 @@ func TestSetMapForMediaPlaylist(t *testing.T) {
t.Errorf("Set map to a media playlist failed: %s", e)
}

expected := `EXT-X-MAP:URI="https://example.com",BYTERANGE=1024000@1048576
expected := `EXT-X-MAP:URI="https://example.com",BYTERANGE="1024000@1048576"
#EXTINF:5.000,
test01.ts`
if !strings.Contains(p.String(), expected) {
Expand Down Expand Up @@ -367,7 +367,7 @@ func TestEncodeMediaPlaylistWithDefaultMap(t *testing.T) {
}

encoded := p.String()
expected := `EXT-X-MAP:URI="https://example.com",BYTERANGE=1024000@1048576`
expected := `EXT-X-MAP:URI="https://example.com",BYTERANGE="1024000@1048576"`
if !strings.Contains(encoded, expected) {
t.Fatalf("Media playlist did not contain: %s\nMedia Playlist:\n%v", expected, encoded)
}
Expand Down Expand Up @@ -409,11 +409,11 @@ func TestEncodeMediaPlaylistWithDiscontinuityAndDefaultMap(t *testing.T) {
}
encoded := p.String()
//fmt.Println(p.Encode().String())
expectDefaultMap := `EXT-X-MAP:URI="https://example.com",BYTERANGE=1024000@1048576`
expectDefaultMap := `EXT-X-MAP:URI="https://example.com",BYTERANGE="1024000@1048576"`
if !strings.Contains(encoded, expectDefaultMap) {
t.Fatalf("Media playlist did not contain: %s\nMedia Playlist:\n%v", expectDefaultMap, encoded)
}
expectSegmentMap := `EXT-X-MAP:URI="https://segmentencoded.com",BYTERANGE=1024000@1048576`
expectSegmentMap := `EXT-X-MAP:URI="https://segmentencoded.com",BYTERANGE="1024000@1048576"`
if !strings.Contains(encoded, expectSegmentMap) {
t.Fatalf("Media playlist did not contain: %s\nMedia Playlist:\n%v", expectSegmentMap, encoded)
}
Expand Down Expand Up @@ -449,11 +449,11 @@ func TestEncodeMediaPlaylistWithDiscontinuityAndDefaultMapWithAppendSegment(t *t
}
encoded := p.String()
//fmt.Println(p.Encode().String())
expectDefaultMap := `EXT-X-MAP:URI="https://example.com",BYTERANGE=1024000@1048576`
expectDefaultMap := `EXT-X-MAP:URI="https://example.com",BYTERANGE="1024000@1048576"`
if !strings.Contains(encoded, expectDefaultMap) {
t.Fatalf("Media playlist did not contain: %s\nMedia Playlist:\n%v", expectDefaultMap, encoded)
}
expectSegmentMap := `EXT-X-MAP:URI="https://segmentencoded.com",BYTERANGE=1024000@1048576`
expectSegmentMap := `EXT-X-MAP:URI="https://segmentencoded.com",BYTERANGE="1024000@1048576"`
if !strings.Contains(encoded, expectSegmentMap) {
t.Fatalf("Media playlist did not contain: %s\nMedia Playlist:\n%v", expectSegmentMap, encoded)
}
Expand Down

0 comments on commit 6eb11f8

Please sign in to comment.