diff --git a/Remotely_Agent/Remotely_Agent.csproj b/Remotely_Agent/Remotely_Agent.csproj index a632906c..242a0b63 100644 --- a/Remotely_Agent/Remotely_Agent.csproj +++ b/Remotely_Agent/Remotely_Agent.csproj @@ -18,11 +18,11 @@ - + - + diff --git a/Remotely_Agent/Resources/Remotely_ScreenCapture.exe b/Remotely_Agent/Resources/Remotely_ScreenCapture.exe deleted file mode 100644 index 0cfecb28..00000000 Binary files a/Remotely_Agent/Resources/Remotely_ScreenCapture.exe and /dev/null differ diff --git a/Remotely_Agent/Services/DeviceSocket.cs b/Remotely_Agent/Services/DeviceSocket.cs index 08432854..9ec47a2d 100644 --- a/Remotely_Agent/Services/DeviceSocket.cs +++ b/Remotely_Agent/Services/DeviceSocket.cs @@ -282,7 +282,7 @@ namespace Remotely_Agent.Services } // Extract ScreenCast. - using (var mrs = Assembly.GetExecutingAssembly().GetManifestResourceStream("Remotely_Agent.Resources.Remotely_ScreenCapture.exe")) + using (var mrs = Assembly.GetExecutingAssembly().GetManifestResourceStream("Remotely_Agent.Resources.Remotely_ScreenCast.exe")) { using (var fs = new FileStream(filePath, FileMode.Create)) { diff --git a/Remotely_ScreenCast/Capture/BitBltCapture.cs b/Remotely_ScreenCast/Capture/BitBltCapture.cs index 718f0f86..2963a29b 100644 --- a/Remotely_ScreenCast/Capture/BitBltCapture.cs +++ b/Remotely_ScreenCast/Capture/BitBltCapture.cs @@ -13,6 +13,7 @@ using System.Drawing.Drawing2D; using System.Diagnostics; using System.Runtime.Serialization.Formatters.Binary; using Remotely_ScreenCast.Utilities; +using System.Threading; namespace Remotely_ScreenCast.Capture { @@ -24,6 +25,7 @@ namespace Remotely_ScreenCast.Capture public bool CaptureFullscreen { get; set; } = true; public int PauseForMilliseconds { get; set; } public EventHandler ScreenChanged { get; set; } + private Stopwatch FramerateTimer { get; } = Stopwatch.StartNew(); public int SelectedScreen { get @@ -60,6 +62,9 @@ namespace Remotely_ScreenCast.Capture PreviousFrame = new Bitmap(CurrentScreenBounds.Width, CurrentScreenBounds.Height, PixelFormat.Format32bppArgb); graphic = Graphics.FromImage(CurrentFrame); desktopName = Win32Interop.GetCurrentDesktop(); + + Debug.WriteLine($"Starting BitBltCapture."); + Debug.WriteLine($"Current Desktop: {desktopName}"); } public void Capture() @@ -74,6 +79,12 @@ namespace Remotely_ScreenCast.Capture Logger.Write($"Set thread desktop: {success}"); } + // Keep framerate below 30 FPS. + if (FramerateTimer.Elapsed.TotalMilliseconds > 33) + { + Thread.Sleep((int)FramerateTimer.Elapsed.TotalMilliseconds); + } + FramerateTimer.Restart(); PreviousFrame = (Bitmap)CurrentFrame.Clone(); diff --git a/Remotely_ScreenCast/Capture/DXCapture.cs b/Remotely_ScreenCast/Capture/DXCapture.cs index 26d8319d..7c6228c3 100644 --- a/Remotely_ScreenCast/Capture/DXCapture.cs +++ b/Remotely_ScreenCast/Capture/DXCapture.cs @@ -24,6 +24,7 @@ namespace Remotely_ScreenCast.Capture public Rectangle CurrentScreenBounds { get; private set; } public bool CaptureFullscreen { get; set; } = true; public EventHandler ScreenChanged { get; set; } + private Stopwatch FramerateTimer { get; } = Stopwatch.StartNew(); public int SelectedScreen { get @@ -71,9 +72,9 @@ namespace Remotely_ScreenCast.Capture private void Init() { - desktopName = Win32Interop.GetCurrentDesktop(); + desktopName = Win32Interop.GetCurrentDesktop(); - factory = new Factory1(); + factory = new Factory1(); //Get first adapter adapter = factory.Adapters1.FirstOrDefault(x => x.Outputs.Length > 0); @@ -119,7 +120,10 @@ namespace Remotely_ScreenCast.Capture screenTexture = new Texture2D(device, textureDesc); duplicatedOutput = output1.DuplicateOutput(device); - } + Debug.WriteLine($"Starting DXCapture."); + Debug.WriteLine($"Current Desktop: {desktopName}"); + + } public void Capture() { try @@ -130,21 +134,26 @@ namespace Remotely_ScreenCast.Capture NeedsInit = false; } var currentDesktop = Win32Interop.GetCurrentDesktop(); - Console.WriteLine($"Using DXCapture."); - Console.WriteLine($"Current Desktop: {currentDesktop}"); if (currentDesktop != desktopName) { desktopName = currentDesktop; var inputDesktop = Win32Interop.OpenInputDesktop(); var success = User32.SetThreadDesktop(inputDesktop); User32.CloseDesktop(inputDesktop); - Logger.Write($"Set thread desktop: {success}"); + Logger.Write($"Set thread desktop to {currentDesktop}: {success}"); return; } SharpDX.DXGI.Resource screenResource; OutputDuplicateFrameInformation duplicateFrameInformation; + // Keep framerate below 30 FPS. + if (FramerateTimer.Elapsed.TotalMilliseconds > 33) + { + Thread.Sleep((int)FramerateTimer.Elapsed.TotalMilliseconds); + } + FramerateTimer.Restart(); + // Try to get duplicated frame within given time is ms duplicatedOutput.AcquireNextFrame(50, out duplicateFrameInformation, out screenResource); diff --git a/Remotely_ScreenCast/Program.cs b/Remotely_ScreenCast/Program.cs index e5184f17..39b92441 100644 --- a/Remotely_ScreenCast/Program.cs +++ b/Remotely_ScreenCast/Program.cs @@ -27,6 +27,7 @@ namespace Remotely_ScreenCast public static bool DisconnectRequested { get; set; } public static string Mode { get; private set; } public static string RequesterID { get; private set; } + public static string ServiceID { get; private set; } public static string Host { get; private set; } public static HubConnection Connection { get; private set; } public static OutgoingMessages OutgoingMessages { get; private set; } diff --git a/Remotely_Server/appsettings.json b/Remotely_Server/appsettings.json index 6dae29aa..4248c3e5 100644 --- a/Remotely_Server/appsettings.json +++ b/Remotely_Server/appsettings.json @@ -16,7 +16,7 @@ "UseDomainAuthentication": false, "ShowMessageOfTheDay": true, "DataRetentionInDays": 90, - "RemoteControlSessionLimit": 1, + "RemoteControlSessionLimit": 5, "IceConfiguration": { "iceServers": [ { "urls": "stun:" },