Skip to content

Commit

Permalink
Add PacketsHeld to TWCC recorder
Browse files Browse the repository at this point in the history
When using `twcc.Recorder` outside the context of
`twcc.SenderInterceptor`, it is useful to have access to
the number of packets currently held. This enables writing
logic other than an interval to determine when to build
feedback packets.
  • Loading branch information
treyhakanson authored and davidzhao committed Aug 23, 2023
1 parent 0efb978 commit c37a592
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#
# This file is auto generated, using git to list all individuals contributors.
# see https://github.com/pion/.goassets/blob/master/scripts/generate-authors.sh for the scripting
Sean DuBois <[email protected]>
ziminghua <[email protected]>
Aaron Boushley <[email protected]>
Adam Kiss <[email protected]>
adamroach <[email protected]>
Expand All @@ -23,8 +25,8 @@ Quentin Renard <[email protected]>
Rayleigh Li <[email protected]>
Sean DuBois <[email protected]>
Steffen Vogel <[email protected]>
treyhakanson <[email protected]>
XLPolar <[email protected]>
ziminghua <[email protected]>

# List of contributors not appearing in Git history

5 changes: 5 additions & 0 deletions pkg/twcc/twcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func (r *Recorder) Record(mediaSSRC uint32, sequenceNumber uint16, arrivalTime i
r.lastSequenceNumber = sequenceNumber
}

// PacketsHeld returns the number of received packets currently held by the recorder
func (r *Recorder) PacketsHeld() int {
return len(r.receivedPackets)
}

func insertSorted(list []pktInfo, element pktInfo) []pktInfo {
if len(list) == 0 {
return append(list, element)
Expand Down
22 changes: 22 additions & 0 deletions pkg/twcc/twcc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,3 +940,25 @@ func TestInsertSorted(t *testing.T) {
})
}
}

func TestPacketsHheld(t *testing.T) {
r := NewRecorder(5000)
assert.Zero(t, r.PacketsHeld())

arrivalTime := int64(scaleFactorReferenceTime)
addRun(t, r, []uint16{0, 1, 2}, []int64{
arrivalTime,
increaseTime(&arrivalTime, rtcp.TypeTCCDeltaScaleFactor),
increaseTime(&arrivalTime, rtcp.TypeTCCDeltaScaleFactor),
})
assert.Equal(t, r.PacketsHeld(), 3)

addRun(t, r, []uint16{3, 4}, []int64{
increaseTime(&arrivalTime, rtcp.TypeTCCDeltaScaleFactor),
increaseTime(&arrivalTime, rtcp.TypeTCCDeltaScaleFactor),
})
assert.Equal(t, r.PacketsHeld(), 5)

r.BuildFeedbackPacket()
assert.Zero(t, r.PacketsHeld())
}

0 comments on commit c37a592

Please sign in to comment.