Skip to content

Commit

Permalink
move AUD logic into mediacommon (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored May 25, 2024
1 parent 00348f4 commit 1d8aa99
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 19 deletions.
2 changes: 1 addition & 1 deletion client_stream_processor_mpegts.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (p *clientStreamProcessorMPEGTS) initializeReader(ctx context.Context, firs

switch track.track.Codec.(type) {
case *codecs.H264:
p.reader.OnDataH26x(mpegtsTrack, func(pts int64, dts int64, au [][]byte) error {
p.reader.OnDataH264(mpegtsTrack, func(pts int64, dts int64, au [][]byte) error {
return processSample(pts, dts, au)
})

Expand Down
8 changes: 4 additions & 4 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestClient(t *testing.T) {
}
mw := mpegts.NewWriter(w, []*mpegts.Track{h264Track, mpeg4audioTrack})

err = mw.WriteH26x(
err = mw.WriteH264(
h264Track,
90000, // +1 sec
8589844592, // -1 sec
Expand All @@ -167,7 +167,7 @@ func TestClient(t *testing.T) {
)
require.NoError(t, err)

err = mw.WriteH26x(
err = mw.WriteH264(
h264Track,
90000+90000/30,
8589844592+90000/30,
Expand Down Expand Up @@ -212,7 +212,7 @@ func TestClient(t *testing.T) {
}
mw := mpegts.NewWriter(w, []*mpegts.Track{h264Track, mpeg4audioTrack})

err = mw.WriteH26x(
err = mw.WriteH264(
h264Track,
8589844592+2*90000/30,
8589844592+2*90000/30,
Expand Down Expand Up @@ -911,7 +911,7 @@ func TestClientErrorInvalidSequenceID(t *testing.T) {
}
mw := mpegts.NewWriter(w, []*mpegts.Track{h264Track})

err := mw.WriteH26x(
err := mw.WriteH264(
h264Track,
90000, // +1 sec
0x1FFFFFFFF-90000+1, // -1 sec
Expand Down
9 changes: 3 additions & 6 deletions examples/client-codec-h264-save-to-disk/mpegts_muxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ func (e *mpegtsMuxer) close() {

// writeH264 writes a H264 access unit into MPEG-TS.
func (e *mpegtsMuxer) writeH264(au [][]byte, pts time.Duration) error {
// prepend an AUD. This is required by some players
filteredAU := [][]byte{
{byte(h264.NALUTypeAccessUnitDelimiter), 240},
}
var filteredAU [][]byte

nonIDRPresent := false
idrPresent := false
Expand Down Expand Up @@ -86,7 +83,7 @@ func (e *mpegtsMuxer) writeH264(au [][]byte, pts time.Duration) error {

au = filteredAU

if len(au) <= 1 || (!nonIDRPresent && !idrPresent) {
if au == nil || (!nonIDRPresent && !idrPresent) {
return nil
}

Expand All @@ -112,5 +109,5 @@ func (e *mpegtsMuxer) writeH264(au [][]byte, pts time.Duration) error {
}

// encode into MPEG-TS
return e.w.WriteH26x(e.track, durationGoToMPEGTS(pts), durationGoToMPEGTS(dts), idrPresent, au)
return e.w.WriteH264(e.track, durationGoToMPEGTS(pts), durationGoToMPEGTS(dts), idrPresent, au)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/asticode/go-astits v1.13.0
github.com/bluenviron/mediacommon v1.11.0
github.com/bluenviron/mediacommon v1.11.1-0.20240525122142-20163863aa75
github.com/stretchr/testify v1.9.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/asticode/go-astikit v0.30.0 h1:DkBkRQRIxYcknlaU7W7ksNfn4gMFsB0tqMJflx
github.com/asticode/go-astikit v0.30.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0=
github.com/asticode/go-astits v1.13.0 h1:XOgkaadfZODnyZRR5Y0/DWkA9vrkLLPLeeOvDwfKZ1c=
github.com/asticode/go-astits v1.13.0/go.mod h1:QSHmknZ51pf6KJdHKZHJTLlMegIrhega3LPWz3ND/iI=
github.com/bluenviron/mediacommon v1.11.0 h1:1xY4QGYz7da9tsV2Xvd+ol+Ul5qq2g7ADJtIlVkQSRI=
github.com/bluenviron/mediacommon v1.11.0/go.mod h1:HDyW2CzjvhYJXtdxstdFPio3G0qSocPhqkhUt/qffec=
github.com/bluenviron/mediacommon v1.11.1-0.20240525122142-20163863aa75 h1:5P8Um+ySuwZApuVS9gI6U0MnrIFybTfLrZSqV2ie5lA=
github.com/bluenviron/mediacommon v1.11.1-0.20240525122142-20163863aa75/go.mod h1:HDyW2CzjvhYJXtdxstdFPio3G0qSocPhqkhUt/qffec=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
6 changes: 1 addition & 5 deletions muxer_segment_mpegts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/bluenviron/gohlslib/pkg/storage"

"github.com/bluenviron/mediacommon/pkg/codecs/h264"
"github.com/bluenviron/mediacommon/pkg/formats/mpegts"
)

Expand Down Expand Up @@ -105,10 +104,7 @@ func (t *muxerSegmentMPEGTS) writeH264(
}
t.size += size

// prepend an AUD. This is required by video.js and iOS
au = append([][]byte{{byte(h264.NALUTypeAccessUnitDelimiter), 240}}, au...)

err := t.writer.WriteH26x(t.writerVideoTrack, durationGoToMPEGTS(pts), durationGoToMPEGTS(dts), idrPresent, au)
err := t.writer.WriteH264(t.writerVideoTrack, durationGoToMPEGTS(pts), durationGoToMPEGTS(dts), idrPresent, au)
if err != nil {
return err
}
Expand Down

0 comments on commit 1d8aa99

Please sign in to comment.