Skip to content

Commit

Permalink
fix: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Wkkkkk committed Feb 11, 2025
1 parent 33a9ed6 commit 2a615f7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion m3u8/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ func parsePreloadHint(parameters string) (*PreloadHint, error) {
case "BYTERANGE-LENGTH":
length, err := strconv.ParseInt(attr.Val, 10, 64)
if err != nil {
return nil, fmt.Errorf("start parsing error: %w", err)
return nil, fmt.Errorf("length parsing error: %w", err)
}
ph.Limit = length
}
Expand Down
10 changes: 6 additions & 4 deletions m3u8/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ func TestDecodeLowLatencyMediaPlaylist(t *testing.T) {
is.True(!pp.Closed) // live playlist
is.Equal(pp.SeqNo, uint64(244))
is.Equal(pp.Count(), uint(6))
is.Equal(pp.PartTargetDuration, float32(1.002000))
is.Equal(pp.PartTargetDuration, 1.002)

// segment names should be in the following format fileSequence%d.m4s
// starting from fileSequence235.m4s
Expand All @@ -900,15 +900,17 @@ func TestDecodeLowLatencyMediaPlaylist(t *testing.T) {

is.Equal(len(pp.PartialSegments), int(10)) // partial segment count must be 10

for _, ps := range pp.PartialSegments {
for i, ps := range pp.PartialSegments {
// The partial segments should have a duration of 1 second
is.Equal(ps.Duration, float64(1.0))
is.True(ps.Independent)
if i < 8 {
is.True(ps.Independent)
}
// partial segment names should be in the following format filePart%d.%d.m4s
is.True(strings.HasPrefix(ps.URI, "filePart"))
}

// The ProgramDateTime of the 8st partial segment should be: 2025-02-10T14:43:30.134Z
// The ProgramDateTime of the 9th partial segment should be: 2025-02-10T14:43:30.134Z
st, _ = time.Parse(time.RFC3339, "2025-02-10T14:43:30.134+00:00")
if !pp.PartialSegments[8].ProgramDateTime.Equal(st) {
t.Errorf("The program date time of the 8st partial segment should be: %v, actual value: %v",
Expand Down
4 changes: 2 additions & 2 deletions m3u8/sample-playlists/media-playlist-low-latency.m3u8
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ fileSequence249.m4s
#EXTINF:4.000,
fileSequence250.m4s
#EXT-X-PROGRAM-DATE-TIME:2025-02-10T14:43:30.134Z
#EXT-X-PART:DURATION=1.000,INDEPENDENT=YES,URI="filePart251.1.m4s"
#EXT-X-PART:DURATION=1.000,INDEPENDENT=YES,URI="filePart251.2.m4s"
#EXT-X-PART:DURATION=1.000,URI="filePart251.1.m4s"
#EXT-X-PART:DURATION=1.000,URI="filePart251.2.m4s"
#EXT-X-PRELOAD-HINT:TYPE=PART,URI="filePart251.3.m4s"
2 changes: 1 addition & 1 deletion m3u8/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ type MediaPlaylist struct {
ver uint8 // protocol version of the playlist, 3 or higher
targetDurLocked bool // target duration is locked and cannot be changed
independentSegments bool // Global tag for EXT-X-INDEPENDENT-SEGMENTS
PartTargetDuration float32 // EXT-X-PART-INF:PART-TARGET
PartTargetDuration float64 // EXT-X-PART-INF:PART-TARGET
PartialSegments []*PartialSegment // List of partial segments in the playlist.
PreloadHints *PreloadHint // EXT-X-PRELOAD-HINT tags
}
Expand Down
2 changes: 1 addition & 1 deletion m3u8/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ func (p *MediaPlaylist) Encode() *bytes.Buffer {
}
if p.PartTargetDuration > 0 {
p.buf.WriteString("#EXT-X-PART-INF:PART-TARGET=")
p.buf.WriteString(strconv.FormatFloat(float64(p.PartTargetDuration), 'f', 3, 64))
p.buf.WriteString(strconv.FormatFloat(p.PartTargetDuration, 'f', 3, 64))
p.buf.WriteRune('\n')
}
p.buf.WriteString("#EXT-X-MEDIA-SEQUENCE:")
Expand Down

0 comments on commit 2a615f7

Please sign in to comment.