1 /*
2 * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * VP5 compatible video decoder
24 */
25
26 #include <stdlib.h>
27 #include <string.h>
28
32
36
37
39 {
41 int rows, cols;
42
48 {
56 }
57 rows =
vp56_rac_gets(c, 8);
/* number of stored macroblock rows */
58 cols =
vp56_rac_gets(c, 8);
/* number of stored macroblock cols */
59 if (!rows || !cols) {
61 cols << 4, rows << 4);
63 }
64 vp56_rac_gets(c, 8);
/* number of displayed macroblock rows */
65 vp56_rac_gets(c, 8);
/* number of displayed macroblock cols */
67 if (!s->macroblocks || /* first frame */
68 16*cols != s->avctx->coded_width ||
69 16*rows != s->avctx->coded_height) {
71 if (ret < 0)
72 return ret;
74 }
75 } else if (!s->macroblocks)
77 return 0;
78 }
79
81 {
85
86 for (comp=0; comp<2; comp++) {
94 delta = di | (delta << 2);
95 delta = (delta ^ -sign) + sign;
96 }
97 if (!comp)
99 else
101 }
102 }
103
105 {
109
110 for (comp=0; comp<2; comp++) {
119 }
120
121 for (comp=0; comp<2; comp++)
122 for (node=0; node<7; node++)
125 }
126
128 {
133 int ct; /* code type */
134 int pt;
/* plane type (0 for Y, 1 for U or V) */
135
136 memset(def_prob, 0x80, sizeof(def_prob));
137
138 for (pt=0; pt<2; pt++)
139 for (node=0; node<11; node++)
145 }
146
147 for (ct=0; ct<3; ct++)
148 for (pt=0; pt<2; pt++)
149 for (cg=0; cg<6; cg++)
150 for (node=0; node<11; node++)
156 }
157
158 /* coeff_dcct is a linear combination of coeff_dccv */
159 for (pt=0; pt<2; pt++)
160 for (ctx=0; ctx<36; ctx++)
161 for (node=0; node<5; node++)
163
164 /* coeff_acct is a linear combination of coeff_ract */
165 for (ct=0; ct<3; ct++)
166 for (pt=0; pt<2; pt++)
167 for (cg=0; cg<3; cg++)
168 for (ctx=0; ctx<6; ctx++)
169 for (node=0; node<5; node++)
171 return 0;
172 }
173
175 {
180 int coeff, sign, coeff_idx;
181 int b, i, cg, idx,
ctx, ctx_last;
182 int pt = 0;
/* plane type (0 for Y, 1 for U or V) */
183
184 for (b=0; b<6; b++) {
185 int ct = 1; /* code type */
186
187 if (b > 3) pt = 1;
188
190 + s->above_blocks[s->above_block_idx[
b]].not_null_dc;
193
194 coeff_idx = 0;
195 for (;;) {
205 } else {
209 } else {
210 coeff = 2;
212 }
214 }
215 ct = 2;
216 } else {
217 ct = 1;
220 coeff = 1;
221 }
222 coeff = (coeff ^ -sign) + sign;
223 if (coeff_idx)
224 coeff *= s->dequant_ac;
225 s->block_coeff[
b][permute[coeff_idx]] =
coeff;
226 } else {
228 break;
229 ct = 0;
231 }
232 coeff_idx++;
233 if (coeff_idx >= 64)
234 break;
235
240 }
241
244 if (coeff_idx < ctx_last)
245 for (i=coeff_idx; i<=ctx_last; i++)
247 s->above_blocks[s->above_block_idx[b]].not_null_dc = s->coeff_ctx[
ff_vp56_b6to4[b]][0];
248 }
249 }
250
252 {
254 int i;
255
256 for (i=0; i<2; i++) {
261 }
264 }
265
267 {
269 int ret;
270
272 return ret;
280
281 return 0;
282 }
283
289 .priv_data_size = sizeof(VP56Context),
294 };
av_cold int ff_vp56_free(AVCodecContext *avctx)
uint8_t coeff_ract[2][3][6][11]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
VP5 and VP6 compatible video decoder (common features)
static av_cold int vp5_decode_init(AVCodecContext *avctx)
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
const uint8_t ff_vp56_coeff_bias[]
uint8_t coeff_dccv[2][11]
static av_cold int init(AVCodecContext *avctx)
uint8_t mb_types_stats[3][10][2]
static int vp5_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
static const uint8_t vp5_coord_div[]
static int vp5_parse_coeff_models(VP56Context *s)
VP5 compatible video decoder.
static void vp5_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
av_cold int ff_vp56_init(AVCodecContext *avctx, int flip, int has_alpha)
static const uint8_t vp5_ract_pct[3][2][6][11]
static void permute(int16_t dst[64], const int16_t src[64], enum idct_permutation_type perm_type)
bitstream reader API header.
static av_always_inline int vp56_rac_get_tree(VP56RangeCoder *c, const VP56Tree *tree, const uint8_t *probs)
static const uint8_t vp5_dccv_pct[2][11]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void vp5_parse_vector_models(VP56Context *s)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_always_inline int vp56_rac_get(VP56RangeCoder *c)
const char * name
Name of the codec implementation.
void ff_vp56_init_dequant(VP56Context *s, int quantizer)
const uint8_t ff_vp56_b6to4[]
VP5 and VP6 compatible video decoder (common data)
static av_unused int vp56_rac_gets_nn(VP56RangeCoder *c, int bits)
static const int16_t vp5_ract_lc[3][3][5][6][2]
int ff_vp56_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
const uint8_t ff_vp56_coeff_bit_length[]
#define vp56_rac_get_prob
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static const int16_t vp5_dccv_lc[5][36][2]
static av_always_inline int vp56_rac_get_prob_branchy(VP56RangeCoder *c, int prob)
Libavcodec external API header.
const VP56Tree ff_vp56_pc_tree[]
main external API structure.
const uint8_t ff_vp56_coeff_parse_table[6][11]
uint8_t coeff_dcct[2][36][5]
void ff_vp56_init_range_decoder(VP56RangeCoder *c, const uint8_t *buf, int buf_size)
uint8_t coeff_acct[2][3][3][6][5]
static const uint8_t vp5_vmc_pct[2][11]
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
const VP56Tree ff_vp56_pva_tree[]
static void vp5_parse_coeff(VP56Context *s)
common internal api header.
static void vp5_default_models_init(VP56Context *s)
static const double coeff[2][5]
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
static const uint8_t vp5_coeff_groups[]
const uint8_t ff_vp56_def_mb_types_stats[3][10][2]
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static int vp56_rac_gets(VP56RangeCoder *c, int bits)