diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-04 14:33:53 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-08-04 14:33:53 +0300 |
| commit | cc194ae37fba4a72bb994b7e8e5e7e2e99e1f2a6 (patch) | |
| tree | 1c9db4aeea41ddf09e6e89a1c4985509a942715a /Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteDesktop/DefaultRemoteDesktopService.cs | |
| parent | 91d5be468e28266a4ae18ee3845f0cb3433dd898 (diff) | |
| download | Tango-cc194ae37fba4a72bb994b7e8e5e7e2e99e1f2a6.tar.gz Tango-cc194ae37fba4a72bb994b7e8e5e7e2e99e1f2a6.zip | |
Fixed issue with TurboJpeg crashed PPC on remote desktop standard.
Diffstat (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteDesktop/DefaultRemoteDesktopService.cs')
| -rw-r--r-- | Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteDesktop/DefaultRemoteDesktopService.cs | 171 |
1 files changed, 90 insertions, 81 deletions
diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteDesktop/DefaultRemoteDesktopService.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteDesktop/DefaultRemoteDesktopService.cs index 45ba29e2a..8535d45d4 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteDesktop/DefaultRemoteDesktopService.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/RemoteDesktop/DefaultRemoteDesktopService.cs @@ -401,119 +401,128 @@ namespace Tango.PPC.Common.RemoteDesktop private async void _engine_FrameReceived(object sender, ScreenCaptureFrameReceivedEventArgs<RasterFrame> e) { - if (_drawCursor) - { - e.Frame.DrawImage((_isMouseDown || _ensureMouseDown) ? Properties.Resources.tap : Properties.Resources.finger3, new System.Drawing.Point(System.Windows.Forms.Cursor.Position.X - 5, System.Windows.Forms.Cursor.Position.Y - 4)); - _ensureMouseDown = false; - } - - _initialPacket = new RemoteDesktopPacket() - { - Bitmap = e.Frame.ToEncoder<PngEncoder>().ToArray(), - }; - - if (_clients.Count > 0) + try { - bool useWebRTC = _clients.ToList().All(x => x.IsWebRtcReady); - - if (useWebRTC) + if (_drawCursor) { - _engine.EnableComparer = false; - - foreach (var client in _clients.ToList()) - { - try - { - client.WebRtcClient.PushFrame(e.Frame.ToBitmap()); - } - catch (Exception ex) - { - LogManager.Log(ex, LogCategory.Debug, "Error pushing remote desktop frame via WebRTC channel."); - } - } - - e.Frame.Dispose(); + e.Frame.DrawImage((_isMouseDown || _ensureMouseDown) ? Properties.Resources.tap : Properties.Resources.finger3, new System.Drawing.Point(System.Windows.Forms.Cursor.Position.X - 5, System.Windows.Forms.Cursor.Position.Y - 4)); + _ensureMouseDown = false; } - else - { - _engine.EnableComparer = true; - foreach (var client in _clients.ToList().Where(x => !x.InitialPacketSent)) - { - try - { - await client.Receiver.SendGenericResponse(new StartRemoteDesktopSessionResponse() - { - Packet = _initialPacket, - }, client.Token, new TransportResponseConfig() - { - Immediate = false, - }); + _initialPacket = new RemoteDesktopPacket() + { + Bitmap = e.Frame.ToEncoder<PngEncoder>().ToArray(), + }; - client.InitialPacketSent = true; - } - catch (Exception ex) - { - Debug.WriteLine(ex); - } - } + if (_clients.Count > 0) + { + bool useWebRTC = _clients.ToList().All(x => x.IsWebRtcReady); - if (e.Frame.DifferenceCount > 0) + if (useWebRTC) { - RemoteDesktopPacket packet = null; - - Point mousePosition = new Point(System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y); + _engine.EnableComparer = false; - if (!e.Frame.DifferenceAvailable) + foreach (var client in _clients.ToList()) { - packet = new RemoteDesktopPacket() + try { - Bitmap = e.Frame.ToEncoder<TurboJpegEncoder>().ToArray(30), - MousePosition = mousePosition, - CursorVisible = _drawCursor - }; - } - else - { - var diffFrame = e.Frame.ToDifference(); - diffFrame = diffFrame.OptimizeBounds(); - - packet = new RemoteDesktopPacket() + client.WebRtcClient.PushFrame(e.Frame.ToBitmap()); + } + catch (Exception ex) { - Bitmap = diffFrame.ToEncoder<PngEncoder>().ToArray(), - IsPartial = true, - PartialRegion = new CaptureRegion(diffFrame.Left, diffFrame.Top, diffFrame.Width, diffFrame.Height), - MousePosition = mousePosition, - CursorVisible = _drawCursor - }; - - diffFrame.Dispose(); + LogManager.Log(ex, LogCategory.Debug, "Error pushing remote desktop frame via WebRTC channel."); + } } - Debug.WriteLine($"Remote Desktop Bitmap Size: {packet.Bitmap.Length / 1000} kb"); + e.Frame.Dispose(); + } + else + { + _engine.EnableComparer = true; - foreach (var client in _clients.ToList().Where(x => x.InitialPacketSent)) + foreach (var client in _clients.ToList().Where(x => !x.InitialPacketSent)) { try { await client.Receiver.SendGenericResponse(new StartRemoteDesktopSessionResponse() { - Packet = packet + Packet = _initialPacket, }, client.Token, new TransportResponseConfig() { Immediate = false, }); + + client.InitialPacketSent = true; } catch (Exception ex) { Debug.WriteLine(ex); } } + + if (e.Frame.DifferenceCount > 0) + { + RemoteDesktopPacket packet = null; + + Point mousePosition = new Point(System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y); + + if (!e.Frame.DifferenceAvailable) + { + packet = new RemoteDesktopPacket() + { + Bitmap = e.Frame.ToEncoder<JpegEncoder>().ToArray(30), + MousePosition = mousePosition, + CursorVisible = _drawCursor + }; + } + else + { + var diffFrame = e.Frame.ToDifference(); + diffFrame = diffFrame.OptimizeBounds(); + + packet = new RemoteDesktopPacket() + { + Bitmap = diffFrame.ToEncoder<PngEncoder>().ToArray(), + IsPartial = true, + PartialRegion = new CaptureRegion(diffFrame.Left, diffFrame.Top, diffFrame.Width, diffFrame.Height), + MousePosition = mousePosition, + CursorVisible = _drawCursor + }; + + diffFrame.Dispose(); + } + + Debug.WriteLine($"Remote Desktop Bitmap Size: {packet.Bitmap.Length / 1000} kb"); + + foreach (var client in _clients.ToList().Where(x => x.InitialPacketSent)) + { + try + { + await client.Receiver.SendGenericResponse(new StartRemoteDesktopSessionResponse() + { + Packet = packet + }, client.Token, new TransportResponseConfig() + { + Immediate = false, + }); + } + catch (Exception ex) + { + Debug.WriteLine(ex); + } + } + } } } } - - e.Frame.Dispose(); + catch (Exception ex) + { + LogManager.Log(ex, "Error occurred on remote desktop engine frame received event."); + } + finally + { + e.Frame.Dispose(); + } } private async void WebRtcClient_TextMessageReceived(object sender, DataMessageReceivedEventArgs<string> e) |
