Skip to content

Commit 57c209d

Browse files
kiddkaffeinekiddkaffeine
authored andcommitted
Separate Video/VideoPlayer from Theora implementation and allow new codecs to be registered
1 parent fba4dfc commit 57c209d

File tree

10 files changed

+1185
-460
lines changed

10 files changed

+1185
-460
lines changed

FNA.Core.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,10 @@
328328
<Compile Include="src\Media\VideoSoundtrackType.cs" />
329329
<Compile Include="src\Media\VisualizationData.cs" />
330330
<Compile Include="src\Media\Xiph\BaseYUVPlayer.cs" />
331+
<Compile Include="src\Media\Xiph\IVideoPlayerImpl.cs" />
331332
<Compile Include="src\Media\Xiph\Video.cs" />
332333
<Compile Include="src\Media\Xiph\VideoPlayer.cs" />
334+
<Compile Include="src\Media\Xiph\VideoPlayerTheora.cs" />
333335
<Compile Include="src\NamespaceDocs.cs" />
334336
<Compile Include="src\Plane.cs" />
335337
<Compile Include="src\PlaneIntersectionType.cs" />

FNA.NetFramework.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,10 @@
329329
<Compile Include="src\Media\VideoSoundtrackType.cs" />
330330
<Compile Include="src\Media\VisualizationData.cs" />
331331
<Compile Include="src\Media\Xiph\BaseYUVPlayer.cs" />
332+
<Compile Include="src\Media\Xiph\IVideoPlayerImpl.cs" />
332333
<Compile Include="src\Media\Xiph\Video.cs" />
333334
<Compile Include="src\Media\Xiph\VideoPlayer.cs" />
335+
<Compile Include="src\Media\Xiph\VideoPlayerTheora.cs" />
334336
<Compile Include="src\NamespaceDocs.cs" />
335337
<Compile Include="src\Plane.cs" />
336338
<Compile Include="src\PlaneIntersectionType.cs" />

FNA.NetStandard.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,10 @@
327327
<Compile Include="src\Media\VideoSoundtrackType.cs" />
328328
<Compile Include="src\Media\VisualizationData.cs" />
329329
<Compile Include="src\Media\Xiph\BaseYUVPlayer.cs" />
330+
<Compile Include="src\Media\Xiph\IVideoPlayerImpl.cs" />
330331
<Compile Include="src\Media\Xiph\Video.cs" />
331332
<Compile Include="src\Media\Xiph\VideoPlayer.cs" />
333+
<Compile Include="src\Media\Xiph\VideoPlayerTheora.cs" />
332334
<Compile Include="src\NamespaceDocs.cs" />
333335
<Compile Include="src\Plane.cs" />
334336
<Compile Include="src\PlaneIntersectionType.cs" />

FNA.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,10 @@
399399
<Compile Include="src\Media\VideoSoundtrackType.cs" />
400400
<Compile Include="src\Media\VisualizationData.cs" />
401401
<Compile Include="src\Media\Xiph\BaseYUVPlayer.cs" />
402+
<Compile Include="src\Media\Xiph\IVideoPlayerImpl.cs" />
402403
<Compile Include="src\Media\Xiph\Video.cs" />
403404
<Compile Include="src\Media\Xiph\VideoPlayer.cs" />
405+
<Compile Include="src\Media\Xiph\VideoPlayerTheora.cs" />
404406
<Compile Include="src\NamespaceDocs.cs" />
405407
<Compile Include="src\Plane.cs" />
406408
<Compile Include="src\PlaneIntersectionType.cs" />

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,11 @@ SRC = \
311311
src/Media/SongCollection.cs \
312312
src/Media/VideoSoundtrackType.cs \
313313
src/Media/VisualizationData.cs \
314+
src/Media/Xiph/IVideoPlayerImpl.cs \
314315
src/Media/Xiph/BaseYUVPlayer.cs \
315316
src/Media/Xiph/Video.cs \
316317
src/Media/Xiph/VideoPlayer.cs \
318+
src/Media/Xiph/VideoPlayerTheora.cs \
317319
src/NamespaceDocs.cs \
318320
src/Plane.cs \
319321
src/PlaneIntersectionType.cs \

