コード例 #1
0
        public static Tuple <IBaseFilter, IBasicAudio> AddSoundRenderer(this IGraphBuilder pGraphBuilder)
        {
            var baseFilter = DsUtils.GetFilter(Clsid.DSoundRender, false);

            if (baseFilter == null)
            {
                TraceSink.GetTraceSink().TraceWarning("Could not instantiate DirectSound Filter.");
                return(null);
            }

            // add the DirectSound filter to the graph
            var hr = pGraphBuilder.AddFilter(baseFilter, "DirectSound Filter");

            if (DsHlp.FAILED(hr))
            {
                Marshal.FinalReleaseComObject(baseFilter);

                TraceSink.GetTraceSink().TraceWarning("Could not add DirectSound Filter to the filter graph.");
                return(null);
            }

            IBasicAudio basicAudio = baseFilter as IBasicAudio;

            if (basicAudio == null)
            {
                pGraphBuilder.RemoveFilter(baseFilter);
                Marshal.FinalReleaseComObject(baseFilter);

                TraceSink.GetTraceSink().TraceWarning("Could not get IBasicAudio interface.");
                return(null);
            }

            return(new Tuple <IBaseFilter, IBasicAudio>(baseFilter, basicAudio));
        }
コード例 #2
0
        public static IBaseFilter AddFilter(this IGraphBuilder pGraphBuilder, FilterDescription filterDescription)
        {
            var baseFilter = DsUtils.GetFilter(filterDescription.ClassId, true);
            var hr         = pGraphBuilder.AddFilter(baseFilter, filterDescription.Name);

            if (DsHlp.FAILED(hr))
            {
                Marshal.FinalReleaseComObject(baseFilter);

                hr.ThrowExceptionForHR();
            }

            return(baseFilter);
        }
コード例 #3
0
        // this function should be called AFTER the video stream has been rendered
        // but before rendering the audio streams
        // however, it will try to find the splitter even if video wasn't rendered
        private bool FindSplitter(IGraphBuilder pGraphBuilder)
        {
            if (_splitterFilter != null)
            {
                DsUtils.RemoveRedundantFilters(_sourceFilter, pGraphBuilder);
                return(true);
            }

            IEnumFilters pEnumFilters = null;
            IBaseFilter  pFilter      = null;
            int          cFetched;
            bool         bSplitterFound = false;

            int hr = pGraphBuilder.EnumFilters(out pEnumFilters);

            if (DsHlp.FAILED(hr))
            {
                return(false);
            }

            IPin pPin;
            int  nFilters = 0;
            bool bCanRelease;

            while ((pEnumFilters.Next(1, out pFilter, out cFetched) == DsHlp.S_OK))
            {
                nFilters++;
                bCanRelease = true;
                pPin        = DsUtils.GetPin(pFilter, PinDirection.Output, false, 0);
                if (pPin != null)
                {
                    if (DsUtils.IsMediaTypeSupported(pPin, MediaType.Audio) == 0 ||
                        DsUtils.IsMediaTypeSupported(pPin, MediaType.Subtitle) == 0)
                    {
                        //this unconnected pin supports audio or subpicture type!
                        bSplitterFound  = true;
                        bCanRelease     = false;
                        _splitterFilter = pFilter;
                    }
                    Marshal.ReleaseComObject(pPin);
                }

                //let's have a look at another filter
                if (bCanRelease)
                {
                    Marshal.ReleaseComObject(pFilter);
                }

                if (bSplitterFound)
                {
                    break;
                }
            }

            Marshal.ReleaseComObject(pEnumFilters);

            if (!bSplitterFound)
            {
                if (nFilters > 3)
                {
                    pPin = DsUtils.GetPin(_sourceFilter, PinDirection.Output, true, 0);
                    if (pPin != null)
                    {
                        IPin pInputPin;
                        hr = pPin.ConnectedTo(out pInputPin);
                        if (hr == DsHlp.S_OK)
                        {
                            PinInfo info = new PinInfo();
                            hr = pInputPin.QueryPinInfo(out info);
                            if (hr == DsHlp.S_OK)
                            {
                                _splitterFilter = info.pFilter;
                                bSplitterFound  = true;
                            }
                            Marshal.ReleaseComObject(pInputPin);
                        }
                        Marshal.ReleaseComObject(pPin);
                    }
                }
                else
                {
                    _splitterFilter = _sourceFilter;
                    bSplitterFound  = true;
                }
            }

            StripSplitter(pGraphBuilder);
            return(bSplitterFound);
        }