blob: 9de9c88493b5f7aaa5c2364065729f9e52290be3 [file] [log] [blame] [view]
Tom Finegan9e57db22017-06-07 07:22:37 -07001# AV1 Codec Library
2
3## Building the library and applications
4
5### Prerequisites
6
7 1. [CMake](https://cmake.org) version 3.5 or higher.
8 2. [Git](https://git-scm.com/).
9 3. [Perl](https://www.perl.org/).
10 4. For x86 targets, [yasm](http://yasm.tortall.net/), which is preferred, or a
11 recent version of [nasm](http://www.nasm.us/).
12 5. Building the documentation requires [doxygen](http://doxygen.org).
Tom Fineganff766cd2017-06-20 14:18:03 -070013 6. Building the unit tests requires [Python](https://www.python.org/).
Tom Finegan84d35992017-07-07 10:38:01 -070014 7. Emscripten builds require the portable
15 [EMSDK](https://kripken.github.io/emscripten-site/index.html).
Tom Finegan9e57db22017-06-07 07:22:37 -070016
17### Basic build
18
19CMake replaces the configure step typical of many projects. Running CMake will
20produce configuration and build files for the currently selected CMake
21generator. For most systems the default generator is Unix Makefiles. The basic
22form of a makefile build is the following:
23
24 $ cmake path/to/aom
25 $ make
26
27The above will generate a makefile build that produces the AV1 library and
28applications for the current host system after the make step completes
29successfully. The compiler chosen varies by host platform, but a general rule
30applies: On systems where cc and c++ are present in $PATH at the time CMake is
31run the generated build will use cc and c++ by default.
32
33### Configuration options
34
35The AV1 codec library has a great many configuration options. These come in two
36varieties:
37
38 1. Build system configuration options. These have the form `ENABLE_FEATURE`.
39 2. AV1 codec configuration options. These have the form `CONFIG_FEATURE`.
40
41Both types of options are set at the time CMake is run. The following example
42enables ccache and disables high bit depth:
43
Tom Finegan007b2ee2017-07-11 14:47:06 -070044~~~
Tom Finegan9e57db22017-06-07 07:22:37 -070045 $ cmake path/to/aom -DENABLE_CCACHE=1 -DCONFIG_HIGHBITDEPTH=0
46 $ make
Tom Finegan007b2ee2017-07-11 14:47:06 -070047~~~
Tom Finegan9e57db22017-06-07 07:22:37 -070048
49The available configuration options are too numerous to list here. Build system
50configuration options can be found at the top of the CMakeLists.txt file found
51in the root of the AV1 repository, and AV1 codec configuration options can
52currently be found in the file `build/cmake/aom_config_defaults.cmake`.
53
Tom Finegan84f2d792017-06-15 23:06:44 -070054### Dylib builds
55
56A dylib (shared object) build of the AV1 codec library can be enabled via the
Tom Finegan007b2ee2017-07-11 14:47:06 -070057CMake built in variable `BUILD_SHARED_LIBS`:
Tom Finegan84f2d792017-06-15 23:06:44 -070058
Tom Finegan007b2ee2017-07-11 14:47:06 -070059~~~
60 $ cmake path/to/aom -DBUILD_SHARED_LIBS=1
Tom Finegan84f2d792017-06-15 23:06:44 -070061 $ make
Tom Finegan007b2ee2017-07-11 14:47:06 -070062~~~
Tom Finegan84f2d792017-06-15 23:06:44 -070063
64This is currently only supported on non-Windows targets.
65
Tom Finegan9e57db22017-06-07 07:22:37 -070066### Cross compiling
67
68For the purposes of building the AV1 codec and applications and relative to the
69scope of this guide, all builds for architectures differing from the native host
70architecture will be considered cross compiles. The AV1 CMake build handles
71cross compiling via the use of toolchain files included in the AV1 repository.
72The toolchain files available at the time of this writing are:
73
74 - arm64-ios.cmake
75 - arm64-linux-gcc.cmake
76 - armv7-ios.cmake
77 - armv7-linux-gcc.cmake
78 - armv7s-ios.cmake
79 - mips32-linux-gcc.cmake
80 - mips64-linux-gcc.cmake
81 - x86-ios-simulator.cmake
82 - x86-linux.cmake
83 - x86-macos.cmake
84 - x86\_64-ios-simulator.cmake
85
86The following example demonstrates use of the x86-macos.cmake toolchain file on
87a x86\_64 MacOS host:
88
Tom Finegan007b2ee2017-07-11 14:47:06 -070089~~~
Tom Finegan9e57db22017-06-07 07:22:37 -070090 $ cmake path/to/aom \
91 -DCMAKE_TOOLCHAIN_FILE=path/to/aom/build/cmake/toolchains/x86-macos.cmake
92 $ make
Tom Finegan007b2ee2017-07-11 14:47:06 -070093~~~
Tom Finegan9e57db22017-06-07 07:22:37 -070094
95To build for an unlisted target creation of a new toolchain file is the best
96solution. The existing toolchain files can be used a starting point for a new
97toolchain file since each one exposes the basic requirements for toolchain files
98as used in the AV1 codec build.
99
100As a temporary work around an unoptimized AV1 configuration that builds only C
101and C++ sources can be produced using the following commands:
102
Tom Finegan007b2ee2017-07-11 14:47:06 -0700103~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700104 $ cmake path/to/aom -DAOM_TARGET_CPU=generic
105 $ make
Tom Finegan007b2ee2017-07-11 14:47:06 -0700106~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700107
108In addition to the above it's important to note that the toolchain files
109suffixed with gcc behave differently than the others. These toolchain files
110attempt to obey the $CROSS environment variable.
111
112### Microsoft Visual Studio builds
113
114Building the AV1 codec library in Microsoft Visual Studio is supported. The
115following example demonstrates generating projects and a solution for the
116Microsoft IDE:
117
Tom Finegan007b2ee2017-07-11 14:47:06 -0700118~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700119 # This does not require a bash shell; command.exe is fine.
120 $ cmake path/to/aom -G "Visual Studio 15 2017"
Tom Finegan007b2ee2017-07-11 14:47:06 -0700121~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700122
123### Xcode builds
124
125Building the AV1 codec library in Xcode is supported. The following example
126demonstrates generating an Xcode project:
127
Tom Finegan007b2ee2017-07-11 14:47:06 -0700128~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700129 $ cmake path/to/aom -G Xcode
Tom Finegan007b2ee2017-07-11 14:47:06 -0700130~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700131
Tom Finegan84d35992017-07-07 10:38:01 -0700132### Emscripten builds
133
134Building the AV1 codec library with Emscripten is supported. Typically this is
135used to hook into the AOMAnalyzer GUI application. These instructions focus on
136using the inspector with AOMAnalyzer, but all tools can be built with
137Emscripten.
138
139It is assumed here that you have already downloaded and installed the EMSDK,
140installed and activated at least one toolchain, and setup your environment
141appropriately using the emsdk\_env script.
142
1431. Download [AOMAnalyzer](https://people.xiph.org/~mbebenita/analyzer/).
144
1452. Configure the build:
146
147~~~
148 $ cmake path/to/aom \
149 -DENABLE_CCACHE=1 \
150 -DAOM_TARGET_CPU=generic \
151 -DENABLE_DOCS=0 \
152 -DCONFIG_ACCOUNTING=1 \
153 -DCONFIG_INSPECTION=1 \
154 -DCONFIG_MULTITHREAD=0 \
155 -DCONFIG_RUNTIME_CPU_DETECT=0 \
156 -DCONFIG_UNIT_TESTS=0 \
157 -DCONFIG_WEBM_IO=0 \
158 -DCMAKE_TOOLCHAIN_FILE=path/to/emsdk-portable/.../Emscripten.cmake
159~~~
160
1613. Build it: run make if that's your generator of choice:
162
163~~~
164 $ make inspect
165~~~
166
1674. Run the analyzer:
168
169~~~
170 # inspect.js is in the examples sub directory of the directory in which you
171 # executed cmake.
172 $ path/to/AOMAnalyzer path/to/examples/inspect.js path/to/av1/input/file
173~~~
174
Tom Finegan9e57db22017-06-07 07:22:37 -0700175
176## Testing the AV1 codec
177
178### Testing basics
179
Tom Finegan007b2ee2017-07-11 14:47:06 -0700180Currently there are two types of tests in the AV1 codec repository.
Tom Finegan9e57db22017-06-07 07:22:37 -0700181
Tom Finegan007b2ee2017-07-11 14:47:06 -0700182#### 1. Unit tests:
Tom Finegan9e57db22017-06-07 07:22:37 -0700183
184The unit tests can be run at build time:
185
Tom Finegan007b2ee2017-07-11 14:47:06 -0700186~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700187 # Before running the make command the LIBAOM_TEST_DATA_PATH environment
188 # variable should be set to avoid downloading the test files to the
189 # cmake build configuration directory.
190 $ cmake path/to/aom
191 # Note: The AV1 CMake build creates many test targets. Running make
192 # with multiple jobs will speed up the test run significantly.
193 $ make runtests
Tom Finegan007b2ee2017-07-11 14:47:06 -0700194~~~
195
196#### 2. Example tests:
Tom Finegan9e57db22017-06-07 07:22:37 -0700197
198The example tests require a bash shell and can be run in the following manner:
199
Tom Finegan007b2ee2017-07-11 14:47:06 -0700200~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700201 # See the note above about LIBAOM_TEST_DATA_PATH above.
202 $ cmake path/to/aom
203 $ make
204 # It's best to build the testdata target using many make jobs.
205 # Running it like this will verify and download (if necessary)
206 # one at a time, which takes a while.
207 $ make testdata
208 $ path/to/aom/test/examples.sh --bin-path examples
Tom Finegan007b2ee2017-07-11 14:47:06 -0700209~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700210
211### IDE hosted tests
212
213By default the generated projects files created by CMake will not include the
214runtests and testdata rules when generating for IDEs like Microsoft Visual
215Studio and Xcode. This is done to avoid intolerably long build cycles in the
216IDEs-- IDE behavior is to build all targets when selecting the build project
217options in MSVS and Xcode. To enable the test rules in IDEs the
218`ENABLE_IDE_TEST_HOSTING` variable must be enabled at CMake generation time:
219
Tom Finegan007b2ee2017-07-11 14:47:06 -0700220~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700221 # This example uses Xcode. To get a list of the generators
222 # available, run cmake with the -G argument missing its
223 # value.
224 $ cmake path/to/aom -DENABLE_IDE_TEST_HOSTING=1 -G Xcode
Tom Finegan007b2ee2017-07-11 14:47:06 -0700225~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700226
227### Downloading the test data
228
229The fastest and easiest way to obtain the test data is to use CMake to generate
230a build using the Unix Makefiles generator, and then to build only the testdata
231rule:
232
Tom Finegan007b2ee2017-07-11 14:47:06 -0700233~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700234 $ cmake path/to/aom -G "Unix Makefiles"
235 # 28 is used because there are 28 test files as of this writing.
236 $ make -j28 testdata
Tom Finegan007b2ee2017-07-11 14:47:06 -0700237~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700238
239The above make command will only download and verify the test data.
240
Tom Finegan007b2ee2017-07-11 14:47:06 -0700241### Sharded testing
242
243The AV1 codec library unit tests are built upon gtest which supports sharding of
244test jobs. Sharded test runs can be achieved in a couple of ways.
245
246#### 1. Running test\_libaom directly:
247
248~~~
249 # Set the environment variable GTEST_TOTAL_SHARDS to 9 to run 10 test shards
250 # (GTEST shard indexing is 0 based).
251 $ export GTEST_TOTAL_SHARDS=9
252 $ for shard in $(seq 0 ${GTEST_TOTAL_SHARDS}); do \
253 [ ${shard} -lt ${GTEST_TOTAL_SHARDS} ] \
254 && GTEST_SHARD_INDEX=${shard} ./test_libaom & \
255 done
256
257~~~
258
259To create a test shard for each CPU core available on the current system set
260`GTEST_TOTAL_SHARDS` to the number of CPU cores on your system minus one.
261
262#### 2. Running the tests via the CMake build:
263
264~~~
265 # For IDE based builds, ENABLE_IDE_TEST_HOSTING must be enabled. See
266 # the IDE hosted tests section above for more information. If the IDE
267 # supports building targets concurrently tests will be sharded by default.
268
269 # For make and ninja builds the -j parameter controls the number of shards
270 # at test run time. This example will run the tests using 10 shards via
271 # make.
272 $ make -j10 runtests
273~~~
274
275The maximum number of test targets that can run concurrently is determined by
276the number of CPUs on the system where the build is configured as detected by
277CMake. A system with 24 cores can run 24 test shards using a value of 24 with
278the `-j` parameter. When CMake is unable to detect the number of cores 10 shards
279is the default maximum value.
Tom Finegan9e57db22017-06-07 07:22:37 -0700280
281## Coding style
282
283The coding style used by this project is enforced with clang-format using the
284configuration contained in the .clang-format file in the root of the repository.
285
286Before pushing changes for review you can format your code with:
287
Tom Finegan007b2ee2017-07-11 14:47:06 -0700288~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700289 # Apply clang-format to modified .c, .h and .cc files
290 $ clang-format -i --style=file \
291 $(git diff --name-only --diff-filter=ACMR '*.[hc]' '*.cc')
Tom Finegan007b2ee2017-07-11 14:47:06 -0700292~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700293
294Check the .clang-format file for the version used to generate it if there is any
295difference between your local formatting and the review system.
296
297See also: http://clang.llvm.org/docs/ClangFormat.html
298
299## Support
300
301This library is an open source project supported by its community. Please
302please email aomediacodec@jointdevelopment.kavi.com for help.
303
304## Bug reports
305
306Bug reports can be filed in the Alliance for Open Media
307[issue tracker](https://bugs.chromium.org/p/aomedia/issues/list).