2023-06-07 21:18:44 +00:00
|
|
|
using System;
|
2023-12-15 18:46:43 +00:00
|
|
|
using MoonWorks.Graphics;
|
2023-06-07 21:18:44 +00:00
|
|
|
|
|
|
|
namespace MoonWorks.Video
|
|
|
|
{
|
2023-12-15 18:46:43 +00:00
|
|
|
internal class VideoAV1Stream : GraphicsResource
|
2023-06-07 21:18:44 +00:00
|
|
|
{
|
|
|
|
public IntPtr Handle => handle;
|
|
|
|
IntPtr handle;
|
|
|
|
|
|
|
|
public bool Ended => Dav1dfile.df_eos(Handle) == 1;
|
|
|
|
|
|
|
|
public IntPtr yDataHandle;
|
|
|
|
public IntPtr uDataHandle;
|
|
|
|
public IntPtr vDataHandle;
|
|
|
|
public uint yDataLength;
|
|
|
|
public uint uvDataLength;
|
|
|
|
public uint yStride;
|
|
|
|
public uint uvStride;
|
|
|
|
|
2023-06-14 02:18:23 +00:00
|
|
|
public bool FrameDataUpdated { get; set; }
|
2023-06-07 21:18:44 +00:00
|
|
|
|
2023-12-15 18:46:43 +00:00
|
|
|
public VideoAV1Stream(GraphicsDevice device, VideoAV1 video) : base(device)
|
2023-06-07 21:18:44 +00:00
|
|
|
{
|
|
|
|
if (Dav1dfile.df_fopen(video.Filename, out handle) == 0)
|
|
|
|
{
|
|
|
|
throw new Exception("Failed to open video file!");
|
|
|
|
}
|
|
|
|
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
{
|
|
|
|
lock (this)
|
|
|
|
{
|
|
|
|
Dav1dfile.df_reset(Handle);
|
|
|
|
ReadNextFrame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ReadNextFrame()
|
|
|
|
{
|
|
|
|
lock (this)
|
|
|
|
{
|
2023-06-14 02:18:23 +00:00
|
|
|
if (!Ended)
|
|
|
|
{
|
|
|
|
if (Dav1dfile.df_readvideo(
|
|
|
|
Handle,
|
|
|
|
1,
|
|
|
|
out var yDataHandle,
|
|
|
|
out var uDataHandle,
|
|
|
|
out var vDataHandle,
|
|
|
|
out var yDataLength,
|
|
|
|
out var uvDataLength,
|
|
|
|
out var yStride,
|
|
|
|
out var uvStride) == 1
|
|
|
|
) {
|
|
|
|
this.yDataHandle = yDataHandle;
|
|
|
|
this.uDataHandle = uDataHandle;
|
|
|
|
this.vDataHandle = vDataHandle;
|
|
|
|
this.yDataLength = yDataLength;
|
|
|
|
this.uvDataLength = uvDataLength;
|
|
|
|
this.yStride = yStride;
|
|
|
|
this.uvStride = uvStride;
|
|
|
|
|
|
|
|
FrameDataUpdated = true;
|
|
|
|
}
|
2023-06-07 21:18:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-15 18:46:43 +00:00
|
|
|
protected override void Dispose(bool disposing)
|
2023-06-07 21:18:44 +00:00
|
|
|
{
|
|
|
|
if (!IsDisposed)
|
|
|
|
{
|
|
|
|
Dav1dfile.df_close(Handle);
|
|
|
|
}
|
2023-12-15 18:46:43 +00:00
|
|
|
base.Dispose(disposing);
|
2023-06-07 21:18:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|