Skip to content

Commit

Permalink
Renderer: Fixes an issue (from last commit with the non-waitable swap…
Browse files Browse the repository at this point in the history
… chain) which ensures no frame drops during important UI updates (such as refresh layout, slide show, frame stepping etc.) and allows it mainly only during playback

Player: Fixes a possible issue with GetBufferedDuration (for MaxLatency)
  • Loading branch information
SuRGeoNix committed Jul 22, 2024
1 parent c0d7565 commit 501159a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions FlyleafLib/MediaFramework/MediaRenderer/Renderer.Present.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public unsafe partial class Renderer
long lastPresentRequestAt= 0;
object lockPresentTask = new();

public bool Present(VideoFrame frame)
public bool Present(VideoFrame frame, bool forceWait = true)
{
if (Monitor.TryEnter(lockDevice, frame.timestamp == 0 ? 100 : 5)) // Allow more time for first frame
{
try
{
PresentInternal(frame);
PresentInternal(frame, forceWait);
VideoDecoder.DisposeFrame(LastFrame);
LastFrame = frame;

Expand Down Expand Up @@ -95,7 +95,7 @@ public void Present()
isPresenting = false;
});
}
internal void PresentInternal(VideoFrame frame)
internal void PresentInternal(VideoFrame frame, bool forceWait = true)
{
if (SCDisposed)
return;
Expand All @@ -116,7 +116,7 @@ internal void PresentInternal(VideoFrame frame)

vpsa[0].InputSurface = vpiv;
vc.VideoProcessorBlt(vp, vpov, 0, 1, vpsa);
swapChain.Present(Config.Video.VSync, Config.Video.PresentFlags);
swapChain.Present(Config.Video.VSync, forceWait ? PresentFlags.None : Config.Video.PresentFlags);

vpiv.Dispose();
}
Expand Down Expand Up @@ -144,7 +144,7 @@ internal void PresentInternal(VideoFrame frame)
context.OMSetBlendState(curPSCase == PSCase.RGBPacked ? blendStateAlpha : null);
}

swapChain.Present(Config.Video.VSync, Config.Video.PresentFlags);
swapChain.Present(Config.Video.VSync, forceWait ? PresentFlags.None : Config.Video.PresentFlags);
}

child?.PresentInternal(frame);
Expand Down Expand Up @@ -245,7 +245,7 @@ public void RefreshLayout()
else if (Config.Video.ClearScreen)
{
context.ClearRenderTargetView(backBufferRtv, Config.Video._BackgroundColor);
swapChain.Present(Config.Video.VSync, PresentFlags.DoNotWait);
swapChain.Present(Config.Video.VSync, PresentFlags.None);
}
}
catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void DisposeSwapChain()
try
{
context.ClearRenderTargetView(backBufferRtv, Config.Video._BackgroundColor);
swapChain.Present(Config.Video.VSync, PresentFlags.DoNotWait);
swapChain.Present(Config.Video.VSync, PresentFlags.None);
}
catch { }
}
Expand Down
6 changes: 3 additions & 3 deletions FlyleafLib/MediaPlayer/Player.Screamers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ private void Screamer()
{
if (CanTrace) Log.Trace($"[V] Presenting {TicksToTime(vFrame.timestamp)}");

if (decoder.VideoDecoder.Renderer.Present(vFrame))
if (decoder.VideoDecoder.Renderer.Present(vFrame, false))
Video.framesDisplayed++;
else
Video.framesDropped++;
Expand Down Expand Up @@ -705,7 +705,7 @@ private void ChangeSpeedWithoutBuffering(double newSpeed)
private long GetBufferedDuration()
{
var decoder = VideoDecoder.Frames.IsEmpty ? 0 : VideoDecoder.Frames.ToArray()[^1].timestamp - vFrame.timestamp;
var demuxer = VideoDemuxer.VideoPackets.LastTimestamp == ffmpeg.AV_NOPTS_VALUE
var demuxer = VideoDemuxer.VideoPackets.IsEmpty || VideoDemuxer.VideoPackets.LastTimestamp == ffmpeg.AV_NOPTS_VALUE
? 0 :
(VideoDemuxer.VideoPackets.LastTimestamp - VideoDemuxer.StartTime) - vFrame.timestamp;

Expand Down Expand Up @@ -920,7 +920,7 @@ private void ScreamerReverse()
Thread.Sleep(sleepMs);
}

decoder.VideoDecoder.Renderer.Present(vFrame);
decoder.VideoDecoder.Renderer.Present(vFrame, false);
if (!MainDemuxer.IsHLSLive && seeks.IsEmpty)
{
curTime = (long) (vFrame.timestamp * Speed);
Expand Down

0 comments on commit 501159a

Please sign in to comment.