Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

playback: fix bug that messed up duration of last sample of each track #3210

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions internal/playback/on_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func writeSegment2(t *testing.T, fpath string) {
var buf2 seekablebuffer.Buffer
parts := fmp4.Parts{
{
SequenceNumber: 1,
SequenceNumber: 3,
Tracks: []*fmp4.PartTrack{{
ID: 1,
BaseTime: 0,
Expand All @@ -152,6 +152,20 @@ func writeSegment2(t *testing.T, fpath string) {
},
}},
},
{
SequenceNumber: 4,
Tracks: []*fmp4.PartTrack{{
ID: 1,
BaseTime: 2 * 90000,
Samples: []*fmp4.PartSample{
{
Duration: 1 * 90000,
IsNonSyncSample: false,
Payload: []byte{11, 12},
},
},
}},
},
}
err = parts.Marshal(&buf2)
require.NoError(t, err)
Expand Down Expand Up @@ -189,7 +203,7 @@ func writeSegment3(t *testing.T, fpath string) {
{
Duration: 1 * 90000,
IsNonSyncSample: false,
Payload: []byte{10, 11},
Payload: []byte{13, 14},
},
},
}},
Expand Down Expand Up @@ -479,6 +493,10 @@ func TestOnGetNTPCompensation(t *testing.T) {
Duration: 90000,
Payload: []byte{9, 10},
},
{
Duration: 90000,
Payload: []byte{11, 12},
},
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions internal/playback/on_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ func TestOnList(t *testing.T) {

require.Equal(t, []interface{}{
map[string]interface{}{
"duration": float64(64),
"duration": float64(65),
"start": time.Date(2008, 11, 0o7, 11, 22, 0, 500000000, time.Local).Format(time.RFC3339Nano),
},
map[string]interface{}{
"duration": float64(2),
"duration": float64(3),
"start": time.Date(2009, 11, 0o7, 11, 23, 2, 500000000, time.Local).Format(time.RFC3339Nano),
},
}, out)
Expand Down
12 changes: 10 additions & 2 deletions internal/playback/segment_fmp4.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ func segmentFMP4SeekAndMuxParts(
}

muxerDTS := int64(tfdt.BaseMediaDecodeTimeV1) - int64(segmentStartOffsetMP4)
atLeastOneSampleWritten := false

for _, e := range trun.Entries {
if muxerDTS >= int64(durationMP4) {
Expand Down Expand Up @@ -386,10 +387,13 @@ func segmentFMP4SeekAndMuxParts(
return nil, err
}

atLeastOneSampleWritten = true
muxerDTS += int64(e.SampleDuration)
}

m.writeFinalDTS(muxerDTS)
if atLeastOneSampleWritten {
m.writeFinalDTS(muxerDTS)
}

if muxerDTS > maxMuxerDTS {
maxMuxerDTS = muxerDTS
Expand Down Expand Up @@ -467,6 +471,7 @@ func segmentFMP4WriteParts(
}

muxerDTS := int64(tfdt.BaseMediaDecodeTimeV1) + int64(segmentStartOffsetMP4)
atLeastOneSampleWritten := false

for _, e := range trun.Entries {
if muxerDTS >= int64(durationMP4) {
Expand All @@ -490,10 +495,13 @@ func segmentFMP4WriteParts(
return nil, err
}

atLeastOneSampleWritten = true
muxerDTS += int64(e.SampleDuration)
}

m.writeFinalDTS(muxerDTS)
if atLeastOneSampleWritten {
m.writeFinalDTS(muxerDTS)
}

if muxerDTS > maxMuxerDTS {
maxMuxerDTS = muxerDTS
Expand Down
Loading