feat: push use tcp default

This commit is contained in:
langhuihui
2023-10-27 09:52:19 +08:00
parent 3e4dcdf649
commit 2a62472b1d
3 changed files with 14 additions and 6 deletions

View File

@@ -116,6 +116,8 @@ func (p *RTSPPusher) Connect() error {
DialContext: p.DialContext,
WriteQueueSize: rtspConfig.WriteBufferCount,
}
p.Transport = gortsplib.TransportTCP
p.Client.Transport = &p.Transport
// parse URL
u, err := url.Parse(p.RemoteURL)
if err != nil {
@@ -143,9 +145,12 @@ func (p *RTSPPusher) Push() (err error) {
// return fmt.Errorf("timeout")
// }
// }
if _, err = p.Announce(u, p.session); err != nil {
var res *base.Response
if res, err = p.Announce(u, p.session); err != nil {
p.Error("Announce", zap.Error(err))
return
} else {
p.Debug("Announce", zap.Any("res", res))
}
err = p.SetupAll(u, p.session.Medias)
if err != nil {
@@ -153,9 +158,11 @@ func (p *RTSPPusher) Push() (err error) {
return
}
if _, err = p.Record(); err != nil {
if res, err = p.Record(); err != nil {
p.Error("Record", zap.Error(err))
return
} else {
p.Debug("Record", zap.Any("res", res))
}
p.PlayRTP()
return

View File

@@ -49,9 +49,9 @@ func (conf *RTSPConfig) OnEvent(event any) {
}
}
case SEpublish:
if url, ok := conf.PushList[v.Target.Path]; ok {
if err := RTSPPlugin.Push(v.Target.Path, url, new(RTSPPusher), false); err != nil {
RTSPPlugin.Error("push", zap.String("streamPath", v.Target.Path), zap.String("url", url), zap.Error(err))
if remoteURL := conf.CheckPush(v.Target.Path); remoteURL != "" {
if err := RTSPPlugin.Push(v.Target.Path, remoteURL, new(RTSPPusher), false); err != nil {
RTSPPlugin.Error("push", zap.String("streamPath", v.Target.Path), zap.String("url", remoteURL), zap.Error(err))
}
}
case InvitePublish: //按需拉流

View File

@@ -39,7 +39,7 @@ func (conf *RTSPConfig) OnSessionClose(ctx *gortsplib.ServerHandlerOnSessionClos
// called after receiving a DESCRIBE request.
func (conf *RTSPConfig) OnDescribe(ctx *gortsplib.ServerHandlerOnDescribeCtx) (*base.Response, *gortsplib.ServerStream, error) {
RTSPPlugin.Debug("describe request")
RTSPPlugin.Debug("describe request", zap.String("sdp", string(ctx.Request.Body)))
var suber RTSPSubscriber
suber.server = conf.server
suber.RemoteAddr = ctx.Conn.NetConn().RemoteAddr().String()
@@ -100,6 +100,7 @@ func (conf *RTSPConfig) OnRecord(ctx *gortsplib.ServerHandlerOnRecordCtx) (*base
}, nil
}
func (conf *RTSPConfig) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (*base.Response, error) {
RTSPPlugin.Debug("annouce request", zap.String("sdp", string(ctx.Request.Body)))
p := &RTSPPublisher{}
p.SetIO(ctx.Conn.NetConn())
if err := RTSPPlugin.Publish(ctx.Path, p); err == nil {