adjust VideoPlayer to unload AV1 streams on Unload
parent
9e4e44bb52
commit
679ad2463c
|
@ -8,6 +8,7 @@ namespace MoonWorks.Video
|
|||
public IntPtr Handle => handle;
|
||||
IntPtr handle;
|
||||
|
||||
public bool Loaded => handle != IntPtr.Zero;
|
||||
public bool Ended => Dav1dfile.df_eos(Handle) == 1;
|
||||
|
||||
public IntPtr yDataHandle;
|
||||
|
@ -20,21 +21,41 @@ namespace MoonWorks.Video
|
|||
|
||||
public bool FrameDataUpdated { get; set; }
|
||||
|
||||
private VideoAV1 Parent;
|
||||
|
||||
public VideoAV1Stream(GraphicsDevice device, VideoAV1 video) : base(device)
|
||||
{
|
||||
if (Dav1dfile.df_fopen(video.Filename, out handle) == 0)
|
||||
{
|
||||
throw new Exception("Failed to open video file!");
|
||||
}
|
||||
handle = IntPtr.Zero;
|
||||
Parent = video;
|
||||
}
|
||||
|
||||
Reset();
|
||||
public void Load()
|
||||
{
|
||||
if (!Loaded)
|
||||
{
|
||||
if (Dav1dfile.df_fopen(Parent.Filename, out handle) == 0)
|
||||
{
|
||||
throw new Exception("Failed to load video file!");
|
||||
}
|
||||
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
|
||||
public void Unload()
|
||||
{
|
||||
if (Loaded)
|
||||
{
|
||||
Dav1dfile.df_close(handle);
|
||||
handle = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
Dav1dfile.df_reset(Handle);
|
||||
Dav1dfile.df_reset(handle);
|
||||
ReadNextFrame();
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +67,7 @@ namespace MoonWorks.Video
|
|||
if (!Ended)
|
||||
{
|
||||
if (Dav1dfile.df_readvideo(
|
||||
Handle,
|
||||
handle,
|
||||
1,
|
||||
out var yDataHandle,
|
||||
out var uDataHandle,
|
||||
|
@ -74,7 +95,7 @@ namespace MoonWorks.Video
|
|||
{
|
||||
if (!IsDisposed)
|
||||
{
|
||||
Dav1dfile.df_close(Handle);
|
||||
Unload();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
|
|
@ -164,9 +164,18 @@ namespace MoonWorks.Video
|
|||
/// </summary>
|
||||
public void Unload()
|
||||
{
|
||||
Stop();
|
||||
ReadNextFrameTask?.Wait();
|
||||
ResetTask?.Wait();
|
||||
ResetSecondaryStreamTask?.Wait();
|
||||
|
||||
Stop();
|
||||
|
||||
Video.StreamA.Unload();
|
||||
Video.StreamB.Unload();
|
||||
|
||||
ReadNextFrameTask = null;
|
||||
ResetTask = null;
|
||||
ResetSecondaryStreamTask = null;
|
||||
Video = null;
|
||||
}
|
||||
|
||||
|
@ -224,6 +233,7 @@ namespace MoonWorks.Video
|
|||
lock (CurrentStream)
|
||||
{
|
||||
ResetTask?.Wait();
|
||||
ResetTask = null;
|
||||
|
||||
var commandBuffer = Device.AcquireCommandBuffer();
|
||||
|
||||
|
@ -322,7 +332,11 @@ namespace MoonWorks.Video
|
|||
|
||||
private void InitializeDav1dStream()
|
||||
{
|
||||
Video.StreamA.Load();
|
||||
Video.StreamB.Load();
|
||||
|
||||
ReadNextFrameTask?.Wait();
|
||||
ReadNextFrameTask = null;
|
||||
|
||||
ResetTask = Task.Run(Video.StreamA.Reset);
|
||||
ResetTask.ContinueWith(HandleTaskException, TaskContinuationOptions.OnlyOnFaulted);
|
||||
|
|
Loading…
Reference in New Issue