Fixed DXCapture.

This commit is contained in:
Jared Goodwin 2019-12-27 23:52:26 -08:00
parent c6212c2e8c
commit f3e368543b
8 changed files with 50 additions and 40 deletions

View File

@ -81,9 +81,11 @@ namespace Remotely.ScreenCast.Core.Capture
}
}
while (viewer.PendingFrames > 10)
while (viewer.PendingFrames > 10000 / viewer.Latency)
{
await Task.Delay(1);
await Task.Delay(10);
}
capturer.Capture();

View File

@ -271,12 +271,13 @@ namespace Remotely.ScreenCast.Core.Sockets
conductor.InvokeViewerRemoved(viewerID);
});
Connection.On("LatencyUpdate", (double latency, string viewerID) =>
Connection.On("LatencyUpdate", (DateTime sentTime, string viewerID) =>
{
if (conductor.Viewers.TryGetValue(viewerID, out var viewer))
{
viewer.PendingFrames--;
viewer.Latency = latency;
var latency = DateTime.UtcNow - sentTime;
viewer.Latency = latency.TotalMilliseconds;
}
});

View File

@ -44,7 +44,6 @@ namespace Remotely.ScreenCast.Win.Capture
{
if (NeedsInit)
{
duplicatedOutput?.Dispose();
Init();
}
@ -58,17 +57,26 @@ namespace Remotely.ScreenCast.Win.Capture
while (duplicateFrameInformation.AccumulatedFrames < 1)
{
duplicatedOutput.ReleaseFrame();
duplicatedOutput.TryAcquireNextFrame(50, out duplicateFrameInformation, out screenResource);
var result = duplicatedOutput.TryAcquireNextFrame(50, out duplicateFrameInformation, out screenResource);
if (result.Failure)
{
try
{
duplicatedOutput.ReleaseFrame();
}
catch { }
}
}
// copy resource into memory that can be accessed by the CPU
using (var screenTexture2D = screenResource.QueryInterface<Texture2D>())
{
device.ImmediateContext.CopyResource(screenTexture2D, screenTexture);
}
// Get the desktop capture texture
var mapSource = device.ImmediateContext.MapSubresource(screenTexture, 0, MapMode.Read, SharpDX.Direct3D11.MapFlags.None);
// Create Drawing.Bitmap
using (var bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb))
{
@ -137,6 +145,8 @@ namespace Remotely.ScreenCast.Win.Capture
public void Init()
{
Dispose();
factory = new Factory1();
//Get first adapter

View File

@ -31,27 +31,25 @@ namespace Remotely.ScreenCast.Win.Services
private static ICapturer GetCapturer()
{
return new BitBltCapture();
// TODO: DXCapture is leaking in the WPF app.
//ICapturer capturer;
//try
//{
// if (Conductor.Current.Viewers.Count == 0)
// {
// capturer = new DXCapture();
// }
// else
// {
// capturer = new BitBltCapture();
// }
//}
//catch (Exception ex)
//{
// Logger.Write(ex);
// capturer = new BitBltCapture();
//}
ICapturer capturer;
try
{
if (Conductor.Current.Viewers.Count == 0)
{
capturer = new DXCapture();
}
else
{
capturer = new BitBltCapture();
}
}
catch (Exception ex)
{
Logger.Write(ex);
capturer = new BitBltCapture();
}
//return capturer;
return capturer;
}
}
}

View File

@ -150,9 +150,9 @@ namespace Remotely.Server.Services
await RCDeviceHub.Clients.Client(ScreenCasterID).SendAsync("ClipboardTransfer", transferText, typeText, Context.ConnectionId);
}
public async Task SendLatencyUpdate(double latency)
public async Task SendLatencyUpdate(DateTime sentTime)
{
await RCDeviceHub.Clients.Client(ScreenCasterID).SendAsync("LatencyUpdate", latency, Context.ConnectionId);
await RCDeviceHub.Clients.Client(ScreenCasterID).SendAsync("LatencyUpdate", sentTime, Context.ConnectionId);
}
public async Task SendQualityChange(int qualityLevel)

View File

@ -36,8 +36,8 @@ export class RCBrowserSockets {
SendScreenCastRequestToDevice() {
this.Connection.invoke("SendScreenCastRequestToDevice", RemoteControl.ClientID, RemoteControl.RequesterName, RemoteControl.Mode);
}
SendLatencyUpdate(latency) {
this.Connection.invoke("SendLatencyUpdate", latency);
SendLatencyUpdate(sentTime) {
this.Connection.invoke("SendLatencyUpdate", sentTime);
}
SendSelectScreen(index) {
this.Connection.invoke("SelectScreen", index);
@ -125,8 +125,7 @@ export class RCBrowserSockets {
UI.Screen2DContext.clearRect(0, 0, width, height);
});
hubConnection.on("ScreenCapture", (buffer, left, top, width, height, captureTime) => {
var latency = Date.now() - new Date(captureTime).getTime();
this.SendLatencyUpdate(latency);
this.SendLatencyUpdate(captureTime);
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

@ -49,8 +49,8 @@ export class RCBrowserSockets {
SendScreenCastRequestToDevice() {
this.Connection.invoke("SendScreenCastRequestToDevice", RemoteControl.ClientID, RemoteControl.RequesterName, RemoteControl.Mode);
}
SendLatencyUpdate(latency: number) {
this.Connection.invoke("SendLatencyUpdate", latency);
SendLatencyUpdate(sentTime: Date) {
this.Connection.invoke("SendLatencyUpdate", sentTime);
}
SendSelectScreen(index: number) {
this.Connection.invoke("SelectScreen", index);
@ -138,8 +138,8 @@ export class RCBrowserSockets {
UI.Screen2DContext.clearRect(0, 0, width, height);
});
hubConnection.on("ScreenCapture", (buffer: Uint8Array, left:number, top:number, width:number, height:number, captureTime: Date) => {
var latency = Date.now() - new Date(captureTime).getTime();
this.SendLatencyUpdate(latency);
this.SendLatencyUpdate(captureTime);
var url = window.URL.createObjectURL(new Blob([buffer]));
var img = document.createElement("img");