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_DSP_DAALABOOLWRITER_H_
13 #define AOM_DSP_DAALABOOLWRITER_H_
14
15 #include <stdio.h>
16
17 #include "aom_dsp/entenc.h"
18 #include "aom_dsp/prob.h"
19 #if CONFIG_BITSTREAM_DEBUG
20 #include "aom_util/debug_util.h"
21 #endif // CONFIG_BITSTREAM_DEBUG
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 struct daala_writer {
28 unsigned int pos;
29 uint8_t *buffer;
30 od_ec_enc ec;
31 };
32
33 typedef struct daala_writer daala_writer;
34
35 void aom_daala_start_encode(daala_writer *w, uint8_t *buffer);
36 void aom_daala_stop_encode(daala_writer *w);
37
aom_daala_write(daala_writer * w,int bit,int prob)38 static INLINE void aom_daala_write(daala_writer *w, int bit, int prob) {
39 int p = (0x7FFFFF - (prob << 15) + prob) >> 8;
40 #if CONFIG_BITSTREAM_DEBUG
41 aom_cdf_prob cdf[2] = { (aom_cdf_prob)p, 32767 };
42 /*int queue_r = 0;
43 int frame_idx_r = 0;
44 int queue_w = bitstream_queue_get_write();
45 int frame_idx_w = bitstream_queue_get_frame_write();
46 if (frame_idx_w == frame_idx_r && queue_w == queue_r) {
47 fprintf(stderr, "\n *** bitstream queue at frame_idx_w %d queue_w %d\n",
48 frame_idx_w, queue_w);
49 }*/
50 bitstream_queue_push(bit, cdf, 2);
51 #endif
52
53 od_ec_encode_bool_q15(&w->ec, bit, p);
54 }
55
56 #if CONFIG_RAWBITS
aom_daala_write_bit(daala_writer * w,int bit)57 static INLINE void aom_daala_write_bit(daala_writer *w, int bit) {
58 od_ec_enc_bits(&w->ec, bit, 1);
59 }
60 #endif
61
daala_write_symbol(daala_writer * w,int symb,const aom_cdf_prob * cdf,int nsymbs)62 static INLINE void daala_write_symbol(daala_writer *w, int symb,
63 const aom_cdf_prob *cdf, int nsymbs) {
64 #if CONFIG_BITSTREAM_DEBUG
65 /*int queue_r = 0;
66 int frame_idx_r = 0;
67 int queue_w = bitstream_queue_get_write();
68 int frame_idx_w = bitstream_queue_get_frame_write();
69 if (frame_idx_w == frame_idx_r && queue_w == queue_r) {
70 fprintf(stderr, "\n *** bitstream queue at frame_idx_w %d queue_w %d\n",
71 frame_idx_w, queue_w);
72 }*/
73 bitstream_queue_push(symb, cdf, nsymbs);
74 #endif
75
76 od_ec_encode_cdf_q15(&w->ec, symb, cdf, nsymbs);
77 }
78
79 #ifdef __cplusplus
80 } // extern "C"
81 #endif
82
83 #endif
84