Skip to content

Commit

Permalink
Raw Video metadata can be queried at construction time
Browse files Browse the repository at this point in the history
  • Loading branch information
flibitijibibo committed Jun 3, 2024
1 parent 5ba3d8b commit 6f23d9a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
20 changes: 17 additions & 3 deletions src/Media/Xiph/Video.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ public sealed class Video
public int Width
{
get;
internal set;
private set;
}

public int Height
{
get;
internal set;
private set;
}

public float FramesPerSecond
{
get;
internal set;
private set;
}

public VideoSoundtrackType VideoSoundtrackType
Expand Down Expand Up @@ -87,6 +87,20 @@ internal Video(string fileName, GraphicsDevice device)
{
throw new FileNotFoundException(fileName);
}
int width;
int height;
double fps;
Theorafile.th_pixel_fmt fmt;
Theorafile.tf_videoinfo(
theora,
out width,
out height,
out fps,
out fmt
);
Width = width;
Height = height;
FramesPerSecond = (float) fps;
Theorafile.tf_close(ref theora);

// FIXME: This is a part of the Duration hack!
Expand Down
39 changes: 11 additions & 28 deletions src/Media/Xiph/VideoPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -662,37 +662,20 @@ out fmt
}

// Sanity checks for video metadata
if (Video.Width > 0 && Video.Height > 0)
if (Video.Width != yWidth || Video.Height != yHeight)
{
if (Video.Width != yWidth || Video.Height != yHeight)
{
throw new InvalidOperationException(
"XNB/OGV width/height mismatch!" +
" Width: " + Video.Width.ToString() +
" Height: " + Video.Height.ToString()
);
}
}
else
{
// Probably the raw path, fill it in
Video.Width = yWidth;
Video.Height = yHeight;
}
if (Video.FramesPerSecond > 0)
{
if (Math.Abs(Video.FramesPerSecond - fps) >= 1.0f)
{
throw new InvalidOperationException(
"XNB/OGV framesPerSecond mismatch!" +
" FPS: " + Video.FramesPerSecond.ToString()
);
}
throw new InvalidOperationException(
"XNB/OGV width/height mismatch!" +
" Width: " + Video.Width.ToString() +
" Height: " + Video.Height.ToString()
);
}
else
if (Math.Abs(Video.FramesPerSecond - fps) >= 1.0f)
{
// Probably the raw path, fill it in
Video.FramesPerSecond = (float) fps;
throw new InvalidOperationException(
"XNB/OGV framesPerSecond mismatch!" +
" FPS: " + Video.FramesPerSecond.ToString()
);
}

// Per-video track settings should always take priority
Expand Down

0 comments on commit 6f23d9a

Please sign in to comment.