Skip to content

Commit cdf7bfe

Browse files
authored
Added missing event handler for RTCP report ready. (sipsorcery-org#1269)
1 parent 60ad77b commit cdf7bfe

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

examples/WebRTCExamples/WebRTCReceiveAudio/Program.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ private static async Task<RTCPeerConnection> SendSDPOffer(WebSocketContext conte
119119
peerConnection.OnAudioFormatsNegotiated += (audioFormats) =>
120120
windowsAudioEP.SetAudioSinkFormat(audioFormats.First());
121121
peerConnection.OnReceiveReport += RtpSession_OnReceiveReport;
122-
peerConnection.OnSendReport += RtpSession_OnSendReport;
123122
peerConnection.OnSendReportByIndex += RtpSession_OnSendReportByIndex;
124123
peerConnection.OnTimeout += (mediaType) => logger.LogDebug($"Timeout on media {mediaType}.");
125124
peerConnection.oniceconnectionstatechange += (state) => logger.LogDebug($"ICE connection state changed to {state}.");
@@ -134,7 +133,7 @@ private static async Task<RTCPeerConnection> SendSDPOffer(WebSocketContext conte
134133
else if (state == RTCPeerConnectionState.closed || state == RTCPeerConnectionState.failed)
135134
{
136135
peerConnection.OnReceiveReport -= RtpSession_OnReceiveReport;
137-
peerConnection.OnSendReport -= RtpSession_OnSendReport;
136+
peerConnection.OnSendReportByIndex -= RtpSession_OnSendReportByIndex;
138137

139138
await windowsAudioEP.CloseAudio();
140139
}
@@ -182,15 +181,12 @@ private static void WebSocketMessageReceived(RTCPeerConnection peerConnection, s
182181
}
183182
}
184183

185-
private static void RtpSession_OnSendReport(SDPMediaTypesEnum mediaType, RTCPCompoundPacket sentRtcpReport)
186-
=> RtpSession_OnSendReportByIndex(0, mediaType, sentRtcpReport);
187-
188184
/// <summary>
189185
/// Diagnostic handler to print out our RTCP sender/receiver reports.
190186
/// </summary>
191187
private static void RtpSession_OnSendReportByIndex(int index, SDPMediaTypesEnum mediaType, RTCPCompoundPacket sentRtcpReport)
192188
{
193-
logger.LogDebug($"RTCP report sent for index {index} and media {mediaType}.");
189+
//logger.LogDebug($"RTCP report sent for index {index} and media {mediaType}.");
194190

195191
if (sentRtcpReport.Bye != null)
196192
{
@@ -206,7 +202,7 @@ private static void RtpSession_OnSendReportByIndex(int index, SDPMediaTypesEnum
206202
if (sentRtcpReport.ReceiverReport.ReceptionReports?.Count > 0)
207203
{
208204
var rrSample = sentRtcpReport.ReceiverReport.ReceptionReports.First();
209-
logger.LogDebug($"RTCP sent RR {mediaType}, ssrc {rrSample.SSRC}, seqnum {rrSample.ExtendedHighestSequenceNumber}.");
205+
logger.LogDebug($"RTCP sent RR {mediaType}, ssrc {rrSample.SSRC}, seqnum {rrSample.ExtendedHighestSequenceNumber}, pkts lost {rrSample.PacketsLost}.");
210206
}
211207
else
212208
{
@@ -220,22 +216,22 @@ private static void RtpSession_OnSendReportByIndex(int index, SDPMediaTypesEnum
220216
/// </summary>
221217
private static void RtpSession_OnReceiveReport(IPEndPoint remoteEndPoint, SDPMediaTypesEnum mediaType, RTCPCompoundPacket recvRtcpReport)
222218
{
223-
logger.LogDebug($"RTCP report received for {mediaType}.");
219+
//logger.LogDebug($"RTCP report received for {mediaType}.");
224220

225221
if (recvRtcpReport.Bye != null)
226222
{
227223
logger.LogDebug($"RTCP recv BYE {mediaType}.");
228224
}
229-
else
225+
else if(recvRtcpReport.ReceiverReport != null)
230226
{
231-
var rr = recvRtcpReport.ReceiverReport?.ReceptionReports?.FirstOrDefault();
227+
var rr = recvRtcpReport.ReceiverReport.ReceptionReports?.FirstOrDefault();
232228
if (rr != null)
233229
{
234-
logger.LogDebug($"RTCP {mediaType} Receiver Report: SSRC {rr.SSRC}, pkts lost {rr.PacketsLost}, delay since SR {rr.DelaySinceLastSenderReport}.");
230+
logger.LogDebug($"RTCP {mediaType} Receiver Report SSRC {rr.SSRC}: pkts lost {rr.PacketsLost}, delay since SR {rr.DelaySinceLastSenderReport}.");
235231
}
236232
else
237233
{
238-
logger.LogDebug($"RTCP {mediaType} Receiver Report: empty.");
234+
logger.LogDebug($"RTCP {mediaType} Receiver Report for SSRC {recvRtcpReport.ReceiverReport.SSRC}: empty.");
239235
}
240236
}
241237
}

src/net/RTP/MediaStream.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,6 @@ public void OnReceiveRTPPacket(RTPHeader hdr, int localPort, IPEndPoint remoteEn
673673
}
674674
}
675675

676-
677676
// Note AC 24 Dec 2020: The problem with waiting until the remote description is set is that the remote peer often starts sending
678677
// RTP packets at the same time it signals its SDP offer or answer. Generally this is not a problem for audio but for video streams
679678
// the first RTP packet(s) are the key frame and if they are ignored the video stream will take additional time or manual

src/net/RTP/RTPSession.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ private void CreateRtcpSession(MediaStream mediaStream)
655655
mediaStream.OnRtpPacketReceivedByIndex += RaisedOnRtpPacketReceived;
656656
mediaStream.OnRtpHeaderReceivedByIndex += RaisedOnRtpHeaderReceived;
657657
mediaStream.OnReceiveReportByIndex += RaisedOnOnReceiveReport;
658+
mediaStream.RtcpSession.OnReportReadyToSend += SendRtcpReport;
658659

659660
if (mediaStream.MediaType == SDPMediaTypesEnum.audio)
660661
{

0 commit comments

Comments
 (0)