Skip to content

Commit

Permalink
muxer: serve different tracks in different streams (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Oct 2, 2024
1 parent a94133b commit 56d25b4
Show file tree
Hide file tree
Showing 6 changed files with 528 additions and 412 deletions.
2 changes: 1 addition & 1 deletion muxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (m *Muxer) Start() error {
}

switch {
case true || m.Variant == MuxerVariantMPEGTS:
case m.Variant == MuxerVariantMPEGTS:
stream := &muxerStream{
muxer: m,
tracks: m.mtracks,
Expand Down
10 changes: 5 additions & 5 deletions muxer_part.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type muxerPart struct {

path string
isIndependent bool
finalDuration time.Duration
endDTS time.Duration
}

func (p *muxerPart) initialize() {
Expand All @@ -29,8 +29,8 @@ func (p *muxerPart) reader() (io.ReadCloser, error) {
return p.storage.Reader()
}

func (p *muxerPart) computeDuration(endDTS time.Duration) time.Duration {
return endDTS - p.startDTS
func (p *muxerPart) getDuration() time.Duration {
return p.endDTS - p.startDTS
}

func (p *muxerPart) finalize(endDTS time.Duration) error {
Expand All @@ -56,7 +56,7 @@ func (p *muxerPart) finalize(endDTS time.Duration) error {
return err
}

p.finalDuration = p.computeDuration(endDTS)
p.endDTS = endDTS

return nil
}
Expand All @@ -67,7 +67,7 @@ func (p *muxerPart) writeSample(track *muxerTrack, sample *fmp4AugmentedSample)
track.fmp4StartDTS = sample.dts
}

if track.isLeading && !sample.IsNonSyncSample {
if (track.isLeading || len(track.stream.tracks) == 1) && !sample.IsNonSyncSample {
p.isIndependent = true
}

Expand Down
2 changes: 1 addition & 1 deletion muxer_segmenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ func (s *muxerSegmenter) fmp4WriteSample(

// switch part
} else if (s.muxer.Variant == MuxerVariantLowLatency) &&
track.stream.nextPart.computeDuration(track.fmp4NextSample.dts) >= s.fmp4AdjustedPartDuration {
(track.fmp4NextSample.dts-track.stream.nextPart.startDTS) >= s.fmp4AdjustedPartDuration {
err := s.muxer.rotateParts(track.fmp4NextSample.dts)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions muxer_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ func partTargetDuration(
}

for _, part := range seg.parts {
if part.finalDuration > ret {
ret = part.finalDuration
if part.getDuration() > ret {
ret = part.getDuration()
}
}
}

for _, part := range stream.nextSegment.(*muxerSegmentFMP4).parts {
if part.finalDuration > ret {
ret = part.finalDuration
if part.getDuration() > ret {
ret = part.getDuration()
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions muxer_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ func (s *muxerStream) generateMediaPlaylistFMP4(
}

plse.Parts = append(plse.Parts, &playlist.MediaPart{
Duration: part.finalDuration,
Duration: part.getDuration(),
URI: u,
Independent: part.isIndependent,
})
Expand All @@ -449,7 +449,7 @@ func (s *muxerStream) generateMediaPlaylistFMP4(
}

pl.Parts = append(pl.Parts, &playlist.MediaPart{
Duration: part.finalDuration,
Duration: part.getDuration(),
URI: u,
Independent: part.isIndependent,
})
Expand Down
Loading

0 comments on commit 56d25b4

Please sign in to comment.