Parent Directory | Revision Log
Revision 1.49.2.17 - (view) (download)
1 : | edgomez | 1.48 | /***************************************************************************** |
2 : | Isibaar | 1.1 | * |
3 : | edgomez | 1.12 | * XVID MPEG-4 VIDEO CODEC |
4 : | edgomez | 1.48 | * - Decoder Module - |
5 : | Isibaar | 1.1 | * |
6 : | edgomez | 1.49.2.7 | * Copyright(C) 2002 MinChen <chenm001@163.com> |
7 : | * 2002-2003 Peter Ross <pross@xvid.org> | ||
8 : | edgomez | 1.42 | * |
9 : | edgomez | 1.49.2.7 | * This program is free software ; you can redistribute it and/or modify |
10 : | edgomez | 1.47 | * it under the terms of the GNU General Public License as published by |
11 : | edgomez | 1.49.2.7 | * the Free Software Foundation ; either version 2 of the License, or |
12 : | edgomez | 1.12 | * (at your option) any later version. |
13 : | * | ||
14 : | * This program is distributed in the hope that it will be useful, | ||
15 : | edgomez | 1.49.2.7 | * but WITHOUT ANY WARRANTY ; without even the implied warranty of |
16 : | edgomez | 1.12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 : | * GNU General Public License for more details. | ||
18 : | * | ||
19 : | * You should have received a copy of the GNU General Public License | ||
20 : | edgomez | 1.49.2.7 | * along with this program ; if not, write to the Free Software |
21 : | edgomez | 1.12 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 : | Isibaar | 1.1 | * |
23 : | syskin | 1.49.2.16 | * $Id: decoder.c,v 1.49.2.15 2003/10/07 13:02:35 edgomez Exp $ |
24 : | edgomez | 1.43 | * |
25 : | edgomez | 1.48 | ****************************************************************************/ |
26 : | Isibaar | 1.1 | |
27 : | edgomez | 1.47 | #include <stdio.h> |
28 : | Isibaar | 1.1 | #include <stdlib.h> |
29 : | edgomez | 1.12 | #include <string.h> |
30 : | Isibaar | 1.1 | |
31 : | chenm001 | 1.27 | #ifdef BFRAMES_DEC_DEBUG |
32 : | #define BFRAMES_DEC | ||
33 : | #endif | ||
34 : | |||
35 : | Isibaar | 1.1 | #include "xvid.h" |
36 : | #include "portab.h" | ||
37 : | edgomez | 1.47 | #include "global.h" |
38 : | Isibaar | 1.1 | |
39 : | #include "decoder.h" | ||
40 : | #include "bitstream/bitstream.h" | ||
41 : | #include "bitstream/mbcoding.h" | ||
42 : | |||
43 : | edgomez | 1.49.2.15 | #include "quant/quant.h" |
44 : | Isibaar | 1.1 | #include "dct/idct.h" |
45 : | #include "dct/fdct.h" | ||
46 : | #include "utils/mem_transfer.h" | ||
47 : | #include "image/interpolate8x8.h" | ||
48 : | edgomez | 1.47 | #include "image/reduced.h" |
49 : | #include "image/font.h" | ||
50 : | Isibaar | 1.1 | |
51 : | #include "bitstream/mbcoding.h" | ||
52 : | #include "prediction/mbprediction.h" | ||
53 : | #include "utils/timer.h" | ||
54 : | #include "utils/emms.h" | ||
55 : | edgomez | 1.47 | #include "motion/motion.h" |
56 : | chl | 1.49.2.9 | #include "motion/gmc.h" |
57 : | Isibaar | 1.1 | |
58 : | #include "image/image.h" | ||
59 : | #include "image/colorspace.h" | ||
60 : | Isibaar | 1.3 | #include "utils/mem_align.h" |
61 : | Isibaar | 1.1 | |
62 : | syskin | 1.49.2.17 | static int |
63 : | edgomez | 1.47 | decoder_resize(DECODER * dec) |
64 : | Isibaar | 1.1 | { |
65 : | edgomez | 1.47 | /* free existing */ |
66 : | image_destroy(&dec->cur, dec->edged_width, dec->edged_height); | ||
67 : | image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); | ||
68 : | image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); | ||
69 : | image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); | ||
70 : | image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); | ||
71 : | |||
72 : | image_destroy(&dec->gmc, dec->edged_width, dec->edged_height); | ||
73 : | Isibaar | 1.1 | |
74 : | edgomez | 1.49.2.13 | if (dec->last_mbs) |
75 : | edgomez | 1.47 | xvid_free(dec->last_mbs); |
76 : | if (dec->mbs) | ||
77 : | xvid_free(dec->mbs); | ||
78 : | Isibaar | 1.1 | |
79 : | edgomez | 1.47 | /* realloc */ |
80 : | Isibaar | 1.1 | dec->mb_width = (dec->width + 15) / 16; |
81 : | dec->mb_height = (dec->height + 15) / 16; | ||
82 : | |||
83 : | dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE; | ||
84 : | dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE; | ||
85 : | edgomez | 1.19 | |
86 : | if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) { | ||
87 : | Isibaar | 1.3 | xvid_free(dec); |
88 : | Isibaar | 1.1 | return XVID_ERR_MEMORY; |
89 : | } | ||
90 : | |||
91 : | edgomez | 1.19 | if (image_create(&dec->refn[0], dec->edged_width, dec->edged_height)) { |
92 : | Isibaar | 1.1 | image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
93 : | Isibaar | 1.3 | xvid_free(dec); |
94 : | Isibaar | 1.1 | return XVID_ERR_MEMORY; |
95 : | } | ||
96 : | edgomez | 1.47 | |
97 : | edgomez | 1.48 | /* Support B-frame to reference last 2 frame */ |
98 : | edgomez | 1.19 | if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) { |
99 : | chenm001 | 1.11 | image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
100 : | image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); | ||
101 : | xvid_free(dec); | ||
102 : | return XVID_ERR_MEMORY; | ||
103 : | } | ||
104 : | edgomez | 1.47 | if (image_create(&dec->tmp, dec->edged_width, dec->edged_height)) { |
105 : | image_destroy(&dec->cur, dec->edged_width, dec->edged_height); | ||
106 : | image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); | ||
107 : | image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); | ||
108 : | xvid_free(dec); | ||
109 : | return XVID_ERR_MEMORY; | ||
110 : | } | ||
111 : | |||
112 : | if (image_create(&dec->qtmp, dec->edged_width, dec->edged_height)) { | ||
113 : | image_destroy(&dec->cur, dec->edged_width, dec->edged_height); | ||
114 : | image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); | ||
115 : | image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); | ||
116 : | image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); | ||
117 : | xvid_free(dec); | ||
118 : | return XVID_ERR_MEMORY; | ||
119 : | } | ||
120 : | |||
121 : | if (image_create(&dec->gmc, dec->edged_width, dec->edged_height)) { | ||
122 : | image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); | ||
123 : | chenm001 | 1.14 | image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
124 : | image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); | ||
125 : | image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); | ||
126 : | edgomez | 1.47 | image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
127 : | chenm001 | 1.14 | xvid_free(dec); |
128 : | return XVID_ERR_MEMORY; | ||
129 : | } | ||
130 : | Isibaar | 1.1 | |
131 : | edgomez | 1.19 | dec->mbs = |
132 : | xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, | ||
133 : | CACHE_LINE); | ||
134 : | if (dec->mbs == NULL) { | ||
135 : | Isibaar | 1.1 | image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
136 : | chenm001 | 1.14 | image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
137 : | image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); | ||
138 : | edgomez | 1.47 | image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
139 : | image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); | ||
140 : | chenm001 | 1.14 | xvid_free(dec); |
141 : | return XVID_ERR_MEMORY; | ||
142 : | } | ||
143 : | Isibaar | 1.20 | memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
144 : | |||
145 : | edgomez | 1.48 | /* For skip MB flag */ |
146 : | edgomez | 1.19 | dec->last_mbs = |
147 : | xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, | ||
148 : | CACHE_LINE); | ||
149 : | if (dec->last_mbs == NULL) { | ||
150 : | chenm001 | 1.14 | xvid_free(dec->mbs); |
151 : | image_destroy(&dec->cur, dec->edged_width, dec->edged_height); | ||
152 : | image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); | ||
153 : | image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); | ||
154 : | edgomez | 1.47 | image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
155 : | image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); | ||
156 : | Isibaar | 1.3 | xvid_free(dec); |
157 : | Isibaar | 1.1 | return XVID_ERR_MEMORY; |
158 : | } | ||
159 : | Isibaar | 1.20 | |
160 : | memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); | ||
161 : | Isibaar | 1.1 | |
162 : | suxen_drol | 1.49.2.1 | return 0; |
163 : | edgomez | 1.47 | } |
164 : | |||
165 : | |||
166 : | int | ||
167 : | suxen_drol | 1.49.2.1 | decoder_create(xvid_dec_create_t * create) |
168 : | edgomez | 1.47 | { |
169 : | DECODER *dec; | ||
170 : | |||
171 : | edgomez | 1.49.2.10 | if (XVID_VERSION_MAJOR(create->version) != 1) /* v1.x.x */ |
172 : | suxen_drol | 1.49.2.1 | return XVID_ERR_VERSION; |
173 : | |||
174 : | edgomez | 1.47 | dec = xvid_malloc(sizeof(DECODER), CACHE_LINE); |
175 : | if (dec == NULL) { | ||
176 : | return XVID_ERR_MEMORY; | ||
177 : | } | ||
178 : | memset(dec, 0, sizeof(DECODER)); | ||
179 : | |||
180 : | suxen_drol | 1.49.2.1 | create->handle = dec; |
181 : | edgomez | 1.47 | |
182 : | suxen_drol | 1.49.2.1 | dec->width = create->width; |
183 : | dec->height = create->height; | ||
184 : | edgomez | 1.47 | |
185 : | image_null(&dec->cur); | ||
186 : | image_null(&dec->refn[0]); | ||
187 : | image_null(&dec->refn[1]); | ||
188 : | image_null(&dec->tmp); | ||
189 : | image_null(&dec->qtmp); | ||
190 : | |||
191 : | edgomez | 1.48 | /* image based GMC */ |
192 : | edgomez | 1.47 | image_null(&dec->gmc); |
193 : | |||
194 : | |||
195 : | dec->mbs = NULL; | ||
196 : | dec->last_mbs = NULL; | ||
197 : | |||
198 : | Isibaar | 1.1 | init_timer(); |
199 : | |||
200 : | edgomez | 1.48 | /* For B-frame support (used to save reference frame's time */ |
201 : | edgomez | 1.47 | dec->frames = 0; |
202 : | chenm001 | 1.14 | dec->time = dec->time_base = dec->last_time_base = 0; |
203 : | edgomez | 1.47 | dec->low_delay = 0; |
204 : | dec->packed_mode = 0; | ||
205 : | |||
206 : | dec->fixed_dimensions = (dec->width > 0 && dec->height > 0); | ||
207 : | edgomez | 1.19 | |
208 : | edgomez | 1.47 | if (dec->fixed_dimensions) |
209 : | return decoder_resize(dec); | ||
210 : | else | ||
211 : | edgomez | 1.49.2.13 | return 0; |
212 : | Isibaar | 1.1 | } |
213 : | |||
214 : | |||
215 : | edgomez | 1.19 | int |
216 : | decoder_destroy(DECODER * dec) | ||
217 : | Isibaar | 1.1 | { |
218 : | chenm001 | 1.14 | xvid_free(dec->last_mbs); |
219 : | Isibaar | 1.3 | xvid_free(dec->mbs); |
220 : | edgomez | 1.47 | |
221 : | edgomez | 1.48 | /* image based GMC */ |
222 : | image_destroy(&dec->gmc, dec->edged_width, dec->edged_height); | ||
223 : | edgomez | 1.47 | |
224 : | chenm001 | 1.11 | image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
225 : | chenm001 | 1.14 | image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
226 : | edgomez | 1.47 | image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
227 : | image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); | ||
228 : | Isibaar | 1.1 | image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
229 : | Isibaar | 1.3 | xvid_free(dec); |
230 : | Isibaar | 1.1 | |
231 : | write_timer(); | ||
232 : | suxen_drol | 1.49.2.1 | return 0; |
233 : | Isibaar | 1.1 | } |
234 : | |||
235 : | edgomez | 1.19 | static const int32_t dquant_table[4] = { |
236 : | Isibaar | 1.1 | -1, -2, 1, 2 |
237 : | }; | ||
238 : | |||
239 : | edgomez | 1.48 | /* decode an intra macroblock */ |
240 : | syskin | 1.49.2.17 | static void |
241 : | edgomez | 1.19 | decoder_mbintra(DECODER * dec, |
242 : | MACROBLOCK * pMB, | ||
243 : | const uint32_t x_pos, | ||
244 : | const uint32_t y_pos, | ||
245 : | const uint32_t acpred_flag, | ||
246 : | const uint32_t cbp, | ||
247 : | Bitstream * bs, | ||
248 : | const uint32_t quant, | ||
249 : | chenm001 | 1.26 | const uint32_t intra_dc_threshold, |
250 : | edgomez | 1.47 | const unsigned int bound, |
251 : | const int reduced_resolution) | ||
252 : | Isibaar | 1.1 | { |
253 : | edgomez | 1.7 | |
254 : | DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); | ||
255 : | edgomez | 1.19 | DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE); |
256 : | edgomez | 1.7 | |
257 : | h | 1.8 | uint32_t stride = dec->edged_width; |
258 : | uint32_t stride2 = stride / 2; | ||
259 : | uint32_t next_block = stride * 8; | ||
260 : | h | 1.5 | uint32_t i; |
261 : | uint32_t iQuant = pMB->quant; | ||
262 : | uint8_t *pY_Cur, *pU_Cur, *pV_Cur; | ||
263 : | |||
264 : | edgomez | 1.47 | if (reduced_resolution) { |
265 : | pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5); | ||
266 : | pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4); | ||
267 : | pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4); | ||
268 : | }else{ | ||
269 : | pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); | ||
270 : | pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); | ||
271 : | pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); | ||
272 : | } | ||
273 : | edgomez | 1.7 | |
274 : | edgomez | 1.48 | memset(block, 0, 6 * 64 * sizeof(int16_t)); /* clear */ |
275 : | h | 1.5 | |
276 : | edgomez | 1.19 | for (i = 0; i < 6; i++) { |
277 : | h | 1.5 | uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
278 : | Isibaar | 1.1 | int16_t predictors[8]; |
279 : | int start_coeff; | ||
280 : | |||
281 : | start_timer(); | ||
282 : | edgomez | 1.19 | predict_acdc(dec->mbs, x_pos, y_pos, dec->mb_width, i, &block[i * 64], |
283 : | chenm001 | 1.26 | iQuant, iDcScaler, predictors, bound); |
284 : | edgomez | 1.19 | if (!acpred_flag) { |
285 : | h | 1.5 | pMB->acpred_directions[i] = 0; |
286 : | Isibaar | 1.1 | } |
287 : | stop_prediction_timer(); | ||
288 : | |||
289 : | edgomez | 1.19 | if (quant < intra_dc_threshold) { |
290 : | Isibaar | 1.1 | int dc_size; |
291 : | int dc_dif; | ||
292 : | |||
293 : | edgomez | 1.19 | dc_size = i < 4 ? get_dc_size_lum(bs) : get_dc_size_chrom(bs); |
294 : | dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0; | ||
295 : | Isibaar | 1.1 | |
296 : | edgomez | 1.19 | if (dc_size > 8) { |
297 : | edgomez | 1.48 | BitstreamSkip(bs, 1); /* marker */ |
298 : | Isibaar | 1.1 | } |
299 : | edgomez | 1.19 | |
300 : | block[i * 64 + 0] = dc_dif; | ||
301 : | Isibaar | 1.1 | start_coeff = 1; |
302 : | chenm001 | 1.26 | |
303 : | edgomez | 1.49.2.5 | DPRINTF(XVID_DEBUG_COEFF,"block[0] %i\n", dc_dif); |
304 : | edgomez | 1.19 | } else { |
305 : | Isibaar | 1.1 | start_coeff = 0; |
306 : | } | ||
307 : | |||
308 : | start_timer(); | ||
309 : | edgomez | 1.48 | if (cbp & (1 << (5 - i))) /* coded */ |
310 : | Isibaar | 1.1 | { |
311 : | edgomez | 1.47 | int direction = dec->alternate_vertical_scan ? |
312 : | 2 : pMB->acpred_directions[i]; | ||
313 : | |||
314 : | get_intra_block(bs, &block[i * 64], direction, start_coeff); | ||
315 : | Isibaar | 1.1 | } |
316 : | stop_coding_timer(); | ||
317 : | |||
318 : | start_timer(); | ||
319 : | edgomez | 1.19 | add_acdc(pMB, i, &block[i * 64], iDcScaler, predictors); |
320 : | Isibaar | 1.1 | stop_prediction_timer(); |
321 : | |||
322 : | start_timer(); | ||
323 : | edgomez | 1.19 | if (dec->quant_type == 0) { |
324 : | edgomez | 1.49.2.15 | dequant_h263_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler); |
325 : | edgomez | 1.19 | } else { |
326 : | edgomez | 1.49.2.15 | dequant_mpeg_intra(&data[i * 64], &block[i * 64], iQuant, iDcScaler); |
327 : | Isibaar | 1.1 | } |
328 : | stop_iquant_timer(); | ||
329 : | |||
330 : | start_timer(); | ||
331 : | edgomez | 1.19 | idct(&data[i * 64]); |
332 : | Isibaar | 1.1 | stop_idct_timer(); |
333 : | edgomez | 1.47 | |
334 : | h | 1.5 | } |
335 : | Isibaar | 1.1 | |
336 : | edgomez | 1.19 | if (dec->interlacing && pMB->field_dct) { |
337 : | h | 1.8 | next_block = stride; |
338 : | stride *= 2; | ||
339 : | Isibaar | 1.1 | } |
340 : | h | 1.5 | |
341 : | start_timer(); | ||
342 : | edgomez | 1.47 | |
343 : | if (reduced_resolution) | ||
344 : | { | ||
345 : | next_block*=2; | ||
346 : | copy_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride); | ||
347 : | copy_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride); | ||
348 : | copy_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride); | ||
349 : | copy_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride); | ||
350 : | copy_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2); | ||
351 : | copy_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2); | ||
352 : | }else{ | ||
353 : | transfer_16to8copy(pY_Cur, &data[0 * 64], stride); | ||
354 : | transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride); | ||
355 : | transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride); | ||
356 : | transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride); | ||
357 : | transfer_16to8copy(pU_Cur, &data[4 * 64], stride2); | ||
358 : | transfer_16to8copy(pV_Cur, &data[5 * 64], stride2); | ||
359 : | } | ||
360 : | h | 1.5 | stop_transfer_timer(); |
361 : | Isibaar | 1.1 | } |
362 : | |||
363 : | syskin | 1.49.2.17 | static void |
364 : | decoder_mb_decode(DECODER * dec, | ||
365 : | const uint32_t cbp, | ||
366 : | Bitstream * bs, | ||
367 : | uint8_t * pY_Cur, | ||
368 : | uint8_t * pU_Cur, | ||
369 : | uint8_t * pV_Cur, | ||
370 : | const int reduced_resolution, | ||
371 : | const MACROBLOCK * pMB) | ||
372 : | { | ||
373 : | DECLARE_ALIGNED_MATRIX(block, 1, 64, int16_t, CACHE_LINE); | ||
374 : | DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE); | ||
375 : | Isibaar | 1.1 | |
376 : | syskin | 1.49.2.17 | int stride = dec->edged_width, next_block = stride * (reduced_resolution ? 16 : 8); |
377 : | const int stride2 = stride/2; | ||
378 : | int i; | ||
379 : | const uint32_t iQuant = pMB->quant; | ||
380 : | const int direction = dec->alternate_vertical_scan ? 2 : 0; | ||
381 : | const quant_interFuncPtr dequant = dec->quant_type == 0 ? dequant_h263_inter : dequant_mpeg_inter; | ||
382 : | Isibaar | 1.1 | |
383 : | syskin | 1.49.2.17 | for (i = 0; i < 6; i++) { |
384 : | |||
385 : | if (cbp & (1 << (5 - i))) { /* coded */ | ||
386 : | |||
387 : | memset(block, 0, 64 * sizeof(int16_t)); /* clear */ | ||
388 : | |||
389 : | start_timer(); | ||
390 : | get_inter_block(bs, block, direction); | ||
391 : | stop_coding_timer(); | ||
392 : | |||
393 : | start_timer(); | ||
394 : | dequant(&data[i * 64], block, iQuant); | ||
395 : | stop_iquant_timer(); | ||
396 : | |||
397 : | start_timer(); | ||
398 : | idct(&data[i * 64]); | ||
399 : | stop_idct_timer(); | ||
400 : | } | ||
401 : | } | ||
402 : | |||
403 : | if (dec->interlacing && pMB->field_dct) { | ||
404 : | next_block = stride; | ||
405 : | stride *= 2; | ||
406 : | } | ||
407 : | |||
408 : | start_timer(); | ||
409 : | if (reduced_resolution) { | ||
410 : | if (cbp & 32) | ||
411 : | add_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride); | ||
412 : | if (cbp & 16) | ||
413 : | add_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride); | ||
414 : | if (cbp & 8) | ||
415 : | add_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride); | ||
416 : | if (cbp & 4) | ||
417 : | add_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride); | ||
418 : | if (cbp & 2) | ||
419 : | add_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2); | ||
420 : | if (cbp & 1) | ||
421 : | add_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2); | ||
422 : | } else { | ||
423 : | if (cbp & 32) | ||
424 : | transfer_16to8add(pY_Cur, &data[0 * 64], stride); | ||
425 : | if (cbp & 16) | ||
426 : | transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride); | ||
427 : | if (cbp & 8) | ||
428 : | transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride); | ||
429 : | if (cbp & 4) | ||
430 : | transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride); | ||
431 : | if (cbp & 2) | ||
432 : | transfer_16to8add(pU_Cur, &data[4 * 64], stride2); | ||
433 : | if (cbp & 1) | ||
434 : | transfer_16to8add(pV_Cur, &data[5 * 64], stride2); | ||
435 : | } | ||
436 : | stop_transfer_timer(); | ||
437 : | } | ||
438 : | Isibaar | 1.1 | |
439 : | edgomez | 1.48 | /* decode an inter macroblock */ |
440 : | syskin | 1.49.2.17 | static void |
441 : | edgomez | 1.19 | decoder_mbinter(DECODER * dec, |
442 : | const MACROBLOCK * pMB, | ||
443 : | const uint32_t x_pos, | ||
444 : | const uint32_t y_pos, | ||
445 : | const uint32_t cbp, | ||
446 : | Bitstream * bs, | ||
447 : | edgomez | 1.47 | const uint32_t rounding, |
448 : | syskin | 1.49.2.17 | const int reduced_resolution, |
449 : | const int ref) | ||
450 : | Isibaar | 1.1 | { |
451 : | h | 1.8 | uint32_t stride = dec->edged_width; |
452 : | uint32_t stride2 = stride / 2; | ||
453 : | edgomez | 1.47 | uint32_t next_block = stride * (reduced_resolution ? 16 : 8); |
454 : | edgomez | 1.7 | uint32_t i; |
455 : | syskin | 1.49.2.17 | |
456 : | h | 1.5 | uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
457 : | edgomez | 1.47 | |
458 : | Isibaar | 1.1 | int uv_dx, uv_dy; |
459 : | edgomez | 1.47 | VECTOR mv[4]; /* local copy of mvs */ |
460 : | |||
461 : | if (reduced_resolution) { | ||
462 : | pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5); | ||
463 : | pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4); | ||
464 : | pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4); | ||
465 : | for (i = 0; i < 4; i++) { | ||
466 : | mv[i].x = RRV_MV_SCALEUP(pMB->mvs[i].x); | ||
467 : | mv[i].y = RRV_MV_SCALEUP(pMB->mvs[i].y); | ||
468 : | } | ||
469 : | } else { | ||
470 : | pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); | ||
471 : | pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); | ||
472 : | pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); | ||
473 : | for (i = 0; i < 4; i++) | ||
474 : | mv[i] = pMB->mvs[i]; | ||
475 : | } | ||
476 : | edgomez | 1.49.2.13 | |
477 : | syskin | 1.49.2.17 | start_timer(); |
478 : | edgomez | 1.47 | |
479 : | syskin | 1.49.2.17 | if (pMB->mode != MODE_INTER4V) { /* INTER, INTER_Q, NOT_CODED, FORWARD, BACKWARD */ |
480 : | edgomez | 1.49.2.13 | |
481 : | syskin | 1.49.2.17 | uv_dx = mv[0].x; |
482 : | uv_dy = mv[0].y; | ||
483 : | if (dec->quarterpel) { | ||
484 : | uv_dx /= 2; | ||
485 : | uv_dy /= 2; | ||
486 : | } | ||
487 : | edgomez | 1.47 | uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; |
488 : | uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; | ||
489 : | |||
490 : | if (reduced_resolution) | ||
491 : | interpolate32x32_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos, | ||
492 : | syskin | 1.49.2.17 | mv[0].x, mv[0].y, stride, rounding); |
493 : | else if (dec->quarterpel) | ||
494 : | interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->qtmp.y, dec->qtmp.y + 64, | ||
495 : | dec->qtmp.y + 128, 16*x_pos, 16*y_pos, | ||
496 : | edgomez | 1.47 | mv[0].x, mv[0].y, stride, rounding); |
497 : | else | ||
498 : | syskin | 1.49.2.17 | interpolate16x16_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos, 16*y_pos, |
499 : | mv[0].x, mv[0].y, stride, rounding); | ||
500 : | edgomez | 1.47 | |
501 : | syskin | 1.49.2.17 | } else { /* MODE_INTER4V */ |
502 : | edgomez | 1.47 | |
503 : | syskin | 1.49.2.17 | if(dec->quarterpel) { |
504 : | uv_dx = (mv[0].x / 2) + (mv[1].x / 2) + (mv[2].x / 2) + (mv[3].x / 2); | ||
505 : | uv_dy = (mv[0].y / 2) + (mv[1].y / 2) + (mv[2].y / 2) + (mv[3].y / 2); | ||
506 : | } else { | ||
507 : | uv_dx = mv[0].x + mv[1].x + mv[2].x + mv[3].x; | ||
508 : | uv_dy = mv[0].y + mv[1].y + mv[2].y + mv[3].y; | ||
509 : | } | ||
510 : | edgomez | 1.47 | |
511 : | syskin | 1.49.2.17 | uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf]; |
512 : | uv_dy = (uv_dy >> 3) + roundtab_76[uv_dy & 0xf]; | ||
513 : | edgomez | 1.47 | |
514 : | syskin | 1.49.2.17 | if (reduced_resolution) { |
515 : | edgomez | 1.47 | interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos, |
516 : | syskin | 1.49.2.17 | mv[0].x, mv[0].y, stride, rounding); |
517 : | edgomez | 1.47 | interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos + 16, 32*y_pos, |
518 : | syskin | 1.49.2.17 | mv[1].x, mv[1].y, stride, rounding); |
519 : | edgomez | 1.47 | interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos, 32*y_pos + 16, |
520 : | syskin | 1.49.2.17 | mv[2].x, mv[2].y, stride, rounding); |
521 : | edgomez | 1.49.2.13 | interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos + 16, 32*y_pos + 16, |
522 : | syskin | 1.49.2.17 | mv[3].x, mv[3].y, stride, rounding); |
523 : | edgomez | 1.47 | interpolate16x16_switch(dec->cur.u, dec->refn[0].u , 16 * x_pos, 16 * y_pos, |
524 : | syskin | 1.49.2.17 | uv_dx, uv_dy, stride2, rounding); |
525 : | edgomez | 1.47 | interpolate16x16_switch(dec->cur.v, dec->refn[0].v , 16 * x_pos, 16 * y_pos, |
526 : | syskin | 1.49.2.17 | uv_dx, uv_dy, stride2, rounding); |
527 : | edgomez | 1.47 | |
528 : | syskin | 1.49.2.17 | } else if (dec->quarterpel) { |
529 : | interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64, | ||
530 : | dec->qtmp.y + 128, 16*x_pos, 16*y_pos, | ||
531 : | mv[0].x, mv[0].y, stride, rounding); | ||
532 : | interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64, | ||
533 : | dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos, | ||
534 : | mv[1].x, mv[1].y, stride, rounding); | ||
535 : | interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64, | ||
536 : | dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8, | ||
537 : | mv[2].x, mv[2].y, stride, rounding); | ||
538 : | interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64, | ||
539 : | dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, | ||
540 : | mv[3].x, mv[3].y, stride, rounding); | ||
541 : | } else { | ||
542 : | interpolate8x8_switch(dec->cur.y, dec->refn[0].y , 16*x_pos, 16*y_pos, | ||
543 : | mv[0].x, mv[0].y, stride, rounding); | ||
544 : | interpolate8x8_switch(dec->cur.y, dec->refn[0].y , 16*x_pos + 8, 16*y_pos, | ||
545 : | mv[1].x, mv[1].y, stride, rounding); | ||
546 : | interpolate8x8_switch(dec->cur.y, dec->refn[0].y , 16*x_pos, 16*y_pos + 8, | ||
547 : | mv[2].x, mv[2].y, stride, rounding); | ||
548 : | interpolate8x8_switch(dec->cur.y, dec->refn[0].y , 16*x_pos + 8, 16*y_pos + 8, | ||
549 : | mv[3].x, mv[3].y, stride, rounding); | ||
550 : | edgomez | 1.47 | } |
551 : | } | ||
552 : | |||
553 : | syskin | 1.49.2.17 | /* chroma */ |
554 : | if (reduced_resolution) { | ||
555 : | interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos, | ||
556 : | uv_dx, uv_dy, stride2, rounding); | ||
557 : | interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos, | ||
558 : | uv_dx, uv_dy, stride2, rounding); | ||
559 : | } else { | ||
560 : | interpolate8x8_switch(dec->cur.u, dec->refn[ref].u, 8 * x_pos, 8 * y_pos, | ||
561 : | uv_dx, uv_dy, stride2, rounding); | ||
562 : | interpolate8x8_switch(dec->cur.v, dec->refn[ref].v, 8 * x_pos, 8 * y_pos, | ||
563 : | uv_dx, uv_dy, stride2, rounding); | ||
564 : | edgomez | 1.47 | } |
565 : | Isibaar | 1.1 | |
566 : | syskin | 1.49.2.17 | stop_comp_timer(); |
567 : | Isibaar | 1.34 | |
568 : | syskin | 1.49.2.17 | if (cbp) |
569 : | decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur, | ||
570 : | reduced_resolution, pMB); | ||
571 : | edgomez | 1.47 | } |
572 : | |||
573 : | static void | ||
574 : | decoder_mbgmc(DECODER * dec, | ||
575 : | MACROBLOCK * const pMB, | ||
576 : | const uint32_t x_pos, | ||
577 : | const uint32_t y_pos, | ||
578 : | const uint32_t fcode, | ||
579 : | const uint32_t cbp, | ||
580 : | Bitstream * bs, | ||
581 : | syskin | 1.49.2.17 | const uint32_t rounding) |
582 : | edgomez | 1.47 | { |
583 : | const uint32_t stride = dec->edged_width; | ||
584 : | const uint32_t stride2 = stride / 2; | ||
585 : | syskin | 1.49.2.17 | |
586 : | edgomez | 1.47 | uint8_t *const pY_Cur=dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
587 : | uint8_t *const pU_Cur=dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); | ||
588 : | uint8_t *const pV_Cur=dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); | ||
589 : | |||
590 : | syskin | 1.49.2.17 | NEW_GMC_DATA * gmc_data = &dec->new_gmc_data; |
591 : | |||
592 : | edgomez | 1.47 | pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv; |
593 : | Isibaar | 1.1 | |
594 : | start_timer(); | ||
595 : | edgomez | 1.49.2.13 | |
596 : | edgomez | 1.47 | /* this is where the calculations are done */ |
597 : | edgomez | 1.49.2.13 | |
598 : | syskin | 1.49.2.17 | gmc_data->predict_16x16(gmc_data, |
599 : | dec->cur.y + y_pos*16*stride + x_pos*16, dec->refn[0].y, | ||
600 : | stride, stride, x_pos, y_pos, rounding); | ||
601 : | |||
602 : | gmc_data->predict_8x8(gmc_data, | ||
603 : | dec->cur.u + y_pos*8*stride2 + x_pos*8, dec->refn[0].u, | ||
604 : | dec->cur.v + y_pos*8*stride2 + x_pos*8, dec->refn[0].v, | ||
605 : | stride2, stride2, x_pos, y_pos, rounding); | ||
606 : | chl | 1.49.2.9 | |
607 : | syskin | 1.49.2.17 | gmc_data->get_average_mv(gmc_data, &pMB->amv, x_pos, y_pos, dec->quarterpel); |
608 : | chl | 1.49.2.9 | |
609 : | syskin | 1.49.2.17 | pMB->amv.x = gmc_sanitize(pMB->amv.x, dec->quarterpel, fcode); |
610 : | pMB->amv.y = gmc_sanitize(pMB->amv.y, dec->quarterpel, fcode); | ||
611 : | chl | 1.49.2.9 | |
612 : | edgomez | 1.47 | pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv; |
613 : | edgomez | 1.49.2.13 | |
614 : | edgomez | 1.47 | stop_transfer_timer(); |
615 : | edgomez | 1.49.2.13 | |
616 : | syskin | 1.49.2.17 | if (cbp) |
617 : | decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur, 0, pMB); | ||
618 : | Isibaar | 1.1 | |
619 : | } | ||
620 : | |||
621 : | |||
622 : | syskin | 1.49.2.17 | static void |
623 : | edgomez | 1.19 | decoder_iframe(DECODER * dec, |
624 : | syskin | 1.49.2.17 | Bitstream * bs, |
625 : | int reduced_resolution, | ||
626 : | int quant, | ||
627 : | int intra_dc_threshold) | ||
628 : | Isibaar | 1.1 | { |
629 : | chenm001 | 1.26 | uint32_t bound; |
630 : | uint32_t x, y; | ||
631 : | edgomez | 1.47 | uint32_t mb_width = dec->mb_width; |
632 : | uint32_t mb_height = dec->mb_height; | ||
633 : | edgomez | 1.49.2.13 | |
634 : | syskin | 1.49.2.17 | if (reduced_resolution) { |
635 : | edgomez | 1.47 | mb_width = (dec->width + 31) / 32; |
636 : | mb_height = (dec->height + 31) / 32; | ||
637 : | } | ||
638 : | chenm001 | 1.25 | |
639 : | chenm001 | 1.26 | bound = 0; |
640 : | edgomez | 1.7 | |
641 : | edgomez | 1.47 | for (y = 0; y < mb_height; y++) { |
642 : | for (x = 0; x < mb_width; x++) { | ||
643 : | chenm001 | 1.26 | MACROBLOCK *mb; |
644 : | Isibaar | 1.1 | uint32_t mcbpc; |
645 : | uint32_t cbpc; | ||
646 : | uint32_t acpred_flag; | ||
647 : | uint32_t cbpy; | ||
648 : | uint32_t cbp; | ||
649 : | |||
650 : | chenm001 | 1.26 | while (BitstreamShowBits(bs, 9) == 1) |
651 : | BitstreamSkip(bs, 9); | ||
652 : | |||
653 : | if (check_resync_marker(bs, 0)) | ||
654 : | { | ||
655 : | edgomez | 1.49.2.13 | bound = read_video_packet_header(bs, dec, 0, |
656 : | edgomez | 1.47 | &quant, NULL, NULL, &intra_dc_threshold); |
657 : | x = bound % mb_width; | ||
658 : | y = bound / mb_width; | ||
659 : | chenm001 | 1.26 | } |
660 : | mb = &dec->mbs[y * dec->mb_width + x]; | ||
661 : | |||
662 : | edgomez | 1.49.2.5 | DPRINTF(XVID_DEBUG_MB, "macroblock (%i,%i) %08x\n", x, y, BitstreamShowBits(bs, 32)); |
663 : | chenm001 | 1.26 | |
664 : | Isibaar | 1.1 | mcbpc = get_mcbpc_intra(bs); |
665 : | mb->mode = mcbpc & 7; | ||
666 : | cbpc = (mcbpc >> 4); | ||
667 : | |||
668 : | acpred_flag = BitstreamGetBit(bs); | ||
669 : | |||
670 : | cbpy = get_cbpy(bs, 1); | ||
671 : | cbp = (cbpy << 2) | cbpc; | ||
672 : | |||
673 : | edgomez | 1.19 | if (mb->mode == MODE_INTRA_Q) { |
674 : | quant += dquant_table[BitstreamGetBits(bs, 2)]; | ||
675 : | if (quant > 31) { | ||
676 : | Isibaar | 1.1 | quant = 31; |
677 : | edgomez | 1.19 | } else if (quant < 1) { |
678 : | Isibaar | 1.1 | quant = 1; |
679 : | } | ||
680 : | } | ||
681 : | mb->quant = quant; | ||
682 : | chenm001 | 1.30 | mb->mvs[0].x = mb->mvs[0].y = |
683 : | mb->mvs[1].x = mb->mvs[1].y = | ||
684 : | mb->mvs[2].x = mb->mvs[2].y = | ||
685 : | mb->mvs[3].x = mb->mvs[3].y =0; | ||
686 : | h | 1.5 | |
687 : | edgomez | 1.19 | if (dec->interlacing) { |
688 : | h | 1.5 | mb->field_dct = BitstreamGetBit(bs); |
689 : | edgomez | 1.49.2.5 | DPRINTF(XVID_DEBUG_MB,"deci: field_dct: %i\n", mb->field_dct); |
690 : | h | 1.5 | } |
691 : | Isibaar | 1.1 | |
692 : | edgomez | 1.19 | decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
693 : | edgomez | 1.47 | intra_dc_threshold, bound, reduced_resolution); |
694 : | |||
695 : | Isibaar | 1.1 | } |
696 : | albeu | 1.32 | if(dec->out_frm) |
697 : | syskin | 1.49.2.17 | output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,0,y,mb_width); |
698 : | Isibaar | 1.1 | } |
699 : | edgomez | 1.7 | |
700 : | Isibaar | 1.1 | } |
701 : | |||
702 : | |||
703 : | syskin | 1.49.2.17 | static void |
704 : | edgomez | 1.19 | get_motion_vector(DECODER * dec, |
705 : | syskin | 1.49.2.17 | Bitstream * bs, |
706 : | int x, | ||
707 : | int y, | ||
708 : | int k, | ||
709 : | VECTOR * ret_mv, | ||
710 : | int fcode, | ||
711 : | const int bound) | ||
712 : | Isibaar | 1.1 | { |
713 : | edgomez | 1.7 | |
714 : | syskin | 1.49.2.17 | const int scale_fac = 1 << (fcode - 1); |
715 : | const int high = (32 * scale_fac) - 1; | ||
716 : | const int low = ((-32) * scale_fac); | ||
717 : | const int range = (64 * scale_fac); | ||
718 : | Isibaar | 1.1 | |
719 : | syskin | 1.49.2.17 | const VECTOR pmv = get_pmv2(dec->mbs, dec->mb_width, bound, x, y, k); |
720 : | edgomez | 1.47 | VECTOR mv; |
721 : | Isibaar | 1.1 | |
722 : | edgomez | 1.47 | mv.x = get_mv(bs, fcode); |
723 : | mv.y = get_mv(bs, fcode); | ||
724 : | edgomez | 1.19 | |
725 : | edgomez | 1.49.2.5 | DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", mv.x, mv.y, pmv.x, pmv.y, mv.x+pmv.x, mv.y+pmv.y); |
726 : | chenm001 | 1.26 | |
727 : | edgomez | 1.47 | mv.x += pmv.x; |
728 : | mv.y += pmv.y; | ||
729 : | Isibaar | 1.1 | |
730 : | edgomez | 1.47 | if (mv.x < low) { |
731 : | mv.x += range; | ||
732 : | } else if (mv.x > high) { | ||
733 : | mv.x -= range; | ||
734 : | Isibaar | 1.1 | } |
735 : | |||
736 : | edgomez | 1.47 | if (mv.y < low) { |
737 : | mv.y += range; | ||
738 : | } else if (mv.y > high) { | ||
739 : | mv.y -= range; | ||
740 : | Isibaar | 1.1 | } |
741 : | |||
742 : | edgomez | 1.47 | ret_mv->x = mv.x; |
743 : | ret_mv->y = mv.y; | ||
744 : | } | ||
745 : | |||
746 : | /* for P_VOP set gmc_warp to NULL */ | ||
747 : | syskin | 1.49.2.17 | static void |
748 : | edgomez | 1.19 | decoder_pframe(DECODER * dec, |
749 : | syskin | 1.49.2.17 | Bitstream * bs, |
750 : | int rounding, | ||
751 : | int reduced_resolution, | ||
752 : | int quant, | ||
753 : | int fcode, | ||
754 : | int intra_dc_threshold, | ||
755 : | const WARPPOINTS *const gmc_warp) | ||
756 : | Isibaar | 1.1 | { |
757 : | uint32_t x, y; | ||
758 : | chenm001 | 1.26 | uint32_t bound; |
759 : | albeu | 1.32 | int cp_mb, st_mb; |
760 : | edgomez | 1.47 | uint32_t mb_width = dec->mb_width; |
761 : | uint32_t mb_height = dec->mb_height; | ||
762 : | edgomez | 1.49.2.13 | |
763 : | syskin | 1.49.2.17 | if (reduced_resolution) { |
764 : | edgomez | 1.47 | mb_width = (dec->width + 31) / 32; |
765 : | mb_height = (dec->height + 31) / 32; | ||
766 : | } | ||
767 : | Isibaar | 1.1 | |
768 : | start_timer(); | ||
769 : | edgomez | 1.19 | image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
770 : | syskin | 1.49.2.17 | dec->width, dec->height); |
771 : | Isibaar | 1.1 | stop_edges_timer(); |
772 : | |||
773 : | syskin | 1.49.2.17 | if (gmc_warp) { |
774 : | /* accuracy: 0==1/2, 1=1/4, 2=1/8, 3=1/16 */ | ||
775 : | edgomez | 1.49.2.13 | generate_GMCparameters( dec->sprite_warping_points, |
776 : | dec->sprite_warping_accuracy, gmc_warp, | ||
777 : | chl | 1.49.2.9 | dec->width, dec->height, &dec->new_gmc_data); |
778 : | edgomez | 1.47 | |
779 : | syskin | 1.49.2.17 | /* image warping is done block-based in decoder_mbgmc(), now */ |
780 : | edgomez | 1.47 | } |
781 : | |||
782 : | chenm001 | 1.26 | bound = 0; |
783 : | |||
784 : | edgomez | 1.47 | for (y = 0; y < mb_height; y++) { |
785 : | albeu | 1.32 | cp_mb = st_mb = 0; |
786 : | edgomez | 1.47 | for (x = 0; x < mb_width; x++) { |
787 : | chenm001 | 1.26 | MACROBLOCK *mb; |
788 : | |||
789 : | edgomez | 1.48 | /* skip stuffing */ |
790 : | chenm001 | 1.26 | while (BitstreamShowBits(bs, 10) == 1) |
791 : | BitstreamSkip(bs, 10); | ||
792 : | |||
793 : | syskin | 1.49.2.17 | if (check_resync_marker(bs, fcode - 1)) { |
794 : | edgomez | 1.49.2.13 | bound = read_video_packet_header(bs, dec, fcode - 1, |
795 : | edgomez | 1.47 | &quant, &fcode, NULL, &intra_dc_threshold); |
796 : | x = bound % mb_width; | ||
797 : | y = bound / mb_width; | ||
798 : | chenm001 | 1.26 | } |
799 : | mb = &dec->mbs[y * dec->mb_width + x]; | ||
800 : | |||
801 : | edgomez | 1.49.2.5 | DPRINTF(XVID_DEBUG_MB, "macroblock (%i,%i) %08x\n", x, y, BitstreamShowBits(bs, 32)); |
802 : | suxen_drol | 1.23 | |
803 : | syskin | 1.49.2.17 | if (!(BitstreamGetBit(bs))) { /* block _is_ coded */ |
804 : | uint32_t mcbpc, cbpc, cbpy, cbp; | ||
805 : | uint32_t intra, acpred_flag = 0; | ||
806 : | edgomez | 1.48 | int mcsel = 0; /* mcsel: '0'=local motion, '1'=GMC */ |
807 : | Isibaar | 1.1 | |
808 : | albeu | 1.32 | cp_mb++; |
809 : | Isibaar | 1.1 | mcbpc = get_mcbpc_inter(bs); |
810 : | mb->mode = mcbpc & 7; | ||
811 : | cbpc = (mcbpc >> 4); | ||
812 : | edgomez | 1.49.2.13 | |
813 : | edgomez | 1.49.2.5 | DPRINTF(XVID_DEBUG_MB, "mode %i\n", mb->mode); |
814 : | DPRINTF(XVID_DEBUG_MB, "cbpc %i\n", cbpc); | ||
815 : | Isibaar | 1.1 | |
816 : | intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q); | ||
817 : | edgomez | 1.19 | |
818 : | edgomez | 1.47 | if (gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)) |
819 : | mcsel = BitstreamGetBit(bs); | ||
820 : | syskin | 1.49.2.17 | else if (intra) |
821 : | edgomez | 1.49.2.12 | acpred_flag = BitstreamGetBit(bs); |
822 : | edgomez | 1.47 | |
823 : | chenm001 | 1.26 | cbpy = get_cbpy(bs, intra); |
824 : | syskin | 1.49.2.17 | DPRINTF(XVID_DEBUG_MB, "cbpy %i mcsel %i \n", cbpy,mcsel); |
825 : | chenm001 | 1.25 | |
826 : | Isibaar | 1.1 | cbp = (cbpy << 2) | cbpc; |
827 : | |||
828 : | edgomez | 1.19 | if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) { |
829 : | chenm001 | 1.26 | int dquant = dquant_table[BitstreamGetBits(bs, 2)]; |
830 : | edgomez | 1.49.2.5 | DPRINTF(XVID_DEBUG_MB, "dquant %i\n", dquant); |
831 : | chenm001 | 1.26 | quant += dquant; |
832 : | edgomez | 1.19 | if (quant > 31) { |
833 : | Isibaar | 1.1 | quant = 31; |
834 : | chenm001 | 1.26 | } else if (quant < 1) { |
835 : | Isibaar | 1.1 | quant = 1; |
836 : | } | ||
837 : | edgomez | 1.49.2.5 | DPRINTF(XVID_DEBUG_MB, "quant %i\n", quant); |
838 : | Isibaar | 1.1 | } |
839 : | mb->quant = quant; | ||
840 : | h | 1.5 | |
841 : | edgomez | 1.19 | if (dec->interlacing) { |
842 : | syskin | 1.49.2.14 | if ((cbp || intra) && !mcsel) { |
843 : | h | 1.37 | mb->field_dct = BitstreamGetBit(bs); |
844 : | edgomez | 1.49.2.5 | DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct); |
845 : | h | 1.37 | } |
846 : | h | 1.5 | |
847 : | edgomez | 1.19 | if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
848 : | h | 1.5 | mb->field_pred = BitstreamGetBit(bs); |
849 : | edgomez | 1.49.2.5 | DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred); |
850 : | h | 1.5 | |
851 : | edgomez | 1.19 | if (mb->field_pred) { |
852 : | h | 1.5 | mb->field_for_top = BitstreamGetBit(bs); |
853 : | edgomez | 1.49.2.5 | DPRINTF(XVID_DEBUG_MB,"decp: field_for_top: %i\n", mb->field_for_top); |
854 : | h | 1.5 | mb->field_for_bot = BitstreamGetBit(bs); |
855 : | edgomez | 1.49.2.5 | DPRINTF(XVID_DEBUG_MB,"decp: field_for_bot: %i\n", mb->field_for_bot); |
856 : | h | 1.5 | } |
857 : | } | ||
858 : | } | ||
859 : | edgomez | 1.49.2.13 | |
860 : | edgomez | 1.47 | if (mcsel) { |
861 : | syskin | 1.49.2.17 | decoder_mbgmc(dec, mb, x, y, fcode, cbp, bs, rounding); |
862 : | edgomez | 1.47 | continue; |
863 : | |||
864 : | } else if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { | ||
865 : | h | 1.5 | |
866 : | edgomez | 1.19 | if (dec->interlacing && mb->field_pred) { |
867 : | syskin | 1.49.2.17 | get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound); |
868 : | get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1], fcode, bound); | ||
869 : | edgomez | 1.19 | } else { |
870 : | syskin | 1.49.2.17 | get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound); |
871 : | edgomez | 1.47 | mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; |
872 : | h | 1.5 | } |
873 : | chl | 1.35 | } else if (mb->mode == MODE_INTER4V ) { |
874 : | chenm001 | 1.26 | get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound); |
875 : | get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode, bound); | ||
876 : | get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode, bound); | ||
877 : | get_motion_vector(dec, bs, x, y, 3, &mb->mvs[3], fcode, bound); | ||
878 : | syskin | 1.49.2.17 | } else { /* MODE_INTRA, MODE_INTRA_Q */ |
879 : | mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0; | ||
880 : | mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0; | ||
881 : | edgomez | 1.19 | decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
882 : | edgomez | 1.47 | intra_dc_threshold, bound, reduced_resolution); |
883 : | Isibaar | 1.1 | continue; |
884 : | } | ||
885 : | |||
886 : | syskin | 1.49.2.17 | decoder_mbinter(dec, mb, x, y, cbp, bs, |
887 : | rounding, reduced_resolution, 0); | ||
888 : | edgomez | 1.47 | |
889 : | syskin | 1.49.2.17 | } else if (gmc_warp) { /* a not coded S(GMC)-VOP macroblock */ |
890 : | edgomez | 1.47 | mb->mode = MODE_NOT_CODED_GMC; |
891 : | syskin | 1.49.2.17 | decoder_mbgmc(dec, mb, x, y, fcode, 0x00, bs, rounding); |
892 : | edgomez | 1.39 | |
893 : | edgomez | 1.47 | if(dec->out_frm && cp_mb > 0) { |
894 : | syskin | 1.49.2.17 | output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb); |
895 : | cp_mb = 0; | ||
896 : | edgomez | 1.47 | } |
897 : | st_mb = x+1; | ||
898 : | syskin | 1.49.2.17 | } else { /* not coded P_VOP macroblock */ |
899 : | chenm001 | 1.14 | mb->mode = MODE_NOT_CODED; |
900 : | edgomez | 1.47 | |
901 : | Isibaar | 1.1 | mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0; |
902 : | mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0; | ||
903 : | edgomez | 1.49.2.13 | |
904 : | syskin | 1.49.2.17 | decoder_mbinter(dec, mb, x, y, 0, bs, |
905 : | rounding, reduced_resolution, 0); | ||
906 : | edgomez | 1.47 | |
907 : | albeu | 1.32 | if(dec->out_frm && cp_mb > 0) { |
908 : | syskin | 1.49.2.17 | output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb); |
909 : | cp_mb = 0; | ||
910 : | albeu | 1.32 | } |
911 : | st_mb = x+1; | ||
912 : | Isibaar | 1.1 | } |
913 : | } | ||
914 : | syskin | 1.49.2.17 | |
915 : | albeu | 1.32 | if(dec->out_frm && cp_mb > 0) |
916 : | syskin | 1.49.2.17 | output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb); |
917 : | Isibaar | 1.1 | } |
918 : | } | ||
919 : | |||
920 : | edgomez | 1.47 | |
921 : | edgomez | 1.48 | /* decode B-frame motion vector */ |
922 : | syskin | 1.49.2.17 | static void |
923 : | get_b_motion_vector(Bitstream * bs, | ||
924 : | edgomez | 1.47 | VECTOR * mv, |
925 : | int fcode, | ||
926 : | const VECTOR pmv) | ||
927 : | chenm001 | 1.14 | { |
928 : | syskin | 1.49.2.17 | const int scale_fac = 1 << (fcode - 1); |
929 : | const int high = (32 * scale_fac) - 1; | ||
930 : | const int low = ((-32) * scale_fac); | ||
931 : | const int range = (64 * scale_fac); | ||
932 : | edgomez | 1.7 | |
933 : | syskin | 1.49.2.17 | int mv_x = get_mv(bs, fcode); |
934 : | int mv_y = get_mv(bs, fcode); | ||
935 : | Isibaar | 1.1 | |
936 : | syskin | 1.49.2.17 | mv_x += pmv.x; |
937 : | mv_y += pmv.y; | ||
938 : | albeu | 1.32 | |
939 : | syskin | 1.49.2.17 | if (mv_x < low) |
940 : | edgomez | 1.47 | mv_x += range; |
941 : | syskin | 1.49.2.17 | else if (mv_x > high) |
942 : | edgomez | 1.47 | mv_x -= range; |
943 : | |||
944 : | syskin | 1.49.2.17 | if (mv_y < low) |
945 : | edgomez | 1.47 | mv_y += range; |
946 : | syskin | 1.49.2.17 | else if (mv_y > high) |
947 : | edgomez | 1.47 | mv_y -= range; |
948 : | |||
949 : | mv->x = mv_x; | ||
950 : | mv->y = mv_y; | ||
951 : | } | ||
952 : | |||
953 : | syskin | 1.49.2.16 | /* decode an B-frame direct & interpolate macroblock */ |
954 : | syskin | 1.49.2.17 | static void |
955 : | edgomez | 1.47 | decoder_bf_interpolate_mbinter(DECODER * dec, |
956 : | syskin | 1.49.2.17 | IMAGE forward, |
957 : | IMAGE backward, | ||
958 : | const MACROBLOCK * pMB, | ||
959 : | const uint32_t x_pos, | ||
960 : | const uint32_t y_pos, | ||
961 : | Bitstream * bs, | ||
962 : | const int direct) | ||
963 : | edgomez | 1.47 | { |
964 : | uint32_t stride = dec->edged_width; | ||
965 : | uint32_t stride2 = stride / 2; | ||
966 : | uint32_t next_block = stride * 8; | ||
967 : | int uv_dx, uv_dy; | ||
968 : | int b_uv_dx, b_uv_dy; | ||
969 : | uint8_t *pY_Cur, *pU_Cur, *pV_Cur; | ||
970 : | syskin | 1.49.2.17 | const uint32_t cbp = pMB->cbp; |
971 : | edgomez | 1.47 | |
972 : | pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); | ||
973 : | pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); | ||
974 : | pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); | ||
975 : | |||
976 : | syskin | 1.49.2.16 | if (!direct) { |
977 : | edgomez | 1.47 | uv_dx = pMB->mvs[0].x; |
978 : | uv_dy = pMB->mvs[0].y; | ||
979 : | |||
980 : | b_uv_dx = pMB->b_mvs[0].x; | ||
981 : | b_uv_dy = pMB->b_mvs[0].y; | ||
982 : | |||
983 : | syskin | 1.49.2.17 | if (dec->quarterpel) { |
984 : | edgomez | 1.47 | uv_dx /= 2; |
985 : | uv_dy /= 2; | ||
986 : | b_uv_dx /= 2; | ||
987 : | b_uv_dy /= 2; | ||
988 : | } | ||
989 : | |||
990 : | uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; | ||
991 : | uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; | ||
992 : | |||
993 : | b_uv_dx = (b_uv_dx >> 1) + roundtab_79[b_uv_dx & 0x3]; | ||
994 : | b_uv_dy = (b_uv_dy >> 1) + roundtab_79[b_uv_dy & 0x3]; | ||
995 : | |||
996 : | syskin | 1.49.2.17 | } else { |
997 : | if(dec->quarterpel) { | ||
998 : | uv_dx = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2); | ||
999 : | uv_dy = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2); | ||
1000 : | b_uv_dx = (pMB->b_mvs[0].x / 2) + (pMB->b_mvs[1].x / 2) + (pMB->b_mvs[2].x / 2) + (pMB->b_mvs[3].x / 2); | ||
1001 : | b_uv_dy = (pMB->b_mvs[0].y / 2) + (pMB->b_mvs[1].y / 2) + (pMB->b_mvs[2].y / 2) + (pMB->b_mvs[3].y / 2); | ||
1002 : | } else { | ||
1003 : | uv_dx = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; | ||
1004 : | uv_dy = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; | ||
1005 : | b_uv_dx = pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x + pMB->b_mvs[3].x; | ||
1006 : | b_uv_dy = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y; | ||
1007 : | } | ||
1008 : | edgomez | 1.47 | |
1009 : | syskin | 1.49.2.17 | uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf]; |
1010 : | uv_dy = (uv_dy >> 3) + roundtab_76[uv_dy & 0xf]; | ||
1011 : | b_uv_dx = (b_uv_dx >> 3) + roundtab_76[b_uv_dx & 0xf]; | ||
1012 : | b_uv_dy = (b_uv_dy >> 3) + roundtab_76[b_uv_dy & 0xf]; | ||
1013 : | edgomez | 1.47 | } |
1014 : | |||
1015 : | start_timer(); | ||
1016 : | if(dec->quarterpel) { | ||
1017 : | syskin | 1.49.2.17 | if(!direct) { |
1018 : | edgomez | 1.47 | interpolate16x16_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1019 : | syskin | 1.49.2.17 | dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1020 : | pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); | ||
1021 : | } else { | ||
1022 : | edgomez | 1.47 | interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1023 : | syskin | 1.49.2.17 | dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1024 : | pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); | ||
1025 : | edgomez | 1.47 | interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1026 : | syskin | 1.49.2.17 | dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos, |
1027 : | pMB->mvs[1].x, pMB->mvs[1].y, stride, 0); | ||
1028 : | edgomez | 1.47 | interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1029 : | syskin | 1.49.2.17 | dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8, |
1030 : | pMB->mvs[2].x, pMB->mvs[2].y, stride, 0); | ||
1031 : | edgomez | 1.47 | interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1032 : | syskin | 1.49.2.17 | dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
1033 : | pMB->mvs[3].x, pMB->mvs[3].y, stride, 0); | ||
1034 : | edgomez | 1.47 | } |
1035 : | syskin | 1.49.2.17 | } else { |
1036 : | edgomez | 1.47 | interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos, |
1037 : | syskin | 1.49.2.17 | pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1038 : | edgomez | 1.47 | interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8, 16 * y_pos, |
1039 : | syskin | 1.49.2.17 | pMB->mvs[1].x, pMB->mvs[1].y, stride, 0); |
1040 : | edgomez | 1.47 | interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos + 8, |
1041 : | syskin | 1.49.2.17 | pMB->mvs[2].x, pMB->mvs[2].y, stride, 0); |
1042 : | edgomez | 1.47 | interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8, |
1043 : | syskin | 1.49.2.17 | 16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride, 0); |
1044 : | edgomez | 1.47 | } |
1045 : | |||
1046 : | interpolate8x8_switch(dec->cur.u, forward.u, 8 * x_pos, 8 * y_pos, uv_dx, | ||
1047 : | syskin | 1.49.2.17 | uv_dy, stride2, 0); |
1048 : | edgomez | 1.47 | interpolate8x8_switch(dec->cur.v, forward.v, 8 * x_pos, 8 * y_pos, uv_dx, |
1049 : | syskin | 1.49.2.17 | uv_dy, stride2, 0); |
1050 : | edgomez | 1.47 | |
1051 : | |||
1052 : | if(dec->quarterpel) { | ||
1053 : | syskin | 1.49.2.17 | if(!direct) { |
1054 : | edgomez | 1.47 | interpolate16x16_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1055 : | syskin | 1.49.2.17 | dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1056 : | pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); | ||
1057 : | } else { | ||
1058 : | edgomez | 1.47 | interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1059 : | syskin | 1.49.2.17 | dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1060 : | pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); | ||
1061 : | edgomez | 1.47 | interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1062 : | syskin | 1.49.2.17 | dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos, |
1063 : | pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0); | ||
1064 : | edgomez | 1.47 | interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1065 : | syskin | 1.49.2.17 | dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8, |
1066 : | pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0); | ||
1067 : | edgomez | 1.47 | interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1068 : | syskin | 1.49.2.17 | dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
1069 : | pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0); | ||
1070 : | edgomez | 1.47 | } |
1071 : | syskin | 1.49.2.17 | } else { |
1072 : | edgomez | 1.47 | interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos, 16 * y_pos, |
1073 : | syskin | 1.49.2.17 | pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
1074 : | edgomez | 1.47 | interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8, |
1075 : | syskin | 1.49.2.17 | 16 * y_pos, pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0); |
1076 : | edgomez | 1.47 | interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos, |
1077 : | syskin | 1.49.2.17 | 16 * y_pos + 8, pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0); |
1078 : | edgomez | 1.47 | interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8, |
1079 : | syskin | 1.49.2.17 | 16 * y_pos + 8, pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0); |
1080 : | edgomez | 1.47 | } |
1081 : | |||
1082 : | interpolate8x8_switch(dec->tmp.u, backward.u, 8 * x_pos, 8 * y_pos, | ||
1083 : | syskin | 1.49.2.17 | b_uv_dx, b_uv_dy, stride2, 0); |
1084 : | edgomez | 1.47 | interpolate8x8_switch(dec->tmp.v, backward.v, 8 * x_pos, 8 * y_pos, |
1085 : | syskin | 1.49.2.17 | b_uv_dx, b_uv_dy, stride2, 0); |
1086 : | edgomez | 1.47 | |
1087 : | interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, | ||
1088 : | dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, | ||
1089 : | dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos, | ||
1090 : | stride, 1, 8); | ||
1091 : | |||
1092 : | interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, | ||
1093 : | dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, | ||
1094 : | dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos + 8, | ||
1095 : | stride, 1, 8); | ||
1096 : | |||
1097 : | interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, | ||
1098 : | dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, | ||
1099 : | dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, | ||
1100 : | stride, 1, 8); | ||
1101 : | |||
1102 : | interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, | ||
1103 : | dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, | ||
1104 : | dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, | ||
1105 : | stride, 1, 8); | ||
1106 : | |||
1107 : | interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, | ||
1108 : | dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, | ||
1109 : | dec->tmp.u + (8 * y_pos * stride2) + 8 * x_pos, | ||
1110 : | stride2, 1, 8); | ||
1111 : | |||
1112 : | interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, | ||
1113 : | dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, | ||
1114 : | dec->tmp.v + (8 * y_pos * stride2) + 8 * x_pos, | ||
1115 : | stride2, 1, 8); | ||
1116 : | |||
1117 : | stop_comp_timer(); | ||
1118 : | |||
1119 : | syskin | 1.49.2.17 | if (cbp) |
1120 : | decoder_mb_decode(dec, cbp, bs, pY_Cur, pU_Cur, pV_Cur, 0, pMB); | ||
1121 : | edgomez | 1.47 | } |
1122 : | |||
1123 : | edgomez | 1.48 | /* for decode B-frame dbquant */ |
1124 : | syskin | 1.49.2.17 | static __inline int32_t |
1125 : | edgomez | 1.47 | get_dbquant(Bitstream * bs) |
1126 : | { | ||
1127 : | syskin | 1.49.2.17 | if (!BitstreamGetBit(bs)) /* '0' */ |
1128 : | edgomez | 1.47 | return (0); |
1129 : | syskin | 1.49.2.17 | else if (!BitstreamGetBit(bs)) /* '10' */ |
1130 : | edgomez | 1.47 | return (-2); |
1131 : | syskin | 1.49.2.17 | else /* '11' */ |
1132 : | edgomez | 1.48 | return (2); |
1133 : | edgomez | 1.47 | } |
1134 : | |||
1135 : | edgomez | 1.48 | /* |
1136 : | syskin | 1.49.2.17 | * decode B-frame mb_type |
1137 : | * bit ret_value | ||
1138 : | * 1 0 | ||
1139 : | * 01 1 | ||
1140 : | * 001 2 | ||
1141 : | * 0001 3 | ||
1142 : | edgomez | 1.48 | */ |
1143 : | syskin | 1.49.2.17 | static int32_t __inline |
1144 : | edgomez | 1.47 | get_mbtype(Bitstream * bs) |
1145 : | { | ||
1146 : | int32_t mb_type; | ||
1147 : | |||
1148 : | syskin | 1.49.2.17 | for (mb_type = 0; mb_type <= 3; mb_type++) |
1149 : | edgomez | 1.47 | if (BitstreamGetBit(bs)) |
1150 : | syskin | 1.49.2.17 | return (mb_type); |
1151 : | edgomez | 1.47 | |
1152 : | syskin | 1.49.2.17 | return -1; |
1153 : | edgomez | 1.47 | } |
1154 : | |||
1155 : | syskin | 1.49.2.17 | static void |
1156 : | edgomez | 1.47 | decoder_bframe(DECODER * dec, |
1157 : | syskin | 1.49.2.17 | Bitstream * bs, |
1158 : | int quant, | ||
1159 : | int fcode_forward, | ||
1160 : | int fcode_backward) | ||
1161 : | edgomez | 1.47 | { |
1162 : | uint32_t x, y; | ||
1163 : | VECTOR mv; | ||
1164 : | const VECTOR zeromv = {0,0}; | ||
1165 : | syskin | 1.49.2.17 | const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp; |
1166 : | int i; | ||
1167 : | |||
1168 : | edgomez | 1.47 | #ifdef BFRAMES_DEC_DEBUG |
1169 : | FILE *fp; | ||
1170 : | static char first=0; | ||
1171 : | syskin | 1.49.2.17 | #define BFRAME_DEBUG |
1172 : | if (!first && fp) { \ | ||
1173 : | syskin | 1.49.2.16 | fprintf(fp,"Y=%3d X=%3d MB=%2d CBP=%02X\n",y,x,mb->mode,mb->cbp); \ |
1174 : | edgomez | 1.47 | } |
1175 : | #endif | ||
1176 : | |||
1177 : | start_timer(); | ||
1178 : | image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, | ||
1179 : | syskin | 1.49.2.17 | dec->width, dec->height); |
1180 : | edgomez | 1.47 | image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, |
1181 : | syskin | 1.49.2.17 | dec->width, dec->height); |
1182 : | edgomez | 1.47 | stop_edges_timer(); |
1183 : | |||
1184 : | #ifdef BFRAMES_DEC_DEBUG | ||
1185 : | if (!first){ | ||
1186 : | fp=fopen("C:\\XVIDDBG.TXT","w"); | ||
1187 : | } | ||
1188 : | #endif | ||
1189 : | |||
1190 : | for (y = 0; y < dec->mb_height; y++) { | ||
1191 : | edgomez | 1.48 | /* Initialize Pred Motion Vector */ |
1192 : | edgomez | 1.47 | dec->p_fmv = dec->p_bmv = zeromv; |
1193 : | for (x = 0; x < dec->mb_width; x++) { | ||
1194 : | MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x]; | ||
1195 : | MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x]; | ||
1196 : | |||
1197 : | mv = | ||
1198 : | mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = | ||
1199 : | mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv; | ||
1200 : | syskin | 1.49.2.17 | mb->quant = quant; |
1201 : | edgomez | 1.47 | |
1202 : | edgomez | 1.48 | /* |
1203 : | edgomez | 1.49.2.13 | * skip if the co-located P_VOP macroblock is not coded |
1204 : | edgomez | 1.48 | * if not codec in co-located S_VOP macroblock is _not_ |
1205 : | * automatically skipped | ||
1206 : | */ | ||
1207 : | edgomez | 1.47 | |
1208 : | if (last_mb->mode == MODE_NOT_CODED) { | ||
1209 : | mb->cbp = 0; | ||
1210 : | syskin | 1.49.2.16 | mb->mode = MODE_FORWARD; |
1211 : | syskin | 1.49.2.17 | decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 1); |
1212 : | edgomez | 1.47 | continue; |
1213 : | } | ||
1214 : | |||
1215 : | edgomez | 1.48 | if (!BitstreamGetBit(bs)) { /* modb=='0' */ |
1216 : | edgomez | 1.47 | const uint8_t modb2 = BitstreamGetBit(bs); |
1217 : | |||
1218 : | syskin | 1.49.2.16 | mb->mode = get_mbtype(bs); |
1219 : | edgomez | 1.47 | |
1220 : | syskin | 1.49.2.17 | if (!modb2) /* modb=='00' */ |
1221 : | edgomez | 1.47 | mb->cbp = BitstreamGetBits(bs, 6); |
1222 : | syskin | 1.49.2.17 | else |
1223 : | edgomez | 1.47 | mb->cbp = 0; |
1224 : | syskin | 1.49.2.17 | |
1225 : | syskin | 1.49.2.16 | if (mb->mode && mb->cbp) { |
1226 : | edgomez | 1.47 | quant += get_dbquant(bs); |
1227 : | syskin | 1.49.2.17 | if (quant > 31) |
1228 : | edgomez | 1.47 | quant = 31; |
1229 : | syskin | 1.49.2.17 | else if (quant < 1) |
1230 : | edgomez | 1.47 | quant = 1; |
1231 : | } | ||
1232 : | syskin | 1.49.2.17 | mb->quant = quant; |
1233 : | syskin | 1.49.2.14 | |
1234 : | if (dec->interlacing) { | ||
1235 : | if (mb->cbp) { | ||
1236 : | mb->field_dct = BitstreamGetBit(bs); | ||
1237 : | DPRINTF(XVID_DEBUG_MB,"decp: field_dct: %i\n", mb->field_dct); | ||
1238 : | } | ||
1239 : | |||
1240 : | syskin | 1.49.2.16 | if (mb->mode) { |
1241 : | syskin | 1.49.2.14 | mb->field_pred = BitstreamGetBit(bs); |
1242 : | DPRINTF(XVID_DEBUG_MB, "decp: field_pred: %i\n", mb->field_pred); | ||
1243 : | |||
1244 : | if (mb->field_pred) { | ||
1245 : | mb->field_for_top = BitstreamGetBit(bs); | ||
1246 : | DPRINTF(XVID_DEBUG_MB,"decp: field_for_top: %i\n", mb->field_for_top); | ||
1247 : | mb->field_for_bot = BitstreamGetBit(bs); | ||
1248 : | DPRINTF(XVID_DEBUG_MB,"decp: field_for_bot: %i\n", mb->field_for_bot); | ||
1249 : | } | ||
1250 : | } | ||
1251 : | } | ||
1252 : | |||
1253 : | edgomez | 1.47 | } else { |
1254 : | syskin | 1.49.2.16 | mb->mode = MODE_DIRECT_NONE_MV; |
1255 : | edgomez | 1.47 | mb->cbp = 0; |
1256 : | } | ||
1257 : | |||
1258 : | syskin | 1.49.2.16 | switch (mb->mode) { |
1259 : | edgomez | 1.47 | case MODE_DIRECT: |
1260 : | syskin | 1.49.2.17 | get_b_motion_vector(bs, &mv, 1, zeromv); |
1261 : | edgomez | 1.47 | |
1262 : | case MODE_DIRECT_NONE_MV: | ||
1263 : | syskin | 1.49.2.17 | for (i = 0; i < 4; i++) { |
1264 : | mb->mvs[i].x = (int32_t) ((TRB * last_mb->mvs[i].x) / TRD + mv.x); | ||
1265 : | mb->b_mvs[i].x = (int32_t) ((mv.x == 0) | ||
1266 : | ? ((TRB - TRD) * last_mb->mvs[i].x) / TRD | ||
1267 : | : mb->mvs[i].x - last_mb->mvs[i].x); | ||
1268 : | mb->mvs[i].y = (int32_t) ((TRB * last_mb->mvs[i].y) / TRD + mv.y); | ||
1269 : | mb->b_mvs[i].y = (int32_t) ((mv.y == 0) | ||
1270 : | ? ((TRB - TRD) * last_mb->mvs[i].y) / TRD | ||
1271 : | : mb->mvs[i].y - last_mb->mvs[i].y); | ||
1272 : | edgomez | 1.47 | } |
1273 : | syskin | 1.49.2.17 | |
1274 : | edgomez | 1.47 | decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
1275 : | syskin | 1.49.2.17 | mb, x, y, bs, 1); |
1276 : | edgomez | 1.47 | break; |
1277 : | |||
1278 : | case MODE_INTERPOLATE: | ||
1279 : | syskin | 1.49.2.17 | get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv); |
1280 : | edgomez | 1.47 | dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; |
1281 : | |||
1282 : | syskin | 1.49.2.17 | get_b_motion_vector(bs, &mb->b_mvs[0], fcode_backward, dec->p_bmv); |
1283 : | dec->p_bmv = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = mb->b_mvs[0]; | ||
1284 : | edgomez | 1.47 | |
1285 : | decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], | ||
1286 : | syskin | 1.49.2.17 | mb, x, y, bs, 0); |
1287 : | edgomez | 1.47 | break; |
1288 : | |||
1289 : | case MODE_BACKWARD: | ||
1290 : | syskin | 1.49.2.17 | get_b_motion_vector(bs, &mb->mvs[0], fcode_backward, dec->p_bmv); |
1291 : | edgomez | 1.47 | dec->p_bmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; |
1292 : | |||
1293 : | syskin | 1.49.2.17 | decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 0); |
1294 : | edgomez | 1.47 | break; |
1295 : | |||
1296 : | case MODE_FORWARD: | ||
1297 : | syskin | 1.49.2.17 | get_b_motion_vector(bs, &mb->mvs[0], fcode_forward, dec->p_fmv); |
1298 : | edgomez | 1.47 | dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; |
1299 : | |||
1300 : | syskin | 1.49.2.17 | decoder_mbinter(dec, mb, x, y, mb->cbp, bs, 0, 0, 1); |
1301 : | edgomez | 1.47 | break; |
1302 : | |||
1303 : | default: | ||
1304 : | syskin | 1.49.2.16 | DPRINTF(XVID_DEBUG_ERROR,"Not supported B-frame mb_type = %i\n", mb->mode); |
1305 : | edgomez | 1.47 | } |
1306 : | edgomez | 1.48 | } /* End of for */ |
1307 : | } | ||
1308 : | edgomez | 1.47 | |
1309 : | #ifdef BFRAMES_DEC_DEBUG | ||
1310 : | if (!first){ | ||
1311 : | first=1; | ||
1312 : | if (fp) | ||
1313 : | fclose(fp); | ||
1314 : | } | ||
1315 : | #endif | ||
1316 : | } | ||
1317 : | |||
1318 : | /* perform post processing if necessary, and output the image */ | ||
1319 : | edgomez | 1.49.2.13 | void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs, |
1320 : | suxen_drol | 1.49.2.1 | xvid_dec_frame_t * frame, xvid_dec_stats_t * stats, int coding_type) |
1321 : | edgomez | 1.47 | { |
1322 : | image_output(img, dec->width, dec->height, | ||
1323 : | suxen_drol | 1.49.2.1 | dec->edged_width, (uint8_t**)frame->output.plane, frame->output.stride, |
1324 : | frame->output.csp, dec->interlacing); | ||
1325 : | |||
1326 : | syskin | 1.49.2.17 | if (stats) { |
1327 : | suxen_drol | 1.49.2.1 | stats->type = coding2type(coding_type); |
1328 : | stats->data.vop.time_base = (int)dec->time_base; | ||
1329 : | edgomez | 1.49.2.6 | stats->data.vop.time_increment = 0; /* XXX: todo */ |
1330 : | suxen_drol | 1.49.2.1 | } |
1331 : | edgomez | 1.47 | } |
1332 : | |||
1333 : | |||
1334 : | int | ||
1335 : | decoder_decode(DECODER * dec, | ||
1336 : | syskin | 1.49.2.17 | xvid_dec_frame_t * frame, xvid_dec_stats_t * stats) |
1337 : | edgomez | 1.47 | { |
1338 : | |||
1339 : | Bitstream bs; | ||
1340 : | uint32_t rounding; | ||
1341 : | uint32_t reduced_resolution; | ||
1342 : | uint32_t quant; | ||
1343 : | uint32_t fcode_forward; | ||
1344 : | uint32_t fcode_backward; | ||
1345 : | uint32_t intra_dc_threshold; | ||
1346 : | WARPPOINTS gmc_warp; | ||
1347 : | suxen_drol | 1.49.2.1 | int coding_type; |
1348 : | int success, output, seen_something; | ||
1349 : | edgomez | 1.47 | |
1350 : | edgomez | 1.49.2.10 | if (XVID_VERSION_MAJOR(frame->version) != 1 || (stats && XVID_VERSION_MAJOR(stats->version) != 1)) /* v1.x.x */ |
1351 : | suxen_drol | 1.49.2.1 | return XVID_ERR_VERSION; |
1352 : | edgomez | 1.47 | |
1353 : | suxen_drol | 1.49.2.1 | start_global_timer(); |
1354 : | edgomez | 1.47 | |
1355 : | suxen_drol | 1.49.2.1 | dec->low_delay_default = (frame->general & XVID_LOWDELAY); |
1356 : | if ((frame->general & XVID_DISCONTINUITY)) | ||
1357 : | edgomez | 1.47 | dec->frames = 0; |
1358 : | suxen_drol | 1.49.2.1 | dec->out_frm = (frame->output.csp == XVID_CSP_SLICE) ? &frame->output : NULL; |
1359 : | edgomez | 1.47 | |
1360 : | syskin | 1.49.2.17 | if (frame->length < 0) { /* decoder flush */ |
1361 : | int ret; | ||
1362 : | /* if not decoding "low_delay/packed", and this isn't low_delay and | ||
1363 : | we have a reference frame, then outout the reference frame */ | ||
1364 : | suxen_drol | 1.49.2.3 | if (!(dec->low_delay_default && dec->packed_mode) && !dec->low_delay && dec->frames>0) { |
1365 : | suxen_drol | 1.49.2.1 | decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type); |
1366 : | syskin | 1.49.2.17 | dec->frames = 0; |
1367 : | ret = 0; | ||
1368 : | } else { | ||
1369 : | if (stats) stats->type = XVID_TYPE_NOTHING; | ||
1370 : | ret = XVID_ERR_END; | ||
1371 : | } | ||
1372 : | edgomez | 1.47 | |
1373 : | emms(); | ||
1374 : | stop_global_timer(); | ||
1375 : | suxen_drol | 1.49.2.3 | return ret; |
1376 : | edgomez | 1.47 | } |
1377 : | edgomez | 1.19 | |
1378 : | Isibaar | 1.1 | BitstreamInit(&bs, frame->bitstream, frame->length); |
1379 : | |||
1380 : | edgomez | 1.48 | /* XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's */ |
1381 : | edgomez | 1.47 | if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f) |
1382 : | { | ||
1383 : | image_output(&dec->refn[0], dec->width, dec->height, dec->edged_width, | ||
1384 : | suxen_drol | 1.49.2.1 | (uint8_t**)frame->output.plane, frame->output.stride, frame->output.csp, dec->interlacing); |
1385 : | if (stats) stats->type = XVID_TYPE_NOTHING; | ||
1386 : | edgomez | 1.47 | emms(); |
1387 : | syskin | 1.49.2.17 | return 1; /* one byte consumed */ |
1388 : | edgomez | 1.47 | } |
1389 : | |||
1390 : | suxen_drol | 1.49.2.1 | success = 0; |
1391 : | output = 0; | ||
1392 : | seen_something = 0; | ||
1393 : | |||
1394 : | edgomez | 1.47 | repeat: |
1395 : | |||
1396 : | syskin | 1.49.2.17 | coding_type = BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, |
1397 : | edgomez | 1.47 | &quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp); |
1398 : | |||
1399 : | edgomez | 1.49.2.13 | DPRINTF(XVID_DEBUG_HEADER, "coding_type=%i, packed=%i, time=%lli, time_pp=%i, time_bp=%i\n", |
1400 : | suxen_drol | 1.49.2.1 | coding_type, dec->packed_mode, dec->time, dec->time_pp, dec->time_bp); |
1401 : | Isibaar | 1.1 | |
1402 : | syskin | 1.49.2.17 | if (coding_type == -1) { /* nothing */ |
1403 : | edgomez | 1.47 | if (success) goto done; |
1404 : | syskin | 1.49.2.17 | if (stats) stats->type = XVID_TYPE_NOTHING; |
1405 : | edgomez | 1.47 | emms(); |
1406 : | syskin | 1.49.2.17 | return BitstreamPos(&bs)/8; |
1407 : | Isibaar | 1.1 | } |
1408 : | |||
1409 : | syskin | 1.49.2.17 | if (coding_type == -2 || coding_type == -3) { /* vol and/or resize */ |
1410 : | |||
1411 : | suxen_drol | 1.49.2.1 | if (coding_type == -3) |
1412 : | edgomez | 1.47 | decoder_resize(dec); |
1413 : | edgomez | 1.49.2.13 | |
1414 : | syskin | 1.49.2.17 | if (stats) { |
1415 : | suxen_drol | 1.49.2.1 | stats->type = XVID_TYPE_VOL; |
1416 : | edgomez | 1.47 | stats->data.vol.general = 0; |
1417 : | suxen_drol | 1.49.2.1 | /*XXX: if (dec->interlacing) |
1418 : | stats->data.vol.general |= ++INTERLACING; */ | ||
1419 : | edgomez | 1.47 | stats->data.vol.width = dec->width; |
1420 : | stats->data.vol.height = dec->height; | ||
1421 : | suxen_drol | 1.49.2.1 | stats->data.vol.par = dec->aspect_ratio; |
1422 : | edgomez | 1.47 | stats->data.vol.par_width = dec->par_width; |
1423 : | stats->data.vol.par_height = dec->par_height; | ||
1424 : | emms(); | ||
1425 : | suxen_drol | 1.49.2.1 | return BitstreamPos(&bs)/8; /* number of bytes consumed */ |
1426 : | edgomez | 1.47 | } |
1427 : | goto repeat; | ||
1428 : | edgomez | 1.49.2.13 | } |
1429 : | edgomez | 1.47 | |
1430 : | edgomez | 1.48 | dec->p_bmv.x = dec->p_bmv.y = dec->p_fmv.y = dec->p_fmv.y = 0; /* init pred vector to 0 */ |
1431 : | edgomez | 1.47 | |
1432 : | /* packed_mode: special-N_VOP treament */ | ||
1433 : | syskin | 1.49.2.17 | if (dec->packed_mode && coding_type == N_VOP) { |
1434 : | if (dec->low_delay_default && dec->frames > 0) { | ||
1435 : | suxen_drol | 1.49.2.1 | decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type); |
1436 : | edgomez | 1.47 | output = 1; |
1437 : | } | ||
1438 : | /* ignore otherwise */ | ||
1439 : | syskin | 1.49.2.17 | } else if (coding_type != B_VOP) { |
1440 : | switch(coding_type) { | ||
1441 : | edgomez | 1.47 | case I_VOP : |
1442 : | decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold); | ||
1443 : | break; | ||
1444 : | case P_VOP : | ||
1445 : | edgomez | 1.49.2.13 | decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, |
1446 : | edgomez | 1.47 | fcode_forward, intra_dc_threshold, NULL); |
1447 : | break; | ||
1448 : | case S_VOP : | ||
1449 : | edgomez | 1.49.2.13 | decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, |
1450 : | edgomez | 1.47 | fcode_forward, intra_dc_threshold, &gmc_warp); |
1451 : | break; | ||
1452 : | case N_VOP : | ||
1453 : | edgomez | 1.49.2.6 | /* XXX: not_coded vops are not used for forward prediction */ |
1454 : | /* we should not swap(last_mbs,mbs) */ | ||
1455 : | edgomez | 1.47 | image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
1456 : | break; | ||
1457 : | } | ||
1458 : | |||
1459 : | syskin | 1.49.2.17 | if (reduced_resolution) { |
1460 : | edgomez | 1.47 | image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs, |
1461 : | (dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width, | ||
1462 : | suxen_drol | 1.49.2.1 | 16, 0); |
1463 : | edgomez | 1.47 | } |
1464 : | Isibaar | 1.1 | |
1465 : | edgomez | 1.47 | /* note: for packed_mode, output is performed when the special-N_VOP is decoded */ |
1466 : | syskin | 1.49.2.17 | if (!(dec->low_delay_default && dec->packed_mode)) { |
1467 : | if (dec->low_delay) { | ||
1468 : | suxen_drol | 1.49.2.1 | decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type); |
1469 : | edgomez | 1.47 | output = 1; |
1470 : | syskin | 1.49.2.17 | } else if (dec->frames > 0) { /* is the reference frame valid? */ |
1471 : | edgomez | 1.47 | /* output the reference frame */ |
1472 : | suxen_drol | 1.49.2.1 | decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type); |
1473 : | edgomez | 1.47 | output = 1; |
1474 : | } | ||
1475 : | } | ||
1476 : | Isibaar | 1.18 | |
1477 : | chenm001 | 1.14 | image_swap(&dec->refn[0], &dec->refn[1]); |
1478 : | image_swap(&dec->cur, &dec->refn[0]); | ||
1479 : | syskin | 1.49.2.17 | SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs); |
1480 : | edgomez | 1.47 | dec->last_reduced_resolution = reduced_resolution; |
1481 : | syskin | 1.49.2.17 | dec->last_coding_type = coding_type; |
1482 : | edgomez | 1.47 | |
1483 : | dec->frames++; | ||
1484 : | seen_something = 1; | ||
1485 : | chenm001 | 1.31 | |
1486 : | syskin | 1.49.2.17 | } else { /* B_VOP */ |
1487 : | edgomez | 1.47 | |
1488 : | syskin | 1.49.2.17 | if (dec->low_delay) { |
1489 : | edgomez | 1.49.2.5 | DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n"); |
1490 : | edgomez | 1.47 | dec->low_delay = 1; |
1491 : | } | ||
1492 : | |||
1493 : | syskin | 1.49.2.17 | if (dec->frames < 2) { |
1494 : | edgomez | 1.47 | /* attemping to decode a bvop without atleast 2 reference frames */ |
1495 : | image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, | ||
1496 : | "broken b-frame, mising ref frames"); | ||
1497 : | syskin | 1.49.2.17 | } else if (dec->time_pp <= dec->time_bp) { |
1498 : | edgomez | 1.49.2.13 | /* this occurs when dx50_bvop_compatibility==0 sequences are |
1499 : | edgomez | 1.47 | decoded in vfw. */ |
1500 : | image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, | ||
1501 : | "broken b-frame, tpp=%i tbp=%i", dec->time_pp, dec->time_bp); | ||
1502 : | syskin | 1.49.2.17 | } else { |
1503 : | edgomez | 1.47 | decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); |
1504 : | } | ||
1505 : | |||
1506 : | suxen_drol | 1.49.2.1 | decoder_output(dec, &dec->cur, dec->mbs, frame, stats, coding_type); |
1507 : | edgomez | 1.47 | output = 1; |
1508 : | dec->frames++; | ||
1509 : | chenm001 | 1.14 | } |
1510 : | |||
1511 : | edgomez | 1.47 | BitstreamByteAlign(&bs); |
1512 : | |||
1513 : | /* low_delay_default mode: repeat in packed_mode */ | ||
1514 : | syskin | 1.49.2.17 | if (dec->low_delay_default && dec->packed_mode && output == 0 && success == 0) { |
1515 : | edgomez | 1.47 | success = 1; |
1516 : | goto repeat; | ||
1517 : | } | ||
1518 : | |||
1519 : | done : | ||
1520 : | |||
1521 : | /* low_delay_default mode: if we've gotten here without outputting anything, | ||
1522 : | then output the recently decoded frame, or print an error message */ | ||
1523 : | syskin | 1.49.2.17 | if (dec->low_delay_default && output == 0) { |
1524 : | if (dec->packed_mode && seen_something) { | ||
1525 : | edgomez | 1.47 | /* output the recently decoded frame */ |
1526 : | suxen_drol | 1.49.2.1 | decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, stats, dec->last_coding_type); |
1527 : | syskin | 1.49.2.17 | } else { |
1528 : | edgomez | 1.47 | image_clear(&dec->cur, dec->width, dec->height, dec->edged_width, 0, 128, 128); |
1529 : | image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, | ||
1530 : | "warning: nothing to output"); | ||
1531 : | image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64, | ||
1532 : | "bframe decoder lag"); | ||
1533 : | |||
1534 : | edgomez | 1.49.2.13 | decoder_output(dec, &dec->cur, NULL, frame, stats, P_VOP); |
1535 : | suxen_drol | 1.49.2.1 | if (stats) stats->type = XVID_TYPE_NOTHING; |
1536 : | edgomez | 1.47 | } |
1537 : | } | ||
1538 : | |||
1539 : | Isibaar | 1.1 | emms(); |
1540 : | stop_global_timer(); | ||
1541 : | |||
1542 : | suxen_drol | 1.49.2.1 | return BitstreamPos(&bs) / 8; /* number of bytes consumed */ |
1543 : | Isibaar | 1.1 | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |