Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay loading Video files as much as possible, to match XNA behavior #8

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Content/ContentReaders/SongReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ protected internal override Song Read(ContentReader input, Song existingInstance
/* The path string includes the ".wma" extension. Let's see if this
* file exists in a format we actually support...
*/
path = Normalize(path.Substring(0, path.Length - 4));
if (String.IsNullOrEmpty(path))
string realPath = Normalize(path.Substring(0, path.Length - 4));
if (!String.IsNullOrEmpty(realPath))
{
throw new ContentLoadException();
path = realPath;
}

int durationMs = input.ReadInt32();
Expand Down
6 changes: 3 additions & 3 deletions src/Content/ContentReaders/VideoReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ Video existingInstance
/* The path string includes the ".wmv" extension. Let's see if this
* file exists in a format we actually support...
*/
path = Normalize(path.Substring(0, path.Length - 4));
if (String.IsNullOrEmpty(path))
string realPath = Normalize(path.Substring(0, path.Length - 4));
if (!String.IsNullOrEmpty(realPath))
{
throw new ContentLoadException();
path = realPath;
}

int durationMS = input.ReadObject<int>();
Expand Down
95 changes: 35 additions & 60 deletions src/Media/Xiph/Video.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,20 @@ public sealed class Video

public int Width
{
get
{
return yWidth;
}
get;
internal set;
}

public int Height
{
get
{
return yHeight;
}
get;
internal set;
}

public float FramesPerSecond
{
get
{
return (float) fps;
}
get;
internal set;
}

public VideoSoundtrackType VideoSoundtrackType
Expand Down Expand Up @@ -69,14 +63,9 @@ internal GraphicsDevice GraphicsDevice

#endregion

#region Internal Variables: Theorafile
#region Internal Variables

internal IntPtr theora;
internal int yWidth;
internal int yHeight;
internal int uvWidth;
internal int uvHeight;
internal double fps;
internal string handle;
internal bool needsDurationHack;

#endregion
Expand All @@ -85,38 +74,20 @@ internal GraphicsDevice GraphicsDevice

internal Video(string fileName, GraphicsDevice device)
{
handle = fileName;
GraphicsDevice = device;

Theorafile.th_pixel_fmt fmt;
/* This is the raw file constructor; unlike the XNB
* constructor we can be up front about files not
* existing, so let's do that!
*/
IntPtr theora;
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)
if (theora == IntPtr.Zero)
{
uvWidth = yWidth;
uvHeight = yHeight;
}
else
{
throw new NotSupportedException(
"Unrecognized YUV format!"
);
throw new FileNotFoundException(fileName);
}
Theorafile.tf_close(ref theora);

// FIXME: This is a part of the Duration hack!
Duration = TimeSpan.MaxValue;
Expand All @@ -131,7 +102,19 @@ internal Video(
int height,
float framesPerSecond,
VideoSoundtrackType soundtrackType
) : this(fileName, device) {
) {
handle = fileName;
GraphicsDevice = device;

/* This is the XNB constructor, which really just loads
* the metadata without actually loading the video. For
* accuracy's sake we have to wait until VideoPlayer
* tries to load this before throwing Exceptions.
*/
Width = width;
Height = height;
FramesPerSecond = framesPerSecond;

// FIXME: Oh, hey! I wish we had this info in Theora!
Duration = TimeSpan.FromMilliseconds(durationMS);
needsDurationHack = false;
Expand Down Expand Up @@ -168,23 +151,15 @@ public static Video FromUriEXT(Uri uri, GraphicsDevice graphicsDevice)
return new Video(path, graphicsDevice);
}

public void SetAudioTrackEXT(int track)
{
if (theora != IntPtr.Zero)
{
Theorafile.tf_setaudiotrack(theora, track);
}
}
// FIXME: These should be in VideoPlayer instead!

#endregion

#region Destructor
internal VideoPlayer parent; // FIXME: Remove this when extension is replaced!!!

~Video()
public void SetAudioTrackEXT(int track)
{
if (theora != IntPtr.Zero)
if (parent != null)
{
Theorafile.tf_close(ref theora);
parent.SetAudioTrackEXT(track);
}
}

Expand Down
Loading
Loading