Browse Source

update gortsplib

pull/1249/head
aler9 4 years ago
parent
commit
282d155a4f
  1. 2
      go.mod
  2. 4
      go.sum
  3. 8
      internal/core/api_test.go
  4. 4
      internal/core/core_test.go
  5. 15
      internal/core/data.go
  6. 2
      internal/core/hls_source.go
  7. 2
      internal/core/metrics_test.go
  8. 10
      internal/core/rpicamera_source.go
  9. 2
      internal/core/rtmp_conn.go
  10. 5
      internal/core/rtmp_server_test.go
  11. 1
      internal/core/rtmp_source.go
  12. 1
      internal/core/rtmp_source_test.go
  13. 11
      internal/core/rtsp_server_test.go
  14. 2
      internal/core/rtsp_session.go
  15. 2
      internal/core/rtsp_source.go
  16. 26
      internal/core/rtsp_source_test.go
  17. 2
      internal/core/stream.go
  18. 9
      internal/core/streamtrack_h264.go
  19. 19
      internal/core/streamtrack_mpeg4audio.go
  20. 1
      internal/hls/fmp4/init.go
  21. 2
      internal/hls/fmp4/init_test.go
  22. 1
      internal/hls/mpegts/tracks.go
  23. 1
      internal/hls/mpegts/writer_test.go
  24. 5
      internal/hls/muxer_test.go
  25. 1
      internal/rtmp/conn.go
  26. 5
      internal/rtmp/conn_test.go

2
go.mod

