annotate vp56.h @ 11273:a2cb557201bb libavcodec

Factorize common code from the top of decode_cabac_mb_mvd() 10-15 cpu cycles faster.
author michael
date Wed, 24 Feb 2010 18:06:02 +0000
parents c57e72227d7d
children 98970e51365a
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 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 8304
diff changeset
2 * @file libavcodec/vp56.h
3695
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 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3759
diff changeset
7 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3759
diff changeset
8 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3759
diff changeset
9 * FFmpeg is free software; you can redistribute it and/or
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
10 * modify it under the terms of the GNU Lesser General Public
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
11 * License as published by the Free Software Foundation; either
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
12 * version 2.1 of the License, or (at your option) any later version.
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
13 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3759
diff changeset
14 * FFmpeg is distributed in the hope that it will be useful,
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
17 * Lesser General Public License for more details.
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
18 *
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3759
diff changeset
20 * License along with FFmpeg; if not, write to the Free Software
5215
2b72f9bc4f06 license header consistency cosmetics
diego
parents: 5089
diff changeset
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
22 */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
23
7760
c4a4495715dd Globally rename the header inclusion guard names.
stefano
parents: 6448
diff changeset
24 #ifndef AVCODEC_VP56_H
c4a4495715dd Globally rename the header inclusion guard names.
stefano
parents: 6448
diff changeset
25 #define AVCODEC_VP56_H
3695
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"
9428
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents: 9356
diff changeset
29 #include "get_bits.h"
5089
bff60ecc02f9 Use AV_xx throughout libavcodec
ramiro
parents: 4595
diff changeset
30 #include "bytestream.h"
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
31
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
32
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
33 typedef struct vp56_context VP56Context;
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
34 typedef struct vp56_mv VP56mv;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
35
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
36 typedef void (*VP56ParseVectorAdjustment)(VP56Context *s,
8300
c47323828269 cosmetics: vertical alignment
aurel
parents: 8299
diff changeset
37 VP56mv *vect);
c47323828269 cosmetics: vertical alignment
aurel
parents: 8299
diff changeset
38 typedef int (*VP56Adjust)(int v, int t);
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
39 typedef void (*VP56Filter)(VP56Context *s, uint8_t *dst, uint8_t *src,
8300
c47323828269 cosmetics: vertical alignment
aurel
parents: 8299
diff changeset
40 int offset1, int offset2, int stride,
c47323828269 cosmetics: vertical alignment
aurel
parents: 8299
diff changeset
41 VP56mv mv, int mask, int select, int luma);
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
42 typedef void (*VP56ParseCoeff)(VP56Context *s);
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
43 typedef void (*VP56DefaultModelsInit)(VP56Context *s);
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
44 typedef void (*VP56ParseVectorModels)(VP56Context *s);
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
45 typedef void (*VP56ParseCoeffModels)(VP56Context *s);
8300
c47323828269 cosmetics: vertical alignment
aurel
parents: 8299
diff changeset
46 typedef int (*VP56ParseHeader)(VP56Context *s, const uint8_t *buf,
c47323828269 cosmetics: vertical alignment
aurel
parents: 8299
diff changeset
47 int buf_size, int *golden_frame);
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
48
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
49 typedef struct {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
50 int high;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
51 int bits;
6297
michael
parents: 5830
diff changeset
52 const uint8_t *buffer;
9919
c7c1c6b35a73 vp56dec: ensure range coder won't read past the end of input buffer
aurel
parents: 9428
diff changeset
53 const uint8_t *end;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
54 unsigned long code_word;
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
55 } VP56RangeCoder;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
56
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
57 typedef struct {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
58 uint8_t not_null_dc;
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
59 VP56Frame ref_frame;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
60 DCTELEM dc_coeff;
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
61 } VP56RefDc;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
62
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
63 struct vp56_mv {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
64 int x;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
65 int y;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
66 };
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
67
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
68 typedef struct {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
69 uint8_t type;
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
70 VP56mv mv;
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
71 } VP56Macroblock;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
72
5711
dae0f80edbb3 move all model related tables into their own struct
aurel
parents: 5708
diff changeset
73 typedef struct {
dae0f80edbb3 move all model related tables into their own struct
aurel
parents: 5708
diff changeset
74 uint8_t coeff_reorder[64]; /* used in vp6 only */
dae0f80edbb3 move all model related tables into their own struct
aurel
parents: 5708
diff changeset
75 uint8_t coeff_index_to_pos[64]; /* used in vp6 only */
dae0f80edbb3 move all model related tables into their own struct
aurel
parents: 5708
diff changeset
76 uint8_t vector_sig[2]; /* delta sign */
dae0f80edbb3 move all model related tables into their own struct
aurel
parents: 5708
diff changeset
77 uint8_t vector_dct[2]; /* delta coding types */
dae0f80edbb3 move all model related tables into their own struct
aurel
parents: 5708
diff changeset
78 uint8_t vector_pdi[2][2]; /* predefined delta init */
dae0f80edbb3 move all model related tables into their own struct
aurel
parents: 5708
diff changeset
79 uint8_t vector_pdv[2][7]; /* predefined delta values */
dae0f80edbb3 move all model related tables into their own struct
aurel
parents: 5708
diff changeset
80 uint8_t vector_fdv[2][8]; /* 8 bit delta value definition */
dae0f80edbb3 move all model related tables into their own struct
aurel
parents: 5708
diff changeset
81 uint8_t coeff_dccv[2][11]; /* DC coeff value */
dae0f80edbb3 move all model related tables into their own struct
aurel
parents: 5708
diff changeset
82 uint8_t coeff_ract[2][3][6][11]; /* Run/AC coding type and AC coeff value */
dae0f80edbb3 move all model related tables into their own struct
aurel
parents: 5708
diff changeset
83 uint8_t coeff_acct[2][3][3][6][5];/* vp5 only AC coding type for coding group < 3 */
dae0f80edbb3 move all model related tables into their own struct
aurel
parents: 5708
diff changeset
84 uint8_t coeff_dcct[2][36][5]; /* DC coeff coding type */
dae0f80edbb3 move all model related tables into their own struct
aurel
parents: 5708
diff changeset
85 uint8_t coeff_runv[2][14]; /* run value (vp6 only) */
dae0f80edbb3 move all model related tables into their own struct
aurel
parents: 5708
diff changeset
86 uint8_t mb_type[3][10][10]; /* model for decoding MB type */
dae0f80edbb3 move all model related tables into their own struct
aurel
parents: 5708
diff changeset
87 uint8_t mb_types_stats[3][10][2];/* contextual, next MB type stats */
8304
3cddc18caeca rename Vp56Model to VP56Model for consistency
aurel
parents: 8300
diff changeset
88 } VP56Model;
5711
dae0f80edbb3 move all model related tables into their own struct
aurel
parents: 5708
diff changeset
89
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
90 struct vp56_context {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
91 AVCodecContext *avctx;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
92 DSPContext dsp;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
93 ScanTable scantable;
5714
314be1cfdcb0 add a new vp6a codec (add alpha plan support to vp6)
aurel
parents: 5711
diff changeset
94 AVFrame frames[4];
314be1cfdcb0 add a new vp6a codec (add alpha plan support to vp6)
aurel
parents: 5711
diff changeset
95 AVFrame *framep[6];
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
96 uint8_t *edge_emu_buffer_alloc;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
97 uint8_t *edge_emu_buffer;
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
98 VP56RangeCoder c;
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
99 VP56RangeCoder cc;
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
100 VP56RangeCoder *ccp;
4308
74b476185cd1 Add support for VP60 and VP61.
aurel
parents: 4078
diff changeset
101 int sub_version;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
102
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
103 /* frame info */
5714
314be1cfdcb0 add a new vp6a codec (add alpha plan support to vp6)
aurel
parents: 5711
diff changeset
104 int plane_width[4];
314be1cfdcb0 add a new vp6a codec (add alpha plan support to vp6)
aurel
parents: 5711
diff changeset
105 int plane_height[4];
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
106 int mb_width; /* number of horizontal MB */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
107 int mb_height; /* number of vertical MB */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
108 int block_offset[6];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
109
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
110 int quantizer;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
111 uint16_t dequant_dc;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
112 uint16_t dequant_ac;
11053
c57e72227d7d Make VP5 and VP6 decoders output a qscale table to allow for more automatic
reimar
parents: 10961
diff changeset
113 int8_t *qscale_table;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
114
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
115 /* DC predictors management */
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
116 VP56RefDc *above_blocks;
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
117 VP56RefDc left_block[4];
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
118 int above_block_idx[6];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
119 DCTELEM prev_dc[3][3]; /* [plan][ref_frame] */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
120
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
121 /* blocks / macroblock */
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
122 VP56mb mb_type;
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
123 VP56Macroblock *macroblocks;
10961
34a65026fa06 Move array specifiers outside DECLARE_ALIGNED() invocations
mru
parents: 9919
diff changeset
124 DECLARE_ALIGNED_16(DCTELEM, block_coeff)[6][64];
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
125
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
126 /* motion vectors */
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
127 VP56mv mv[6]; /* vectors for each block in MB */
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
128 VP56mv vector_candidate[2];
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
129 int vector_candidate_pos;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
130
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
131 /* filtering hints */
4348
d3dcf62d52c5 add support for another variant of vp6
aurel
parents: 4308
diff changeset
132 int filter_header; /* used in vp6 only */
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
133 int deblock_filtering;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
134 int filter_selection;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
135 int filter_mode;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
136 int max_vector_length;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
137 int sample_variance_threshold;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
138
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
139 uint8_t coeff_ctx[4][64]; /* used in vp5 only */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
140 uint8_t coeff_ctx_last[4]; /* used in vp5 only */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
141
5714
314be1cfdcb0 add a new vp6a codec (add alpha plan support to vp6)
aurel
parents: 5711
diff changeset
142 int has_alpha;
314be1cfdcb0 add a new vp6a codec (add alpha plan support to vp6)
aurel
parents: 5711
diff changeset
143
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
144 /* upside-down flipping hints */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
145 int flip; /* are we flipping ? */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
146 int frbi; /* first row block index in MB */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
147 int srbi; /* second row block index in MB */
5714
314be1cfdcb0 add a new vp6a codec (add alpha plan support to vp6)
aurel
parents: 5711
diff changeset
148 int stride[4]; /* stride for each plan */
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
149
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
150 const uint8_t *vp56_coord_div;
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
151 VP56ParseVectorAdjustment parse_vector_adjustment;
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
152 VP56Adjust adjust;
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
153 VP56Filter filter;
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
154 VP56ParseCoeff parse_coeff;
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
155 VP56DefaultModelsInit default_models_init;
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
156 VP56ParseVectorModels parse_vector_models;
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
157 VP56ParseCoeffModels parse_coeff_models;
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
158 VP56ParseHeader parse_header;
5711
dae0f80edbb3 move all model related tables into their own struct
aurel
parents: 5708
diff changeset
159
8304
3cddc18caeca rename Vp56Model to VP56Model for consistency
aurel
parents: 8300
diff changeset
160 VP56Model *modelp;
3cddc18caeca rename Vp56Model to VP56Model for consistency
aurel
parents: 8300
diff changeset
161 VP56Model models[2];
5821
51918cb97f6f add support for VP6 with huffman encoded blocks
aurel
parents: 5714
diff changeset
162
51918cb97f6f add support for VP6 with huffman encoded blocks
aurel
parents: 5714
diff changeset
163 /* huffman decoding */
51918cb97f6f add support for VP6 with huffman encoded blocks
aurel
parents: 5714
diff changeset
164 int use_huffman;
51918cb97f6f add support for VP6 with huffman encoded blocks
aurel
parents: 5714
diff changeset
165 GetBitContext gb;
51918cb97f6f add support for VP6 with huffman encoded blocks
aurel
parents: 5714
diff changeset
166 VLC dccv_vlc[2];
51918cb97f6f add support for VP6 with huffman encoded blocks
aurel
parents: 5714
diff changeset
167 VLC runv_vlc[2];
51918cb97f6f add support for VP6 with huffman encoded blocks
aurel
parents: 5714
diff changeset
168 VLC ract_vlc[2][3][6];
51918cb97f6f add support for VP6 with huffman encoded blocks
aurel
parents: 5714
diff changeset
169 unsigned int nb_null[2][2]; /* number of consecutive NULL DC/AC */
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
170 };
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
171
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
172
5714
314be1cfdcb0 add a new vp6a codec (add alpha plan support to vp6)
aurel
parents: 5711
diff changeset
173 void vp56_init(AVCodecContext *avctx, int flip, int has_alpha);
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
174 int vp56_free(AVCodecContext *avctx);
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
175 void vp56_init_dequant(VP56Context *s, int quantizer);
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
176 int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
9356
2983bd7deaf5 fix vp5/vp6 decoding by using new prototype for decode function
aurel
parents: 8718
diff changeset
177 AVPacket *avpkt);
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
178
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
179
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
180 /**
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
181 * vp56 specific range coder implementation
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
182 */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
183
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
184 static inline void vp56_init_range_decoder(VP56RangeCoder *c,
6297
michael
parents: 5830
diff changeset
185 const uint8_t *buf, int buf_size)
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
186 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
187 c->high = 255;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
188 c->bits = 8;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
189 c->buffer = buf;
9919
c7c1c6b35a73 vp56dec: ensure range coder won't read past the end of input buffer
aurel
parents: 9428
diff changeset
190 c->end = buf + buf_size;
5089
bff60ecc02f9 Use AV_xx throughout libavcodec
ramiro
parents: 4595
diff changeset
191 c->code_word = bytestream_get_be16(&c->buffer);
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
192 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
193
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
194 static inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob)
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
195 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
196 unsigned int low = 1 + (((c->high - 1) * prob) / 256);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
197 unsigned int low_shift = low << 8;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
198 int bit = c->code_word >= low_shift;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
199
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
200 if (bit) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
201 c->high -= low;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
202 c->code_word -= low_shift;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
203 } else {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
204 c->high = low;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
205 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
206
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
207 /* normalize */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
208 while (c->high < 128) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
209 c->high <<= 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
210 c->code_word <<= 1;
9919
c7c1c6b35a73 vp56dec: ensure range coder won't read past the end of input buffer
aurel
parents: 9428
diff changeset
211 if (--c->bits == 0 && c->buffer < c->end) {
3695
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 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
216 return bit;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
217 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
218
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
219 static inline int vp56_rac_get(VP56RangeCoder *c)
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
220 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
221 /* equiprobable */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
222 int low = (c->high + 1) >> 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
223 unsigned int low_shift = low << 8;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
224 int bit = c->code_word >= low_shift;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
225 if (bit) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
226 c->high = (c->high - low) << 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
227 c->code_word -= low_shift;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
228 } else {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
229 c->high = low << 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
230 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
231
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
232 /* normalize */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
233 c->code_word <<= 1;
9919
c7c1c6b35a73 vp56dec: ensure range coder won't read past the end of input buffer
aurel
parents: 9428
diff changeset
234 if (--c->bits == 0 && c->buffer < c->end) {
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
235 c->bits = 8;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
236 c->code_word |= *c->buffer++;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
237 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
238 return bit;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
239 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
240
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
241 static inline int vp56_rac_gets(VP56RangeCoder *c, int bits)
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
242 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
243 int value = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
244
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
245 while (bits--) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
246 value = (value << 1) | vp56_rac_get(c);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
247 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
248
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
249 return value;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
250 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
251
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
252 static inline int vp56_rac_gets_nn(VP56RangeCoder *c, int bits)
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
253 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
254 int v = vp56_rac_gets(c, 7) << 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
255 return v + !v;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
256 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
257
8299
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
258 static inline int vp56_rac_get_tree(VP56RangeCoder *c,
524cb7f5ad2b avoid POSIX reserved _t suffix
aurel
parents: 7760
diff changeset
259 const VP56Tree *tree,
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
260 const uint8_t *probs)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
261 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
262 while (tree->val > 0) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
263 if (vp56_rac_get_prob(c, probs[tree->prob_idx]))
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
264 tree += tree->val;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
265 else
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
266 tree++;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
267 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
268 return -tree->val;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
269 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
270
7760
c4a4495715dd Globally rename the header inclusion guard names.
stefano
parents: 6448
diff changeset
271 #endif /* AVCODEC_VP56_H */