mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
improve performance
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
bufferSize = 64
|
bufferSize = 64
|
||||||
negativeThreshold = 0xFFFF / 2
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Reorderer filters incoming RTP packets, in order to
|
// Reorderer filters incoming RTP packets, in order to
|
||||||
@@ -37,12 +36,12 @@ func (r *Reorderer) Process(pkt *rtp.Packet) ([]*rtp.Packet, int) {
|
|||||||
return []*rtp.Packet{pkt}, 0
|
return []*rtp.Packet{pkt}, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
relPos := pkt.SequenceNumber - r.expectedSeqNum
|
relPos := int16(pkt.SequenceNumber - r.expectedSeqNum)
|
||||||
|
|
||||||
// packet is a duplicate or has been sent
|
// packet is a duplicate or has been sent
|
||||||
// before the first packet processed by Reorderer.
|
// before the first packet processed by Reorderer.
|
||||||
// discard.
|
// discard.
|
||||||
if relPos > negativeThreshold {
|
if relPos < 0 {
|
||||||
r.negativeCount++
|
r.negativeCount++
|
||||||
|
|
||||||
// stream has been resetted, therefore reset reorderer too
|
// stream has been resetted, therefore reset reorderer too
|
||||||
@@ -94,7 +93,7 @@ func (r *Reorderer) Process(pkt *rtp.Packet) ([]*rtp.Packet, int) {
|
|||||||
|
|
||||||
// there's a missing packet
|
// there's a missing packet
|
||||||
if relPos != 0 {
|
if relPos != 0 {
|
||||||
p := (r.absPos + relPos) & (bufferSize - 1)
|
p := (r.absPos + uint16(relPos)) & (bufferSize - 1)
|
||||||
|
|
||||||
// current packet is a duplicate. discard
|
// current packet is a duplicate. discard
|
||||||
if r.buffer[p] != nil {
|
if r.buffer[p] != nil {
|
||||||
|
@@ -5,8 +5,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const negativeThreshold = 0xFFFFFFFF / 2
|
|
||||||
|
|
||||||
// avoid an int64 overflow and preserve resolution by splitting division into two parts:
|
// avoid an int64 overflow and preserve resolution by splitting division into two parts:
|
||||||
// first add the integer part, then the decimal part.
|
// first add the integer part, then the decimal part.
|
||||||
func multiplyAndDivide(v, m, d time.Duration) time.Duration {
|
func multiplyAndDivide(v, m, d time.Duration) time.Duration {
|
||||||
@@ -38,17 +36,9 @@ func (d *Decoder) Decode(ts uint32) time.Duration {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
diff := ts - d.prev
|
diff := int32(ts - d.prev)
|
||||||
|
|
||||||
// negative difference
|
|
||||||
if diff > negativeThreshold {
|
|
||||||
diff = d.prev - ts
|
|
||||||
d.prev = ts
|
|
||||||
d.overall -= time.Duration(diff)
|
|
||||||
} else {
|
|
||||||
d.prev = ts
|
d.prev = ts
|
||||||
d.overall += time.Duration(diff)
|
d.overall += time.Duration(diff)
|
||||||
}
|
|
||||||
|
|
||||||
return multiplyAndDivide(d.overall, time.Second, d.clockRate)
|
return multiplyAndDivide(d.overall, time.Second, d.clockRate)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user