Skip to content

Commit 36f31a4

Browse files
authored
Merge pull request #99 from dasisdormax/av1-decoding
Desktop: Add dav1d library for AV1 software decoding
2 parents d120bc0 + cebf26c commit 36f31a4

File tree

14 files changed

+291
-129
lines changed

14 files changed

+291
-129
lines changed

.github/workflows/gradle.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Java CI with Gradle
33
on:
44
pull_request:
55
branches: [ master ]
6+
workflow_dispatch:
67

78
jobs:
89
natives-macos:
@@ -23,10 +24,10 @@ jobs:
2324
uses: gradle/gradle-build-action@v2
2425

2526
- name: Install additional build dependencies
26-
run: brew install nasm
27+
run: brew install nasm meson
2728

2829
- name: Build with Gradle
29-
run: ./gradlew :gdx-video-desktop:buildFFmpegMacosAll :gdx-video-desktop:jnigenBuildMacosAll
30+
run: ./gradlew :gdx-video-desktop:FFmpeg:buildFFmpegMacosAll :gdx-video-desktop:jnigenBuildMacosAll
3031

3132
- name: Upload artifacts
3233
uses: actions/upload-artifact@v3
@@ -56,12 +57,12 @@ jobs:
5657
run: |
5758
sudo apt update
5859
sudo apt install -y --force-yes gcc g++
59-
sudo apt install -y --force-yes nasm
60+
sudo apt install -y --force-yes nasm meson
6061
sudo apt install -y --force-yes gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross
6162
sudo apt install -y --force-yes gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf libc6-dev-armhf-cross
6263
6364
- name: Build natives with Gradle
64-
run: ./gradlew :gdx-video-desktop:buildFFmpegLinuxAll :gdx-video-desktop:jnigenBuildLinuxAll
65+
run: ./gradlew :gdx-video-desktop:FFmpeg:buildFFmpegLinuxAll :gdx-video-desktop:jnigenBuildLinuxAll
6566

6667
- name: Upload artifacts
6768
uses: actions/upload-artifact@v3
@@ -90,11 +91,11 @@ jobs:
9091
- name: Install build dependencies and cross-compilation toolchains
9192
run: |
9293
sudo apt update
93-
sudo apt install -y --force-yes nasm
94+
sudo apt install -y --force-yes nasm meson
9495
sudo apt install -y --force-yes mingw-w64 lib32z1
9596
9697
- name: Build natives with Gradle
97-
run: ./gradlew :gdx-video-desktop:buildFFmpegWindowsAll :gdx-video-desktop:jnigenBuildWindowsAll
98+
run: ./gradlew :gdx-video-desktop:FFmpeg:buildFFmpegWindowsAll :gdx-video-desktop:jnigenBuildWindowsAll
9899

99100
- name: Upload artifacts
100101
uses: actions/upload-artifact@v3

.github/workflows/publish_snapshot.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ jobs:
3030
uses: gradle/gradle-build-action@v2
3131

3232
- name: Install additional build dependencies
33-
run: brew install nasm
33+
run: brew install nasm meson
3434

3535
- name: Build with Gradle
36-
run: ./gradlew :gdx-video-desktop:buildFFmpegMacosAll :gdx-video-desktop:jnigenBuildMacosAll
36+
run: ./gradlew :gdx-video-desktop:FFmpeg:buildFFmpegMacosAll :gdx-video-desktop:jnigenBuildMacosAll
3737

3838
- name: Upload artifacts
3939
uses: actions/upload-artifact@v3
@@ -63,12 +63,12 @@ jobs:
6363
run: |
6464
sudo apt update
6565
sudo apt install -y --force-yes gcc g++
66-
sudo apt install -y --force-yes nasm
66+
sudo apt install -y --force-yes nasm meson
6767
sudo apt install -y --force-yes gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross
6868
sudo apt install -y --force-yes gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf libc6-dev-armhf-cross
6969
7070
- name: Build natives with Gradle
71-
run: ./gradlew :gdx-video-desktop:buildFFmpegLinuxAll :gdx-video-desktop:jnigenBuildLinuxAll
71+
run: ./gradlew :gdx-video-desktop:FFmpeg:buildFFmpegLinuxAll :gdx-video-desktop:jnigenBuildLinuxAll
7272

