Skip to content

Commit b32de41

Browse files
authored
Sdp audio fix (#1334)
* 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 * remove comment marker * Check for null * Fix bug with HasVideo and HasAudio * Fix audio parsing with multiple ports * Add unit test
1 parent 8f51ce4 commit b32de41

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

src/net/SDP/SDP.cs

+16-2
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,27 @@ public static SDP ParseSDPDescription(string sdpDescription)
309309
break;
310310

311311
case var l when l.StartsWith("m="):
312-
Match mediaMatch = Regex.Match(sdpLineTrimmed.Substring(2), @"(?<type>\w+)\s+(?<port>\d+)\s+(?<transport>\S+)(\s*)(?<formats>.*)$");
312+
Match mediaMatch = Regex.Match(
313+
sdpLineTrimmed.Substring(2),
314+
@"(?<type>\w+)\s+(?<port>\d+)(?:\/(?<portCount>\d+))?\s+(?<transport>\S+)\s*(?<formats>.*)$"
315+
);
313316
if (mediaMatch.Success)
314317
{
315318
SDPMediaAnnouncement announcement = new SDPMediaAnnouncement();
316319
announcement.MLineIndex = mLineIndex;
317320
announcement.Media = SDPMediaTypes.GetSDPMediaType(mediaMatch.Result("${type}"));
318-
Int32.TryParse(mediaMatch.Result("${port}"), out announcement.Port);
321+
322+
// Parse the primary port.
323+
int.TryParse(mediaMatch.Result("${port}"), out announcement.Port);
324+
if (mediaMatch.Groups["portCount"].Success)
325+
{
326+
int portCount;
327+
if (Int32.TryParse(mediaMatch.Result("${portCount}"), out portCount))
328+
{
329+
announcement.PortCount = portCount;
330+
}
331+
}
332+
319333
announcement.Transport = mediaMatch.Result("${transport}");
320334
announcement.ParseMediaFormats(mediaMatch.Result("${formats}"));
321335
if (announcement.Media == SDPMediaTypesEnum.audio || announcement.Media == SDPMediaTypesEnum.video)

src/net/SDP/SDPMediaAnnouncement.cs

+6
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ public class SDPMediaAnnouncement
9292
// Media Announcement fields.
9393
public SDPMediaTypesEnum Media = SDPMediaTypesEnum.audio; // Media type for the stream.
9494
public int Port; // For UDP transports should be in the range 1024 to 65535 and for RTP compliance should be even (only even ports used for data).
95+
/// <summary>
96+
/// Gets or sets the number of consecutive ports specified for the media stream in the SDP.
97+
/// When the SDP media line includes a port range (e.g., "30000/2"), this property holds the count of ports.
98+
/// Typically, a value of 2 indicates that two ports are allocated: one for RTP and the following port for RTCP.
99+
/// </summary>
100+
public int PortCount { get; set; }
95101
public string Transport = "RTP/AVP"; // Defined types RTP/AVP (RTP Audio Visual Profile) and udp.
96102
public string IceUfrag; // If ICE is being used the username for the STUN requests.
97103
public string IcePwd; // If ICE is being used the password for the STUN requests.

test/unit/net/SDP/SDPUnitTests.cs

+34
Original file line numberDiff line numberDiff line change
@@ -1310,5 +1310,39 @@ public void Media_Formats_Order_Test()
13101310

13111311
Assert.Equal(8, sdpParsed.Media.Where(x => x.Media == SDPMediaTypesEnum.audio).First().MediaFormats.First().Key);
13121312
}
1313+
1314+
/// <summary>
1315+
/// Tests that parsing the number of ports parameter works correctly.
1316+
/// </summary>
1317+
/// <remarks>
1318+
/// https://datatracker.ietf.org/doc/html/rfc4566#section-5.14
1319+
/// </remarks>
1320+
[Fact]
1321+
public void Parse_Number_Of_Ports_Unit_Test()
1322+
{
1323+
logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
1324+
logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);
1325+
1326+
string sdpStr =
1327+
"v=0" + m_CRLF +
1328+
"o=root 3285 3285 IN IP4 10.0.0.4" + m_CRLF +
1329+
"s=session" + m_CRLF +
1330+
"c=IN IP4 10.0.0.4" + m_CRLF +
1331+
"t=0 0" + m_CRLF +
1332+
"m=audio 12228/2 RTP/AVP 0 101" + m_CRLF +
1333+
"a=rtpmap:0 PCMU/8000" + m_CRLF +
1334+
"a=rtpmap:101 telephone-event/8000" + m_CRLF +
1335+
"a=fmtp:101 0-16" + m_CRLF +
1336+
"a=silenceSupp:off - - - -" + m_CRLF +
1337+
"a=ptime:20" + m_CRLF +
1338+
"a=sendrecv";
1339+
1340+
SDP sdp = SDP.ParseSDPDescription(sdpStr);
1341+
1342+
logger.LogDebug(sdp.ToString());
1343+
1344+
Assert.True(sdp.Media[0].Port == 12228, "The connection port was not parsed correctly.");
1345+
Assert.True(sdp.Media[0].PortCount == 2, "The port count was not parsed correctly.");
1346+
}
13131347
}
13141348
}

0 commit comments

Comments
 (0)