コード例 #1
0
 public bool Matches(SupportedVideoFormat compareTo)
 {
     return
         (Width == compareTo.Width &&
          Height == compareTo.Height &&
          Math.Abs(FrameRate - compareTo.FrameRate) < 0.01 &&
          BitCount == compareTo.BitCount);
 }
コード例 #2
0
        private static void DoSupportedVideoFormatsOperation(string deviceName, SupportedVideoFormatCallback callback)
        {
            IGraphBuilder         graphBuilder        = null;
            ICaptureGraphBuilder2 captureGraphBuilder = null;
            IBaseFilter           theDevice           = null;

            try
            {
                graphBuilder        = (IGraphBuilder) new FilterGraph();
                captureGraphBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();
                theDevice           = CreateFilter(FilterCategory.VideoInputDevice, deviceName);

                // Attach the filter graph to the capture graph
                int hr = captureGraphBuilder.SetFiltergraph(graphBuilder);
                DsError.ThrowExceptionForHR(hr);

                // Add the Video input device to the graph
                hr = graphBuilder.AddFilter(theDevice, "source filter");
                DsError.ThrowExceptionForHR(hr);

                object o;
                // AMMediaType media;
                IAMStreamConfig videoStreamConfig;
                IAMVideoControl videoControl = theDevice as IAMVideoControl;

                hr = captureGraphBuilder.FindInterface(PinCategory.Capture, MediaType.Video, theDevice, typeof(IAMStreamConfig).GUID, out o);
                DsError.ThrowExceptionForHR(hr);

                videoStreamConfig = o as IAMStreamConfig;
                try
                {
                    if (videoStreamConfig == null)
                    {
                        throw new Exception("Failed to get IAMStreamConfig");
                    }

                    int iCount = 0, iSize = 0;
                    videoStreamConfig.GetNumberOfCapabilities(out iCount, out iSize);

                    IntPtr taskMemPointer = Marshal.AllocCoTaskMem(iSize);

                    AMMediaType pmtConfig = null;
                    for (int iFormat = 0; iFormat < iCount; iFormat++)
                    {
                        IntPtr ptr = IntPtr.Zero;

                        videoStreamConfig.GetStreamCaps(iFormat, out pmtConfig, taskMemPointer);

                        var v2 = (VideoInfoHeader)Marshal.PtrToStructure(pmtConfig.formatPtr, typeof(VideoInfoHeader));

                        if (v2.BmiHeader.BitCount > 0)
                        {
                            var entry = new SupportedVideoFormat()
                            {
                                Width     = v2.BmiHeader.Width,
                                Height    = v2.BmiHeader.Height,
                                BitCount  = v2.BmiHeader.BitCount,
                                FrameRate = 10000000.0 / v2.AvgTimePerFrame
                            };

                            callback(entry);

                            Trace.WriteLine(entry.AsSerialized());
                        }
                    }

                    Marshal.FreeCoTaskMem(taskMemPointer);
                    DsUtils.FreeAMMediaType(pmtConfig);
                }
                finally
                {
                    Marshal.ReleaseComObject(videoStreamConfig);
                }
            }
            finally
            {
                if (theDevice != null)
                {
                    Marshal.ReleaseComObject(theDevice);
                }

                if (graphBuilder != null)
                {
                    Marshal.ReleaseComObject(graphBuilder);
                }

                if (captureGraphBuilder != null)
                {
                    Marshal.ReleaseComObject(captureGraphBuilder);
                }
            }
        }
コード例 #3
0
ファイル: VideoFormatHelper.cs プロジェクト: hpavlov/occurec
 public SupportedVideoFormat(SupportedVideoFormat cloneFrom)
 {
     Width = cloneFrom.Width;
     Height = cloneFrom.Height;
     FrameRate = cloneFrom.FrameRate;
     BitCount = cloneFrom.BitCount;
 }
