mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 23:26:54 +08:00
client: do not send sender / receiver reports when using TCP
This commit is contained in:
35
client.go
35
client.go
@@ -187,8 +187,8 @@ type Client struct {
|
|||||||
// private
|
// private
|
||||||
//
|
//
|
||||||
|
|
||||||
senderReportPeriod time.Duration
|
udpSenderReportPeriod time.Duration
|
||||||
receiverReportPeriod time.Duration
|
udpReceiverReportPeriod time.Duration
|
||||||
|
|
||||||
scheme string
|
scheme string
|
||||||
host string
|
host string
|
||||||
@@ -211,7 +211,7 @@ type Client struct {
|
|||||||
tcpWriteMutex sync.Mutex // tcp
|
tcpWriteMutex sync.Mutex // tcp
|
||||||
writeMutex sync.RWMutex // write
|
writeMutex sync.RWMutex // write
|
||||||
writeFrameAllowed bool // write
|
writeFrameAllowed bool // write
|
||||||
reportTimer *time.Timer
|
udpReportTimer *time.Timer
|
||||||
checkStreamTimer *time.Timer
|
checkStreamTimer *time.Timer
|
||||||
checkStreamInitial bool
|
checkStreamInitial bool
|
||||||
tcpLastFrameTime int64
|
tcpLastFrameTime int64
|
||||||
@@ -279,11 +279,11 @@ func (c *Client) Start(scheme string, host string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// private
|
// private
|
||||||
if c.senderReportPeriod == 0 {
|
if c.udpSenderReportPeriod == 0 {
|
||||||
c.senderReportPeriod = 10 * time.Second
|
c.udpSenderReportPeriod = 10 * time.Second
|
||||||
}
|
}
|
||||||
if c.receiverReportPeriod == 0 {
|
if c.udpReceiverReportPeriod == 0 {
|
||||||
c.receiverReportPeriod = 10 * time.Second
|
c.udpReceiverReportPeriod = 10 * time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, ctxCancel := context.WithCancel(context.Background())
|
ctx, ctxCancel := context.WithCancel(context.Background())
|
||||||
@@ -292,7 +292,7 @@ func (c *Client) Start(scheme string, host string) error {
|
|||||||
c.host = host
|
c.host = host
|
||||||
c.ctx = ctx
|
c.ctx = ctx
|
||||||
c.ctxCancel = ctxCancel
|
c.ctxCancel = ctxCancel
|
||||||
c.reportTimer = emptyTimer()
|
c.udpReportTimer = emptyTimer()
|
||||||
c.checkStreamTimer = emptyTimer()
|
c.checkStreamTimer = emptyTimer()
|
||||||
c.keepaliveTimer = emptyTimer()
|
c.keepaliveTimer = emptyTimer()
|
||||||
c.options = make(chan optionsReq)
|
c.options = make(chan optionsReq)
|
||||||
@@ -469,7 +469,7 @@ func (c *Client) run() {
|
|||||||
res, err := c.doPause()
|
res, err := c.doPause()
|
||||||
req.res <- clientRes{res: res, err: err}
|
req.res <- clientRes{res: res, err: err}
|
||||||
|
|
||||||
case <-c.reportTimer.C:
|
case <-c.udpReportTimer.C:
|
||||||
if c.state == clientStatePlay {
|
if c.state == clientStatePlay {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
for trackID, cct := range c.tracks {
|
for trackID, cct := range c.tracks {
|
||||||
@@ -477,7 +477,7 @@ func (c *Client) run() {
|
|||||||
c.WritePacketRTCP(trackID, rr)
|
c.WritePacketRTCP(trackID, rr)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.reportTimer = time.NewTimer(c.receiverReportPeriod)
|
c.udpReportTimer = time.NewTimer(c.udpReceiverReportPeriod)
|
||||||
} else { // Record
|
} else { // Record
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
for trackID, cct := range c.tracks {
|
for trackID, cct := range c.tracks {
|
||||||
@@ -487,7 +487,7 @@ func (c *Client) run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.reportTimer = time.NewTimer(c.senderReportPeriod)
|
c.udpReportTimer = time.NewTimer(c.udpSenderReportPeriod)
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-c.checkStreamTimer.C:
|
case <-c.checkStreamTimer.C:
|
||||||
@@ -684,15 +684,16 @@ func (c *Client) playRecordStart() {
|
|||||||
|
|
||||||
// start timers
|
// start timers
|
||||||
if c.state == clientStatePlay {
|
if c.state == clientStatePlay {
|
||||||
c.reportTimer = time.NewTimer(c.receiverReportPeriod)
|
|
||||||
c.keepaliveTimer = time.NewTimer(clientKeepalivePeriod)
|
c.keepaliveTimer = time.NewTimer(clientKeepalivePeriod)
|
||||||
|
|
||||||
switch *c.protocol {
|
switch *c.protocol {
|
||||||
case TransportUDP:
|
case TransportUDP:
|
||||||
|
c.udpReportTimer = time.NewTimer(c.udpReceiverReportPeriod)
|
||||||
c.checkStreamTimer = time.NewTimer(c.InitialUDPReadTimeout)
|
c.checkStreamTimer = time.NewTimer(c.InitialUDPReadTimeout)
|
||||||
c.checkStreamInitial = true
|
c.checkStreamInitial = true
|
||||||
|
|
||||||
case TransportUDPMulticast:
|
case TransportUDPMulticast:
|
||||||
|
c.udpReportTimer = time.NewTimer(c.udpReceiverReportPeriod)
|
||||||
c.checkStreamTimer = time.NewTimer(clientCheckStreamPeriod)
|
c.checkStreamTimer = time.NewTimer(clientCheckStreamPeriod)
|
||||||
|
|
||||||
default: // TCP
|
default: // TCP
|
||||||
@@ -700,7 +701,13 @@ func (c *Client) playRecordStart() {
|
|||||||
c.tcpLastFrameTime = time.Now().Unix()
|
c.tcpLastFrameTime = time.Now().Unix()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c.reportTimer = time.NewTimer(c.senderReportPeriod)
|
switch *c.protocol {
|
||||||
|
case TransportUDP:
|
||||||
|
c.udpReportTimer = time.NewTimer(c.udpSenderReportPeriod)
|
||||||
|
|
||||||
|
case TransportUDPMulticast:
|
||||||
|
c.udpReportTimer = time.NewTimer(c.udpSenderReportPeriod)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for some reason, SetReadDeadline() must always be called in the same
|
// for some reason, SetReadDeadline() must always be called in the same
|
||||||
@@ -785,7 +792,7 @@ func (c *Client) playRecordStop(isClosing bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// stop timers
|
// stop timers
|
||||||
c.reportTimer = emptyTimer()
|
c.udpReportTimer = emptyTimer()
|
||||||
c.checkStreamTimer = emptyTimer()
|
c.checkStreamTimer = emptyTimer()
|
||||||
c.keepaliveTimer = emptyTimer()
|
c.keepaliveTimer = emptyTimer()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user