Ejemplo n.º 1
0
        /// <summary>
        /// If the url to be played can be buffered before starting playback, this function
        /// starts building a graph by adding the preferred video and audio render to it.
        /// This needs to be called on the MpMain Thread.
        /// </summary>
        /// <returns>true, if the url can be buffered (a graph was started), false if it can't be and null if an error occured building the graph</returns>
        public bool?PrepareGraph()
        {
            //string sourceFilterName = SOURCE_FILTER_NAME; //GetSourceFilterName(m_strCurrentFile);

            if (!string.IsNullOrEmpty(sourceFilterName))
            {
                graphBuilder = (IGraphBuilder) new FilterGraph();
                _rotEntry    = new DsROTEntry((IFilterGraph)graphBuilder);

                Vmr9 = new VMR9Util();
                Vmr9.AddVMR9(graphBuilder);
                Vmr9.Enable(false);
                // set VMR9 back to NOT Active -> otherwise GUI is not refreshed while graph is building
                GUIGraphicsContext.Vmr9Active = false;

                // add the audio renderer
                using (Settings settings = new MPSettings())
                {
                    string audiorenderer = settings.GetValueAsString("movieplayer", "audiorenderer", "Default DirectSound Device");
                    DirectShowUtil.AddAudioRendererToGraph(graphBuilder, audiorenderer, false);
                }

                // set fields for playback
                mediaCtrl  = (IMediaControl)graphBuilder;
                mediaEvt   = (IMediaEventEx)graphBuilder;
                mediaSeek  = (IMediaSeeking)graphBuilder;
                mediaPos   = (IMediaPosition)graphBuilder;
                basicAudio = (IBasicAudio)graphBuilder;
                videoWin   = (IVideoWindow)graphBuilder;

                // add the source filter
                return(tryAddSourceFilter());
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public static IBaseFilter AddToGraph(IGraphBuilder graphBuilder)
        {
            IBaseFilter vob = null;

            using (Settings xmlreader = new MPSettings())
            {
                string engineType = xmlreader.GetValueAsString("subtitles", "engine", "DirectVobSub");
                XySubFilter = engineType.Equals("XySubFilter");
            }

            if (!XySubFilter)
            {
                DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.DirectVobSubAutoload, out vob);
                if (vob == null)
                {
                    //Try the "normal" filter then.
                    DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.DirectVobSubNormal, out vob);
                }
            }
            else
            {
                //Try the XySubFilter "autoload" filter.
                DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.XySubFilterAutoload, out vob);
                if (vob != null)
                {
                    return(vob);
                }

                //Try the XySubFilter "normal" filter then.
                DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.XySubFilterNormal, out vob);
                if (vob != null)
                {
                    return(vob);
                }

                vob = DirectShowUtil.AddFilterToGraph(graphBuilder, "XySubFilter");
                if (vob == null)
                {
                    Log.Warn("VideoPlayerVMR9: DirectVobSub or XySubFilter filter not found! You need to install XySubFilter");
                    return(null);
                }
                Log.Debug("VideoPlayerVMR9: VobSub filter added to graph");
                return(vob);
            }

            //if the directvobsub filter has not been added to the graph. (i.e. with evr)
            //we add a bit more intelligence to determine if subtitles are enabled.
            //and if subtitles are present for the video / movie then we add it if necessary to the graph.
            if (vob == null)
            {
                Log.Info("VideoPlayerVMR9: No VobSub filter in the current graph");
                //the filter has not been added lets check if it should be added or not.
                //add the filter to the graph
                vob = DirectShowUtil.AddFilterToGraph(graphBuilder, "DirectVobSub");
                if (vob == null)
                {
                    Log.Warn("VideoPlayerVMR9: DirectVobSub or XySubFilter filter not found! You need to install VSFilter");
                    return(null);
                }
                Log.Debug("VideoPlayerVMR9: VobSub filter added to graph");
            }
            else // VobSub already loaded
            {
                return(vob);
            }

            // Check if Haali Media Splitter is in the graph.
            IBaseFilter hms = null;

            DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.HaaliGuid, out hms);
            if (hms == null)
            {
                DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.MPCMatroska, out hms);
            }
            if (hms == null)
            {
                DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.MPCMatroskaSource, out hms);
            }
            if (hms == null)
            {
                DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.LAVFilter, out hms);
            }
            if (hms == null)
            {
                DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.LAVFilterSource, out hms);
            }
            if (hms != null)
            {
                IPin pinSubTo = null;
                // It is. Connect it' subtitle output pin (if any) to Vobsub's subtitle input.
                pinSubTo = DirectShowUtil.FindPin(hms, PinDirection.Output, "Subtitle");
                if (pinSubTo == null)
                {
                    while (true)
                    {
                        IPin freeSubtitle = DirectShowUtil.FindFirstFreePinSub(hms, PinDirection.Output, "");
                        IPin freeVobSub   = DirectShowUtil.FindFirstFreePin(vob, PinDirection.Input, "Input");
                        if (freeSubtitle != null && freeVobSub != null)
                        {
                            Log.Debug("VideoPlayerVMR9: Connecting Matroska's subtitle output to VobSub's input.");
                            graphBuilder.Connect(freeSubtitle, freeVobSub);
                            DirectShowUtil.ReleaseComObject(freeSubtitle);
                            freeSubtitle = null;
                            DirectShowUtil.ReleaseComObject(freeVobSub);
                            freeVobSub = null;
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                DirectShowUtil.ReleaseComObject(hms);
                hms = null;
                if (pinSubTo != null)
                {
                    Log.Debug("VideoPlayerVMR9: Connecting Haali's subtitle output to VobSub's input.");
                    // Try to render pins
                    IPin pinVobSubSub = DirectShowUtil.FindPin(vob, PinDirection.Input, "Input");
                    // If pinSubTo is already connected (disconnect it)
                    graphBuilder.Disconnect(pinSubTo);
                    graphBuilder.Connect(pinSubTo, pinVobSubSub);
                    DirectShowUtil.ReleaseComObject(pinSubTo);
                    pinSubTo = null;
                    DirectShowUtil.ReleaseComObject(pinVobSubSub);
                    pinVobSubSub = null;
                }
            }

            // Now check if vobsub's video input is not connected.
            // Check only if vmr9 is connected (render was successful).
            VMR9Util Vmr9 = VMR9Util.g_vmr9;

            if (Vmr9.IsVMR9Connected)
            {
                Log.Debug("VideoPlayerVMR9: Connect VobSub's video pins");

                IPin pinVobSubVideoIn  = DsFindPin.ByDirection(vob, PinDirection.Input, 0);
                IPin pinVobSubVideoOut = DsFindPin.ByDirection(vob, PinDirection.Output, 0);

                // This is the pin that we will connect to vobsub's input.
                IPin pinVideoTo   = Vmr9.PinConnectedTo;
                IPin pinVideoFrom = null;
                pinVideoTo.ConnectedTo(out pinVideoFrom);
                pinVideoTo.Disconnect();
                pinVideoFrom.Disconnect();
                //Now make connection to VobSub
                int hr = graphBuilder.Connect(pinVideoTo, pinVobSubVideoIn);
                //hr = graphBuilder.Render(pinVideoFrom);
                if (hr != 0)
                {
                    Log.Error("VideoPlayerVMR9: could not connect Vobsub's input video pin");
                    return(null);
                }
                hr = graphBuilder.Connect(pinVobSubVideoOut, pinVideoFrom);
                //hr = graphBuilder.Render(pinVobSubVideoOut);
                if (hr != 0)
                {
                    Log.Error("VideoPlayerVMR9: could not connect Vobsub's output video pin");
                    return(null);
                }

                Log.Debug("VideoPlayerVMR9: Vobsub's video pins connected");
                DirectShowUtil.ReleaseComObject(pinVideoTo);
                pinVideoTo = null;
                DirectShowUtil.ReleaseComObject(pinVobSubVideoIn);
                pinVobSubVideoIn = null;
                DirectShowUtil.ReleaseComObject(pinVobSubVideoOut);
                pinVobSubVideoOut = null;
                DirectShowUtil.ReleaseComObject(pinVideoFrom);
                pinVideoFrom = null;
            }
            Vmr9 = null;
            return(vob);
        }
Ejemplo n.º 3
0
        protected override bool GetInterfaces()
        {
            GetInterface = true;
            try
            {
                graphBuilder = (IGraphBuilder) new FilterGraph();
                _rotEntry    = new DsROTEntry((IFilterGraph)graphBuilder);
                int hr;
                filterConfig = GetFilterConfiguration();
                filterCodec  = GetFilterCodec();
                if (filterConfig.bAutoDecoderSettings)
                {
                    AutoRenderingCheck = true;
                    return(base.GetInterfaces());
                }


                string extension = Path.GetExtension(m_strCurrentFile).ToLowerInvariant();


                GUIMessage msg;
                if (extension == ".mpls" || extension == ".bdmv")
                {
                    filterConfig.bForceSourceSplitter = false;
                    filterConfig = GetFilterConfigurationBD();
                }

                //Manually add codecs based on file extension if not in auto-settings
                // switch back to directx fullscreen mode
                Log.Info("MyAnime3Player: Enabling DX9 exclusive mode");
                msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SWITCH_FULL_WINDOWED, 0, 0, 0, 1, 0, null);
                GUIWindowManager.SendMessage(msg);

                // add the VMR9 in the graph
                // after enabeling exclusive mode, if done first it causes MediPortal to minimize if for example the "Windows key" is pressed while playing a video
                if (extension != ".dts" && extension != ".mp3" && extension != ".mka" && extension != ".ac3")
                {
                    if (g_Player.MediaInfo != null && !g_Player.MediaInfo.MediaInfoNotloaded &&
                        !g_Player._mediaInfo.HasVideo)
                    {
                        AudioOnly = true;
                    }
                    else
                    {
                        Vmr9 = new VMR9Util();
                        Vmr9.AddVMR9(graphBuilder);
                        Vmr9.Enable(false);
                    }
                }
                else
                {
                    AudioOnly = true;
                }

                if (filterConfig.strsplitterfilter == LAV_SPLITTER_FILTER_SOURCE && filterConfig.bForceSourceSplitter)
                {
                    LoadLAVSplitter(LAV_SPLITTER_FILTER_SOURCE);
                    hr = graphBuilder.AddFilter(_interfaceSourceFilter, LAV_SPLITTER_FILTER_SOURCE);
                    DsError.ThrowExceptionForHR(hr);

                    Log.Debug("MyAnime3Player: Add LAVSplitter Source to graph");

                    IFileSourceFilter interfaceFile = (IFileSourceFilter)_interfaceSourceFilter;
                    hr = interfaceFile.Load(m_strCurrentFile, null);

                    if (hr != 0)
                    {
                        Error.SetError("Unable to play movie", "Unable build graph for VMR9");
                        Cleanup();
                        return(false);
                    }
                }
                else
                {
                    _interfaceSourceFilter = filterConfig.bForceSourceSplitter
                        ? DirectShowUtil.AddFilterToGraph(graphBuilder, filterConfig.strsplitterfilter)
                        : null;
                    if (_interfaceSourceFilter == null && !filterConfig.bForceSourceSplitter)
                    {
                        graphBuilder.AddSourceFilter(m_strCurrentFile, null, out _interfaceSourceFilter);
                    }
                    else
                    {
                        try
                        {
                            int result = ((IFileSourceFilter)_interfaceSourceFilter).Load(m_strCurrentFile, null);
                            if (result != 0)
                            {
                                graphBuilder.RemoveFilter(_interfaceSourceFilter);
                                DirectShowUtil.ReleaseComObject(_interfaceSourceFilter);
                                _interfaceSourceFilter = null;
                                graphBuilder.AddSourceFilter(m_strCurrentFile, null, out _interfaceSourceFilter);
                            }
                        }

                        catch (Exception ex)
                        {
                            Log.Error(
                                "MyAnime3Player: Exception loading Source Filter setup in setting in DShow graph , try to load by merit",
                                ex);
                            graphBuilder.RemoveFilter(_interfaceSourceFilter);
                            DirectShowUtil.ReleaseComObject(_interfaceSourceFilter);
                            _interfaceSourceFilter = null;
                            graphBuilder.AddSourceFilter(m_strCurrentFile, null, out _interfaceSourceFilter);
                        }
                    }

                    //Detection of File Source (Async.) as source filter, return true if found
                    IBaseFilter fileSyncbaseFilter = null;
                    DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.FilesyncSource, out fileSyncbaseFilter);
                    if (fileSyncbaseFilter == null)
                    {
                        graphBuilder.FindFilterByName("File Source (Async.)", out fileSyncbaseFilter);
                    }
                    if (fileSyncbaseFilter != null && filterConfig.bForceSourceSplitter)
                    {
                        FileSync = true;
                        DirectShowUtil.ReleaseComObject(fileSyncbaseFilter);
                        fileSyncbaseFilter = null;
                        if (filterConfig.strsplitterfilefilter == LAV_SPLITTER_FILTER)
                        {
                            LoadLAVSplitter(LAV_SPLITTER_FILTER);
                            hr = graphBuilder.AddFilter(Splitter, LAV_SPLITTER_FILTER);
                            DsError.ThrowExceptionForHR(hr);

                            Log.Debug("MyAnime3Player: Add LAVSplitter to graph");

                            if (hr != 0)
                            {
                                Error.SetError("Unable to play movie", "Unable build graph for VMR9");
                                Cleanup();
                                return(false);
                            }
                        }
                        else
                        {
                            Splitter = DirectShowUtil.AddFilterToGraph(graphBuilder, filterConfig.strsplitterfilefilter);
                        }
                    }
                }

                // Add preferred video filters
                UpdateFilters("Video");

                //Add Audio Renderer
                if (filterConfig.AudioRenderer.Length > 0 && filterCodec._audioRendererFilter == null)
                {
                    filterCodec._audioRendererFilter = DirectShowUtil.AddAudioRendererToGraph(graphBuilder,
                                                                                              filterConfig.AudioRenderer, false);
                }

                // Add preferred audio filters
                UpdateFilters("Audio");

                #region Set High Audio

                //Set High Resolution Output > 2 channels
                IBaseFilter baseFilter    = null;
                bool        FFDShowLoaded = false;
                graphBuilder.FindFilterByName("WMAudio Decoder DMO", out baseFilter);
                if (baseFilter != null && filterConfig.wmvAudio != false) //Also check configuration option enabled
                {
                    //Set the filter setting to enable more than 2 audio channels
                    const string g_wszWMACHiResOutput = "_HIRESOUTPUT";
                    object       val     = true;
                    IPropertyBag propBag = (IPropertyBag)baseFilter;
                    hr = propBag.Write(g_wszWMACHiResOutput, ref val);
                    if (hr != 0)
                    {
                        Log.Info("VideoPlayer9: Unable to turn WMAudio multichannel on. Reason: {0}", hr);
                    }
                    else
                    {
                        Log.Info("VideoPlayer9: WMAudio Decoder now set for > 2 audio channels");
                    }
                    if (!FFDShowLoaded)
                    {
                        IBaseFilter FFDShowAudio = DirectShowUtil.GetFilterByName(graphBuilder,
                                                                                  FFDSHOW_AUDIO_DECODER_FILTER);
                        if (FFDShowAudio != null)
                        {
                            DirectShowUtil.ReleaseComObject(FFDShowAudio);
                            FFDShowAudio = null;
                        }
                        else
                        {
                            _FFDShowAudio = DirectShowUtil.AddFilterToGraph(graphBuilder, FFDSHOW_AUDIO_DECODER_FILTER);
                        }
                        FFDShowLoaded = true;
                    }
                    DirectShowUtil.ReleaseComObject(baseFilter);
                    baseFilter = null;
                }

                #endregion

                if (_interfaceSourceFilter != null)
                {
                    DirectShowUtil.RenderGraphBuilderOutputPins(graphBuilder, _interfaceSourceFilter);
                }

                //Test and remove orphelin Audio Renderer
                //RemoveAudioR();

                //remove InternalScriptRenderer as it takes subtitle pin
                disableISR();

                //disable Closed Captions!
                disableCC();

                DirectShowUtil.RemoveUnusedFiltersFromGraph(graphBuilder);

                //remove orphelin audio renderer
                RemoveAudioR();

                //EnableClock();

                if ((Vmr9 == null || !Vmr9.IsVMR9Connected) && !AudioOnly)
                {
                    Log.Error("MyAnime3Player: Failed to render file -> vmr9");
                    mediaCtrl = null;
                    Cleanup();
                    return(false);
                }

                mediaCtrl  = (IMediaControl)graphBuilder;
                mediaEvt   = (IMediaEventEx)graphBuilder;
                mediaSeek  = (IMediaSeeking)graphBuilder;
                mediaPos   = (IMediaPosition)graphBuilder;
                basicAudio = (IBasicAudio)graphBuilder;
                videoWin   = (IVideoWindow)graphBuilder;
                if (Vmr9 != null)
                {
                    m_iVideoWidth  = Vmr9.VideoWidth;
                    m_iVideoHeight = Vmr9.VideoHeight;
                    Vmr9.SetDeinterlaceMode();
                }
                return(true);
            }
            catch (Exception ex)
            {
                Error.SetError("Unable to play movie", "Unable build graph for VMR9");
                Log.Error("MyAnime3Player: Exception while creating DShow graph {0} {1}", ex.Message, ex.StackTrace);
                Cleanup();
                return(false);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// If the url to be played can be buffered before starting playback, this function
        /// starts building a graph by adding the preferred video and audio render to it.
        /// This needs to be called on the MpMain Thread.
        /// </summary>
        /// <returns>true, if the url can be buffered (a graph was started), false if it can't be and null if an error occured building the graph</returns>
        public bool?PrepareGraph()
        {
            string sourceFilterName = GetSourceFilterName(m_strCurrentFile);

            if (!string.IsNullOrEmpty(sourceFilterName))
            {
                graphBuilder = (IGraphBuilder) new FilterGraph();
                _rotEntry    = new DsROTEntry((IFilterGraph)graphBuilder);

                basicVideo = graphBuilder as IBasicVideo2;

                Vmr9 = new VMR9Util();
                Vmr9.AddVMR9(graphBuilder);
                Vmr9.Enable(false);
                // set VMR9 back to NOT Active -> otherwise GUI is not refreshed while graph is building
                GUIGraphicsContext.Vmr9Active = false;

                // add the audio renderer
                using (Settings settings = new MPSettings())
                {
                    string audiorenderer = settings.GetValueAsString("movieplayer", "audiorenderer", "Default DirectSound Device");
                    DirectShowUtil.AddAudioRendererToGraph(graphBuilder, audiorenderer, false);
                }

                // set fields for playback
                mediaCtrl  = (IMediaControl)graphBuilder;
                mediaEvt   = (IMediaEventEx)graphBuilder;
                mediaSeek  = (IMediaSeeking)graphBuilder;
                mediaPos   = (IMediaPosition)graphBuilder;
                basicAudio = (IBasicAudio)graphBuilder;
                videoWin   = (IVideoWindow)graphBuilder;

                // add the source filter
                IBaseFilter sourceFilter = null;
                try
                {
                    if (sourceFilterName == OnlineVideos.MPUrlSourceFilter.Downloader.FilterName)
                    {
                        sourceFilter = FilterFromFile.LoadFilterFromDll("MPUrlSourceSplitter\\MPUrlSourceSplitter.ax", new Guid(OnlineVideos.MPUrlSourceFilter.Downloader.FilterCLSID), true);
                        if (sourceFilter != null)
                        {
                            Marshal.ThrowExceptionForHR(graphBuilder.AddFilter(sourceFilter, OnlineVideos.MPUrlSourceFilter.Downloader.FilterName));
                        }
                    }
                    if (sourceFilter == null)
                    {
                        sourceFilter = DirectShowUtil.AddFilterToGraph(graphBuilder, sourceFilterName);
                    }
                }
                catch (Exception ex)
                {
                    Log.Instance.Warn("Error adding '{0}' filter to graph: {1}", sourceFilterName, ex.Message);
                    return(null);
                }
                finally
                {
                    if (sourceFilter != null)
                    {
                        DirectShowUtil.ReleaseComObject(sourceFilter, 2000);
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }