From c4d0bcd72385ea9cf010f384e9588ebe467dd1ae Mon Sep 17 00:00:00 2001 From: Flamefire Date: Mon, 21 Oct 2013 15:31:20 +0200 Subject: [PATCH] Rework on the ffmpeg video decoder (Bg were videos flickering? Can't reproduce) --- Vocaluxe/Lib/Video/Acinerella/CDecoder.cs | 27 ++++++++--------------- 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/Vocaluxe/Lib/Video/Acinerella/CDecoder.cs b/Vocaluxe/Lib/Video/Acinerella/CDecoder.cs index 37b031fe..e68593fe 100644 --- a/Vocaluxe/Lib/Video/Acinerella/CDecoder.cs +++ b/Vocaluxe/Lib/Video/Acinerella/CDecoder.cs @@ -23,7 +23,7 @@ namespace Vocaluxe.Lib.Video.Acinerella private float _FrameDuration; // frame time in s private float _LastDecodedTime; // time of last decoded frame - private float _LastShownTime; // current video position + private float _LastShownTime; // time if the last shown frame in s private float _Time; private float _Gap; @@ -106,12 +106,6 @@ namespace Vocaluxe.Lib.Video.Acinerella public bool GetFrame(ref CTexture frame, float time, out float videoTime) { - if (_Paused) - { - videoTime = 0; - return false; - } - if (Loop) { lock (_MutexSyncSignals) @@ -120,17 +114,17 @@ namespace Vocaluxe.Lib.Video.Acinerella _LoopTimer.Restart(); } } - else if (Math.Abs(_SetTime - time) > float.Epsilon) + else if (Math.Abs(_SetTime - time) >= 1f / 1000f) //Check 1 ms difference { lock (_MutexSyncSignals) { _SetTime = time; } } - else + else if (Math.Abs(_LastShownTime - time) < 1f / 1000 && frame != null) //Check 1 ms difference { - videoTime = 0; - return false; //Check if this false is right. But should as we don't give a frame here + videoTime = _LastShownTime; + return true; } _UploadNewFrame(ref frame); videoTime = _LastShownTime; @@ -168,11 +162,6 @@ namespace Vocaluxe.Lib.Video.Acinerella } _LastDecodedTime = _SkipTime; - lock (_MutexSyncSignals) - { - _LastShownTime = _LastDecodedTime; - } - lock (_MutexFramebuffer) { _Framebuffer.Clear(); @@ -408,13 +397,15 @@ namespace Vocaluxe.Lib.Video.Acinerella float now = _SetTime + _Gap; float maxEnd = now - _FrameDuration * 2; //Get only frames younger than 2 CFrame frame; + bool paused = _Paused; while ((frame = _Framebuffer.Get()) != null) { float frameEnd = frame.Time + _FrameDuration; //Don't show frames that are shown during or after now if (frameEnd >= now) break; //All following frames are after that one - + if (paused) // Don't modify anything + break; _Framebuffer.SetRead(); //Get the last(newest) possible frame and skip the rest to force in-order showing if (frameEnd <= maxEnd) @@ -438,4 +429,4 @@ namespace Vocaluxe.Lib.Video.Acinerella } #endregion Threading } -} +} \ No newline at end of file