private static IFilterGraph GetInitialFilterGraph(string source,
                                                          MediaSourceType mediaSourceType)
        {
            IFilterGraph filterGraph;

            if (mediaSourceType == MediaSourceType.Dvd)
            {
                filterGraph = new DvdFilterGraph();
            }
            else
            {
                var sourceType = GetSourceTypeByExtension(source);
                switch (sourceType)
                {
                case SourceType.Basic:
                case SourceType.Asf:
                case SourceType.Mkv:
                case SourceType.Flv:
                    filterGraph = new RegularFilterGraph(sourceType, Guid.Empty);
                    break;

                case SourceType.Dvd:
                    filterGraph = new DvdFilterGraph();
                    break;

                default:
                    TraceSink.GetTraceSink().TraceWarning("Could not identify source type.");
                    throw new FilterGraphBuilderException(GraphBuilderError.CantPlayFile);
                }
            }

            return(filterGraph);
        }
Пример #2
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));
        }
Пример #3
0
 public static TraceSink GetTraceSink()
 {
     return(_traceSink ?? (_traceSink = new TraceSink()));
 }
        public static IFilterGraph BuildFilterGraph(string source,
                                                    MediaSourceType mediaSourceType,
                                                    IntPtr hMediaWindow,
                                                    Renderer preferredVideoRenderer,
                                                    Action <string> onErrorCallback,
                                                    Func <string, bool> onPartialSuccessCallback)
        {
            IFilterGraph filterGraph = null;
            var          success     = false;

            try
            {
                TraceSink.GetTraceSink().TraceInformation(
                    String.Format("Start building filter graph. Source: {0}. WhatToPlay: {1}. PreferredVideoRenderer: {2}.",
                                  source, mediaSourceType, preferredVideoRenderer));

                filterGraph = GetInitialFilterGraph(source, mediaSourceType);

                var parameters = new FilterGraphBuilderParameters
                {
                    Source                 = source,
                    MediaWindowHandle      = hMediaWindow,
                    PreferredVideoRenderer = preferredVideoRenderer,
                    DiscPath               = source,
                    Flags = AM_DVD_GRAPH_FLAGS.AM_DVD_HWDEC_PREFER,
                    OnPartialSuccessCallback = onPartialSuccessCallback
                };

                filterGraph.BuildUp(parameters);
#if DEBUG
                filterGraph.AddToRot();
#endif
                TraceSink.GetTraceSink().TraceInformation("The graph was built successfully.");
                success = true;

                return(filterGraph);
            }
            catch (AbortException)
            {
                TraceSink.GetTraceSink().TraceWarning("User abort.");
                return(null);
            }
            catch (FilterGraphBuilderException e)
            {
                TraceSink.GetTraceSink().TraceError(e.ToString());
                onErrorCallback(e.Message);
                return(null);
            }
            catch (Exception e)
            {
                TraceSink.GetTraceSink().TraceError(e.ToString());
                onErrorCallback(e.Message);
                return(null);
            }
            finally
            {
                if (!success && filterGraph != null)
                {
                    filterGraph.Dispose();
                }
            }
        }