blob: acedb105c3db5be028b61c320c707c7d1382ce29 [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 Fineganfe809bd2017-09-27 11:54:24 -070066### Debugging
67
68Depending on the generator used there are multiple ways of going about
69debugging AV1 components. For single configuration generators like the Unix
70Makefiles generator, setting `CMAKE_BUILD_TYPE` to Debug is sufficient:
71
72~~~
73 $ cmake path/to/aom -DCMAKE_BUILD_TYPE=Debug
74~~~
75
76For Xcode, mainly because configuration controls for Xcode builds are buried two
Tom Finegand77323d2017-09-29 09:41:43 -070077configuration windows deep and must be set for each subproject within the Xcode
78IDE individually, `CMAKE_CONFIGURATION_TYPES` should be set to Debug:
Tom Fineganfe809bd2017-09-27 11:54:24 -070079
80~~~
81 $ cmake path/to/aom -G Xcode -DCMAKE_CONFIGURATION_TYPES=Debug
82~~~
83
84For Visual Studio the in-IDE configuration controls should be used. Simply set
85the IDE project configuration to Debug to allow for stepping through the code.
86
87In addition to the above it can sometimes be useful to debug only C and C++
Tom Finegand77323d2017-09-29 09:41:43 -070088code. To disable all assembly code and intrinsics set `AOM_TARGET_CPU` to
Tom Fineganfe809bd2017-09-27 11:54:24 -070089generic at generation time:
90
91~~~
92 $ cmake path/to/aom -DAOM_TARGET_CPU=generic
93~~~
94
Tom Finegan9e57db22017-06-07 07:22:37 -070095### Cross compiling
96
97For the purposes of building the AV1 codec and applications and relative to the
98scope of this guide, all builds for architectures differing from the native host
99architecture will be considered cross compiles. The AV1 CMake build handles
100cross compiling via the use of toolchain files included in the AV1 repository.
101The toolchain files available at the time of this writing are:
102
103 - arm64-ios.cmake
104 - arm64-linux-gcc.cmake
105 - armv7-ios.cmake
106 - armv7-linux-gcc.cmake
107 - armv7s-ios.cmake
108 - mips32-linux-gcc.cmake
109 - mips64-linux-gcc.cmake
110 - x86-ios-simulator.cmake
111 - x86-linux.cmake
112 - x86-macos.cmake
Tom Finegand77323d2017-09-29 09:41:43 -0700113 - x86-mingw-gcc.cmake
Tom Finegan9e57db22017-06-07 07:22:37 -0700114 - x86\_64-ios-simulator.cmake
Tom Finegand77323d2017-09-29 09:41:43 -0700115 - x86\_64-mingw-gcc.cmake
Tom Finegan9e57db22017-06-07 07:22:37 -0700116
117The following example demonstrates use of the x86-macos.cmake toolchain file on
118a x86\_64 MacOS host:
119
Tom Finegan007b2ee2017-07-11 14:47:06 -0700120~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700121 $ cmake path/to/aom \
122 -DCMAKE_TOOLCHAIN_FILE=path/to/aom/build/cmake/toolchains/x86-macos.cmake
123 $ make
Tom Finegan007b2ee2017-07-11 14:47:06 -0700124~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700125
126To build for an unlisted target creation of a new toolchain file is the best
127solution. The existing toolchain files can be used a starting point for a new
128toolchain file since each one exposes the basic requirements for toolchain files
129as used in the AV1 codec build.
130
131As a temporary work around an unoptimized AV1 configuration that builds only C
132and C++ sources can be produced using the following commands:
133
Tom Finegan007b2ee2017-07-11 14:47:06 -0700134~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700135 $ cmake path/to/aom -DAOM_TARGET_CPU=generic
136 $ make
Tom Finegan007b2ee2017-07-11 14:47:06 -0700137~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700138
139In addition to the above it's important to note that the toolchain files
140suffixed with gcc behave differently than the others. These toolchain files
141attempt to obey the $CROSS environment variable.
142
Tom Finegan8a30baf2017-09-13 11:35:34 -0700143### Sanitizers
144
145Sanitizer integration is built-in to the CMake build system. To enable a
146sanitizer, add `-DSANITIZE=<type>` to the CMake command line. For example, to
147enable address sanitizer:
148
149~~~
150 $ cmake path/to/aom -DSANITIZE=address
151 $ make
152~~~
153
154Sanitizers available vary by platform, target, and compiler. Consult your
155compiler documentation to determine which, if any, are available.
156
Tom Finegan9e57db22017-06-07 07:22:37 -0700157### Microsoft Visual Studio builds
158
159Building the AV1 codec library in Microsoft Visual Studio is supported. The
160following example demonstrates generating projects and a solution for the
161Microsoft IDE:
162
Tom Finegan007b2ee2017-07-11 14:47:06 -0700163~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700164 # This does not require a bash shell; command.exe is fine.
165 $ cmake path/to/aom -G "Visual Studio 15 2017"
Tom Finegan007b2ee2017-07-11 14:47:06 -0700166~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700167
168### Xcode builds
169
170Building the AV1 codec library in Xcode is supported. The following example
171demonstrates generating an Xcode project:
172
Tom Finegan007b2ee2017-07-11 14:47:06 -0700173~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700174 $ cmake path/to/aom -G Xcode
Tom Finegan007b2ee2017-07-11 14:47:06 -0700175~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700176
Tom Finegan84d35992017-07-07 10:38:01 -0700177### Emscripten builds
178
179Building the AV1 codec library with Emscripten is supported. Typically this is
180used to hook into the AOMAnalyzer GUI application. These instructions focus on
181using the inspector with AOMAnalyzer, but all tools can be built with
182Emscripten.
183
184It is assumed here that you have already downloaded and installed the EMSDK,
185installed and activated at least one toolchain, and setup your environment
186appropriately using the emsdk\_env script.
187
1881. Download [AOMAnalyzer](https://people.xiph.org/~mbebenita/analyzer/).
189
1902. Configure the build:
191
192~~~
193 $ cmake path/to/aom \
194 -DENABLE_CCACHE=1 \
195 -DAOM_TARGET_CPU=generic \
196 -DENABLE_DOCS=0 \
197 -DCONFIG_ACCOUNTING=1 \
198 -DCONFIG_INSPECTION=1 \
199 -DCONFIG_MULTITHREAD=0 \
200 -DCONFIG_RUNTIME_CPU_DETECT=0 \
201 -DCONFIG_UNIT_TESTS=0 \
202 -DCONFIG_WEBM_IO=0 \
203 -DCMAKE_TOOLCHAIN_FILE=path/to/emsdk-portable/.../Emscripten.cmake
204~~~
205
2063. Build it: run make if that's your generator of choice:
207
208~~~
209 $ make inspect
210~~~
211
2124. Run the analyzer:
213
214~~~
215 # inspect.js is in the examples sub directory of the directory in which you
216 # executed cmake.
217 $ path/to/AOMAnalyzer path/to/examples/inspect.js path/to/av1/input/file
218~~~
219
Tom Finegan9e57db22017-06-07 07:22:37 -0700220
221## Testing the AV1 codec
222
223### Testing basics
224
Tom Finegan007b2ee2017-07-11 14:47:06 -0700225Currently there are two types of tests in the AV1 codec repository.
Tom Finegan9e57db22017-06-07 07:22:37 -0700226
Tom Finegan007b2ee2017-07-11 14:47:06 -0700227#### 1. Unit tests:
Tom Finegan9e57db22017-06-07 07:22:37 -0700228
229The unit tests can be run at build time:
230
Tom Finegan007b2ee2017-07-11 14:47:06 -0700231~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700232 # Before running the make command the LIBAOM_TEST_DATA_PATH environment
233 # variable should be set to avoid downloading the test files to the
234 # cmake build configuration directory.
235 $ cmake path/to/aom
236 # Note: The AV1 CMake build creates many test targets. Running make
237 # with multiple jobs will speed up the test run significantly.
238 $ make runtests
Tom Finegan007b2ee2017-07-11 14:47:06 -0700239~~~
240
241#### 2. Example tests:
Tom Finegan9e57db22017-06-07 07:22:37 -0700242
243The example tests require a bash shell and can be run in the following manner:
244
Tom Finegan007b2ee2017-07-11 14:47:06 -0700245~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700246 # See the note above about LIBAOM_TEST_DATA_PATH above.
247 $ cmake path/to/aom
248 $ make
249 # It's best to build the testdata target using many make jobs.
250 # Running it like this will verify and download (if necessary)
251 # one at a time, which takes a while.
252 $ make testdata
253 $ path/to/aom/test/examples.sh --bin-path examples
Tom Finegan007b2ee2017-07-11 14:47:06 -0700254~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700255
256### IDE hosted tests
257
258By default the generated projects files created by CMake will not include the
259runtests and testdata rules when generating for IDEs like Microsoft Visual
260Studio and Xcode. This is done to avoid intolerably long build cycles in the
261IDEs-- IDE behavior is to build all targets when selecting the build project
262options in MSVS and Xcode. To enable the test rules in IDEs the
263`ENABLE_IDE_TEST_HOSTING` variable must be enabled at CMake generation time:
264
Tom Finegan007b2ee2017-07-11 14:47:06 -0700265~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700266 # This example uses Xcode. To get a list of the generators
267 # available, run cmake with the -G argument missing its
268 # value.
269 $ cmake path/to/aom -DENABLE_IDE_TEST_HOSTING=1 -G Xcode
Tom Finegan007b2ee2017-07-11 14:47:06 -0700270~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700271
272### Downloading the test data
273
274The fastest and easiest way to obtain the test data is to use CMake to generate
275a build using the Unix Makefiles generator, and then to build only the testdata
276rule:
277
Tom Finegan007b2ee2017-07-11 14:47:06 -0700278~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700279 $ cmake path/to/aom -G "Unix Makefiles"
280 # 28 is used because there are 28 test files as of this writing.
281 $ make -j28 testdata
Tom Finegan007b2ee2017-07-11 14:47:06 -0700282~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700283
284The above make command will only download and verify the test data.
285
Tom Finegan007b2ee2017-07-11 14:47:06 -0700286### Sharded testing
287
288The AV1 codec library unit tests are built upon gtest which supports sharding of
289test jobs. Sharded test runs can be achieved in a couple of ways.
290
291#### 1. Running test\_libaom directly:
292
293~~~
294 # Set the environment variable GTEST_TOTAL_SHARDS to 9 to run 10 test shards
295 # (GTEST shard indexing is 0 based).
296 $ export GTEST_TOTAL_SHARDS=9
James Zern515c8692017-08-30 16:32:28 -0700297 $ seq 0 $(( $GTEST_TOTAL_SHARDS - 1 )) \
298 | xargs -n 1 -P 0 -I{} env GTEST_SHARD_INDEX={} ./test_libaom
Tom Finegan007b2ee2017-07-11 14:47:06 -0700299~~~
300
301To create a test shard for each CPU core available on the current system set
302`GTEST_TOTAL_SHARDS` to the number of CPU cores on your system minus one.
303
304#### 2. Running the tests via the CMake build:
305
306~~~
307 # For IDE based builds, ENABLE_IDE_TEST_HOSTING must be enabled. See
308 # the IDE hosted tests section above for more information. If the IDE
309 # supports building targets concurrently tests will be sharded by default.
310
311 # For make and ninja builds the -j parameter controls the number of shards
312 # at test run time. This example will run the tests using 10 shards via
313 # make.
314 $ make -j10 runtests
315~~~
316
317The maximum number of test targets that can run concurrently is determined by
318the number of CPUs on the system where the build is configured as detected by
319CMake. A system with 24 cores can run 24 test shards using a value of 24 with
320the `-j` parameter. When CMake is unable to detect the number of cores 10 shards
321is the default maximum value.
Tom Finegan9e57db22017-06-07 07:22:37 -0700322
323## Coding style
324
325The coding style used by this project is enforced with clang-format using the
326configuration contained in the .clang-format file in the root of the repository.
327
328Before pushing changes for review you can format your code with:
329
Tom Finegan007b2ee2017-07-11 14:47:06 -0700330~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700331 # Apply clang-format to modified .c, .h and .cc files
332 $ clang-format -i --style=file \
333 $(git diff --name-only --diff-filter=ACMR '*.[hc]' '*.cc')
Tom Finegan007b2ee2017-07-11 14:47:06 -0700334~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700335
336Check the .clang-format file for the version used to generate it if there is any
337difference between your local formatting and the review system.
338
339See also: http://clang.llvm.org/docs/ClangFormat.html
340
341## Support
342
343This library is an open source project supported by its community. Please
344please email aomediacodec@jointdevelopment.kavi.com for help.
345
346## Bug reports
347
348Bug reports can be filed in the Alliance for Open Media
349[issue tracker](https://bugs.chromium.org/p/aomedia/issues/list).