@@ -15,6 +15,7 @@ func TestConvertTWCC(t *testing.T) {
1515 ts time.Time
1616 feedback * rtcp.TransportLayerCC
1717 expect map [uint32 ]acknowledgementList
18+ expectTS time.Time
1819 }{
1920 {},
2021 {
@@ -24,26 +25,27 @@ func TestConvertTWCC(t *testing.T) {
2425 MediaSSRC : 2 ,
2526 BaseSequenceNumber : 178 ,
2627 PacketStatusCount : 0 ,
27- ReferenceTime : 0 ,
28+ ReferenceTime : 3 ,
2829 FbPktCount : 0 ,
2930 PacketChunks : []rtcp.PacketStatusChunk {},
3031 RecvDeltas : []* rtcp.RecvDelta {},
3132 },
3233 expect : map [uint32 ]acknowledgementList {
33- 2 : {
34+ 0 : {
3435 ts : timeZero .Add (2 * time .Second ),
35- acks : [] acknowledgement {} ,
36+ acks : nil ,
3637 },
3738 },
39+ expectTS : time.Time {}.Add (3 * 64 * time .Millisecond ),
3840 },
3941 {
4042 ts : timeZero .Add (2 * time .Second ),
4143 feedback : & rtcp.TransportLayerCC {
4244 SenderSSRC : 1 ,
4345 MediaSSRC : 2 ,
4446 BaseSequenceNumber : 178 ,
45- PacketStatusCount : 3 ,
46- ReferenceTime : 0 ,
47+ PacketStatusCount : 18 ,
48+ ReferenceTime : 3 ,
4749 FbPktCount : 0 ,
4850 PacketChunks : []rtcp.PacketStatusChunk {
4951 & rtcp.RunLengthChunk {
@@ -77,38 +79,38 @@ func TestConvertTWCC(t *testing.T) {
7779 },
7880 },
7981 RecvDeltas : []* rtcp.RecvDelta {
80- {Type : rtcp .TypeTCCPacketReceivedSmallDelta , Delta : 0 },
81- {Type : rtcp .TypeTCCPacketReceivedSmallDelta , Delta : 0 },
82- {Type : rtcp .TypeTCCPacketReceivedSmallDelta , Delta : 0 },
83- {Type : rtcp .TypeTCCPacketReceivedSmallDelta , Delta : 0 },
84- {Type : rtcp .TypeTCCPacketReceivedSmallDelta , Delta : 0 },
85- {Type : rtcp .TypeTCCPacketReceivedSmallDelta , Delta : 0 },
86- {Type : rtcp .TypeTCCPacketReceivedLargeDelta , Delta : 0 },
87- {Type : rtcp .TypeTCCPacketReceivedLargeDelta , Delta : 0 },
82+ {Type : rtcp .TypeTCCPacketReceivedSmallDelta , Delta : 1000 },
83+ {Type : rtcp .TypeTCCPacketReceivedSmallDelta , Delta : 1000 },
84+ {Type : rtcp .TypeTCCPacketReceivedSmallDelta , Delta : 1000 },
85+ {Type : rtcp .TypeTCCPacketReceivedSmallDelta , Delta : 1000 },
86+ {Type : rtcp .TypeTCCPacketReceivedSmallDelta , Delta : 1000 },
87+ {Type : rtcp .TypeTCCPacketReceivedSmallDelta , Delta : 1000 },
88+ {Type : rtcp .TypeTCCPacketReceivedLargeDelta , Delta : 1000 },
89+ {Type : rtcp .TypeTCCPacketReceivedLargeDelta , Delta : 1000 },
8890 },
8991 },
9092 expect : map [uint32 ]acknowledgementList {
91- 2 : {
93+ 0 : {
9294 ts : timeZero .Add (2 * time .Second ),
9395 acks : []acknowledgement {
9496 // first run length chunk
95- {seqNr : 178 , arrived : true , arrival : time.Time {}, ecn : 0 },
96- {seqNr : 179 , arrived : true , arrival : time.Time {}, ecn : 0 },
97- {seqNr : 180 , arrived : true , arrival : time.Time {}, ecn : 0 },
97+ {seqNr : 178 , arrived : true , arrival : time.Time {}. Add ( 3 * 64 * time . Millisecond + 1 * time . Millisecond ) , ecn : 0 },
98+ {seqNr : 179 , arrived : true , arrival : time.Time {}. Add ( 3 * 64 * time . Millisecond + 2 * time . Millisecond ) , ecn : 0 },
99+ {seqNr : 180 , arrived : true , arrival : time.Time {}. Add ( 3 * 64 * time . Millisecond + 3 * time . Millisecond ) , ecn : 0 },
98100
99101 // first status vector chunk
100- {seqNr : 181 , arrived : true , arrival : time.Time {}, ecn : 0 },
101- {seqNr : 182 , arrived : true , arrival : time.Time {}, ecn : 0 },
102- {seqNr : 183 , arrived : true , arrival : time.Time {}, ecn : 0 },
102+ {seqNr : 181 , arrived : true , arrival : time.Time {}. Add ( 3 * 64 * time . Millisecond + 4 * time . Millisecond ) , ecn : 0 },
103+ {seqNr : 182 , arrived : true , arrival : time.Time {}. Add ( 3 * 64 * time . Millisecond + 5 * time . Millisecond ) , ecn : 0 },
104+ {seqNr : 183 , arrived : true , arrival : time.Time {}. Add ( 3 * 64 * time . Millisecond + 6 * time . Millisecond ) , ecn : 0 },
103105 {seqNr : 184 , arrived : false , arrival : time.Time {}, ecn : 0 },
104106 {seqNr : 185 , arrived : false , arrival : time.Time {}, ecn : 0 },
105107 {seqNr : 186 , arrived : false , arrival : time.Time {}, ecn : 0 },
106108 {seqNr : 187 , arrived : false , arrival : time.Time {}, ecn : 0 },
107109 {seqNr : 188 , arrived : false , arrival : time.Time {}, ecn : 0 },
108110
109111 // second status vector chunk
110- {seqNr : 189 , arrived : true , arrival : time.Time {}, ecn : 0 },
111- {seqNr : 190 , arrived : true , arrival : time.Time {}, ecn : 0 },
112+ {seqNr : 189 , arrived : true , arrival : time.Time {}. Add ( 3 * 64 * time . Millisecond + 7 * time . Millisecond ) , ecn : 0 },
113+ {seqNr : 190 , arrived : true , arrival : time.Time {}. Add ( 3 * 64 * time . Millisecond + 8 * time . Millisecond ) , ecn : 0 },
112114 {seqNr : 191 , arrived : false , arrival : time.Time {}, ecn : 0 },
113115 {seqNr : 192 , arrived : false , arrival : time.Time {}, ecn : 0 },
114116 {seqNr : 193 , arrived : false , arrival : time.Time {}, ecn : 0 },
@@ -117,24 +119,14 @@ func TestConvertTWCC(t *testing.T) {
117119 },
118120 },
119121 },
122+ expectTS : time.Time {}.Add (3 * 64 * time .Millisecond ),
120123 },
121124 }
122125 for i , tc := range cases {
123126 t .Run (fmt .Sprintf ("%v" , i ), func (t * testing.T ) {
124- res := convertTWCC (tc .ts , tc .feedback )
125-
126- // Can't directly check equality since arrival timestamp conversions
127- // may be slightly off due to ntp conversions.
128- assert .Equal (t , len (tc .expect ), len (res ))
129- for i , ee := range tc .expect {
130- assert .Equal (t , ee .ts , res [i ].ts )
131- for j , ack := range ee .acks {
132- assert .Equal (t , ack .seqNr , res [i ].acks [j ].seqNr )
133- assert .Equal (t , ack .arrived , res [i ].acks [j ].arrived )
134- assert .Equal (t , ack .ecn , res [i ].acks [j ].ecn )
135- assert .InDelta (t , ack .arrival .UnixNano (), res [i ].acks [j ].arrival .UnixNano (), float64 (time .Millisecond .Nanoseconds ()))
136- }
137- }
127+ resTS , res := convertTWCC (tc .ts , tc .feedback )
128+ assert .Equal (t , tc .expect , res )
129+ assert .Equal (t , tc .expectTS , resTS )
138130 })
139131 }
140132
0 commit comments