src/Media/Xiph/BaseYUVPlayer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace Microsoft.Xna.Framework.Media
1717
{
18-
internal abstract class BaseYUVPlayer : IDisposable
18+
public abstract class BaseYUVPlayer : IDisposable
1919
{
2020
#region Hardware-accelerated YUV -> RGBA
2121

src/Media/Xiph/IVideoPlayerImpl.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#region License
2+
/* FNA - XNA4 Reimplementation for Desktop Platforms
3+
* Copyright 2009-2024 Ethan Lee and the MonoGame Team
4+
*
5+
* Released under the Microsoft Public License.
6+
* See LICENSE for details.
7+
*/
8+
#endregion
9+
10+
#region Using Statements
11+
using System;
12+
using Microsoft.Xna.Framework.Graphics;
13+
#endregion
14+
15+
namespace Microsoft.Xna.Framework.Media
16+
{
17+
public interface IVideoPlayerImpl : IDisposable
18+
{
19+
#region Public Member Data: XNA VideoPlayer Implementation
20+
21+
bool IsLooped
22+
{
23+
get;
24+
set;
25+
}
26+
27+
bool IsMuted
28+
{
29+
get;
30+
set;
31+
}
32+
33+
TimeSpan PlayPosition
34+
{
35+
get;
36+
}
37+
38+
MediaState State
39+
{
40+
get;
41+
}
42+
43+
Video Video
44+
{
45+
get;
46+
}
47+
48+
float Volume
49+
{
50+
get;
51+
set;
52+
}
53+
54+
#endregion
55+
56+
#region Public Methods: XNA VideoPlayer Implementation
57+
58+
Texture2D GetTexture();
59+
void Play(Video video);
60+
void Stop();
61+
void Pause();
62+
void Resume();
63+
void SetAudioTrackEXT(int track);
64+
void SetVideoTrackEXT(int track);
65+
66+
#endregion
67+
}
68+
}

src/Media/Xiph/Video.cs

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
#region Using Statements
1111
using System;
12+
using System.Collections.Generic;
1213
using System.IO;
13-
1414
using Microsoft.Xna.Framework.Graphics;
1515
#endregion
1616

@@ -61,6 +61,12 @@ internal GraphicsDevice GraphicsDevice
6161
private set;
6262
}
6363

64+
internal String Codec
65+
{
66+
get;
67+
private set;
68+
}
69+
6470
#endregion
6571

6672
#region Internal Variables
@@ -86,24 +92,11 @@ internal Video(string fileName, GraphicsDevice device)
8692
throw new FileNotFoundException(fileName);
8793
}
8894

89-
IntPtr theora;
90-
int width;
91-
int height;
92-
double fps;
93-
Theorafile.th_pixel_fmt fmt;
94-
Theorafile.tf_fopen(fileName, out theora);
95-
Theorafile.tf_videoinfo(
96-
theora,
97-
out width,
98-
out height,
99-
out fps,
100-
out fmt
101-
);
102-
Theorafile.tf_close(ref theora);
103-
104-
Width = width;
105-
Height = height;
106-
FramesPerSecond = (float) fps;
95+
Codec = GuessCodec(fileName);
96+
VideoPlayer.VideoInfo info = VideoPlayer.codecInfoReaders[Codec](fileName);
97+
Width = info.width;
98+
Height = info.height;
99+
FramesPerSecond = (float) info.fps;
107100

108101
// FIXME: This is a part of the Duration hack!
109102
Duration = TimeSpan.MaxValue;
@@ -118,6 +111,18 @@ internal Video(
118111
int height,
119112
float framesPerSecond,
120113
VideoSoundtrackType soundtrackType
114+
) : this(fileName, device, durationMS, width, height, framesPerSecond, soundtrackType, GuessCodec(fileName)) {
115+
}
116+
117+
internal Video(
118+
string fileName,
119+
GraphicsDevice device,
120+
int durationMS,
121+
int width,
122+
int height,
123+
float framesPerSecond,
124+
VideoSoundtrackType soundtrackType,
125+
string codec
121126
) {
122127
handle = fileName;
123128
GraphicsDevice = device;
@@ -130,6 +135,7 @@ VideoSoundtrackType soundtrackType
130135
Width = width;
131136
Height = height;
132137
FramesPerSecond = framesPerSecond;
138+
Codec = codec;
133139

134140
// FIXME: Oh, hey! I wish we had this info in Theora!
135141
Duration = TimeSpan.FromMilliseconds(durationMS);
@@ -141,7 +147,7 @@ VideoSoundtrackType soundtrackType
141147
#endregion
142148

143149
#region Public Extensions
144-
150+
145151
public static Video FromUriEXT(Uri uri, GraphicsDevice graphicsDevice)
146152
{
147153
string path;
@@ -169,7 +175,7 @@ public static Video FromUriEXT(Uri uri, GraphicsDevice graphicsDevice)
169175

170176
internal int audioTrack = -1;
171177
internal int videoTrack = -1;
172-
internal VideoPlayer parent;
178+
internal IVideoPlayerImpl parent;
173179

174180
public void SetAudioTrackEXT(int track)
175181
{
@@ -190,5 +196,24 @@ public void SetVideoTrackEXT(int track)
190196
}
191197

192198
#endregion
199+
200+
#region Private Static Methods
201+
202+
private static string GuessCodec(String filename)
203+
{
204+
filename = filename.ToLower();
205+
foreach (KeyValuePair<string, string> kvp in VideoPlayer.codecExtensions)
206+
{
207+
if (filename.EndsWith(kvp.Key))
208+
{
209+
return kvp.Value;
210+
}
211+
}
212+
213+
// For backwards compatibility
214+
return "Theora";
215+
}
216+
217+
#endregion
193218
}
194219
}

0 commit comments

Comments
 (0)