2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
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.
12 #ifndef AOM_AOM_DSP_BITWRITER_H_
13 #define AOM_AOM_DSP_BITWRITER_H_
17 #include "config/aom_config.h"
19 #include "aom_dsp/entenc.h"
20 #include "aom_dsp/prob.h"
23 #include "av1/common/blockd.h"
24 #include "av1/encoder/cost.h"
27 #if CONFIG_BITSTREAM_DEBUG
28 #include "aom_util/debug_util.h"
29 #endif // CONFIG_BITSTREAM_DEBUG
39 uint8_t allow_update_cdf
;
42 typedef struct aom_writer aom_writer
;
44 typedef struct TOKEN_STATS
{
47 int txb_coeff_cost_map
[TXB_COEFF_COST_MAP_SIZE
][TXB_COEFF_COST_MAP_SIZE
];
51 static INLINE
void init_token_stats(TOKEN_STATS
*token_stats
) {
54 for (r
= 0; r
< TXB_COEFF_COST_MAP_SIZE
; ++r
) {
55 for (c
= 0; c
< TXB_COEFF_COST_MAP_SIZE
; ++c
) {
56 token_stats
->txb_coeff_cost_map
[r
][c
] = 0;
60 token_stats
->cost
= 0;
63 void aom_start_encode(aom_writer
*w
, uint8_t *buffer
);
65 int aom_stop_encode(aom_writer
*w
);
67 int aom_tell_size(aom_writer
*w
);
69 static INLINE
void aom_write(aom_writer
*w
, int bit
, int probability
) {
70 int p
= (0x7FFFFF - (probability
<< 15) + probability
) >> 8;
71 #if CONFIG_BITSTREAM_DEBUG
72 aom_cdf_prob cdf
[2] = { (aom_cdf_prob
)p
, 32767 };
73 bitstream_queue_push(bit
, cdf
, 2);
76 od_ec_encode_bool_q15(&w
->ec
, bit
, p
);
79 static INLINE
void aom_write_bit(aom_writer
*w
, int bit
) {
80 aom_write(w
, bit
, 128); // aom_prob_half
83 static INLINE
void aom_write_literal(aom_writer
*w
, int data
, int bits
) {
86 for (bit
= bits
- 1; bit
>= 0; bit
--) aom_write_bit(w
, 1 & (data
>> bit
));
89 static INLINE
void aom_write_cdf(aom_writer
*w
, int symb
,
90 const aom_cdf_prob
*cdf
, int nsymbs
) {
91 #if CONFIG_BITSTREAM_DEBUG
92 bitstream_queue_push(symb
, cdf
, nsymbs
);
95 od_ec_encode_cdf_q15(&w
->ec
, symb
, cdf
, nsymbs
);
98 static INLINE
void aom_write_symbol(aom_writer
*w
, int symb
, aom_cdf_prob
*cdf
,
100 aom_write_cdf(w
, symb
, cdf
, nsymbs
);
101 if (w
->allow_update_cdf
) update_cdf(cdf
, symb
, nsymbs
);
108 #endif // AOM_AOM_DSP_BITWRITER_H_