Skip to content

Commit 4a5cf6f

Browse files
authored
Add RTP port-based media stream lookup fallback (#1480)
Add GetMediaStreamByRTPPort method to enable media stream identification by RTP port when SSRC and payload type matching fails. This provides an additional fallback mechanism in OnReceiveRTPPacket to correctly route incoming RTP packets to their corresponding media streams.
1 parent ed55ff3 commit 4a5cf6f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/net/RTP/RTPSession.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2592,6 +2592,11 @@ private void OnReceiveRTPPacket(int localPort, IPEndPoint remoteEndPoint, byte[]
25922592
mediaStream = GetMediaStreamFromPayloadType(hdr.PayloadType);
25932593
}
25942594

2595+
if (mediaStream == null)
2596+
{
2597+
mediaStream = GetMediaStreamByRTPPort(localPort);
2598+
}
2599+
25952600
if (mediaStream == null)
25962601
{
25972602
logger.LogWarning("An RTP packet with SSRC {SyncSource} and payload ID {PayloadType} was received that could not be matched to an audio or video stream.", hdr.SyncSource, hdr.PayloadType);
@@ -2644,6 +2649,35 @@ private MediaStream GetMediaStreamFromPayloadType(int payloadId)
26442649
return null;
26452650
}
26462651

2652+
private MediaStream GetMediaStreamByRTPPort(int port)
2653+
{
2654+
foreach (var audioStream in AudioStreamList)
2655+
{
2656+
if (audioStream?.GetRTPChannel()?.RTPPort == port)
2657+
{
2658+
return audioStream;
2659+
}
2660+
}
2661+
2662+
foreach (var videoStream in VideoStreamList)
2663+
{
2664+
if (videoStream?.GetRTPChannel()?.RTPPort == port)
2665+
{
2666+
return videoStream;
2667+
}
2668+
}
2669+
2670+
foreach (var textStream in TextStreamList)
2671+
{
2672+
if (textStream?.GetRTPChannel()?.RTPPort == port)
2673+
{
2674+
return textStream;
2675+
}
2676+
}
2677+
2678+
return null;
2679+
}
2680+
26472681
private MediaStream GetMediaStream(uint ssrc)
26482682
{
26492683
foreach (var audioStream in AudioStreamList)

0 commit comments

Comments
 (0)