annotate vp56.c @ 3848:4d9aba494478 libavcodec

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