xref: /aosp_15_r20/external/libgav1/README.md (revision 095378508e87ed692bf8dfeb34008b65b3735891)
1*09537850SAkhilesh Sanikop# libgav1 -- an AV1 decoder
2*09537850SAkhilesh Sanikop
3*09537850SAkhilesh Sanikoplibgav1 is a Main profile (0), High profile (1) & Professional profile (2)
4*09537850SAkhilesh Sanikopcompliant AV1 decoder. More information on the AV1 video format can be found at
5*09537850SAkhilesh Sanikop[aomedia.org](https://aomedia.org).
6*09537850SAkhilesh Sanikop
7*09537850SAkhilesh Sanikop[TOC]
8*09537850SAkhilesh Sanikop
9*09537850SAkhilesh Sanikop## Building
10*09537850SAkhilesh Sanikop
11*09537850SAkhilesh Sanikop### Prerequisites
12*09537850SAkhilesh Sanikop
13*09537850SAkhilesh Sanikop1.  A C++11 compiler. gcc 6+, clang 7+ or Microsoft Visual Studio 2017+ are
14*09537850SAkhilesh Sanikop    recommended.
15*09537850SAkhilesh Sanikop
16*09537850SAkhilesh Sanikop2.  [CMake >= 3.7.1](https://cmake.org/download/)
17*09537850SAkhilesh Sanikop
18*09537850SAkhilesh Sanikop3.  [Abseil](https://abseil.io)
19*09537850SAkhilesh Sanikop
20*09537850SAkhilesh Sanikop    From within the libgav1 directory:
21*09537850SAkhilesh Sanikop
22*09537850SAkhilesh Sanikop    ```shell
23*09537850SAkhilesh Sanikop    $ git clone -b 20220623.0 --depth 1 \
24*09537850SAkhilesh Sanikop      https://github.com/abseil/abseil-cpp.git third_party/abseil-cpp
25*09537850SAkhilesh Sanikop    ```
26*09537850SAkhilesh Sanikop
27*09537850SAkhilesh Sanikop    Note: Abseil is required by the examples and tests. libgav1 will depend on
28*09537850SAkhilesh Sanikop    it if `LIBGAV1_THREADPOOL_USE_STD_MUTEX` is set to `0` (see below).
29*09537850SAkhilesh Sanikop
30*09537850SAkhilesh Sanikop4.  (Optional) [GoogleTest](https://github.com/google/googletest)
31*09537850SAkhilesh Sanikop
32*09537850SAkhilesh Sanikop    From within the libgav1 directory:
33*09537850SAkhilesh Sanikop
34*09537850SAkhilesh Sanikop    ```shell
35*09537850SAkhilesh Sanikop    $ git clone -b release-1.12.1 --depth 1 \
36*09537850SAkhilesh Sanikop      https://github.com/google/googletest.git third_party/googletest
37*09537850SAkhilesh Sanikop    ```
38*09537850SAkhilesh Sanikop
39*09537850SAkhilesh Sanikop### Compile
40*09537850SAkhilesh Sanikop
41*09537850SAkhilesh Sanikop```shell
42*09537850SAkhilesh Sanikop  $ mkdir build && cd build
43*09537850SAkhilesh Sanikop  $ cmake -G "Unix Makefiles" ..
44*09537850SAkhilesh Sanikop  $ make
45*09537850SAkhilesh Sanikop```
46*09537850SAkhilesh Sanikop
47*09537850SAkhilesh SanikopConfiguration options:
48*09537850SAkhilesh Sanikop
49*09537850SAkhilesh Sanikop*   `LIBGAV1_MAX_BITDEPTH`: defines the maximum supported bitdepth (8, 10, 12;
50*09537850SAkhilesh Sanikop    default: 12).
51*09537850SAkhilesh Sanikop*   `LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS`: define to a non-zero value to disable
52*09537850SAkhilesh Sanikop    [symbol reduction](#symbol-reduction) in an optimized build to keep all
53*09537850SAkhilesh Sanikop    versions of dsp functions available. Automatically defined in
54*09537850SAkhilesh Sanikop    `src/dsp/dsp.h` if unset.
55*09537850SAkhilesh Sanikop*   `LIBGAV1_ENABLE_AVX2`: define to a non-zero value to enable avx2
56*09537850SAkhilesh Sanikop    optimizations. Automatically defined in `src/utils/cpu.h` if unset.
57*09537850SAkhilesh Sanikop*   `LIBGAV1_ENABLE_NEON`: define to a non-zero value to enable NEON
58*09537850SAkhilesh Sanikop    optimizations. Automatically defined in `src/utils/cpu.h` if unset.
59*09537850SAkhilesh Sanikop*   `LIBGAV1_ENABLE_SSE4_1`: define to a non-zero value to enable sse4.1
60*09537850SAkhilesh Sanikop    optimizations. Automatically defined in `src/utils/cpu.h` if unset. Note
61*09537850SAkhilesh Sanikop    setting this to 0 will also disable AVX2.
62*09537850SAkhilesh Sanikop*   `LIBGAV1_ENABLE_LOGGING`: define to 0/1 to control debug logging.
63*09537850SAkhilesh Sanikop    Automatically defined in `src/utils/logging.h` if unset.
64*09537850SAkhilesh Sanikop*   `LIBGAV1_EXAMPLES_ENABLE_LOGGING`: define to 0/1 to control error logging in
65*09537850SAkhilesh Sanikop    the examples. Automatically defined in `examples/logging.h` if unset.
66*09537850SAkhilesh Sanikop*   `LIBGAV1_ENABLE_TRANSFORM_RANGE_CHECK`: define to 1 to enable transform
67*09537850SAkhilesh Sanikop    coefficient range checks.
68*09537850SAkhilesh Sanikop*   `LIBGAV1_LOG_LEVEL`: controls the maximum allowed log level, see `enum
69*09537850SAkhilesh Sanikop    LogSeverity` in `src/utils/logging.h`. Automatically defined in
70*09537850SAkhilesh Sanikop    `src/utils/logging.cc` if unset.
71*09537850SAkhilesh Sanikop*   `LIBGAV1_THREADPOOL_USE_STD_MUTEX`: controls use of std::mutex and
72*09537850SAkhilesh Sanikop    absl::Mutex in ThreadPool. Defining this to 1 will remove any Abseil
73*09537850SAkhilesh Sanikop    dependency from the core library. Automatically defined in
74*09537850SAkhilesh Sanikop    `src/utils/threadpool.h` if unset. Defaults to 1 on Android & iOS, 0
75*09537850SAkhilesh Sanikop    otherwise.
76*09537850SAkhilesh Sanikop*   `LIBGAV1_MAX_THREADS`: sets the number of threads that the library is
77*09537850SAkhilesh Sanikop    allowed to create. Has to be an integer > 0. Otherwise this is ignored. The
78*09537850SAkhilesh Sanikop    default value is 128.
79*09537850SAkhilesh Sanikop*   `LIBGAV1_FRAME_PARALLEL_THRESHOLD_MULTIPLIER`: the threshold multiplier that
80*09537850SAkhilesh Sanikop    is used to determine when to use frame parallel decoding. Frame parallel
81*09537850SAkhilesh Sanikop    decoding will be used if |threads| > |tile_count| * this multiplier. Has to
82*09537850SAkhilesh Sanikop    be an integer > 0. The default value is 4. This is an advanced setting
83*09537850SAkhilesh Sanikop    intended for testing purposes.
84*09537850SAkhilesh Sanikop
85*09537850SAkhilesh SanikopFor additional options see:
86*09537850SAkhilesh Sanikop
87*09537850SAkhilesh Sanikop```shell
88*09537850SAkhilesh Sanikop  $ cmake .. -LH
89*09537850SAkhilesh Sanikop```
90*09537850SAkhilesh Sanikop
91*09537850SAkhilesh Sanikop## Testing
92*09537850SAkhilesh Sanikop
93*09537850SAkhilesh Sanikop*   `gav1_decode` can be used to decode IVF files, see `gav1_decode --help` for
94*09537850SAkhilesh Sanikop    options. Note: tools like [FFmpeg](https://ffmpeg.org) can be used to
95*09537850SAkhilesh Sanikop    convert other container formats to IVF.
96*09537850SAkhilesh Sanikop
97*09537850SAkhilesh Sanikop*   Unit tests are built when `LIBGAV1_ENABLE_TESTS` is set to `1`. The binaries
98*09537850SAkhilesh Sanikop    can be invoked directly or with
99*09537850SAkhilesh Sanikop    [`ctest`](https://cmake.org/cmake/help/latest/manual/ctest.1.html).
100*09537850SAkhilesh Sanikop
101*09537850SAkhilesh Sanikop    *   The test input location can be given by setting the
102*09537850SAkhilesh Sanikop        `LIBGAV1_TEST_DATA_PATH` environment variable; it defaults to
103*09537850SAkhilesh Sanikop        `<libgav1_src>/tests/data`, where `<libgav1_src>` is `/data/local/tmp`
104*09537850SAkhilesh Sanikop        on Android platforms or the source directory configured with cmake
105*09537850SAkhilesh Sanikop        otherwise.
106*09537850SAkhilesh Sanikop
107*09537850SAkhilesh Sanikop    *   Output is written to the value of the `TMPDIR` or `TEMP` environment
108*09537850SAkhilesh Sanikop        variables in that order if set, otherwise `/data/local/tmp` on Android
109*09537850SAkhilesh Sanikop        platforms, the value of `LIBGAV1_FLAGS_TMPDIR` if defined during
110*09537850SAkhilesh Sanikop        compilation or the current directory if not.
111*09537850SAkhilesh Sanikop
112*09537850SAkhilesh Sanikop## Development
113*09537850SAkhilesh Sanikop
114*09537850SAkhilesh Sanikop### Contributing
115*09537850SAkhilesh Sanikop
116*09537850SAkhilesh SanikopSee [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to submit patches.
117*09537850SAkhilesh Sanikop
118*09537850SAkhilesh Sanikop### Style
119*09537850SAkhilesh Sanikop
120*09537850SAkhilesh Sanikoplibgav1 follows the
121*09537850SAkhilesh Sanikop[Google C++ style guide](https://google.github.io/styleguide/cppguide.html) with
122*09537850SAkhilesh Sanikopformatting enforced by `clang-format`.
123*09537850SAkhilesh Sanikop
124*09537850SAkhilesh Sanikop### Comments
125*09537850SAkhilesh Sanikop
126*09537850SAkhilesh SanikopComments of the form '`// X.Y(.Z).`', '`Section X.Y(.Z).`' or '`... in the
127*09537850SAkhilesh Sanikopspec`' reference the relevant section(s) in the
128*09537850SAkhilesh Sanikop[AV1 specification](http://aomediacodec.github.io/av1-spec/av1-spec.pdf).
129*09537850SAkhilesh Sanikop
130*09537850SAkhilesh Sanikop### DSP structure
131*09537850SAkhilesh Sanikop
132*09537850SAkhilesh Sanikop*   `src/dsp/dsp.cc` defines the main entry point: `libgav1::dsp::DspInit()`.
133*09537850SAkhilesh Sanikop    This handles cpu-detection and initializing each logical unit which populate
134*09537850SAkhilesh Sanikop    `libgav1::dsp::Dsp` function tables.
135*09537850SAkhilesh Sanikop*   `src/dsp/dsp.h` contains function and type definitions for all logical units
136*09537850SAkhilesh Sanikop    (e.g., intra-predictors)
137*09537850SAkhilesh Sanikop*   `src/utils/cpu.h` contains definitions for cpu-detection
138*09537850SAkhilesh Sanikop*   base implementations are located in `src/dsp/*.{h,cc}` with platform
139*09537850SAkhilesh Sanikop    specific optimizations in sub-folders
140*09537850SAkhilesh Sanikop*   unit tests define `DISABLED_Speed` test(s) to allow timing of individual
141*09537850SAkhilesh Sanikop    functions
142*09537850SAkhilesh Sanikop
143*09537850SAkhilesh Sanikop#### Symbol reduction
144*09537850SAkhilesh Sanikop
145*09537850SAkhilesh SanikopBased on the build configuration unneeded lesser optimizations are removed using
146*09537850SAkhilesh Sanikopa hierarchical include and define system. Each logical unit in `src/dsp` should
147*09537850SAkhilesh Sanikopinclude all platform specific headers in descending order to allow higher level
148*09537850SAkhilesh Sanikopoptimizations to disable lower level ones. See `src/dsp/loop_filter.h` for an
149*09537850SAkhilesh Sanikopexample.
150*09537850SAkhilesh Sanikop
151*09537850SAkhilesh SanikopEach function receives a new define which can be checked in platform specific
152*09537850SAkhilesh Sanikopheaders. The format is: `LIBGAV1_<Dsp-table>_FunctionName` or
153*09537850SAkhilesh Sanikop`LIBGAV1_<Dsp-table>_[sub-table-index1][...-indexN]`, e.g.,
154*09537850SAkhilesh Sanikop`LIBGAV1_Dsp8bpp_AverageBlend`,
155*09537850SAkhilesh Sanikop`LIBGAV1_Dsp8bpp_TransformSize4x4_IntraPredictorDc`. The Dsp-table name is of
156*09537850SAkhilesh Sanikopthe form `Dsp<bitdepth>bpp` e.g. `Dsp10bpp` for bitdepth == 10 (bpp stands for
157*09537850SAkhilesh Sanikopbits per pixel). The indices correspond to enum values used as lookups with
158*09537850SAkhilesh Sanikopleading 'k' removed. Platform specific headers then should first check if the
159*09537850SAkhilesh Sanikopsymbol is defined and if not set the value to the corresponding
160*09537850SAkhilesh Sanikop`LIBGAV1_CPU_<arch>` value from `src/utils/cpu.h`.
161*09537850SAkhilesh Sanikop
162*09537850SAkhilesh Sanikop```
163*09537850SAkhilesh Sanikop  #ifndef LIBGAV1_Dsp8bpp_TransformSize4x4_IntraPredictorDc
164*09537850SAkhilesh Sanikop  #define LIBGAV1_Dsp8bpp_TransformSize4x4_IntraPredictorDc LIBGAV1_CPU_SSE4_1
165*09537850SAkhilesh Sanikop  #endif
166*09537850SAkhilesh Sanikop```
167*09537850SAkhilesh Sanikop
168*09537850SAkhilesh SanikopWithin each module the code should check if the symbol is defined to its
169*09537850SAkhilesh Sanikopspecific architecture or forced via `LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS` before
170*09537850SAkhilesh Sanikopdefining the function. The `DSP_ENABLED_(8|10)BPP_*` macros are available to
171*09537850SAkhilesh Sanikopsimplify this check for optimized code.
172*09537850SAkhilesh Sanikop
173*09537850SAkhilesh Sanikop```
174*09537850SAkhilesh Sanikop  #if DSP_ENABLED_8BPP_SSE4_1(TransformSize4x4_IntraPredictorDc)
175*09537850SAkhilesh Sanikop  ...
176*09537850SAkhilesh Sanikop
177*09537850SAkhilesh Sanikop  // In unoptimized code use the following structure; there's no equivalent
178*09537850SAkhilesh Sanikop  // define for LIBGAV1_CPU_C as it would require duplicating the function
179*09537850SAkhilesh Sanikop  // defines used in optimized code for only a small benefit to this
180*09537850SAkhilesh Sanikop  // boilerplate.
181*09537850SAkhilesh Sanikop  #if LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
182*09537850SAkhilesh Sanikop  ...
183*09537850SAkhilesh Sanikop  #else  // !LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
184*09537850SAkhilesh Sanikop  #ifndef LIBGAV1_Dsp8bpp_TransformSize4x4_IntraPredictorDcFill
185*09537850SAkhilesh Sanikop  ...
186*09537850SAkhilesh Sanikop```
187*09537850SAkhilesh Sanikop
188*09537850SAkhilesh Sanikop## Bugs
189*09537850SAkhilesh Sanikop
190*09537850SAkhilesh SanikopPlease report all bugs to the issue tracker:
191*09537850SAkhilesh Sanikophttps://issuetracker.google.com/issues/new?component=750480&template=1355007
192*09537850SAkhilesh Sanikop
193*09537850SAkhilesh Sanikop## Discussion
194*09537850SAkhilesh Sanikop
195*09537850SAkhilesh SanikopEmail: [email protected]
196*09537850SAkhilesh Sanikop
197*09537850SAkhilesh SanikopWeb: https://groups.google.com/forum/#!forum/gav1-devel
198