mirror of
https://github.com/aler9/gortsplib
synced 2025-10-07 16:10:59 +08:00
add ConnClient.LoopUDP()
This commit is contained in:
@@ -22,6 +22,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
clientReadBufferSize = 4096
|
clientReadBufferSize = 4096
|
||||||
clientWriteBufferSize = 4096
|
clientWriteBufferSize = 4096
|
||||||
|
clientTcpKeepalivePeriod = 30 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
// Track is a track available in a certain URL.
|
// Track is a track available in a certain URL.
|
||||||
@@ -403,3 +404,19 @@ func (c *ConnClient) Play(u *url.URL) (*Response, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoopUDP is called after setupping UDP tracks and calling Play(); it keeps
|
||||||
|
// the TCP connection open through keepalives, and returns when the TCP
|
||||||
|
// connection closes.
|
||||||
|
func (c *ConnClient) LoopUDP(u *url.URL) (error) {
|
||||||
|
keepaliveTicker := time.NewTicker(clientTcpKeepalivePeriod)
|
||||||
|
defer keepaliveTicker.Stop()
|
||||||
|
|
||||||
|
for {
|
||||||
|
<- keepaliveTicker.C
|
||||||
|
_, err := c.Options(u)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -67,21 +67,6 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
done := make(chan struct{})
|
|
||||||
|
|
||||||
// send periodic keepalive
|
|
||||||
go func() {
|
|
||||||
keepaliveTicker := time.NewTicker(30 * time.Second)
|
|
||||||
for range keepaliveTicker.C {
|
|
||||||
_, err = rconn.Options(u)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("connection is closed")
|
|
||||||
close(done)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// receive RTP packets
|
// receive RTP packets
|
||||||
for trackId, l := range rtpListeners {
|
for trackId, l := range rtpListeners {
|
||||||
go func(trackId int, l net.PacketConn) {
|
go func(trackId int, l net.PacketConn) {
|
||||||
@@ -112,5 +97,5 @@ func main() {
|
|||||||
}(trackId, l)
|
}(trackId, l)
|
||||||
}
|
}
|
||||||
|
|
||||||
<-done
|
panic(rconn.LoopUDP(u))
|
||||||
}
|
}
|
||||||
|
2
utils.go
2
utils.go
@@ -40,7 +40,7 @@ const (
|
|||||||
// StreamTypeRtp means that the stream contains RTP packets
|
// StreamTypeRtp means that the stream contains RTP packets
|
||||||
StreamTypeRtp StreamType = iota + 1
|
StreamTypeRtp StreamType = iota + 1
|
||||||
|
|
||||||
// StreamTypeRtp means that the stream contains RTCP packets
|
// StreamTypeRtcp means that the stream contains RTCP packets
|
||||||
StreamTypeRtcp
|
StreamTypeRtcp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user