/////////////////////////////////////////////////////////////////////////////// // Small helping Methods // /////////////////////////////////////////////////////////////////////////////// #region HELPER /// <summary> /// loop through the list of the differnet sizes and FPS /// </summary> /// <param name="lst"></param> /// <param name="instance"></param> /// <returns></returns> private bool inSizeFpsList(List <CamSizeFPS> lst, CamSizeFPS instance) { foreach (CamSizeFPS c in lst) { if (c.CompareTo(instance) == 0) { return(true); } } return(false); }
public int CompareTo(object obj) { if (obj is CamSizeFPS) { CamSizeFPS csf = (CamSizeFPS)obj; return((csf.Height + csf.Width + csf.FPS).CompareTo(this.Height + this.Width + this.FPS)); } else { throw new ArgumentException("Object is not a CamSizeFPS"); } }
private bool ParametersOK(CamSizeFPS instance) { if (instance.FPS < minFps || instance.FPS > maxFps) { return(false); } if (instance.Width < minWidth || instance.Width > maxWidth) { return(false); } if (instance.Height < minHeight || instance.Height > maxHeight) { return(false); } return(true); }
/// <summary> /// Returns the <see cref="CameraInfo"/> for the given <see cref="DsDevice"/>. /// </summary> /// <param name="dev">A <see cref="DsDevice"/> to parse name and capabilities for.</param> /// <returns>The <see cref="CameraInfo"/> for the given device.</returns> private CameraInfo Caps(DsDevice dev) { CameraInfo camerainfo = new CameraInfo(); try { int hr; // Get the graphbuilder object m_graphBuilder = (IFilterGraph2) new FilterGraph(); // Get the ICaptureGraphBuilder2 capGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2(); // Add the video device hr = m_graphBuilder.AddSourceFilterForMoniker(dev.Mon, null, "Video input", out capFilter); //DsError.ThrowExceptionForHR(hr); if (hr != 0) { return(null); } hr = capGraph.SetFiltergraph(m_graphBuilder); DsError.ThrowExceptionForHR(hr); hr = m_graphBuilder.AddFilter(capFilter, "Ds.NET Video Capture Device"); DsError.ThrowExceptionForHR(hr); object o = null; DsGuid cat = PinCategory.Capture; DsGuid type = MediaType.Interleaved; DsGuid iid = typeof(IAMStreamConfig).GUID; // Check if Video capture filter is in use hr = capGraph.RenderStream(cat, MediaType.Video, capFilter, null, null); if (hr != 0) { return(null); } //hr = capGraph.FindInterface(PinCategory.Capture, MediaType.Interleaved, capFilter, typeof(IAMStreamConfig).GUID, out o); //if (hr != 0) //{ hr = capGraph.FindInterface(PinCategory.Capture, MediaType.Video, capFilter, typeof(IAMStreamConfig).GUID, out o); DsError.ThrowExceptionForHR(hr); //} IAMStreamConfig videoStreamConfig = o as IAMStreamConfig; int iCount = 0; int iSize = 0; try { videoStreamConfig.GetNumberOfCapabilities(out iCount, out iSize); } catch (Exception ex) { ErrorLogger.ProcessException(ex, false); return(null); } pscc = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(VideoStreamConfigCaps))); camerainfo.Name = dev.Name; camerainfo.DirectshowDevice = dev; for (int i = 0; i < iCount; i++) { AMMediaType curMedType; VideoStreamConfigCaps scc; try { hr = videoStreamConfig.GetStreamCaps(i, out curMedType, pscc); Marshal.ThrowExceptionForHR(hr); scc = (VideoStreamConfigCaps)Marshal.PtrToStructure(pscc, typeof(VideoStreamConfigCaps)); CamSizeFPS CSF = new CamSizeFPS(); CSF.FPS = (int)(10000000 / scc.MinFrameInterval); CSF.Height = scc.InputSize.Height; CSF.Width = scc.InputSize.Width; if (!inSizeFpsList(camerainfo.SupportedSizesAndFPS, CSF)) { if (ParametersOK(CSF)) { camerainfo.SupportedSizesAndFPS.Add(CSF); } } } catch (Exception ex) { ErrorLogger.ProcessException(ex, false); } } } finally { } return(camerainfo); }