blob: bab84096336bb6ef5ba63a46af2c89929c7f5383 [file] [log] [blame] [view]
Tom Finegan9e57db22017-06-07 07:22:37 -07001# AV1 Codec Library
2
Tom Fineganbca03fc2017-12-08 07:47:06 -08003## Contents
41. [Building the lib and applications](#building-the-library-and-applications)
5 - [Prerequisites](#prerequisites)
6 - [Basics](#basic-build)
7 - [Configuration options](#configuration-options)
8 - [Dylib builds](#dylib-builds)
9 - [Debugging](#debugging)
10 - [Cross compiling](#cross-compiling)
11 - [Sanitizer support](#sanitizers)
12 - [MSVC builds](#microsoft-visual-studio-builds)
13 - [Xcode builds](#xcode-builds)
14 - [Emscripten builds](#emscripten-builds)
152. [Testing the library](#testing-the-av1-codec)
16 - [Basics](#testing-basics)
17 - [Unit tests](#1_unit-tests)
18 - [Example tests](#2_example-tests)
19 - [IDE hosted tests](#ide-hosted-tests)
20 - [Downloading test data](#downloading-the-test-data)
21 - [Sharded testing](#sharded-testing)
22 - [Running tests directly](#1_running-test_libaom-directly)
23 - [Running tests via CMake](#2_running-the-tests-via-the-cmake-build)
243. [Coding style](#coding-style)
254. [Support](#support)
265. [Bug reports](#bug-reports)
27
Tom Finegan9e57db22017-06-07 07:22:37 -070028## Building the library and applications
29
30### Prerequisites
31
32 1. [CMake](https://cmake.org) version 3.5 or higher.
33 2. [Git](https://git-scm.com/).
34 3. [Perl](https://www.perl.org/).
35 4. For x86 targets, [yasm](http://yasm.tortall.net/), which is preferred, or a
36 recent version of [nasm](http://www.nasm.us/).
37 5. Building the documentation requires [doxygen](http://doxygen.org).
Tom Fineganff766cd2017-06-20 14:18:03 -070038 6. Building the unit tests requires [Python](https://www.python.org/).
Tom Finegan84d35992017-07-07 10:38:01 -070039 7. Emscripten builds require the portable
40 [EMSDK](https://kripken.github.io/emscripten-site/index.html).
Tom Finegan9e57db22017-06-07 07:22:37 -070041
42### Basic build
43
44CMake replaces the configure step typical of many projects. Running CMake will
45produce configuration and build files for the currently selected CMake
46generator. For most systems the default generator is Unix Makefiles. The basic
47form of a makefile build is the following:
48
49 $ cmake path/to/aom
50 $ make
51
52The above will generate a makefile build that produces the AV1 library and
53applications for the current host system after the make step completes
54successfully. The compiler chosen varies by host platform, but a general rule
55applies: On systems where cc and c++ are present in $PATH at the time CMake is
56run the generated build will use cc and c++ by default.
57
58### Configuration options
59
60The AV1 codec library has a great many configuration options. These come in two
61varieties:
62
63 1. Build system configuration options. These have the form `ENABLE_FEATURE`.
64 2. AV1 codec configuration options. These have the form `CONFIG_FEATURE`.
65
66Both types of options are set at the time CMake is run. The following example
67enables ccache and disables high bit depth:
68
Tom Finegan007b2ee2017-07-11 14:47:06 -070069~~~
Tom Finegan9e57db22017-06-07 07:22:37 -070070 $ cmake path/to/aom -DENABLE_CCACHE=1 -DCONFIG_HIGHBITDEPTH=0
71 $ make
Tom Finegan007b2ee2017-07-11 14:47:06 -070072~~~
Tom Finegan9e57db22017-06-07 07:22:37 -070073
74The available configuration options are too numerous to list here. Build system
75configuration options can be found at the top of the CMakeLists.txt file found
76in the root of the AV1 repository, and AV1 codec configuration options can
77currently be found in the file `build/cmake/aom_config_defaults.cmake`.
78
Tom Finegan84f2d792017-06-15 23:06:44 -070079### Dylib builds
80
81A dylib (shared object) build of the AV1 codec library can be enabled via the
Tom Finegan007b2ee2017-07-11 14:47:06 -070082CMake built in variable `BUILD_SHARED_LIBS`:
Tom Finegan84f2d792017-06-15 23:06:44 -070083
Tom Finegan007b2ee2017-07-11 14:47:06 -070084~~~
85 $ cmake path/to/aom -DBUILD_SHARED_LIBS=1
Tom Finegan84f2d792017-06-15 23:06:44 -070086 $ make
Tom Finegan007b2ee2017-07-11 14:47:06 -070087~~~
Tom Finegan84f2d792017-06-15 23:06:44 -070088
89This is currently only supported on non-Windows targets.
90
Tom Fineganfe809bd2017-09-27 11:54:24 -070091### Debugging
92
93Depending on the generator used there are multiple ways of going about
94debugging AV1 components. For single configuration generators like the Unix
95Makefiles generator, setting `CMAKE_BUILD_TYPE` to Debug is sufficient:
96
97~~~
98 $ cmake path/to/aom -DCMAKE_BUILD_TYPE=Debug
99~~~
100
101For Xcode, mainly because configuration controls for Xcode builds are buried two
Tom Finegand77323d2017-09-29 09:41:43 -0700102configuration windows deep and must be set for each subproject within the Xcode
103IDE individually, `CMAKE_CONFIGURATION_TYPES` should be set to Debug:
Tom Fineganfe809bd2017-09-27 11:54:24 -0700104
105~~~
106 $ cmake path/to/aom -G Xcode -DCMAKE_CONFIGURATION_TYPES=Debug
107~~~
108
109For Visual Studio the in-IDE configuration controls should be used. Simply set
110the IDE project configuration to Debug to allow for stepping through the code.
111
112In addition to the above it can sometimes be useful to debug only C and C++
Tom Finegand77323d2017-09-29 09:41:43 -0700113code. To disable all assembly code and intrinsics set `AOM_TARGET_CPU` to
Tom Fineganfe809bd2017-09-27 11:54:24 -0700114generic at generation time:
115
116~~~
117 $ cmake path/to/aom -DAOM_TARGET_CPU=generic
118~~~
119
Tom Finegan9e57db22017-06-07 07:22:37 -0700120### Cross compiling
121
122For the purposes of building the AV1 codec and applications and relative to the
123scope of this guide, all builds for architectures differing from the native host
124architecture will be considered cross compiles. The AV1 CMake build handles
125cross compiling via the use of toolchain files included in the AV1 repository.
126The toolchain files available at the time of this writing are:
127
128 - arm64-ios.cmake
129 - arm64-linux-gcc.cmake
130 - armv7-ios.cmake
131 - armv7-linux-gcc.cmake
132 - armv7s-ios.cmake
133 - mips32-linux-gcc.cmake
134 - mips64-linux-gcc.cmake
135 - x86-ios-simulator.cmake
136 - x86-linux.cmake
137 - x86-macos.cmake
Tom Finegand77323d2017-09-29 09:41:43 -0700138 - x86-mingw-gcc.cmake
Tom Finegan9e57db22017-06-07 07:22:37 -0700139 - x86\_64-ios-simulator.cmake
Tom Finegand77323d2017-09-29 09:41:43 -0700140 - x86\_64-mingw-gcc.cmake
Tom Finegan9e57db22017-06-07 07:22:37 -0700141
142The following example demonstrates use of the x86-macos.cmake toolchain file on
143a x86\_64 MacOS host:
144
Tom Finegan007b2ee2017-07-11 14:47:06 -0700145~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700146 $ cmake path/to/aom \
147 -DCMAKE_TOOLCHAIN_FILE=path/to/aom/build/cmake/toolchains/x86-macos.cmake
148 $ make
Tom Finegan007b2ee2017-07-11 14:47:06 -0700149~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700150
151To build for an unlisted target creation of a new toolchain file is the best
152solution. The existing toolchain files can be used a starting point for a new
153toolchain file since each one exposes the basic requirements for toolchain files
154as used in the AV1 codec build.
155
156As a temporary work around an unoptimized AV1 configuration that builds only C
157and C++ sources can be produced using the following commands:
158
Tom Finegan007b2ee2017-07-11 14:47:06 -0700159~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700160 $ cmake path/to/aom -DAOM_TARGET_CPU=generic
161 $ make
Tom Finegan007b2ee2017-07-11 14:47:06 -0700162~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700163
164In addition to the above it's important to note that the toolchain files
165suffixed with gcc behave differently than the others. These toolchain files
166attempt to obey the $CROSS environment variable.
167
Tom Finegan8a30baf2017-09-13 11:35:34 -0700168### Sanitizers
169
170Sanitizer integration is built-in to the CMake build system. To enable a
171sanitizer, add `-DSANITIZE=<type>` to the CMake command line. For example, to
172enable address sanitizer:
173
174~~~
175 $ cmake path/to/aom -DSANITIZE=address
176 $ make
177~~~
178
179Sanitizers available vary by platform, target, and compiler. Consult your
180compiler documentation to determine which, if any, are available.
181
Tom Finegan9e57db22017-06-07 07:22:37 -0700182### Microsoft Visual Studio builds
183
184Building the AV1 codec library in Microsoft Visual Studio is supported. The
185following example demonstrates generating projects and a solution for the
186Microsoft IDE:
187
Tom Finegan007b2ee2017-07-11 14:47:06 -0700188~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700189 # This does not require a bash shell; command.exe is fine.
190 $ cmake path/to/aom -G "Visual Studio 15 2017"
Tom Finegan007b2ee2017-07-11 14:47:06 -0700191~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700192
193### Xcode builds
194
195Building the AV1 codec library in Xcode is supported. The following example
196demonstrates generating an Xcode project:
197
Tom Finegan007b2ee2017-07-11 14:47:06 -0700198~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700199 $ cmake path/to/aom -G Xcode
Tom Finegan007b2ee2017-07-11 14:47:06 -0700200~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700201
Tom Finegan84d35992017-07-07 10:38:01 -0700202### Emscripten builds
203
204Building the AV1 codec library with Emscripten is supported. Typically this is
205used to hook into the AOMAnalyzer GUI application. These instructions focus on
206using the inspector with AOMAnalyzer, but all tools can be built with
207Emscripten.
208
209It is assumed here that you have already downloaded and installed the EMSDK,
210installed and activated at least one toolchain, and setup your environment
211appropriately using the emsdk\_env script.
212
2131. Download [AOMAnalyzer](https://people.xiph.org/~mbebenita/analyzer/).
214
2152. Configure the build:
216
217~~~
218 $ cmake path/to/aom \
219 -DENABLE_CCACHE=1 \
220 -DAOM_TARGET_CPU=generic \
221 -DENABLE_DOCS=0 \
222 -DCONFIG_ACCOUNTING=1 \
223 -DCONFIG_INSPECTION=1 \
224 -DCONFIG_MULTITHREAD=0 \
225 -DCONFIG_RUNTIME_CPU_DETECT=0 \
226 -DCONFIG_UNIT_TESTS=0 \
227 -DCONFIG_WEBM_IO=0 \
228 -DCMAKE_TOOLCHAIN_FILE=path/to/emsdk-portable/.../Emscripten.cmake
229~~~
230
2313. Build it: run make if that's your generator of choice:
232
233~~~
234 $ make inspect
235~~~
236
2374. Run the analyzer:
238
239~~~
240 # inspect.js is in the examples sub directory of the directory in which you
241 # executed cmake.
242 $ path/to/AOMAnalyzer path/to/examples/inspect.js path/to/av1/input/file
243~~~
244
Tom Finegan9e57db22017-06-07 07:22:37 -0700245
246## Testing the AV1 codec
247
248### Testing basics
249
Tom Finegan007b2ee2017-07-11 14:47:06 -0700250Currently there are two types of tests in the AV1 codec repository.
Tom Finegan9e57db22017-06-07 07:22:37 -0700251
Tom Finegan007b2ee2017-07-11 14:47:06 -0700252#### 1. Unit tests:
Tom Finegan9e57db22017-06-07 07:22:37 -0700253
254The unit tests can be run at build time:
255
Tom Finegan007b2ee2017-07-11 14:47:06 -0700256~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700257 # Before running the make command the LIBAOM_TEST_DATA_PATH environment
258 # variable should be set to avoid downloading the test files to the
259 # cmake build configuration directory.
260 $ cmake path/to/aom
261 # Note: The AV1 CMake build creates many test targets. Running make
262 # with multiple jobs will speed up the test run significantly.
263 $ make runtests
Tom Finegan007b2ee2017-07-11 14:47:06 -0700264~~~
265
266#### 2. Example tests:
Tom Finegan9e57db22017-06-07 07:22:37 -0700267
268The example tests require a bash shell and can be run in the following manner:
269
Tom Finegan007b2ee2017-07-11 14:47:06 -0700270~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700271 # See the note above about LIBAOM_TEST_DATA_PATH above.
272 $ cmake path/to/aom
273 $ make
274 # It's best to build the testdata target using many make jobs.
275 # Running it like this will verify and download (if necessary)
276 # one at a time, which takes a while.
277 $ make testdata
278 $ path/to/aom/test/examples.sh --bin-path examples
Tom Finegan007b2ee2017-07-11 14:47:06 -0700279~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700280
281### IDE hosted tests
282
283By default the generated projects files created by CMake will not include the
284runtests and testdata rules when generating for IDEs like Microsoft Visual
285Studio and Xcode. This is done to avoid intolerably long build cycles in the
286IDEs-- IDE behavior is to build all targets when selecting the build project
287options in MSVS and Xcode. To enable the test rules in IDEs the
288`ENABLE_IDE_TEST_HOSTING` variable must be enabled at CMake generation time:
289
Tom Finegan007b2ee2017-07-11 14:47:06 -0700290~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700291 # This example uses Xcode. To get a list of the generators
292 # available, run cmake with the -G argument missing its
293 # value.
294 $ cmake path/to/aom -DENABLE_IDE_TEST_HOSTING=1 -G Xcode
Tom Finegan007b2ee2017-07-11 14:47:06 -0700295~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700296
297### Downloading the test data
298
299The fastest and easiest way to obtain the test data is to use CMake to generate
300a build using the Unix Makefiles generator, and then to build only the testdata
301rule:
302
Tom Finegan007b2ee2017-07-11 14:47:06 -0700303~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700304 $ cmake path/to/aom -G "Unix Makefiles"
305 # 28 is used because there are 28 test files as of this writing.
306 $ make -j28 testdata
Tom Finegan007b2ee2017-07-11 14:47:06 -0700307~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700308
309The above make command will only download and verify the test data.
310
Tom Finegan007b2ee2017-07-11 14:47:06 -0700311### Sharded testing
312
313The AV1 codec library unit tests are built upon gtest which supports sharding of
314test jobs. Sharded test runs can be achieved in a couple of ways.
315
316#### 1. Running test\_libaom directly:
317
318~~~
319 # Set the environment variable GTEST_TOTAL_SHARDS to 9 to run 10 test shards
320 # (GTEST shard indexing is 0 based).
321 $ export GTEST_TOTAL_SHARDS=9
James Zern515c8692017-08-30 16:32:28 -0700322 $ seq 0 $(( $GTEST_TOTAL_SHARDS - 1 )) \
323 | xargs -n 1 -P 0 -I{} env GTEST_SHARD_INDEX={} ./test_libaom
Tom Finegan007b2ee2017-07-11 14:47:06 -0700324~~~
325
326To create a test shard for each CPU core available on the current system set
327`GTEST_TOTAL_SHARDS` to the number of CPU cores on your system minus one.
328
329#### 2. Running the tests via the CMake build:
330
331~~~
332 # For IDE based builds, ENABLE_IDE_TEST_HOSTING must be enabled. See
333 # the IDE hosted tests section above for more information. If the IDE
334 # supports building targets concurrently tests will be sharded by default.
335
336 # For make and ninja builds the -j parameter controls the number of shards
337 # at test run time. This example will run the tests using 10 shards via
338 # make.
339 $ make -j10 runtests
340~~~
341
342The maximum number of test targets that can run concurrently is determined by
343the number of CPUs on the system where the build is configured as detected by
344CMake. A system with 24 cores can run 24 test shards using a value of 24 with
345the `-j` parameter. When CMake is unable to detect the number of cores 10 shards
346is the default maximum value.
Tom Finegan9e57db22017-06-07 07:22:37 -0700347
348## Coding style
349
350The coding style used by this project is enforced with clang-format using the
351configuration contained in the .clang-format file in the root of the repository.
352
353Before pushing changes for review you can format your code with:
354
Tom Finegan007b2ee2017-07-11 14:47:06 -0700355~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700356 # Apply clang-format to modified .c, .h and .cc files
357 $ clang-format -i --style=file \
358 $(git diff --name-only --diff-filter=ACMR '*.[hc]' '*.cc')
Tom Finegan007b2ee2017-07-11 14:47:06 -0700359~~~
Tom Finegan9e57db22017-06-07 07:22:37 -0700360
361Check the .clang-format file for the version used to generate it if there is any
362difference between your local formatting and the review system.
363
364See also: http://clang.llvm.org/docs/ClangFormat.html
365
366## Support
367
368This library is an open source project supported by its community. Please
369please email aomediacodec@jointdevelopment.kavi.com for help.
370
371## Bug reports
372
373Bug reports can be filed in the Alliance for Open Media
374[issue tracker](https://bugs.chromium.org/p/aomedia/issues/list).