暂时修复向远程推流

This commit is contained in:
dexter
2022-05-10 15:30:14 +08:00
parent 4a0da71ee9
commit 91e1726920

View File

@@ -67,6 +67,20 @@ type RTSPPusher struct {
gortsplib.Transport gortsplib.Transport
} }
func (p *RTSPPusher) OnEvent(event any) {
switch v := event.(type) {
case *engine.AudioFrame:
for _, pack := range v.RTP {
p.Client.WritePacketRTP(p.audioTrackId, &pack.Packet)
}
case *engine.VideoFrame:
for _, pack := range v.RTP {
p.Client.WritePacketRTP(p.videoTrackId, &pack.Packet)
}
default:
p.RTSPSubscriber.OnEvent(event)
}
}
func (p *RTSPPusher) Connect() error { func (p *RTSPPusher) Connect() error {
if p.Transport == gortsplib.TransportTCP { if p.Transport == gortsplib.TransportTCP {
p.Transport = gortsplib.TransportUDP p.Transport = gortsplib.TransportUDP
@@ -86,7 +100,8 @@ func (p *RTSPPusher) Connect() error {
if err = p.Client.Start(u.Scheme, u.Host); err != nil { if err = p.Client.Start(u.Scheme, u.Host); err != nil {
return err return err
} }
return nil _, err = p.Client.Options(u)
return err
} }
func (p *RTSPPusher) Push() (err error) { func (p *RTSPPusher) Push() (err error) {
var u *base.URL var u *base.URL
@@ -97,9 +112,8 @@ func (p *RTSPPusher) Push() (err error) {
} }
}() }()
startTime := time.Now() startTime := time.Now()
for p.tracks == nil { for len(p.tracks) < 2 {
time.Sleep(time.Millisecond * 100) if time.Sleep(time.Second); time.Since(startTime) > time.Second*10 {
if time.Since(startTime) > time.Second*5 {
return fmt.Errorf("timeout") return fmt.Errorf("timeout")
} }
} }