Skip to content

Commit f724ce4

Browse files
kiddkaffeinekiddkaffeine
authored andcommitted
Draft of AV1 support
1 parent 87c46aa commit f724ce4

File tree

11 files changed

+604
-2
lines changed

11 files changed

+604
-2
lines changed

FNA.Core.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@
331331
<Compile Include="src\Media\Xiph\IVideoPlayerCodec.cs" />
332332
<Compile Include="src\Media\Xiph\Video.cs" />
333333
<Compile Include="src\Media\Xiph\VideoPlayer.cs" />
334+
<Compile Include="src\Media\Xiph\VideoPlayerAV1.cs" />
334335
<Compile Include="src\Media\Xiph\VideoPlayerTheora.cs" />
335336
<Compile Include="src\NamespaceDocs.cs" />
336337
<Compile Include="src\Plane.cs" />
@@ -360,6 +361,7 @@
360361
<Compile Include="lib\SDL3-CS\SDL3\SDL3.Legacy.cs" />
361362
<Compile Include="lib\FAudio\csharp\FAudio.cs" />
362363
<Compile Include="lib\Theorafile\csharp\Theorafile.cs" />
364+
<Compile Include="lib\dav1dfile\csharp\dav1dfile.Legacy.cs" />
363365
</ItemGroup>
364366
<ItemGroup>
365367
<None Include="app.config" />
@@ -386,5 +388,8 @@
386388
<EmbeddedResource Include="src\Graphics\Effect\YUVToRGBA\YUVToRGBAEffect.fxb">
387389
<LogicalName>Microsoft.Xna.Framework.Graphics.Effect.Resources.YUVToRGBAEffect.fxb</LogicalName>
388390
</EmbeddedResource>
391+
<EmbeddedResource Include="src\Graphics\Effect\YUVToRGBA\YUVToRGBAEffectR.fxb">
392+
<LogicalName>Microsoft.Xna.Framework.Graphics.Effect.Resources.YUVToRGBAEffectR.fxb</LogicalName>
393+
</EmbeddedResource>
389394
</ItemGroup>
390395
</Project>

FNA.NetFramework.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@
332332
<Compile Include="src\Media\Xiph\IVideoPlayerCodec.cs" />
333333
<Compile Include="src\Media\Xiph\Video.cs" />
334334
<Compile Include="src\Media\Xiph\VideoPlayer.cs" />
335+
<Compile Include="src\Media\Xiph\VideoPlayerAV1.cs" />
335336
<Compile Include="src\Media\Xiph\VideoPlayerTheora.cs" />
336337
<Compile Include="src\NamespaceDocs.cs" />
337338
<Compile Include="src\Plane.cs" />
@@ -361,6 +362,7 @@
361362
<Compile Include="lib\SDL3-CS\SDL3\SDL3.Legacy.cs" />
362363
<Compile Include="lib\FAudio\csharp\FAudio.cs" />
363364
<Compile Include="lib\Theorafile\csharp\Theorafile.cs" />
365+
<Compile Include="lib\dav1dfile\csharp\dav1dfile.Legacy.cs" />
364366
</ItemGroup>
365367
<ItemGroup>
366368
<None Include="app.config" />
@@ -387,5 +389,8 @@
387389
<EmbeddedResource Include="src\Graphics\Effect\YUVToRGBA\YUVToRGBAEffect.fxb">
388390
<LogicalName>Microsoft.Xna.Framework.Graphics.Effect.Resources.YUVToRGBAEffect.fxb</LogicalName>
389391
</EmbeddedResource>
392+
<EmbeddedResource Include="src\Graphics\Effect\YUVToRGBA\YUVToRGBAEffectR.fxb">
393+
<LogicalName>Microsoft.Xna.Framework.Graphics.Effect.Resources.YUVToRGBAEffectR.fxb</LogicalName>
394+
</EmbeddedResource>
390395
</ItemGroup>
391396
</Project>

FNA.NetStandard.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@
330330
<Compile Include="src\Media\Xiph\IVideoPlayerCodec.cs" />
331331
<Compile Include="src\Media\Xiph\Video.cs" />
332332
<Compile Include="src\Media\Xiph\VideoPlayer.cs" />
333+
<Compile Include="src\Media\Xiph\VideoPlayerAV1.cs" />
333334
<Compile Include="src\Media\Xiph\VideoPlayerTheora.cs" />
334335
<Compile Include="src\NamespaceDocs.cs" />
335336
<Compile Include="src\Plane.cs" />
@@ -359,6 +360,7 @@
359360
<Compile Include="lib\SDL3-CS\SDL3\SDL3.Legacy.cs" />
360361
<Compile Include="lib\FAudio\csharp\FAudio.cs" />
361362
<Compile Include="lib\Theorafile\csharp\Theorafile.cs" />
363+
<Compile Include="lib\dav1dfile\csharp\dav1dfile.Legacy.cs" />
362364
</ItemGroup>
363365
<ItemGroup>
364366
<None Include="app.config" />
@@ -385,5 +387,8 @@
385387
<EmbeddedResource Include="src\Graphics\Effect\YUVToRGBA\YUVToRGBAEffect.fxb">
386388
<LogicalName>Microsoft.Xna.Framework.Graphics.Effect.Resources.YUVToRGBAEffect.fxb</LogicalName>
387389
</EmbeddedResource>
390+
<EmbeddedResource Include="src\Graphics\Effect\YUVToRGBA\YUVToRGBAEffectR.fxb">
391+
<LogicalName>Microsoft.Xna.Framework.Graphics.Effect.Resources.YUVToRGBAEffectR.fxb</LogicalName>
392+
</EmbeddedResource>
388393
</ItemGroup>
389394
</Project>

