annotate vp56.c @ 4254:bd7f921813b1 libavcodec

Unused variable removed
author lu_zero
date Sat, 02 Dec 2006 01:28:21 +0000
parents e5d148036c87
children 3b1815b57b6d
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.c
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: 3715
diff changeset
7 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3715
diff changeset
8 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3715
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: 3715
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: 3715
diff changeset
20 * License along with FFmpeg; if not, write to the Free Software
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
22 */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
23
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
24 #include "avcodec.h"
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
25
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
26 #include "vp56.h"
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
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
29
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
30 void vp56_init_dequant(vp56_context_t *s, int quantizer)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
31 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
32 s->quantizer = quantizer;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
33 s->dequant_dc = vp56_dc_dequant[quantizer] << 2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
34 s->dequant_ac = vp56_ac_dequant[quantizer] << 2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
35 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
36
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
37 static int vp56_get_vectors_predictors(vp56_context_t *s, int row, int col,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
38 vp56_frame_t ref_frame)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
39 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
40 int nb_pred = 0;
3697
596e62da8f29 rename vector to vect to avoid clash with Apple gcc
aurel
parents: 3695
diff changeset
41 vp56_mv_t vect[2] = {{0,0}, {0,0}};
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
42 int pos, offset;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
43 vp56_mv_t mvp;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
44
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
45 for (pos=0; pos<12; pos++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
46 mvp.x = col + vp56_candidate_predictor_pos[pos][0];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
47 mvp.y = row + vp56_candidate_predictor_pos[pos][1];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
48 if (mvp.x < 0 || mvp.x >= s->mb_width ||
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
49 mvp.y < 0 || mvp.y >= s->mb_height)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
50 continue;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
51 offset = mvp.x + s->mb_width*mvp.y;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
52
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
53 if (vp56_reference_frame[s->macroblocks[offset].type] != ref_frame)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
54 continue;
3697
596e62da8f29 rename vector to vect to avoid clash with Apple gcc
aurel
parents: 3695
diff changeset
55 if ((s->macroblocks[offset].mv.x == vect[0].x &&
596e62da8f29 rename vector to vect to avoid clash with Apple gcc
aurel
parents: 3695
diff changeset
56 s->macroblocks[offset].mv.y == vect[0].y) ||
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
57 (s->macroblocks[offset].mv.x == 0 &&
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
58 s->macroblocks[offset].mv.y == 0))
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
59 continue;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
60
3697
596e62da8f29 rename vector to vect to avoid clash with Apple gcc
aurel
parents: 3695
diff changeset
61 vect[nb_pred++] = s->macroblocks[offset].mv;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
62 if (nb_pred > 1) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
63 nb_pred = -1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
64 break;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
65 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
66 s->vector_candidate_pos = pos;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
67 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
68
3697
596e62da8f29 rename vector to vect to avoid clash with Apple gcc
aurel
parents: 3695
diff changeset
69 s->vector_candidate[0] = vect[0];
596e62da8f29 rename vector to vect to avoid clash with Apple gcc
aurel
parents: 3695
diff changeset
70 s->vector_candidate[1] = vect[1];
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
71
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
72 return nb_pred+1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
73 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
74
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
75 static void vp56_parse_mb_type_models(vp56_context_t *s)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
76 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
77 vp56_range_coder_t *c = &s->c;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
78 int i, ctx, type;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
79
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
80 for (ctx=0; ctx<3; ctx++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
81 if (vp56_rac_get_prob(c, 174)) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
82 int idx = vp56_rac_gets(c, 4);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
83 memcpy(s->mb_types_stats[ctx],vp56_pre_def_mb_type_stats[idx][ctx],
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
84 sizeof(s->mb_types_stats[ctx]));
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
85 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
86 if (vp56_rac_get_prob(c, 254)) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
87 for (type=0; type<10; type++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
88 for(i=0; i<2; i++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
89 if (vp56_rac_get_prob(c, 205)) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
90 int delta, sign = vp56_rac_get(c);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
91
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
92 delta = vp56_rac_get_tree(c, vp56_pmbtm_tree,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
93 vp56_mb_type_model_model);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
94 if (!delta)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
95 delta = 4 * vp56_rac_gets(c, 7);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
96 s->mb_types_stats[ctx][type][i] += (delta ^ -sign) + sign;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
97 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
98 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
99 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
100 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
101 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
102
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
103 /* compute MB type probability tables based on previous MB type */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
104 for (ctx=0; ctx<3; ctx++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
105 int p[10];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
106
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
107 for (type=0; type<10; type++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
108 p[type] = 100 * s->mb_types_stats[ctx][type][1];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
109
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
110 for (type=0; type<10; type++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
111 int p02, p34, p0234, p17, p56, p89, p5689, p156789;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
112
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
113 /* conservative MB type probability */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
114 s->mb_type_model[ctx][type][0] = 255 - (255 * s->mb_types_stats[ctx][type][0]) / (1 + s->mb_types_stats[ctx][type][0] + s->mb_types_stats[ctx][type][1]);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
115
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
116 p[type] = 0; /* same MB type => weight is null */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
117
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
118 /* binary tree parsing probabilities */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
119 p02 = p[0] + p[2];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
120 p34 = p[3] + p[4];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
121 p0234 = p02 + p34;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
122 p17 = p[1] + p[7];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
123 p56 = p[5] + p[6];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
124 p89 = p[8] + p[9];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
125 p5689 = p56 + p89;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
126 p156789 = p17 + p5689;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
127
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
128 s->mb_type_model[ctx][type][1] = 1 + 255 * p0234/(1+p0234+p156789);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
129 s->mb_type_model[ctx][type][2] = 1 + 255 * p02 / (1+p0234);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
130 s->mb_type_model[ctx][type][3] = 1 + 255 * p17 / (1+p156789);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
131 s->mb_type_model[ctx][type][4] = 1 + 255 * p[0] / (1+p02);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
132 s->mb_type_model[ctx][type][5] = 1 + 255 * p[3] / (1+p34);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
133 s->mb_type_model[ctx][type][6] = 1 + 255 * p[1] / (1+p17);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
134 s->mb_type_model[ctx][type][7] = 1 + 255 * p56 / (1+p5689);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
135 s->mb_type_model[ctx][type][8] = 1 + 255 * p[5] / (1+p56);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
136 s->mb_type_model[ctx][type][9] = 1 + 255 * p[8] / (1+p89);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
137
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
138 /* restore initial value */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
139 p[type] = 100 * s->mb_types_stats[ctx][type][1];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
140 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
141 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
142 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
143
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
144 static vp56_mb_t vp56_parse_mb_type(vp56_context_t *s,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
145 vp56_mb_t prev_type, int ctx)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
146 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
147 uint8_t *mb_type_model = s->mb_type_model[ctx][prev_type];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
148 vp56_range_coder_t *c = &s->c;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
149
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
150 if (vp56_rac_get_prob(c, mb_type_model[0]))
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
151 return prev_type;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
152 else
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
153 return vp56_rac_get_tree(c, vp56_pmbt_tree, mb_type_model);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
154 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
155
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
156 static void vp56_decode_4mv(vp56_context_t *s, int row, int col)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
157 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
158 vp56_mv_t mv = {0,0};
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
159 int type[4];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
160 int b;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
161
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
162 /* parse each block type */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
163 for (b=0; b<4; b++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
164 type[b] = vp56_rac_gets(&s->c, 2);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
165 if (type[b])
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
166 type[b]++; /* only returns 0, 2, 3 or 4 (all INTER_PF) */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
167 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
168
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
169 /* get vectors */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
170 for (b=0; b<4; b++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
171 switch (type[b]) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
172 case VP56_MB_INTER_NOVEC_PF:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
173 s->mv[b] = (vp56_mv_t) {0,0};
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
174 break;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
175 case VP56_MB_INTER_DELTA_PF:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
176 s->parse_vector_adjustment(s, &s->mv[b]);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
177 break;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
178 case VP56_MB_INTER_V1_PF:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
179 s->mv[b] = s->vector_candidate[0];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
180 break;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
181 case VP56_MB_INTER_V2_PF:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
182 s->mv[b] = s->vector_candidate[1];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
183 break;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
184 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
185 mv.x += s->mv[b].x;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
186 mv.y += s->mv[b].y;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
187 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
188
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
189 /* this is the one selected for the whole MB for prediction */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
190 s->macroblocks[row * s->mb_width + col].mv = s->mv[3];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
191
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
192 /* chroma vectors are average luma vectors */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
193 if (s->avctx->codec->id == CODEC_ID_VP5) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
194 s->mv[4].x = s->mv[5].x = RSHIFT(mv.x,2);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
195 s->mv[4].y = s->mv[5].y = RSHIFT(mv.y,2);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
196 } else {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
197 s->mv[4] = s->mv[5] = (vp56_mv_t) {mv.x/4, mv.y/4};
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
198 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
199 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
200
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
201 static vp56_mb_t vp56_decode_mv(vp56_context_t *s, int row, int col)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
202 {
3697
596e62da8f29 rename vector to vect to avoid clash with Apple gcc
aurel
parents: 3695
diff changeset
203 vp56_mv_t *mv, vect = {0,0};
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
204 int ctx, b;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
205
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
206 ctx = vp56_get_vectors_predictors(s, row, col, VP56_FRAME_PREVIOUS);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
207 s->mb_type = vp56_parse_mb_type(s, s->mb_type, ctx);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
208 s->macroblocks[row * s->mb_width + col].type = s->mb_type;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
209
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
210 switch (s->mb_type) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
211 case VP56_MB_INTER_V1_PF:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
212 mv = &s->vector_candidate[0];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
213 break;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
214
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
215 case VP56_MB_INTER_V2_PF:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
216 mv = &s->vector_candidate[1];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
217 break;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
218
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
219 case VP56_MB_INTER_V1_GF:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
220 vp56_get_vectors_predictors(s, row, col, VP56_FRAME_GOLDEN);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
221 mv = &s->vector_candidate[0];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
222 break;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
223
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
224 case VP56_MB_INTER_V2_GF:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
225 vp56_get_vectors_predictors(s, row, col, VP56_FRAME_GOLDEN);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
226 mv = &s->vector_candidate[1];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
227 break;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
228
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
229 case VP56_MB_INTER_DELTA_PF:
3697
596e62da8f29 rename vector to vect to avoid clash with Apple gcc
aurel
parents: 3695
diff changeset
230 s->parse_vector_adjustment(s, &vect);
596e62da8f29 rename vector to vect to avoid clash with Apple gcc
aurel
parents: 3695
diff changeset
231 mv = &vect;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
232 break;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
233
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
234 case VP56_MB_INTER_DELTA_GF:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
235 vp56_get_vectors_predictors(s, row, col, VP56_FRAME_GOLDEN);
3697
596e62da8f29 rename vector to vect to avoid clash with Apple gcc
aurel
parents: 3695
diff changeset
236 s->parse_vector_adjustment(s, &vect);
596e62da8f29 rename vector to vect to avoid clash with Apple gcc
aurel
parents: 3695
diff changeset
237 mv = &vect;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
238 break;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
239
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
240 case VP56_MB_INTER_4V:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
241 vp56_decode_4mv(s, row, col);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
242 return s->mb_type;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
243
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
244 default:
3697
596e62da8f29 rename vector to vect to avoid clash with Apple gcc
aurel
parents: 3695
diff changeset
245 mv = &vect;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
246 break;
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 s->macroblocks[row*s->mb_width + col].mv = *mv;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
250
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
251 /* same vector for all blocks */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
252 for (b=0; b<6; b++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
253 s->mv[b] = *mv;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
254
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
255 return s->mb_type;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
256 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
257
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
258 static void vp56_add_predictors_dc(vp56_context_t *s, vp56_frame_t ref_frame)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
259 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
260 int idx = s->scantable.permutated[0];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
261 int i;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
262
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
263 for (i=0; i<6; i++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
264 vp56_ref_dc_t *ab = &s->above_blocks[s->above_block_idx[i]];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
265 vp56_ref_dc_t *lb = &s->left_block[vp56_b6to4[i]];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
266 int count = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
267 int dc = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
268
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
269 if (ref_frame == lb->ref_frame) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
270 dc += lb->dc_coeff;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
271 count++;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
272 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
273 if (ref_frame == ab->ref_frame) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
274 dc += ab->dc_coeff;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
275 count++;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
276 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
277 if (s->avctx->codec->id == CODEC_ID_VP5) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
278 if (count < 2 && ref_frame == ab[-1].ref_frame) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
279 dc += ab[-1].dc_coeff;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
280 count++;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
281 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
282 if (count < 2 && ref_frame == ab[1].ref_frame) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
283 dc += ab[1].dc_coeff;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
284 count++;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
285 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
286 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
287 if (count == 0)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
288 dc = s->prev_dc[vp56_b6to3[i]][ref_frame];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
289 else if (count == 2)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
290 dc /= 2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
291
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
292 s->block_coeff[i][idx] += dc;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
293 s->prev_dc[vp56_b6to3[i]][ref_frame] = s->block_coeff[i][idx];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
294 ab->dc_coeff = s->block_coeff[i][idx];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
295 ab->ref_frame = ref_frame;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
296 lb->dc_coeff = s->block_coeff[i][idx];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
297 lb->ref_frame = ref_frame;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
298 s->block_coeff[i][idx] *= s->dequant_dc;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
299 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
300 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
301
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
302 static void vp56_edge_filter(vp56_context_t *s, uint8_t *yuv,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
303 int pix_inc, int line_inc, int t)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
304 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
305 int pix2_inc = 2 * pix_inc;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
306 int i, v;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
307
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
308 for (i=0; i<12; i++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
309 v = (yuv[-pix2_inc] + 3*(yuv[0]-yuv[-pix_inc]) - yuv[pix_inc] + 4) >>3;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
310 v = s->adjust(v, t);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
311 yuv[-pix_inc] = clip_uint8(yuv[-pix_inc] + v);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
312 yuv[0] = clip_uint8(yuv[0] - v);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
313 yuv += line_inc;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
314 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
315 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
316
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
317 static void vp56_deblock_filter(vp56_context_t *s, uint8_t *yuv,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
318 int stride, int dx, int dy)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
319 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
320 int t = vp56_filter_threshold[s->quantizer];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
321 if (dx) vp56_edge_filter(s, yuv + 10-dx , 1, stride, t);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
322 if (dy) vp56_edge_filter(s, yuv + stride*(10-dy), stride, 1, t);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
323 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
324
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
325 static void vp56_mc(vp56_context_t *s, int b, uint8_t *src,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
326 int stride, int x, int y)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
327 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
328 int plane = vp56_b6to3[b];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
329 uint8_t *dst= s->frames[VP56_FRAME_CURRENT].data[plane]+s->block_offset[b];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
330 uint8_t *src_block;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
331 int src_offset;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
332 int overlap_offset = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
333 int mask = s->vp56_coord_div[b] - 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
334 int deblock_filtering = s->deblock_filtering;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
335 int dx;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
336 int dy;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
337
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
338 if (s->avctx->skip_loop_filter >= AVDISCARD_ALL ||
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
339 (s->avctx->skip_loop_filter >= AVDISCARD_NONKEY
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
340 && !s->frames[VP56_FRAME_CURRENT].key_frame))
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
341 deblock_filtering = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
342
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
343 dx = s->mv[b].x / s->vp56_coord_div[b];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
344 dy = s->mv[b].y / s->vp56_coord_div[b];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
345
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
346 if (b >= 4) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
347 x /= 2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
348 y /= 2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
349 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
350 x += dx - 2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
351 y += dy - 2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
352
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
353 if (x<0 || x+12>=s->plane_width[plane] ||
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
354 y<0 || y+12>=s->plane_height[plane]) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
355 ff_emulated_edge_mc(s->edge_emu_buffer,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
356 src + s->block_offset[b] + (dy-2)*stride + (dx-2),
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
357 stride, 12, 12, x, y,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
358 s->plane_width[plane],
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
359 s->plane_height[plane]);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
360 src_block = s->edge_emu_buffer;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
361 src_offset = 2 + 2*stride;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
362 } else if (deblock_filtering) {
3715
cdaee53c5da1 replaces back some C code by dsp.put_pixels_tab[0][0] (revert r6231)
aurel
parents: 3706
diff changeset
363 /* only need a 12x12 block, but there is no such dsp function, */
cdaee53c5da1 replaces back some C code by dsp.put_pixels_tab[0][0] (revert r6231)
aurel
parents: 3706
diff changeset
364 /* so copy a 16x12 block */
cdaee53c5da1 replaces back some C code by dsp.put_pixels_tab[0][0] (revert r6231)
aurel
parents: 3706
diff changeset
365 s->dsp.put_pixels_tab[0][0](s->edge_emu_buffer,
cdaee53c5da1 replaces back some C code by dsp.put_pixels_tab[0][0] (revert r6231)
aurel
parents: 3706
diff changeset
366 src + s->block_offset[b] + (dy-2)*stride + (dx-2),
cdaee53c5da1 replaces back some C code by dsp.put_pixels_tab[0][0] (revert r6231)
aurel
parents: 3706
diff changeset
367 stride, 12);
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
368 src_block = s->edge_emu_buffer;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
369 src_offset = 2 + 2*stride;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
370 } else {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
371 src_block = src;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
372 src_offset = s->block_offset[b] + dy*stride + dx;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
373 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
374
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
375 if (deblock_filtering)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
376 vp56_deblock_filter(s, src_block, stride, dx&7, dy&7);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
377
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
378 if (s->mv[b].x & mask)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
379 overlap_offset += (s->mv[b].x > 0) ? 1 : -1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
380 if (s->mv[b].y & mask)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
381 overlap_offset += (s->mv[b].y > 0) ? stride : -stride;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
382
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
383 if (overlap_offset) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
384 if (s->filter)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
385 s->filter(s, dst, src_block, src_offset, src_offset+overlap_offset,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
386 stride, s->mv[b], mask, s->filter_selection, b<4);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
387 else
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
388 s->dsp.put_no_rnd_pixels_l2[1](dst, src_block+src_offset,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
389 src_block+src_offset+overlap_offset,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
390 stride, 8);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
391 } else {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
392 s->dsp.put_pixels_tab[1][0](dst, src_block+src_offset, stride, 8);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
393 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
394 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
395
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
396 static void vp56_decode_mb(vp56_context_t *s, int row, int col)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
397 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
398 AVFrame *frame_current, *frame_ref;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
399 vp56_mb_t mb_type;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
400 vp56_frame_t ref_frame;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
401 int b, plan, off;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
402
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
403 if (s->frames[VP56_FRAME_CURRENT].key_frame)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
404 mb_type = VP56_MB_INTRA;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
405 else
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
406 mb_type = vp56_decode_mv(s, row, col);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
407 ref_frame = vp56_reference_frame[mb_type];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
408
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
409 memset(s->block_coeff, 0, sizeof(s->block_coeff));
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
410
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
411 s->parse_coeff(s);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
412
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
413 vp56_add_predictors_dc(s, ref_frame);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
414
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
415 frame_current = &s->frames[VP56_FRAME_CURRENT];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
416 frame_ref = &s->frames[ref_frame];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
417
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
418 switch (mb_type) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
419 case VP56_MB_INTRA:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
420 for (b=0; b<6; b++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
421 plan = vp56_b6to3[b];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
422 s->dsp.idct_put(frame_current->data[plan] + s->block_offset[b],
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
423 s->stride[plan], s->block_coeff[b]);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
424 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
425 break;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
426
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
427 case VP56_MB_INTER_NOVEC_PF:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
428 case VP56_MB_INTER_NOVEC_GF:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
429 for (b=0; b<6; b++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
430 plan = vp56_b6to3[b];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
431 off = s->block_offset[b];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
432 s->dsp.put_pixels_tab[1][0](frame_current->data[plan] + off,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
433 frame_ref->data[plan] + off,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
434 s->stride[plan], 8);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
435 s->dsp.idct_add(frame_current->data[plan] + off,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
436 s->stride[plan], s->block_coeff[b]);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
437 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
438 break;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
439
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
440 case VP56_MB_INTER_DELTA_PF:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
441 case VP56_MB_INTER_V1_PF:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
442 case VP56_MB_INTER_V2_PF:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
443 case VP56_MB_INTER_DELTA_GF:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
444 case VP56_MB_INTER_4V:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
445 case VP56_MB_INTER_V1_GF:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
446 case VP56_MB_INTER_V2_GF:
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
447 for (b=0; b<6; b++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
448 int x_off = b==1 || b==3 ? 8 : 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
449 int y_off = b==2 || b==3 ? 8 : 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
450 plan = vp56_b6to3[b];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
451 vp56_mc(s, b, frame_ref->data[plan], s->stride[plan],
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
452 16*col+x_off, 16*row+y_off);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
453 s->dsp.idct_add(frame_current->data[plan] + s->block_offset[b],
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
454 s->stride[plan], s->block_coeff[b]);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
455 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
456 break;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
457 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
458 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
459
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
460 static int vp56_size_changed(AVCodecContext *avctx, vp56_context_t *s)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
461 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
462 int stride = s->frames[VP56_FRAME_CURRENT].linesize[0];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
463 int i;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
464
4061
e5d148036c87 use coded_width and coded_height instead of width and height
aurel
parents: 3947
diff changeset
465 s->plane_width[0] = s->avctx->coded_width;
e5d148036c87 use coded_width and coded_height instead of width and height
aurel
parents: 3947
diff changeset
466 s->plane_width[1] = s->plane_width[2] = s->avctx->coded_width/2;
e5d148036c87 use coded_width and coded_height instead of width and height
aurel
parents: 3947
diff changeset
467 s->plane_height[0] = s->avctx->coded_height;
e5d148036c87 use coded_width and coded_height instead of width and height
aurel
parents: 3947
diff changeset
468 s->plane_height[1] = s->plane_height[2] = s->avctx->coded_height/2;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
469
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
470 for (i=0; i<3; i++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
471 s->stride[i] = s->flip * s->frames[VP56_FRAME_CURRENT].linesize[i];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
472
4061
e5d148036c87 use coded_width and coded_height instead of width and height
aurel
parents: 3947
diff changeset
473 s->mb_width = (s->avctx->coded_width+15) / 16;
e5d148036c87 use coded_width and coded_height instead of width and height
aurel
parents: 3947
diff changeset
474 s->mb_height = (s->avctx->coded_height+15) / 16;
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
475
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
476 if (s->mb_width > 1000 || s->mb_height > 1000) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
477 av_log(avctx, AV_LOG_ERROR, "picture too big\n");
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
478 return -1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
479 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
480
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
481 s->above_blocks = av_realloc(s->above_blocks,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
482 (4*s->mb_width+6) * sizeof(*s->above_blocks));
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
483 s->macroblocks = av_realloc(s->macroblocks,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
484 s->mb_width*s->mb_height*sizeof(*s->macroblocks));
3715
cdaee53c5da1 replaces back some C code by dsp.put_pixels_tab[0][0] (revert r6231)
aurel
parents: 3706
diff changeset
485 av_free(s->edge_emu_buffer_alloc);
cdaee53c5da1 replaces back some C code by dsp.put_pixels_tab[0][0] (revert r6231)
aurel
parents: 3706
diff changeset
486 s->edge_emu_buffer_alloc = av_malloc(16*stride);
3695
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
487 s->edge_emu_buffer = s->edge_emu_buffer_alloc;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
488 if (s->flip < 0)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
489 s->edge_emu_buffer += 15 * stride;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
490
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
491 return 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
492 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
493
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
494 int vp56_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
495 uint8_t *buf, int buf_size)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
496 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
497 vp56_context_t *s = avctx->priv_data;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
498 AVFrame *const p = &s->frames[VP56_FRAME_CURRENT];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
499 AVFrame *picture = data;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
500 int mb_row, mb_col, mb_row_flip, mb_offset = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
501 int block, y, uv, stride_y, stride_uv;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
502 int golden_frame = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
503 int res;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
504
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
505 res = s->parse_header(s, buf, buf_size, &golden_frame);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
506 if (!res)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
507 return -1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
508
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
509 p->reference = 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
510 if (avctx->get_buffer(avctx, p) < 0) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
511 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
512 return -1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
513 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
514
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
515 if (res == 2)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
516 if (vp56_size_changed(avctx, s)) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
517 avctx->release_buffer(avctx, p);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
518 return -1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
519 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
520
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
521 if (p->key_frame) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
522 p->pict_type = FF_I_TYPE;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
523 s->default_models_init(s);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
524 for (block=0; block<s->mb_height*s->mb_width; block++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
525 s->macroblocks[block].type = VP56_MB_INTRA;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
526 } else {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
527 p->pict_type = FF_P_TYPE;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
528 vp56_parse_mb_type_models(s);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
529 s->parse_vector_models(s);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
530 s->mb_type = VP56_MB_INTER_NOVEC_PF;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
531 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
532
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
533 s->parse_coeff_models(s);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
534
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
535 memset(s->prev_dc, 0, sizeof(s->prev_dc));
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
536 s->prev_dc[1][VP56_FRAME_CURRENT] = 128;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
537 s->prev_dc[2][VP56_FRAME_CURRENT] = 128;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
538
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
539 for (block=0; block < 4*s->mb_width+6; block++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
540 s->above_blocks[block].ref_frame = -1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
541 s->above_blocks[block].dc_coeff = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
542 s->above_blocks[block].not_null_dc = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
543 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
544 s->above_blocks[2*s->mb_width + 2].ref_frame = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
545 s->above_blocks[3*s->mb_width + 4].ref_frame = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
546
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
547 stride_y = p->linesize[0];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
548 stride_uv = p->linesize[1];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
549
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
550 if (s->flip < 0)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
551 mb_offset = 7;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
552
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
553 /* main macroblocks loop */
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
554 for (mb_row=0; mb_row<s->mb_height; mb_row++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
555 if (s->flip < 0)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
556 mb_row_flip = s->mb_height - mb_row - 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
557 else
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
558 mb_row_flip = mb_row;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
559
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
560 for (block=0; block<4; block++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
561 s->left_block[block].ref_frame = -1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
562 s->left_block[block].dc_coeff = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
563 s->left_block[block].not_null_dc = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
564 memset(s->coeff_ctx[block], 0, 64*sizeof(s->coeff_ctx[block][0]));
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
565 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
566 memset(s->coeff_ctx_last, 24, sizeof(s->coeff_ctx_last));
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
567
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
568 s->above_block_idx[0] = 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
569 s->above_block_idx[1] = 2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
570 s->above_block_idx[2] = 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
571 s->above_block_idx[3] = 2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
572 s->above_block_idx[4] = 2*s->mb_width + 2 + 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
573 s->above_block_idx[5] = 3*s->mb_width + 4 + 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
574
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
575 s->block_offset[s->frbi] = (mb_row_flip*16 + mb_offset) * stride_y;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
576 s->block_offset[s->srbi] = s->block_offset[s->frbi] + 8*stride_y;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
577 s->block_offset[1] = s->block_offset[0] + 8;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
578 s->block_offset[3] = s->block_offset[2] + 8;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
579 s->block_offset[4] = (mb_row_flip*8 + mb_offset) * stride_uv;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
580 s->block_offset[5] = s->block_offset[4];
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
581
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
582 for (mb_col=0; mb_col<s->mb_width; mb_col++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
583 vp56_decode_mb(s, mb_row, mb_col);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
584
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
585 for (y=0; y<4; y++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
586 s->above_block_idx[y] += 2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
587 s->block_offset[y] += 16;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
588 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
589
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
590 for (uv=4; uv<6; uv++) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
591 s->above_block_idx[uv] += 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
592 s->block_offset[uv] += 8;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
593 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
594 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
595 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
596
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
597 if (s->frames[VP56_FRAME_PREVIOUS].data[0]
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
598 && (s->frames[VP56_FRAME_PREVIOUS].data[0]
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
599 != s->frames[VP56_FRAME_GOLDEN].data[0])) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
600 avctx->release_buffer(avctx, &s->frames[VP56_FRAME_PREVIOUS]);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
601 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
602 if (p->key_frame || golden_frame) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
603 if (s->frames[VP56_FRAME_GOLDEN].data[0])
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
604 avctx->release_buffer(avctx, &s->frames[VP56_FRAME_GOLDEN]);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
605 s->frames[VP56_FRAME_GOLDEN] = *p;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
606 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
607 s->frames[VP56_FRAME_PREVIOUS] = *p;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
608
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
609 *picture = *p;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
610 *data_size = sizeof(AVPicture);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
611
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
612 return buf_size;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
613 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
614
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
615 void vp56_init(vp56_context_t *s, AVCodecContext *avctx, int flip)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
616 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
617 int i;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
618
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
619 s->avctx = avctx;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
620 avctx->pix_fmt = PIX_FMT_YUV420P;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
621
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
622 if (s->avctx->idct_algo == FF_IDCT_AUTO)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
623 s->avctx->idct_algo = FF_IDCT_VP3;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
624 dsputil_init(&s->dsp, s->avctx);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
625 ff_init_scantable(s->dsp.idct_permutation, &s->scantable,ff_zigzag_direct);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
626
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
627 avcodec_set_dimensions(s->avctx, 0, 0);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
628
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
629 for (i=0; i<3; i++)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
630 s->frames[i].data[0] = NULL;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
631 s->edge_emu_buffer_alloc = NULL;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
632
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
633 s->above_blocks = NULL;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
634 s->macroblocks = NULL;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
635 s->quantizer = -1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
636 s->deblock_filtering = 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
637
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
638 s->filter = NULL;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
639
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
640 if (flip) {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
641 s->flip = -1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
642 s->frbi = 2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
643 s->srbi = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
644 } else {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
645 s->flip = 1;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
646 s->frbi = 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
647 s->srbi = 2;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
648 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
649 }
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
650
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
651 int vp56_free(AVCodecContext *avctx)
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
652 {
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
653 vp56_context_t *s = avctx->priv_data;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
654
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
655 av_free(s->above_blocks);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
656 av_free(s->macroblocks);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
657 av_free(s->edge_emu_buffer_alloc);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
658 if (s->frames[VP56_FRAME_GOLDEN].data[0]
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
659 && (s->frames[VP56_FRAME_PREVIOUS].data[0]
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
660 != s->frames[VP56_FRAME_GOLDEN].data[0]))
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
661 avctx->release_buffer(avctx, &s->frames[VP56_FRAME_GOLDEN]);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
662 if (s->frames[VP56_FRAME_PREVIOUS].data[0])
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
663 avctx->release_buffer(avctx, &s->frames[VP56_FRAME_PREVIOUS]);
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
664 return 0;
6795c9e5f983 VP5 and VP6 video decoder
aurel
parents:
diff changeset
665 }