[cvs] / xvidcore / src / decoder.c Repository:
ViewVC logotype

Annotation of /xvidcore/src/decoder.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (view) (download)

1 : Isibaar 1.1 /**************************************************************************
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 1.3 * This program is xvid_free software; you can redistribute it and/or modify
16 : Isibaar 1.1 * it under the terms of the GNU General Public License as published by
17 : Isibaar 1.3 * the xvid_free Software Foundation; either version 2 of the License, or
18 : Isibaar 1.1 * (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 1.3 * along with this program; if not, write to the xvid_free Software
27 : Isibaar 1.1 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 :     *
29 :     *************************************************************************/
30 :    
31 :     /**************************************************************************
32 :     *
33 :     * History:
34 :     *
35 : h 1.5 * 26.03.2002 interlacing support - moved transfers outside decode loop
36 : Isibaar 1.1 * 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 1.5 #include "utils/mbfunctions.h"
59 : Isibaar 1.1
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 1.3 #include "utils/mem_align.h"
68 : Isibaar 1.1
69 :     int decoder_create(XVID_DEC_PARAM * param)
70 :     {
71 :     DECODER * dec;
72 :    
73 : Isibaar 1.4 dec = xvid_malloc(sizeof(DECODER), CACHE_LINE);
74 : Isibaar 1.1 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 1.3 xvid_free(dec);
92 : Isibaar 1.1 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 1.3 xvid_free(dec);
99 : Isibaar 1.1 return XVID_ERR_MEMORY;
100 :     }
101 :    
102 : Isibaar 1.4 dec->mbs = xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, CACHE_LINE);
103 : Isibaar 1.1 if (dec->mbs == NULL)
104 :     {
105 :     image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
106 : Isibaar 1.3 xvid_free(dec);
107 : Isibaar 1.1 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 1.3 xvid_free(dec->mbs);
120 : Isibaar 1.1 image_destroy(&dec->refn, dec->edged_width, dec->edged_height);
121 :     image_destroy(&dec->cur, dec->edged_width, dec->edged_height);
122 : Isibaar 1.3 xvid_free(dec);
123 : Isibaar 1.1
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 1.5 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 1.1 {
150 : canard 1.6 #ifdef LINUX
151 :     DECLARE_ALIGNED_MATRIX(block,6,64,int16_t,16);
152 :     DECLARE_ALIGNED_MATRIX(data,6,64,int16_t,16);
153 :     #else
154 : h 1.5 CACHE_ALIGN int16_t block[6][64];
155 :     CACHE_ALIGN int16_t data[6][64];
156 : canard 1.6 #endif
157 : h 1.5 const uint32_t stride = dec->edged_width;
158 :     uint32_t i;
159 :     uint32_t iQuant = pMB->quant;
160 :     uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
161 :    
162 :     pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
163 :     pU_Cur = dec->cur.u + (y_pos << 3) * (stride >> 1) + (x_pos << 3);
164 :     pV_Cur = dec->cur.v + (y_pos << 3) * (stride >> 1) + (x_pos << 3);
165 :    
166 : canard 1.6 #ifdef LINUX
167 :     memset(block,0,sizeof(int16_t)*6*64);
168 :     #else
169 : h 1.5 memset(block, 0, sizeof(block)); // clear
170 : canard 1.6 #endif
171 : h 1.5
172 :     for (i = 0; i < 6; i++)
173 : Isibaar 1.1 {
174 : h 1.5 uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
175 : Isibaar 1.1 int16_t predictors[8];
176 :     int start_coeff;
177 :    
178 :     start_timer();
179 : h 1.5 predict_acdc(dec->mbs, x_pos, y_pos, dec->mb_width, i, block[i], iQuant, iDcScaler, predictors);
180 : Isibaar 1.1 if (!acpred_flag)
181 :     {
182 : h 1.5 pMB->acpred_directions[i] = 0;
183 : Isibaar 1.1 }
184 :     stop_prediction_timer();
185 :    
186 :     if (quant < intra_dc_threshold)
187 :     {
188 :     int dc_size;
189 :     int dc_dif;
190 :    
191 : h 1.5 dc_size = i < 4 ? get_dc_size_lum(bs) : get_dc_size_chrom(bs);
192 : Isibaar 1.1 dc_dif = dc_size ? get_dc_dif(bs, dc_size) : 0 ;
193 :    
194 :     if (dc_size > 8)
195 :     {
196 :     BitstreamSkip(bs, 1); // marker
197 :     }
198 :    
199 : h 1.5 block[i][0] = dc_dif;
200 : Isibaar 1.1 start_coeff = 1;
201 :     }
202 :     else
203 :     {
204 :     start_coeff = 0;
205 :     }
206 :    
207 :     start_timer();
208 : h 1.5 if (cbp & (1 << (5-i))) // coded
209 : Isibaar 1.1 {
210 : h 1.5 get_intra_block(bs, block[i], pMB->acpred_directions[i], start_coeff);
211 : Isibaar 1.1 }
212 :     stop_coding_timer();
213 :    
214 :     start_timer();
215 : h 1.5 add_acdc(pMB, i, block[i], iDcScaler, predictors);
216 : Isibaar 1.1 stop_prediction_timer();
217 :    
218 :     start_timer();
219 :     if (dec->quant_type == 0)
220 :     {
221 : h 1.5 dequant_intra(data[i], block[i], iQuant, iDcScaler);
222 : Isibaar 1.1 }
223 :     else
224 :     {
225 : h 1.5 dequant4_intra(data[i], block[i], iQuant, iDcScaler);
226 : Isibaar 1.1 }
227 :     stop_iquant_timer();
228 :    
229 :     start_timer();
230 : h 1.5 idct(data[i]);
231 : Isibaar 1.1 stop_idct_timer();
232 : h 1.5 }
233 : Isibaar 1.1
234 : h 1.5 start_timer();
235 :     if (dec->interlacing && pMB->field_dct)
236 :     {
237 :     MBFieldToFrame(data);
238 : Isibaar 1.1 }
239 : h 1.5 stop_interlacing_timer();
240 :    
241 :     start_timer();
242 :     transfer_16to8copy(pY_Cur, data[0], stride);
243 :     transfer_16to8copy(pY_Cur + 8, data[1], stride);
244 :     transfer_16to8copy(pY_Cur + 8 * stride, data[2], stride);
245 :     transfer_16to8copy(pY_Cur + 8 + 8 * stride, data[3], stride);
246 :     transfer_16to8copy(pU_Cur, data[4], stride / 2);
247 :     transfer_16to8copy(pV_Cur, data[5], stride / 2);
248 :     stop_transfer_timer();
249 : Isibaar 1.1 }
250 :    
251 :    
252 :    
253 :    
254 :    
255 :     #define SIGN(X) (((X)>0)?1:-1)
256 :     #define ABS(X) (((X)>0)?(X):-(X))
257 :     static const uint32_t roundtab[16] =
258 :     { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 };
259 :    
260 :    
261 :     // decode an inter macroblock
262 :    
263 : h 1.5 void decoder_mbinter(DECODER * dec,
264 :     const MACROBLOCK * pMB,
265 :     const uint32_t x_pos,
266 :     const uint32_t y_pos,
267 :     const uint32_t acpred_flag,
268 :     const uint32_t cbp,
269 :     Bitstream * bs,
270 :     const uint32_t quant,
271 :     const uint32_t rounding)
272 : Isibaar 1.1 {
273 : canard 1.6 #ifdef LINUX
274 :     DECLARE_ALIGNED_MATRIX(block,6,64,int16_t,16);
275 :     DECLARE_ALIGNED_MATRIX(data,6,64,int16_t,16);
276 :     #else
277 : h 1.5 CACHE_ALIGN int16_t block[6][64];
278 :     CACHE_ALIGN int16_t data[6][64];
279 : canard 1.6 #endif
280 : h 1.5
281 : Isibaar 1.1 const uint32_t stride = dec->edged_width;
282 :     const uint32_t stride2 = dec->edged_width / 2;
283 : h 1.5 uint32_t i;
284 :     uint32_t iQuant = pMB->quant;
285 :     uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
286 : Isibaar 1.1 int uv_dx, uv_dy;
287 :    
288 : h 1.5 pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4);
289 :     pU_Cur = dec->cur.u + (y_pos << 3) * (stride >> 1) + (x_pos << 3);
290 :     pV_Cur = dec->cur.v + (y_pos << 3) * (stride >> 1) + (x_pos << 3);
291 :    
292 :     if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)
293 : Isibaar 1.1 {
294 : h 1.5 uv_dx = pMB->mvs[0].x;
295 :     uv_dy = pMB->mvs[0].y;
296 : Isibaar 1.1
297 :     uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2;
298 :     uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2;
299 :     }
300 :     else
301 :     {
302 :     int sum;
303 : h 1.5 sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x;
304 : Isibaar 1.1 uv_dx = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) );
305 :    
306 : h 1.5 sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y;
307 : Isibaar 1.1 uv_dy = (sum == 0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + (ABS(sum) / 16) * 2) );
308 :     }
309 :    
310 :     start_timer();
311 : h 1.5 interpolate8x8_switch(dec->cur.y, dec->refn.y, 16*x_pos, 16*y_pos , pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding);
312 :     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);
313 :     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);
314 :     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);
315 :     interpolate8x8_switch(dec->cur.u, dec->refn.u, 8*x_pos, 8*y_pos, uv_dx, uv_dy, stride2, rounding);
316 :     interpolate8x8_switch(dec->cur.v, dec->refn.v, 8*x_pos, 8*y_pos, uv_dx, uv_dy, stride2, rounding);
317 : Isibaar 1.1 stop_comp_timer();
318 :    
319 : h 1.5 for (i = 0; i < 6; i++)
320 : Isibaar 1.1 {
321 : h 1.5 if (cbp & (1 << (5-i))) // coded
322 : Isibaar 1.1 {
323 : h 1.5 memset(block[i], 0, 64 * sizeof(int16_t)); // clear
324 : Isibaar 1.1
325 :     start_timer();
326 : h 1.5 get_inter_block(bs, block[i]);
327 : Isibaar 1.1 stop_coding_timer();
328 :    
329 :     start_timer();
330 :     if (dec->quant_type == 0)
331 :     {
332 : h 1.5 dequant_inter(data[i], block[i], iQuant);
333 : Isibaar 1.1 }
334 :     else
335 :     {
336 : h 1.5 dequant4_inter(data[i], block[i], iQuant);
337 : Isibaar 1.1 }
338 :     stop_iquant_timer();
339 :    
340 :     start_timer();
341 : h 1.5 idct(data[i]);
342 : Isibaar 1.1 stop_idct_timer();
343 : h 1.5 }
344 :     }
345 : Isibaar 1.1
346 : h 1.5 start_timer();
347 :     if (pMB->field_dct)
348 :     {
349 :     MBFieldToFrame(data);
350 : Isibaar 1.1 }
351 : h 1.5 stop_interlacing_timer();
352 :    
353 :     start_timer();
354 :     if (cbp & 32)
355 :     transfer_16to8add(pY_Cur, data[0], stride);
356 :     if (cbp & 16)
357 :     transfer_16to8add(pY_Cur + 8, data[1], stride);
358 :     if (cbp & 8)
359 :     transfer_16to8add(pY_Cur + 8 * stride, data[2], stride);
360 :     if (cbp & 4)
361 :     transfer_16to8add(pY_Cur + 8 + 8 * stride, data[3], stride);
362 :     if (cbp & 2)
363 :     transfer_16to8add(pU_Cur, data[4], stride / 2);
364 :     if (cbp & 1)
365 :     transfer_16to8add(pV_Cur, data[5], stride / 2);
366 :     stop_transfer_timer();
367 : Isibaar 1.1 }
368 :    
369 :    
370 :     void decoder_iframe(DECODER * dec, Bitstream * bs, int quant, int intra_dc_threshold)
371 :     {
372 :     uint32_t x, y;
373 :    
374 :     for (y = 0; y < dec->mb_height; y++)
375 :     {
376 :     for (x = 0; x < dec->mb_width; x++)
377 :     {
378 :     MACROBLOCK * mb = &dec->mbs[y*dec->mb_width + x];
379 :    
380 :     uint32_t mcbpc;
381 :     uint32_t cbpc;
382 :     uint32_t acpred_flag;
383 :     uint32_t cbpy;
384 :     uint32_t cbp;
385 :    
386 :     mcbpc = get_mcbpc_intra(bs);
387 :     mb->mode = mcbpc & 7;
388 :     cbpc = (mcbpc >> 4);
389 :    
390 :     acpred_flag = BitstreamGetBit(bs);
391 :    
392 :     if (mb->mode == MODE_STUFFING)
393 :     {
394 :     DEBUG("-- STUFFING ?");
395 :     continue;
396 :     }
397 :    
398 :     cbpy = get_cbpy(bs, 1);
399 :     cbp = (cbpy << 2) | cbpc;
400 :    
401 :     if (mb->mode == MODE_INTRA_Q)
402 :     {
403 :     quant += dquant_table[BitstreamGetBits(bs,2)];
404 :     if (quant > 31)
405 :     {
406 :     quant = 31;
407 :     }
408 :     else if (quant < 1)
409 :     {
410 :     quant = 1;
411 :     }
412 :     }
413 :     mb->quant = quant;
414 : h 1.5
415 :     if (dec->interlacing)
416 :     {
417 :     mb->field_dct = BitstreamGetBit(bs);
418 :     DEBUG1("deci: field_dct: ", mb->field_dct);
419 :     }
420 : Isibaar 1.1
421 :     decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, intra_dc_threshold);
422 :     }
423 :     }
424 :     }
425 :    
426 :    
427 :     void get_motion_vector(DECODER *dec, Bitstream *bs, int x, int y, int k, VECTOR * mv, int fcode)
428 :     {
429 :     int scale_fac = 1 << (fcode - 1);
430 :     int high = (32 * scale_fac) - 1;
431 :     int low = ((-32) * scale_fac);
432 :     int range = (64 * scale_fac);
433 :    
434 :     VECTOR pmv[4];
435 :     uint32_t psad[4];
436 :    
437 :     int mv_x, mv_y;
438 :     int pmv_x, pmv_y;
439 :    
440 :    
441 :     get_pmvdata(dec->mbs, x, y, dec->mb_width, k, pmv, psad);
442 :    
443 :     pmv_x = pmv[0].x;
444 :     pmv_y = pmv[0].y;
445 :    
446 :     mv_x = get_mv(bs, fcode);
447 :     mv_y = get_mv(bs, fcode);
448 :    
449 :     mv_x += pmv_x;
450 :     mv_y += pmv_y;
451 :    
452 :     if (mv_x < low)
453 :     {
454 :     mv_x += range;
455 :     }
456 :     else if (mv_x > high)
457 :     {
458 :     mv_x -= range;
459 :     }
460 :    
461 :     if (mv_y < low)
462 :     {
463 :     mv_y += range;
464 :     }
465 :     else if (mv_y > high)
466 :     {
467 :     mv_y -= range;
468 :     }
469 :    
470 :     mv->x = mv_x;
471 :     mv->y = mv_y;
472 :    
473 :     }
474 :    
475 :    
476 :     void decoder_pframe(DECODER * dec, Bitstream * bs, int rounding, int quant, int fcode, int intra_dc_threshold)
477 :     {
478 :     uint32_t x, y;
479 :    
480 :     image_swap(&dec->cur, &dec->refn);
481 :    
482 :     start_timer();
483 : h 1.5 image_setedges(&dec->refn, dec->edged_width, dec->edged_height, dec->width, dec->height, dec->interlacing);
484 : Isibaar 1.1 stop_edges_timer();
485 :    
486 :     for (y = 0; y < dec->mb_height; y++)
487 :     {
488 :     for (x = 0; x < dec->mb_width; x++)
489 :     {
490 :     MACROBLOCK * mb = &dec->mbs[y*dec->mb_width + x];
491 :    
492 :     if (!BitstreamGetBit(bs)) // not_coded
493 :     {
494 :     uint32_t mcbpc;
495 :     uint32_t cbpc;
496 :     uint32_t acpred_flag;
497 :     uint32_t cbpy;
498 :     uint32_t cbp;
499 :     uint32_t intra;
500 :    
501 :     mcbpc = get_mcbpc_inter(bs);
502 :     mb->mode = mcbpc & 7;
503 :     cbpc = (mcbpc >> 4);
504 : edgomez 1.2 acpred_flag = 0;
505 : Isibaar 1.1
506 :     intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q);
507 :    
508 :     if (intra)
509 :     {
510 :     acpred_flag = BitstreamGetBit(bs);
511 :     }
512 :    
513 :     if (mb->mode == MODE_STUFFING)
514 :     {
515 :     DEBUG("-- STUFFING ?");
516 :     continue;
517 :     }
518 :    
519 :     cbpy = get_cbpy(bs, intra);
520 :     cbp = (cbpy << 2) | cbpc;
521 :    
522 :     if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q)
523 :     {
524 :     quant += dquant_table[BitstreamGetBits(bs,2)];
525 :     if (quant > 31)
526 :     {
527 :     quant = 31;
528 :     }
529 :     else if (mb->quant < 1)
530 :     {
531 :     quant = 1;
532 :     }
533 :     }
534 :     mb->quant = quant;
535 : h 1.5
536 :     if (dec->interlacing)
537 :     {
538 :     mb->field_dct = BitstreamGetBit(bs);
539 :     DEBUG1("decp: field_dct: ", mb->field_dct);
540 :    
541 :     if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)
542 :     {
543 :     mb->field_pred = BitstreamGetBit(bs);
544 :     DEBUG1("decp: field_pred: ", mb->field_pred);
545 :    
546 :     if (mb->field_pred)
547 :     {
548 :     mb->field_for_top = BitstreamGetBit(bs);
549 :     DEBUG1("decp: field_for_top: ", mb->field_for_top);
550 :     mb->field_for_bot = BitstreamGetBit(bs);
551 :     DEBUG1("decp: field_for_bot: ", mb->field_for_bot);
552 :     }
553 :     }
554 :     }
555 :    
556 : Isibaar 1.1 if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)
557 :     {
558 : h 1.5 if (dec->interlacing && mb->field_pred)
559 :     {
560 :     get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode);
561 :     get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1], fcode);
562 :     }
563 :     else
564 :     {
565 :     get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode);
566 :     mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x;
567 :     mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y;
568 :     }
569 : Isibaar 1.1 }
570 :     else if (mb->mode == MODE_INTER4V /* || mb->mode == MODE_INTER4V_Q */)
571 :     {
572 :     get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode);
573 :     get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode);
574 :     get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode);
575 :     get_motion_vector(dec, bs, x, y, 3, &mb->mvs[3], fcode);
576 :     }
577 :     else // MODE_INTRA, MODE_INTRA_Q
578 :     {
579 :     mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0;
580 :     mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0;
581 :     decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, intra_dc_threshold);
582 :     continue;
583 :     }
584 :    
585 :     decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant, rounding);
586 :     }
587 :     else // not coded
588 :     {
589 :    
590 :     mb->mode = MODE_NOT_CODED;
591 :     mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0;
592 :     mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0;
593 :    
594 :     // copy macroblock directly from ref to cur
595 :    
596 :     start_timer();
597 :    
598 :     transfer8x8_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x),
599 :     dec->refn.y + (16*y)*dec->edged_width + (16*x),
600 :     dec->edged_width);
601 :    
602 :     transfer8x8_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x+8),
603 :     dec->refn.y + (16*y)*dec->edged_width + (16*x+8),
604 :     dec->edged_width);
605 :    
606 :     transfer8x8_copy(dec->cur.y + (16*y+8)*dec->edged_width + (16*x),
607 :     dec->refn.y + (16*y+8)*dec->edged_width + (16*x),
608 :     dec->edged_width);
609 :    
610 :     transfer8x8_copy(dec->cur.y + (16*y+8)*dec->edged_width + (16*x+8),
611 :     dec->refn.y + (16*y+8)*dec->edged_width + (16*x+8),
612 :     dec->edged_width);
613 :    
614 :     transfer8x8_copy(dec->cur.u + (8*y)*dec->edged_width/2 + (8*x),
615 :     dec->refn.u + (8*y)*dec->edged_width/2 + (8*x),
616 :     dec->edged_width/2);
617 :    
618 :     transfer8x8_copy(dec->cur.v + (8*y)*dec->edged_width/2 + (8*x),
619 :     dec->refn.v + (8*y)*dec->edged_width/2 + (8*x),
620 :     dec->edged_width/2);
621 :    
622 :     stop_transfer_timer();
623 :     }
624 :     }
625 :     }
626 :     }
627 :    
628 :     int decoder_decode(DECODER * dec, XVID_DEC_FRAME * frame)
629 :     {
630 :     Bitstream bs;
631 :     uint32_t rounding;
632 :     uint32_t quant;
633 :     uint32_t fcode;
634 :     uint32_t intra_dc_threshold;
635 :    
636 :     start_global_timer();
637 :    
638 :     BitstreamInit(&bs, frame->bitstream, frame->length);
639 :    
640 :     switch (BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode, &intra_dc_threshold))
641 :     {
642 :     case P_VOP :
643 :     decoder_pframe(dec, &bs, rounding, quant, fcode, intra_dc_threshold);
644 :     break;
645 :    
646 :     case I_VOP :
647 :     //DEBUG1("",intra_dc_threshold);
648 :     decoder_iframe(dec, &bs, quant, intra_dc_threshold);
649 :     break;
650 :    
651 :     case B_VOP : // ignore
652 :     break;
653 :    
654 :     case N_VOP : // vop not coded
655 :     break;
656 :    
657 :     default :
658 :     return XVID_ERR_FAIL;
659 :     }
660 :    
661 :     frame->length = BitstreamPos(&bs) / 8;
662 :    
663 :     start_timer();
664 :     image_output(&dec->cur, dec->width, dec->height, dec->edged_width,
665 :     frame->image, frame->stride, frame->colorspace);
666 :     stop_conv_timer();
667 :    
668 :     emms();
669 :    
670 :     stop_global_timer();
671 :    
672 :     return XVID_ERR_OK;
673 :     }

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4