some stability changes to webcam support

This commit is contained in:
Alexander Eckart committed 2013-01-04 11:09:47 +01:00
1 parent d5889e4c4c
commit 5388b6f816
2 files changed
+34 -25

No files matched your search

+5 -5
View File
@@ -21,7 +21,7 @@ namespace Vocaluxe.Lib.Webcam
private VideoCaptureDevice _Webcam;
private FilterInfoCollection _WebcamDevices;
private SWebcamConfig _Config;
byte[] data;
byte[] data = new byte[1];
int _Width, _Height;
public void Close()
@@ -31,13 +31,13 @@ namespace Vocaluxe.Lib.Webcam
_Webcam.SignalToStop();
_Webcam.WaitForStop();
_Webcam.NewFrame -= new NewFrameEventHandler(OnFrame);
data = null;
data = new byte[1];
}
}
public bool GetFrame(ref STexture Frame)
{
if (_Webcam != null && data != null && _Width > 0 && _Height > 0)
if (_Webcam != null && _Width > 0 && _Height > 0 && data.Length == _Width * _Height * 4)
{
lock (data)
{
@@ -57,7 +57,7 @@ namespace Vocaluxe.Lib.Webcam
public Bitmap GetBitmap()
{
if (data != null && _Webcam != null && _Width > 0 && _Height > 0)
if (_Webcam != null && _Width > 0 && _Height > 0 && data.Length == _Height * _Width * 4)
{
lock (data)
{
@@ -108,7 +108,7 @@ namespace Vocaluxe.Lib.Webcam
{
lock (data)
{
if (_Width != e.Frame.Width || _Height != e.Frame.Height || data == null)
if (_Width != e.Frame.Width || _Height != e.Frame.Height || data.Length != e.Frame.Width * e.Frame.Height * 4)
data = new byte[4 * e.Frame.Width * e.Frame.Height];
_Width = e.Frame.Width;
+29 -20
View File
@@ -165,33 +165,42 @@ namespace Vocaluxe.Screens
SWebcamDevice[] devices = CWebcam.GetDevices();
if (devices != null)
try
{
if (devices.Length > 0)
if (devices != null)
{
_DeviceNr = 0;
_CapabilityNr = 0;
GetFirstConfiguredWebcamDevice(ref _DeviceNr, ref _CapabilityNr);
foreach (SWebcamDevice d in devices)
if (devices.Length > 0)
{
SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].AddValue(d.Name);
}
SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection = _DeviceNr;
_DeviceNr = 0;
_CapabilityNr = 0;
GetFirstConfiguredWebcamDevice(ref _DeviceNr, ref _CapabilityNr);
foreach (SCapabilities c in devices[_DeviceNr].Capabilities)
{
SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].AddValue(c.Width.ToString() + " x " + c.Height.ToString() + " @ " + c.Framerate.ToString() + " FPS ");
foreach (SWebcamDevice d in devices)
{
SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].AddValue(d.Name);
}
SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection = _DeviceNr;
foreach (SCapabilities c in devices[_DeviceNr].Capabilities)
{
SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].AddValue(c.Width.ToString() + " x " + c.Height.ToString() + " @ " + c.Framerate.ToString() + " FPS ");
}
_Config.MonikerString = devices[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].MonikerString;
_Config.Width = devices[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Width;
_Config.Height = devices[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Height;
_Config.Framerate = devices[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Framerate;
CWebcam.Close();
CWebcam.Select(CConfig.WebcamConfig);
CWebcam.Start();
}
_Config.MonikerString = devices[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].MonikerString;
_Config.Width = devices[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Width;
_Config.Height = devices[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Height;
_Config.Framerate = devices[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Framerate;
CWebcam.Close();
CWebcam.Select(CConfig.WebcamConfig);
CWebcam.Start();
}
}
catch (Exception e)
{
CLog.LogError("Error on listing webcam capabilities: " + e.Message);
devices = null;
}
SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Visible = (devices != null && devices.Length > 0);
SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Visible = (devices != null && devices.Length > 0);
Statics[htStatics(StaticWebcamOutput)].Visible = (devices != null && devices.Length > 0);