From 871b32d742bcf6e7b75d5842e7220c734c1a0109 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Mon, 11 Mar 2024 18:04:50 -0700 Subject: [PATCH] some more threading changes --- src/Video/VideoPlayer.cs | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/Video/VideoPlayer.cs b/src/Video/VideoPlayer.cs index 3966237..39dc44c 100644 --- a/src/Video/VideoPlayer.cs +++ b/src/Video/VideoPlayer.cs @@ -154,7 +154,7 @@ namespace MoonWorks.Video lastTimestamp = 0; timeElapsed = 0; - InitializeDav1dStream(); + ResetDav1dStream(); State = VideoState.Stopped; } @@ -168,7 +168,13 @@ namespace MoonWorks.Video ResetTask?.Wait(); ResetSecondaryStreamTask?.Wait(); - Stop(); + timer.Stop(); + timer.Reset(); + + lastTimestamp = 0; + timeElapsed = 0; + + State = VideoState.Stopped; Video.StreamA.Unload(); Video.StreamB.Unload(); @@ -211,8 +217,8 @@ namespace MoonWorks.Video timer.Stop(); timer.Reset(); - ResetTask = Task.Run(CurrentStream.Reset); - ResetTask.ContinueWith(HandleTaskException, TaskContinuationOptions.OnlyOnFaulted); + ResetSecondaryStreamTask = Task.Run(CurrentStream.Reset); + ResetSecondaryStreamTask.ContinueWith(HandleTaskException, TaskContinuationOptions.OnlyOnFaulted); if (Loop) { @@ -332,9 +338,26 @@ namespace MoonWorks.Video private void InitializeDav1dStream() { - Video.StreamA.Load(); - Video.StreamB.Load(); + ReadNextFrameTask?.Wait(); + ReadNextFrameTask = null; + ResetTask?.Wait(); + ResetTask = null; + + ResetSecondaryStreamTask?.Wait(); + ResetSecondaryStreamTask = null; + + ResetTask = Task.Run(Video.StreamA.Load); + ResetTask.ContinueWith(HandleTaskException, TaskContinuationOptions.OnlyOnFaulted); + ResetSecondaryStreamTask = Task.Run(Video.StreamB.Load); + ResetSecondaryStreamTask.ContinueWith(HandleTaskException, TaskContinuationOptions.OnlyOnFaulted); + + CurrentStream = Video.StreamA; + currentFrame = -1; + } + + private void ResetDav1dStream() + { ReadNextFrameTask?.Wait(); ReadNextFrameTask = null;