Skip to content

Commit 74d9c59

Browse files
Add Transport Wide Congestion Control support (TWCC) reports and some bug fixes (#1331)
* fix stream retrieval bug RTC updates * add translations for tray app and installer * fix for ptz serialization use wyze camera name from url * fix bug in g722 codec * Only get stream format once Add timeout to ice gathering Add prefer H264 flag for compatible formats * revert * Optimise SendVideo and SendAudio (only get SendingFormat once) Add sanity check for ICE Gathering timeout * Optimise SendVideo and SendAudio (only get SendingFormat once) Add sanity check for ICE Gathering timeout Fix bug in g722 codec * remove turn folder * Remove turn folder * Move gather timeout to config * Fix rounding bug in SendAudioFrame Fix bug where duplicate durations were being added to local track timestamp in SendAudioFrame Ignore H264 formats that use unsupported packetization modes Clean up logic in AreMatch * remove comment marker * Check for null * Fix bug with HasVideo and HasAudio * Fix locking issue * fix lock * Fix stuttering on connect * Fix DtlsSrtpTransport bug * Fix issues with buffer over-runs * Add TWCC header extension support * Add support for TWCC Fix SDP parsing of audio m fields with ports Return null if stream not matched (was causing issues with RTP processing) Use PrimaryStream to unprotect incoming RTP packets Fix logic bug in SendRtpRaw Prevent some buffer over-reads var videoExtensions = new Dictionary<int, RTPHeaderExtension>(); videoExtensions.Add(extensionId, RTPHeaderExtension.GetRTPHeaderExtension(extensionId++, TransportWideCCExtension.RTP_HEADER_EXTENSION_URI, SDPMediaTypesEnum.video)); MediaStreamTrack videoTrack = new MediaStreamTrack(SDPMediaTypesEnum.video, false, formats.Select(x => new SDPAudioVideoMediaFormat(x)).ToList(), MediaStreamStatusEnum.SendOnly, null, videoExtensions ); in OnReceiveReport access rr.TWCCFeedback * Use feedback type parser * Add notes * Fix limit check * Fix issues with parsing TWCC packet parsing * ignore invalid chunkType * remove console.writeline * Update src/net/RTCP/RTCPCompoundPacket.cs Co-authored-by: Paulo Morgado <[email protected]> * Update src/net/RTCP/RTCPCompoundPacket.cs Co-authored-by: Paulo Morgado <[email protected]> * Update for code review * remove announcement portcount (move to new PR) * Add SRTP fallback * bug fix --------- Co-authored-by: Paulo Morgado <[email protected]>
1 parent 690cf2c commit 74d9c59

14 files changed

+845
-78
lines changed

src/net/RTCP/RTCPCompoundPacket.cs

+33-12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
using System;
1818
using System.Collections.Generic;
19+
using System.Diagnostics;
1920
using System.Linq;
2021
using System.Text;
2122
using Microsoft.Extensions.Logging;
@@ -39,6 +40,7 @@ public class RTCPCompoundPacket
3940
public RTCPSDesReport SDesReport { get; private set; }
4041
public RTCPBye Bye { get; set; }
4142
public RTCPFeedback Feedback { get; set; }
43+
public RTCPTWCCFeedback TWCCFeedback { get; set; }
4244

4345
protected internal RTCPCompoundPacket()
4446
{
@@ -99,12 +101,19 @@ public RTCPCompoundPacket(byte[] packet)
99101
offset += byeLength;
100102
break;
101103
case (byte)RTCPReportTypesEnum.RTPFB:
102-
// TODO: Interpret Generic RTP feedback reports.
103-
Feedback = new RTCPFeedback(buffer);
104-
int rtpfbFeedbackLength = (Feedback != null) ? Feedback.GetBytes().Length : Int32.MaxValue;
105-
offset += rtpfbFeedbackLength;
106-
//var rtpfbHeader = new RTCPHeader(buffer);
107-
//offset += rtpfbHeader.Length * 4 + 4;
104+
var typ = RTCPHeader.ParseFeedbackType(buffer);
105+
switch (typ) {
106+
case RTCPFeedbackTypesEnum.TWCC:
107+
TWCCFeedback = new RTCPTWCCFeedback(buffer);
108+
int twccFeedbackLength = (TWCCFeedback.Header.Length + 1) * 4;
109+
offset += twccFeedbackLength;
110+
break;
111+
default:
112+
Feedback = new RTCPFeedback(buffer);
113+
int rtpfbFeedbackLength = Feedback.GetBytes().Length;
114+
offset += rtpfbFeedbackLength;
115+
break;
116+
}
108117
break;
109118
case (byte)RTCPReportTypesEnum.PSFB:
110119
// TODO: Interpret Payload specific feedback reports.
@@ -255,12 +264,24 @@ public static bool TryParse(
255264
offset += byeLength;
256265
break;
257266
case (byte)RTCPReportTypesEnum.RTPFB:
258-
// TODO: Interpret Generic RTP feedback reports.
259-
rtcpCompoundPacket.Feedback = new RTCPFeedback(buffer);
260-
int rtpfbFeedbackLength = (rtcpCompoundPacket.Feedback != null) ? rtcpCompoundPacket.Feedback.GetBytes().Length : Int32.MaxValue;
261-
offset += rtpfbFeedbackLength;
262-
//var rtpfbHeader = new RTCPHeader(buffer);
263-
//offset += rtpfbHeader.Length * 4 + 4;
267+
var typ = RTCPHeader.ParseFeedbackType(buffer);
268+
switch (typ)
269+
{
270+
default:
271+
{
272+
rtcpCompoundPacket.Feedback = new RTCPFeedback(buffer);
273+
int rtpfbFeedbackLength = (rtcpCompoundPacket.Feedback != null) ? rtcpCompoundPacket.Feedback.GetBytes().Length : Int32.MaxValue;
274+
offset += rtpfbFeedbackLength;
275+
}
276+
break;
277+
case RTCPFeedbackTypesEnum.TWCC:
278+
{
279+
rtcpCompoundPacket.TWCCFeedback = new RTCPTWCCFeedback(buffer);
280+
int twccFeedbackLength = (rtcpCompoundPacket.TWCCFeedback != null) ? rtcpCompoundPacket.TWCCFeedback.GetBytes().Length : Int32.MaxValue;
281+
offset += twccFeedbackLength;
282+
}
283+
break;
284+
}
264285
break;
265286
case (byte)RTCPReportTypesEnum.PSFB:
266287
// TODO: Interpret Payload specific feedback reports.

src/net/RTCP/RTCPFeedback.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public enum RTCPFeedbackTypesEnum : int
4848
TLLEI = 7, // Transport-Layer Third-Party Loss Early Indication [RFC6642]
4949
RTCP_ECN_FB = 8, // RTCP ECN Feedback [RFC6679]
5050
PAUSE_RESUME = 9, // Media Pause/Resume [RFC7728]
51-
52-
DBI = 10 // Delay Budget Information (DBI) [3GPP TS 26.114 v16.3.0][Ozgur_Oyman]
51+
DBI = 10, // Delay Budget Information (DBI) [3GPP TS 26.114 v16.3.0][Ozgur_Oyman]
52+
TWCC = 15, // Transport-Wide Congestion Control [RFC8888]
5353
// 11-30 // Unassigned
5454
// Extension = 31 // Reserved for future extensions [RFC4585]
5555
}

src/net/RTCP/RTCPHeader.cs

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//-----------------------------------------------------------------------------
1+
//-----------------------------------------------------------------------------
22
// Filename: RTCPHeader.cs
33
//
44
// Description: RTCP Header as defined in RFC3550.
@@ -128,6 +128,21 @@ public bool IsFeedbackReport()
128128
}
129129
}
130130

