适配引擎版本升级

This commit is contained in:
langhuihui
2021-06-15 08:06:40 +08:00
parent d08230bf0c
commit b0c3cdb21a
6 changed files with 92 additions and 165 deletions

View File

@@ -18,13 +18,15 @@ import (
. "github.com/Monibuca/engine/v3" . "github.com/Monibuca/engine/v3"
. "github.com/Monibuca/utils/v3" . "github.com/Monibuca/utils/v3"
"github.com/pion/rtp"
) )
// PullStream 从外部拉流 // PullStream 从外部拉流
func (rtsp *RTSP) PullStream(streamPath string, rtspUrl string) (err error) { func (rtsp *RTSP) PullStream(streamPath string, rtspUrl string) (err error) {
if result := rtsp.Publish(streamPath); result { rtsp.Stream = &Stream{
rtsp.Stream.Type = "RTSP" StreamPath: streamPath,
Type: "RTSP Pull",
}
if result := rtsp.Publish(); result {
rtsp.TransType = TRANS_TYPE_TCP rtsp.TransType = TRANS_TYPE_TCP
rtsp.vRTPChannel = 0 rtsp.vRTPChannel = 0
rtsp.vRTPControlChannel = 1 rtsp.vRTPControlChannel = 1
@@ -217,14 +219,12 @@ func (client *RTSP) requestStream() (err error) {
switch t { switch t {
case "video": case "video":
if len(sdpInfo.SpropParameterSets) > 1 { if len(sdpInfo.SpropParameterSets) > 1 {
vt := NewVideoTrack() client.RtpVideo = client.NewRTPVideo(7)
vt.CodecID = 7 client.RtpVideo.PushNalu(VideoPack{NALUs: sdpInfo.SpropParameterSets})
var pack VideoPack } else if client.VSdp.Codec == "H264" {
pack.Payload = sdpInfo.SpropParameterSets[0] client.RtpVideo = client.NewRTPVideo(7)
vt.Push(pack) } else if client.VSdp.Codec == "H265" {
pack.Payload = sdpInfo.SpropParameterSets[1] client.RtpVideo = client.NewRTPVideo(12)
vt.Push(pack)
client.SetOriginVT(vt)
} }
if client.TransType == TRANS_TYPE_TCP { if client.TransType == TRANS_TYPE_TCP {
headers["Transport"] = fmt.Sprintf("RTP/AVP/TCP;unicast;interleaved=%d-%d", client.vRTPChannel, client.vRTPControlChannel) 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 client.Conn.timeout = 0 // UDP ignore timeout
} }
case "audio": case "audio":
at := NewAudioTrack() client.RtpAudio = client.NewRTPAudio(0)
if len(sdpInfo.Config) > 0 { at := client.RtpAudio.AudioTrack
at.SetASC(sdpInfo.Config) if len(client.ASdp.Control) > 0 {
at.SetASC(client.ASdp.Config)
} else { } else {
client.setAudioFormat(at) client.setAudioFormat(at)
} }
client.SetOriginAT(at)
if client.TransType == TRANS_TYPE_TCP { if client.TransType == TRANS_TYPE_TCP {
headers["Transport"] = fmt.Sprintf("RTP/AVP/TCP;unicast;interleaved=%d-%d", client.aRTPChannel, client.aRTPControlChannel) headers["Transport"] = fmt.Sprintf("RTP/AVP/TCP;unicast;interleaved=%d-%d", client.aRTPChannel, client.aRTPControlChannel)
} else { } else {
@@ -339,15 +339,14 @@ func (client *RTSP) startStream() {
Printf("io.ReadFull err:%v", err) Printf("io.ReadFull err:%v", err)
return return
} }
var pack rtp.Packet
pack.Unmarshal(content)
switch channel { switch channel {
case client.aRTPChannel: case client.aRTPChannel:
client.OriginAudioTrack.PushRTP(pack) client.RtpAudio.Push(content)
case client.aRTPControlChannel: case client.aRTPControlChannel:
case client.vRTPChannel: case client.vRTPChannel:
client.OriginVideoTrack.PushRTP(pack) client.RtpVideo.Push(content)
case client.vRTPControlChannel: case client.vRTPControlChannel:
default: default:

10
go.mod
View File

@@ -3,11 +3,9 @@ module github.com/Monibuca/plugin-rtsp/v3
go 1.16 go 1.16
require ( require (
github.com/Monibuca/engine/v3 v3.0.0-alpha6 github.com/Monibuca/engine/v3 v3.0.0-beta5
github.com/Monibuca/utils/v3 v3.0.0-alpha5 github.com/Monibuca/utils/v3 v3.0.0-beta
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect github.com/pion/rtp v1.6.5
github.com/pion/rtp v1.6.2
github.com/shirou/gopsutil v3.21.1+incompatible // indirect
github.com/teris-io/shortid v0.0.0-20201117134242-e59966efd125 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
View File

@@ -1,98 +1,43 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 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 h1:USZa+JDVJd13rb9wmX06ZxjRCrqYTAPe5wVD+0IODEE=
github.com/Monibuca/engine/v3 v3.0.0-alpha6/go.mod h1:V0/kfen6K5O/RLXHPsZj4DF/LboDZ0OqfeCfn35bWMo= 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/engine/v3 v3.0.0-beta3 h1:/co+L2qCRZUq55S0LtYpY9xzOJiUUG3VGytYGFf1RD4=
github.com/Monibuca/plugin-rtp v0.0.0-20200531014802-504413c0dfcb/go.mod h1:8HxBilkF835Lepe/DLUCjaw1mRiu3MxTDsG7g9UcfZA= github.com/Monibuca/engine/v3 v3.0.0-beta3/go.mod h1:SMgnlwih4pBA/HkTLjKXZFYkv3ukRzFjv65CARRLVIk=
github.com/Monibuca/plugin-rtp v1.0.0 h1:yksNsIIGxoKX8UZirkAUK+mGZ/XoEeS2vqbIqtqXyCg= github.com/Monibuca/engine/v3 v3.0.0-beta5 h1:b27ZQDfvf5dBMZbCSIUXItUwVIFs95fpkAV4xjN7BNE=
github.com/Monibuca/plugin-rtp v1.0.0/go.mod h1:0xkNm23a/BjVnEMz1zXyOqfEjoVmGe3PJqPNF1KyFGc= github.com/Monibuca/engine/v3 v3.0.0-beta5/go.mod h1:SMgnlwih4pBA/HkTLjKXZFYkv3ukRzFjv65CARRLVIk=
github.com/Monibuca/utils/v3 v3.0.0-alpha4 h1:pecYA89kWmtGOeY6R99d4T1epPJ1wc+jFrrJY13VD04=
github.com/Monibuca/utils/v3 v3.0.0-alpha4/go.mod h1:3xYmhQbgAZBHLyIMteUCd1va+1z/xnd72B585mCaT3c= 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 h1:IOyW/KJSRdRg+TPcgwkHLBynqfNQOV6p3iP7LgXEMFc=
github.com/Monibuca/utils/v3 v3.0.0-alpha5/go.mod h1:3xYmhQbgAZBHLyIMteUCd1va+1z/xnd72B585mCaT3c= 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/Monibuca/utils/v3 v3.0.0-beta h1:z4p/BSH5J9Ja/gwoDmj1RyN+b0q28Nmn/fqXiwq2hGY=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/Monibuca/utils/v3 v3.0.0-beta/go.mod h1:mQYP/OMox1tkWP6Qut7pBfARr1TXSRkK662dexQl6kI=
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/funny/slab v0.0.0-20180511031532-b1fad5e5d478 h1:Db9StoJ6RZN3YttC0Pm0I4Y5izITRYch3RMbT59BYN0= 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/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 h1:Z0r1CZnoIWFB/Uiwh1BU5FYmuFe6L5NPi6XWQEmsTRg=
github.com/funny/utest v0.0.0-20161029064919-43870a374500/go.mod h1:mUn39tBov9jKnTWV1RlOYoNzxdBFHiSzXWdY1FoNGGg= 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 h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= 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 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= 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 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 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 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8= 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 h1:iGBerLX6JiDjB9NXuaPzHyxHFG9JsIEdgwTC0lp5n/U=
github.com/pion/rtp v1.6.2/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko= 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 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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/q191201771/naza v0.19.1 h1:4KLcxT2CHztO+7miPRtBG3FFgadSQYQw1gPPPKN7rnY=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/q191201771/naza v0.19.1/go.mod h1:5LeGupZZFtYP1g/S203n9vXoUNVdlRnPIfM6rExjqt0=
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/teris-io/shortid v0.0.0-20201117134242-e59966efd125 h1:3SNcvBmEPE1YlB1JpVZouslJpI3GBNoiqW7+wb0Rz7w= 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= 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 h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 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-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-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 h1:SgQ6LNaYJU0JIuEHv9+s6EbhSCwYeAf5Yvj6lpYlqAE=
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 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= golang.org/x/sys v0.0.0-20210611083646-a4fc73990273 h1:faDu4veV+8pcThn4fewv6TVlNCezafGoC1gM/mxQLbQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= golang.org/x/sys v0.0.0-20210611083646-a4fc73990273/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

27
main.go
View File

@@ -6,7 +6,6 @@ import (
"log" "log"
"net" "net"
"net/http" "net/http"
"strings"
"sync" "sync"
"time" "time"
@@ -75,12 +74,12 @@ func runPlugin() {
if config.ListenAddr != "" { if config.ListenAddr != "" {
go log.Fatal(ListenRtsp(config.ListenAddr)) go log.Fatal(ListenRtsp(config.ListenAddr))
} }
AddHook(HOOK_SUBSCRIBE, func(value interface{}) { // AddHook(HOOK_SUBSCRIBE, func(value interface{}) {
s := value.(*Subscriber) // s := value.(*Subscriber)
if config.AutoPull && s.Publisher == nil { // if config.AutoPull && s.Publisher == nil {
new(RTSP).PullStream(s.StreamPath, strings.Replace(config.RemoteAddr, "${streamPath}", s.StreamPath, -1)) // new(RTSP).PullStream(s.StreamPath, strings.Replace(config.RemoteAddr, "${streamPath}", s.StreamPath, -1))
} // }
}) // })
} }
func ListenRtsp(addr string) error { func ListenRtsp(addr string) error {
@@ -129,7 +128,7 @@ func ListenRtsp(addr string) error {
} }
type RTSP struct { type RTSP struct {
Publisher *Stream
URL string URL string
SDPRaw string SDPRaw string
InBytes int InBytes int
@@ -159,21 +158,27 @@ type RTSP struct {
Auth func(string) string `json:"-"` Auth func(string) string `json:"-"`
HasVideo bool HasVideo bool
HasAudio bool HasAudio bool
RtpAudio *RTPAudio
RtpVideo *RTPVideo
} }
func (rtsp *RTSP) setAudioFormat(at *AudioTrack) { func (rtsp *RTSP) setAudioFormat(at *AudioTrack) {
switch rtsp.ASdp.Codec { switch rtsp.ASdp.Codec {
case "aac": case "aac":
at.SoundFormat = 10 at.CodecID = 10
case "pcma": case "pcma":
at.SoundFormat = 7 at.CodecID = 7
at.SoundRate = rtsp.ASdp.TimeScale at.SoundRate = rtsp.ASdp.TimeScale
at.SoundSize = 16 at.SoundSize = 16
case "pcmu": case "pcmu":
at.SoundFormat = 8 at.CodecID = 8
at.SoundRate = rtsp.ASdp.TimeScale at.SoundRate = rtsp.ASdp.TimeScale
at.SoundSize = 16 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 { type RTSPClientInfo struct {

View File

@@ -114,43 +114,42 @@ func (session *RTSP) AcceptPush() {
} }
channel := int(buf1) channel := int(buf1)
rtpLen := int(binary.BigEndian.Uint16(buf2)) rtpLen := int(binary.BigEndian.Uint16(buf2))
pack := new(RTPPack)
rtpBytes := make([]byte, rtpLen) rtpBytes := make([]byte, rtpLen)
if _, err := io.ReadFull(session.connRW, rtpBytes); err != nil { if _, err := io.ReadFull(session.connRW, rtpBytes); err != nil {
Println(err) Println(err)
return return
} }
if err = pack.Unmarshal(rtpBytes); err != nil {
Println(err) // t := pack.Timestamp / 90
return
}
t := pack.Timestamp / 90
Println(t,pack.SequenceNumber)
switch channel { switch channel {
case session.aRTPChannel: case session.aRTPChannel:
pack.Type = RTP_TYPE_AUDIO // pack.Type = RTP_TYPE_AUDIO
elapsed := time.Now().Sub(timer) elapsed := time.Since(timer)
if elapsed >= 30*time.Second { if elapsed >= 30*time.Second {
Println("Recv an audio RTP package") Println("Recv an audio RTP package")
timer = time.Now() timer = time.Now()
} }
for _, payload := range codec.ParseRTPAAC(pack.Payload) { if session.RtpAudio.CodecID == 10 {
session.OriginAudioTrack.Push(t, payload) for _, payload := range codec.ParseRTPAAC(rtpBytes) {
session.RtpAudio.Push(payload)
}
} else {
session.RtpAudio.Push(rtpBytes)
} }
case session.aRTPControlChannel: case session.aRTPControlChannel:
pack.Type = RTP_TYPE_AUDIOCONTROL // pack.Type = RTP_TYPE_AUDIOCONTROL
case session.vRTPChannel: case session.vRTPChannel:
pack.Type = RTP_TYPE_VIDEO // pack.Type = RTP_TYPE_VIDEO
elapsed := time.Now().Sub(timer) elapsed := time.Since(timer)
if elapsed >= 30*time.Second { if elapsed >= 30*time.Second {
Println("Recv an video RTP package") Println("Recv an video RTP package")
timer = time.Now() timer = time.Now()
} }
session.OriginVideoTrack.Push(VideoPack{Timestamp: t, Payload: pack.Payload}) session.RtpVideo.Push(rtpBytes)
case session.vRTPControlChannel: case session.vRTPControlChannel:
pack.Type = RTP_TYPE_VIDEOCONTROL // pack.Type = RTP_TYPE_VIDEOCONTROL
default: default:
Printf("unknow rtp pack type, %v", pack.Type) // Printf("unknow rtp pack type, %v", pack.Type)
continue continue
} }
session.InBytes += rtpLen + 4 session.InBytes += rtpLen + 4
@@ -335,28 +334,30 @@ func (session *RTSP) handleRequest(req *Request) {
session.SDPRaw = req.Body session.SDPRaw = req.Body
session.SDPMap = ParseSDP(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 { 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 { if len(session.ASdp.Control) > 0 {
at.SetASC(session.ASdp.Config) at.SetASC(session.ASdp.Config)
} else { } else {
session.setAudioFormat(at) session.setAudioFormat(at)
} }
session.SetOriginAT(at)
Printf("audio codec[%s]\n", session.ASdp.Codec) Printf("audio codec[%s]\n", session.ASdp.Codec)
} }
if session.VSdp, session.HasVideo = session.SDPMap["video"]; session.HasVideo { if session.VSdp, session.HasVideo = session.SDPMap["video"]; session.HasVideo {
if len(session.VSdp.SpropParameterSets) > 1 { if len(session.VSdp.SpropParameterSets) > 1 {
vt := NewVideoTrack() session.RtpVideo = stream.NewRTPVideo(7)
vt.CodecID = 7 session.RtpVideo.PushNalu(VideoPack{NALUs: session.VSdp.SpropParameterSets})
var pack VideoPack } else if session.VSdp.Codec == "H264" {
pack.Payload = session.VSdp.SpropParameterSets[0] session.RtpVideo = stream.NewRTPVideo(7)
vt.Push(pack) } else if session.VSdp.Codec == "H265" {
pack.Payload = session.VSdp.SpropParameterSets[1] session.RtpVideo = stream.NewRTPVideo(12)
vt.Push(pack)
vt.SPSInfo, err = codec.ParseSPS(vt.SPS)
session.SetOriginVT(vt)
} }
Printf("video codec[%s]\n", session.VSdp.Codec) Printf("video codec[%s]\n", session.VSdp.Codec)
} }

View File

@@ -25,19 +25,6 @@ func (s *UDPServer) AddInputBytes(bytes int) {
panic(fmt.Errorf("session and RTSPClient both nil")) 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() { func (s *UDPServer) Stop() {
if s.Stoped { if s.Stoped {
return return
@@ -96,11 +83,7 @@ func (s *UDPServer) SetupAudio() (err error) {
timer = time.Now() timer = time.Now()
} }
s.AddInputBytes(n) s.AddInputBytes(n)
pack := RTPPack{ s.Session.RtpAudio.Push(bufUDP[:n])
Type: RTP_TYPE_AUDIO,
}
pack.Unmarshal(bufUDP[:n])
s.HandleRTP(pack)
} else { } else {
Println("udp server read audio pack error", err) Println("udp server read audio pack error", err)
continue continue
@@ -135,11 +118,11 @@ func (s *UDPServer) SetupAudio() (err error) {
if n, _, err := s.AControlConn.ReadFromUDP(bufUDP); err == nil { if n, _, err := s.AControlConn.ReadFromUDP(bufUDP); err == nil {
//Printf("Package recv from AControlConn.len:%d\n", n) //Printf("Package recv from AControlConn.len:%d\n", n)
s.AddInputBytes(n) s.AddInputBytes(n)
pack := RTPPack{ // pack := RTPPack{
Type: RTP_TYPE_AUDIOCONTROL, // Type: RTP_TYPE_AUDIOCONTROL,
} // }
pack.Unmarshal(bufUDP[:n]) // pack.Unmarshal(bufUDP[:n])
s.HandleRTP(pack) // s.HandleRTP(pack)
} else { } else {
Println("udp server read audio control pack error", err) Println("udp server read audio control pack error", err)
continue continue
@@ -184,11 +167,7 @@ func (s *UDPServer) SetupVideo() (err error) {
timer = time.Now() timer = time.Now()
} }
s.AddInputBytes(n) s.AddInputBytes(n)
pack := RTPPack{ s.Session.RtpVideo.Push(bufUDP[:n])
Type: RTP_TYPE_VIDEO,
}
pack.Unmarshal(bufUDP[:n])
s.HandleRTP(pack)
} else { } else {
Println("udp server read video pack error", err) Println("udp server read video pack error", err)
continue continue
@@ -224,11 +203,11 @@ func (s *UDPServer) SetupVideo() (err error) {
if n, _, err := s.VControlConn.ReadFromUDP(bufUDP); err == nil { if n, _, err := s.VControlConn.ReadFromUDP(bufUDP); err == nil {
//Printf("Package recv from VControlConn.len:%d\n", n) //Printf("Package recv from VControlConn.len:%d\n", n)
s.AddInputBytes(n) s.AddInputBytes(n)
pack := RTPPack{ // pack := RTPPack{
Type: RTP_TYPE_VIDEOCONTROL, // Type: RTP_TYPE_VIDEOCONTROL,
} // }
pack.Unmarshal(bufUDP[:n]) // pack.Unmarshal(bufUDP[:n])
s.HandleRTP(pack) // s.HandleRTP(pack)
} else { } else {
Println("udp server read video control pack error", err) Println("udp server read video control pack error", err)
continue continue