Пример #1
0
        /// <summary>
        /// Returns available resolutions with RGB color system for device moniker
        /// </summary>
        /// <param name="moniker">Moniker (device identification) of camera.</param>
        /// <returns>List of resolutions with RGB color system of device</returns>
        public static ResolutionList GetResolutionList(IMoniker moniker)
        {
            int hr;

            ResolutionList ResolutionsAvailable = null; //new ResolutionList();

            // Get the graphbuilder object
            IFilterGraph2 filterGraph = new FilterGraph() as IFilterGraph2;
            IBaseFilter   capFilter   = null;

            try
            {
                // add the video input device
                hr = filterGraph.AddSourceFilterForMoniker(moniker, null, "Source Filter", out capFilter);
                DsError.ThrowExceptionForHR(hr);

                ResolutionsAvailable = GetResolutionsAvailable(capFilter);
            }
            finally
            {
                SafeReleaseComObject(filterGraph);
                filterGraph = null;

                SafeReleaseComObject(capFilter);
                capFilter = null;
            }

            return(ResolutionsAvailable);
        }
Пример #2
0
        /// <summary>
        /// Gets available resolutions (which are appropriate for us) for capture filter.
        /// </summary>
        /// <param name="captureFilter">Capture filter for asking for resolution list.</param>
        public static ResolutionList GetResolutionsAvailable(IBaseFilter captureFilter)
        {
            ResolutionList resolution_list = null;

            IPin pRaw = null;

            try
            {
                pRaw = DsFindPin.ByDirection(captureFilter, PinDirection.Output, 0);
                //pRaw = DsFindPin.ByCategory(captureFilter, PinCategory.Capture, 0);
                //pRaw = DsFindPin.ByCategory(filter, PinCategory.Preview, 0);

                resolution_list = GetResolutionsAvailable(pRaw);
            }
            catch
            {
                throw;
                //resolution_list = new ResolutionList();
                //resolution_list.Add(new Resolution(640, 480));
            }
            finally
            {
                SafeReleaseComObject(pRaw);
                pRaw = null;
            }

            return(resolution_list);
        }
Пример #3
0
        /// <summary>
        /// Adds video source filter to the filter graph.
        /// </summary>
        private void GraphBuilding_AddFilter_Source()
        {
            int hr = 0;

            DX.CaptureFilter = null;
            hr = DX.FilterGraph.AddSourceFilterForMoniker(_Moniker, null, "Source Filter", out DX.CaptureFilter);
            DsError.ThrowExceptionForHR(hr);

            _ResolutionList = CameraHelpers.GetResolutionsAvailable(DX.CaptureFilter);
        }
Пример #4
0
        /// <summary>
        /// Gets available resolutions (which are appropriate for us) for capture pin (PinCategory.Capture).
        /// </summary>
        /// <param name="captureFilter">Capture pin (PinCategory.Capture) for asking for resolution list.</param>
        public static ResolutionList GetResolutionsAvailable(IPin pinOutput)
        {
            int hr = 0;

            ResolutionList ResolutionsAvailable = new ResolutionList();

            //ResolutionsAvailable.Clear();

            // Media type (shoudl be cleaned)
            AMMediaType media_type = null;

            //NOTE: pSCC is not used. All we need is media_type
            IntPtr pSCC = IntPtr.Zero;

            try
            {
                IAMStreamConfig videoStreamConfig = pinOutput as IAMStreamConfig;

                // -------------------------------------------------------------------------
                // We want the interface to expose all media types it supports and not only the last one set
                hr = videoStreamConfig.SetFormat(null);
                DsError.ThrowExceptionForHR(hr);

                int piCount = 0;
                int piSize  = 0;

                hr = videoStreamConfig.GetNumberOfCapabilities(out piCount, out piSize);
                DsError.ThrowExceptionForHR(hr);

                for (int i = 0; i < piCount; i++)
                {
                    // ---------------------------------------------------
                    pSCC = Marshal.AllocCoTaskMem(piSize);
                    videoStreamConfig.GetStreamCaps(i, out media_type, pSCC);

                    // NOTE: we could use VideoStreamConfigCaps.InputSize or something like that to get resolution, but it's deprecated
                    //VideoStreamConfigCaps videoStreamConfigCaps = (VideoStreamConfigCaps)Marshal.PtrToStructure(pSCC, typeof(VideoStreamConfigCaps));
                    // ---------------------------------------------------

                    if (IsBitCountAppropriate(GetBitCountForMediaType(media_type)))
                    {
                        ResolutionsAvailable.AddIfNew(GetResolutionForMediaType(media_type));
                    }

                    FreeSCCMemory(ref pSCC);
                    FreeMediaType(ref media_type);
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                // clean up
                FreeSCCMemory(ref pSCC);
                FreeMediaType(ref media_type);
            }

            return(ResolutionsAvailable);
        }