From ac8b7dc9405212dea221e704b46614d9d4eb67c0 Mon Sep 17 00:00:00 2001 From: Flamefire Date: Wed, 22 May 2013 00:21:20 +0200 Subject: [PATCH] Improved video loading --- Vocaluxe/Base/CBackgroundMusic.cs | 40 ++++---------- Vocaluxe/Base/CTheme.cs | 7 +-- Vocaluxe/Lib/Video/Acinerella/CDecoder.cs | 66 ++++++++++------------- 3 files changed, 42 insertions(+), 71 deletions(-) diff --git a/Vocaluxe/Base/CBackgroundMusic.cs b/Vocaluxe/Base/CBackgroundMusic.cs index 26377f1d..4203e73c 100644 --- a/Vocaluxe/Base/CBackgroundMusic.cs +++ b/Vocaluxe/Base/CBackgroundMusic.cs @@ -55,14 +55,9 @@ namespace Vocaluxe.Base get { return _VideoEnabled; } set { - if (_VideoEnabled && value) + if (_VideoEnabled == value) return; - if (!_VideoEnabled && !value) - return; - if (_VideoEnabled && !value) - ToggleVideo(); - if (!_VideoEnabled && value) - ToggleVideo(); + ToggleVideo(); _VideoEnabled = value; } } @@ -439,20 +434,9 @@ namespace Vocaluxe.Base { if (_Video != -1) { - if (_VideoEnabled) - { - _VideoEnabled = false; - CVideo.Close(_Video); - _Video = -1; - CDraw.RemoveTexture(ref _CurrentVideoTexture); - return; - } - if (CVideo.Finished(_Video)) - { CVideo.Close(_Video); CDraw.RemoveTexture(ref _CurrentVideoTexture); _Video = -1; - } } else _LoadVideo(); @@ -485,17 +469,15 @@ namespace Vocaluxe.Base private static void _LoadVideo() { - if (_Video == -1) - { - _Video = CVideo.Load(_CurrentPlaylistElement.VideoFilePath); - if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) - CVideo.Skip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); - else - CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap); - _VideoEnabled = true; - _FadeTimer.Reset(); - _FadeTimer.Start(); - } + if (_Video != -1 || String.IsNullOrEmpty(_CurrentPlaylistElement.VideoFilePath)) + return; + _Video = CVideo.Load(_CurrentPlaylistElement.VideoFilePath); + if (_CurrentPlaylistElement.Start > 0.001 && CConfig.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON) + CVideo.Skip(_Video, _CurrentPlaylistElement.Start, _CurrentPlaylistElement.VideoGap); + else + CVideo.Skip(_Video, 0f, _CurrentPlaylistElement.VideoGap); + _FadeTimer.Reset(); + _FadeTimer.Start(); } } diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs index 9461dbda..f5ed2b10 100644 --- a/Vocaluxe/Base/CTheme.cs +++ b/Vocaluxe/Base/CTheme.cs @@ -203,11 +203,8 @@ namespace Vocaluxe.Base try { xmlReader.GetValue("//root/Videos/" + _Skins[skinIndex].VideoList[i].Name, out value, String.Empty); - SSkinElement sk = new SSkinElement {Name = _Skins[skinIndex].VideoList[i].Name, Value = value}; - sk.VideoIndex = CVideo.Load(Path.Combine(_Skins[skinIndex].Path, sk.Value)); - CVideo.SetLoop(sk.VideoIndex, true); - CVideo.Pause(sk.VideoIndex); - sk.Texture = null; + //Do not load video yet + SSkinElement sk = new SSkinElement {Name = _Skins[skinIndex].VideoList[i].Name, Value = value, VideoIndex = -1, Texture = null}; _Skins[skinIndex].VideoList[i] = sk; } catch (Exception e) diff --git a/Vocaluxe/Lib/Video/Acinerella/CDecoder.cs b/Vocaluxe/Lib/Video/Acinerella/CDecoder.cs index 406db75f..e5041906 100644 --- a/Vocaluxe/Lib/Video/Acinerella/CDecoder.cs +++ b/Vocaluxe/Lib/Video/Acinerella/CDecoder.cs @@ -87,10 +87,14 @@ namespace Vocaluxe.Lib.Video.Acinerella if (!File.Exists(fileName)) return false; - //Do this here as one may want to get the length afterwards! - _FileOpened = _DoOpen(); - _FileName = fileName; + + //Do this here as one may want to get the length afterwards! + if (!_DoOpen()) + return false; + + _FileOpened = true; + _Thread.Priority = ThreadPriority.Normal; _Thread.Name = Path.GetFileName(fileName); _Thread.Start(); @@ -105,8 +109,6 @@ namespace Vocaluxe.Lib.Video.Acinerella public bool GetFrame(ref CTexture frame, float time, out float videoTime) { videoTime = 0; - if (!_FileOpened) - return false; if (_Paused) return false; @@ -118,9 +120,7 @@ namespace Vocaluxe.Lib.Video.Acinerella _SetTime += _LoopTimer.ElapsedMilliseconds / 1000f; videoTime = _SetTime; - _LoopTimer.Stop(); - _LoopTimer.Reset(); - _LoopTimer.Start(); + _LoopTimer.Restart(); } @@ -160,9 +160,6 @@ namespace Vocaluxe.Lib.Video.Acinerella #region Threading private void _Skip() { - if (!_FileOpened) - return; - _VideoSkipTime = _Gap; _SkipTime = _Start + _Gap; _BeforeLoop = false; @@ -216,31 +213,29 @@ namespace Vocaluxe.Lib.Video.Acinerella //EventDecode.Set(); while (!_Terminated) { + //if (EventDecode.WaitOne(10)) + bool skip = false; + lock (_MutexSyncSignals) { - //if (EventDecode.WaitOne(10)) - bool skip = false; - lock (_MutexSyncSignals) - { - _Time = _SetTime; - if (_SetSkip) - skip = true; + _Time = _SetTime; + if (_SetSkip) + skip = true; - _SetSkip = false; - _Gap = _SetGap; - _Start = _SetStart; - _Loop = Loop; - } - - if (skip) - _Skip(); - - if (!_NewFrame) - _Decode(); - - if (_NewFrame) - _Copy(); - Thread.Sleep(1); + _SetSkip = false; + _Gap = _SetGap; + _Start = _SetStart; + _Loop = Loop; } + + if (skip) + _Skip(); + + if (!_NewFrame) + _Decode(); + + if (_NewFrame) + _Copy(); + Thread.Sleep(1); } _Free(); @@ -314,7 +309,7 @@ namespace Vocaluxe.Lib.Video.Acinerella { const int framedropcount = 4; - if (!_FileOpened || _NewFrame) + if (_NewFrame) return; if (_Paused || _NoMoreFrames || _BufferFull) @@ -452,9 +447,6 @@ namespace Vocaluxe.Lib.Video.Acinerella private void _UploadNewFrame(ref CTexture frame) { - if (!_FileOpened) - return; - lock (_MutexFramebuffer) { int num = _FindFrame();