public override void SetTitle(string title) { if (_titleInfos == null) { return; } int titleIndex = _titleInfos.Select(t => t.ToString()).ToList().IndexOf(title); if (titleIndex >= 0) { _currentTitle = titleIndex; _bdReader.ForceTitleBasedPlayback(true, (uint)titleIndex); _bdReader.Start(); } }
protected bool GetInterfaces(string filename, int titleBD) { try { Log.Debug("BDPlayer: GetInterfaces()"); _graphBuilder = (IGraphBuilder)new FilterGraph(); _rotEntry = new DsROTEntry(_graphBuilder as IFilterGraph); filterConfig = GetFilterConfiguration(); if (filterConfig.AudioRenderer.Length > 0) { _audioRendererFilter = DirectShowUtil.AddAudioRendererToGraph(_graphBuilder, filterConfig.AudioRenderer, true); } BDReader reader = new BDReader(); _interfaceBDReader = reader as IBaseFilter; _ireader = reader as IBDReader; if (_interfaceBDReader == null || _ireader == null) { // todo: add exception return false; } // add the BD reader int hr = _graphBuilder.AddFilter(_interfaceBDReader, BD_READER_GRAPH_NAME); DsError.ThrowExceptionForHR(hr); Log.Debug("BDPlayer: Add BDReader to graph"); IFileSourceFilter interfaceFile = (IFileSourceFilter)_interfaceBDReader; LoadSettings(_ireader); _ireader.SetD3DDevice(DirectShowUtil.GetUnmanagedDevice(GUIGraphicsContext.DX9Device)); _ireader.SetBDReaderCallback(this); hr = interfaceFile.Load(filename, null); DsError.ThrowExceptionForHR(hr); Log.Debug("BDPlayer: BDReader loaded: {0}", filename); List<TitleInfo> titles = GetTitleInfoCollection(_ireader); while (true) { if (g_Player.ForcePlay && g_Player.SetResumeBDTitleState < g_Player.BdDefaultTitle) { if (titles.Count == 1) { _titleToPlay = 0; g_Player.SetResumeBDTitleState = g_Player.BdRemuxTitle; } else { _titleToPlay = g_Player.SetResumeBDTitleState; } _forceTitle = true; g_Player.ForcePlay = false; } else { if (titles.Count == 1) { // BD has only one title (remux one) _forceTitle = true; _titleToPlay = 0; g_Player.SetResumeBDTitleState = g_Player.BdRemuxTitle; if (g_Player.SetResumeBDTitleState == -1) { // user cancelled dialog titles.Dispose(); g_Player.Stop(); return false; } } else { _titleToPlay = SelectTitle(titles); g_Player.SetResumeBDTitleState = _titleToPlay; Log.Info("BDPlayer: BDReader _titleToPlay : {0}", _titleToPlay); if (_titleToPlay > -1) { // a specific title was selected _forceTitle = true; if (g_Player.SetResumeBDTitleState == -1) { // user cancelled dialog titles.Dispose(); g_Player.Stop(); return false; } } else { if (_titleToPlay == -1) { // user cancelled dialog g_Player.Stop(); titles.Dispose(); return false; } // user choose to display menu _forceTitle = false; } } } _ireader.ForceTitleBasedPlayback(_forceTitle, (uint)_titleToPlay); Log.Debug("BDPlayer: Starting BDReader"); eventBuffer.Clear(); hr = _ireader.Start(); if (hr != 0) { if (!_forceTitle) { Log.Error("BDPlayer: Failed to start file:{0} :0x{1:x}", filename, hr); continue; } Log.Error("BDPlayer: Failed to start in title based mode file:{0} :0x{1:x}", filename, hr); titles.Dispose(); return false; } else { Log.Info("BDPlayer: BDReader started"); } break; } titles.Dispose(); #region Filters Log.Info("BDPlayer: Adding filters"); _vmr9 = new VMR9Util(); _vmr9.AddVMR9(_graphBuilder); _vmr9.Enable(false); // Set VideoDecoder and VC1Override before adding filter in graph SetVideoDecoder(); SetVC1Override(); // Add preferred video filters UpdateFilters("Video"); // Add preferred audio filters UpdateFilters("Audio"); // Let the subtitle engine handle the proper filters try { SubtitleRenderer.GetInstance().AddSubtitleFilter(_graphBuilder); } catch (Exception e) { Log.Error(e); } #endregion #region PostProcessingEngine Detection IPostProcessingEngine postengine = PostProcessingEngine.GetInstance(true); if (!postengine.LoadPostProcessing(_graphBuilder)) { PostProcessingEngine.engine = new PostProcessingEngine.DummyEngine(); } #endregion #region render BDReader output pins Log.Info("BDPlayer: Render BDReader outputs"); if (_interfaceBDReader != null) { DirectShowUtil.RenderGraphBuilderOutputPins(_graphBuilder, _interfaceBDReader); } //remove InternalScriptRenderer as it takes subtitle pin disableISR(); //disable Closed Captions! disableCC(); //RemoveAudioR(); DirectShowUtil.RemoveUnusedFiltersFromGraph(_graphBuilder); #endregion _mediaCtrl = (IMediaControl)_graphBuilder; _mediaEvt = (IMediaEventEx)_graphBuilder; _mediaSeeking = (IMediaSeeking)_graphBuilder; try { SubtitleRenderer.GetInstance().SetPlayer(this); _dvbSubRenderer = SubtitleRenderer.GetInstance(); } catch (Exception e) { Log.Error(e); } _subtitleStream = (Player.TSReaderPlayer.ISubtitleStream)_interfaceBDReader; if (_subtitleStream == null) { Log.Error("BDPlayer: Unable to get ISubtitleStream interface"); } // if only dvb subs are enabled, pass null for ttxtDecoder _subSelector = new SubtitleSelector(_subtitleStream, _dvbSubRenderer, null); EnableSubtitle = _subtitlesEnabled; //Sync Audio Renderer SyncAudioRenderer(); if (!_vmr9.IsVMR9Connected) { Log.Error("BDPlayer: Failed vmr9 not connected"); return false; } _vmr9.SetDeinterlaceMode(); return true; } catch (Exception ex) { Log.Error("BDPlayer: Exception while creating DShow graph {0}", ex.Message); return false; } }
/// <summary> /// Adds the file source filter to the graph. /// </summary> protected override void AddSourceFilter() { if (!IsLocalFilesystemResource) { throw new IllegalCallException("The BluRayPlayer can only play local file system resources"); } // Load source filter, assembly location must be determined here, otherwise LoadFilterFromDll would try to lookup the file relative to VideoPlayer! string filterPath = FilterLoader.BuildAssemblyRelativePath("BDReader.ax"); _fileSource = FilterLoader.LoadFilterFromDll(filterPath, typeof(BDReader).GUID); var baseFilter = _fileSource.GetFilter(); // Init BD Reader _bdReader = (IBDReader)baseFilter; LoadSettings(); _bdReader.SetD3DDevice(_device.NativePointer); _bdReader.SetBDReaderCallback(this); _graphBuilder.AddFilter(baseFilter, BluRayAPI.BDREADER_FILTER_NAME); // TODO: add the correct subtitle filter /* _subtitleRenderer = new SubtitleRenderer(OnTextureInvalidated); * _subtitleFilter = _subtitleRenderer.AddSubtitleFilter(_graphBuilder); * if (_subtitleFilter != null) * { * _subtitleRenderer.RenderSubtitles = true; * _subtitleRenderer.SetPlayer(this); * } */ // Prepare event handling _eventThread = new Thread(HandleBDEvent); _eventThread.Start(); // Render the file IFileSourceFilter f = (IFileSourceFilter)_fileSource; using (((ILocalFsResourceAccessor)_resourceAccessor).EnsureLocalFileSystemAccess()) { string strFile = Path.Combine(((ILocalFsResourceAccessor)_resourceAccessor).LocalFileSystemPath, @"BDMV\index.bdmv"); f.Load(strFile, null); // Init GraphRebuilder _graphRebuilder = new GraphRebuilder(_graphBuilder, baseFilter, OnAfterGraphRebuild) { PlayerName = PlayerTitle }; // Get the complete BD title information (including all streams, chapters...) _titleInfos = GetTitleInfoCollection(_bdReader); ulong duration = 0; uint maxIdx = 0; foreach (BluRayAPI.BDTitleInfo bdTitleInfo in _titleInfos) { if (bdTitleInfo.Duration > duration) { duration = bdTitleInfo.Duration; maxIdx = bdTitleInfo.Index; } } // TEST: play the longest title _forceTitle = false; if (_forceTitle) { _bdReader.ForceTitleBasedPlayback(true, maxIdx); _currentTitle = (int)maxIdx; } else { _bdReader.ForceTitleBasedPlayback(false, 0); } _bdReader.Start(); SetVideoDecoder(); } }
/// <summary> /// Adds the file source filter to the graph. /// </summary> protected override void AddSourceFilter() { if (!IsLocalFilesystemResource) throw new IllegalCallException("The BluRayPlayer can only play local file system resources"); // Load source filter, assembly location must be determined here, otherwise LoadFilterFromDll would try to lookup the file relative to VideoPlayer! string filterPath = FilterLoader.BuildAssemblyRelativePath("BDReader.ax"); _fileSource = FilterLoader.LoadFilterFromDll(filterPath, typeof(BDReader).GUID); // Init BD Reader _bdReader = (IBDReader)_fileSource; _bdReader.SetD3DDevice(_device.NativePointer); _bdReader.SetBDReaderCallback(this); _graphBuilder.AddFilter(_fileSource, BluRayAPI.BDREADER_FILTER_NAME); _subtitleRenderer = new SubtitleRenderer(OnTextureInvalidated); _subtitleFilter = _subtitleRenderer.AddSubtitleFilter(_graphBuilder); if (_subtitleFilter != null) { _subtitleRenderer.RenderSubtitles = true; _subtitleRenderer.SetPlayer(this); } // Render the file IFileSourceFilter f = (IFileSourceFilter)_fileSource; using (((ILocalFsResourceAccessor)_resourceAccessor).EnsureLocalFileSystemAccess()) { string strFile = Path.Combine(((ILocalFsResourceAccessor)_resourceAccessor).LocalFileSystemPath, @"BDMV\index.bdmv"); f.Load(strFile, null); // Init GraphRebuilder _graphRebuilder = new GraphRebuilder(_graphBuilder, _fileSource, OnAfterGraphRebuild) { PlayerName = PlayerTitle }; // Get the complete BD title information (including all streams, chapters...) _titleInfos = GetTitleInfoCollection(_bdReader); ulong duration = 0; uint maxIdx = 0; foreach (BluRayAPI.BDTitleInfo bdTitleInfo in _titleInfos) { if (bdTitleInfo.Duration > duration) { duration = bdTitleInfo.Duration; maxIdx = bdTitleInfo.Index; } } // TEST: play the longest title _forceTitle = false; if (_forceTitle) { _bdReader.ForceTitleBasedPlayback(true, maxIdx); _currentTitle = (int)maxIdx; } else { _bdReader.ForceTitleBasedPlayback(false, 0); } _bdReader.Start(); } }