使用内置的协议自动选择机制

This commit is contained in:
langhuihui
2023-04-15 08:48:44 +08:00
parent 225bb482d5
commit a4773b4044
2 changed files with 12 additions and 21 deletions

View File

@@ -10,23 +10,11 @@ import (
type RTSPPuller struct { type RTSPPuller struct {
RTSPPublisher RTSPPublisher
engine.Puller engine.Puller
*gortsplib.Client `json:"-"` *gortsplib.Client `json:"-" yaml:"-"`
gortsplib.Transport gortsplib.Transport
} }
func (p *RTSPPuller) Connect() error { func (p *RTSPPuller) Connect() error {
switch rtspConfig.PullProtocol {
case "tcp", "TCP":
p.Transport = gortsplib.TransportTCP
case "udp", "UDP":
p.Transport = gortsplib.TransportUDP
default:
if p.Transport == gortsplib.TransportTCP {
p.Transport = gortsplib.TransportUDP
} else {
p.Transport = gortsplib.TransportTCP
}
}
p.Client = &gortsplib.Client{ p.Client = &gortsplib.Client{
// OnPacketRTP: func(ctx *gortsplib.ClientOnPacketRTPCtx) { // OnPacketRTP: func(ctx *gortsplib.ClientOnPacketRTPCtx) {
// if p.RTSPPublisher.Tracks[ctx.TrackID] != nil { // if p.RTSPPublisher.Tracks[ctx.TrackID] != nil {
@@ -34,9 +22,16 @@ func (p *RTSPPuller) Connect() error {
// } // }
// }, // },
ReadBufferCount: rtspConfig.ReadBufferSize, ReadBufferCount: rtspConfig.ReadBufferSize,
Transport: &p.Transport,
} }
switch rtspConfig.PullProtocol {
case "tcp", "TCP":
p.Transport = gortsplib.TransportTCP
p.Client.Transport = &p.Transport
case "udp", "UDP":
p.Transport = gortsplib.TransportUDP
p.Client.Transport = &p.Transport
}
// parse URL // parse URL
u, err := url.Parse(p.RemoteURL) u, err := url.Parse(p.RemoteURL)
if err != nil { if err != nil {
@@ -100,14 +95,8 @@ func (p *RTSPPusher) OnEvent(event any) {
} }
} }
func (p *RTSPPusher) Connect() error { func (p *RTSPPusher) Connect() error {
if p.Transport == gortsplib.TransportTCP {
p.Transport = gortsplib.TransportUDP
} else {
p.Transport = gortsplib.TransportTCP
}
p.Client = &gortsplib.Client{ p.Client = &gortsplib.Client{
ReadBufferCount: rtspConfig.ReadBufferSize, ReadBufferCount: rtspConfig.ReadBufferSize,
Transport: &p.Transport,
} }
// parse URL // parse URL
u, err := url.Parse(p.RemoteURL) u, err := url.Parse(p.RemoteURL)

View File

@@ -13,7 +13,7 @@ import (
type RTSPPublisher struct { type RTSPPublisher struct {
Publisher Publisher
Tracks map[*media.Media]common.AVTrack `json:"-"` Tracks map[*media.Media]common.AVTrack `json:"-" yaml:"-"`
RTSPIO RTSPIO
} }
@@ -86,9 +86,11 @@ func (p *RTSPPublisher) SetTracks() error {
} }
if p.VideoTrack == nil { if p.VideoTrack == nil {
p.Config.PubVideo = false p.Config.PubVideo = false
p.Info("no video track")
} }
if p.AudioTrack == nil { if p.AudioTrack == nil {
p.Config.PubAudio = false p.Config.PubAudio = false
p.Info("no audio track")
} }
return nil return nil
} }