Skip to content

Commit

Permalink
muxer: remove redundant checks (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Sep 29, 2024
1 parent a7b1616 commit 81e3dd9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 80 deletions.
4 changes: 2 additions & 2 deletions muxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ func (m *Muxer) Start() error {
if m.VideoTrack != nil {
if _, ok := m.VideoTrack.Codec.(*codecs.H264); !ok {
return fmt.Errorf(
"the MPEG-TS variant of HLS only supports H264 video. Use the fMP4 or Low-Latency variants instead")
"the MPEG-TS variant of HLS supports H264 video only")
}
}
if m.AudioTrack != nil {
if _, ok := m.AudioTrack.Codec.(*codecs.MPEG4Audio); !ok {
return fmt.Errorf(
"the MPEG-TS variant of HLS only supports MPEG-4 Audio. Use the fMP4 or Low-Latency variants instead")
"the MPEG-TS variant of HLS supports MPEG-4 Audio only")
}
}
}
Expand Down
139 changes: 61 additions & 78 deletions muxer_segmenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,22 @@ func (s *muxerSegmenter) writeAV1(
paramsChanged = true
}

if s.muxer.Variant == MuxerVariantMPEGTS {
return fmt.Errorf("unimplemented")
} else {
ps, err := fmp4.NewPartSampleAV1(
randomAccess,
tu)
if err != nil {
return err
}

return s.fmp4WriteSample(
track,
randomAccess,
paramsChanged,
&fmp4AugmentedSample{
PartSample: *ps,
dts: pts,
ntp: ntp,
})
ps, err := fmp4.NewPartSampleAV1(
randomAccess,
tu)
if err != nil {
return err
}

return s.fmp4WriteSample(
track,
randomAccess,
paramsChanged,
&fmp4AugmentedSample{
PartSample: *ps,
dts: pts,
ntp: ntp,
})
}

func (s *muxerSegmenter) writeVP9(
Expand Down Expand Up @@ -180,22 +176,18 @@ func (s *muxerSegmenter) writeVP9(
track.firstRandomAccessReceived = true
}

if s.muxer.Variant == MuxerVariantMPEGTS {
return fmt.Errorf("unimplemented")
} else {
return s.fmp4WriteSample(
track,
randomAccess,
paramsChanged,
&fmp4AugmentedSample{
PartSample: fmp4.PartSample{
IsNonSyncSample: !randomAccess,
Payload: frame,
},
dts: pts,
ntp: ntp,
})
}
return s.fmp4WriteSample(
track,
randomAccess,
paramsChanged,
&fmp4AugmentedSample{
PartSample: fmp4.PartSample{
IsNonSyncSample: !randomAccess,
Payload: frame,
},
dts: pts,
ntp: ntp,
})
}

func (s *muxerSegmenter) writeH265(
Expand Down Expand Up @@ -256,28 +248,23 @@ func (s *muxerSegmenter) writeH265(
return fmt.Errorf("unable to extract DTS: %w", err)
}

if s.muxer.Variant == MuxerVariantMPEGTS {
return fmt.Errorf("unimplemented")
} else {
ps, err := fmp4.NewPartSampleH26x(
int32(durationGoToMp4(pts-dts, 90000)),
randomAccess,
au)
if err != nil {
return err
}

return s.fmp4WriteSample(
track,
randomAccess,
paramsChanged,
&fmp4AugmentedSample{
PartSample: *ps,
dts: dts,
ntp: ntp,
})
ps, err := fmp4.NewPartSampleH26x(
int32(durationGoToMp4(pts-dts, 90000)),
randomAccess,
au)
if err != nil {
return err
}

return s.fmp4WriteSample(
track,
randomAccess,
paramsChanged,
&fmp4AugmentedSample{
PartSample: *ps,
dts: dts,
ntp: ntp,
})
}

func (s *muxerSegmenter) writeH264(
Expand Down Expand Up @@ -398,33 +385,29 @@ func (s *muxerSegmenter) writeOpus(
) error {
track := s.muxer.mtracksByTrack[s.muxer.AudioTrack]

if s.muxer.Variant == MuxerVariantMPEGTS {
return fmt.Errorf("unimplemented")
} else {
for _, packet := range packets {
err := s.fmp4WriteSample(
track,
true,
false,
&fmp4AugmentedSample{
PartSample: fmp4.PartSample{
Payload: packet,
},
dts: pts,
ntp: ntp,
for _, packet := range packets {
err := s.fmp4WriteSample(
track,
true,
false,
&fmp4AugmentedSample{
PartSample: fmp4.PartSample{
Payload: packet,
},
)
if err != nil {
return err
}

duration := opus.PacketDuration(packet)
ntp = ntp.Add(duration)
pts += duration
dts: pts,
ntp: ntp,
},
)
if err != nil {
return err
}

return nil
duration := opus.PacketDuration(packet)
ntp = ntp.Add(duration)
pts += duration
}

return nil
}

func (s *muxerSegmenter) writeMPEG4Audio(ntp time.Time, pts time.Duration, aus [][]byte) error {
Expand Down

0 comments on commit 81e3dd9

Please sign in to comment.