Working on quality reduction.

This commit is contained in:
Jared Goodwin 2019-03-09 17:36:18 -08:00
parent 444a13c954
commit 4a4e6c40a4
15 changed files with 36 additions and 81 deletions

View File

@ -103,6 +103,10 @@ namespace Remotely_Agent.Services
ps.Invoke();
ps.Commands.Clear();
}
else if (OSUtils.IsLinux)
{
Process.Start("sudo", "systemctl stop remotely_service");
}
ps.AddScript(@"
Get-Process | Where-Object {
@ -159,54 +163,5 @@ namespace Remotely_Agent.Services
Environment.Exit(0);
}
}
internal static async Task DownloadLatestScreenCastVersion(HubConnection hubConnection, string requesterID)
{
if (!OSUtils.IsWindows)
{
return;
}
var fileName = OSUtils.ScreenCastZipFileName;
var wc = new WebClient();
var progress = 0;
wc.DownloadProgressChanged += async (sender, args) =>
{
if (args.ProgressPercentage - progress > 5)
{
progress = args.ProgressPercentage;
await hubConnection.InvokeAsync("DisplayConsoleMessage", $"Download progress: {args.ProgressPercentage}%", requesterID);
}
};
var done = false;
wc.DownloadFileCompleted += async (sender, args) =>
{
await hubConnection.InvokeAsync("DisplayConsoleMessage", $"Download completed.", requesterID);
done = true;
};
var rcDir = Directory.CreateDirectory(Path.Combine(Utilities.AppDataDir, "remote_control")).FullName;
var downloadFilePath = Path.Combine(rcDir, fileName);
if (File.Exists(downloadFilePath))
{
File.Delete(downloadFilePath);
}
wc.DownloadFileAsync(new Uri(Utilities.GetConnectionInfo().Host + $"/Downloads/{fileName}"), downloadFilePath);
while (!done)
{
await Task.Delay(100);
}
await hubConnection.InvokeAsync("DisplayConsoleMessage", "Extracting files...", requesterID);
if (OSUtils.IsWindows)
{
ZipFile.ExtractToDirectory(downloadFilePath, Path.Combine(Utilities.AppDataDir, "remote_control"), true);
}
//if (OSUtils.IsLinux)
//{
// // ZipFile doesn't extract nested directories properly on Linux, so...
// Directory.SetCurrentDirectory(rcDir);
// Process.Start("apt-get", "install unzip").WaitForExit();
// Process.Start("unzip", $"-o {fileName}").WaitForExit();
// Process.Start("chmod", "755 " + Path.Combine(Utilities.AppDataDir, "remote_control", "remotely_remote_control")).WaitForExit();
//}
}
}
}

View File

@ -12,7 +12,7 @@ using System.Threading.Tasks;
namespace Remotely_ScreenCast.Capture
{
public class ImageDiff
public class ImageUtils
{
private static EncoderParameters EncoderParams { get; } = new EncoderParameters()
{
@ -92,14 +92,6 @@ namespace Remotely_ScreenCast.Capture
return mergedFrame;
}
public static byte[] EncodeBitmapAndResize(Bitmap bitmap)
{
using (var ms = new MemoryStream())
{
bitmap.Save(ms, CodecInfo, EncoderParams);
return ms.ToArray();
}
}
public static byte[] EncodeBitmap(Bitmap bitmap)
{
using (var ms = new MemoryStream())

View File

@ -95,24 +95,38 @@ namespace Remotely_ScreenCast.Capture
// continue;
//}
//if (viewer.NextCaptureDelay > 0)
//{
// await Task.Delay((int)viewer.NextCaptureDelay);
// viewer.NextCaptureDelay = 0;
//}
while (viewer.PendingFrames > 10)
{
await Task.Delay(1);
}
capturer.Capture();
var newImage = ImageDiff.GetImageDiff(capturer.CurrentFrame, capturer.PreviousFrame, capturer.CaptureFullscreen);
var newImage = ImageUtils.GetImageDiff(capturer.CurrentFrame, capturer.PreviousFrame, capturer.CaptureFullscreen);
if (viewer.PendingFrames > 5)
{
var reductionRatio = (double)5 / viewer.PendingFrames;
Logger.Write($"Reducing image quality to {reductionRatio}.");
newImage = new Bitmap(
capturer.CurrentFrame,
(int)(capturer.CurrentScreenBounds.Width * reductionRatio),
(int)(capturer.CurrentScreenBounds.Height * reductionRatio));
}
if (capturer.CaptureFullscreen)
{
capturer.CaptureFullscreen = false;
}
var img = ImageDiff.EncodeBitmapAndResize(newImage);
var img = ImageUtils.EncodeBitmap(newImage);
if (img?.Length > 0)
{
await outgoingMessages.SendScreenCapture(img, viewerID, DateTime.UtcNow);
viewer.PendingFrames++;
}
}
catch (Exception ex)

View File

@ -1,6 +1,7 @@
using Remotely_ScreenCast.Capture;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -14,5 +15,7 @@ namespace Remotely_ScreenCast.Models
public ICapturer Capturer { get; set; }
public bool DisconnectRequested { get; set; }
public bool HasControl { get; set; }
public double Latency { get; set; }
public int PendingFrames { get; set; }
}
}

