Reduce packet meta data cache - part 1 (#2073)
* Reduce packet meta data cache - part 1 Packet meta data cache takes a good amount of space. That cache is 8K entries deep and each entry is 8 bytes. So, that takes 64KB per RTP stream. It is mostly needed for down stream to line up with receiver reports. So, removing cache from up stream (RTPStatsReceiver) as part 1. Will look at optimising the down stream in part 2. * Remove caching from RTPStatsReceiver * clean up a bit more * maintain history and fix test
This commit is contained in:
@@ -51,14 +51,14 @@ type RTPStatsSender struct {
|
||||
maxJitterFromRR float64
|
||||
|
||||
nextSenderSnapshotID uint32
|
||||
senderSnapshots map[uint32]*senderSnapshot
|
||||
senderSnapshots []senderSnapshot
|
||||
}
|
||||
|
||||
func NewRTPStatsSender(params RTPStatsParams) *RTPStatsSender {
|
||||
return &RTPStatsSender{
|
||||
rtpStatsBase: newRTPStatsBase(params),
|
||||
nextSenderSnapshotID: cFirstSnapshotID,
|
||||
senderSnapshots: make(map[uint32]*senderSnapshot),
|
||||
senderSnapshots: make([]senderSnapshot, 2),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,10 +86,8 @@ func (r *RTPStatsSender) Seed(from *RTPStatsSender) {
|
||||
r.maxJitterFromRR = from.maxJitterFromRR
|
||||
|
||||
r.nextSenderSnapshotID = from.nextSenderSnapshotID
|
||||
for id, ss := range from.senderSnapshots {
|
||||
ssCopy := *ss
|
||||
r.senderSnapshots[id] = &ssCopy
|
||||
}
|
||||
r.senderSnapshots = make([]senderSnapshot, cap(from.senderSnapshots))
|
||||
copy(r.senderSnapshots, from.senderSnapshots)
|
||||
}
|
||||
|
||||
func (r *RTPStatsSender) NewSnapshotId() uint32 {
|
||||
@@ -104,12 +102,17 @@ func (r *RTPStatsSender) NewSenderSnapshotId() uint32 {
|
||||
defer r.lock.Unlock()
|
||||
|
||||
id := r.nextSenderSnapshotID
|
||||
r.nextSenderSnapshotID++
|
||||
|
||||
if cap(r.senderSnapshots) < int(r.nextSenderSnapshotID) {
|
||||
senderSnapshots := make([]senderSnapshot, r.nextSenderSnapshotID)
|
||||
copy(senderSnapshots, r.senderSnapshots)
|
||||
r.senderSnapshots = senderSnapshots
|
||||
}
|
||||
|
||||
if r.initialized {
|
||||
r.senderSnapshots[id] = &senderSnapshot{
|
||||
snapshot: snapshot{
|
||||
startTime: time.Now(),
|
||||
extStartSN: r.extStartSN,
|
||||
},
|
||||
r.senderSnapshots[id] = senderSnapshot{
|
||||
snapshot: r.initSnapshot(time.Now(), r.extStartSN),
|
||||
extStartSNFromRR: r.extStartSN,
|
||||
}
|
||||
}
|
||||
@@ -153,14 +156,16 @@ func (r *RTPStatsSender) Update(
|
||||
|
||||
// initialize snapshots if any
|
||||
for i := uint32(cFirstSnapshotID); i < r.nextSnapshotID; i++ {
|
||||
r.snapshots[i] = &snapshot{
|
||||
r.snapshots[i] = snapshot{
|
||||
isValid: true,
|
||||
startTime: r.startTime,
|
||||
extStartSN: r.extStartSN,
|
||||
}
|
||||
}
|
||||
for i := uint32(cFirstSnapshotID); i < r.nextSenderSnapshotID; i++ {
|
||||
r.senderSnapshots[i] = &senderSnapshot{
|
||||
r.senderSnapshots[i] = senderSnapshot{
|
||||
snapshot: snapshot{
|
||||
isValid: true,
|
||||
startTime: r.startTime,
|
||||
extStartSN: r.extStartSN,
|
||||
},
|
||||
@@ -580,39 +585,23 @@ func (r *RTPStatsSender) getAndResetSenderSnapshot(senderSnapshotID uint32) (*se
|
||||
}
|
||||
|
||||
then := r.senderSnapshots[senderSnapshotID]
|
||||
if then == nil {
|
||||
then = &senderSnapshot{
|
||||
snapshot: snapshot{
|
||||
startTime: r.startTime,
|
||||
extStartSN: r.extStartSN,
|
||||
},
|
||||
if !then.isValid {
|
||||
then = senderSnapshot{
|
||||
snapshot: r.initSnapshot(r.startTime, r.extStartSN),
|
||||
extStartSNFromRR: r.extStartSN,
|
||||
}
|
||||
r.senderSnapshots[senderSnapshotID] = then
|
||||
}
|
||||
|
||||
// snapshot now
|
||||
r.senderSnapshots[senderSnapshotID] = &senderSnapshot{
|
||||
snapshot: snapshot{
|
||||
startTime: r.lastRRTime,
|
||||
extStartSN: r.extHighestSN + 1,
|
||||
packetsDuplicate: r.packetsDuplicate,
|
||||
bytesDuplicate: r.bytesDuplicate,
|
||||
headerBytesDuplicate: r.headerBytesDuplicate,
|
||||
nacks: r.nacks,
|
||||
plis: r.plis,
|
||||
firs: r.firs,
|
||||
maxJitter: r.jitter,
|
||||
maxRtt: r.rtt,
|
||||
},
|
||||
now := senderSnapshot{
|
||||
snapshot: r.getSnapshot(r.lastRRTime, r.extHighestSN+1),
|
||||
extStartSNFromRR: r.extHighestSNFromRR + (r.extStartSN & 0xFFFF_FFFF_FFFF_0000) + 1,
|
||||
packetsLostFromRR: r.packetsLostFromRR,
|
||||
maxJitterFromRR: r.jitterFromRR,
|
||||
}
|
||||
// make a copy so that it can be used independently
|
||||
now := *r.senderSnapshots[senderSnapshotID]
|
||||
|
||||
return then, &now
|
||||
r.senderSnapshots[senderSnapshotID] = now
|
||||
return &then, &now
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user