FNA.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@
402402
<Compile Include="src\Media\Xiph\IVideoPlayerCodec.cs" />
403403
<Compile Include="src\Media\Xiph\Video.cs" />
404404
<Compile Include="src\Media\Xiph\VideoPlayer.cs" />
405+
<Compile Include="src\Media\Xiph\VideoPlayerAV1.cs" />
405406
<Compile Include="src\Media\Xiph\VideoPlayerTheora.cs" />
406407
<Compile Include="src\NamespaceDocs.cs" />
407408
<Compile Include="src\Plane.cs" />
@@ -431,6 +432,7 @@
431432
<Compile Include="lib\SDL3-CS\SDL3\SDL3.Legacy.cs" />
432433
<Compile Include="lib\FAudio\csharp\FAudio.cs" />
433434
<Compile Include="lib\Theorafile\csharp\Theorafile.cs" />
435+
<Compile Include="lib\dav1dfile\csharp\dav1dfile.Legacy.cs" />
434436
</ItemGroup>
435437
<ItemGroup>
436438
<None Include="app.config">
@@ -460,5 +462,8 @@
460462
<EmbeddedResource Include="src\Graphics\Effect\YUVToRGBA\YUVToRGBAEffect.fxb">
461463
<LogicalName>Microsoft.Xna.Framework.Graphics.Effect.Resources.YUVToRGBAEffect.fxb</LogicalName>
462464
</EmbeddedResource>
465+
<EmbeddedResource Include="src\Graphics\Effect\YUVToRGBA\YUVToRGBAEffectR.fxb">
466+
<LogicalName>Microsoft.Xna.Framework.Graphics.Effect.Resources.YUVToRGBAEffectR.fxb</LogicalName>
467+
</EmbeddedResource>
463468
</ItemGroup>
464469
</Project>

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ SRC = \
316316
src/Media/Xiph/Video.cs \
317317
src/Media/Xiph/VideoPlayer.cs \
318318
src/Media/Xiph/VideoPlayerTheora.cs \
319+
src/Media/Xiph/VideoPlayerAV1.cs \
319320
src/NamespaceDocs.cs \
320321
src/Plane.cs \
321322
src/PlaneIntersectionType.cs \
@@ -342,7 +343,8 @@ SRC = \
342343
lib/SDL2-CS/src/SDL2.cs \
343344
lib/SDL3-CS/SDL3/SDL3.Legacy.cs \
344345
lib/FAudio/csharp/FAudio.cs \
345-
lib/Theorafile/csharp/Theorafile.cs
346+
lib/Theorafile/csharp/Theorafile.cs \
347+
lib/dav1dfile/csharp/dav1dfile.Legacy.cs
346348

347349
RESDIR = src/Graphics/Effect/StockEffects/FXB
348350
RESNAME = Microsoft.Xna.Framework.Graphics.Effect.Resources
@@ -353,7 +355,8 @@ RES = \
353355
-resource:$(RESDIR)/EnvironmentMapEffect.fxb,$(RESNAME).EnvironmentMapEffect.fxb \
354356
-resource:$(RESDIR)/SkinnedEffect.fxb,$(RESNAME).SkinnedEffect.fxb \
355357
-resource:$(RESDIR)/SpriteEffect.fxb,$(RESNAME).SpriteEffect.fxb \
356-
-resource:src/Graphics/Effect/YUVToRGBA/YUVToRGBAEffect.fxb,$(RESNAME).YUVToRGBAEffect.fxb
358+
-resource:src/Graphics/Effect/YUVToRGBA/YUVToRGBAEffect.fxb,$(RESNAME).YUVToRGBAEffect.fxb \
359+
-resource:src/Graphics/Effect/YUVToRGBA/YUVToRGBAEffectR.fxb,$(RESNAME).YUVToRGBAEffectR.fxb
357360

358361
# Targets
359362

app.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
<dllmap dll="FAudio" os="osx" target="libFAudio.0.dylib"/>
1313
<dllmap dll="FAudio" os="linux,freebsd,netbsd" target="libFAudio.so.0"/>
1414

