annotate vp56.h @ 3923:f5faf4b1b30e libavcodec

Also remove cpuid_test on clean.
author diego
date Tue, 03 Oct 2006 17:59:10 +0000
parents 64642d08db1b
children c8c591fe26f8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
1 /**
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
2 * @file vp56.h
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
3 * VP5 and VP6 compatible video decoder (common features)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
4 *
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
5 * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
6 *
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
7 * This library is free software; you can redistribute it and/or
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
11 *
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
12 * This library is distributed in the hope that it will be useful,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
15 * Lesser General Public License for more details.
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
16 *
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
18 * License along with this library; if not, write to the Free Software
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
20 */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
21
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
22 #ifndef VP56_H
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
23 #define VP56_H
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
24
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
25 #include <stdint.h>
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
26
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
27 #include "vp56data.h"
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
28 #include "dsputil.h"
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
29 #include "mpegvideo.h"
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
30
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
31
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
32 typedef struct vp56_context vp56_context_t;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
33 typedef struct vp56_mv vp56_mv_t;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
34
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
35 typedef void (*vp56_parse_vector_adjustment_t)(vp56_context_t *s,
3759
64642d08db1b rename vector to vect to avoid clash with Apple gcc
aurel
parents: 3695
diff changeset
36 vp56_mv_t *vect);
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
37 typedef int (*vp56_adjust_t)(int v, int t);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
38 typedef void (*vp56_filter_t)(vp56_context_t *s, uint8_t *dst, uint8_t *src,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
39 int offset1, int offset2, int stride,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
40 vp56_mv_t mv, int mask, int select, int luma);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
41 typedef void (*vp56_parse_coeff_t)(vp56_context_t *s);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
42 typedef void (*vp56_default_models_init_t)(vp56_context_t *s);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
43 typedef void (*vp56_parse_vector_models_t)(vp56_context_t *s);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
44 typedef void (*vp56_parse_coeff_models_t)(vp56_context_t *s);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
45 typedef int (*vp56_parse_header_t)(vp56_context_t *s, uint8_t *buf,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
46 int buf_size, int *golden_frame);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
47
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
48 typedef struct {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
49 int high;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
50 int bits;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
51 const uint8_t *buffer;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
52 unsigned long code_word;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
53 } vp56_range_coder_t;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
54
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
55 typedef struct {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
56 uint8_t not_null_dc;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
57 vp56_frame_t ref_frame;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
58 DCTELEM dc_coeff;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
59 } vp56_ref_dc_t;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
60
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
61 struct vp56_mv {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
62 int x;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
63 int y;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
64 };
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
65
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
66 typedef struct {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
67 uint8_t type;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
68 vp56_mv_t mv;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
69 } vp56_macroblock_t;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
70
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
71 struct vp56_context {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
72 AVCodecContext *avctx;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
73 DSPContext dsp;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
74 ScanTable scantable;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
75 AVFrame frames[3];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
76 uint8_t *edge_emu_buffer_alloc;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
77 uint8_t *edge_emu_buffer;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
78 vp56_range_coder_t c;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
79
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
80 /* frame info */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
81 int plane_width[3];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
82 int plane_height[3];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
83 int mb_width; /* number of horizontal MB */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
84 int mb_height; /* number of vertical MB */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
85 int block_offset[6];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
86
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
87 int quantizer;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
88 uint16_t dequant_dc;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
89 uint16_t dequant_ac;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
90
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
91 /* DC predictors management */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
92 vp56_ref_dc_t *above_blocks;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
93 vp56_ref_dc_t left_block[4];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
94 int above_block_idx[6];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
95 DCTELEM prev_dc[3][3]; /* [plan][ref_frame] */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
96
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
97 /* blocks / macroblock */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
98 vp56_mb_t mb_type;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
99 vp56_macroblock_t *macroblocks;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
100 DECLARE_ALIGNED_16(DCTELEM, block_coeff[6][64]);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
101 uint8_t coeff_reorder[64]; /* used in vp6 only */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
102 uint8_t coeff_index_to_pos[64]; /* used in vp6 only */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
103
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
104 /* motion vectors */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
105 vp56_mv_t mv[6]; /* vectors for each block in MB */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
106 vp56_mv_t vector_candidate[2];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
107 int vector_candidate_pos;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
108
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
109 /* filtering hints */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
110 int deblock_filtering;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
111 int filter_selection;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
112 int filter_mode;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
113 int max_vector_length;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
114 int sample_variance_threshold;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
115
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
116 /* AC models */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
117 uint8_t vector_model_sig[2]; /* delta sign */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
118 uint8_t vector_model_dct[2]; /* delta coding types */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
119 uint8_t vector_model_pdi[2][2]; /* predefined delta init */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
120 uint8_t vector_model_pdv[2][7]; /* predefined delta values */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
121 uint8_t vector_model_fdv[2][8]; /* 8 bit delta value definition */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
122 uint8_t mb_type_model[3][10][10]; /* model for decoding MB type */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
123 uint8_t coeff_model_dccv[2][11]; /* DC coeff value */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
124 uint8_t coeff_model_ract[2][3][6][11]; /* Run/AC coding type and AC coeff value */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
125 uint8_t coeff_model_acct[2][3][3][6][5];/* vp5 only AC coding type for coding group < 3 */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
126 uint8_t coeff_model_dcct[2][36][5]; /* DC coeff coding type */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
127 uint8_t coeff_model_runv[2][14]; /* run value (vp6 only) */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
128 uint8_t mb_types_stats[3][10][2]; /* contextual, next MB type stats */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
129 uint8_t coeff_ctx[4][64]; /* used in vp5 only */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
130 uint8_t coeff_ctx_last[4]; /* used in vp5 only */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
131
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
132 /* upside-down flipping hints */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
133 int flip; /* are we flipping ? */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
134 int frbi; /* first row block index in MB */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
135 int srbi; /* second row block index in MB */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
136 int stride[3]; /* stride for each plan */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
137
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
138 const uint8_t *vp56_coord_div;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
139 vp56_parse_vector_adjustment_t parse_vector_adjustment;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
140 vp56_adjust_t adjust;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
141 vp56_filter_t filter;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
142 vp56_parse_coeff_t parse_coeff;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
143 vp56_default_models_init_t default_models_init;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
144 vp56_parse_vector_models_t parse_vector_models;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
145 vp56_parse_coeff_models_t parse_coeff_models;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
146 vp56_parse_header_t parse_header;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
147 };
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
148
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
149
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
150 void vp56_init(vp56_context_t *s, AVCodecContext *avctx, int flip);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
151 int vp56_free(AVCodecContext *avctx);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
152 void vp56_init_dequant(vp56_context_t *s, int quantizer);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
153 int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
154 uint8_t *buf, int buf_size);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
155
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
156
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
157 /**
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
158 * vp56 specific range coder implementation
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
159 */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
160
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
161 static inline void vp56_init_range_decoder(vp56_range_coder_t *c,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
162 const uint8_t *buf, int buf_size)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
163 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
164 c->high = 255;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
165 c->bits = 8;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
166 c->buffer = buf;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
167 c->code_word = *c->buffer++ << 8;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
168 c->code_word |= *c->buffer++;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
169 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
170
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
171 static inline int vp56_rac_get_prob(vp56_range_coder_t *c, uint8_t prob)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
172 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
173 unsigned int low = 1 + (((c->high - 1) * prob) / 256);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
174 unsigned int low_shift = low << 8;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
175 int bit = c->code_word >= low_shift;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
176
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
177 if (bit) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
178 c->high -= low;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
179 c->code_word -= low_shift;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
180 } else {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
181 c->high = low;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
182 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
183
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
184 /* normalize */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
185 while (c->high < 128) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
186 c->high <<= 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
187 c->code_word <<= 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
188 if (--c->bits == 0) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
189 c->bits = 8;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
190 c->code_word |= *c->buffer++;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
191 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
192 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
193 return bit;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
194 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
195
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
196 static inline int vp56_rac_get(vp56_range_coder_t *c)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
197 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
198 /* equiprobable */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
199 int low = (c->high + 1) >> 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
200 unsigned int low_shift = low << 8;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
201 int bit = c->code_word >= low_shift;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
202 if (bit) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
203 c->high = (c->high - low) << 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
204 c->code_word -= low_shift;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
205 } else {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
206 c->high = low << 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
207 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
208
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
209 /* normalize */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
210 c->code_word <<= 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
211 if (--c->bits == 0) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
212 c->bits = 8;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
213 c->code_word |= *c->buffer++;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
214 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
215 return bit;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
216 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
217
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
218 static inline int vp56_rac_gets(vp56_range_coder_t *c, int bits)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
219 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
220 int value = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
221
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
222 while (bits--) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
223 value = (value << 1) | vp56_rac_get(c);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
224 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
225
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
226 return value;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
227 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
228
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
229 static inline int vp56_rac_gets_nn(vp56_range_coder_t *c, int bits)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
230 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
231 int v = vp56_rac_gets(c, 7) << 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
232 return v + !v;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
233 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
234
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
235 static inline int vp56_rac_get_tree(vp56_range_coder_t *c,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
236 const vp56_tree_t *tree,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
237 const uint8_t *probs)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
238 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
239 while (tree->val > 0) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
240 if (vp56_rac_get_prob(c, probs[tree->prob_idx]))
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
241 tree += tree->val;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
242 else
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
243 tree++;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
244 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
245 return -tree->val;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
246 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
247
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
248 #endif /* VP56_H */