Skip to content

Commit

Permalink
muxer: progressively increase SequenceNumber of parts (#115)
Browse files Browse the repository at this point in the history
this prevents warning 'Fragment sequence discontinuity detected' in
VLC.
  • Loading branch information
aler9 authored Dec 26, 2023
1 parent d761dd2 commit a85e630
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
4 changes: 3 additions & 1 deletion muxer_part.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ func (p *muxerPart) computeDuration(nextDTS time.Duration) time.Duration {
}

func (p *muxerPart) finalize(nextDTS time.Duration) error {
part := fmp4.Part{}
part := fmp4.Part{
SequenceNumber: uint32(p.id),
}

if p.videoSamples != nil {
part.Tracks = append(part.Tracks, &fmp4.PartTrack{
Expand Down
48 changes: 42 additions & 6 deletions muxer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"regexp"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -822,12 +823,10 @@ func TestMuxerDynamicParams(t *testing.T) {
bu, _, err = doRequest(m, m.prefix+"_init.mp4", "", "", "")
require.NoError(t, err)

func() {
var init fmp4.Init
err = init.Unmarshal(bu)
require.NoError(t, err)
require.Equal(t, testSPS2, init.Tracks[0].Codec.(*fmp4.CodecH264).SPS)
}()
var init fmp4.Init
err = init.Unmarshal(bu)
require.NoError(t, err)
require.Equal(t, testSPS2, init.Tracks[0].Codec.(*fmp4.CodecH264).SPS)
}

func TestMuxerFMP4ZeroDuration(t *testing.T) {
Expand Down Expand Up @@ -950,3 +949,40 @@ func TestMuxerFMP4NegativeTimestamp(t *testing.T) {
},
}}, parts)
}

func TestMuxerFMP4SequenceNumber(t *testing.T) {
m := &Muxer{
Variant: MuxerVariantLowLatency,
SegmentCount: 7,
SegmentDuration: 2 * time.Second,
VideoTrack: testVideoTrack,
}

err := m.Start()
require.NoError(t, err)
defer m.Close()

err = m.WriteH26x(testTime, 0, [][]byte{
testSPS,
{5}, // IDR
{1},
})
require.NoError(t, err)

for i := 0; i < 3; i++ {
err = m.WriteH26x(testTime, (1+time.Duration(i))*time.Second, [][]byte{
{1}, // non IDR
})
require.NoError(t, err)
}

for i := 0; i < 3; i++ {
buf, _, err := doRequest(m, m.prefix+"_part"+strconv.FormatInt(int64(i), 10)+".mp4", "", "", "")
require.NoError(t, err)

var parts fmp4.Parts
err = parts.Unmarshal(buf)
require.NoError(t, err)
require.Equal(t, uint32(i), parts[0].SequenceNumber)
}
}

0 comments on commit a85e630

Please sign in to comment.