xref: /aosp_15_r20/external/libaom/av1/decoder/accounting.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2016, 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_AV1_DECODER_ACCOUNTING_H_
12*77c1e3ccSAndroid Build Coastguard Worker #define AOM_AV1_DECODER_ACCOUNTING_H_
13*77c1e3ccSAndroid Build Coastguard Worker #include <stdlib.h>
14*77c1e3ccSAndroid Build Coastguard Worker #include "aom/aomdx.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  // __cplusplus
19*77c1e3ccSAndroid Build Coastguard Worker 
20*77c1e3ccSAndroid Build Coastguard Worker #define AOM_ACCOUNTING_HASH_SIZE (1021)
21*77c1e3ccSAndroid Build Coastguard Worker 
22*77c1e3ccSAndroid Build Coastguard Worker /* Max number of entries for symbol types in the dictionary (increase as
23*77c1e3ccSAndroid Build Coastguard Worker    necessary). */
24*77c1e3ccSAndroid Build Coastguard Worker #define MAX_SYMBOL_TYPES (256)
25*77c1e3ccSAndroid Build Coastguard Worker 
26*77c1e3ccSAndroid Build Coastguard Worker /*The resolution of fractional-precision bit usage measurements, i.e.,
27*77c1e3ccSAndroid Build Coastguard Worker    3 => 1/8th bits.*/
28*77c1e3ccSAndroid Build Coastguard Worker #define AOM_ACCT_BITRES (3)
29*77c1e3ccSAndroid Build Coastguard Worker 
30*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
31*77c1e3ccSAndroid Build Coastguard Worker   int16_t x;
32*77c1e3ccSAndroid Build Coastguard Worker   int16_t y;
33*77c1e3ccSAndroid Build Coastguard Worker } AccountingSymbolContext;
34*77c1e3ccSAndroid Build Coastguard Worker 
35*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
36*77c1e3ccSAndroid Build Coastguard Worker   AccountingSymbolContext context;
37*77c1e3ccSAndroid Build Coastguard Worker   uint32_t id;
38*77c1e3ccSAndroid Build Coastguard Worker   /** Number of bits in units of 1/8 bit. */
39*77c1e3ccSAndroid Build Coastguard Worker   uint32_t bits;
40*77c1e3ccSAndroid Build Coastguard Worker   uint32_t samples;
41*77c1e3ccSAndroid Build Coastguard Worker } AccountingSymbol;
42*77c1e3ccSAndroid Build Coastguard Worker 
43*77c1e3ccSAndroid Build Coastguard Worker /** Dictionary for translating strings into id. */
44*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
45*77c1e3ccSAndroid Build Coastguard Worker   char *strs[MAX_SYMBOL_TYPES];
46*77c1e3ccSAndroid Build Coastguard Worker   int num_strs;
47*77c1e3ccSAndroid Build Coastguard Worker } AccountingDictionary;
48*77c1e3ccSAndroid Build Coastguard Worker 
49*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
50*77c1e3ccSAndroid Build Coastguard Worker   /** All recorded symbols decoded. */
51*77c1e3ccSAndroid Build Coastguard Worker   AccountingSymbol *syms;
52*77c1e3ccSAndroid Build Coastguard Worker   /** Number of syntax actually recorded. */
53*77c1e3ccSAndroid Build Coastguard Worker   int num_syms;
54*77c1e3ccSAndroid Build Coastguard Worker   /** Raw symbol decoding calls for non-binary values. */
55*77c1e3ccSAndroid Build Coastguard Worker   int num_multi_syms;
56*77c1e3ccSAndroid Build Coastguard Worker   /** Raw binary symbol decoding calls. */
57*77c1e3ccSAndroid Build Coastguard Worker   int num_binary_syms;
58*77c1e3ccSAndroid Build Coastguard Worker   /** Dictionary for translating strings into id. */
59*77c1e3ccSAndroid Build Coastguard Worker   AccountingDictionary dictionary;
60*77c1e3ccSAndroid Build Coastguard Worker } AccountingSymbols;
61*77c1e3ccSAndroid Build Coastguard Worker 
62*77c1e3ccSAndroid Build Coastguard Worker struct Accounting {
63*77c1e3ccSAndroid Build Coastguard Worker   AccountingSymbols syms;
64*77c1e3ccSAndroid Build Coastguard Worker   /** Size allocated for symbols (not all may be used). */
65*77c1e3ccSAndroid Build Coastguard Worker   int num_syms_allocated;
66*77c1e3ccSAndroid Build Coastguard Worker   int16_t hash_dictionary[AOM_ACCOUNTING_HASH_SIZE];
67*77c1e3ccSAndroid Build Coastguard Worker   AccountingSymbolContext context;
68*77c1e3ccSAndroid Build Coastguard Worker   uint32_t last_tell_frac;
69*77c1e3ccSAndroid Build Coastguard Worker };
70*77c1e3ccSAndroid Build Coastguard Worker 
71*77c1e3ccSAndroid Build Coastguard Worker void aom_accounting_init(Accounting *accounting);
72*77c1e3ccSAndroid Build Coastguard Worker void aom_accounting_reset(Accounting *accounting);
73*77c1e3ccSAndroid Build Coastguard Worker void aom_accounting_clear(Accounting *accounting);
74*77c1e3ccSAndroid Build Coastguard Worker void aom_accounting_set_context(Accounting *accounting, int16_t x, int16_t y);
75*77c1e3ccSAndroid Build Coastguard Worker int aom_accounting_dictionary_lookup(Accounting *accounting, const char *str);
76*77c1e3ccSAndroid Build Coastguard Worker void aom_accounting_record(Accounting *accounting, const char *str,
77*77c1e3ccSAndroid Build Coastguard Worker                            uint32_t bits);
78*77c1e3ccSAndroid Build Coastguard Worker void aom_accounting_dump(Accounting *accounting);
79*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
80*77c1e3ccSAndroid Build Coastguard Worker }  // extern "C"
81*77c1e3ccSAndroid Build Coastguard Worker #endif  // __cplusplus
82*77c1e3ccSAndroid Build Coastguard Worker #endif  // AOM_AV1_DECODER_ACCOUNTING_H_
83