Skip to content

Commit

Permalink
Re-implement auto quality toggle.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed May 8, 2021
1 parent 85c4fad commit a606372
Show file tree
Hide file tree
Showing 34 changed files with 129 additions and 45 deletions.
8 changes: 8 additions & 0 deletions Desktop.Core/Services/DtoMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public async Task ParseMessage(Viewer viewer, byte[] message)
case BaseDtoType.CtrlAltDel:
await viewer.SendCtrlAltDel();
break;
case BaseDtoType.ToggleAutoQuality:
ToggleAutoQuality(message, viewer);
break;
case BaseDtoType.ToggleAudio:
ToggleAudio(message);
break;
Expand Down Expand Up @@ -261,6 +264,11 @@ private void ToggleAudio(byte[] message)
var dto = MessagePackSerializer.Deserialize<ToggleAudioDto>(message);
AudioCapturer.ToggleAudio(dto.ToggleOn);
}
private void ToggleAutoQuality(byte[] message, Viewer viewer)
{
var dto = MessagePackSerializer.Deserialize<ToggleAutoQualityDto>(message);
viewer.AutoQuality = dto.ToggleOn;
}

private void ToggleBlockInput(byte[] message)
{
Expand Down
11 changes: 7 additions & 4 deletions Desktop.Core/Services/ScreenCaster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ await viewer.SendScreenCapture(new CaptureFrame()
continue;
}

if (refreshTimer.Elapsed.TotalSeconds > 10 ||
refreshNeeded && refreshTimer.Elapsed.TotalSeconds > 5)
if (refreshNeeded && refreshTimer.Elapsed.TotalSeconds > 5)
{
viewer.Capturer.CaptureFullscreen = true;
}
Expand Down Expand Up @@ -179,12 +178,16 @@ await viewer.SendScreenCapture(new CaptureFrame()
}
else
{
if (viewer.AverageBytesPerSecond > 0)
if (!viewer.AutoQuality)
{
currentQuality = _maxQuality;
}
else if (viewer.AverageBytesPerSecond > 0)
{
var expectedSize = diffArea.Height * diffArea.Width * 4 * .1;
var timeToSend = expectedSize / viewer.AverageBytesPerSecond;
currentQuality = Math.Max(_minQuality, Math.Min(_maxQuality, (int)(.1 / timeToSend * _maxQuality)));
if (currentQuality < _maxQuality - 10)
if (currentQuality < _maxQuality - 5)
{
refreshNeeded = true;
Debug.WriteLine($"Quality Reduced: {currentQuality}");
Expand Down
2 changes: 2 additions & 0 deletions Desktop.Core/Services/Viewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public Viewer(ICasterSocket casterSocket,
public bool DisconnectRequested { get; set; }
public EncoderParameters EncoderParams { get; private set; }
public bool HasControl { get; set; } = true;
public bool AutoQuality { get; set; } = true;
public bool IsConnected => CasterSocket.IsConnected;

public bool IsStalled
Expand Down Expand Up @@ -78,6 +79,7 @@ public bool IsUsingWebRtcVideo
public string ViewerConnectionID { get; set; }
private IAudioCapturer AudioCapturer { get; }


private ICasterSocket CasterSocket { get; }

private IClipboardService ClipboardService { get; }
Expand Down
4 changes: 4 additions & 0 deletions Server/Pages/RemoteControl.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@
</div>

<div>
<button id="autoQualityButton" class="toggled option-button" title="Automatically reduce image quality on slower connections.">
Auto Quality <i class="fas fa-image"></i>
</button>

<button id="streamVideoButton" class="option-button" hidden title="Reduce bandwidth and increase FPS, but increase input delay.">
Stream Mode <i class="fas fa-video"></i>
</button>
Expand Down
1 change: 1 addition & 0 deletions Server/wwwroot/src/RemoteControl/App.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Server/wwwroot/src/RemoteControl/App.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Server/wwwroot/src/RemoteControl/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export const ViewerApp = {

ApplyInputHandlers();

UI.UpdateAutoQualityToggled(ViewerApp.Settings.autoQuality);

if (UI.RequesterNameInput.value) {
ViewerApp.RequesterName = UI.RequesterNameInput.value;
}
Expand Down
1 change: 1 addition & 0 deletions Server/wwwroot/src/RemoteControl/DtoMessageHandler.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Server/wwwroot/src/RemoteControl/DtoMessageHandler.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Server/wwwroot/src/RemoteControl/DtoMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export class DtoMessageHandler {
}
HandleScreenData(screenDataDto: ScreenDataDto) {
UI.UpdateDisplays(screenDataDto.SelectedScreen, screenDataDto.DisplayNames);
ViewerApp.MessageSender.SendToggleAutoQuality(ViewerApp.Settings.autoQuality);
}

HandleScreenSize(screenSizeDto: ScreenSizeDto) {
Expand Down
1 change: 1 addition & 0 deletions Server/wwwroot/src/RemoteControl/Enums/BaseDtoType.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Server/wwwroot/src/RemoteControl/Enums/BaseDtoType.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Server/wwwroot/src/RemoteControl/Enums/BaseDtoType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
KeyDown = 13,
KeyUp = 14,
CtrlAltDel = 15,
ToggleAutoQuality = 16,
ToggleAudio = 17,
ToggleBlockInput = 18,
ClipboardTransfer = 19,
Expand Down
Loading

0 comments on commit a606372

Please sign in to comment.