7373
- name: Upload artifacts
7474
uses: actions/upload-artifact@v3
@@ -97,11 +97,11 @@ jobs:
9797
- name: Install build dependencies and cross-compilation toolchains
9898
run: |
9999
sudo apt update
100-
sudo apt install -y --force-yes nasm
100+
sudo apt install -y --force-yes nasm meson
101101
sudo apt install -y --force-yes mingw-w64 lib32z1
102102
103103
- name: Build natives with Gradle
104-
run: ./gradlew :gdx-video-desktop:buildFFmpegWindowsAll :gdx-video-desktop:jnigenBuildWindowsAll
104+
run: ./gradlew :gdx-video-desktop:FFmpeg:buildFFmpegWindowsAll :gdx-video-desktop:jnigenBuildWindowsAll
105105

106106
- name: Upload artifacts
107107
uses: actions/upload-artifact@v3

.gitmodules

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
[submodule "gdx-video-desktop/FFmpeg"]
2-
path = gdx-video-desktop/FFmpeg
2+
path = gdx-video-desktop/FFmpeg/src/FFmpeg
33
url = https://github.com/FFmpeg/FFmpeg.git
44
branch = release/4.3
5+
[submodule "gdx-video-desktop/dependencies/dav1d"]
6+
path = gdx-video-desktop/FFmpeg/src/dav1d
7+
url = https://code.videolan.org/videolan/dav1d.git

README.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,31 @@ your game on real devices.
112112

113113
### File format and codec
114114

115-
| Format | Desktop | Android | iOS | Web |
116-
|------------------------|----------|----------|---------|-----|
117-
| MP4 (H.264/AVC + AAC) | ❌ * |* | | ⚠️ |
118-
| MP4 (H.265/HEVC + AAC) | ❌ * | ⚠️ > 5.0 | ⚠️ > 11 | ⚠️ |
119-
| WebM (VP8 + Vorbis) ||| ||
120-
| WebM (VP9 + Opus) || ⚠️ > 5.0 | ||
121-
| MKV (AV1 + Opus) || ⚠️ > 10 | | ⚠️ |
115+
| Format | Desktop | Android | iOS | Web |
116+
|------------------------|----------|----------|--------|-----|
117+
| MP4 (H.264/AVC + AAC) | ❌ * | || ⚠️ |
118+
| MP4 (H.265/HEVC + AAC) | ❌ * | ⚠️ > 5.0 | > 11 | ⚠️ |
119+
| WebM (VP8 + Vorbis) |||||
120+
| WebM (VP9 + Opus) || ⚠️ > 5.0 |||
121+
| MKV (AV1 + Opus) || ⚠️ > 10 |* | ⚠️ |
122122

123123
#### Additional notes
124124

125125
**Desktop:** Additional formats and codecs can be enabled when compiling
126-
gdx-video yourself. See the file [gdx-video-desktop/build.gradle](gdx-video-desktop/build.gradle).
126+
gdx-video yourself. See the file [gdx-video-desktop/FFmpeg/build.gradle](gdx-video-desktop/FFmpeg/build.gradle).
127127

128-
**iOS**: H.265 support notes from apple: <https://support.apple.com/de-de/HT207022>
128+
**iOS**: H.265 is supported since iOS 11. AV1 requires a current high-end
129+
device with a hardware decoder.
129130

130131
**Android**: See the following webpage for officially supported media formats:
131132
<https://developer.android.com/guide/topics/media/platform/supported-formats>.
132133
Note that this support table is not always accurate, especially for devices
133-
and emulator images without Google Play Services. When in doubt, use VP8, VP9
134-
and Vorbis.
134+
and emulator images without Google Play Services.
135+
136+
In practice, H.264 is a good choice for physical Android tablets / smartphones
137+
as most devices (including old and cheap ones) have hardware decoding support.
138+
Remember to dispose a VideoPlayer before loading a new one, as some devices
139+
fail to load the next video otherwise.
135140

136141
### Resolution and framerate
137142

