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_BITWRITER_H_ 13 #define AOM_AOM_DSP_BITWRITER_H_ 14 15 #include <assert.h> 16 17 #include "config/aom_config.h" 18 19 #include "aom_dsp/daalaboolwriter.h" 20 #include "aom_dsp/prob.h" 21 22 #if CONFIG_RD_DEBUG 23 #include "av1/common/blockd.h" 24 #include "av1/encoder/cost.h" 25 #endif 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 typedef struct daala_writer aom_writer; 32 33 typedef struct TOKEN_STATS { 34 int cost; 35 #if CONFIG_RD_DEBUG 36 int txb_coeff_cost_map[TXB_COEFF_COST_MAP_SIZE][TXB_COEFF_COST_MAP_SIZE]; 37 #endif 38 } TOKEN_STATS; 39 40 static INLINE void init_token_stats(TOKEN_STATS *token_stats) { 41 #if CONFIG_RD_DEBUG 42 int r, c; 43 for (r = 0; r < TXB_COEFF_COST_MAP_SIZE; ++r) { 44 for (c = 0; c < TXB_COEFF_COST_MAP_SIZE; ++c) { 45 token_stats->txb_coeff_cost_map[r][c] = 0; 46 } 47 } 48 #endif 49 token_stats->cost = 0; 50 } 51 52 static INLINE void aom_start_encode(aom_writer *bc, uint8_t *buffer) { 53 aom_daala_start_encode(bc, buffer); 54 } 55 56 static INLINE int aom_stop_encode(aom_writer *bc) { 57 return aom_daala_stop_encode(bc); 58 } 59 60 static INLINE void aom_write(aom_writer *br, int bit, int probability) { 61 aom_daala_write(br, bit, probability); 62 } 63 64 static INLINE void aom_write_bit(aom_writer *w, int bit) { 65 aom_write(w, bit, 128); // aom_prob_half 66 } 67 68 static INLINE void aom_write_literal(aom_writer *w, int data, int bits) { 69 int bit; 70 71 for (bit = bits - 1; bit >= 0; bit--) aom_write_bit(w, 1 & (data >> bit)); 72 } 73 74 static INLINE void aom_write_cdf(aom_writer *w, int symb, 75 const aom_cdf_prob *cdf, int nsymbs) { 76 daala_write_symbol(w, symb, cdf, nsymbs); 77 } 78 79 static INLINE void aom_write_symbol(aom_writer *w, int symb, aom_cdf_prob *cdf, 80 int nsymbs) { 81 aom_write_cdf(w, symb, cdf, nsymbs); 82 if (w->allow_update_cdf) update_cdf(cdf, symb, nsymbs); 83 } 84 85 #ifdef __cplusplus 86 } // extern "C" 87 #endif 88 89 #endif // AOM_AOM_DSP_BITWRITER_H_ 90