mirror of https://bitbucket.org/ausocean/av.git
protocol/rtcp: using defer where I can
This commit is contained in:
parent
f66a94543a
commit
881ddc3d38
|
@ -243,11 +243,9 @@ func (c *client) UpdateSequence(s uint32) {
|
|||
|
||||
// highestSequence will return the highest sequence number received through RTP.
|
||||
func (c *client) highestSequence() uint32 {
|
||||
var s uint32
|
||||
c.mu.Lock()
|
||||
s = c.sequence
|
||||
c.mu.Unlock()
|
||||
return s
|
||||
defer c.mu.Unlock()
|
||||
return c.sequence
|
||||
}
|
||||
|
||||
// jitter returns the interarrival jitter as described by RTCP specifications:
|
||||
|
@ -259,34 +257,30 @@ 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 {
|
||||
var ts uint32
|
||||
c.mu.Lock()
|
||||
ts = binary.BigEndian.Uint32(c.senderTs[2:])
|
||||
c.mu.Unlock()
|
||||
return ts
|
||||
defer c.mu.Unlock()
|
||||
return binary.BigEndian.Uint32(c.senderTs[2:])
|
||||
}
|
||||
|
||||
// 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 {
|
||||
var receiveTime time.Time
|
||||
c.mu.Lock()
|
||||
receiveTime = c.receiveTime
|
||||
c.mu.Unlock()
|
||||
defer c.mu.Unlock()
|
||||
now := time.Now()
|
||||
return uint32(now.Sub(receiveTime).Seconds() / delayUnit)
|
||||
return uint32(now.Sub(c.receiveTime).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()
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ func Timestamp(buf []byte) (msw, lsw uint32, err error) {
|
|||
if len(buf) < 4 {
|
||||
return 0, 0, errors.New("bad RTCP packet, not of sufficient length")
|
||||
}
|
||||
if (buf[0]&0xc0)>>6 != rtpVer {
|
||||
if (buf[0]&0xc0)>>6 != rtcpVer {
|
||||
return 0, 0, errors.New("incompatible RTCP version")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue