Skip to content

Commit

Permalink
Don't discarding if TWCC Generator isn't ready
Browse files Browse the repository at this point in the history
Instead return nil to the caller and don't modify
any internal state

Resolves #159
  • Loading branch information
Sean-Der committed Apr 25, 2023
1 parent 1075999 commit 81c3c2a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 9 deletions.
5 changes: 4 additions & 1 deletion AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Adam Kiss <[email protected]>
adamroach <[email protected]>
Aditya Kumar <[email protected]>
aler9 <[email protected]>
Antoine <[email protected]>
Antoine Baché <[email protected]>
Atsushi Watanabe <[email protected]>
Bobby Peck <[email protected]>
Expand All @@ -18,8 +17,12 @@ Jonathan Müller <[email protected]>
Kevin Caffrey <[email protected]>
Maksim Nesterov <[email protected]>
Mathis Engelbart <[email protected]>
Quentin Renard <[email protected]>
Rayleigh Li <[email protected]>
Sean <[email protected]>
Sean DuBois <[email protected]>
Steffen Vogel <[email protected]>
XLPolar <[email protected]>
ziminghua <[email protected]>

# List of contributors not appearing in Git history
Expand Down
7 changes: 3 additions & 4 deletions pkg/twcc/twcc.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,12 @@ func insertSorted(list []pktInfo, element pktInfo) []pktInfo {

// BuildFeedbackPacket creates a new RTCP packet containing a TWCC feedback report.
func (r *Recorder) BuildFeedbackPacket() []rtcp.Packet {
feedback := newFeedback(r.senderSSRC, r.mediaSSRC, r.fbPktCnt)
r.fbPktCnt++
if len(r.receivedPackets) < 2 {
r.receivedPackets = []pktInfo{}
return []rtcp.Packet{feedback.getRTCP()}
return nil
}

feedback := newFeedback(r.senderSSRC, r.mediaSSRC, r.fbPktCnt)
r.fbPktCnt++
feedback.setBase(uint16(r.receivedPackets[0].sequenceNumber&0xffff), r.receivedPackets[0].arrivalTime)

var pkts []rtcp.Packet
Expand Down
56 changes: 52 additions & 4 deletions pkg/twcc/twcc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,9 @@ func TestBuildFeedbackPacket_Rolling(t *testing.T) {
r := NewRecorder(5000)

arrivalTime := int64(scaleFactorReferenceTime)
addRun(t, r, []uint16{65535}, []int64{
addRun(t, r, []uint16{65534, 65535}, []int64{
arrivalTime,
increaseTime(&arrivalTime, rtcp.TypeTCCDeltaScaleFactor),
})

rtcpPackets := r.BuildFeedbackPacket()
Expand Down Expand Up @@ -482,7 +483,7 @@ func TestBuildFeedbackPacket_Rolling(t *testing.T) {
},
},
RecvDeltas: []*rtcp.RecvDelta{
{Type: rtcp.TypeTCCPacketReceivedSmallDelta, Delta: rtcp.TypeTCCDeltaScaleFactor},
{Type: rtcp.TypeTCCPacketReceivedSmallDelta, Delta: rtcp.TypeTCCDeltaScaleFactor * 2},
{Type: rtcp.TypeTCCPacketReceivedSmallDelta, Delta: rtcp.TypeTCCDeltaScaleFactor},
{Type: rtcp.TypeTCCPacketReceivedSmallDelta, Delta: rtcp.TypeTCCDeltaScaleFactor},
{Type: rtcp.TypeTCCPacketReceivedSmallDelta, Delta: rtcp.TypeTCCDeltaScaleFactor},
Expand All @@ -491,21 +492,68 @@ func TestBuildFeedbackPacket_Rolling(t *testing.T) {
marshalAll(t, rtcpPackets)
}

func TestBuildFeedbackPacketCount(t *testing.T) {
func TestBuildFeedbackPacket_MinInput(t *testing.T) {
r := NewRecorder(5000)

arrivalTime := int64(scaleFactorReferenceTime)
addRun(t, r, []uint16{0}, []int64{
arrivalTime,
})

pkts := r.BuildFeedbackPacket()
assert.Nil(t, pkts)

addRun(t, r, []uint16{1}, []int64{
increaseTime(&arrivalTime, rtcp.TypeTCCDeltaScaleFactor),
})

pkts = r.BuildFeedbackPacket()
assert.Equal(t, 1, len(pkts))

assert.Equal(t, &rtcp.TransportLayerCC{
Header: rtcp.Header{
Count: rtcp.FormatTCC,
Type: rtcp.TypeTransportSpecificFeedback,
Length: 5,
},
SenderSSRC: 5000,
MediaSSRC: 5000,
BaseSequenceNumber: 0,
ReferenceTime: 1,
FbPktCount: 0,
PacketStatusCount: 2,
PacketChunks: []rtcp.PacketStatusChunk{
&rtcp.RunLengthChunk{
PacketStatusSymbol: 1,
Type: rtcp.TypeTCCRunLengthChunk,
RunLength: 2,
},
},
RecvDeltas: []*rtcp.RecvDelta{
{Type: rtcp.TypeTCCPacketReceivedSmallDelta, Delta: 0},
{Type: rtcp.TypeTCCPacketReceivedSmallDelta, Delta: rtcp.TypeTCCDeltaScaleFactor},
},
}, rtcpToTwcc(t, pkts)[0])
marshalAll(t, pkts)
}

func TestBuildFeedbackPacketCount(t *testing.T) {
r := NewRecorder(5000)

arrivalTime := int64(scaleFactorReferenceTime)
addRun(t, r, []uint16{0, 1}, []int64{
arrivalTime,
arrivalTime,
})

pkts := r.BuildFeedbackPacket()
assert.Len(t, pkts, 1)

twcc := rtcpToTwcc(t, pkts)[0]
assert.Equal(t, uint8(0), twcc.FbPktCount)

addRun(t, r, []uint16{0}, []int64{
addRun(t, r, []uint16{0, 1}, []int64{
arrivalTime,
arrivalTime,
})

Expand Down

0 comments on commit 81c3c2a

Please sign in to comment.