コード例 #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)
        {
            var camerainfo = new CameraInfo();

            try
            {
                // Get the graphbuilder object
                m_graphBuilder = (IFilterGraph2) new FilterGraph();

                // Get the ICaptureGraphBuilder2
                capGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

                // Add the video device
                int 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);
                //}

                var videoStreamConfig = o as IAMStreamConfig;

                int iCount = 0;
                int iSize  = 0;

                try
                {
                    if (videoStreamConfig != null)
                    {
                        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++)
                {
                    VideoStreamConfigCaps scc;

                    try
                    {
                        AMMediaType curMedType;
                        if (videoStreamConfig != null)
                        {
                            hr = videoStreamConfig.GetStreamCaps(i, out curMedType, pscc);
                        }
                        Marshal.ThrowExceptionForHR(hr);
                        scc = (VideoStreamConfigCaps)Marshal.PtrToStructure(pscc, typeof(VideoStreamConfigCaps));


                        var 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);
        }