/src/mozilla-central/third_party/aom/aom_dsp/bitreader.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
3 | | * |
4 | | * This source code is subject to the terms of the BSD 2 Clause License and |
5 | | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
6 | | * was not distributed with this source code in the LICENSE file, you can |
7 | | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
8 | | * Media Patent License 1.0 was not distributed with this source code in the |
9 | | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
10 | | */ |
11 | | |
12 | | #ifndef AOM_AOM_DSP_BITREADER_H_ |
13 | | #define AOM_AOM_DSP_BITREADER_H_ |
14 | | |
15 | | #include <assert.h> |
16 | | #include <limits.h> |
17 | | |
18 | | #include "config/aom_config.h" |
19 | | |
20 | | #include "aom/aomdx.h" |
21 | | #include "aom/aom_integer.h" |
22 | | #include "aom_dsp/daalaboolreader.h" |
23 | | #include "aom_dsp/prob.h" |
24 | | #include "av1/common/odintrin.h" |
25 | | |
26 | | #if CONFIG_ACCOUNTING |
27 | | #include "av1/decoder/accounting.h" |
28 | | #define ACCT_STR_NAME acct_str |
29 | | #define ACCT_STR_PARAM , const char *ACCT_STR_NAME |
30 | | #define ACCT_STR_ARG(s) , s |
31 | | #else |
32 | | #define ACCT_STR_PARAM |
33 | | #define ACCT_STR_ARG(s) |
34 | | #endif |
35 | | |
36 | | #define aom_read(r, prob, ACCT_STR_NAME) \ |
37 | 0 | aom_read_(r, prob ACCT_STR_ARG(ACCT_STR_NAME)) |
38 | | #define aom_read_bit(r, ACCT_STR_NAME) \ |
39 | 0 | aom_read_bit_(r ACCT_STR_ARG(ACCT_STR_NAME)) |
40 | | #define aom_read_tree(r, tree, probs, ACCT_STR_NAME) \ |
41 | | aom_read_tree_(r, tree, probs ACCT_STR_ARG(ACCT_STR_NAME)) |
42 | | #define aom_read_literal(r, bits, ACCT_STR_NAME) \ |
43 | 0 | aom_read_literal_(r, bits ACCT_STR_ARG(ACCT_STR_NAME)) |
44 | | #define aom_read_cdf(r, cdf, nsymbs, ACCT_STR_NAME) \ |
45 | 0 | aom_read_cdf_(r, cdf, nsymbs ACCT_STR_ARG(ACCT_STR_NAME)) |
46 | | #define aom_read_symbol(r, cdf, nsymbs, ACCT_STR_NAME) \ |
47 | 0 | aom_read_symbol_(r, cdf, nsymbs ACCT_STR_ARG(ACCT_STR_NAME)) |
48 | | |
49 | | #ifdef __cplusplus |
50 | | extern "C" { |
51 | | #endif |
52 | | |
53 | | typedef struct daala_reader aom_reader; |
54 | | |
55 | | static INLINE int aom_reader_init(aom_reader *r, const uint8_t *buffer, |
56 | 0 | size_t size) { |
57 | 0 | return aom_daala_reader_init(r, buffer, (int)size); |
58 | 0 | } Unexecuted instantiation: binary_codes_reader.c:aom_reader_init Unexecuted instantiation: av1_dx_iface.c:aom_reader_init Unexecuted instantiation: decodeframe.c:aom_reader_init Unexecuted instantiation: decodemv.c:aom_reader_init Unexecuted instantiation: decoder.c:aom_reader_init Unexecuted instantiation: decodetxb.c:aom_reader_init Unexecuted instantiation: detokenize.c:aom_reader_init Unexecuted instantiation: dthread.c:aom_reader_init Unexecuted instantiation: obu.c:aom_reader_init |
59 | | |
60 | 0 | static INLINE const uint8_t *aom_reader_find_begin(aom_reader *r) { |
61 | 0 | return aom_daala_reader_find_begin(r); |
62 | 0 | } Unexecuted instantiation: binary_codes_reader.c:aom_reader_find_begin Unexecuted instantiation: av1_dx_iface.c:aom_reader_find_begin Unexecuted instantiation: decodeframe.c:aom_reader_find_begin Unexecuted instantiation: decodemv.c:aom_reader_find_begin Unexecuted instantiation: decoder.c:aom_reader_find_begin Unexecuted instantiation: decodetxb.c:aom_reader_find_begin Unexecuted instantiation: detokenize.c:aom_reader_find_begin Unexecuted instantiation: dthread.c:aom_reader_find_begin Unexecuted instantiation: obu.c:aom_reader_find_begin |
63 | | |
64 | 0 | static INLINE const uint8_t *aom_reader_find_end(aom_reader *r) { |
65 | 0 | return aom_daala_reader_find_end(r); |
66 | 0 | } Unexecuted instantiation: binary_codes_reader.c:aom_reader_find_end Unexecuted instantiation: av1_dx_iface.c:aom_reader_find_end Unexecuted instantiation: decodeframe.c:aom_reader_find_end Unexecuted instantiation: decodemv.c:aom_reader_find_end Unexecuted instantiation: decoder.c:aom_reader_find_end Unexecuted instantiation: decodetxb.c:aom_reader_find_end Unexecuted instantiation: detokenize.c:aom_reader_find_end Unexecuted instantiation: dthread.c:aom_reader_find_end Unexecuted instantiation: obu.c:aom_reader_find_end |
67 | | |
68 | 0 | static INLINE int aom_reader_has_error(aom_reader *r) { |
69 | 0 | return aom_daala_reader_has_error(r); |
70 | 0 | } Unexecuted instantiation: binary_codes_reader.c:aom_reader_has_error Unexecuted instantiation: av1_dx_iface.c:aom_reader_has_error Unexecuted instantiation: decodeframe.c:aom_reader_has_error Unexecuted instantiation: decodemv.c:aom_reader_has_error Unexecuted instantiation: decoder.c:aom_reader_has_error Unexecuted instantiation: decodetxb.c:aom_reader_has_error Unexecuted instantiation: detokenize.c:aom_reader_has_error Unexecuted instantiation: dthread.c:aom_reader_has_error Unexecuted instantiation: obu.c:aom_reader_has_error |
71 | | |
72 | | // Returns true if the bit reader has tried to decode more data from the buffer |
73 | | // than was actually provided. |
74 | 0 | static INLINE int aom_reader_has_overflowed(const aom_reader *r) { |
75 | 0 | return aom_daala_reader_has_overflowed(r); |
76 | 0 | } Unexecuted instantiation: binary_codes_reader.c:aom_reader_has_overflowed Unexecuted instantiation: av1_dx_iface.c:aom_reader_has_overflowed Unexecuted instantiation: decodeframe.c:aom_reader_has_overflowed Unexecuted instantiation: decodemv.c:aom_reader_has_overflowed Unexecuted instantiation: decoder.c:aom_reader_has_overflowed Unexecuted instantiation: decodetxb.c:aom_reader_has_overflowed Unexecuted instantiation: detokenize.c:aom_reader_has_overflowed Unexecuted instantiation: dthread.c:aom_reader_has_overflowed Unexecuted instantiation: obu.c:aom_reader_has_overflowed |
77 | | |
78 | | // Returns the position in the bit reader in bits. |
79 | 0 | static INLINE uint32_t aom_reader_tell(const aom_reader *r) { |
80 | 0 | return aom_daala_reader_tell(r); |
81 | 0 | } Unexecuted instantiation: binary_codes_reader.c:aom_reader_tell Unexecuted instantiation: av1_dx_iface.c:aom_reader_tell Unexecuted instantiation: decodeframe.c:aom_reader_tell Unexecuted instantiation: decodemv.c:aom_reader_tell Unexecuted instantiation: decoder.c:aom_reader_tell Unexecuted instantiation: decodetxb.c:aom_reader_tell Unexecuted instantiation: detokenize.c:aom_reader_tell Unexecuted instantiation: dthread.c:aom_reader_tell Unexecuted instantiation: obu.c:aom_reader_tell |
82 | | |
83 | | // Returns the position in the bit reader in 1/8th bits. |
84 | 0 | static INLINE uint32_t aom_reader_tell_frac(const aom_reader *r) { |
85 | 0 | return aom_daala_reader_tell_frac(r); |
86 | 0 | } Unexecuted instantiation: binary_codes_reader.c:aom_reader_tell_frac Unexecuted instantiation: av1_dx_iface.c:aom_reader_tell_frac Unexecuted instantiation: decodeframe.c:aom_reader_tell_frac Unexecuted instantiation: decodemv.c:aom_reader_tell_frac Unexecuted instantiation: decoder.c:aom_reader_tell_frac Unexecuted instantiation: decodetxb.c:aom_reader_tell_frac Unexecuted instantiation: detokenize.c:aom_reader_tell_frac Unexecuted instantiation: dthread.c:aom_reader_tell_frac Unexecuted instantiation: obu.c:aom_reader_tell_frac |
87 | | |
88 | | #if CONFIG_ACCOUNTING |
89 | | static INLINE void aom_process_accounting(const aom_reader *r ACCT_STR_PARAM) { |
90 | | if (r->accounting != NULL) { |
91 | | uint32_t tell_frac; |
92 | | tell_frac = aom_reader_tell_frac(r); |
93 | | aom_accounting_record(r->accounting, ACCT_STR_NAME, |
94 | | tell_frac - r->accounting->last_tell_frac); |
95 | | r->accounting->last_tell_frac = tell_frac; |
96 | | } |
97 | | } |
98 | | |
99 | | static INLINE void aom_update_symb_counts(const aom_reader *r, int is_binary) { |
100 | | if (r->accounting != NULL) { |
101 | | r->accounting->syms.num_multi_syms += !is_binary; |
102 | | r->accounting->syms.num_binary_syms += !!is_binary; |
103 | | } |
104 | | } |
105 | | #endif |
106 | | |
107 | 0 | static INLINE int aom_read_(aom_reader *r, int prob ACCT_STR_PARAM) { |
108 | 0 | int ret; |
109 | 0 | ret = aom_daala_read(r, prob); |
110 | | #if CONFIG_ACCOUNTING |
111 | | if (ACCT_STR_NAME) aom_process_accounting(r, ACCT_STR_NAME); |
112 | | aom_update_symb_counts(r, 1); |
113 | | #endif |
114 | | return ret; |
115 | 0 | } Unexecuted instantiation: binary_codes_reader.c:aom_read_ Unexecuted instantiation: av1_dx_iface.c:aom_read_ Unexecuted instantiation: decodeframe.c:aom_read_ Unexecuted instantiation: decodemv.c:aom_read_ Unexecuted instantiation: decoder.c:aom_read_ Unexecuted instantiation: decodetxb.c:aom_read_ Unexecuted instantiation: detokenize.c:aom_read_ Unexecuted instantiation: dthread.c:aom_read_ Unexecuted instantiation: obu.c:aom_read_ |
116 | | |
117 | 0 | static INLINE int aom_read_bit_(aom_reader *r ACCT_STR_PARAM) { |
118 | 0 | int ret; |
119 | 0 | ret = aom_read(r, 128, NULL); // aom_prob_half |
120 | | #if CONFIG_ACCOUNTING |
121 | | if (ACCT_STR_NAME) aom_process_accounting(r, ACCT_STR_NAME); |
122 | | #endif |
123 | | return ret; |
124 | 0 | } Unexecuted instantiation: binary_codes_reader.c:aom_read_bit_ Unexecuted instantiation: av1_dx_iface.c:aom_read_bit_ Unexecuted instantiation: decodeframe.c:aom_read_bit_ Unexecuted instantiation: decodemv.c:aom_read_bit_ Unexecuted instantiation: decoder.c:aom_read_bit_ Unexecuted instantiation: decodetxb.c:aom_read_bit_ Unexecuted instantiation: detokenize.c:aom_read_bit_ Unexecuted instantiation: dthread.c:aom_read_bit_ Unexecuted instantiation: obu.c:aom_read_bit_ |
125 | | |
126 | 0 | static INLINE int aom_read_literal_(aom_reader *r, int bits ACCT_STR_PARAM) { |
127 | 0 | int literal = 0, bit; |
128 | 0 |
|
129 | 0 | for (bit = bits - 1; bit >= 0; bit--) literal |= aom_read_bit(r, NULL) << bit; |
130 | | #if CONFIG_ACCOUNTING |
131 | | if (ACCT_STR_NAME) aom_process_accounting(r, ACCT_STR_NAME); |
132 | | #endif |
133 | | return literal; |
134 | 0 | } Unexecuted instantiation: binary_codes_reader.c:aom_read_literal_ Unexecuted instantiation: av1_dx_iface.c:aom_read_literal_ Unexecuted instantiation: decodeframe.c:aom_read_literal_ Unexecuted instantiation: decodemv.c:aom_read_literal_ Unexecuted instantiation: decoder.c:aom_read_literal_ Unexecuted instantiation: decodetxb.c:aom_read_literal_ Unexecuted instantiation: detokenize.c:aom_read_literal_ Unexecuted instantiation: dthread.c:aom_read_literal_ Unexecuted instantiation: obu.c:aom_read_literal_ |
135 | | |
136 | | static INLINE int aom_read_cdf_(aom_reader *r, const aom_cdf_prob *cdf, |
137 | 0 | int nsymbs ACCT_STR_PARAM) { |
138 | 0 | int ret; |
139 | 0 | ret = daala_read_symbol(r, cdf, nsymbs); |
140 | 0 |
|
141 | | #if CONFIG_ACCOUNTING |
142 | | if (ACCT_STR_NAME) aom_process_accounting(r, ACCT_STR_NAME); |
143 | | aom_update_symb_counts(r, (nsymbs == 2)); |
144 | | #endif |
145 | | return ret; |
146 | 0 | } Unexecuted instantiation: binary_codes_reader.c:aom_read_cdf_ Unexecuted instantiation: av1_dx_iface.c:aom_read_cdf_ Unexecuted instantiation: decodeframe.c:aom_read_cdf_ Unexecuted instantiation: decodemv.c:aom_read_cdf_ Unexecuted instantiation: decoder.c:aom_read_cdf_ Unexecuted instantiation: decodetxb.c:aom_read_cdf_ Unexecuted instantiation: detokenize.c:aom_read_cdf_ Unexecuted instantiation: dthread.c:aom_read_cdf_ Unexecuted instantiation: obu.c:aom_read_cdf_ |
147 | | |
148 | | static INLINE int aom_read_symbol_(aom_reader *r, aom_cdf_prob *cdf, |
149 | 0 | int nsymbs ACCT_STR_PARAM) { |
150 | 0 | int ret; |
151 | 0 | ret = aom_read_cdf(r, cdf, nsymbs, ACCT_STR_NAME); |
152 | 0 | if (r->allow_update_cdf) update_cdf(cdf, ret, nsymbs); |
153 | 0 | return ret; |
154 | 0 | } Unexecuted instantiation: binary_codes_reader.c:aom_read_symbol_ Unexecuted instantiation: av1_dx_iface.c:aom_read_symbol_ Unexecuted instantiation: decodeframe.c:aom_read_symbol_ Unexecuted instantiation: decodemv.c:aom_read_symbol_ Unexecuted instantiation: decoder.c:aom_read_symbol_ Unexecuted instantiation: decodetxb.c:aom_read_symbol_ Unexecuted instantiation: detokenize.c:aom_read_symbol_ Unexecuted instantiation: dthread.c:aom_read_symbol_ Unexecuted instantiation: obu.c:aom_read_symbol_ |
155 | | |
156 | | #ifdef __cplusplus |
157 | | } // extern "C" |
158 | | #endif |
159 | | |
160 | | #endif // AOM_AOM_DSP_BITREADER_H_ |