Skip to content

Commit

Permalink
fix 'fragment sequence discontinuity' warning when reading record seg…
Browse files Browse the repository at this point in the history
…ments with VLC
  • Loading branch information
aler9 committed Oct 7, 2023
1 parent ca2a487 commit a097deb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/aler9/writerseeker v1.1.0
github.com/bluenviron/gohlslib v1.0.3
github.com/bluenviron/gortsplib/v4 v4.2.0
github.com/bluenviron/mediacommon v1.4.1-0.20231007133411-92ec4e147f89
github.com/bluenviron/mediacommon v1.4.1-0.20231007152904-4c7d799a3253
github.com/datarhei/gosrt v0.5.4
github.com/fsnotify/fsnotify v1.6.0
github.com/gin-gonic/gin v1.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ github.com/bluenviron/gohlslib v1.0.3 h1:FMHevlIrrZ67uzCXmlTSGflsfYREEtHb8L9BDyf
github.com/bluenviron/gohlslib v1.0.3/go.mod h1:R/aIsSxLI61N0CVMjtcHqJouK6+Ddd5YIihcCr7IFIw=
github.com/bluenviron/gortsplib/v4 v4.2.0 h1:EbIMqkFxFo/iG5Hkld+Flew9R8ORKnuxlgUyFdpd5Rk=
github.com/bluenviron/gortsplib/v4 v4.2.0/go.mod h1:wz9d4Tn2qS/mexc+BnvNeWzlNOpyaHzNK6SXxtg4mfM=
github.com/bluenviron/mediacommon v1.4.1-0.20231007133411-92ec4e147f89 h1:IEicF/CpzU78BJ95v0XwTWL5D2Kr2grlpe5jnuhbRN8=
github.com/bluenviron/mediacommon v1.4.1-0.20231007133411-92ec4e147f89/go.mod h1:Ij/kE1LEucSjryNBVTyPL/gBI0d6/Css3f5PyrM957w=
github.com/bluenviron/mediacommon v1.4.1-0.20231007152904-4c7d799a3253 h1:r98CMlefqn1U/mYHifWD9Udb52E8axvjUkv70FJV2qQ=
github.com/bluenviron/mediacommon v1.4.1-0.20231007152904-4c7d799a3253/go.mod h1:Ij/kE1LEucSjryNBVTyPL/gBI0d6/Css3f5PyrM957w=
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
Expand Down
13 changes: 7 additions & 6 deletions internal/record/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,13 @@ type Agent struct {
onSegmentComplete func(string)
parent logger.Writer

ctx context.Context
ctxCancel func()
writer *asyncwriter.Writer
tracks []*track
hasVideo bool
currentSegment *segment
ctx context.Context
ctxCancel func()
writer *asyncwriter.Writer
tracks []*track
hasVideo bool
currentSegment *segment
nextSequenceNumber uint32

done chan struct{}
}
Expand Down
20 changes: 12 additions & 8 deletions internal/record/part.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/bluenviron/mediamtx/internal/logger"
)

func writePart(f io.Writer, partTracks map[*track]*fmp4.PartTrack) error {
func writePart(f io.Writer, sequenceNumber uint32, partTracks map[*track]*fmp4.PartTrack) error {
fmp4PartTracks := make([]*fmp4.PartTrack, len(partTracks))
i := 0
for _, partTrack := range partTracks {
Expand All @@ -21,7 +21,8 @@ func writePart(f io.Writer, partTracks map[*track]*fmp4.PartTrack) error {
}

part := &fmp4.Part{
Tracks: fmp4PartTracks,
SequenceNumber: sequenceNumber,
Tracks: fmp4PartTracks,
}

var ws writerseeker.WriterSeeker
Expand All @@ -35,21 +36,24 @@ func writePart(f io.Writer, partTracks map[*track]*fmp4.PartTrack) error {
}

type part struct {
s *segment
startDTS time.Duration
s *segment
sequenceNumber uint32
startDTS time.Duration

partTracks map[*track]*fmp4.PartTrack
endDTS time.Duration
}

func newPart(
s *segment,
sequenceNumber uint32,
startDTS time.Duration,
) *part {
return &part{
s: s,
startDTS: startDTS,
partTracks: make(map[*track]*fmp4.PartTrack),
s: s,
startDTS: startDTS,
sequenceNumber: sequenceNumber,
partTracks: make(map[*track]*fmp4.PartTrack),
}
}

Expand Down Expand Up @@ -77,7 +81,7 @@ func (p *part) close() error {
p.s.f = f
}

return writePart(p.s.f, p.partTracks)
return writePart(p.s.f, p.sequenceNumber, p.partTracks)
}

func (p *part) record(track *track, sample *sample) error {
Expand Down
6 changes: 4 additions & 2 deletions internal/record/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func (s *segment) close() error {

func (s *segment) record(track *track, sample *sample) error {
if s.curPart == nil {
s.curPart = newPart(s, sample.dts)
s.curPart = newPart(s, s.r.nextSequenceNumber, sample.dts)
s.r.nextSequenceNumber++
} else if s.curPart.duration() >= s.r.partDuration {
err := s.curPart.close()
s.curPart = nil
Expand All @@ -85,7 +86,8 @@ func (s *segment) record(track *track, sample *sample) error {
return err
}

s.curPart = newPart(s, sample.dts)
s.curPart = newPart(s, s.r.nextSequenceNumber, sample.dts)
s.r.nextSequenceNumber++

Check warning on line 90 in internal/record/segment.go

View check run for this annotation

Codecov / codecov/patch

internal/record/segment.go#L89-L90

Added lines #L89 - L90 were not covered by tests
}

return s.curPart.record(track, sample)
Expand Down

0 comments on commit a097deb

Please sign in to comment.