gdx-video-desktop/FFmpeg

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
tasks.register('cleanFFmpeg')
2+
tasks.register('cleanAV1')
3+
clean.configure {
4+
dependsOn 'cleanFFmpeg'
5+
dependsOn 'cleanAV1'
6+
}
7+
8+
String checkCrossPrefix(String crossToolchain) {
9+
def tc = crossToolchain
10+
if (tc == null || System.getProperty("os.name").startsWith("Win")) return ""
11+
def result = project.exec {
12+
ignoreExitValue = true
13+
commandLine "bash", "-l", "-c",
14+
"(command -v $tc-g++ && command -v $tc-ar && command -v $tc-ld)>/dev/null"
15+
}
16+
if (result.getExitValue() == 0) {
17+
return "$tc-"
18+
}
19+
return ""
20+
}
21+
22+
String checkCrossFile(String buildName, String crossToolchain) {
23+
String prefix = checkCrossPrefix(crossToolchain)
24+
if (prefix.isEmpty()) {
25+
return ""
26+
}
27+
def options = [
28+
"Windows32" : "i686-w64-mingw32",
29+
"Windows64" : "x86_64-w64-mingw32",
30+
"LinuxARM64": "aarch64-linux"
31+
]
32+
def name = options[buildName]
33+
if(name == null) return ""
34+
return "src/dav1d/package/crossfiles/${name}.meson"
35+
}
36+
37+
38+
void registerBuild(String buildName, String crossToolchain, String... extraArgs) {
39+
String outDir = file("build/${buildName.toLowerCase()}").absolutePath
40+
String av1Dir = "$outDir/src/dav1d"
41+
String ffDir = "$outDir/src/FFmpeg"
42+
43+
def crossPrefix = checkCrossPrefix(crossToolchain)
44+
def crossFile = checkCrossFile(buildName, crossToolchain)
45+
46+
tasks.register("cleanAV1$buildName", Delete) {
47+
delete av1Dir
48+
delete "$outDir/lib/libdav1d.a"
49+
}
50+
cleanAV1.configure {
51+
dependsOn "cleanAV1$buildName"
52+
}
53+
tasks.register("buildAV1$buildName") {
54+
doFirst {
55+
mkdir av1Dir
56+
String[] crossArgs = []
57+
String crossPath = ""
58+
if (!crossFile.isEmpty()) {
59+
crossPath = file(crossFile).absolutePath
60+
} else if(buildName == "Macos64") {
61+
crossPath = file("src/x86_64-macos.meson").absolutePath
62+
} else if(buildName == "MacosARM64") {
63+
crossPath = file("src/arm64-macos.meson").absolutePath
64+
} else if(buildName == "Linux64" && System.getProperty("os.name") != "Linux") {
65+
crossPath = file("src/x86_64-linux.meson").absolutePath
66+
} else if(buildName == "LinuxARM32") {
67+
crossPath = file("src/arm32-linux.meson").absolutePath
68+
}
69+
if (!crossPath.isEmpty()) {
70+
crossArgs = ["--cross-file=$crossPath"]
71+
}
72+
project.exec {
73+
workingDir av1Dir
74+
executable 'meson'
75+
args 'setup', '-Denable_tools=false', '-Denable_tests=false'
76+
args crossArgs
77+
args '../../../../src/dav1d', '--default-library=static'
78+
args '--prefix', "$outDir"
79+
args "--libdir=$outDir/lib"
80+
}
81+
project.exec {
82+
workingDir av1Dir
83+
commandLine 'ninja'
84+
}
85+
project.exec {
86+
workingDir av1Dir
87+
commandLine 'ninja', 'install'
88+
}
89+
}
90+
outputs.upToDateWhen { file("$outDir/lib/libdav1d.a").exists() }
91+
}
92+
93+
tasks.register("cleanFFmpeg$buildName", Delete) {
94+
delete ffDir
95+
delete "$outDir/lib/libavformat.a"
96+
}
97+
cleanFFmpeg.configure {
98+
dependsOn "cleanFFmpeg$buildName"
99+
}
100+
tasks.register("buildFFmpeg$buildName") {
101+
dependsOn "buildAV1$buildName"
102+
doFirst {
103+
mkdir ffDir
104+
String[] crossArgs = []
105+
if (!crossPrefix.isEmpty()) {
106+
crossArgs = ["--enable-cross-compile", "--cross-prefix=$crossPrefix"]
107+
}
108+
project.exec {
109+
workingDir ffDir
110+
environment["PKG_CONFIG_PATH"] = "$outDir/lib/pkgconfig"
111+
executable '../../../../src/FFmpeg/configure'
112+
args '--pkg-config=pkg-config', '--pkg-config-flags=--static'
113+
args '--disable-autodetect'
114+
args '--enable-pic', '--disable-symver', '--disable-doc', '--disable-shared', '--enable-static'
115+
args crossArgs
116+
args '--disable-everything'
117+
args '--enable-protocol=file', '--enable-filter=aresample', '--enable-filter=deshake'
118+
args '--enable-demuxer=ogg', '--enable-demuxer=matroska', '--enable-demuxer=mov'
119+
args '--enable-decoder=vorbis', '--enable-decoder=opus', '--enable-decoder=aac'
120+
args '--enable-decoder=vp8', '--enable-decoder=vp9', '--enable-decoder=theora', '--enable-decoder=av1'
121+
args '--enable-libdav1d', '--enable-decoder=libdav1d'
122+
args "--extra-cflags=-I$outDir/include"
123+
args "--extra-ldflags=-L$outDir/lib"
124+
args "--prefix=$outDir"
125+
// Uncomment the following line for MP4 video support:
126+
//args '--enable-decoder=h264', '--enable-decoder=hevc'
127+
args extraArgs
128+
}
129+
project.exec {
130+
workingDir ffDir
131+
commandLine 'make', '-j16'
132+
}
133+
project.exec {
134+
workingDir ffDir
135+
commandLine 'make', 'install'
136+
}
137+
}
138+
outputs.upToDateWhen { file("$outDir/lib/libavformat.a").exists() }
139+
}
140+
}
141+
142+
registerBuild 'Windows32', 'i686-w64-mingw32', '--arch=x86', '--target-os=mingw32'
143+
registerBuild 'Windows64', 'x86_64-w64-mingw32', '--arch=x86_64', '--target-os=mingw32'
144+
145+
registerBuild 'Linux64', 'x86_64-linux-gnu', '--arch=x86_64', '--target-os=linux', '--disable-cuda', '--disable-cuvid'
146+
147+
registerBuild 'LinuxARM32', 'arm-linux-gnueabihf', '--arch=arm', '--target-os=linux'
148+
registerBuild 'LinuxARM64', 'aarch64-linux-gnu', '--arch=aarch64', '--target-os=linux'
149+
150+
registerBuild 'Macos64', null, '--enable-cross-compile',// '--enable-hwaccel=h264_videotoolbox', '--enable-hwaccel=hevc_videotoolbox',
151+
'--arch=x86_64', '--target-os=darwin', '--cc=clang', '--cxx=clang++', '--dep-cc=clang',
152+
'--extra-cflags=-mmacosx-version-min=10.11 -arch x86_64', '--extra-cxxflags=-mmacosx-version-min=10.11 -arch x86_64', '--extra-ldflags=-mmacosx-version-min=10.11 -arch x86_64'
153+
registerBuild 'MacosARM64', null, '--enable-cross-compile',// '--enable-hwaccel=h264_videotoolbox', '--enable-hwaccel=hevc_videotoolbox',
154+
'--arch=arm64', '--target-os=darwin', '--cc=clang', '--cxx=clang++', '--dep-cc=clang',
155+
'--extra-cflags=-mmacosx-version-min=10.11 -arch arm64', '--extra-cxxflags=-mmacosx-version-min=10.11 -arch arm64', '--extra-ldflags=-mmacosx-version-min=10.11 -arch arm64'
156+
157+
tasks.register('buildFFmpegWindowsAll') {
158+
dependsOn buildFFmpegWindows32, buildFFmpegWindows64
159+
}
160+
161+
tasks.register('buildFFmpegLinuxAll') {
162+
dependsOn buildFFmpegLinux64, buildFFmpegLinuxARM32, buildFFmpegLinuxARM64
163+
}
164+
165+
tasks.register('buildFFmpegMacosAll') {
166+
dependsOn buildFFmpegMacos64, buildFFmpegMacosARM64
167+
}
Submodule FFmpeg added at cde3c5f
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[binaries]
2+
c = 'arm-linux-gnueabihf-gcc'
3+
cpp = 'arm-linux-gnueabihf-gcc'
4+
ar = 'arm-linux-gnueabihf-ar'
5+
strip = 'arm-linux-gnueabihf-strip'
6+
7+
[host_machine]
8+
system = 'linux'
9+
cpu_family = 'arm'
10+
cpu = 'arm'
11+
endian = 'little'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[binaries]
2+
c = ['clang', '-arch', 'arm64']
3+
cpp = ['clang++', '-arch', 'arm64']
4+
objc = ['clang', '-arch', 'arm64']
5+
objcpp = ['clang++', '-arch', 'arm64']
6+
ar = 'ar'
7+
strip = 'strip'
8+
9+
[built-in options]
10+
c_args = ['-mmacos-version-min=10.11']
11+
cpp_args = ['-mmacos-version-min=10.11']
12+
c_link_args = ['-mmacos-version-min=10.11']
13+
cpp_link_args = ['-mmacos-version-min=10.11']
14+
objc_args = ['-mmacos-version-min=10.11']
15+
objcpp_args = ['-mmacos-version-min=10.11']
16+
17+
[host_machine]
18+
system = 'darwin'
19+
subsystem = 'macos'
20+
kernel = 'xnu'
21+
cpu_family = 'aarch64'
22+
cpu = 'aarch64'
23+
endian = 'little'

gdx-video-desktop/FFmpeg/src/dav1d

Submodule dav1d added at 2ba57aa

0 commit comments

Comments
 (0)