@ -5,7 +5,7 @@ go 1.18 @@ -5,7 +5,7 @@ go 1.18
require (
code.cloudfoundry.org/bytefmt v0.0.0-20211005130812-5bb3c17173e5
github.com/abema/go-mp4 v0.8.0
github.com/aler9/gortsplib v0.0.0-20221110211534-12c8845fef0d
github.com/aler9/gortsplib v0.0.0-20221115222755-87d5a512b129
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

4
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-20221110211534-12c8845fef0d h1:fRx79L1YMXaoiSMkB32xgVCUMbOcmQ4JfySaUv7XZpc=
github.com/aler9/gortsplib v0.0.0-20221110211534-12c8845fef0d/go.mod h1:BOWNZ/QBkY/eVcRqUzJbPFEsRJshwxaxBT01K260Jeo=
github.com/aler9/gortsplib v0.0.0-20221115222755-87d5a512b129 h1:CG96FPsxizdlpsRIsjU2xQR6G3QC0sPK+f+AeVEr0Tg=
github.com/aler9/gortsplib v0.0.0-20221115222755-87d5a512b129/go.mod h1:BOWNZ/QBkY/eVcRqUzJbPFEsRJshwxaxBT01K260Jeo=
github.com/aler9/writerseeker v0.0.0-20220601075008-6f0e685b9c82 h1:9WgSzBLo3a9ToSVV7sRTBYZ1GGOZUpq4+5H3SN0UZq4=
github.com/aler9/writerseeker v0.0.0-20220601075008-6f0e685b9c82/go.mod h1:qsMrZCbeBf/mCLOeF16KDkPu4gktn/pOWyaq1aYQE7U=
github.com/asticode/go-astikit v0.20.0 h1:+7N+J4E4lWx2QOkRdOf6DafWJMv6O4RRfgClwQokrH8=

8
internal/core/api_test.go

@ -196,6 +196,7 @@ func TestAPIPathsList(t *testing.T) { @@ -196,6 +196,7 @@ func TestAPIPathsList(t *testing.T) {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
},
&gortsplib.TrackMPEG4Audio{
PayloadType: 96,
@ -218,7 +219,7 @@ func TestAPIPathsList(t *testing.T) { @@ -218,7 +219,7 @@ func TestAPIPathsList(t *testing.T) {
PayloadType: 96,
},
Payload: []byte{0x01, 0x02, 0x03, 0x04},
}, true)
})
var out pathList
err = httpRequest(http.MethodGet, "http://localhost:9997/v1/paths/list", nil, &out)
@ -260,6 +261,7 @@ func TestAPIPathsList(t *testing.T) { @@ -260,6 +261,7 @@ func TestAPIPathsList(t *testing.T) {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
},
&gortsplib.TrackMPEG4Audio{
PayloadType: 97,
@ -416,6 +418,7 @@ func TestAPIProtocolSpecificList(t *testing.T) { @@ -416,6 +418,7 @@ func TestAPIProtocolSpecificList(t *testing.T) {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
}
switch ca {
@ -469,6 +472,7 @@ func TestAPIProtocolSpecificList(t *testing.T) { @@ -469,6 +472,7 @@ func TestAPIProtocolSpecificList(t *testing.T) {
0x00, 0x00, 0x03, 0x00, 0xf0, 0x3c, 0x60, 0xc9, 0x20,
},
PPS: []byte{0x08, 0x06, 0x07, 0x08},
PacketizationMode: 1,
}
err = conn.WriteTracks(videoTrack, nil)
@ -588,6 +592,7 @@ func TestAPIKick(t *testing.T) { @@ -588,6 +592,7 @@ func TestAPIKick(t *testing.T) {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
}
switch ca {
@ -629,6 +634,7 @@ func TestAPIKick(t *testing.T) { @@ -629,6 +634,7 @@ func TestAPIKick(t *testing.T) {
0x00, 0x00, 0x03, 0x00, 0xf0, 0x3c, 0x60, 0xc9, 0x20,
},
PPS: []byte{0x08, 0x06, 0x07, 0x08},
PacketizationMode: 1,
}
err = conn.WriteTracks(videoTrack, nil)

4
internal/core/core_test.go

@ -194,6 +194,7 @@ func main() { @@ -194,6 +194,7 @@ func main() {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
}
source := gortsplib.Client{}
@ -324,6 +325,7 @@ func TestCorePathRunOnReady(t *testing.T) { @@ -324,6 +325,7 @@ func TestCorePathRunOnReady(t *testing.T) {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
}
c := gortsplib.Client{}
@ -360,6 +362,7 @@ func TestCoreHotReloading(t *testing.T) { @@ -360,6 +362,7 @@ func TestCoreHotReloading(t *testing.T) {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
}
c := gortsplib.Client{}
@ -382,6 +385,7 @@ func TestCoreHotReloading(t *testing.T) { @@ -382,6 +385,7 @@ func TestCoreHotReloading(t *testing.T) {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
}
conn := gortsplib.Client{}

15
internal/core/data.go

@ -10,13 +10,11 @@ import ( @@ -10,13 +10,11 @@ import (
type data interface {
getTrackID() int
getRTPPackets() []*rtp.Packet
getPTSEqualsDTS() bool
}
type dataGeneric struct {
trackID int
rtpPackets []*rtp.Packet
ptsEqualsDTS bool
}
func (d *dataGeneric) getTrackID() int {
@ -27,14 +25,9 @@ func (d *dataGeneric) getRTPPackets() []*rtp.Packet { @@ -27,14 +25,9 @@ func (d *dataGeneric) getRTPPackets() []*rtp.Packet {
return d.rtpPackets
}
func (d *dataGeneric) getPTSEqualsDTS() bool {
return d.ptsEqualsDTS
}
type dataH264 struct {
trackID int
rtpPackets []*rtp.Packet
ptsEqualsDTS bool
pts time.Duration
nalus [][]byte
}
@ -47,10 +40,6 @@ func (d *dataH264) getRTPPackets() []*rtp.Packet { @@ -47,10 +40,6 @@ func (d *dataH264) getRTPPackets() []*rtp.Packet {
return d.rtpPackets
}
func (d *dataH264) getPTSEqualsDTS() bool {
return d.ptsEqualsDTS
}
type dataMPEG4Audio struct {
trackID int
rtpPackets []*rtp.Packet
@ -65,7 +54,3 @@ func (d *dataMPEG4Audio) getTrackID() int { @@ -65,7 +54,3 @@ func (d *dataMPEG4Audio) getTrackID() int {
func (d *dataMPEG4Audio) getRTPPackets() []*rtp.Packet {
return d.rtpPackets
}
func (d *dataMPEG4Audio) getPTSEqualsDTS() bool {
return true
}

2
internal/core/hls_source.go

@ -5,7 +5,6 @@ import ( @@ -5,7 +5,6 @@ import (
"time"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/h264"
"github.com/aler9/rtsp-simple-server/internal/hls"
"github.com/aler9/rtsp-simple-server/internal/logger"
@ -81,7 +80,6 @@ func (s *hlsSource) run(ctx context.Context) error { @@ -81,7 +80,6 @@ func (s *hlsSource) run(ctx context.Context) error {
onVideoData := func(pts time.Duration, nalus [][]byte) {
err := stream.writeData(&dataH264{
trackID: videoTrackID,
ptsEqualsDTS: h264.IDRPresent(nalus),
pts: pts,
nalus: nalus,
})

2
internal/core/metrics_test.go

@ -37,6 +37,7 @@ func TestMetrics(t *testing.T) { @@ -37,6 +37,7 @@ func TestMetrics(t *testing.T) {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
}
source := gortsplib.Client{}
@ -70,6 +71,7 @@ func TestMetrics(t *testing.T) { @@ -70,6 +71,7 @@ func TestMetrics(t *testing.T) {
0x00, 0x00, 0x03, 0x00, 0xf0, 0x3c, 0x60, 0xc9, 0x20,
},
PPS: []byte{0x08, 0x06, 0x07, 0x08},
PacketizationMode: 1,
}
err = conn.WriteTracks(videoTrack, nil)

10
internal/core/rpicamera_source.go

@ -5,8 +5,6 @@ import ( @@ -5,8 +5,6 @@ import (
"time"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/h264"
"github.com/aler9/gortsplib/pkg/rtph264"
"github.com/aler9/rtsp-simple-server/internal/logger"
"github.com/aler9/rtsp-simple-server/internal/rpicamera"
@ -39,10 +37,11 @@ func (s *rpiCameraSource) Log(level logger.Level, format string, args ...interfa @@ -39,10 +37,11 @@ func (s *rpiCameraSource) Log(level logger.Level, format string, args ...interfa
// run implements sourceStaticImpl.
func (s *rpiCameraSource) run(ctx context.Context) error {
track := &gortsplib.TrackH264{PayloadType: 96}
track := &gortsplib.TrackH264{
PayloadType: 96,
PacketizationMode: 1,
}
tracks := gortsplib.Tracks{track}
enc := &rtph264.Encoder{PayloadType: 96}
enc.Init()
var stream *stream
onData := func(dts time.Duration, nalus [][]byte) {
@ -61,7 +60,6 @@ func (s *rpiCameraSource) run(ctx context.Context) error { @@ -61,7 +60,6 @@ func (s *rpiCameraSource) run(ctx context.Context) error {
err := stream.writeData(&dataH264{
trackID: 0,
ptsEqualsDTS: h264.IDRPresent(nalus),
pts: dts,
nalus: nalus,
})

2
internal/core/rtmp_conn.go

@ -560,7 +560,6 @@ func (c *rtmpConn) runPublish(ctx context.Context, u *url.URL) error { @@ -560,7 +560,6 @@ func (c *rtmpConn) runPublish(ctx context.Context, u *url.URL) error {
err := rres.stream.writeData(&dataH264{
trackID: videoTrackID,
ptsEqualsDTS: false,
pts: tmsg.DTS + tmsg.PTSDelta,
nalus: nalus,
})
@ -599,7 +598,6 @@ func (c *rtmpConn) runPublish(ctx context.Context, u *url.URL) error { @@ -599,7 +598,6 @@ func (c *rtmpConn) runPublish(ctx context.Context, u *url.URL) error {
err = rres.stream.writeData(&dataH264{
trackID: videoTrackID,
ptsEqualsDTS: h264.IDRPresent(validNALUs),
pts: tmsg.DTS + tmsg.PTSDelta,
nalus: validNALUs,
})

5
internal/core/rtmp_server_test.go

@ -76,6 +76,7 @@ func TestRTMPServerPublishRead(t *testing.T) { @@ -76,6 +76,7 @@ func TestRTMPServerPublishRead(t *testing.T) {
0x00, 0x00, 0x03, 0x00, 0xf0, 0x3c, 0x60, 0xc9, 0x20,
},
PPS: []byte{0x08, 0x06, 0x07, 0x08},
PacketizationMode: 1,
}
audioTrack := &gortsplib.TrackMPEG4Audio{
@ -199,6 +200,7 @@ func TestRTMPServerAuth(t *testing.T) { @@ -199,6 +200,7 @@ func TestRTMPServerAuth(t *testing.T) {
PPS: []byte{
0x68, 0xee, 0x3c, 0x80,
},
PacketizationMode: 1,
}
err = conn1.WriteTracks(videoTrack, nil)
@ -262,6 +264,7 @@ func TestRTMPServerAuthFail(t *testing.T) { @@ -262,6 +264,7 @@ func TestRTMPServerAuthFail(t *testing.T) {
PPS: []byte{
0x68, 0xee, 0x3c, 0x80,
},
PacketizationMode: 1,
}
err = conn1.WriteTracks(videoTrack, nil)
@ -316,6 +319,7 @@ func TestRTMPServerAuthFail(t *testing.T) { @@ -316,6 +319,7 @@ func TestRTMPServerAuthFail(t *testing.T) {
PPS: []byte{
0x68, 0xee, 0x3c, 0x80,
},
PacketizationMode: 1,
}
err = conn1.WriteTracks(videoTrack, nil)
@ -369,6 +373,7 @@ func TestRTMPServerAuthFail(t *testing.T) { @@ -369,6 +373,7 @@ func TestRTMPServerAuthFail(t *testing.T) {
PPS: []byte{
0x68, 0xee, 0x3c, 0x80,
},
PacketizationMode: 1,
}
err = conn1.WriteTracks(videoTrack, nil)

1
internal/core/rtmp_source.go

@ -172,7 +172,6 @@ func (s *rtmpSource) run(ctx context.Context) error { @@ -172,7 +172,6 @@ func (s *rtmpSource) run(ctx context.Context) error {
err = res.stream.writeData(&dataH264{
trackID: videoTrackID,
ptsEqualsDTS: h264.IDRPresent(nalus),
pts: tmsg.DTS + tmsg.PTSDelta,
nalus: nalus,
})

1
internal/core/rtmp_source_test.go

@ -65,6 +65,7 @@ func TestRTMPSource(t *testing.T) { @@ -65,6 +65,7 @@ func TestRTMPSource(t *testing.T) {
0x00, 0x00, 0x03, 0x00, 0xf0, 0x3c, 0x60, 0xc9, 0x20,
},
PPS: []byte{0x08, 0x06, 0x07, 0x08},
PacketizationMode: 1,
}
audioTrack := &gortsplib.TrackMPEG4Audio{

11
internal/core/rtsp_server_test.go

@ -48,6 +48,7 @@ func TestRTSPServerAuth(t *testing.T) { @@ -48,6 +48,7 @@ func TestRTSPServerAuth(t *testing.T) {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
}
source := gortsplib.Client{}
@ -97,6 +98,7 @@ func TestRTSPServerAuth(t *testing.T) { @@ -97,6 +98,7 @@ func TestRTSPServerAuth(t *testing.T) {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
}
source := gortsplib.Client{}
@ -145,6 +147,7 @@ func TestRTSPServerAuthFail(t *testing.T) { @@ -145,6 +147,7 @@ func TestRTSPServerAuthFail(t *testing.T) {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
}
c := gortsplib.Client{}
@ -215,6 +218,7 @@ func TestRTSPServerAuthFail(t *testing.T) { @@ -215,6 +218,7 @@ func TestRTSPServerAuthFail(t *testing.T) {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
}
c := gortsplib.Client{}
@ -241,6 +245,7 @@ func TestRTSPServerAuthFail(t *testing.T) { @@ -241,6 +245,7 @@ func TestRTSPServerAuthFail(t *testing.T) {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
}
c := gortsplib.Client{}
@ -276,6 +281,7 @@ func TestRTSPServerPublisherOverride(t *testing.T) { @@ -276,6 +281,7 @@ func TestRTSPServerPublisherOverride(t *testing.T) {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
}
s1 := gortsplib.Client{}
@ -332,7 +338,7 @@ func TestRTSPServerPublisherOverride(t *testing.T) { @@ -332,7 +338,7 @@ func TestRTSPServerPublisherOverride(t *testing.T) {
Marker: true,
},
Payload: []byte{0x01, 0x02, 0x03, 0x04},
}, true)
})
if ca == "enabled" {
require.Error(t, err)
} else {
@ -350,7 +356,7 @@ func TestRTSPServerPublisherOverride(t *testing.T) { @@ -350,7 +356,7 @@ func TestRTSPServerPublisherOverride(t *testing.T) {
Marker: true,
},
Payload: []byte{0x05, 0x06, 0x07, 0x08},
}, true)
})
require.NoError(t, err)
}
@ -387,6 +393,7 @@ func TestRTSPServerFallback(t *testing.T) { @@ -387,6 +393,7 @@ func TestRTSPServerFallback(t *testing.T) {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
}})
require.NoError(t, err)
defer source.Close()

2
internal/core/rtsp_session.go

@ -386,7 +386,6 @@ func (s *rtspSession) onPacketRTP(ctx *gortsplib.ServerHandlerOnPacketRTPCtx) { @@ -386,7 +386,6 @@ func (s *rtspSession) onPacketRTP(ctx *gortsplib.ServerHandlerOnPacketRTPCtx) {
err = s.stream.writeData(&dataH264{
trackID: ctx.TrackID,
rtpPackets: []*rtp.Packet{ctx.Packet},
ptsEqualsDTS: ctx.PTSEqualsDTS,
})
case *gortsplib.TrackMPEG4Audio:
@ -399,7 +398,6 @@ func (s *rtspSession) onPacketRTP(ctx *gortsplib.ServerHandlerOnPacketRTPCtx) { @@ -399,7 +398,6 @@ func (s *rtspSession) onPacketRTP(ctx *gortsplib.ServerHandlerOnPacketRTPCtx) {
err = s.stream.writeData(&dataGeneric{
trackID: ctx.TrackID,
rtpPackets: []*rtp.Packet{ctx.Packet},
ptsEqualsDTS: ctx.PTSEqualsDTS,
})
}

2
internal/core/rtsp_source.go

@ -151,7 +151,6 @@ func (s *rtspSource) run(ctx context.Context) error { @@ -151,7 +151,6 @@ func (s *rtspSource) run(ctx context.Context) error {
err = res.stream.writeData(&dataH264{
trackID: ctx.TrackID,
rtpPackets: []*rtp.Packet{ctx.Packet},
ptsEqualsDTS: ctx.PTSEqualsDTS,
})
case *gortsplib.TrackMPEG4Audio:
@ -164,7 +163,6 @@ func (s *rtspSource) run(ctx context.Context) error { @@ -164,7 +163,6 @@ func (s *rtspSource) run(ctx context.Context) error {
err = res.stream.writeData(&dataGeneric{
trackID: ctx.TrackID,
rtpPackets: []*rtp.Packet{ctx.Packet},
ptsEqualsDTS: ctx.PTSEqualsDTS,
})
}

26
internal/core/rtsp_source_test.go

@ -14,7 +14,6 @@ import ( @@ -14,7 +14,6 @@ import (
"github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/gortsplib/pkg/conn"
"github.com/aler9/gortsplib/pkg/headers"
"github.com/aler9/gortsplib/pkg/rtph264"
"github.com/aler9/gortsplib/pkg/url"
"github.com/pion/rtp"
"github.com/stretchr/testify/require"
@ -50,6 +49,7 @@ func TestRTSPSource(t *testing.T) { @@ -50,6 +49,7 @@ func TestRTSPSource(t *testing.T) {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
}
stream := gortsplib.NewServerStream(gortsplib.Tracks{track})
@ -96,7 +96,7 @@ func TestRTSPSource(t *testing.T) { @@ -96,7 +96,7 @@ func TestRTSPSource(t *testing.T) {
Marker: true,
},
Payload: []byte{0x01, 0x02, 0x03, 0x04},
}, true)
})
}()
return &base.Response{
@ -182,6 +182,7 @@ func TestRTSPSourceNoPassword(t *testing.T) { @@ -182,6 +182,7 @@ func TestRTSPSourceNoPassword(t *testing.T) {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
}
stream := gortsplib.NewServerStream(gortsplib.Tracks{track})
@ -242,9 +243,11 @@ func TestRTSPSourceNoPassword(t *testing.T) { @@ -242,9 +243,11 @@ func TestRTSPSourceNoPassword(t *testing.T) {
}
func TestRTSPSourceDynamicH264Params(t *testing.T) {
stream := gortsplib.NewServerStream(gortsplib.Tracks{&gortsplib.TrackH264{
track := &gortsplib.TrackH264{
PayloadType: 96,
}})
PacketizationMode: 1,
}
stream := gortsplib.NewServerStream(gortsplib.Tracks{track})
defer stream.Close()
s := gortsplib.Server{
@ -282,16 +285,15 @@ func TestRTSPSourceDynamicH264Params(t *testing.T) { @@ -282,16 +285,15 @@ func TestRTSPSourceDynamicH264Params(t *testing.T) {
time.Sleep(1 * time.Second)
enc := &rtph264.Encoder{PayloadType: 96}
enc.Init()
enc := track.CreateEncoder()
pkts, err := enc.Encode([][]byte{{7, 1, 2, 3}}, 0) // SPS
require.NoError(t, err)
stream.WritePacketRTP(0, pkts[0], true)
stream.WritePacketRTP(0, pkts[0])
pkts, err = enc.Encode([][]byte{{8}}, 0) // PPS
require.NoError(t, err)
stream.WritePacketRTP(0, pkts[0], true)
stream.WritePacketRTP(0, pkts[0])
time.Sleep(500 * time.Millisecond)
@ -316,11 +318,11 @@ func TestRTSPSourceDynamicH264Params(t *testing.T) { @@ -316,11 +318,11 @@ func TestRTSPSourceDynamicH264Params(t *testing.T) {
pkts, err = enc.Encode([][]byte{{7, 4, 5, 6}}, 0) // SPS
require.NoError(t, err)
stream.WritePacketRTP(0, pkts[0], true)
stream.WritePacketRTP(0, pkts[0])
pkts, err = enc.Encode([][]byte{{8, 1}}, 0) // PPS
require.NoError(t, err)
stream.WritePacketRTP(0, pkts[0], true)
stream.WritePacketRTP(0, pkts[0])
time.Sleep(500 * time.Millisecond)
@ -347,6 +349,7 @@ func TestRTSPSourceDynamicH264Params(t *testing.T) { @@ -347,6 +349,7 @@ func TestRTSPSourceDynamicH264Params(t *testing.T) {
func TestRTSPSourceRemovePadding(t *testing.T) {
stream := gortsplib.NewServerStream(gortsplib.Tracks{&gortsplib.TrackH264{
PayloadType: 96,
PacketizationMode: 1,
}})
defer stream.Close()
@ -430,7 +433,7 @@ func TestRTSPSourceRemovePadding(t *testing.T) { @@ -430,7 +433,7 @@ func TestRTSPSourceRemovePadding(t *testing.T) {
},
Payload: []byte{0x01, 0x02, 0x03, 0x04},
PaddingSize: 20,
}, true)
})
<-packetRecv
}
@ -476,6 +479,7 @@ func TestRTSPSourceOversizedPackets(t *testing.T) { @@ -476,6 +479,7 @@ func TestRTSPSourceOversizedPackets(t *testing.T) {
PayloadType: 96,
SPS: []byte{0x01, 0x02, 0x03, 0x04},
PPS: []byte{0x01, 0x02, 0x03, 0x04},
PacketizationMode: 1,
}}
err = conn.WriteResponse(&base.Response{

2
internal/core/stream.go

@ -112,7 +112,7 @@ func (s *stream) writeData(data data) error { @@ -112,7 +112,7 @@ func (s *stream) writeData(data data) error {
// forward RTP packets to RTSP readers
for _, pkt := range data.getRTPPackets() {
atomic.AddUint64(s.bytesReceived, uint64(pkt.MarshalSize()))
s.rtspStream.WritePacketRTP(data.getTrackID(), pkt, data.getPTSEqualsDTS())
s.rtspStream.WritePacketRTP(data.getTrackID(), pkt)
}
// forward data to non-RTSP readers

9
internal/core/streamtrack_h264.go

@ -5,7 +5,7 @@ import ( @@ -5,7 +5,7 @@ import (
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/h264"
"github.com/aler9/gortsplib/pkg/rtph264"
"github.com/aler9/gortsplib/pkg/rtpcodecs/rtph264"
"github.com/pion/rtp"
)
@ -77,8 +77,7 @@ func newStreamTrackH264( @@ -77,8 +77,7 @@ func newStreamTrackH264(
}
if allocateEncoder {
t.encoder = &rtph264.Encoder{PayloadType: 96}
t.encoder.Init()
t.encoder = track.CreateEncoder()
}
return t
@ -200,6 +199,7 @@ func (t *streamTrackH264) onData(dat data, hasNonRTSPReaders bool) error { @@ -200,6 +199,7 @@ func (t *streamTrackH264) onData(dat data, hasNonRTSPReaders bool) error {
SSRC: &v1,
InitialSequenceNumber: &v2,
InitialTimestamp: &v3,
PacketizationMode: t.track.PacketizationMode,
}
t.encoder.Init()
}
@ -208,8 +208,7 @@ func (t *streamTrackH264) onData(dat data, hasNonRTSPReaders bool) error { @@ -208,8 +208,7 @@ func (t *streamTrackH264) onData(dat data, hasNonRTSPReaders bool) error {
// decode from RTP
if hasNonRTSPReaders || t.encoder != nil {
if t.decoder == nil {
t.decoder = &rtph264.Decoder{}
t.decoder.Init()
t.decoder = t.track.CreateDecoder()
}
nalus, pts, err := t.decoder.Decode(pkt)

19
internal/core/streamtrack_mpeg4audio.go

@ -4,7 +4,7 @@ import ( @@ -4,7 +4,7 @@ import (
"fmt"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/pkg/rtpmpeg4audio"
"github.com/aler9/gortsplib/pkg/rtpcodecs/rtpmpeg4audio"
)
type streamTrackMPEG4Audio struct {
@ -22,14 +22,7 @@ func newStreamTrackMPEG4Audio( @@ -22,14 +22,7 @@ func newStreamTrackMPEG4Audio(
}
if allocateEncoder {
t.encoder = &rtpmpeg4audio.Encoder{
PayloadType: 96,
SampleRate: track.ClockRate(),
SizeLength: 13,
IndexLength: 3,
IndexDeltaLength: 3,
}
t.encoder.Init()
t.encoder = track.CreateEncoder()
}
return t
@ -63,13 +56,7 @@ func (t *streamTrackMPEG4Audio) onData(dat data, hasNonRTSPReaders bool) error { @@ -63,13 +56,7 @@ func (t *streamTrackMPEG4Audio) onData(dat data, hasNonRTSPReaders bool) error {
// decode from RTP
if hasNonRTSPReaders {
if t.decoder == nil {
t.decoder = &rtpmpeg4audio.Decoder{
SampleRate: t.track.Config.SampleRate,
SizeLength: t.track.SizeLength,
IndexLength: t.track.IndexLength,
IndexDeltaLength: t.track.IndexDeltaLength,
}
t.decoder.Init()
t.decoder = t.track.CreateDecoder()
}
aus, pts, err := t.decoder.Decode(pkt)

1
internal/hls/fmp4/init.go

@ -109,6 +109,7 @@ func (i *Init) Unmarshal(byts []byte) error { @@ -109,6 +109,7 @@ func (i *Init) Unmarshal(byts []byte) error {
PayloadType: 96,
SPS: sps,
PPS: pps,
PacketizationMode: 1,
}
state = waitingTrak

2
internal/hls/fmp4/init_test.go

@ -20,6 +20,7 @@ var testVideoTrack = &gortsplib.TrackH264{ @@ -20,6 +20,7 @@ var testVideoTrack = &gortsplib.TrackH264{
PayloadType: 96,
SPS: testSPS,
PPS: []byte{0x08},
PacketizationMode: 1,
}
var testAudioTrack = &gortsplib.TrackMPEG4Audio{
@ -567,6 +568,7 @@ func TestInitUnmarshal(t *testing.T) { @@ -567,6 +568,7 @@ func TestInitUnmarshal(t *testing.T) {
PPS: []byte{
0x68, 0xcb, 0x8c, 0xb2,
},
PacketizationMode: 1,
},
},
},

1
internal/hls/mpegts/tracks.go

@ -79,6 +79,7 @@ func FindTracks(byts []byte) ([]*Track, error) { @@ -79,6 +79,7 @@ func FindTracks(byts []byte) ([]*Track, error) {
case astits.StreamTypeH264Video:
t.Track = &gortsplib.TrackH264{
PayloadType: 96,
PacketizationMode: 1,
}
case astits.StreamTypeAACAudio:

1
internal/hls/mpegts/writer_test.go

@ -25,6 +25,7 @@ func TestWriter(t *testing.T) { @@ -25,6 +25,7 @@ func TestWriter(t *testing.T) {
PayloadType: 96,
SPS: testSPS,
PPS: []byte{0x08},
PacketizationMode: 1,
}
testAudioTrack := &gortsplib.TrackMPEG4Audio{

5
internal/hls/muxer_test.go

@ -26,6 +26,7 @@ func TestMuxerVideoAudio(t *testing.T) { @@ -26,6 +26,7 @@ func TestMuxerVideoAudio(t *testing.T) {
PayloadType: 96,
SPS: testSPS,
PPS: []byte{0x08},
PacketizationMode: 1,
}
audioTrack := &gortsplib.TrackMPEG4Audio{
@ -183,6 +184,7 @@ func TestMuxerVideoOnly(t *testing.T) { @@ -183,6 +184,7 @@ func TestMuxerVideoOnly(t *testing.T) {
PayloadType: 96,
SPS: testSPS,
PPS: []byte{0x08},
PacketizationMode: 1,
}
for _, ca := range []string{
@ -407,6 +409,7 @@ func TestMuxerCloseBeforeFirstSegmentReader(t *testing.T) { @@ -407,6 +409,7 @@ func TestMuxerCloseBeforeFirstSegmentReader(t *testing.T) {
PayloadType: 96,
SPS: testSPS,
PPS: []byte{0x08},
PacketizationMode: 1,
}
m, err := NewMuxer(MuxerVariantMPEGTS, 3, 1*time.Second, 0, 50*1024*1024, videoTrack, nil)
@ -431,6 +434,7 @@ func TestMuxerMaxSegmentSize(t *testing.T) { @@ -431,6 +434,7 @@ func TestMuxerMaxSegmentSize(t *testing.T) {
PayloadType: 96,
SPS: testSPS,
PPS: []byte{0x08},
PacketizationMode: 1,
}
m, err := NewMuxer(MuxerVariantMPEGTS, 3, 1*time.Second, 0, 0, videoTrack, nil)
@ -449,6 +453,7 @@ func TestMuxerDoubleRead(t *testing.T) { @@ -449,6 +453,7 @@ func TestMuxerDoubleRead(t *testing.T) {
PayloadType: 96,
SPS: testSPS,
PPS: []byte{0x08},
PacketizationMode: 1,
}
m, err := NewMuxer(MuxerVariantMPEGTS, 3, 1*time.Second, 0, 50*1024*1024, videoTrack, nil)

1
internal/rtmp/conn.go

@ -591,6 +591,7 @@ func trackFromH264DecoderConfig(data []byte) (*gortsplib.TrackH264, error) { @@ -591,6 +591,7 @@ func trackFromH264DecoderConfig(data []byte) (*gortsplib.TrackH264, error) {
PayloadType: 96,
SPS: conf.SPS,
PPS: conf.PPS,
PacketizationMode: 1,
}, nil
}

5
internal/rtmp/conn_test.go

@ -502,6 +502,7 @@ func TestReadTracks(t *testing.T) { @@ -502,6 +502,7 @@ func TestReadTracks(t *testing.T) {
PayloadType: 96,
SPS: sps,
PPS: pps,
PacketizationMode: 1,
}, videoTrack)
require.Equal(t, &gortsplib.TrackMPEG4Audio{
@ -521,6 +522,7 @@ func TestReadTracks(t *testing.T) { @@ -521,6 +522,7 @@ func TestReadTracks(t *testing.T) {
PayloadType: 96,
SPS: sps,
PPS: pps,
PacketizationMode: 1,
}, videoTrack)
require.Nil(t, audioTrack)
@ -530,6 +532,7 @@ func TestReadTracks(t *testing.T) { @@ -530,6 +532,7 @@ func TestReadTracks(t *testing.T) {
PayloadType: 96,
SPS: sps,
PPS: pps,
PacketizationMode: 1,
}, videoTrack)
require.Equal(t, &gortsplib.TrackMPEG4Audio{
@ -549,6 +552,7 @@ func TestReadTracks(t *testing.T) { @@ -549,6 +552,7 @@ func TestReadTracks(t *testing.T) {
PayloadType: 96,
SPS: sps,
PPS: pps,
PacketizationMode: 1,
}, videoTrack)
require.Equal(t, &gortsplib.TrackMPEG4Audio{
@ -936,6 +940,7 @@ func TestWriteTracks(t *testing.T) { @@ -936,6 +940,7 @@ func TestWriteTracks(t *testing.T) {
PPS: []byte{
0x68, 0xee, 0x3c, 0x80,
},
PacketizationMode: 1,
}
audioTrack := &gortsplib.TrackMPEG4Audio{

Loading…
Cancel
Save