mirror of
https://github.com/Monibuca/plugin-rtsp.git
synced 2025-09-27 12:02:20 +08:00
暂时修复向远程推流
This commit is contained in:
22
client.go
22
client.go
@@ -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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user