15+
<dllmap dll="dav1dfile" os="windows" target="libdav1dfile.dll"/>
16+
<dllmap dll="dav1dfile" os="osx" target="libdav1dfile.1.dylib"/>
17+
<dllmap dll="dav1dfile" os="linux,freebsd,netbsd" target="libdav1dfile.so.0"/>
18+
1519
<!-- Deprecated! -->
1620
<dllmap dll="SDL2" os="windows" target="SDL2.dll"/>
1721
<dllmap dll="SDL2" os="osx" target="libSDL2-2.0.0.dylib"/>

src/Graphics/Effect/Resources.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ public static byte[] YUVToRGBAEffect
102102
}
103103
}
104104

105+
public static byte[] YUVToRGBAEffectR
106+
{
107+
get
108+
{
109+
if (yuvToRGBAEffectR == null)
110+
{
111+
yuvToRGBAEffectR = GetResource("YUVToRGBAEffectR");
112+
}
113+
return yuvToRGBAEffectR;
114+
}
115+
}
116+
105117
#endregion
106118

107119
#region Private Static Variables
@@ -113,6 +125,7 @@ public static byte[] YUVToRGBAEffect
113125
private static byte[] skinnedEffect;
114126
private static byte[] spriteEffect;
115127
private static byte[] yuvToRGBAEffect;
128+
private static byte[] yuvToRGBAEffectR;
116129

117130
#endregion
118131

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* YUV-to-RGBA Effect
2+
* Written by Ethan "flibitijibibo" Lee
3+
* http://www.flibitijibibo.com/
4+
*
5+
* This effect is based on the YUV-to-RGBA GLSL shader found in SDL.
6+
* Thus, it also released under the zlib license:
7+
* http://libsdl.org/license.php
8+
*/
9+
10+
sampler samp0 : register(s0);
11+
sampler samp1 : register(s1);
12+
sampler samp2 : register(s2);
13+
14+
float4 RescaleFactor : register(ps, c0) = float4(1, 1, 1, 1);
15+
16+
void VS(inout float2 tex : TEXCOORD0,
17+
inout float4 pos : SV_Position)
18+
{
19+
pos.w = 1.0;
20+
}
21+
22+
float4 PS(float2 tex : TEXCOORD0) : SV_Target0
23+
{
24+
const float3 offset = float3(-0.0625, -0.5, -0.5);
25+
26+
/* More info about colorspace conversion:
27+
* http://www.equasys.de/colorconversion.html
28+
* http://www.equasys.de/colorformat.html
29+
*/
30+
#if 1
31+
/* ITU-R BT.709 */
32+
const float3 Rcoeff = float3(1.164, 0.000, 1.793);
33+
const float3 Gcoeff = float3(1.164, -0.213, -0.533);
34+
const float3 Bcoeff = float3(1.164, 2.112, 0.000);
35+
#else
36+
/* ITU-R BT.601 */
37+
const float3 Rcoeff = float3(1.164, 0.000, 1.596);
38+
const float3 Gcoeff = float3(1.164, -0.391, -0.813);
39+
const float3 Bcoeff = float3(1.164, 2.018, 0.000);
40+
#endif
41+
42+
float3 yuv;
43+
yuv.x = tex2D(samp0, tex).r;
44+
yuv.y = tex2D(samp1, tex).r;
45+
yuv.z = tex2D(samp2, tex).r;
46+
yuv *= RescaleFactor;
47+
yuv += offset;
48+
49+
float4 rgba;
50+
rgba.x = dot(yuv, Rcoeff);
51+
rgba.y = dot(yuv, Gcoeff);
52+
rgba.z = dot(yuv, Bcoeff);
53+
rgba.w = 1.0;
54+
return rgba;
55+
}
56+
57+
Technique T
58+
{
59+
Pass P
60+
{
61+
VertexShader = compile vs_3_0 VS();
62+
PixelShader = compile ps_3_0 PS();
63+
}
64+
}
1.2 KB
Binary file not shown.

src/Media/Xiph/VideoPlayer.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,22 @@ public float Volume
121121
internal static Dictionary<string, string> codecExtensions =
122122
new Dictionary<string, string>
123123
{
124+
{ "obu", "AV1" },
125+
{ "av1", "AV1" },
124126
{ "ogv", "Theora" }
125127
};
126128

127129
internal static Dictionary<string, Func<string, VideoInfo>> codecInfoReaders =
128130
new Dictionary<string, Func<string, VideoInfo>>
129131
{
132+
{ "AV1", VideoPlayerAV1.ReadInfo },
130133
{ "Theora", VideoPlayerTheora.ReadInfo }
131134
};
132135

133136
internal static Dictionary<string, Func<IVideoPlayerCodec>> codecPlayers =
134137
new Dictionary<string, Func<IVideoPlayerCodec>>
135138
{
139+
{ "AV1", () => new VideoPlayerAV1() },
136140
{ "Theora", () => new VideoPlayerTheora() },
137141
};
138142

0 commit comments

Comments
 (0)