Parent Directory
|
Revision Log
Revision 69 -
(view)
(download)
Original Path: trunk/xvidcore/src/decoder.c
1 : | Isibaar | 3 | /************************************************************************** |
2 : | * | ||
3 : | * XVID MPEG-4 VIDEO CODEC | ||
4 : | * decoder main | ||
5 : | * | ||
6 : | * This program is an implementation of a part of one or more MPEG-4 | ||
7 : | * Video tools as specified in ISO/IEC 14496-2 standard. Those intending | ||
8 : | * to use this software module in hardware or software products are | ||
9 : | * advised that its use may infringe existing patents or copyrights, and | ||
10 : | * any such use would be at such party's own risk. The original | ||
11 : | * developer of this software module and his/her company, and subsequent | ||
12 : | * editors and their companies, will have no liability for use of this | ||
13 : | * software or modifications or derivatives thereof. | ||
14 : | * | ||
15 : | Isibaar | 41 | * This program is xvid_free software; you can redistribute it and/or modify |
16 : | Isibaar | 3 | * it under the terms of the GNU General Public License as published by |
17 : | Isibaar | 41 | * the xvid_free Software Foundation; either version 2 of the License, or |
18 : | Isibaar | 3 | * (at your option) any later version. |
19 : | * | ||
20 : | * This program is distributed in the hope that it will be useful, | ||
21 : | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
22 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
23 : | * GNU General Public License for more details. | ||
24 : | * | ||
25 : | * You should have received a copy of the GNU General Public License | ||
26 : | Isibaar | 41 | * along with this program; if not, write to the xvid_free Software |
27 : | Isibaar | 3 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
28 : | * | ||
29 : | *************************************************************************/ | ||
30 : | |||
31 : | /************************************************************************** | ||
32 : | * | ||
33 : | * History: | ||
34 : | * | ||
35 : | h | 69 | * 26.03.2002 interlacing support - moved transfers outside decode loop |
36 : | Isibaar | 3 | * 26.12.2001 decoder_mbinter: dequant/idct moved within if(coded) block |
37 : | * 22.12.2001 block based interpolation | ||
38 : | * 01.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> | ||
39 : | * | ||
40 : | *************************************************************************/ | ||
41 : | |||
42 : | #include <stdlib.h> | ||
43 : | #include <string.h> // memset | ||
44 : | |||
45 : | #include "xvid.h" | ||
46 : | #include "portab.h" | ||
47 : | |||
48 : | #include "decoder.h" | ||
49 : | #include "bitstream/bitstream.h" | ||
50 : | #include "bitstream/mbcoding.h" | ||
51 : | |||
52 : | #include "quant/quant_h263.h" | ||
53 : | #include "quant/quant_mpeg4.h" | ||
54 : | #include "dct/idct.h" | ||
55 : | #include "dct/fdct.h" | ||
56 : | #include "utils/mem_transfer.h" | ||
57 : | #include "image/interpolate8x8.h" | ||
58 : | h | 69 | #include "utils/mbfunctions.h" |
59 : | Isibaar | 3 | |
60 : | #include "bitstream/mbcoding.h" | ||
61 : | #include "prediction/mbprediction.h" | ||
62 : | #include "utils/timer.h" | ||
63 : | #include "utils/emms.h" | ||
64 : | |||
65 : | #include "image/image.h" | ||
66 : | #include "image/colorspace.h" | ||
67 : | Isibaar | 41 | #include "utils/mem_align.h" |
68 : | Isibaar | 3 | |
69 : | int decoder_create(XVID_DEC_PARAM * param) | ||
70 : | { | ||
71 : | DECODER * dec; | ||
72 : | |||
73 : | Isibaar | 42 | dec = xvid_malloc(sizeof(DECODER), CACHE_LINE); |
74 : | Isibaar | 3 | if (dec == NULL) |
75 : | { | ||
76 : | return XVID_ERR_MEMORY; | ||
77 : | } | ||
78 : | param->handle = dec; | ||
79 : | |||
80 : | dec->width = param->width; | ||
81 : | dec->height = param->height; | ||
82 : | |||
83 : | dec->mb_width = (dec->width + 15) / 16; | ||
84 : | dec->mb_height = (dec->height + 15) / 16; | ||
85 : | |||
86 : | dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE; | ||
87 : | dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE; | ||
88 : | |||
89 : | if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) | ||
90 : | { | ||
91 : | Isibaar | 41 | xvid_free(dec); |
92 : | Isibaar | 3 | return XVID_ERR_MEMORY; |
93 : | } | ||
94 : | |||
95 : | if (image_create(&dec->refn, dec->edged_width, dec->edged_height)) | ||
96 : | { | ||
97 : | image_destroy(&dec->cur, dec->edged_width, dec->edged_height); | ||
98 : | Isibaar | 41 | xvid_free(dec); |
99 : | Isibaar | 3 | return XVID_ERR_MEMORY; |
100 : | } | ||
101 : | |||
102 : | Isibaar | 42 | dec->mbs = xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, CACHE_LINE); |
103 : | Isibaar | 3 | if (dec->mbs == NULL) |
104 : | { | ||
105 : | image_destroy(&dec->cur, dec->edged_width, dec->edged_height); | ||
106 : | Isibaar | 41 | xvid_free(dec); |
107 : | Isibaar | 3 | return XVID_ERR_MEMORY; |
108 : | } | ||
109 : | |||
110 : | init_timer(); | ||
111 : | create_vlc_tables(); | ||
112 : | |||
113 : | return XVID_ERR_OK; | ||
114 : | } | ||
115 : | |||
116 : | |||
117 : | int decoder_destroy(DECODER * dec) | ||
118 : | { | ||
119 : | Isibaar | 41 | xvid_free(dec->mbs); |
120 : | Isibaar | 3 | image_destroy(&dec->refn, dec->edged_width, dec->edged_height); |
121 : | image_destroy(&dec->cur, dec->edged_width, dec->edged_height); | ||
122 : | Isibaar | 41 | xvid_free(dec); |
123 : | Isibaar | 3 | |
124 : | destroy_vlc_tables(); | ||
125 : | |||
126 : | write_timer(); | ||
127 : | return XVID_ERR_OK; | ||
128 : | } | ||
129 : | |||
130 : | |||
131 : | |||
132 : | static const int32_t dquant_table[4] = | ||
133 : | { | ||
134 : | -1, -2, 1, 2 | ||
135 : | }; | ||
136 : | |||
137 : | |||
138 : | // decode an intra macroblock | ||
139 : | |||
140 : | h | 69 | void decoder_mbintra(DECODER * dec, |
141 : | MACROBLOCK * pMB, | ||
142 : | const uint32_t x_pos, | ||
143 : | const uint32_t y_pos, | ||
144 : | const uint32_t acpred_flag, | ||
145 : | const uint32_t cbp, | ||
146 : | Bitstream * bs, | ||
147 : | const uint32_t quant, | ||
148 : | const uint32_t intra_dc_threshold) | ||
149 : | Isibaar | 3 | { |
150 : | h | 69 | CACHE_ALIGN int16_t block[6][64]; |
151 : | CACHE_ALIGN int16_t data[6][64]; | ||
152 : | Isibaar | 3 | |
153 : | h | 69 | const uint32_t stride = dec->edged_width; |
154 : | uint32_t i; | ||
155 : | uint32_t iQuant = pMB->quant; | ||
156 : | uint8_t *pY_Cur, *pU_Cur, *pV_Cur; | ||
157 : | |||
158 : | pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); | ||
159 : | pU_Cur = dec->cur.u + (y_pos << 3) * (stride >> 1) + (x_pos << 3); | ||
160 : | pV_Cur = dec->cur.v + (y_pos << 3) * (stride >> 1) + (x_pos << 3); | ||
161 : | |||
162 : | memset(block, 0, sizeof(block)); // clear | ||
163 : | |||
164 : | for (i = 0; i < 6; i++) | ||
165 : | Isibaar | 3 | { |
166 : | h | 69 | uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
167 : | Isibaar | 3 | int16_t predictors[8]; |
168 : | int start_coeff; | ||
169 : | |||
170 : | start_timer(); | ||
171 : | h | 69 | predict_acdc(dec->mbs, x_pos, y_pos, dec->mb_width, i, block[i], iQuant, iDcScaler, predictors); |
172 : | Isibaar | 3 | if (!acpred_flag) |
173 : | { | ||
174 : | h | 69 | pMB->acpred_directions[i] = 0; |
175 : | Isibaar | 3 | } |
176 : | stop_prediction_timer(); | ||
177 : | |||
178 : | if (quant < intra_dc_threshold) | ||
179 : | { | ||
180 : | int dc_size; | ||
181 : | int dc_dif; | ||
182 : | |||
183 : | h | 69 | dc_size = i < 4 ? get_dc_size_lum(bs) : get_dc_size_chrom(bs); |
184 : | Isibaar | 3 | dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0 ; |
185 : | |||
186 : | if (dc_size > 8) | ||
187 : | { | ||
188 : | BitstreamSkip(bs, 1); // marker | ||
189 : | } | ||
190 : | |||
191 : | h | 69 | block[i][0] = dc_dif; |
192 : | Isibaar | 3 | start_coeff = 1; |
193 : | } | ||
194 : | else | ||
195 : | { | ||
196 : | start_coeff = 0; | ||
197 : | } | ||
198 : | |||
199 : | start_timer(); | ||
200 : | h | 69 | if (cbp & (1 << (5-i))) // coded |
201 : | Isibaar | 3 | { |
202 : | h | 69 | get_intra_block(bs, block[i], pMB->acpred_directions[i], start_coeff); |
203 : | Isibaar | 3 | } |
204 : | stop_coding_timer(); | ||
205 : | |||
206 : | start_timer(); | ||
207 : | h | 69 | add_acdc(pMB, i, block[i], iDcScaler, predictors); |
208 : | Isibaar | 3 | stop_prediction_timer(); |
209 : | |||
210 : | start_timer(); | ||
211 : | if (dec->quant_type == 0) | ||
212 : | { | ||
213 : | h | 69 | dequant_intra(data[i], block[i], iQuant, iDcScaler); |
214 : | Isibaar | 3 | } |
215 : | else | ||
216 : | { | ||
217 : | h | 69 | dequant4_intra(data[i], block[i], iQuant, iDcScaler); |
218 : | Isibaar | 3 | } |
219 : | stop_iquant_timer(); | ||
220 : | |||
221 : | start_timer(); | ||
222 : | h | 69 | idct(data[i]); |
223 : | Isibaar | 3 | stop_idct_timer(); |
224 : | h | 69 | } |
225 : | Isibaar | 3 | |
226 : | h | 69 | start_timer(); |
227 : | if (dec->interlacing && pMB->field_dct) | ||
228 : | { | ||
229 : | MBFieldToFrame(data); | ||
230 : | Isibaar | 3 | } |
231 : | h | 69 | stop_interlacing_timer(); |
232 : | |||
233 : | start_timer(); | ||
234 : | transfer_16to8copy(pY_Cur, data[0], stride); | ||
235 : | transfer_16to8copy(pY_Cur + 8, data[1], stride); | ||
236 : | transfer_16to8copy(pY_Cur + 8 * stride, data[2], stride); | ||
237 : | transfer_16to8copy(pY_Cur + 8 + 8 * stride, data[3], stride); | ||
238 : | transfer_16to8copy(pU_Cur, data[4], stride / 2); | ||
239 : | transfer_16to8copy(pV_Cur, data[5], stride / 2); | ||
240 : | stop_transfer_timer(); | ||
241 : | Isibaar | 3 | } |
242 : | |||
243 : | |||
244 : | |||
245 : | |||
246 : | |||
247 : | #define SIGN(X) (((X)>0)?1:-1) | ||
248 : | #define ABS(X) (((X)>0)?(X):-(X)) | ||
249 : | static const uint32_t roundtab[16] = | ||
250 : | { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 }; | ||
251 : | |||
252 : | |||
253 : | // decode an inter macroblock | ||
254 : | |||
255 : | h | 69 | void decoder_mbinter(DECODER * dec, |
256 : | const MACROBLOCK * pMB, | ||
257 : | const uint32_t x_pos, | ||
258 : | const uint32_t y_pos, | ||
259 : | const uint32_t acpred_flag, | ||
260 : | const uint32_t cbp, | ||
261 : | Bitstream * bs, | ||
262 : | const uint32_t quant, | ||
263 : | const uint32_t rounding) | ||
264 : | Isibaar | 3 | { |
265 : | h | 69 | CACHE_ALIGN int16_t block[6][64]; |
266 : | CACHE_ALIGN int16_t data[6][64]; | ||
267 : | |||
268 : | Isibaar | 3 | const uint32_t stride = dec->edged_width; |
269 : | const uint32_t stride2 = dec->edged_width / 2; | ||
270 : | h | 69 | uint32_t i; |
271 : | uint32_t iQuant = pMB->quant; | ||
272 : | uint8_t *pY_Cur, *pU_Cur, *pV_Cur; | ||
273 : | Isibaar | 3 | int uv_dx, uv_dy; |
274 : | |||
275 : | h | 69 | pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
276 : | pU_Cur = dec->cur.u + (y_pos << 3) * (stride >> 1) + (x_pos << 3); | ||
277 : | pV_Cur = dec->cur.v + (y_pos << 3) * (stride >> 1) + (x_pos << 3); | ||
278 : | |||
279 : | if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) | ||
280 : | Isibaar | 3 | { |
281 : | h | 69 | uv_dx = pMB->mvs[0].x; |
282 : | uv_dy = pMB->mvs[0].y; | ||
283 : | Isibaar | 3 | |
284 : | uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2; | ||
285 : | uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2; | ||
286 : | } | ||
287 : | else | ||
288 : | { | ||
289 : | int sum; | ||
290 : | h | 69 | sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
291 : | Isibaar | 3 | uv_dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) ); |
292 : | |||
293 : | h | 69 | sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
294 : | Isibaar | 3 | uv_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) ); |
295 : | } | ||
296 : | |||
297 : | start_timer(); | ||
298 : | h | 69 | interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x_pos, 16*y_pos , pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
299 : | interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x_pos + 8, 16*y_pos , pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); | ||
300 : | interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x_pos, 16*y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); | ||
301 : | interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x_pos + 8, 16*y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); | ||
302 : | interpolate8x8_switch(dec->cur.u, dec->refn.u, 8*x_pos, 8*y_pos, uv_dx, uv_dy, stride2, rounding); | ||
303 : | interpolate8x8_switch(dec->cur.v, dec->refn.v, 8*x_pos, 8*y_pos, uv_dx, uv_dy, stride2, rounding); | ||
304 : | Isibaar | 3 | stop_comp_timer(); |
305 : | |||
306 : | h | 69 | for (i = 0; i < 6; i++) |
307 : | Isibaar | 3 | { |
308 : | h | 69 | if (cbp & (1 << (5-i))) // coded |
309 : | Isibaar | 3 | { |
310 : | h | 69 | memset(block[i], 0, 64 * sizeof(int16_t)); // clear |
311 : | Isibaar | 3 | |
312 : | start_timer(); | ||
313 : | h | 69 | get_inter_block(bs, block[i]); |
314 : | Isibaar | 3 | stop_coding_timer(); |
315 : | |||
316 : | start_timer(); | ||
317 : | if (dec->quant_type == 0) | ||
318 : | { | ||
319 : | h | 69 | dequant_inter(data[i], block[i], iQuant); |
320 : | Isibaar | 3 | } |
321 : | else | ||
322 : | { | ||
323 : | h | 69 | dequant4_inter(data[i], block[i], iQuant); |
324 : | Isibaar | 3 | } |
325 : | stop_iquant_timer(); | ||
326 : | |||
327 : | start_timer(); | ||
328 : | h | 69 | idct(data[i]); |
329 : | Isibaar | 3 | stop_idct_timer(); |
330 : | } | ||
331 : | } | ||
332 : | h | 69 | |
333 : | start_timer(); | ||
334 : | if (pMB->field_dct) | ||
335 : | { | ||
336 : | MBFieldToFrame(data); | ||
337 : | } | ||
338 : | stop_interlacing_timer(); | ||
339 : | |||
340 : | start_timer(); | ||
341 : | if (cbp & 32) | ||
342 : | transfer_16to8add(pY_Cur, data[0], stride); | ||
343 : | if (cbp & 16) | ||
344 : | transfer_16to8add(pY_Cur + 8, data[1], stride); | ||
345 : | if (cbp & 8) | ||
346 : | transfer_16to8add(pY_Cur + 8 * stride, data[2], stride); | ||
347 : | if (cbp & 4) | ||
348 : | transfer_16to8add(pY_Cur + 8 + 8 * stride, data[3], stride); | ||
349 : | if (cbp & 2) | ||
350 : | transfer_16to8add(pU_Cur, data[4], stride / 2); | ||
351 : | if (cbp & 1) | ||
352 : | transfer_16to8add(pV_Cur, data[5], stride / 2); | ||
353 : | stop_transfer_timer(); | ||
354 : | Isibaar | 3 | } |
355 : | |||
356 : | |||
357 : | void decoder_iframe(DECODER * dec, Bitstream * bs, int quant, int intra_dc_threshold) | ||
358 : | { | ||
359 : | uint32_t x, y; | ||
360 : | |||
361 : | for (y = 0; y < dec->mb_height; y++) | ||
362 : | { | ||
363 : | for (x = 0; x < dec->mb_width; x++) | ||
364 : | { | ||
365 : | MACROBLOCK * mb = &dec->mbs[y*dec->mb_width + x]; | ||
366 : | |||
367 : | uint32_t mcbpc; | ||
368 : | uint32_t cbpc; | ||
369 : | uint32_t acpred_flag; | ||
370 : | uint32_t cbpy; | ||
371 : | uint32_t cbp; | ||
372 : | |||
373 : | mcbpc = get_mcbpc_intra(bs); | ||
374 : | mb->mode = mcbpc & 7; | ||
375 : | cbpc = (mcbpc >> 4); | ||
376 : | |||
377 : | acpred_flag = BitstreamGetBit(bs); | ||
378 : | |||
379 : | if (mb->mode == MODE_STUFFING) | ||
380 : | { | ||
381 : | DEBUG("-- STUFFING ?"); | ||
382 : | continue; | ||
383 : | } | ||
384 : | |||
385 : | cbpy = get_cbpy(bs, 1); | ||
386 : | cbp = (cbpy << 2) | cbpc; | ||
387 : | |||
388 : | if (mb->mode == MODE_INTRA_Q) | ||
389 : | { | ||
390 : | quant += dquant_table[BitstreamGetBits(bs,2)]; | ||
391 : | if (quant > 31) | ||
392 : | { | ||
393 : | quant = 31; | ||
394 : | } | ||
395 : | else if (quant < 1) | ||
396 : | { | ||
397 : | quant = 1; | ||
398 : | } | ||
399 : | } | ||
400 : | mb->quant = quant; | ||
401 : | |||
402 : | h | 69 | if (dec->interlacing) |
403 : | { | ||
404 : | mb->field_dct = BitstreamGetBit(bs); | ||
405 : | DEBUG1("deci: field_dct: ", mb->field_dct); | ||
406 : | } | ||
407 : | |||
408 : | Isibaar | 3 | decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, intra_dc_threshold); |
409 : | } | ||
410 : | } | ||
411 : | } | ||
412 : | |||
413 : | |||
414 : | void get_motion_vector(DECODER *dec, Bitstream *bs, int x, int y, int k, VECTOR * mv, int fcode) | ||
415 : | { | ||
416 : | int scale_fac = 1 << (fcode - 1); | ||
417 : | int high = (32 * scale_fac) - 1; | ||
418 : | int low = ((-32) * scale_fac); | ||
419 : | int range = (64 * scale_fac); | ||
420 : | |||
421 : | VECTOR pmv[4]; | ||
422 : | uint32_t psad[4]; | ||
423 : | |||
424 : | int mv_x, mv_y; | ||
425 : | int pmv_x, pmv_y; | ||
426 : | |||
427 : | |||
428 : | get_pmvdata(dec->mbs, x, y, dec->mb_width, k, pmv, psad); | ||
429 : | |||
430 : | pmv_x = pmv[0].x; | ||
431 : | pmv_y = pmv[0].y; | ||
432 : | |||
433 : | mv_x = get_mv(bs, fcode); | ||
434 : | mv_y = get_mv(bs, fcode); | ||
435 : | |||
436 : | mv_x += pmv_x; | ||
437 : | mv_y += pmv_y; | ||
438 : | |||
439 : | if (mv_x < low) | ||
440 : | { | ||
441 : | mv_x += range; | ||
442 : | } | ||
443 : | else if (mv_x > high) | ||
444 : | { | ||
445 : | mv_x -= range; | ||
446 : | } | ||
447 : | |||
448 : | if (mv_y < low) | ||
449 : | { | ||
450 : | mv_y += range; | ||
451 : | } | ||
452 : | else if (mv_y > high) | ||
453 : | { | ||
454 : | mv_y -= range; | ||
455 : | } | ||
456 : | |||
457 : | mv->x = mv_x; | ||
458 : | mv->y = mv_y; | ||
459 : | |||
460 : | } | ||
461 : | |||
462 : | |||
463 : | void decoder_pframe(DECODER * dec, Bitstream * bs, int rounding, int quant, int fcode, int intra_dc_threshold) | ||
464 : | { | ||
465 : | uint32_t x, y; | ||
466 : | |||
467 : | image_swap(&dec->cur, &dec->refn); | ||
468 : | |||
469 : | start_timer(); | ||
470 : | h | 69 | image_setedges(&dec->refn, dec->edged_width, dec->edged_height, dec->width, dec->height, dec->interlacing); |
471 : | Isibaar | 3 | stop_edges_timer(); |
472 : | |||
473 : | for (y = 0; y < dec->mb_height; y++) | ||
474 : | { | ||
475 : | for (x = 0; x < dec->mb_width; x++) | ||
476 : | { | ||
477 : | MACROBLOCK * mb = &dec->mbs[y*dec->mb_width + x]; | ||
478 : | |||
479 : | if (!BitstreamGetBit(bs)) // not_coded | ||
480 : | { | ||
481 : | uint32_t mcbpc; | ||
482 : | uint32_t cbpc; | ||
483 : | uint32_t acpred_flag; | ||
484 : | uint32_t cbpy; | ||
485 : | uint32_t cbp; | ||
486 : | uint32_t intra; | ||
487 : | |||
488 : | mcbpc = get_mcbpc_inter(bs); | ||
489 : | mb->mode = mcbpc & 7; | ||
490 : | cbpc = (mcbpc >> 4); | ||
491 : | edgomez | 12 | acpred_flag = 0; |
492 : | Isibaar | 3 | |
493 : | intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q); | ||
494 : | |||
495 : | if (intra) | ||
496 : | { | ||
497 : | acpred_flag = BitstreamGetBit(bs); | ||
498 : | } | ||
499 : | |||
500 : | if (mb->mode == MODE_STUFFING) | ||
501 : | { | ||
502 : | DEBUG("-- STUFFING ?"); | ||
503 : | continue; | ||
504 : | } | ||
505 : | |||
506 : | cbpy = get_cbpy(bs, intra); | ||
507 : | cbp = (cbpy << 2) | cbpc; | ||
508 : | |||
509 : | if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) | ||
510 : | { | ||
511 : | quant += dquant_table[BitstreamGetBits(bs,2)]; | ||
512 : | if (quant > 31) | ||
513 : | { | ||
514 : | quant = 31; | ||
515 : | } | ||
516 : | else if (mb->quant < 1) | ||
517 : | { | ||
518 : | quant = 1; | ||
519 : | } | ||
520 : | } | ||
521 : | mb->quant = quant; | ||
522 : | h | 69 | |
523 : | if (dec->interlacing) | ||
524 : | Isibaar | 3 | { |
525 : | h | 69 | mb->field_dct = BitstreamGetBit(bs); |
526 : | DEBUG1("decp: field_dct: ", mb->field_dct); | ||
527 : | Isibaar | 3 | |
528 : | h | 69 | if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) |
529 : | { | ||
530 : | mb->field_pred = BitstreamGetBit(bs); | ||
531 : | DEBUG1("decp: field_pred: ", mb->field_pred); | ||
532 : | |||
533 : | if (mb->field_pred) | ||
534 : | { | ||
535 : | mb->field_for_top = BitstreamGetBit(bs); | ||
536 : | DEBUG1("decp: field_for_top: ", mb->field_for_top); | ||
537 : | mb->field_for_bot = BitstreamGetBit(bs); | ||
538 : | DEBUG1("decp: field_for_bot: ", mb->field_for_bot); | ||
539 : | } | ||
540 : | } | ||
541 : | Isibaar | 3 | } |
542 : | h | 69 | |
543 : | if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) | ||
544 : | { | ||
545 : | if (dec->interlacing && mb->field_pred) | ||
546 : | { | ||
547 : | get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode); | ||
548 : | get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1], fcode); | ||
549 : | } | ||
550 : | else | ||
551 : | { | ||
552 : | get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode); | ||
553 : | mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x; | ||
554 : | mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y; | ||
555 : | } | ||
556 : | } | ||
557 : | Isibaar | 3 | else if (mb->mode == MODE_INTER4V /* || mb->mode == MODE_INTER4V_Q */) |
558 : | { | ||
559 : | get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode); | ||
560 : | get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode); | ||
561 : | get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode); | ||
562 : | get_motion_vector(dec, bs, x, y, 3, &mb->mvs[3], fcode); | ||
563 : | } | ||
564 : | else // MODE_INTRA, MODE_INTRA_Q | ||
565 : | { | ||
566 : | mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0; | ||
567 : | mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0; | ||
568 : | decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, intra_dc_threshold); | ||
569 : | continue; | ||
570 : | } | ||
571 : | |||
572 : | decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant, rounding); | ||
573 : | } | ||
574 : | else // not coded | ||
575 : | { | ||
576 : | |||
577 : | mb->mode = MODE_NOT_CODED; | ||
578 : | mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0; | ||
579 : | mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0; | ||
580 : | |||
581 : | // copy macroblock directly from ref to cur | ||
582 : | |||
583 : | start_timer(); | ||
584 : | |||
585 : | transfer8x8_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x), | ||
586 : | dec->refn.y + (16*y)*dec->edged_width + (16*x), | ||
587 : | dec->edged_width); | ||
588 : | |||
589 : | transfer8x8_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x+8), | ||
590 : | dec->refn.y + (16*y)*dec->edged_width + (16*x+8), | ||
591 : | dec->edged_width); | ||
592 : | |||
593 : | transfer8x8_copy(dec->cur.y + (16*y+8)*dec->edged_width + (16*x), | ||
594 : | dec->refn.y + (16*y+8)*dec->edged_width + (16*x), | ||
595 : | dec->edged_width); | ||
596 : | |||
597 : | transfer8x8_copy(dec->cur.y + (16*y+8)*dec->edged_width + (16*x+8), | ||
598 : | dec->refn.y + (16*y+8)*dec->edged_width + (16*x+8), | ||
599 : | dec->edged_width); | ||
600 : | |||
601 : | transfer8x8_copy(dec->cur.u + (8*y)*dec->edged_width/2 + (8*x), | ||
602 : | dec->refn.u + (8*y)*dec->edged_width/2 + (8*x), | ||
603 : | dec->edged_width/2); | ||
604 : | |||
605 : | transfer8x8_copy(dec->cur.v + (8*y)*dec->edged_width/2 + (8*x), | ||
606 : | dec->refn.v + (8*y)*dec->edged_width/2 + (8*x), | ||
607 : | dec->edged_width/2); | ||
608 : | |||
609 : | stop_transfer_timer(); | ||
610 : | } | ||
611 : | } | ||
612 : | } | ||
613 : | } | ||
614 : | |||
615 : | int decoder_decode(DECODER * dec, XVID_DEC_FRAME * frame) | ||
616 : | { | ||
617 : | Bitstream bs; | ||
618 : | uint32_t rounding; | ||
619 : | uint32_t quant; | ||
620 : | uint32_t fcode; | ||
621 : | uint32_t intra_dc_threshold; | ||
622 : | |||
623 : | start_global_timer(); | ||
624 : | |||
625 : | BitstreamInit(&bs, frame->bitstream, frame->length); | ||
626 : | |||
627 : | switch (BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode, &intra_dc_threshold)) | ||
628 : | { | ||
629 : | case P_VOP : | ||
630 : | decoder_pframe(dec, &bs, rounding, quant, fcode, intra_dc_threshold); | ||
631 : | break; | ||
632 : | |||
633 : | case I_VOP : | ||
634 : | //DEBUG1("",intra_dc_threshold); | ||
635 : | decoder_iframe(dec, &bs, quant, intra_dc_threshold); | ||
636 : | break; | ||
637 : | |||
638 : | case B_VOP : // ignore | ||
639 : | break; | ||
640 : | |||
641 : | case N_VOP : // vop not coded | ||
642 : | break; | ||
643 : | |||
644 : | default : | ||
645 : | return XVID_ERR_FAIL; | ||
646 : | } | ||
647 : | |||
648 : | frame->length = BitstreamPos(&bs) / 8; | ||
649 : | |||
650 : | start_timer(); | ||
651 : | image_output(&dec->cur, dec->width, dec->height, dec->edged_width, | ||
652 : | frame->image, frame->stride, frame->colorspace); | ||
653 : | stop_conv_timer(); | ||
654 : | |||
655 : | emms(); | ||
656 : | |||
657 : | stop_global_timer(); | ||
658 : | |||
659 : | return XVID_ERR_OK; | ||
660 : | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |