Browse Source

update gortsplib

pull/543/head
aler9 4 years ago
parent
commit
b65207012c
  1. 2
      go.mod
  2. 4
      go.sum
  3. 6
      internal/core/api_test.go
  4. 10
      internal/core/hls_muxer.go
  5. 2
      internal/core/metrics_test.go
  6. 10
      internal/core/rtsp_server_test.go
  7. 2
      internal/core/rtsp_source_test.go
  8. 42
      internal/hls/muxer.go
  9. 8
      internal/hls/muxer_test.go
  10. 11
      internal/hls/primaryplaylist.go
  11. 24
      internal/hls/segment.go
  12. 38
      internal/rtmp/metadata.go

2
go.mod

@ -5,7 +5,7 @@ go 1.16 @@ -5,7 +5,7 @@ go 1.16
require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/aler9/gortsplib v0.0.0-20210825160422-accfc7cd5d40
github.com/aler9/gortsplib v0.0.0-20210825171651-d744a2e0d3c4
github.com/asticode/go-astits v1.9.0
github.com/fsnotify/fsnotify v1.4.9
github.com/gin-gonic/gin v1.7.2

4
go.sum

@ -2,8 +2,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo @@ -2,8 +2,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-20210825160422-accfc7cd5d40 h1:U9xjMsifS0Lslrg1KCZWVVb+r9X54D9fkcosuej6W/8=
github.com/aler9/gortsplib v0.0.0-20210825160422-accfc7cd5d40/go.mod h1:s5FsbPRxJhU/YedvUKAKHVY+lQEdYsiJpuN2CHb89cI=
github.com/aler9/gortsplib v0.0.0-20210825171651-d744a2e0d3c4 h1:+bgGJF63Ze5VQ4JIk9f7h/MWo6MIW7+y0F5XsALTtwc=
github.com/aler9/gortsplib v0.0.0-20210825171651-d744a2e0d3c4/go.mod h1:s5FsbPRxJhU/YedvUKAKHVY+lQEdYsiJpuN2CHb89cI=
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/asticode/go-astikit v0.20.0 h1:+7N+J4E4lWx2QOkRdOf6DafWJMv6O4RRfgClwQokrH8=

6
internal/core/api_test.go

@ -179,7 +179,7 @@ func TestAPIPathsList(t *testing.T) { @@ -179,7 +179,7 @@ func TestAPIPathsList(t *testing.T) {
_, ok = out.Items["mypath"]
require.Equal(t, true, ok)
track, err := gortsplib.NewTrackH264(96, []byte("123456"), []byte("123456"))
track, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}})
require.NoError(t, err)
func() {
@ -227,7 +227,7 @@ func TestAPIList(t *testing.T) { @@ -227,7 +227,7 @@ func TestAPIList(t *testing.T) {
require.Equal(t, true, ok)
defer p.close()
track, err := gortsplib.NewTrackH264(96, []byte("123456"), []byte("123456"))
track, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}})
require.NoError(t, err)
switch ca {
@ -308,7 +308,7 @@ func TestAPIKick(t *testing.T) { @@ -308,7 +308,7 @@ func TestAPIKick(t *testing.T) {
require.Equal(t, true, ok)
defer p.close()
track, err := gortsplib.NewTrackH264(96, []byte("123456"), []byte("123456"))
track, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}})
require.NoError(t, err)
switch ca {

10
internal/core/hls_muxer.go

@ -263,7 +263,6 @@ func (r *hlsMuxer) runInner(innerCtx context.Context, innerReady chan struct{}) @@ -263,7 +263,6 @@ func (r *hlsMuxer) runInner(innerCtx context.Context, innerReady chan struct{})
var h264Decoder *rtph264.Decoder
var audioTrack *gortsplib.Track
audioTrackID := -1
var aacConfig rtpaac.MPEG4AudioConfig
var aacDecoder *rtpaac.Decoder
for i, t := range res.Stream.tracks() {
@ -285,17 +284,12 @@ func (r *hlsMuxer) runInner(innerCtx context.Context, innerReady chan struct{}) @@ -285,17 +284,12 @@ func (r *hlsMuxer) runInner(innerCtx context.Context, innerReady chan struct{})
audioTrack = t
audioTrackID = i
byts, err := t.ExtractDataAAC()
conf, err := t.ExtractConfigAAC()
if err != nil {
return err
}
err = aacConfig.Decode(byts)
if err != nil {
return err
}
aacDecoder = rtpaac.NewDecoder(aacConfig.SampleRate)
aacDecoder = rtpaac.NewDecoder(conf.SampleRate)
}
}

2
internal/core/metrics_test.go

@ -27,7 +27,7 @@ func TestMetrics(t *testing.T) { @@ -27,7 +27,7 @@ func TestMetrics(t *testing.T) {
require.Equal(t, true, ok)
defer p.close()
track, err := gortsplib.NewTrackH264(96, []byte("123456"), []byte("123456"))
track, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}})
require.NoError(t, err)
source, err := gortsplib.DialPublish("rtsp://localhost:8554/mypath",

10
internal/core/rtsp_server_test.go

@ -354,7 +354,7 @@ func TestRTSPServerAuthFail(t *testing.T) { @@ -354,7 +354,7 @@ func TestRTSPServerAuthFail(t *testing.T) {
require.Equal(t, true, ok)
defer p.close()
track, err := gortsplib.NewTrackH264(68, []byte{0x01, 0x02, 0x03, 0x04}, []byte{0x01, 0x02, 0x03, 0x04})
track, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}})
require.NoError(t, err)
_, err = gortsplib.DialPublish(
@ -412,7 +412,7 @@ func TestRTSPServerAuthFail(t *testing.T) { @@ -412,7 +412,7 @@ func TestRTSPServerAuthFail(t *testing.T) {
require.Equal(t, true, ok)
defer p.close()
track, err := gortsplib.NewTrackH264(68, []byte{0x01, 0x02, 0x03, 0x04}, []byte{0x01, 0x02, 0x03, 0x04})
track, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}})
require.NoError(t, err)
_, err = gortsplib.DialPublish(
@ -477,7 +477,7 @@ func TestRTSPServerPublisherOverride(t *testing.T) { @@ -477,7 +477,7 @@ func TestRTSPServerPublisherOverride(t *testing.T) {
require.Equal(t, true, ok)
defer p.close()
track, err := gortsplib.NewTrackH264(68, []byte{0x01, 0x02, 0x03, 0x04}, []byte{0x01, 0x02, 0x03, 0x04})
track, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}})
require.NoError(t, err)
s1, err := gortsplib.DialPublish("rtsp://localhost:8554/teststream",
@ -544,7 +544,7 @@ func TestRTSPServerNonCompliantFrameSize(t *testing.T) { @@ -544,7 +544,7 @@ func TestRTSPServerNonCompliantFrameSize(t *testing.T) {
require.Equal(t, true, ok)
defer p.close()
track, err := gortsplib.NewTrackH264(96, []byte("123456"), []byte("123456"))
track, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}})
require.NoError(t, err)
client := &gortsplib.Client{
@ -594,7 +594,7 @@ func TestRTSPServerNonCompliantFrameSize(t *testing.T) { @@ -594,7 +594,7 @@ func TestRTSPServerNonCompliantFrameSize(t *testing.T) {
require.Equal(t, true, ok)
defer p1.close()
track, err := gortsplib.NewTrackH264(96, []byte("123456"), []byte("123456"))
track, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}})
require.NoError(t, err)
client := &gortsplib.Client{

2
internal/core/rtsp_source_test.go

@ -36,7 +36,7 @@ func (sh *testServer) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*ba @@ -36,7 +36,7 @@ func (sh *testServer) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*ba
}, nil, nil
}
track, _ := gortsplib.NewTrackH264(96, []byte{0x01, 0x02, 0x03, 0x04}, []byte{0x05, 0x06})
track, _ := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x05, 0x06}})
sh.stream = gortsplib.NewServerStream(gortsplib.Tracks{track})
return &base.Response{

42
internal/hls/muxer.go

@ -5,7 +5,6 @@ import ( @@ -5,7 +5,6 @@ import (
"time"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/rtpaac"
"github.com/aler9/rtsp-simple-server/internal/h264"
)
@ -26,9 +25,8 @@ type Muxer struct { @@ -26,9 +25,8 @@ type Muxer struct {
videoTrack *gortsplib.Track
audioTrack *gortsplib.Track
h264SPS []byte
h264PPS []byte
aacConfig rtpaac.MPEG4AudioConfig
h264Conf *gortsplib.TrackConfigH264
aacConf *gortsplib.TrackConfigAAC
videoDTSEst *h264.DTSEstimator
audioAUCount int
currentSegment *segment
@ -44,24 +42,19 @@ func NewMuxer( @@ -44,24 +42,19 @@ func NewMuxer(
hlsSegmentDuration time.Duration,
videoTrack *gortsplib.Track,
audioTrack *gortsplib.Track) (*Muxer, error) {
var h264SPS []byte
var h264PPS []byte
var h264Conf *gortsplib.TrackConfigH264
if videoTrack != nil {
var err error
h264SPS, h264PPS, err = videoTrack.ExtractDataH264()
h264Conf, err = videoTrack.ExtractConfigH264()
if err != nil {
return nil, err
}
}
var aacConfig rtpaac.MPEG4AudioConfig
var aacConf *gortsplib.TrackConfigAAC
if audioTrack != nil {
byts, err := audioTrack.ExtractDataAAC()
if err != nil {
return nil, err
}
err = aacConfig.Decode(byts)
var err error
aacConf, err = audioTrack.ExtractConfigAAC()
if err != nil {
return nil, err
}
@ -72,12 +65,11 @@ func NewMuxer( @@ -72,12 +65,11 @@ func NewMuxer(
hlsSegmentDuration: hlsSegmentDuration,
videoTrack: videoTrack,
audioTrack: audioTrack,
h264SPS: h264SPS,
h264PPS: h264PPS,
aacConfig: aacConfig,
h264Conf: h264Conf,
aacConf: aacConf,
videoDTSEst: h264.NewDTSEstimator(),
currentSegment: newSegment(videoTrack, audioTrack, h264SPS, h264PPS),
primaryPlaylist: newPrimaryPlaylist(videoTrack, audioTrack, h264SPS, h264PPS),
currentSegment: newSegment(videoTrack, audioTrack, h264Conf, aacConf),
primaryPlaylist: newPrimaryPlaylist(videoTrack, audioTrack, h264Conf),
streamPlaylist: newStreamPlaylist(hlsSegmentCount),
}
@ -111,7 +103,7 @@ func (m *Muxer) WriteH264(pts time.Duration, nalus [][]byte) error { @@ -111,7 +103,7 @@ func (m *Muxer) WriteH264(pts time.Duration, nalus [][]byte) error {
m.currentSegment.duration() >= m.hlsSegmentDuration {
m.streamPlaylist.pushSegment(m.currentSegment)
m.currentSegment = newSegment(m.videoTrack, m.audioTrack, m.h264SPS, m.h264PPS)
m.currentSegment = newSegment(m.videoTrack, m.audioTrack, m.h264Conf, m.aacConf)
m.currentSegment.setStartPCR(m.startPCR)
}
} else {
@ -144,7 +136,7 @@ func (m *Muxer) WriteAAC(pts time.Duration, aus [][]byte) error { @@ -144,7 +136,7 @@ func (m *Muxer) WriteAAC(pts time.Duration, aus [][]byte) error {
m.streamPlaylist.pushSegment(m.currentSegment)
m.currentSegment = newSegment(m.videoTrack, m.audioTrack, m.h264SPS, m.h264PPS)
m.currentSegment = newSegment(m.videoTrack, m.audioTrack, m.h264Conf, m.aacConf)
m.currentSegment.setStartPCR(m.startPCR)
}
} else {
@ -161,13 +153,9 @@ func (m *Muxer) WriteAAC(pts time.Duration, aus [][]byte) error { @@ -161,13 +153,9 @@ func (m *Muxer) WriteAAC(pts time.Duration, aus [][]byte) error {
pts = pts + ptsOffset - m.startPTS
for i, au := range aus {
auPTS := pts + time.Duration(i)*1000*time.Second/time.Duration(m.aacConfig.SampleRate)
auPTS := pts + time.Duration(i)*1000*time.Second/time.Duration(m.aacConf.SampleRate)
err := m.currentSegment.writeAAC(
m.aacConfig.SampleRate,
m.aacConfig.ChannelCount,
auPTS,
au)
err := m.currentSegment.writeAAC(auPTS, au)
if err != nil {
return err
}

8
internal/hls/muxer_test.go

@ -17,10 +17,10 @@ func checkTSPacket(t *testing.T, byts []byte, pid int, afc int) { @@ -17,10 +17,10 @@ func checkTSPacket(t *testing.T, byts []byte, pid int, afc int) {
}
func TestMuxer(t *testing.T) {
videoTrack, err := gortsplib.NewTrackH264(96, []byte{0x07, 0x01, 0x02, 0x03}, []byte{0x08})
videoTrack, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x07, 0x01, 0x02, 0x03}, PPS: []byte{0x08}})
require.NoError(t, err)
audioTrack, err := gortsplib.NewTrackAAC(97, []byte{17, 144})
audioTrack, err := gortsplib.NewTrackAAC(97, &gortsplib.TrackConfigAAC{Type: 2, SampleRate: 44100, ChannelCount: 2})
require.NoError(t, err)
m, err := NewMuxer(3, 1*time.Second, videoTrack, audioTrack)
@ -107,10 +107,10 @@ func TestMuxer(t *testing.T) { @@ -107,10 +107,10 @@ func TestMuxer(t *testing.T) {
}
func TestMuxerCloseBeforeFirstSegment(t *testing.T) {
videoTrack, err := gortsplib.NewTrackH264(96, []byte{0x07, 0x01, 0x02, 0x03}, []byte{0x08})
videoTrack, err := gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: []byte{0x07, 0x01, 0x02, 0x03}, PPS: []byte{0x08}})
require.NoError(t, err)
audioTrack, err := gortsplib.NewTrackAAC(97, []byte{17, 144})
audioTrack, err := gortsplib.NewTrackAAC(97, &gortsplib.TrackConfigAAC{Type: 2, SampleRate: 44100, ChannelCount: 2})
require.NoError(t, err)
m, err := NewMuxer(3, 1*time.Second, videoTrack, audioTrack)

11
internal/hls/primaryplaylist.go

@ -12,8 +12,7 @@ import ( @@ -12,8 +12,7 @@ import (
type primaryPlaylist struct {
videoTrack *gortsplib.Track
audioTrack *gortsplib.Track
h264SPS []byte
h264PPS []byte
h264Conf *gortsplib.TrackConfigH264
breader *bytes.Reader
}
@ -21,20 +20,18 @@ type primaryPlaylist struct { @@ -21,20 +20,18 @@ type primaryPlaylist struct {
func newPrimaryPlaylist(
videoTrack *gortsplib.Track,
audioTrack *gortsplib.Track,
h264SPS []byte,
h264PPS []byte,
h264Conf *gortsplib.TrackConfigH264,
) *primaryPlaylist {
p := &primaryPlaylist{
videoTrack: videoTrack,
audioTrack: audioTrack,
h264SPS: h264SPS,
h264PPS: h264PPS,
h264Conf: h264Conf,
}
var codecs []string
if p.videoTrack != nil {
codecs = append(codecs, "avc1."+hex.EncodeToString(p.h264SPS[1:4]))
codecs = append(codecs, "avc1."+hex.EncodeToString(p.h264Conf.SPS[1:4]))
}
if p.audioTrack != nil {

24
internal/hls/segment.go

@ -16,8 +16,8 @@ import ( @@ -16,8 +16,8 @@ import (
type segment struct {
videoTrack *gortsplib.Track
h264SPS []byte
h264PPS []byte
h264Conf *gortsplib.TrackConfigH264
aacConf *gortsplib.TrackConfigAAC
name string
buf bytes.Buffer
@ -32,13 +32,13 @@ type segment struct { @@ -32,13 +32,13 @@ type segment struct {
func newSegment(
videoTrack *gortsplib.Track,
audioTrack *gortsplib.Track,
h264SPS []byte,
h264PPS []byte,
h264Conf *gortsplib.TrackConfigH264,
aacConf *gortsplib.TrackConfigAAC,
) *segment {
t := &segment{
videoTrack: videoTrack,
h264SPS: h264SPS,
h264PPS: h264PPS,
h264Conf: h264Conf,
aacConf: aacConf,
name: strconv.FormatInt(time.Now().Unix(), 10),
}
@ -117,8 +117,8 @@ func (t *segment) writeH264( @@ -117,8 +117,8 @@ func (t *segment) writeH264(
// add SPS and PPS before IDR
if typ == h264.NALUTypeIDR {
filteredNALUs = append(filteredNALUs, t.h264SPS)
filteredNALUs = append(filteredNALUs, t.h264PPS)
filteredNALUs = append(filteredNALUs, t.h264Conf.SPS)
filteredNALUs = append(filteredNALUs, t.h264Conf.PPS)
}
filteredNALUs = append(filteredNALUs, nalu)
@ -176,7 +176,9 @@ func (t *segment) writeH264( @@ -176,7 +176,9 @@ func (t *segment) writeH264(
return err
}
func (t *segment) writeAAC(sampleRate int, channelCount int, pts time.Duration, au []byte) error {
func (t *segment) writeAAC(
pts time.Duration,
au []byte) error {
if t.videoTrack == nil {
if !t.firstPacketWritten {
t.firstPacketWritten = true
@ -194,8 +196,8 @@ func (t *segment) writeAAC(sampleRate int, channelCount int, pts time.Duration, @@ -194,8 +196,8 @@ func (t *segment) writeAAC(sampleRate int, channelCount int, pts time.Duration,
adtsPkt, err := aac.EncodeADTS([]*aac.ADTSPacket{
{
SampleRate: sampleRate,
ChannelCount: channelCount,
SampleRate: t.aacConf.SampleRate,
ChannelCount: t.aacConf.ChannelCount,
Frame: au,
},
})

38
internal/rtmp/metadata.go

@ -4,6 +4,7 @@ import ( @@ -4,6 +4,7 @@ import (
"fmt"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/rtpaac"
"github.com/notedit/rtmp/av"
nh264 "github.com/notedit/rtmp/codec/h264"
"github.com/notedit/rtmp/format/flv/flvio"
@ -121,6 +122,7 @@ func (c *Conn) ReadMetadata() (*gortsplib.Track, *gortsplib.Track, error) { @@ -121,6 +122,7 @@ func (c *Conn) ReadMetadata() (*gortsplib.Track, *gortsplib.Track, error) {
if !hasVideo {
return nil, nil, fmt.Errorf("unexpected video packet")
}
if videoTrack != nil {
return nil, nil, fmt.Errorf("video track setupped twice")
}
@ -130,7 +132,7 @@ func (c *Conn) ReadMetadata() (*gortsplib.Track, *gortsplib.Track, error) { @@ -130,7 +132,7 @@ func (c *Conn) ReadMetadata() (*gortsplib.Track, *gortsplib.Track, error) {
return nil, nil, err
}
videoTrack, err = gortsplib.NewTrackH264(96, codec.SPS[0], codec.PPS[0])
videoTrack, err = gortsplib.NewTrackH264(96, &gortsplib.TrackConfigH264{SPS: codec.SPS[0], PPS: codec.PPS[0]})
if err != nil {
return nil, nil, err
}
@ -139,11 +141,23 @@ func (c *Conn) ReadMetadata() (*gortsplib.Track, *gortsplib.Track, error) { @@ -139,11 +141,23 @@ func (c *Conn) ReadMetadata() (*gortsplib.Track, *gortsplib.Track, error) {
if !hasAudio {
return nil, nil, fmt.Errorf("unexpected audio packet")
}
if audioTrack != nil {
return nil, nil, fmt.Errorf("audio track setupped twice")
}
audioTrack, err = gortsplib.NewTrackAAC(96, pkt.Data)
var mpegConf rtpaac.MPEG4AudioConfig
err := mpegConf.Decode(pkt.Data)
if err != nil {
return nil, nil, err
}
audioTrack, err = gortsplib.NewTrackAAC(96, &gortsplib.TrackConfigAAC{
Type: int(mpegConf.Type),
SampleRate: mpegConf.SampleRate,
ChannelCount: mpegConf.ChannelCount,
AOTSpecificConfig: mpegConf.AOTSpecificConfig,
})
if err != nil {
return nil, nil, err
}
@ -194,17 +208,17 @@ func (c *Conn) WriteMetadata(videoTrack *gortsplib.Track, audioTrack *gortsplib. @@ -194,17 +208,17 @@ func (c *Conn) WriteMetadata(videoTrack *gortsplib.Track, audioTrack *gortsplib.
}
if videoTrack != nil {
sps, pps, err := videoTrack.ExtractDataH264()
conf, err := videoTrack.ExtractConfigH264()
if err != nil {
return err
}
codec := nh264.Codec{
SPS: map[int][]byte{
0: sps,
0: conf.SPS,
},
PPS: map[int][]byte{
0: pps,
0: conf.PPS,
},
}
b := make([]byte, 128)
@ -222,14 +236,24 @@ func (c *Conn) WriteMetadata(videoTrack *gortsplib.Track, audioTrack *gortsplib. @@ -222,14 +236,24 @@ func (c *Conn) WriteMetadata(videoTrack *gortsplib.Track, audioTrack *gortsplib.
}
if audioTrack != nil {
config, err := audioTrack.ExtractDataAAC()
conf, err := audioTrack.ExtractConfigAAC()
if err != nil {
return err
}
enc, err := rtpaac.MPEG4AudioConfig{
Type: rtpaac.MPEG4AudioType(conf.Type),
SampleRate: conf.SampleRate,
ChannelCount: conf.ChannelCount,
AOTSpecificConfig: conf.AOTSpecificConfig,
}.Encode()
if err != nil {
return err
}
err = c.WritePacket(av.Packet{
Type: av.AACDecoderConfig,
Data: config,
Data: enc,
})
if err != nil {
return err

Loading…
Cancel
Save