From 99c5d2cddeb882971d9695d35788c0953e955cc9 Mon Sep 17 00:00:00 2001 From: Brendan McGrath Date: Fri, 31 May 2024 10:13:53 +1000 Subject: [PATCH] Don't throw exception for missing Video until its played --- src/Content/ContentReaders/VideoReader.cs | 3 +- src/Media/Xiph/Video.cs | 68 +++++++++++++---------- src/Media/Xiph/VideoPlayer.cs | 9 +++ 3 files changed, 50 insertions(+), 30 deletions(-) diff --git a/src/Content/ContentReaders/VideoReader.cs b/src/Content/ContentReaders/VideoReader.cs index b9b768704..00e3dc61d 100644 --- a/src/Content/ContentReaders/VideoReader.cs +++ b/src/Content/ContentReaders/VideoReader.cs @@ -41,10 +41,11 @@ Video existingInstance /* The path string includes the ".wmv" extension. Let's see if this * file exists in a format we actually support... */ + string origpath = path; path = Normalize(path.Substring(0, path.Length - 4)); if (String.IsNullOrEmpty(path)) { - throw new ContentLoadException(); + path = origpath; } int durationMS = input.ReadObject(); diff --git a/src/Media/Xiph/Video.cs b/src/Media/Xiph/Video.cs index 4e1ef9665..c29a995a5 100644 --- a/src/Media/Xiph/Video.cs +++ b/src/Media/Xiph/Video.cs @@ -89,38 +89,41 @@ internal Video(string fileName, GraphicsDevice device) Theorafile.th_pixel_fmt fmt; Theorafile.tf_fopen(fileName, out theora); - Theorafile.tf_videoinfo( - theora, - out yWidth, - out yHeight, - out fps, - out fmt - ); - if (fmt == Theorafile.th_pixel_fmt.TH_PF_420) - { - uvWidth = yWidth / 2; - uvHeight = yHeight / 2; - } - else if (fmt == Theorafile.th_pixel_fmt.TH_PF_422) - { - uvWidth = yWidth / 2; - uvHeight = yHeight; - } - else if (fmt == Theorafile.th_pixel_fmt.TH_PF_444) - { - uvWidth = yWidth; - uvHeight = yHeight; - } - else + if (theora != IntPtr.Zero) { - throw new NotSupportedException( - "Unrecognized YUV format!" + Theorafile.tf_videoinfo( + theora, + out yWidth, + out yHeight, + out fps, + out fmt ); - } + if (fmt == Theorafile.th_pixel_fmt.TH_PF_420) + { + uvWidth = yWidth / 2; + uvHeight = yHeight / 2; + } + else if (fmt == Theorafile.th_pixel_fmt.TH_PF_422) + { + uvWidth = yWidth / 2; + uvHeight = yHeight; + } + else if (fmt == Theorafile.th_pixel_fmt.TH_PF_444) + { + uvWidth = yWidth; + uvHeight = yHeight; + } + else + { + throw new NotSupportedException( + "Unrecognized YUV format!" + ); + } - // FIXME: This is a part of the Duration hack! - Duration = TimeSpan.MaxValue; - needsDurationHack = true; + // FIXME: This is a part of the Duration hack! + Duration = TimeSpan.MaxValue; + needsDurationHack = true; + } } internal Video( @@ -136,6 +139,13 @@ VideoSoundtrackType soundtrackType Duration = TimeSpan.FromMilliseconds(durationMS); needsDurationHack = false; + if (theora == IntPtr.Zero) + { + yWidth = width; + yHeight = height; + fps = framesPerSecond; + } + VideoSoundtrackType = soundtrackType; } diff --git a/src/Media/Xiph/VideoPlayer.cs b/src/Media/Xiph/VideoPlayer.cs index 3627f52d9..beaed0ab3 100644 --- a/src/Media/Xiph/VideoPlayer.cs +++ b/src/Media/Xiph/VideoPlayer.cs @@ -594,6 +594,15 @@ public Texture2D GetTexture() public void Play(Video video) { + if (video == null) + { + throw new System.ArgumentNullException(); + } + if (video.theora == IntPtr.Zero) + { + throw new System.ArgumentException(); + } + checkDisposed(); // We need to assign this regardless of what happens next.