Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

muxer: serve different tracks in different streams #180

Merged
merged 2 commits into from
Oct 2, 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
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 @@
}

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()

Check warning on line 59 in muxer_server.go

View check run for this annotation

Codecov / codecov/patch

muxer_server.go#L58-L59

Added lines #L58 - L59 were not covered by tests
}
}
}
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 @@
}

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

pl.Parts = append(pl.Parts, &playlist.MediaPart{
Duration: part.finalDuration,
Duration: part.getDuration(),

Check warning on line 452 in muxer_stream.go

View check run for this annotation

Codecov / codecov/patch

muxer_stream.go#L452

Added line #L452 was not covered by tests
URI: u,
Independent: part.isIndependent,
})
Expand Down
Loading
Loading