Esempio n. 1
0
        /// <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);
        }