diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-08 01:19:58 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-03-08 01:19:58 +0200 |
| commit | 436ceaea56ecff755476a3796cff72e1da39dfc6 (patch) | |
| tree | 5d8ebc02e999f777378df5e699f0b13a9827d622 /Software/Visual_Studio/Tango.WebRTC | |
| parent | 9d18d9ec9658af3716814625b608d58ad3daa14c (diff) | |
| download | Tango-436ceaea56ecff755476a3796cff72e1da39dfc6.tar.gz Tango-436ceaea56ecff755476a3796cff72e1da39dfc6.zip | |
Integrated WebRTC channel to PPC/FSE.
Diffstat (limited to 'Software/Visual_Studio/Tango.WebRTC')
| -rw-r--r-- | Software/Visual_Studio/Tango.WebRTC/Tango.WebRTC.csproj | 4 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.WebRTC/WebRtcClient.cs | 76 |
2 files changed, 43 insertions, 37 deletions
diff --git a/Software/Visual_Studio/Tango.WebRTC/Tango.WebRTC.csproj b/Software/Visual_Studio/Tango.WebRTC/Tango.WebRTC.csproj index 0d85bb902..d9cea42dc 100644 --- a/Software/Visual_Studio/Tango.WebRTC/Tango.WebRTC.csproj +++ b/Software/Visual_Studio/Tango.WebRTC/Tango.WebRTC.csproj @@ -59,6 +59,10 @@ <Project>{a07e6cb4-0132-4eb1-9a38-c8c057884dc2}</Project> <Name>WebRtc.NET</Name> </ProjectReference> + <ProjectReference Include="..\Tango.Core\Tango.Core.csproj"> + <Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project> + <Name>Tango.Core</Name> + </ProjectReference> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/Tango.WebRTC/WebRtcClient.cs b/Software/Visual_Studio/Tango.WebRTC/WebRtcClient.cs index 9866395ae..bbbabb4e4 100644 --- a/Software/Visual_Studio/Tango.WebRTC/WebRtcClient.cs +++ b/Software/Visual_Studio/Tango.WebRTC/WebRtcClient.cs @@ -8,6 +8,7 @@ using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; +using Tango.Core.Threading; using WebRtc.NET; namespace Tango.WebRTC @@ -192,14 +193,15 @@ namespace Tango.WebRTC completion.SetResult(true); - Stopwatch watch = new Stopwatch(); - watch.Start(); + //Stopwatch watch = new Stopwatch(); + //watch.Start(); while (!_isDisposed) { - watch.Restart(); + //watch.Restart(); _conductor.ProcessMessages(1000); - Thread.Sleep(Math.Max(10, (int)watch.ElapsedMilliseconds)); + Thread.Sleep(10); + //Thread.Sleep(Math.Max(10, (int)watch.ElapsedMilliseconds)); } IsInitialized = false; @@ -211,9 +213,35 @@ namespace Tango.WebRTC _conductor.OnFailure -= _conductor_OnFailure; _conductor.OnIceStateChanged -= _conductor_OnIceStateChanged; + unsafe + { + _conductor.OnRenderRemote -= _conductor_OnRenderRemote; + } + _conductor.Dispose(); + + try + { + if (_sendFrame != null) + { + _sendFrame.Dispose(); + } + + } + catch { } + + + try + { + if (_bufHandle != null) + { + _bufHandle.Free(); + } + } + catch { } }); + _conductorThread.SetApartmentState(ApartmentState.STA); _conductorThread.IsBackground = true; _conductorThread.Start(); @@ -320,16 +348,14 @@ namespace Tango.WebRTC _conductor.OnSuccessOffer += del; - Task.Factory.StartNew(async () => + TimeoutTask.StartNew(() => { - await Task.Delay(10000); - if (!completed) { completed = true; completion.SetException(new TimeoutException("The offer was not created within the given time.")); } - }); + }, TimeSpan.FromSeconds(10)); _conductor.CreateOffer(); @@ -358,16 +384,14 @@ namespace Tango.WebRTC _conductor.OnSuccessAnswer += del; - Task.Factory.StartNew(async () => + TimeoutTask.StartNew(() => { - await Task.Delay(10000); - if (!completed) { completed = true; completion.SetException(new TimeoutException("The answer was not created within the given time.")); } - }); + }, TimeSpan.FromSeconds(10)); _conductor.OnOfferRequest(offer.Sdp); @@ -392,7 +416,7 @@ namespace Tango.WebRTC { EnsureInitialized(); - Task.Factory.StartNew(() => + ThreadFactory.StartNew(() => { _conductor.AddIceCandidate(ice.SdpMid, ice.SdpMLineIndex, ice.Sdp); }); @@ -437,16 +461,14 @@ namespace Tango.WebRTC { if (timeout != null) { - Task.Factory.StartNew(async () => + TimeoutTask.StartNew(() => { - await Task.Delay(timeout.Value); - if (!IsReady) { _readyCompletionSource.SetException(new TimeoutException("The connection was not ready within the given time.")); _readyCompletionSource = null; } - }); + }, timeout.Value); } _readyCompletionSource = new TaskCompletionSource<bool>(); @@ -463,26 +485,6 @@ namespace Tango.WebRTC if (!_isDisposed) { _isDisposed = true; - - try - { - if (_sendFrame != null) - { - _sendFrame.Dispose(); - } - - } - catch { } - - - try - { - if (_bufHandle != null) - { - _bufHandle.Free(); - } - } - catch { } } } |