131+
public static RTCPFeedbackTypesEnum ParseFeedbackType(byte[] packet)
132+
{
133+
if (packet.Length < HEADER_BYTES_LENGTH)
134+
{
135+
throw new ApplicationException("The packet did not contain the minimum number of bytes for an RTCP header packet.");
136+
}
137+
UInt16 firstWord = BitConverter.ToUInt16(packet, 0);
138+
139+
if (BitConverter.IsLittleEndian)
140+
{
141+
firstWord = NetConvert.DoReverseEndian(firstWord);
142+
}
143+
return (RTCPFeedbackTypesEnum)((firstWord >> 8) & 0x1f);
144+
}
145+
131146
/// <summary>
132147
/// Extract and load the RTCP header from an RTCP packet.
133148
/// </summary>

src/net/RTCP/RTCPReceiverReport.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//-----------------------------------------------------------------------------
1+
//-----------------------------------------------------------------------------
22
// Filename: RTCPReceiverReport.cs
33
//
44
// Description:
@@ -98,8 +98,12 @@ public RTCPReceiverReport(byte[] packet)
9898
int rrIndex = 8;
9999
for (int i = 0; i < Header.ReceptionReportCount; i++)
100100
{
101-
var rr = new ReceptionReportSample(packet.Skip(rrIndex + i * ReceptionReportSample.PAYLOAD_SIZE).ToArray());
102-
ReceptionReports.Add(rr);
101+
var pkt = packet.Skip(rrIndex + i * ReceptionReportSample.PAYLOAD_SIZE).ToArray();
102+
if (pkt.Length >= ReceptionReportSample.PAYLOAD_SIZE)
103+
{
104+
var rr = new ReceptionReportSample(pkt);
105+
ReceptionReports.Add(rr);
106+
}
103107
}
104108
}
105109

src/net/RTCP/RTCPSenderReport.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//-----------------------------------------------------------------------------
1+
//-----------------------------------------------------------------------------
22
// Filename: RTCPSenderReport.cs
33
//
44
// Description:
@@ -121,8 +121,13 @@ public RTCPSenderReport(byte[] packet)
121121
int rrIndex = 28;
122122
for (int i = 0; i < Header.ReceptionReportCount; i++)
123123
{
124-
var rr = new ReceptionReportSample(packet.Skip(rrIndex + i * ReceptionReportSample.PAYLOAD_SIZE).ToArray());
125-
ReceptionReports.Add(rr);
124+
var pkt = packet.Skip(rrIndex + i * ReceptionReportSample.PAYLOAD_SIZE).ToArray();
125+
if (pkt.Length >= ReceptionReportSample.PAYLOAD_SIZE)
126+
{
127+
var rr = new ReceptionReportSample(pkt);
128+
ReceptionReports.Add(rr);
129+
}
130+
126131
}
127132
}
128133

0 commit comments

Comments
 (0)