View File

@ -151,7 +151,7 @@
<Compile Include="Capture\CursorIconWatcher.cs" />
<Compile Include="Capture\DXCapture.cs" />
<Compile Include="Capture\ICapturer.cs" />
<Compile Include="Capture\ImageDiff.cs" />
<Compile Include="Capture\ImageUtils.cs" />
<Compile Include="Capture\ScreenCaster.cs" />
<Compile Include="Enums\AppMode.cs" />
<Compile Include="Models\Viewer.cs" />

View File

@ -173,8 +173,8 @@ namespace Remotely_ScreenCast.Sockets
{
if (Program.Viewers.TryGetValue(viewerID, out var viewer))
{
// TODO.
//viewer.Capturer.NextCaptureDelay = delayTime;
viewer.PendingFrames--;
viewer.Latency = latency;
}
});

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@ -2,7 +2,6 @@ import * as UI from "./UI.js";
import { RemoteControl } from "./RemoteControl.js";
import { GetCursor } from "./CursorMap.js";
var signalR = window["signalR"];
var lastLatency = Date.now();
export class RCBrowserSockets {
Connect() {
this.Connection = new signalR.HubConnectionBuilder()
@ -34,7 +33,6 @@ export class RCBrowserSockets {
}
SendLatencyUpdate(latency, payloadSize) {
this.Connection.invoke("SendLatencyUpdate", latency, payloadSize);
console.log(`Sending latency update. Latency:${latency}. Size: ${payloadSize}`);
}
SendSelectScreen(index) {
return this.Connection.invoke("SelectScreen", index);
@ -108,10 +106,7 @@ export class RCBrowserSockets {
});
hubConnection.on("ScreenCapture", (buffer, captureTime) => {
var latency = Date.now() - new Date(captureTime).getTime();
if (latency > 3000 && Date.now() - lastLatency > 3000) {
this.SendLatencyUpdate(latency, buffer.length);
lastLatency = Date.now();
}
this.SendLatencyUpdate(latency, buffer.length);
var url = window.URL.createObjectURL(new Blob([buffer]));
var img = document.createElement("img");
img.onload = () => {

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,6 @@ import { RemoteControl } from "./RemoteControl.js";
import { GetCursor } from "./CursorMap.js";
var signalR = window["signalR"];
var lastLatency = Date.now();
export class RCBrowserSockets {
Connection: any;
@ -41,7 +40,6 @@ export class RCBrowserSockets {
}
SendLatencyUpdate(latency: number, payloadSize: number) {
this.Connection.invoke("SendLatencyUpdate", latency, payloadSize);
console.log(`Sending latency update. Latency:${latency}. Size: ${payloadSize}`)
}
SendSelectScreen(index: number) {
return this.Connection.invoke("SelectScreen", index);
@ -116,10 +114,8 @@ export class RCBrowserSockets {
});
hubConnection.on("ScreenCapture", (buffer: Uint8Array, captureTime: Date) => {
var latency = Date.now() - new Date(captureTime).getTime();
if (latency > 3000 && Date.now() - lastLatency > 3000) {
this.SendLatencyUpdate(latency, buffer.length);
lastLatency = Date.now();
}
this.SendLatencyUpdate(latency, buffer.length);
var url = window.URL.createObjectURL(new Blob([buffer]));
var img = document.createElement("img");
img.onload = () => {