mirror of
https://github.com/Monibuca/plugin-rtsp.git
synced 2025-09-27 03:56:08 +08:00
适配引擎版本升级
This commit is contained in:
37
client.go
37
client.go
@@ -18,13 +18,15 @@ import (
|
||||
|
||||
. "github.com/Monibuca/engine/v3"
|
||||
. "github.com/Monibuca/utils/v3"
|
||||
"github.com/pion/rtp"
|
||||
)
|
||||
|
||||
// PullStream 从外部拉流
|
||||
func (rtsp *RTSP) PullStream(streamPath string, rtspUrl string) (err error) {
|
||||
if result := rtsp.Publish(streamPath); result {
|
||||
rtsp.Stream.Type = "RTSP"
|
||||
rtsp.Stream = &Stream{
|
||||
StreamPath: streamPath,
|
||||
Type: "RTSP Pull",
|
||||
}
|
||||
if result := rtsp.Publish(); result {
|
||||
rtsp.TransType = TRANS_TYPE_TCP
|
||||
rtsp.vRTPChannel = 0
|
||||
rtsp.vRTPControlChannel = 1
|
||||
@@ -217,14 +219,12 @@ func (client *RTSP) requestStream() (err error) {
|
||||
switch t {
|
||||
case "video":
|
||||
if len(sdpInfo.SpropParameterSets) > 1 {
|
||||
vt := NewVideoTrack()
|
||||
vt.CodecID = 7
|
||||
var pack VideoPack
|
||||
pack.Payload = sdpInfo.SpropParameterSets[0]
|
||||
vt.Push(pack)
|
||||
pack.Payload = sdpInfo.SpropParameterSets[1]
|
||||
vt.Push(pack)
|
||||
client.SetOriginVT(vt)
|
||||
client.RtpVideo = client.NewRTPVideo(7)
|
||||
client.RtpVideo.PushNalu(VideoPack{NALUs: sdpInfo.SpropParameterSets})
|
||||
} else if client.VSdp.Codec == "H264" {
|
||||
client.RtpVideo = client.NewRTPVideo(7)
|
||||
} else if client.VSdp.Codec == "H265" {
|
||||
client.RtpVideo = client.NewRTPVideo(12)
|
||||
}
|
||||
if client.TransType == TRANS_TYPE_TCP {
|
||||
headers["Transport"] = fmt.Sprintf("RTP/AVP/TCP;unicast;interleaved=%d-%d", client.vRTPChannel, client.vRTPControlChannel)
|
||||
@@ -238,13 +238,13 @@ func (client *RTSP) requestStream() (err error) {
|
||||
client.Conn.timeout = 0 // UDP ignore timeout
|
||||
}
|
||||
case "audio":
|
||||
at := NewAudioTrack()
|
||||
if len(sdpInfo.Config) > 0 {
|
||||
at.SetASC(sdpInfo.Config)
|
||||
client.RtpAudio = client.NewRTPAudio(0)
|
||||
at := client.RtpAudio.AudioTrack
|
||||
if len(client.ASdp.Control) > 0 {
|
||||
at.SetASC(client.ASdp.Config)
|
||||
} else {
|
||||
client.setAudioFormat(at)
|
||||
}
|
||||
client.SetOriginAT(at)
|
||||
if client.TransType == TRANS_TYPE_TCP {
|
||||
headers["Transport"] = fmt.Sprintf("RTP/AVP/TCP;unicast;interleaved=%d-%d", client.aRTPChannel, client.aRTPControlChannel)
|
||||
} else {
|
||||
@@ -339,15 +339,14 @@ func (client *RTSP) startStream() {
|
||||
Printf("io.ReadFull err:%v", err)
|
||||
return
|
||||
}
|
||||
var pack rtp.Packet
|
||||
pack.Unmarshal(content)
|
||||
|
||||
switch channel {
|
||||
case client.aRTPChannel:
|
||||
client.OriginAudioTrack.PushRTP(pack)
|
||||
client.RtpAudio.Push(content)
|
||||
case client.aRTPControlChannel:
|
||||
|
||||
case client.vRTPChannel:
|
||||
client.OriginVideoTrack.PushRTP(pack)
|
||||
client.RtpVideo.Push(content)
|
||||
case client.vRTPControlChannel:
|
||||
|
||||
default:
|
||||
|
10
go.mod
10
go.mod
@@ -3,11 +3,9 @@ module github.com/Monibuca/plugin-rtsp/v3
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/Monibuca/engine/v3 v3.0.0-alpha6
|
||||
github.com/Monibuca/utils/v3 v3.0.0-alpha5
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
|
||||
github.com/pion/rtp v1.6.2
|
||||
github.com/shirou/gopsutil v3.21.1+incompatible // indirect
|
||||
github.com/Monibuca/engine/v3 v3.0.0-beta5
|
||||
github.com/Monibuca/utils/v3 v3.0.0-beta
|
||||
github.com/pion/rtp v1.6.5
|
||||
github.com/teris-io/shortid v0.0.0-20201117134242-e59966efd125
|
||||
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43 // indirect
|
||||
golang.org/x/sys v0.0.0-20210611083646-a4fc73990273 // indirect
|
||||
)
|
||||
|
79
go.sum
79
go.sum
@@ -1,98 +1,43 @@
|
||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/Monibuca/engine v1.2.2 h1:hNjsrZpOmui8lYhgCJ5ltJU8g/k0Rrdysx2tHNGGnbI=
|
||||
github.com/Monibuca/engine/v2 v2.1.0 h1:pHeDCEFDusKFsZLpconYj8U5LCaWApnjd+yQRHYgQsQ=
|
||||
github.com/Monibuca/engine/v2 v2.1.0/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||
github.com/Monibuca/engine/v2 v2.1.2 h1:7dUrHJAPEtvGFOO4GsKGjfMCmcbMrtLyYQ7WoK5EpG0=
|
||||
github.com/Monibuca/engine/v2 v2.1.2/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||
github.com/Monibuca/engine/v2 v2.1.9 h1:IulMIeP24qv8xWaI+tcg233Y7w3mCaLXxt4iQaVpT7s=
|
||||
github.com/Monibuca/engine/v2 v2.1.9/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||
github.com/Monibuca/engine/v2 v2.2.0 h1:A4SyWwzVLegd8Oa6LfSW3LpNfBmWq+MHJJLO55gvaYI=
|
||||
github.com/Monibuca/engine/v2 v2.2.0/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||
github.com/Monibuca/engine/v2 v2.2.1 h1:I9mcnj9ZABl974n+HKGWe4pFcn9z8kETLVpD1fx2zEI=
|
||||
github.com/Monibuca/engine/v2 v2.2.1/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||
github.com/Monibuca/engine/v2 v2.2.2 h1:ho5M3aFW9Mlj9Lb56Qvk0m+9L8yWc7RhwPh8dRWAeBk=
|
||||
github.com/Monibuca/engine/v2 v2.2.2/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||
github.com/Monibuca/engine/v2 v2.3.0 h1:fGyah7FJ9WCcS1Z86xMV0ACF6IrUENT9IS7Ett2pXkE=
|
||||
github.com/Monibuca/engine/v2 v2.3.0/go.mod h1:34EYjjV15G6myuHOKaJkO7y5tJ1Arq/NfC9Weacr2mc=
|
||||
github.com/Monibuca/engine/v3 v3.0.0-alpha4 h1:kAStDd1p9tlSQeNyAAmb7vrPL2UCz7LFTzw5LdbGxBI=
|
||||
github.com/Monibuca/engine/v3 v3.0.0-alpha4/go.mod h1:V0/kfen6K5O/RLXHPsZj4DF/LboDZ0OqfeCfn35bWMo=
|
||||
github.com/Monibuca/engine/v3 v3.0.0-alpha5 h1:sXLg39SBkeiVkGcbcinXuRrYyClJvMVirxA5axiUD7s=
|
||||
github.com/Monibuca/engine/v3 v3.0.0-alpha5/go.mod h1:V0/kfen6K5O/RLXHPsZj4DF/LboDZ0OqfeCfn35bWMo=
|
||||
github.com/Monibuca/engine/v3 v3.0.0-alpha6 h1:USZa+JDVJd13rb9wmX06ZxjRCrqYTAPe5wVD+0IODEE=
|
||||
github.com/Monibuca/engine/v3 v3.0.0-alpha6/go.mod h1:V0/kfen6K5O/RLXHPsZj4DF/LboDZ0OqfeCfn35bWMo=
|
||||
github.com/Monibuca/plugin-rtp v0.0.0-20200531014802-504413c0dfcb h1:CnmoQ8XsWxs/6mulbQfTGUa8cPr6c/3bkkTsNozRBwE=
|
||||
github.com/Monibuca/plugin-rtp v0.0.0-20200531014802-504413c0dfcb/go.mod h1:8HxBilkF835Lepe/DLUCjaw1mRiu3MxTDsG7g9UcfZA=
|
||||
github.com/Monibuca/plugin-rtp v1.0.0 h1:yksNsIIGxoKX8UZirkAUK+mGZ/XoEeS2vqbIqtqXyCg=
|
||||
github.com/Monibuca/plugin-rtp v1.0.0/go.mod h1:0xkNm23a/BjVnEMz1zXyOqfEjoVmGe3PJqPNF1KyFGc=
|
||||
github.com/Monibuca/utils/v3 v3.0.0-alpha4 h1:pecYA89kWmtGOeY6R99d4T1epPJ1wc+jFrrJY13VD04=
|
||||
github.com/Monibuca/engine/v3 v3.0.0-beta3 h1:/co+L2qCRZUq55S0LtYpY9xzOJiUUG3VGytYGFf1RD4=
|
||||
github.com/Monibuca/engine/v3 v3.0.0-beta3/go.mod h1:SMgnlwih4pBA/HkTLjKXZFYkv3ukRzFjv65CARRLVIk=
|
||||
github.com/Monibuca/engine/v3 v3.0.0-beta5 h1:b27ZQDfvf5dBMZbCSIUXItUwVIFs95fpkAV4xjN7BNE=
|
||||
github.com/Monibuca/engine/v3 v3.0.0-beta5/go.mod h1:SMgnlwih4pBA/HkTLjKXZFYkv3ukRzFjv65CARRLVIk=
|
||||
github.com/Monibuca/utils/v3 v3.0.0-alpha4/go.mod h1:3xYmhQbgAZBHLyIMteUCd1va+1z/xnd72B585mCaT3c=
|
||||
github.com/Monibuca/utils/v3 v3.0.0-alpha5 h1:IOyW/KJSRdRg+TPcgwkHLBynqfNQOV6p3iP7LgXEMFc=
|
||||
github.com/Monibuca/utils/v3 v3.0.0-alpha5/go.mod h1:3xYmhQbgAZBHLyIMteUCd1va+1z/xnd72B585mCaT3c=
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/Monibuca/utils/v3 v3.0.0-beta h1:z4p/BSH5J9Ja/gwoDmj1RyN+b0q28Nmn/fqXiwq2hGY=
|
||||
github.com/Monibuca/utils/v3 v3.0.0-beta/go.mod h1:mQYP/OMox1tkWP6Qut7pBfARr1TXSRkK662dexQl6kI=
|
||||
github.com/funny/slab v0.0.0-20180511031532-b1fad5e5d478 h1:Db9StoJ6RZN3YttC0Pm0I4Y5izITRYch3RMbT59BYN0=
|
||||
github.com/funny/slab v0.0.0-20180511031532-b1fad5e5d478/go.mod h1:0j1+svBH8ABEIPdUP0AIg4qedsybnXGJBakCEw8cfoo=
|
||||
github.com/funny/utest v0.0.0-20161029064919-43870a374500 h1:Z0r1CZnoIWFB/Uiwh1BU5FYmuFe6L5NPi6XWQEmsTRg=
|
||||
github.com/funny/utest v0.0.0-20161029064919-43870a374500/go.mod h1:mUn39tBov9jKnTWV1RlOYoNzxdBFHiSzXWdY1FoNGGg=
|
||||
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
|
||||
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
|
||||
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381 h1:bqDmpDG49ZRnB5PcgP0RXtQvnMSgIF14M7CBd2shtXs=
|
||||
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
||||
github.com/mask-pp/rtp-ps v1.0.0 h1:JFxuJL9N+gD1ldgJlAy3b7rYfY8wAVHi9ODNmdP4+EE=
|
||||
github.com/mask-pp/rtp-ps v1.0.0/go.mod h1:jCxsZ2G7z/jX+aqFypEWMePnhNrfnUiXUEKm6Xp0vgU=
|
||||
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
|
||||
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw=
|
||||
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
|
||||
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/pion/randutil v0.0.0 h1:aLWLVhTG2jzoD25F0OlW6nXvXrjoGwiXq2Sz7j7NzL0=
|
||||
github.com/pion/randutil v0.0.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
|
||||
github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
|
||||
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
|
||||
github.com/pion/rtp v1.5.4 h1:PuNg6xqV3brIUihatcKZj1YDUs+M45L0ZbrZWYtkDxY=
|
||||
github.com/pion/rtp v1.5.4/go.mod h1:bg60AL5GotNOlYZsqycbhDtEV3TkfbpXG0KBiUq29Mg=
|
||||
github.com/pion/rtp v1.6.0 h1:4Ssnl/T5W2LzxHj9ssYpGVEQh3YYhQFNVmSWO88MMwk=
|
||||
github.com/pion/rtp v1.6.0/go.mod h1:QgfogHsMBVE/RFNno467U/KBqfUywEH+HK+0rtnwsdI=
|
||||
github.com/pion/rtp v1.6.2 h1:iGBerLX6JiDjB9NXuaPzHyxHFG9JsIEdgwTC0lp5n/U=
|
||||
github.com/pion/rtp v1.6.2/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
|
||||
github.com/pion/rtp v1.6.5 h1:o2cZf8OascA5HF/b0PAbTxRKvOWxTQxWYt7SlToxFGI=
|
||||
github.com/pion/rtp v1.6.5/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/shirou/gopsutil v2.20.1+incompatible h1:oIq9Cq4i84Hk8uQAUOG3eNdI/29hBawGrD5YRl6JRDY=
|
||||
github.com/shirou/gopsutil v2.20.1+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/shirou/gopsutil v2.20.7+incompatible h1:Ymv4OD12d6zm+2yONe39VSmp2XooJe8za7ngOLW/o/w=
|
||||
github.com/shirou/gopsutil v2.20.7+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/shirou/gopsutil v3.21.1+incompatible h1:2LwXWdbjXwyDgq26Yy/OT4xozlpmssQfy/rtfhWb0bY=
|
||||
github.com/shirou/gopsutil v3.21.1+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf h1:Z2X3Os7oRzpdJ75iPqWZc0HeJWFYNCvKsfpQwFpRNTA=
|
||||
github.com/teris-io/shortid v0.0.0-20171029131806-771a37caa5cf/go.mod h1:M8agBzgqHIhgj7wEn9/0hJUZcrvt9VY+Ln+S1I5Mha0=
|
||||
github.com/q191201771/naza v0.19.1 h1:4KLcxT2CHztO+7miPRtBG3FFgadSQYQw1gPPPKN7rnY=
|
||||
github.com/q191201771/naza v0.19.1/go.mod h1:5LeGupZZFtYP1g/S203n9vXoUNVdlRnPIfM6rExjqt0=
|
||||
github.com/teris-io/shortid v0.0.0-20201117134242-e59966efd125 h1:3SNcvBmEPE1YlB1JpVZouslJpI3GBNoiqW7+wb0Rz7w=
|
||||
github.com/teris-io/shortid v0.0.0-20201117134242-e59966efd125/go.mod h1:M8agBzgqHIhgj7wEn9/0hJUZcrvt9VY+Ln+S1I5Mha0=
|
||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs=
|
||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200828161417-c663848e9a16 h1:54u1berWyLujz9htI1BHtZpcCEYaYNUSDFLXMNDd7To=
|
||||
golang.org/x/sys v0.0.0-20200828161417-c663848e9a16/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210217105451-b926d437f341 h1:2/QtM1mL37YmcsT8HaDNHDgTqqFVw+zr8UzMiBVLzYU=
|
||||
golang.org/x/sys v0.0.0-20210217105451-b926d437f341/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43 h1:SgQ6LNaYJU0JIuEHv9+s6EbhSCwYeAf5Yvj6lpYlqAE=
|
||||
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
golang.org/x/sys v0.0.0-20210611083646-a4fc73990273 h1:faDu4veV+8pcThn4fewv6TVlNCezafGoC1gM/mxQLbQ=
|
||||
golang.org/x/sys v0.0.0-20210611083646-a4fc73990273/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
|
27
main.go
27
main.go
@@ -6,7 +6,6 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -75,12 +74,12 @@ func runPlugin() {
|
||||
if config.ListenAddr != "" {
|
||||
go log.Fatal(ListenRtsp(config.ListenAddr))
|
||||
}
|
||||
AddHook(HOOK_SUBSCRIBE, func(value interface{}) {
|
||||
s := value.(*Subscriber)
|
||||
if config.AutoPull && s.Publisher == nil {
|
||||
new(RTSP).PullStream(s.StreamPath, strings.Replace(config.RemoteAddr, "${streamPath}", s.StreamPath, -1))
|
||||
}
|
||||
})
|
||||
// AddHook(HOOK_SUBSCRIBE, func(value interface{}) {
|
||||
// s := value.(*Subscriber)
|
||||
// if config.AutoPull && s.Publisher == nil {
|
||||
// new(RTSP).PullStream(s.StreamPath, strings.Replace(config.RemoteAddr, "${streamPath}", s.StreamPath, -1))
|
||||
// }
|
||||
// })
|
||||
}
|
||||
|
||||
func ListenRtsp(addr string) error {
|
||||
@@ -129,7 +128,7 @@ func ListenRtsp(addr string) error {
|
||||
}
|
||||
|
||||
type RTSP struct {
|
||||
Publisher
|
||||
*Stream
|
||||
URL string
|
||||
SDPRaw string
|
||||
InBytes int
|
||||
@@ -159,21 +158,27 @@ type RTSP struct {
|
||||
Auth func(string) string `json:"-"`
|
||||
HasVideo bool
|
||||
HasAudio bool
|
||||
RtpAudio *RTPAudio
|
||||
RtpVideo *RTPVideo
|
||||
}
|
||||
|
||||
func (rtsp *RTSP) setAudioFormat(at *AudioTrack) {
|
||||
switch rtsp.ASdp.Codec {
|
||||
case "aac":
|
||||
at.SoundFormat = 10
|
||||
at.CodecID = 10
|
||||
case "pcma":
|
||||
at.SoundFormat = 7
|
||||
at.CodecID = 7
|
||||
at.SoundRate = rtsp.ASdp.TimeScale
|
||||
at.SoundSize = 16
|
||||
case "pcmu":
|
||||
at.SoundFormat = 8
|
||||
at.CodecID = 8
|
||||
at.SoundRate = rtsp.ASdp.TimeScale
|
||||
at.SoundSize = 16
|
||||
default:
|
||||
Printf("rtsp audio codec not support:%s", rtsp.ASdp.Codec)
|
||||
return
|
||||
}
|
||||
rtsp.AudioTracks.AddTrack(rtsp.ASdp.Codec, at)
|
||||
}
|
||||
|
||||
type RTSPClientInfo struct {
|
||||
|
59
session.go
59
session.go
@@ -114,43 +114,42 @@ func (session *RTSP) AcceptPush() {
|
||||
}
|
||||
channel := int(buf1)
|
||||
rtpLen := int(binary.BigEndian.Uint16(buf2))
|
||||
pack := new(RTPPack)
|
||||
rtpBytes := make([]byte, rtpLen)
|
||||
if _, err := io.ReadFull(session.connRW, rtpBytes); err != nil {
|
||||
Println(err)
|
||||
return
|
||||
}
|
||||
if err = pack.Unmarshal(rtpBytes); err != nil {
|
||||
Println(err)
|
||||
return
|
||||
}
|
||||
t := pack.Timestamp / 90
|
||||
Println(t,pack.SequenceNumber)
|
||||
|
||||
// t := pack.Timestamp / 90
|
||||
switch channel {
|
||||
case session.aRTPChannel:
|
||||
pack.Type = RTP_TYPE_AUDIO
|
||||
elapsed := time.Now().Sub(timer)
|
||||
// pack.Type = RTP_TYPE_AUDIO
|
||||
elapsed := time.Since(timer)
|
||||
if elapsed >= 30*time.Second {
|
||||
Println("Recv an audio RTP package")
|
||||
timer = time.Now()
|
||||
}
|
||||
for _, payload := range codec.ParseRTPAAC(pack.Payload) {
|
||||
session.OriginAudioTrack.Push(t, payload)
|
||||
if session.RtpAudio.CodecID == 10 {
|
||||
for _, payload := range codec.ParseRTPAAC(rtpBytes) {
|
||||
session.RtpAudio.Push(payload)
|
||||
}
|
||||
} else {
|
||||
session.RtpAudio.Push(rtpBytes)
|
||||
}
|
||||
case session.aRTPControlChannel:
|
||||
pack.Type = RTP_TYPE_AUDIOCONTROL
|
||||
// pack.Type = RTP_TYPE_AUDIOCONTROL
|
||||
case session.vRTPChannel:
|
||||
pack.Type = RTP_TYPE_VIDEO
|
||||
elapsed := time.Now().Sub(timer)
|
||||
// pack.Type = RTP_TYPE_VIDEO
|
||||
elapsed := time.Since(timer)
|
||||
if elapsed >= 30*time.Second {
|
||||
Println("Recv an video RTP package")
|
||||
timer = time.Now()
|
||||
}
|
||||
session.OriginVideoTrack.Push(VideoPack{Timestamp: t, Payload: pack.Payload})
|
||||
session.RtpVideo.Push(rtpBytes)
|
||||
case session.vRTPControlChannel:
|
||||
pack.Type = RTP_TYPE_VIDEOCONTROL
|
||||
// pack.Type = RTP_TYPE_VIDEOCONTROL
|
||||
default:
|
||||
Printf("unknow rtp pack type, %v", pack.Type)
|
||||
// Printf("unknow rtp pack type, %v", pack.Type)
|
||||
continue
|
||||
}
|
||||
session.InBytes += rtpLen + 4
|
||||
@@ -335,28 +334,30 @@ func (session *RTSP) handleRequest(req *Request) {
|
||||
|
||||
session.SDPRaw = req.Body
|
||||
session.SDPMap = ParseSDP(req.Body)
|
||||
if session.Publish(streamPath) {
|
||||
stream := &Stream{
|
||||
StreamPath: streamPath,
|
||||
Type: "RTSP",
|
||||
}
|
||||
session.Stream = stream
|
||||
if session.Publish() {
|
||||
if session.ASdp, session.HasAudio = session.SDPMap["audio"]; session.HasAudio {
|
||||
at := NewAudioTrack()
|
||||
session.RtpAudio = stream.NewRTPAudio(0)
|
||||
at := session.RtpAudio.AudioTrack
|
||||
if len(session.ASdp.Control) > 0 {
|
||||
at.SetASC(session.ASdp.Config)
|
||||
} else {
|
||||
session.setAudioFormat(at)
|
||||
}
|
||||
session.SetOriginAT(at)
|
||||
Printf("audio codec[%s]\n", session.ASdp.Codec)
|
||||
}
|
||||
if session.VSdp, session.HasVideo = session.SDPMap["video"]; session.HasVideo {
|
||||
if len(session.VSdp.SpropParameterSets) > 1 {
|
||||
vt := NewVideoTrack()
|
||||
vt.CodecID = 7
|
||||
var pack VideoPack
|
||||
pack.Payload = session.VSdp.SpropParameterSets[0]
|
||||
vt.Push(pack)
|
||||
pack.Payload = session.VSdp.SpropParameterSets[1]
|
||||
vt.Push(pack)
|
||||
vt.SPSInfo, err = codec.ParseSPS(vt.SPS)
|
||||
session.SetOriginVT(vt)
|
||||
session.RtpVideo = stream.NewRTPVideo(7)
|
||||
session.RtpVideo.PushNalu(VideoPack{NALUs: session.VSdp.SpropParameterSets})
|
||||
} else if session.VSdp.Codec == "H264" {
|
||||
session.RtpVideo = stream.NewRTPVideo(7)
|
||||
} else if session.VSdp.Codec == "H265" {
|
||||
session.RtpVideo = stream.NewRTPVideo(12)
|
||||
}
|
||||
Printf("video codec[%s]\n", session.VSdp.Codec)
|
||||
}
|
||||
|
@@ -25,19 +25,6 @@ func (s *UDPServer) AddInputBytes(bytes int) {
|
||||
panic(fmt.Errorf("session and RTSPClient both nil"))
|
||||
}
|
||||
|
||||
func (s *UDPServer) HandleRTP(pack RTPPack) {
|
||||
if s.Session != nil {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
switch pack.Type {
|
||||
case RTP_TYPE_AUDIO:
|
||||
s.Session.OriginAudioTrack.PushRTP(pack.Packet)
|
||||
case RTP_TYPE_VIDEO:
|
||||
s.Session.OriginVideoTrack.PushRTP(pack.Packet)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *UDPServer) Stop() {
|
||||
if s.Stoped {
|
||||
return
|
||||
@@ -96,11 +83,7 @@ func (s *UDPServer) SetupAudio() (err error) {
|
||||
timer = time.Now()
|
||||
}
|
||||
s.AddInputBytes(n)
|
||||
pack := RTPPack{
|
||||
Type: RTP_TYPE_AUDIO,
|
||||
}
|
||||
pack.Unmarshal(bufUDP[:n])
|
||||
s.HandleRTP(pack)
|
||||
s.Session.RtpAudio.Push(bufUDP[:n])
|
||||
} else {
|
||||
Println("udp server read audio pack error", err)
|
||||
continue
|
||||
@@ -135,11 +118,11 @@ func (s *UDPServer) SetupAudio() (err error) {
|
||||
if n, _, err := s.AControlConn.ReadFromUDP(bufUDP); err == nil {
|
||||
//Printf("Package recv from AControlConn.len:%d\n", n)
|
||||
s.AddInputBytes(n)
|
||||
pack := RTPPack{
|
||||
Type: RTP_TYPE_AUDIOCONTROL,
|
||||
}
|
||||
pack.Unmarshal(bufUDP[:n])
|
||||
s.HandleRTP(pack)
|
||||
// pack := RTPPack{
|
||||
// Type: RTP_TYPE_AUDIOCONTROL,
|
||||
// }
|
||||
// pack.Unmarshal(bufUDP[:n])
|
||||
// s.HandleRTP(pack)
|
||||
} else {
|
||||
Println("udp server read audio control pack error", err)
|
||||
continue
|
||||
@@ -184,11 +167,7 @@ func (s *UDPServer) SetupVideo() (err error) {
|
||||
timer = time.Now()
|
||||
}
|
||||
s.AddInputBytes(n)
|
||||
pack := RTPPack{
|
||||
Type: RTP_TYPE_VIDEO,
|
||||
}
|
||||
pack.Unmarshal(bufUDP[:n])
|
||||
s.HandleRTP(pack)
|
||||
s.Session.RtpVideo.Push(bufUDP[:n])
|
||||
} else {
|
||||
Println("udp server read video pack error", err)
|
||||
continue
|
||||
@@ -224,11 +203,11 @@ func (s *UDPServer) SetupVideo() (err error) {
|
||||
if n, _, err := s.VControlConn.ReadFromUDP(bufUDP); err == nil {
|
||||
//Printf("Package recv from VControlConn.len:%d\n", n)
|
||||
s.AddInputBytes(n)
|
||||
pack := RTPPack{
|
||||
Type: RTP_TYPE_VIDEOCONTROL,
|
||||
}
|
||||
pack.Unmarshal(bufUDP[:n])
|
||||
s.HandleRTP(pack)
|
||||
// pack := RTPPack{
|
||||
// Type: RTP_TYPE_VIDEOCONTROL,
|
||||
// }
|
||||
// pack.Unmarshal(bufUDP[:n])
|
||||
// s.HandleRTP(pack)
|
||||
} else {
|
||||
Println("udp server read video control pack error", err)
|
||||
continue
|
||||
|
Reference in New Issue
Block a user