From 23252a149fa17623b3af7234d5748231c524d00d Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Tue, 20 Sep 2022 11:31:27 -0700 Subject: [PATCH] ignore currently loaded video on VideoPlayer.Load --- src/Video/VideoPlayer.cs | 119 ++++++++++++++++++++------------------- 1 file changed, 61 insertions(+), 58 deletions(-) diff --git a/src/Video/VideoPlayer.cs b/src/Video/VideoPlayer.cs index 987ef73..5622b6d 100644 --- a/src/Video/VideoPlayer.cs +++ b/src/Video/VideoPlayer.cs @@ -58,66 +58,69 @@ namespace MoonWorks.Video public void Load(Video video) { - Stop(); - - if (RenderTexture == null) + if (Video != video) { - RenderTexture = CreateRenderTexture(GraphicsDevice, video.Width, video.Height); + Stop(); + + if (RenderTexture == null) + { + RenderTexture = CreateRenderTexture(GraphicsDevice, video.Width, video.Height); + } + + if (yTexture == null) + { + yTexture = CreateSubTexture(GraphicsDevice, video.Width, video.Height); + } + + if (uTexture == null) + { + uTexture = CreateSubTexture(GraphicsDevice, video.UVWidth, video.UVHeight); + } + + if (vTexture == null) + { + vTexture = CreateSubTexture(GraphicsDevice, video.UVWidth, video.UVHeight); + } + + if (video.Width != RenderTexture.Width || video.Height != RenderTexture.Height) + { + RenderTexture.Dispose(); + RenderTexture = CreateRenderTexture(GraphicsDevice, video.Width, video.Height); + } + + if (video.Width != yTexture.Width || video.Height != yTexture.Height) + { + yTexture.Dispose(); + yTexture = CreateSubTexture(GraphicsDevice, video.Width, video.Height); + } + + if (video.UVWidth != uTexture.Width || video.UVHeight != uTexture.Height) + { + uTexture.Dispose(); + uTexture = CreateSubTexture(GraphicsDevice, video.UVWidth, video.UVHeight); + } + + if (video.UVWidth != vTexture.Width || video.UVHeight != vTexture.Height) + { + vTexture.Dispose(); + vTexture = CreateSubTexture(GraphicsDevice, video.UVWidth, video.UVHeight); + } + + var newDataLength = ( + (video.Width * video.Height) + + (video.UVWidth * video.UVHeight * 2) + ); + + if (newDataLength != yuvDataLength) + { + yuvData = NativeMemory.Realloc(yuvData, (nuint) newDataLength); + yuvDataLength = newDataLength; + } + + Video = video; + + InitializeTheoraStream(); } - - if (yTexture == null) - { - yTexture = CreateSubTexture(GraphicsDevice, video.Width, video.Height); - } - - if (uTexture == null) - { - uTexture = CreateSubTexture(GraphicsDevice, video.UVWidth, video.UVHeight); - } - - if (vTexture == null) - { - vTexture = CreateSubTexture(GraphicsDevice, video.UVWidth, video.UVHeight); - } - - if (video.Width != RenderTexture.Width || video.Height != RenderTexture.Height) - { - RenderTexture.Dispose(); - RenderTexture = CreateRenderTexture(GraphicsDevice, video.Width, video.Height); - } - - if (video.Width != yTexture.Width || video.Height != yTexture.Height) - { - yTexture.Dispose(); - yTexture = CreateSubTexture(GraphicsDevice, video.Width, video.Height); - } - - if (video.UVWidth != uTexture.Width || video.UVHeight != uTexture.Height) - { - uTexture.Dispose(); - uTexture = CreateSubTexture(GraphicsDevice, video.UVWidth, video.UVHeight); - } - - if (video.UVWidth != vTexture.Width || video.UVHeight != vTexture.Height) - { - vTexture.Dispose(); - vTexture = CreateSubTexture(GraphicsDevice, video.UVWidth, video.UVHeight); - } - - var newDataLength = ( - (video.Width * video.Height) + - (video.UVWidth * video.UVHeight * 2) - ); - - if (newDataLength != yuvDataLength) - { - yuvData = NativeMemory.Realloc(yuvData, (nuint) newDataLength); - yuvDataLength = newDataLength; - } - - Video = video; - - InitializeTheoraStream(); } public void Play()