Skip to content

Commit dedc327

Browse files
authored
Adjustments for ffmpeg file processing fixes. (#1279)
* Adjustments for ffmpeg file processing fixes. * Removed ffmpeg project reference from webrtc examples. * Updated the ffmpeg nuget version in the mp4 demo.
1 parent d7833a6 commit dedc327

7 files changed

Lines changed: 39 additions & 28 deletions

File tree

examples/WebRTCExamples/WebRTCEchoServer/WebRTCEchoServer.cs

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public async Task<RTCSessionDescriptionInit> GotOffer(RTCSessionDescriptionInit
9999
{
100100
_logger.LogDebug($"RTP event received: {ev.EventID}.");
101101
// Echo the DTMF event back.
102-
var echoEvent = new RTPEvent(ev.EventID, true, RTPEvent.DEFAULT_VOLUME, RTPSession.DTMF_EVENT_DURATION, RTPSession.DTMF_EVENT_PAYLOAD_ID);
102+
var echoEvent = new RTPEvent(ev.EventID, true, RTPEvent.DEFAULT_VOLUME, RTPSession.DTMF_EVENT_DURATION, RTPSession.DEFAULT_DTMF_EVENT_PAYLOAD_ID);
103103
await pc.SendDtmfEvent(echoEvent, CancellationToken.None).ConfigureAwait(false);
104104
}
105105

@@ -109,15 +109,15 @@ public async Task<RTCSessionDescriptionInit> GotOffer(RTCSessionDescriptionInit
109109
{
110110
_logger.LogDebug($"RTP event received: {ev.EventID}.");
111111
// Echo the DTMF event back.
112-
var echoEvent = new RTPEvent(ev.EventID, true, RTPEvent.DEFAULT_VOLUME, RTPSession.DTMF_EVENT_DURATION, RTPSession.DTMF_EVENT_PAYLOAD_ID);
112+
var echoEvent = new RTPEvent(ev.EventID, true, RTPEvent.DEFAULT_VOLUME, RTPSession.DTMF_EVENT_DURATION, RTPSession.DEFAULT_DTMF_EVENT_PAYLOAD_ID);
113113
await pc.SendDtmfEvent(echoEvent, CancellationToken.None).ConfigureAwait(false);
114114
}
115115
else if (!ev.EndOfEvent)
116116
{
117117
_rtpEventSsrc = hdr.SyncSource;
118118
_logger.LogDebug($"RTP event received: {ev.EventID}.");
119119
// Echo the DTMF event back.
120-
var echoEvent = new RTPEvent(ev.EventID, true, RTPEvent.DEFAULT_VOLUME, RTPSession.DTMF_EVENT_DURATION, RTPSession.DTMF_EVENT_PAYLOAD_ID);
120+
var echoEvent = new RTPEvent(ev.EventID, true, RTPEvent.DEFAULT_VOLUME, RTPSession.DTMF_EVENT_DURATION, RTPSession.DEFAULT_DTMF_EVENT_PAYLOAD_ID);
121121
await pc.SendDtmfEvent(echoEvent, CancellationToken.None).ConfigureAwait(false);
122122
}
123123
}

examples/WebRTCExamples/WebRTCMp4Source/Program.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
//-----------------------------------------------------------------------------
1616

1717
using System;
18-
using System.Collections.Generic;
1918
using System.Linq;
2019
using System.Net;
2120
using System.Threading;
@@ -33,8 +32,8 @@ namespace demo
3332
{
3433
class Program
3534
{
36-
//private const string MP4_PATH = @"media\max_intro.mp4"; // /!\ A valid path to Video file
37-
private const string MP4_PATH = @"media\big_buck_bunny.mp4";
35+
private const string MP4_PATH = @"media\max_intro.mp4"; // /!\ A valid path to Video file
36+
//private const string MP4_PATH = @"media\big_buck_bunny.mp4";
3837

3938
private const int WEBSOCKET_PORT = 8081;
4039
private const string STUN_URL = "stun:stun.sipsorcery.com";
@@ -72,14 +71,15 @@ private static Task<RTCPeerConnection> CreatePeerConnection()
7271
{
7372
RTCConfiguration config = new RTCConfiguration
7473
{
75-
iceServers = new List<RTCIceServer> { new RTCIceServer { urls = STUN_URL } }
74+
//iceServers = new List<RTCIceServer> { new RTCIceServer { urls = STUN_URL } }
7675
};
7776
var pc = new RTCPeerConnection(config);
7877

7978
SIPSorceryMedia.FFmpeg.FFmpegInit.Initialise(SIPSorceryMedia.FFmpeg.FfmpegLogLevelEnum.AV_LOG_VERBOSE, null, logger);
80-
var mediaFileSource = new SIPSorceryMedia.FFmpeg.FFmpegFileSource(MP4_PATH, false, new AudioEncoder());
79+
var mediaFileSource = new SIPSorceryMedia.FFmpeg.FFmpegFileSource(MP4_PATH, true, new AudioEncoder());
8180
mediaFileSource.RestrictFormats(x => x.Codec == VideoCodecsEnum.VP8);
82-
mediaFileSource.RestrictFormats(x => x.Codec == AudioCodecsEnum.PCMU);
81+
82+
//mediaFileSource.RestrictFormats(x => x.Codec == AudioCodecsEnum.OPUS);
8383
//mediaFileSource..OnEndOfFile += () => pc.Close("source eof");
8484

8585
MediaStreamTrack videoTrack = new MediaStreamTrack(mediaFileSource.GetVideoSourceFormats(), MediaStreamStatusEnum.SendRecv);
@@ -100,7 +100,7 @@ private static Task<RTCPeerConnection> CreatePeerConnection()
100100
{
101101
pc.Close("ice disconnection");
102102
}
103-
else if (state == RTCPeerConnectionState.closed)
103+
else if (state is RTCPeerConnectionState.closed or RTCPeerConnectionState.disconnected)
104104
{
105105
await mediaFileSource.CloseVideo();
106106
}
@@ -110,6 +110,20 @@ private static Task<RTCPeerConnection> CreatePeerConnection()
110110
}
111111
};
112112

113+
pc.onsignalingstatechange += () =>
114+
{
115+
logger.LogDebug($"Signalling state change to {pc.signalingState}.");
116+
117+
if (pc.signalingState == RTCSignalingState.have_local_offer)
118+
{
119+
logger.LogDebug($"Local SDP offer:\n{pc.localDescription.sdp}");
120+
}
121+
else if (pc.signalingState == RTCSignalingState.stable)
122+
{
123+
logger.LogDebug($"Remote SDP offer:\n{pc.remoteDescription.sdp}");
124+
}
125+
};
126+
113127
// Diagnostics.
114128
//pc.OnReceiveReport += (re, media, rr) => logger.LogDebug($"RTCP Receive for {media} from {re}\n{rr.GetDebugSummary()}");
115129
//pc.OnSendReport += (media, sr) => logger.LogDebug($"RTCP Send for {media}\n{sr.GetDebugSummary()}");

examples/WebRTCExamples/WebRTCMp4Source/WebRTCMp4Source.csproj

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net8</TargetFramework>
6-
</PropertyGroup>
7-
8-
<PropertyGroup>
96
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
107
<Prefer32Bit>false</Prefer32Bit>
8+
<LangVersion>10</LangVersion>
119
</PropertyGroup>
1210

1311
<ItemGroup>
@@ -25,11 +23,11 @@
2523
</ItemGroup>
2624

2725
<ItemGroup>
28-
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
29-
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
30-
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
26+
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
27+
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" />
28+
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
3129
<PackageReference Include="SIPSorcery.WebSocketSharp" Version="0.0.1" />
32-
<PackageReference Include="SIPSorceryMedia.FFmpeg" Version="8.0.7" />
30+
<PackageReference Include="SIPSorceryMedia.FFmpeg" Version="8.0.8" />
3331
</ItemGroup>
3432

3533
<ItemGroup>

src/net/RTP/AudioStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public async Task SendDtmfEvent(RTPEvent rtpEvent, CancellationToken cancellatio
236236
/// be used to cancel the send.</param>
237237
public virtual Task SendDtmf(byte key, CancellationToken ct)
238238
{
239-
var dtmfEvent = new RTPEvent(key, false, RTPEvent.DEFAULT_VOLUME, RTPSession.DTMF_EVENT_DURATION, RTPSession.DTMF_EVENT_PAYLOAD_ID);
239+
var dtmfEvent = new RTPEvent(key, false, RTPEvent.DEFAULT_VOLUME, RTPSession.DTMF_EVENT_DURATION, NegotiatedRtpEventPayloadID);
240240
return SendDtmfEvent(dtmfEvent, ct);
241241
}
242242

src/net/RTP/MediaStream.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ public bool IsClosed
140140

141141
/// <summary>
142142
/// In order to detect RTP events from the remote party this property needs to
143-
/// be set to the payload ID they are using.
143+
/// be negotiated to a common payload ID. RTP events are typically DTMF tones.
144144
/// </summary>
145-
public int RemoteRtpEventPayloadID { get; set; } = RTPSession.DEFAULT_DTMF_EVENT_PAYLOAD_ID;
145+
public int NegotiatedRtpEventPayloadID { get; set; } = RTPSession.DEFAULT_DTMF_EVENT_PAYLOAD_ID;
146146

147147
/// <summary>
148148
/// To type of this media
@@ -172,7 +172,7 @@ public MediaStreamTrack LocalTrack
172172
if (MediaType == SDPMediaTypesEnum.audio)
173173
{
174174
if (m_localTrack.Capabilities != null && !m_localTrack.NoDtmfSupport &&
175-
!m_localTrack.Capabilities.Any(x => x.ID == RTPSession.DTMF_EVENT_PAYLOAD_ID))
175+
!m_localTrack.Capabilities.Any(x => x.ID == RTPSession.DEFAULT_DTMF_EVENT_PAYLOAD_ID))
176176
{
177177
m_localTrack.Capabilities.Add(DefaultRTPEventFormat);
178178
}
@@ -220,7 +220,7 @@ public static SDPAudioVideoMediaFormat DefaultRTPEventFormat
220220
{
221221
return new SDPAudioVideoMediaFormat(
222222
SDPMediaTypesEnum.audio,
223-
RTPSession.DTMF_EVENT_PAYLOAD_ID,
223+
RTPSession.DEFAULT_DTMF_EVENT_PAYLOAD_ID,
224224
SDP.TELEPHONE_EVENT_ATTRIBUTE,
225225
RTPSession.DEFAULT_AUDIO_CLOCK_RATE,
226226
SDPAudioVideoMediaFormat.DEFAULT_AUDIO_CHANNEL_COUNT,
@@ -647,7 +647,7 @@ public void SendRtcpFeedback(RTCPFeedback feedback)
647647
public void OnReceiveRTPPacket(RTPHeader hdr, int localPort, IPEndPoint remoteEndPoint, byte[] buffer, VideoStream videoStream = null)
648648
{
649649
RTPPacket rtpPacket;
650-
if (RemoteRtpEventPayloadID != 0 && hdr.PayloadType == RemoteRtpEventPayloadID)
650+
if (NegotiatedRtpEventPayloadID != 0 && hdr.PayloadType == NegotiatedRtpEventPayloadID)
651651
{
652652
if (!EnsureBufferUnprotected(buffer, hdr, out rtpPacket))
653653
{
@@ -919,7 +919,7 @@ public SDPAudioVideoMediaFormat GetSendingFormat()
919919
if (MediaType == SDPMediaTypesEnum.audio)
920920
{
921921
format = SDPAudioVideoMediaFormat.GetCompatibleFormats(RemoteTrack.Capabilities, LocalTrack.Capabilities)
922-
.Where(x => x.ID != RemoteRtpEventPayloadID).FirstOrDefault();
922+
.Where(x => x.ID != NegotiatedRtpEventPayloadID).FirstOrDefault();
923923
}
924924
else
925925
{

src/net/RTP/RTPSession.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ public class RTPSession : IMediaSession, IDisposable
163163
public const string RTP_SECUREMEDIA_PROFILE = "RTP/SAVP";
164164
protected const int SDP_SESSIONID_LENGTH = 10; // The length of the pseudo-random string to use for the session ID.
165165
public const int DTMF_EVENT_DURATION = 1200; // Default duration for a DTMF event.
166-
public const int DTMF_EVENT_PAYLOAD_ID = 101;
167166

168167
/// <summary>
169168
/// When there are no RTP packets being sent for an audio or video stream webrtc.lib
@@ -1080,7 +1079,7 @@ public virtual SetDescriptionResultEnum SetRemoteDescription(SdpType sdpType, SD
10801079
SDPAudioVideoMediaFormat commonEventFormat = SDPAudioVideoMediaFormat.GetCommonRtpEventFormat(announcement.MediaFormats.Values.ToList(), currentMediaStream.LocalTrack.Capabilities);
10811080
if (!commonEventFormat.IsEmpty())
10821081
{
1083-
currentMediaStream.RemoteRtpEventPayloadID = commonEventFormat.ID;
1082+
currentMediaStream.NegotiatedRtpEventPayloadID = commonEventFormat.ID;
10841083
}
10851084
}
10861085

@@ -1973,7 +1972,7 @@ public void SendVideo(uint durationRtpUnits, byte[] sample)
19731972
}
19741973

19751974
/// <summary>
1976-
/// Sends a DTMF toneas an RTP event to the remote party. (on the primary one)
1975+
/// Sends a DTMF tone as an RTP event to the remote party. (on the primary one)
19771976
/// </summary>
19781977
/// <param name="key">The DTMF tone to send.</param>
19791978
/// <param name="ct">RTP events can span multiple RTP packets. This token can

src/net/RTP/VideoStream.cs

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public void CheckVideoFormatsNegotiation()
309309
public VideoStream(RtpSessionConfig config, int index) : base(config, index)
310310
{
311311
MediaType = SDPMediaTypesEnum.video;
312-
RemoteRtpEventPayloadID = 0;
312+
NegotiatedRtpEventPayloadID = 0;
313313
}
314314
}
315315
}

0 commit comments

Comments
 (0)