potential fix for render before decode finish

what_if_no_video_threads
cosmonaut 2024-03-11 16:57:31 -07:00
parent 8813a0139d
commit 9e4e44bb52
1 changed files with 12 additions and 19 deletions

View File

@ -19,8 +19,8 @@ namespace MoonWorks.Video
private VideoAV1Stream CurrentStream = null; private VideoAV1Stream CurrentStream = null;
private Task ReadNextFrameTask; private Task ReadNextFrameTask;
private Task ResetStreamATask; private Task ResetTask;
private Task ResetStreamBTask; private Task ResetSecondaryStreamTask;
private Texture yTexture = null; private Texture yTexture = null;
private Texture uTexture = null; private Texture uTexture = null;
@ -165,8 +165,8 @@ namespace MoonWorks.Video
public void Unload() public void Unload()
{ {
Stop(); Stop();
ResetStreamATask?.Wait(); ResetTask?.Wait();
ResetStreamBTask?.Wait(); ResetSecondaryStreamTask?.Wait();
Video = null; Video = null;
} }
@ -202,17 +202,8 @@ namespace MoonWorks.Video
timer.Stop(); timer.Stop();
timer.Reset(); timer.Reset();
var task = Task.Run(CurrentStream.Reset); ResetTask = Task.Run(CurrentStream.Reset);
task.ContinueWith(HandleTaskException, TaskContinuationOptions.OnlyOnFaulted); ResetTask.ContinueWith(HandleTaskException, TaskContinuationOptions.OnlyOnFaulted);
if (CurrentStream == Video.StreamA)
{
ResetStreamATask = task;
}
else
{
ResetStreamBTask = task;
}
if (Loop) if (Loop)
{ {
@ -232,6 +223,8 @@ namespace MoonWorks.Video
{ {
lock (CurrentStream) lock (CurrentStream)
{ {
ResetTask?.Wait();
var commandBuffer = Device.AcquireCommandBuffer(); var commandBuffer = Device.AcquireCommandBuffer();
var ySpan = new Span<byte>((void*) CurrentStream.yDataHandle, (int) CurrentStream.yDataLength); var ySpan = new Span<byte>((void*) CurrentStream.yDataHandle, (int) CurrentStream.yDataLength);
@ -331,10 +324,10 @@ namespace MoonWorks.Video
{ {
ReadNextFrameTask?.Wait(); ReadNextFrameTask?.Wait();
ResetStreamATask = Task.Run(Video.StreamA.Reset); ResetTask = Task.Run(Video.StreamA.Reset);
ResetStreamATask.ContinueWith(HandleTaskException, TaskContinuationOptions.OnlyOnFaulted); ResetTask.ContinueWith(HandleTaskException, TaskContinuationOptions.OnlyOnFaulted);
ResetStreamBTask = Task.Run(Video.StreamB.Reset); ResetSecondaryStreamTask = Task.Run(Video.StreamB.Reset);
ResetStreamBTask.ContinueWith(HandleTaskException, TaskContinuationOptions.OnlyOnFaulted); ResetSecondaryStreamTask.ContinueWith(HandleTaskException, TaskContinuationOptions.OnlyOnFaulted);
CurrentStream = Video.StreamA; CurrentStream = Video.StreamA;
currentFrame = -1; currentFrame = -1;