1515//-----------------------------------------------------------------------------
1616
1717using System ;
18- using System . Collections . Generic ;
1918using System . Linq ;
2019using System . Net ;
2120using 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()}");
0 commit comments