xref: /aosp_15_r20/external/libaom/common/av1_config.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2018, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker  *
4*77c1e3ccSAndroid Build Coastguard Worker  * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker  * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker  * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker  */
11*77c1e3ccSAndroid Build Coastguard Worker #ifndef AOM_COMMON_AV1_CONFIG_H_
12*77c1e3ccSAndroid Build Coastguard Worker #define AOM_COMMON_AV1_CONFIG_H_
13*77c1e3ccSAndroid Build Coastguard Worker 
14*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aom_integer.h"
15*77c1e3ccSAndroid Build Coastguard Worker 
16*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
17*77c1e3ccSAndroid Build Coastguard Worker extern "C" {
18*77c1e3ccSAndroid Build Coastguard Worker #endif
19*77c1e3ccSAndroid Build Coastguard Worker 
20*77c1e3ccSAndroid Build Coastguard Worker // Struct representing ISOBMFF/Matroska AV1 config. See:
21*77c1e3ccSAndroid Build Coastguard Worker // https://aomediacodec.github.io/av1-isobmff/#av1codecconfigurationbox-syntax
22*77c1e3ccSAndroid Build Coastguard Worker //
23*77c1e3ccSAndroid Build Coastguard Worker // The AV1 config has the following format:
24*77c1e3ccSAndroid Build Coastguard Worker //
25*77c1e3ccSAndroid Build Coastguard Worker // unsigned int (1) marker = 1;
26*77c1e3ccSAndroid Build Coastguard Worker // unsigned int (7) version = 1;
27*77c1e3ccSAndroid Build Coastguard Worker // unsigned int (3) seq_profile;
28*77c1e3ccSAndroid Build Coastguard Worker // unsigned int (5) seq_level_idx_0;
29*77c1e3ccSAndroid Build Coastguard Worker // unsigned int (1) seq_tier_0;
30*77c1e3ccSAndroid Build Coastguard Worker // unsigned int (1) high_bitdepth;
31*77c1e3ccSAndroid Build Coastguard Worker // unsigned int (1) twelve_bit;
32*77c1e3ccSAndroid Build Coastguard Worker // unsigned int (1) monochrome;
33*77c1e3ccSAndroid Build Coastguard Worker // unsigned int (1) chroma_subsampling_x;
34*77c1e3ccSAndroid Build Coastguard Worker // unsigned int (1) chroma_subsampling_y;
35*77c1e3ccSAndroid Build Coastguard Worker // unsigned int (2) chroma_sample_position;
36*77c1e3ccSAndroid Build Coastguard Worker // unsigned int (3) reserved = 0;
37*77c1e3ccSAndroid Build Coastguard Worker //
38*77c1e3ccSAndroid Build Coastguard Worker // unsigned int (1) initial_presentation_delay_present;
39*77c1e3ccSAndroid Build Coastguard Worker // if (initial_presentation_delay_present) {
40*77c1e3ccSAndroid Build Coastguard Worker //   unsigned int (4) initial_presentation_delay_minus_one;
41*77c1e3ccSAndroid Build Coastguard Worker // } else {
42*77c1e3ccSAndroid Build Coastguard Worker //   unsigned int (4) reserved = 0;
43*77c1e3ccSAndroid Build Coastguard Worker // }
44*77c1e3ccSAndroid Build Coastguard Worker //
45*77c1e3ccSAndroid Build Coastguard Worker // unsigned int (8)[] configOBUs;
46*77c1e3ccSAndroid Build Coastguard Worker //
47*77c1e3ccSAndroid Build Coastguard Worker // Note: get_av1config_from_obu() does not currently store 'configOBUs' data, so
48*77c1e3ccSAndroid Build Coastguard Worker // the field is omitted.
49*77c1e3ccSAndroid Build Coastguard Worker typedef struct _Av1Config {
50*77c1e3ccSAndroid Build Coastguard Worker   uint8_t marker;
51*77c1e3ccSAndroid Build Coastguard Worker   uint8_t version;
52*77c1e3ccSAndroid Build Coastguard Worker   uint8_t seq_profile;
53*77c1e3ccSAndroid Build Coastguard Worker   uint8_t seq_level_idx_0;
54*77c1e3ccSAndroid Build Coastguard Worker   uint8_t seq_tier_0;
55*77c1e3ccSAndroid Build Coastguard Worker   uint8_t high_bitdepth;
56*77c1e3ccSAndroid Build Coastguard Worker   uint8_t twelve_bit;
57*77c1e3ccSAndroid Build Coastguard Worker   uint8_t monochrome;
58*77c1e3ccSAndroid Build Coastguard Worker   uint8_t chroma_subsampling_x;
59*77c1e3ccSAndroid Build Coastguard Worker   uint8_t chroma_subsampling_y;
60*77c1e3ccSAndroid Build Coastguard Worker   uint8_t chroma_sample_position;
61*77c1e3ccSAndroid Build Coastguard Worker   uint8_t initial_presentation_delay_present;
62*77c1e3ccSAndroid Build Coastguard Worker   uint8_t initial_presentation_delay_minus_one;
63*77c1e3ccSAndroid Build Coastguard Worker } Av1Config;
64*77c1e3ccSAndroid Build Coastguard Worker 
65*77c1e3ccSAndroid Build Coastguard Worker // Attempts to parse a Sequence Header OBU and set the paramenters of 'config'.
66*77c1e3ccSAndroid Build Coastguard Worker // Returns 0 upon success, and -1 upon failure. 'buffer' can contain multiple
67*77c1e3ccSAndroid Build Coastguard Worker // OBUs, but the Sequence Header OBU must be the first OBU within the buffer.
68*77c1e3ccSAndroid Build Coastguard Worker int get_av1config_from_obu(const uint8_t *buffer, size_t length, int is_annexb,
69*77c1e3ccSAndroid Build Coastguard Worker                            Av1Config *config);
70*77c1e3ccSAndroid Build Coastguard Worker 
71*77c1e3ccSAndroid Build Coastguard Worker // Attempts to parse an AV1 config from 'buffer'. Returns 0 upon success.
72*77c1e3ccSAndroid Build Coastguard Worker // Returns -1 when 'buffer_length' is less than 4, when passed NULL pointers, or
73*77c1e3ccSAndroid Build Coastguard Worker // when parsing of 'buffer' fails.
74*77c1e3ccSAndroid Build Coastguard Worker int read_av1config(const uint8_t *buffer, size_t buffer_length,
75*77c1e3ccSAndroid Build Coastguard Worker                    size_t *bytes_read, Av1Config *config);
76*77c1e3ccSAndroid Build Coastguard Worker 
77*77c1e3ccSAndroid Build Coastguard Worker // Writes 'config' to 'buffer'. Returns 0 upon successful write to 'buffer'.
78*77c1e3ccSAndroid Build Coastguard Worker // Returns -1 when passed NULL pointers or when 'capacity' insufficient.
79*77c1e3ccSAndroid Build Coastguard Worker int write_av1config(const Av1Config *config, size_t capacity,
80*77c1e3ccSAndroid Build Coastguard Worker                     size_t *bytes_written, uint8_t *buffer);
81*77c1e3ccSAndroid Build Coastguard Worker 
82*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
83*77c1e3ccSAndroid Build Coastguard Worker } /* extern "C" */
84*77c1e3ccSAndroid Build Coastguard Worker #endif
85*77c1e3ccSAndroid Build Coastguard Worker 
86*77c1e3ccSAndroid Build Coastguard Worker #endif  // AOM_COMMON_AV1_CONFIG_H_
87