• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DAALABOOLWRITER_H_
13 #define AOM_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   uint8_t allow_update_cdf;
32 };
33 
34 typedef struct daala_writer daala_writer;
35 
36 void aom_daala_start_encode(daala_writer *w, uint8_t *buffer);
37 int aom_daala_stop_encode(daala_writer *w);
38 
aom_daala_write(daala_writer * w,int bit,int prob)39 static INLINE void aom_daala_write(daala_writer *w, int bit, int prob) {
40   int p = (0x7FFFFF - (prob << 15) + prob) >> 8;
41 #if CONFIG_BITSTREAM_DEBUG
42   aom_cdf_prob cdf[2] = { (aom_cdf_prob)p, 32767 };
43   /*int queue_r = 0;
44   int frame_idx_r = 0;
45   int queue_w = bitstream_queue_get_write();
46   int frame_idx_w = bitstream_queue_get_frame_write();
47   if (frame_idx_w == frame_idx_r && queue_w == queue_r) {
48     fprintf(stderr, "\n *** bitstream queue at frame_idx_w %d queue_w %d\n",
49     frame_idx_w, queue_w);
50   }*/
51   bitstream_queue_push(bit, cdf, 2);
52 #endif
53 
54   od_ec_encode_bool_q15(&w->ec, bit, p);
55 }
56 
daala_write_symbol(daala_writer * w,int symb,const aom_cdf_prob * cdf,int nsymbs)57 static INLINE void daala_write_symbol(daala_writer *w, int symb,
58                                       const aom_cdf_prob *cdf, int nsymbs) {
59 #if CONFIG_BITSTREAM_DEBUG
60   /*int queue_r = 0;
61   int frame_idx_r = 0;
62   int queue_w = bitstream_queue_get_write();
63   int frame_idx_w = bitstream_queue_get_frame_write();
64   if (frame_idx_w == frame_idx_r && queue_w == queue_r) {
65     fprintf(stderr, "\n *** bitstream queue at frame_idx_w %d queue_w %d\n",
66     frame_idx_w, queue_w);
67   }*/
68   bitstream_queue_push(symb, cdf, nsymbs);
69 #endif
70 
71   od_ec_encode_cdf_q15(&w->ec, symb, cdf, nsymbs);
72 }
73 
74 #ifdef __cplusplus
75 }  // extern "C"
76 #endif
77 
78 #endif  // AOM_AOM_DSP_DAALABOOLWRITER_H_
79