Browse Source

update gortsplib

pull/1003/head
aler9 3 years ago
parent
commit
41b08c9f50
  1. 3
      go.mod
  2. 8
      go.sum
  3. 2
      internal/core/hls_muxer.go
  4. 2
      internal/core/rtmp_conn.go
  5. 10
      internal/hls/client_audio_processor.go
  6. 2
      internal/hls/muxer_primary_playlist.go
  7. 21
      internal/hls/muxer_test.go
  8. 15
      internal/hls/muxer_variant_fmp4_init.go
  9. 6
      internal/hls/muxer_variant_mpegts_segment.go
  10. 22
      internal/rtmp/conn.go
  11. 46
      internal/rtmp/conn_test.go

3
go.mod

@ -5,7 +5,7 @@ go 1.17 @@ -5,7 +5,7 @@ go 1.17
require (
code.cloudfoundry.org/bytefmt v0.0.0-20211005130812-5bb3c17173e5
github.com/abema/go-mp4 v0.7.2
github.com/aler9/gortsplib v0.0.0-20220623113557-d80977dbaea3
github.com/aler9/gortsplib v0.0.0-20220624145247-52123a2741aa
github.com/asticode/go-astits v1.10.1-0.20220319093903-4abe66a9b757
github.com/fsnotify/fsnotify v1.4.9
github.com/gin-gonic/gin v1.8.1
@ -32,7 +32,6 @@ require ( @@ -32,7 +32,6 @@ require (
github.com/go-playground/validator/v10 v10.10.0 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/icza/bitio v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect

8
go.sum

@ -6,8 +6,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo @@ -6,8 +6,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/aler9/gortsplib v0.0.0-20220623113557-d80977dbaea3 h1:4kPboldLlj92Qr+LOoj3F+syP5k/dgW4EZhC1NfGeLc=
github.com/aler9/gortsplib v0.0.0-20220623113557-d80977dbaea3/go.mod h1:i1e4CEs42IrbidMUNTSNOKmeGPCOHVX9P3BvPxzyMtI=
github.com/aler9/gortsplib v0.0.0-20220624145247-52123a2741aa h1:XorLtWX1uhmUuyFtJxyaRS3r+pTMe1XLEGeX5NhAM9Y=
github.com/aler9/gortsplib v0.0.0-20220624145247-52123a2741aa/go.mod h1:WI3nMhY2mM6nfoeW9uyk7TyG5Qr6YnYxmFoCply0sbo=
github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927 h1:95mXJ5fUCYpBRdSOnLAQAdJHHKxxxJrVCiaqDi965YQ=
github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927/go.mod h1:vzuE21rowz+lT1NGsWbreIvYulgBpCGnQyeTyFblUHc=
github.com/aler9/writerseeker v0.0.0-20220601075008-6f0e685b9c82 h1:9WgSzBLo3a9ToSVV7sRTBYZ1GGOZUpq4+5H3SN0UZq4=
@ -62,10 +62,6 @@ github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQ @@ -62,10 +62,6 @@ github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQ
github.com/grafov/m3u8 v0.11.1 h1:igZ7EBIB2IAsPPazKwRKdbhxcoBKO3lO1UY57PZDeNA=
github.com/grafov/m3u8 v0.11.1/go.mod h1:nqzOkfBiZJENr52zTVd/Dcl03yzphIMbJqkXGu+u080=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/icza/bitio v1.1.0 h1:ysX4vtldjdi3Ygai5m1cWy4oLkhWTAi+SyO6HC8L9T0=
github.com/icza/bitio v1.1.0/go.mod h1:0jGnlLAx8MKMr9VGnn/4YrvZiprkvBelsVIbA9Jjr9A=
github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6 h1:8UsGZ2rr2ksmEru6lToqnXgA8Mz1DP11X4zSJ159C3k=
github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6/go.mod h1:xQig96I1VNBDIWGCdTt54nHt6EeI639SmHycLYL7FkA=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=

2
internal/core/hls_muxer.go

@ -311,7 +311,7 @@ func (m *hlsMuxer) runInner(innerCtx context.Context, innerReady chan struct{}) @@ -311,7 +311,7 @@ func (m *hlsMuxer) runInner(innerCtx context.Context, innerReady chan struct{})
audioTrack = tt
audioTrackID = i
aacDecoder = &rtpaac.Decoder{
SampleRate: tt.SampleRate,
SampleRate: tt.Config.SampleRate,
SizeLength: tt.SizeLength,
IndexLength: tt.IndexLength,
IndexDeltaLength: tt.IndexDeltaLength,

2
internal/core/rtmp_conn.go

@ -278,7 +278,7 @@ func (c *rtmpConn) runRead(ctx context.Context) error { @@ -278,7 +278,7 @@ func (c *rtmpConn) runRead(ctx context.Context) error {
audioTrack = tt
audioTrackID = i
aacDecoder = &rtpaac.Decoder{
SampleRate: tt.SampleRate,
SampleRate: tt.Config.SampleRate,
SizeLength: tt.SizeLength,
IndexLength: tt.IndexLength,
IndexDeltaLength: tt.IndexDeltaLength,

10
internal/hls/client_audio_processor.go

@ -79,10 +79,12 @@ func (p *clientAudioProcessor) doProcess( @@ -79,10 +79,12 @@ func (p *clientAudioProcessor) doProcess(
p.trackInitialized = true
track := &gortsplib.TrackAAC{
PayloadType: 96,
Type: pkt.Type,
SampleRate: pkt.SampleRate,
ChannelCount: pkt.ChannelCount,
PayloadType: 96,
Config: &aac.MPEG4AudioConfig{
Type: pkt.Type,
SampleRate: pkt.SampleRate,
ChannelCount: pkt.ChannelCount,
},
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,

2
internal/hls/muxer_primary_playlist.go

@ -47,7 +47,7 @@ func (p *muxerPrimaryPlaylist) file() *MuxerFileResponse { @@ -47,7 +47,7 @@ func (p *muxerPrimaryPlaylist) file() *MuxerFileResponse {
// https://developer.mozilla.org/en-US/docs/Web/Media/Formats/codecs_parameter
if p.audioTrack != nil {
codecs = append(codecs, "mp4a.40."+strconv.FormatInt(int64(p.audioTrack.Type), 10))
codecs = append(codecs, "mp4a.40."+strconv.FormatInt(int64(p.audioTrack.Config.Type), 10))
}
switch {

21
internal/hls/muxer_test.go

@ -9,6 +9,7 @@ import ( @@ -9,6 +9,7 @@ import (
"time"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/aac"
"github.com/asticode/go-astits"
"github.com/stretchr/testify/require"
)
@ -29,10 +30,12 @@ func TestMuxerVideoAudio(t *testing.T) { @@ -29,10 +30,12 @@ func TestMuxerVideoAudio(t *testing.T) {
}
audioTrack := &gortsplib.TrackAAC{
PayloadType: 97,
Type: 2,
SampleRate: 44100,
ChannelCount: 2,
PayloadType: 97,
Config: &aac.MPEG4AudioConfig{
Type: 2,
SampleRate: 44100,
ChannelCount: 2,
},
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,
@ -280,10 +283,12 @@ func TestMuxerVideoOnly(t *testing.T) { @@ -280,10 +283,12 @@ func TestMuxerVideoOnly(t *testing.T) {
func TestMuxerAudioOnly(t *testing.T) {
audioTrack := &gortsplib.TrackAAC{
PayloadType: 97,
Type: 2,
SampleRate: 44100,
ChannelCount: 2,
PayloadType: 97,
Config: &aac.MPEG4AudioConfig{
Type: 2,
SampleRate: 44100,
ChannelCount: 2,
},
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,

15
internal/hls/muxer_variant_fmp4_init.go

@ -3,7 +3,6 @@ package hls @@ -3,7 +3,6 @@ package hls
import (
gomp4 "github.com/abema/go-mp4"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/aac"
"github.com/aler9/gortsplib/pkg/h264"
"github.com/aler9/rtsp-simple-server/internal/mp4"
@ -389,7 +388,7 @@ func mp4InitGenerateAudioTrack(w *mp4.Writer, trackID int, audioTrack *gortsplib @@ -389,7 +388,7 @@ func mp4InitGenerateAudioTrack(w *mp4.Writer, trackID int, audioTrack *gortsplib
},
DataReferenceIndex: 1,
},
ChannelCount: uint16(audioTrack.ChannelCount),
ChannelCount: uint16(audioTrack.Config.ChannelCount),
SampleSize: 16,
SampleRate: uint32(audioTrack.ClockRate() * 65536),
})
@ -397,21 +396,15 @@ func mp4InitGenerateAudioTrack(w *mp4.Writer, trackID int, audioTrack *gortsplib @@ -397,21 +396,15 @@ func mp4InitGenerateAudioTrack(w *mp4.Writer, trackID int, audioTrack *gortsplib
return err
}
c := aac.MPEG4AudioConfig{
Type: aac.MPEG4AudioType(audioTrack.Type),
SampleRate: audioTrack.SampleRate,
ChannelCount: audioTrack.ChannelCount,
AOTSpecificConfig: audioTrack.AOTSpecificConfig,
}
conf, _ := c.Encode()
enc, _ := audioTrack.Config.Marshal()
decSpecificInfoTagSize := uint8(len(conf))
decSpecificInfoTagSize := uint8(len(enc))
decSpecificInfoTag := append(
[]byte{
gomp4.DecSpecificInfoTag,
0x80, 0x80, 0x80, decSpecificInfoTagSize, // size
},
conf...,
enc...,
)
esDescrTag := []byte{

6
internal/hls/muxer_variant_mpegts_segment.go

@ -151,9 +151,9 @@ func (t *muxerVariantMPEGTSSegment) writeAAC( @@ -151,9 +151,9 @@ func (t *muxerVariantMPEGTSSegment) writeAAC(
for i, au := range aus {
pkts[i] = &aac.ADTSPacket{
Type: t.audioTrack.Type,
SampleRate: t.audioTrack.SampleRate,
ChannelCount: t.audioTrack.ChannelCount,
Type: t.audioTrack.Config.Type,
SampleRate: t.audioTrack.Config.SampleRate,
ChannelCount: t.audioTrack.Config.ChannelCount,
AU: au,
}
}

22
internal/rtmp/conn.go

@ -98,20 +98,17 @@ func trackFromH264DecoderConfig(data []byte) (*gortsplib.TrackH264, error) { @@ -98,20 +98,17 @@ func trackFromH264DecoderConfig(data []byte) (*gortsplib.TrackH264, error) {
func trackFromAACDecoderConfig(data []byte) (*gortsplib.TrackAAC, error) {
var mpegConf aac.MPEG4AudioConfig
err := mpegConf.Decode(data)
err := mpegConf.Unmarshal(data)
if err != nil {
return nil, err
}
return &gortsplib.TrackAAC{
PayloadType: 97,
Type: int(mpegConf.Type),
SampleRate: mpegConf.SampleRate,
ChannelCount: mpegConf.ChannelCount,
AOTSpecificConfig: mpegConf.AOTSpecificConfig,
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,
PayloadType: 97,
Config: &mpegConf,
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,
}, nil
}
@ -395,12 +392,7 @@ func (c *Conn) WriteTracks(videoTrack *gortsplib.TrackH264, audioTrack *gortspli @@ -395,12 +392,7 @@ func (c *Conn) WriteTracks(videoTrack *gortsplib.TrackH264, audioTrack *gortspli
}
if audioTrack != nil {
enc, err := aac.MPEG4AudioConfig{
Type: aac.MPEG4AudioType(audioTrack.Type),
SampleRate: audioTrack.SampleRate,
ChannelCount: audioTrack.ChannelCount,
AOTSpecificConfig: audioTrack.AOTSpecificConfig,
}.Encode()
enc, err := audioTrack.Config.Marshal()
if err != nil {
return err
}

46
internal/rtmp/conn_test.go

@ -92,10 +92,12 @@ func TestReadTracks(t *testing.T) { @@ -92,10 +92,12 @@ func TestReadTracks(t *testing.T) {
}, videoTrack)
require.Equal(t, &gortsplib.TrackAAC{
PayloadType: 97,
Type: 2,
SampleRate: 44100,
ChannelCount: 2,
PayloadType: 97,
Config: &aac.MPEG4AudioConfig{
Type: 2,
SampleRate: 44100,
ChannelCount: 2,
},
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,
@ -109,10 +111,12 @@ func TestReadTracks(t *testing.T) { @@ -109,10 +111,12 @@ func TestReadTracks(t *testing.T) {
}, videoTrack)
require.Equal(t, &gortsplib.TrackAAC{
PayloadType: 97,
Type: 2,
SampleRate: 44100,
ChannelCount: 2,
PayloadType: 97,
Config: &aac.MPEG4AudioConfig{
Type: 2,
SampleRate: 44100,
ChannelCount: 2,
},
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,
@ -126,10 +130,12 @@ func TestReadTracks(t *testing.T) { @@ -126,10 +130,12 @@ func TestReadTracks(t *testing.T) {
}, videoTrack)
require.Equal(t, &gortsplib.TrackAAC{
PayloadType: 97,
Type: 2,
SampleRate: 44100,
ChannelCount: 2,
PayloadType: 97,
Config: &aac.MPEG4AudioConfig{
Type: 2,
SampleRate: 44100,
ChannelCount: 2,
},
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,
@ -378,7 +384,7 @@ func TestReadTracks(t *testing.T) { @@ -378,7 +384,7 @@ func TestReadTracks(t *testing.T) {
Type: 2,
SampleRate: 44100,
ChannelCount: 2,
}.Encode()
}.Marshal()
require.NoError(t, err)
err = mrw.Write(&message.MsgAudio{
ChunkStreamID: 4,
@ -443,7 +449,7 @@ func TestReadTracks(t *testing.T) { @@ -443,7 +449,7 @@ func TestReadTracks(t *testing.T) {
Type: 2,
SampleRate: 44100,
ChannelCount: 2,
}.Encode()
}.Marshal()
require.NoError(t, err)
err = mrw.Write(&message.MsgAudio{
ChunkStreamID: 4,
@ -483,7 +489,7 @@ func TestReadTracks(t *testing.T) { @@ -483,7 +489,7 @@ func TestReadTracks(t *testing.T) {
Type: 2,
SampleRate: 44100,
ChannelCount: 2,
}.Encode()
}.Marshal()
require.NoError(t, err)
err = mrw.Write(&message.MsgAudio{
ChunkStreamID: 4,
@ -529,10 +535,12 @@ func TestWriteTracks(t *testing.T) { @@ -529,10 +535,12 @@ func TestWriteTracks(t *testing.T) {
}
audioTrack := &gortsplib.TrackAAC{
PayloadType: 97,
Type: 2,
SampleRate: 44100,
ChannelCount: 2,
PayloadType: 97,
Config: &aac.MPEG4AudioConfig{
Type: 2,
SampleRate: 44100,
ChannelCount: 2,
},
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,

Loading…
Cancel
Save