Rework on the ffmpeg video decoder (Bg were videos flickering? Can't reproduce)

This commit is contained in:
Flamefire committed 2013-10-21 15:31:20 +02:00
1 parent 5a5d94d18b
commit c4d0bcd723
1 file changed
+8 -17
+8 -17
View File
@@ -23,7 +23,7 @@ namespace Vocaluxe.Lib.Video.Acinerella
private float _FrameDuration; // frame time in s private float _FrameDuration; // frame time in s
private float _LastDecodedTime; // time of last decoded frame 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 _Time;
private float _Gap; private float _Gap;
@@ -106,12 +106,6 @@ namespace Vocaluxe.Lib.Video.Acinerella
public bool GetFrame(ref CTexture frame, float time, out float videoTime) public bool GetFrame(ref CTexture frame, float time, out float videoTime)
{ {
if (_Paused)
{
videoTime = 0;
return false;
}
if (Loop) if (Loop)
{ {
lock (_MutexSyncSignals) lock (_MutexSyncSignals)
@@ -120,17 +114,17 @@ namespace Vocaluxe.Lib.Video.Acinerella
_LoopTimer.Restart(); _LoopTimer.Restart();
} }
} }
else if (Math.Abs(_SetTime - time) > float.Epsilon) else if (Math.Abs(_SetTime - time) >= 1f / 1000f) //Check 1 ms difference
{ {
lock (_MutexSyncSignals) lock (_MutexSyncSignals)
{ {
_SetTime = time; _SetTime = time;
} }
} }
else else if (Math.Abs(_LastShownTime - time) < 1f / 1000 && frame != null) //Check 1 ms difference
{ {
videoTime = 0; videoTime = _LastShownTime;
return false; //Check if this false is right. But should as we don't give a frame here return true;
} }
_UploadNewFrame(ref frame); _UploadNewFrame(ref frame);
videoTime = _LastShownTime; videoTime = _LastShownTime;
@@ -168,11 +162,6 @@ namespace Vocaluxe.Lib.Video.Acinerella
} }
_LastDecodedTime = _SkipTime; _LastDecodedTime = _SkipTime;
lock (_MutexSyncSignals)
{
_LastShownTime = _LastDecodedTime;
}
lock (_MutexFramebuffer) lock (_MutexFramebuffer)
{ {
_Framebuffer.Clear(); _Framebuffer.Clear();
@@ -408,13 +397,15 @@ namespace Vocaluxe.Lib.Video.Acinerella
float now = _SetTime + _Gap; float now = _SetTime + _Gap;
float maxEnd = now - _FrameDuration * 2; //Get only frames younger than 2 float maxEnd = now - _FrameDuration * 2; //Get only frames younger than 2
CFrame frame; CFrame frame;
bool paused = _Paused;
while ((frame = _Framebuffer.Get()) != null) while ((frame = _Framebuffer.Get()) != null)
{ {
float frameEnd = frame.Time + _FrameDuration; float frameEnd = frame.Time + _FrameDuration;
//Don't show frames that are shown during or after now //Don't show frames that are shown during or after now
if (frameEnd >= now) if (frameEnd >= now)
break; //All following frames are after that one break; //All following frames are after that one
if (paused) // Don't modify anything
break;
_Framebuffer.SetRead(); _Framebuffer.SetRead();
//Get the last(newest) possible frame and skip the rest to force in-order showing //Get the last(newest) possible frame and skip the rest to force in-order showing
if (frameEnd <= maxEnd) if (frameEnd <= maxEnd)