protocol/rtcp/client.go: not using defer for simple setters/getters

This commit is contained in:
Saxon 2019-04-17 07:41:31 +09:30
parent 881ddc3d38
commit d34eabcd34
1 changed files with 11 additions and 9 deletions

View File

@ -244,8 +244,9 @@ func (c *client) UpdateSequence(s uint32) {
// highestSequence will return the highest sequence number received through RTP.
func (c *client) highestSequence() uint32 {
c.mu.Lock()
defer c.mu.Unlock()
return c.sequence
s := c.sequence
c.mu.Unlock()
return s
}
// jitter returns the interarrival jitter as described by RTCP specifications:
@ -257,30 +258,31 @@ func (c *client) jitter() uint32 {
// setSenderTs allows us to safely set the current sender report timestamp.
func (c *client) setSenderTs(msw, lsw uint32) {
c.mu.Lock()
defer c.mu.Unlock()
binary.BigEndian.PutUint32(c.senderTs[:], msw)
binary.BigEndian.PutUint32(c.senderTs[4:], lsw)
c.mu.Unlock()
}
// lastSenderTs returns the timestamp of the most recent sender report.
func (c *client) lastSenderTs() uint32 {
c.mu.Lock()
defer c.mu.Unlock()
return binary.BigEndian.Uint32(c.senderTs[2:])
t := binary.BigEndian.Uint32(c.senderTs[2:])
c.mu.Unlock()
return t
}
// delay returns the duration between the receive time of the last sender report
// and now. This is called when forming a receiver report.
func (c *client) delay() uint32 {
c.mu.Lock()
defer c.mu.Unlock()
now := time.Now()
return uint32(now.Sub(c.receiveTime).Seconds() / delayUnit)
t := c.receiveTime
c.mu.Unlock()
return uint32(time.Now().Sub(t).Seconds() / delayUnit)
}
// received is called when a sender report is received to mark the receive time.
func (c *client) received() {
c.mu.Lock()
defer c.mu.Unlock()
c.receiveTime = time.Now()
c.mu.Unlock()
}