コード例 #4
0
ファイル: VideoFormatHelper.cs プロジェクト: hpavlov/occurec
 public bool Matches(SupportedVideoFormat compareTo)
 {
     return
         Width == compareTo.Width &&
         Height == compareTo.Height &&
         Math.Abs(FrameRate - compareTo.FrameRate) < 0.01 &&
         BitCount  == compareTo.BitCount;
 }
コード例 #5
0
ファイル: VideoFormatHelper.cs プロジェクト: hpavlov/occurec
        private static void DoSupportedVideoFormatsOperation(string deviceName, SupportedVideoFormatCallback callback)
        {
            IGraphBuilder graphBuilder = null;
            ICaptureGraphBuilder2 captureGraphBuilder = null;
            IBaseFilter theDevice = null;

            try
            {
                graphBuilder = (IGraphBuilder)new FilterGraph();
                captureGraphBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
                theDevice = CreateFilter(FilterCategory.VideoInputDevice, deviceName);

                // Attach the filter graph to the capture graph
                int hr = captureGraphBuilder.SetFiltergraph(graphBuilder);
                DsError.ThrowExceptionForHR(hr);

                // Add the Video input device to the graph
                hr = graphBuilder.AddFilter(theDevice, "source filter");
                DsError.ThrowExceptionForHR(hr);

                object o;
                AMMediaType media;
                IAMStreamConfig videoStreamConfig;
                IAMVideoControl videoControl = theDevice as IAMVideoControl;

                hr = captureGraphBuilder.FindInterface(PinCategory.Capture, MediaType.Video, theDevice, typeof(IAMStreamConfig).GUID, out o);
                DsError.ThrowExceptionForHR(hr);

                videoStreamConfig = o as IAMStreamConfig;
                try
                {
                    if (videoStreamConfig == null)
                    {
                        throw new Exception("Failed to get IAMStreamConfig");
                    }

                    int iCount = 0, iSize = 0;
                    videoStreamConfig.GetNumberOfCapabilities(out iCount, out iSize);

                    IntPtr taskMemPointer = Marshal.AllocCoTaskMem(iSize);

                    AMMediaType pmtConfig = null;
                    Trace.WriteLine(string.Format("Video formats supported by {0}:", deviceName));
                    for (int iFormat = 0; iFormat < iCount; iFormat++)
                    {
                        IntPtr ptr = IntPtr.Zero;

                        videoStreamConfig.GetStreamCaps(iFormat, out pmtConfig, taskMemPointer);

                        var v2 = (VideoInfoHeader)Marshal.PtrToStructure(pmtConfig.formatPtr, typeof(VideoInfoHeader));

                        if (v2.BmiHeader.BitCount > 0)
                        {
                            var entry = new SupportedVideoFormat()
                            {
                                Width = v2.BmiHeader.Width,
                                Height = v2.BmiHeader.Height,
                                BitCount = v2.BmiHeader.BitCount,
                                FrameRate = 10000000.0 / v2.AvgTimePerFrame
                            };

                            if (Math.Abs(entry.FrameRate - 0) < 0.01 || double.IsNaN(entry.FrameRate) || double.IsInfinity(entry.FrameRate))
                            {
                                // Some drivers don't report a frame rate or report incorrect frame rate. In this caasea dd both PAL and NTSC frame rates
                                entry.FrameRate = 25.0;
                                callback(entry);

                                var entry2 = new SupportedVideoFormat(entry);
                                entry2.FrameRate = 29.97;
                                callback(entry2);
                            }
                            else
                                callback(entry);

                            Trace.WriteLine(entry.AsSerialized());
                        }
                    }

                    Marshal.FreeCoTaskMem(taskMemPointer);
                    DsUtils.FreeAMMediaType(pmtConfig);
                }
                finally
                {
                    Marshal.ReleaseComObject(videoStreamConfig);
                }
            }
            finally
            {
                if (theDevice != null)
                    Marshal.ReleaseComObject(theDevice);

                if (graphBuilder != null)
                    Marshal.ReleaseComObject(graphBuilder);

                if (captureGraphBuilder != null)
                    Marshal.ReleaseComObject(captureGraphBuilder);
            }
        }