public void RenderLayer(float timePassed) { // if (VideoRendererStatistics.VideoState == VideoRendererStatistics.State.VideoPresent) // Before , we got a black screen until GUI_MSG_NOTIFY command has finished // That we don't want ( do we ?) if (VideoRendererStatistics.VideoState == VideoRendererStatistics.State.VideoPresent || VideoRendererStatistics.VideoState == VideoRendererStatistics.State.NoSignal) { if (GUIGraphicsContext.RenderBlackImage) { RenderBlackImage(timePassed); } //Render video texture if (_shouldRenderTexture == false) { return; } if (_textureAddress != 0) { DrawTexture(_textureAddress, _diffuseColor); } } else { GUIGraphicsContext.RenderBlackImage = true; RenderBlackImage(timePassed); GUIGraphicsContext.RenderBlackImage = false; } SubtitleRenderer.GetInstance().Render(); SubEngine.GetInstance().Render(_subsRect, _destinationRect); }
private void Cleanup() { if (graphBuilder == null) { return; } int hr; Log.Info("RTSPPlayer:cleanup DShow graph"); try { if (VMR9Util.g_vmr9 != null) { VMR9Util.g_vmr9.Vmr9MediaCtrl(_mediaCtrl); VMR9Util.g_vmr9.Enable(false); } if (mediaEvt != null) { hr = mediaEvt.SetNotifyWindow(IntPtr.Zero, WM_GRAPHNOTIFY, IntPtr.Zero); } videoWin = graphBuilder as IVideoWindow; if (videoWin != null && GUIGraphicsContext.VideoRenderer != GUIGraphicsContext.VideoRendererType.madVR) { videoWin.put_Owner(IntPtr.Zero); videoWin.put_Visible(OABool.False); } _mediaCtrl = null; mediaEvt = null; _mediaSeeking = null; mediaPos = null; basicAudio = null; basicVideo = null; videoWin = null; SubEngine.GetInstance().FreeSubtitles(); if (graphBuilder != null) { DirectShowUtil.RemoveFilters(graphBuilder); if (_rotEntry != null) { _rotEntry.SafeDispose(); _rotEntry = null; } DirectShowUtil.FinalReleaseComObject(graphBuilder); graphBuilder = null; } if (VMR9Util.g_vmr9 != null) { VMR9Util.g_vmr9.SafeDispose(); VMR9Util.g_vmr9 = null; } GUIGraphicsContext.form.Invalidate(true); _state = PlayState.Init; if (_mpegDemux != null) { Log.Info("cleanup mpegdemux"); DirectShowUtil.FinalReleaseComObject(_mpegDemux); _mpegDemux = null; } if (_rtspSource != null) { Log.Info("cleanup _rtspSource"); DirectShowUtil.FinalReleaseComObject(_rtspSource); _rtspSource = null; } if (_subtitleFilter != null) { DirectShowUtil.FinalReleaseComObject(_subtitleFilter); _subtitleFilter = null; if (this.dvbSubRenderer != null) { this.dvbSubRenderer.SetPlayer(null); } this.dvbSubRenderer = null; } if (vobSub != null) { Log.Info("cleanup vobSub"); DirectShowUtil.FinalReleaseComObject(vobSub); vobSub = null; } } catch (Exception ex) { if (VMR9Util.g_vmr9 != null) { VMR9Util.g_vmr9.RestoreGuiForMadVr(); VMR9Util.g_vmr9.SafeDispose(); } Log.Error("RTSPPlayer: Exception while cleanuping DShow graph - {0} {1}", ex.Message, ex.StackTrace); } //switch back to directx windowed mode Log.Info("RTSPPlayer: Disabling DX9 exclusive mode"); GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SWITCH_FULL_WINDOWED, 0, 0, 0, 0, 0, null); GUIWindowManager.SendMessage(msg); }
private void Cleanup() { if (graphBuilder == null) { return; } int hr; Log.Info("RTSPPlayer:cleanup DShow graph"); try { if (_mediaCtrl != null) { int counter = 0; FilterState state; hr = _mediaCtrl.Stop(); hr = _mediaCtrl.GetState(10, out state); while (state != FilterState.Stopped || GUIGraphicsContext.InVmr9Render) { Thread.Sleep(100); hr = _mediaCtrl.GetState(10, out state); counter++; if (counter >= 30) { if (state != FilterState.Stopped) { Log.Error("RTSPPlayer: graph still running"); } if (GUIGraphicsContext.InVmr9Render) { Log.Error("RTSPPlayer: in renderer"); } break; } } _mediaCtrl = null; } if (Vmr9 != null) { Vmr9.Enable(false); } if (mediaEvt != null) { hr = mediaEvt.SetNotifyWindow(IntPtr.Zero, WM_GRAPHNOTIFY, IntPtr.Zero); mediaEvt = null; } videoWin = graphBuilder as IVideoWindow; if (videoWin != null) { hr = videoWin.put_Visible(OABool.False); hr = videoWin.put_Owner(IntPtr.Zero); videoWin = null; } _mediaSeeking = null; mediaPos = null; basicAudio = null; basicVideo = null; videoWin = null; SubEngine.GetInstance().FreeSubtitles(); if (graphBuilder != null) { DirectShowUtil.RemoveFilters(graphBuilder); if (_rotEntry != null) { _rotEntry.SafeDispose(); _rotEntry = null; } DirectShowUtil.ReleaseComObject(graphBuilder); graphBuilder = null; } if (Vmr9 != null) { Vmr9.SafeDispose(); Vmr9 = null; } GUIGraphicsContext.form.Invalidate(true); _state = PlayState.Init; if (_mpegDemux != null) { Log.Info("cleanup mpegdemux"); while ((hr = DirectShowUtil.ReleaseComObject(_mpegDemux)) > 0) { ; } _mpegDemux = null; } if (_rtspSource != null) { Log.Info("cleanup _rtspSource"); while ((hr = DirectShowUtil.ReleaseComObject(_rtspSource)) > 0) { ; } _rtspSource = null; } if (_subtitleFilter != null) { while ((hr = DirectShowUtil.ReleaseComObject(_subtitleFilter)) > 0) { ; } _subtitleFilter = null; if (this.dvbSubRenderer != null) { this.dvbSubRenderer.SetPlayer(null); } this.dvbSubRenderer = null; } if (vobSub != null) { Log.Info("cleanup vobSub"); while ((hr = DirectShowUtil.ReleaseComObject(vobSub)) > 0) { ; } vobSub = null; } } catch (Exception ex) { Log.Error("RTSPPlayer: Exception while cleanuping DShow graph - {0} {1}", ex.Message, ex.StackTrace); } //switch back to directx windowed mode Log.Info("RTSPPlayer: Disabling DX9 exclusive mode"); GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SWITCH_FULL_WINDOWED, 0, 0, 0, 0, 0, null); GUIWindowManager.SendMessage(msg); }
public override bool Play(string strFile) { updateTimer = DateTime.Now; m_speedRate = 10000; m_bVisible = false; m_iVolume = 100; m_state = PlayState.Init; if (strFile != "http://localhost/OnlineVideo.mp4") { m_strCurrentFile = strFile; // hack to get around the MP 1.3 Alpha bug with non http URLs } m_bFullScreen = true; m_ar = GUIGraphicsContext.ARType; VideoRendererStatistics.VideoState = VideoRendererStatistics.State.VideoPresent; _updateNeeded = true; Log.Instance.Info("OnlineVideosPlayer: Play '{0}'", m_strCurrentFile); m_bStarted = false; if (!GetInterfaces()) { m_strCurrentFile = ""; CloseInterfaces(); return(false); } // if we are playing a local file set the cache file so refresh rate adaption can happen Uri uri = new Uri(m_strCurrentFile); string protocol = uri.Scheme.Substring(0, Math.Min(uri.Scheme.Length, 4)); if (protocol == "file") { cacheFile = m_strCurrentFile; } AdaptRefreshRateFromCacheFile(); ISubEngine engine = SubEngine.GetInstance(true); if (!engine.LoadSubtitles(graphBuilder, string.IsNullOrEmpty(SubtitleFile) ? m_strCurrentFile : SubtitleFile)) { SubEngine.engine = new SubEngine.DummyEngine(); } else { engine.Enable = true; } IPostProcessingEngine postengine = PostProcessingEngine.GetInstance(true); if (!postengine.LoadPostProcessing(graphBuilder)) { PostProcessingEngine.engine = new PostProcessingEngine.DummyEngine(); } AnalyseStreams(); SelectSubtitles(); SelectAudioLanguage(); OnInitialized(); int hr = mediaEvt.SetNotifyWindow(GUIGraphicsContext.ActiveForm, WM_GRAPHNOTIFY, IntPtr.Zero); if (hr < 0) { Error.SetError("Unable to play movie", "Can not set notifications"); m_strCurrentFile = ""; CloseInterfaces(); return(false); } if (videoWin != null) { videoWin.put_WindowStyle((WindowStyle)((int)WindowStyle.Child + (int)WindowStyle.ClipChildren + (int)WindowStyle.ClipSiblings)); videoWin.put_MessageDrain(GUIGraphicsContext.form.Handle); } DirectShowUtil.SetARMode(graphBuilder, AspectRatioMode.Stretched); try { if (protocol == "file") { if (Vmr9 != null) { Vmr9.StartMediaCtrl(mediaCtrl); } } else { hr = mediaCtrl.Run(); DsError.ThrowExceptionForHR(hr); if (hr == 1) // S_FALSE from IMediaControl::Run means: The graph is preparing to run, but some filters have not completed the transition to a running state. { // wait max. 20 seconds for the graph to transition to the running state DateTime startTime = DateTime.Now; FilterState filterState; do { Thread.Sleep(100); hr = mediaCtrl.GetState(100, out filterState); // check with timeout max. 10 times a second if the state changed } while ((hr != 0) && ((DateTime.Now - startTime).TotalSeconds <= 20)); if (hr != 0) // S_OK { DsError.ThrowExceptionForHR(hr); throw new Exception(string.Format("IMediaControl.GetState after 20 seconds: 0x{0} - '{1}'", hr.ToString("X8"), DsError.GetErrorText(hr))); } } } } catch (Exception error) { Log.Instance.Warn("OnlineVideosPlayer: Unable to play with reason: {0}", error.Message); } if (hr != 0) // S_OK { Error.SetError("Unable to play movie", "Unable to start movie"); m_strCurrentFile = ""; CloseInterfaces(); return(false); } if (basicVideo != null) { basicVideo.GetVideoSize(out m_iVideoWidth, out m_iVideoHeight); } if (GoFullscreen) { GUIWindowManager.ActivateWindow(GUIOnlineVideoFullscreen.WINDOW_FULLSCREEN_ONLINEVIDEO); } GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_PLAYBACK_STARTED, 0, 0, 0, 0, 0, null); msg.Label = CurrentFile; GUIWindowManager.SendThreadMessage(msg); m_state = PlayState.Playing; m_iPositionX = GUIGraphicsContext.VideoWindow.X; m_iPositionY = GUIGraphicsContext.VideoWindow.Y; m_iWidth = GUIGraphicsContext.VideoWindow.Width; m_iHeight = GUIGraphicsContext.VideoWindow.Height; m_ar = GUIGraphicsContext.ARType; _updateNeeded = true; SetVideoWindow(); mediaPos.get_Duration(out m_dDuration); Log.Instance.Info("OnlineVideosPlayer: Duration {0} sec", m_dDuration.ToString("F")); return(true); }
public void SetSampleTime(long nsSampleTime) { SubEngine.GetInstance().SetTime(nsSampleTime); }
protected void Cleanup() { if (graphBuilder == null) { return; } int hr = 0; Log.Info("VideoPlayer9: Cleanup DShow graph"); try { if (mediaCtrl != null) { int counter = 0; FilterState state; hr = mediaCtrl.Stop(); hr = mediaCtrl.GetState(10, out state); while (state != FilterState.Stopped || GUIGraphicsContext.InVmr9Render) { Log.Debug("VideoPlayer9: graph still running"); Thread.Sleep(100); hr = mediaCtrl.GetState(10, out state); counter++; if (counter >= 30) { if (state != FilterState.Stopped) { Log.Debug("VideoPlayer9: graph still running"); } if (GUIGraphicsContext.InVmr9Render) { Log.Debug("VideoPlayer9: in renderer"); } break; } } mediaCtrl = null; } if (mediaEvt != null) { hr = mediaEvt.SetNotifyWindow(IntPtr.Zero, WM_GRAPHNOTIFY, IntPtr.Zero); mediaEvt = null; } if (videoWin != null) { hr = videoWin.put_Visible(OABool.False); hr = videoWin.put_Owner(IntPtr.Zero); videoWin = null; } mediaSeek = null; mediaPos = null; basicAudio = null; basicVideo = null; SubEngine.GetInstance().FreeSubtitles(); PostProcessingEngine.GetInstance().FreePostProcess(); if (_FFDShowAudio != null) { DirectShowUtil.ReleaseComObject(_FFDShowAudio); _FFDShowAudio = null; } if (_audioSwitcher != null) { DirectShowUtil.ReleaseComObject(_audioSwitcher); _audioSwitcher = null; } if (Vmr9 != null) { Vmr9.Enable(false); Vmr9.SafeDispose(); Vmr9 = null; } if (graphBuilder != null) { DirectShowUtil.RemoveFilters(graphBuilder); if (_rotEntry != null) { _rotEntry.SafeDispose(); _rotEntry = null; } DirectShowUtil.ReleaseComObject(graphBuilder); graphBuilder = null; } GUIGraphicsContext.form.Invalidate(true); m_state = PlayState.Init; } catch (Exception ex) { Log.Error("VideoPlayerVMR9: Exception while cleanuping DShow graph - {0} {1}", ex.Message, ex.StackTrace); } //switch back to directx windowed mode Log.Info("VideoPlayerVMR9: Disabling DX9 exclusive mode"); GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SWITCH_FULL_WINDOWED, 0, 0, 0, 0, 0, null); GUIWindowManager.SendMessage(msg); }