59 |
* |
* |
60 |
*************************************************************************/ |
*************************************************************************/ |
61 |
|
|
62 |
|
#include <stdio.h> |
63 |
#include <stdlib.h> |
#include <stdlib.h> |
64 |
#include <string.h> |
#include <string.h> |
65 |
|
|
69 |
|
|
70 |
#include "xvid.h" |
#include "xvid.h" |
71 |
#include "portab.h" |
#include "portab.h" |
72 |
|
#include "global.h" |
73 |
|
|
74 |
#include "decoder.h" |
#include "decoder.h" |
75 |
#include "bitstream/bitstream.h" |
#include "bitstream/bitstream.h" |
81 |
#include "dct/fdct.h" |
#include "dct/fdct.h" |
82 |
#include "utils/mem_transfer.h" |
#include "utils/mem_transfer.h" |
83 |
#include "image/interpolate8x8.h" |
#include "image/interpolate8x8.h" |
84 |
|
#include "image/reduced.h" |
85 |
|
#include "image/font.h" |
86 |
|
|
87 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
88 |
#include "prediction/mbprediction.h" |
#include "prediction/mbprediction.h" |
99 |
{ |
{ |
100 |
/* free existing */ |
/* free existing */ |
101 |
|
|
102 |
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
103 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
104 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
105 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
106 |
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); |
107 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
|
108 |
|
image_destroy(&dec->gmc, dec->edged_width, dec->edged_height); |
109 |
|
|
110 |
if (dec->last_mbs) |
if (dec->last_mbs) |
111 |
xvid_free(dec->last_mbs); |
xvid_free(dec->last_mbs); |
139 |
xvid_free(dec); |
xvid_free(dec); |
140 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
141 |
} |
} |
142 |
if (image_create(&dec->refn[2], dec->edged_width, dec->edged_height)) { |
if (image_create(&dec->tmp, dec->edged_width, dec->edged_height)) { |
143 |
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
144 |
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
145 |
|
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
146 |
|
xvid_free(dec); |
147 |
|
return XVID_ERR_MEMORY; |
148 |
|
} |
149 |
|
|
150 |
|
if (image_create(&dec->qtmp, dec->edged_width, dec->edged_height)) { |
151 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
152 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
153 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
154 |
|
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
155 |
xvid_free(dec); |
xvid_free(dec); |
156 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
157 |
} |
} |
158 |
|
|
159 |
if (image_create(&dec->refh, dec->edged_width, dec->edged_height)) { |
if (image_create(&dec->gmc, dec->edged_width, dec->edged_height)) { |
160 |
|
image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); |
161 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
162 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
163 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
164 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
165 |
xvid_free(dec); |
xvid_free(dec); |
166 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
167 |
} |
} |
173 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
174 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
175 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
176 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
177 |
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); |
178 |
xvid_free(dec); |
xvid_free(dec); |
179 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
180 |
} |
} |
190 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
191 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
192 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
193 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
194 |
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); |
195 |
xvid_free(dec); |
xvid_free(dec); |
196 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
197 |
} |
} |
221 |
image_null(&dec->cur); |
image_null(&dec->cur); |
222 |
image_null(&dec->refn[0]); |
image_null(&dec->refn[0]); |
223 |
image_null(&dec->refn[1]); |
image_null(&dec->refn[1]); |
224 |
image_null(&dec->refn[2]); |
image_null(&dec->tmp); |
225 |
image_null(&dec->refh); |
image_null(&dec->qtmp); |
226 |
|
|
227 |
|
/* image based GMC */ |
228 |
|
image_null(&dec->gmc); |
229 |
|
|
230 |
|
|
231 |
dec->mbs = NULL; |
dec->mbs = NULL; |
232 |
dec->last_mbs = NULL; |
dec->last_mbs = NULL; |
235 |
|
|
236 |
// add by chenm001 <chenm001@163.com> |
// add by chenm001 <chenm001@163.com> |
237 |
// for support B-frame to save reference frame's time |
// for support B-frame to save reference frame's time |
238 |
dec->frames = -1; |
dec->frames = 0; |
239 |
dec->time = dec->time_base = dec->last_time_base = 0; |
dec->time = dec->time_base = dec->last_time_base = 0; |
240 |
dec->low_delay = 0; |
dec->low_delay = 0; |
241 |
|
dec->packed_mode = 0; |
242 |
|
|
243 |
dec->fixed_dimensions = (dec->width > 0 && dec->height > 0); |
dec->fixed_dimensions = (dec->width > 0 && dec->height > 0); |
244 |
|
|
254 |
{ |
{ |
255 |
xvid_free(dec->last_mbs); |
xvid_free(dec->last_mbs); |
256 |
xvid_free(dec->mbs); |
xvid_free(dec->mbs); |
257 |
|
|
258 |
|
image_destroy(&dec->gmc, dec->edged_width, dec->edged_height); /* image based GMC */ |
259 |
|
|
260 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
261 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
262 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
263 |
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); |
264 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
265 |
xvid_free(dec); |
xvid_free(dec); |
266 |
|
|
289 |
Bitstream * bs, |
Bitstream * bs, |
290 |
const uint32_t quant, |
const uint32_t quant, |
291 |
const uint32_t intra_dc_threshold, |
const uint32_t intra_dc_threshold, |
292 |
const unsigned int bound) |
const unsigned int bound, |
293 |
|
const int reduced_resolution) |
294 |
{ |
{ |
295 |
|
|
296 |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
303 |
uint32_t iQuant = pMB->quant; |
uint32_t iQuant = pMB->quant; |
304 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
305 |
|
|
306 |
|
if (reduced_resolution) { |
307 |
|
pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5); |
308 |
|
pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4); |
309 |
|
pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4); |
310 |
|
}else{ |
311 |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
312 |
pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
313 |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
314 |
|
} |
315 |
|
|
316 |
memset(block, 0, 6 * 64 * sizeof(int16_t)); // clear |
memset(block, 0, 6 * 64 * sizeof(int16_t)); // clear |
317 |
|
|
372 |
start_timer(); |
start_timer(); |
373 |
idct(&data[i * 64]); |
idct(&data[i * 64]); |
374 |
stop_idct_timer(); |
stop_idct_timer(); |
375 |
|
|
376 |
} |
} |
377 |
|
|
378 |
if (dec->interlacing && pMB->field_dct) { |
if (dec->interlacing && pMB->field_dct) { |
381 |
} |
} |
382 |
|
|
383 |
start_timer(); |
start_timer(); |
384 |
|
|
385 |
|
if (reduced_resolution) |
386 |
|
{ |
387 |
|
next_block*=2; |
388 |
|
copy_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride); |
389 |
|
copy_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride); |
390 |
|
copy_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride); |
391 |
|
copy_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride); |
392 |
|
copy_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2); |
393 |
|
copy_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2); |
394 |
|
}else{ |
395 |
transfer_16to8copy(pY_Cur, &data[0 * 64], stride); |
transfer_16to8copy(pY_Cur, &data[0 * 64], stride); |
396 |
transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride); |
transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride); |
397 |
transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride); |
transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride); |
398 |
transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride); |
transfer_16to8copy(pY_Cur + 8 + next_block, &data[3 * 64], stride); |
399 |
transfer_16to8copy(pU_Cur, &data[4 * 64], stride2); |
transfer_16to8copy(pU_Cur, &data[4 * 64], stride2); |
400 |
transfer_16to8copy(pV_Cur, &data[5 * 64], stride2); |
transfer_16to8copy(pV_Cur, &data[5 * 64], stride2); |
401 |
|
} |
402 |
stop_transfer_timer(); |
stop_transfer_timer(); |
403 |
} |
} |
404 |
|
|
405 |
|
|
406 |
|
|
407 |
|
|
|
|
|
|
#define SIGN(X) (((X)>0)?1:-1) |
|
|
#define ABS(X) (((X)>0)?(X):-(X)) |
|
|
|
|
408 |
// decode an inter macroblock |
// decode an inter macroblock |
409 |
|
|
410 |
void |
void |
412 |
const MACROBLOCK * pMB, |
const MACROBLOCK * pMB, |
413 |
const uint32_t x_pos, |
const uint32_t x_pos, |
414 |
const uint32_t y_pos, |
const uint32_t y_pos, |
415 |
const uint32_t acpred_flag, |
const uint32_t fcode, |
416 |
const uint32_t cbp, |
const uint32_t cbp, |
417 |
Bitstream * bs, |
Bitstream * bs, |
418 |
const uint32_t quant, |
const uint32_t quant, |
419 |
const uint32_t rounding) |
const uint32_t rounding, |
420 |
|
const int reduced_resolution) |
421 |
{ |
{ |
422 |
|
|
423 |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
425 |
|
|
426 |
uint32_t stride = dec->edged_width; |
uint32_t stride = dec->edged_width; |
427 |
uint32_t stride2 = stride / 2; |
uint32_t stride2 = stride / 2; |
428 |
uint32_t next_block = stride * 8; |
uint32_t next_block = stride * (reduced_resolution ? 16 : 8); |
429 |
uint32_t i; |
uint32_t i; |
430 |
uint32_t iQuant = pMB->quant; |
uint32_t iQuant = pMB->quant; |
431 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
432 |
|
|
433 |
int uv_dx, uv_dy; |
int uv_dx, uv_dy; |
434 |
|
VECTOR mv[4]; /* local copy of mvs */ |
435 |
|
|
436 |
|
if (reduced_resolution) { |
437 |
|
pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5); |
438 |
|
pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4); |
439 |
|
pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4); |
440 |
|
for (i = 0; i < 4; i++) { |
441 |
|
mv[i].x = RRV_MV_SCALEUP(pMB->mvs[i].x); |
442 |
|
mv[i].y = RRV_MV_SCALEUP(pMB->mvs[i].y); |
443 |
|
} |
444 |
|
} else { |
445 |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
446 |
pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
447 |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
448 |
|
for (i = 0; i < 4; i++) |
449 |
|
mv[i] = pMB->mvs[i]; |
450 |
|
} |
451 |
|
|
452 |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) { |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) { |
|
uv_dx = pMB->mvs[0].x; |
|
|
uv_dy = pMB->mvs[0].y; |
|
453 |
|
|
454 |
if (dec->quarterpel) |
uv_dx = mv[0].x / (1 + dec->quarterpel); |
455 |
{ |
uv_dy = mv[0].y / (1 + dec->quarterpel); |
|
uv_dx /= 2; |
|
|
uv_dy /= 2; |
|
|
} |
|
456 |
|
|
457 |
uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; |
uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; |
458 |
uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; |
uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; |
459 |
|
|
460 |
start_timer(); |
start_timer(); |
461 |
|
if (reduced_resolution) |
462 |
|
{ |
463 |
|
interpolate32x32_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos, |
464 |
|
mv[0].x, mv[0].y, stride, rounding); |
465 |
|
interpolate16x16_switch(dec->cur.u, dec->refn[0].u, 16 * x_pos, 16 * y_pos, |
466 |
|
uv_dx, uv_dy, stride2, rounding); |
467 |
|
interpolate16x16_switch(dec->cur.v, dec->refn[0].v, 16 * x_pos, 16 * y_pos, |
468 |
|
uv_dx, uv_dy, stride2, rounding); |
469 |
|
|
470 |
|
} |
471 |
|
else |
472 |
|
{ |
473 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
474 |
interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->qtmp.y, dec->qtmp.y + 64, |
475 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
476 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
mv[0].x, mv[0].y, stride, rounding); |
477 |
} |
} |
478 |
else { |
else { |
479 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos, |
interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos, |
480 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
mv[0].x, mv[0].y, stride, rounding); |
|
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos, |
|
|
pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
|
|
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8, |
|
|
pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
|
|
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8, |
|
|
pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
|
481 |
} |
} |
482 |
|
|
483 |
interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos, |
484 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
485 |
interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos, |
486 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
487 |
|
} |
488 |
stop_comp_timer(); |
stop_comp_timer(); |
489 |
|
|
490 |
} else { |
} else { /* MODE_INTER4V */ |
491 |
int sum; |
int sum; |
492 |
|
|
493 |
if(dec->quarterpel) |
if(dec->quarterpel) |
494 |
sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2); |
sum = (mv[0].x / 2) + (mv[1].x / 2) + (mv[2].x / 2) + (mv[3].x / 2); |
495 |
else |
else |
496 |
sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
sum = mv[0].x + mv[1].x + mv[2].x + mv[3].x; |
497 |
|
|
498 |
uv_dx = (sum >> 3) + roundtab_76[sum & 0xf]; |
uv_dx = (sum >> 3) + roundtab_76[sum & 0xf]; |
499 |
|
|
500 |
if(dec->quarterpel) |
if(dec->quarterpel) |
501 |
sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2); |
sum = (mv[0].y / 2) + (mv[1].y / 2) + (mv[2].y / 2) + (mv[3].y / 2); |
502 |
else |
else |
503 |
sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
sum = mv[0].y + mv[1].y + mv[2].y + mv[3].y; |
504 |
|
|
505 |
uv_dy = (sum >> 3) + roundtab_76[sum & 0xf]; |
uv_dy = (sum >> 3) + roundtab_76[sum & 0xf]; |
506 |
|
|
507 |
start_timer(); |
start_timer(); |
508 |
|
if (reduced_resolution) |
509 |
|
{ |
510 |
|
interpolate16x16_switch(dec->cur.y, dec->refn[0].y, 32*x_pos, 32*y_pos, |
511 |
|
mv[0].x, mv[0].y, stride, rounding); |
512 |
|
interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos + 16, 32*y_pos, |
513 |
|
mv[1].x, mv[1].y, stride, rounding); |
514 |
|
interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos, 32*y_pos + 16, |
515 |
|
mv[2].x, mv[2].y, stride, rounding); |
516 |
|
interpolate16x16_switch(dec->cur.y, dec->refn[0].y , 32*x_pos + 16, 32*y_pos + 16, |
517 |
|
mv[3].x, mv[3].y, stride, rounding); |
518 |
|
interpolate16x16_switch(dec->cur.u, dec->refn[0].u , 16 * x_pos, 16 * y_pos, |
519 |
|
uv_dx, uv_dy, stride2, rounding); |
520 |
|
interpolate16x16_switch(dec->cur.v, dec->refn[0].v , 16 * x_pos, 16 * y_pos, |
521 |
|
uv_dx, uv_dy, stride2, rounding); |
522 |
|
|
523 |
|
// set_block(pY_Cur, stride, 32, 32, 127); |
524 |
|
} |
525 |
|
else |
526 |
|
{ |
527 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
528 |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64, |
529 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
530 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
mv[0].x, mv[0].y, stride, rounding); |
531 |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64, |
532 |
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos, |
533 |
pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
mv[1].x, mv[1].y, stride, rounding); |
534 |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64, |
535 |
dec->refh.y + 128, 16*x_pos, 16*y_pos + 8, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8, |
536 |
pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
mv[2].x, mv[2].y, stride, rounding); |
537 |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y , dec->qtmp.y, dec->qtmp.y + 64, |
538 |
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
539 |
pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
mv[3].x, mv[3].y, stride, rounding); |
540 |
} |
} |
541 |
else { |
else { |
542 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos, |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos, |
543 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
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, |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos, |
545 |
pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
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, |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8, |
547 |
pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
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, |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8, |
549 |
pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
mv[3].x, mv[3].y, stride, rounding); |
550 |
} |
} |
551 |
|
|
552 |
interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos, |
553 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
554 |
interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos, |
555 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
556 |
|
} |
557 |
stop_comp_timer(); |
stop_comp_timer(); |
558 |
} |
} |
559 |
|
|
588 |
} |
} |
589 |
|
|
590 |
start_timer(); |
start_timer(); |
591 |
|
if (reduced_resolution) |
592 |
|
{ |
593 |
|
if (cbp & 32) |
594 |
|
add_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride); |
595 |
|
if (cbp & 16) |
596 |
|
add_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride); |
597 |
|
if (cbp & 8) |
598 |
|
add_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride); |
599 |
|
if (cbp & 4) |
600 |
|
add_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride); |
601 |
|
if (cbp & 2) |
602 |
|
add_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2); |
603 |
|
if (cbp & 1) |
604 |
|
add_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2); |
605 |
|
} |
606 |
|
else |
607 |
|
{ |
608 |
|
if (cbp & 32) |
609 |
|
transfer_16to8add(pY_Cur, &data[0 * 64], stride); |
610 |
|
if (cbp & 16) |
611 |
|
transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride); |
612 |
|
if (cbp & 8) |
613 |
|
transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride); |
614 |
|
if (cbp & 4) |
615 |
|
transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride); |
616 |
|
if (cbp & 2) |
617 |
|
transfer_16to8add(pU_Cur, &data[4 * 64], stride2); |
618 |
|
if (cbp & 1) |
619 |
|
transfer_16to8add(pV_Cur, &data[5 * 64], stride2); |
620 |
|
} |
621 |
|
stop_transfer_timer(); |
622 |
|
} |
623 |
|
|
624 |
|
static __inline int gmc_sanitize(int value, int quarterpel, int fcode) |
625 |
|
{ |
626 |
|
int length = 1 << (fcode+4); |
627 |
|
|
628 |
|
if (quarterpel) value *= 2; |
629 |
|
|
630 |
|
if (value < -length) |
631 |
|
return -length; |
632 |
|
else if (value >= length) |
633 |
|
return length-1; |
634 |
|
else return value; |
635 |
|
} |
636 |
|
|
637 |
|
|
638 |
|
static void |
639 |
|
decoder_mbgmc(DECODER * dec, |
640 |
|
MACROBLOCK * const pMB, |
641 |
|
const uint32_t x_pos, |
642 |
|
const uint32_t y_pos, |
643 |
|
const uint32_t fcode, |
644 |
|
const uint32_t cbp, |
645 |
|
Bitstream * bs, |
646 |
|
const uint32_t quant, |
647 |
|
const uint32_t rounding, |
648 |
|
const int reduced_resolution) /* no reduced res support */ |
649 |
|
{ |
650 |
|
|
651 |
|
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
652 |
|
DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE); |
653 |
|
|
654 |
|
const uint32_t stride = dec->edged_width; |
655 |
|
const uint32_t stride2 = stride / 2; |
656 |
|
const uint32_t next_block = stride * (reduced_resolution ? 16 : 8); |
657 |
|
uint32_t i; |
658 |
|
const uint32_t iQuant = pMB->quant; |
659 |
|
uint8_t *const pY_Cur=dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
660 |
|
uint8_t *const pU_Cur=dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
661 |
|
uint8_t *const pV_Cur=dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
662 |
|
|
663 |
|
pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv; |
664 |
|
|
665 |
|
start_timer(); |
666 |
|
|
667 |
|
/* this is where the calculations are done */ |
668 |
|
|
669 |
|
{ |
670 |
|
pMB->amv = generate_GMCimageMB(&dec->gmc_data, &dec->refn[0], x_pos, y_pos, |
671 |
|
stride, stride2, dec->quarterpel, rounding, &dec->cur); |
672 |
|
|
673 |
|
pMB->amv.x = gmc_sanitize(pMB->amv.x, dec->quarterpel, fcode); |
674 |
|
pMB->amv.y = gmc_sanitize(pMB->amv.y, dec->quarterpel, fcode); |
675 |
|
} |
676 |
|
pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv; |
677 |
|
|
678 |
|
|
679 |
|
/* transfer16x16_copy(pY_Cur, dec->gmc.y + (y_pos << 4)*stride + (x_pos << 4), stride); |
680 |
|
transfer8x8_copy(pU_Cur, dec->gmc.u + (y_pos << 3)*stride2 + (x_pos << 3), stride2); |
681 |
|
transfer8x8_copy(pV_Cur, dec->gmc.v + (y_pos << 3)*stride2 + (x_pos << 3), stride2); |
682 |
|
*/ |
683 |
|
|
684 |
|
|
685 |
|
stop_transfer_timer(); |
686 |
|
|
687 |
|
if (!cbp) return; |
688 |
|
|
689 |
|
for (i = 0; i < 6; i++) { |
690 |
|
int direction = dec->alternate_vertical_scan ? 2 : 0; |
691 |
|
|
692 |
|
if (cbp & (1 << (5 - i))) // coded |
693 |
|
{ |
694 |
|
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
695 |
|
|
696 |
|
start_timer(); |
697 |
|
get_inter_block(bs, &block[i * 64], direction); |
698 |
|
stop_coding_timer(); |
699 |
|
|
700 |
|
start_timer(); |
701 |
|
if (dec->quant_type == 0) { |
702 |
|
dequant_inter(&data[i * 64], &block[i * 64], iQuant); |
703 |
|
} else { |
704 |
|
dequant4_inter(&data[i * 64], &block[i * 64], iQuant); |
705 |
|
} |
706 |
|
stop_iquant_timer(); |
707 |
|
|
708 |
|
start_timer(); |
709 |
|
idct(&data[i * 64]); |
710 |
|
stop_idct_timer(); |
711 |
|
} |
712 |
|
} |
713 |
|
|
714 |
|
/* interlace + GMC is this possible ??? */ |
715 |
|
/* if (dec->interlacing && pMB->field_dct) { |
716 |
|
next_block = stride; |
717 |
|
stride *= 2; |
718 |
|
} |
719 |
|
*/ |
720 |
|
start_timer(); |
721 |
if (cbp & 32) |
if (cbp & 32) |
722 |
transfer_16to8add(pY_Cur, &data[0 * 64], stride); |
transfer_16to8add(pY_Cur, &data[0 * 64], stride); |
723 |
if (cbp & 16) |
if (cbp & 16) |
743 |
{ |
{ |
744 |
uint32_t bound; |
uint32_t bound; |
745 |
uint32_t x, y; |
uint32_t x, y; |
746 |
int mb_width = dec->mb_width; |
uint32_t mb_width = dec->mb_width; |
747 |
int mb_height = dec->mb_height; |
uint32_t mb_height = dec->mb_height; |
748 |
|
|
749 |
if (reduced_resolution) |
if (reduced_resolution) |
750 |
{ |
{ |
751 |
mb_width /= 2; |
mb_width = (dec->width + 31) / 32; |
752 |
mb_height /= 2; |
mb_height = (dec->height + 31) / 32; |
753 |
} |
} |
754 |
|
|
755 |
bound = 0; |
bound = 0; |
770 |
{ |
{ |
771 |
bound = read_video_packet_header(bs, dec, 0, |
bound = read_video_packet_header(bs, dec, 0, |
772 |
&quant, NULL, NULL, &intra_dc_threshold); |
&quant, NULL, NULL, &intra_dc_threshold); |
773 |
x = bound % dec->mb_width; |
x = bound % mb_width; |
774 |
y = bound / dec->mb_width; |
y = bound / mb_width; |
775 |
} |
} |
776 |
mb = &dec->mbs[y * dec->mb_width + x]; |
mb = &dec->mbs[y * dec->mb_width + x]; |
777 |
|
|
802 |
|
|
803 |
if (dec->interlacing) { |
if (dec->interlacing) { |
804 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
805 |
DEBUG1("deci: field_dct: ", mb->field_dct); |
DPRINTF(DPRINTF_MB,"deci: field_dct: %i", mb->field_dct); |
806 |
} |
} |
807 |
|
|
808 |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
809 |
intra_dc_threshold, bound); |
intra_dc_threshold, bound, reduced_resolution); |
810 |
|
|
811 |
} |
} |
812 |
if(dec->out_frm) |
if(dec->out_frm) |
813 |
output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,0,y,dec->mb_width); |
output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,0,y,mb_width); |
814 |
} |
} |
815 |
|
|
816 |
} |
} |
822 |
int x, |
int x, |
823 |
int y, |
int y, |
824 |
int k, |
int k, |
825 |
VECTOR * mv, |
VECTOR * ret_mv, |
826 |
int fcode, |
int fcode, |
827 |
const int bound) |
const int bound) |
828 |
{ |
{ |
833 |
int range = (64 * scale_fac); |
int range = (64 * scale_fac); |
834 |
|
|
835 |
VECTOR pmv; |
VECTOR pmv; |
836 |
int mv_x, mv_y; |
VECTOR mv; |
837 |
|
|
838 |
pmv = get_pmv2(dec->mbs, dec->mb_width, bound, x, y, k); |
pmv = get_pmv2(dec->mbs, dec->mb_width, bound, x, y, k); |
839 |
|
|
840 |
mv_x = get_mv(bs, fcode); |
mv.x = get_mv(bs, fcode); |
841 |
mv_y = get_mv(bs, fcode); |
mv.y = get_mv(bs, fcode); |
842 |
|
|
843 |
DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i)", mv_x, mv_y, pmv.x, pmv.y); |
DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)", mv.x, mv.y, pmv.x, pmv.y, mv.x+pmv.x, mv.y+pmv.y); |
844 |
|
|
845 |
mv_x += pmv.x; |
mv.x += pmv.x; |
846 |
mv_y += pmv.y; |
mv.y += pmv.y; |
847 |
|
|
848 |
if (mv_x < low) { |
if (mv.x < low) { |
849 |
mv_x += range; |
mv.x += range; |
850 |
} else if (mv_x > high) { |
} else if (mv.x > high) { |
851 |
mv_x -= range; |
mv.x -= range; |
852 |
} |
} |
853 |
|
|
854 |
if (mv_y < low) { |
if (mv.y < low) { |
855 |
mv_y += range; |
mv.y += range; |
856 |
} else if (mv_y > high) { |
} else if (mv.y > high) { |
857 |
mv_y -= range; |
mv.y -= range; |
858 |
} |
} |
859 |
|
|
860 |
mv->x = mv_x; |
ret_mv->x = mv.x; |
861 |
mv->y = mv_y; |
ret_mv->y = mv.y; |
862 |
} |
} |
863 |
|
|
864 |
|
|
865 |
|
|
|
static __inline int gmc_sanitize(int value, int quarterpel, int fcode) |
|
|
{ |
|
|
int length = 1 << (fcode+4); |
|
|
|
|
|
if (quarterpel) value *= 2; |
|
|
|
|
|
if (value < -length) |
|
|
return -length; |
|
|
else if (value >= length) |
|
|
return length-1; |
|
|
else return value; |
|
|
} |
|
866 |
|
|
867 |
|
|
868 |
/* for P_VOP set gmc_mv to NULL */ |
/* for P_VOP set gmc_warp to NULL */ |
869 |
void |
void |
870 |
decoder_pframe(DECODER * dec, |
decoder_pframe(DECODER * dec, |
871 |
Bitstream * bs, |
Bitstream * bs, |
874 |
int quant, |
int quant, |
875 |
int fcode, |
int fcode, |
876 |
int intra_dc_threshold, |
int intra_dc_threshold, |
877 |
VECTOR * gmc_mv) |
const WARPPOINTS *const gmc_warp) |
878 |
{ |
{ |
879 |
|
|
880 |
uint32_t x, y; |
uint32_t x, y; |
881 |
uint32_t bound; |
uint32_t bound; |
882 |
int cp_mb, st_mb; |
int cp_mb, st_mb; |
883 |
|
uint32_t mb_width = dec->mb_width; |
884 |
|
uint32_t mb_height = dec->mb_height; |
885 |
|
|
886 |
|
if (reduced_resolution) |
887 |
|
{ |
888 |
|
mb_width = (dec->width + 31) / 32; |
889 |
|
mb_height = (dec->height + 31) / 32; |
890 |
|
} |
891 |
|
|
892 |
start_timer(); |
start_timer(); |
893 |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
894 |
dec->width, dec->height); |
dec->width, dec->height); |
895 |
stop_edges_timer(); |
stop_edges_timer(); |
896 |
|
|
897 |
|
if (gmc_warp) |
898 |
|
{ |
899 |
|
|
900 |
|
// accuracy: 0==1/2, 1=1/4, 2=1/8, 3=1/16 |
901 |
|
if ( (dec->sprite_warping_accuracy != 3) || (dec->sprite_warping_points != 2) ) |
902 |
|
{ |
903 |
|
fprintf(stderr,"Wrong GMC parameters acc=%d(-> 1/%d), %d!!!\n", |
904 |
|
dec->sprite_warping_accuracy,(2<<dec->sprite_warping_accuracy), |
905 |
|
dec->sprite_warping_points); |
906 |
|
} |
907 |
|
|
908 |
|
generate_GMCparameters( dec->sprite_warping_points, |
909 |
|
(2 << dec->sprite_warping_accuracy), gmc_warp, |
910 |
|
dec->width, dec->height, &dec->gmc_data); |
911 |
|
|
912 |
|
/* image warping is done block-based in decoder_mbgmc(), now */ |
913 |
|
/* |
914 |
|
generate_GMCimage(&dec->gmc_data, &dec->refn[0], |
915 |
|
mb_width, mb_height, |
916 |
|
dec->edged_width, dec->edged_width/2, |
917 |
|
fcode, dec->quarterpel, 0, |
918 |
|
rounding, dec->mbs, &dec->gmc); |
919 |
|
*/ |
920 |
|
} |
921 |
|
|
922 |
bound = 0; |
bound = 0; |
923 |
|
|
924 |
for (y = 0; y < dec->mb_height; y++) { |
for (y = 0; y < mb_height; y++) { |
925 |
cp_mb = st_mb = 0; |
cp_mb = st_mb = 0; |
926 |
for (x = 0; x < dec->mb_width; x++) { |
for (x = 0; x < mb_width; x++) { |
927 |
MACROBLOCK *mb; |
MACROBLOCK *mb; |
928 |
|
|
929 |
// skip stuffing |
// skip stuffing |
934 |
{ |
{ |
935 |
bound = read_video_packet_header(bs, dec, fcode - 1, |
bound = read_video_packet_header(bs, dec, fcode - 1, |
936 |
&quant, &fcode, NULL, &intra_dc_threshold); |
&quant, &fcode, NULL, &intra_dc_threshold); |
937 |
x = bound % dec->mb_width; |
x = bound % mb_width; |
938 |
y = bound / dec->mb_width; |
y = bound / mb_width; |
939 |
} |
} |
940 |
mb = &dec->mbs[y * dec->mb_width + x]; |
mb = &dec->mbs[y * dec->mb_width + x]; |
941 |
|
|
942 |
DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32)); |
DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32)); |
943 |
|
|
944 |
//if (!(dec->mb_skip[y*dec->mb_width + x]=BitstreamGetBit(bs))) // not_coded |
//if (!(dec->mb_skip[y*dec->mb_width + x]=BitstreamGetBit(bs))) // not_coded |
945 |
if (!(BitstreamGetBit(bs))) // not_coded |
if (!(BitstreamGetBit(bs))) // block _is_ coded |
946 |
{ |
{ |
947 |
uint32_t mcbpc; |
uint32_t mcbpc; |
948 |
uint32_t cbpc; |
uint32_t cbpc; |
967 |
acpred_flag = BitstreamGetBit(bs); |
acpred_flag = BitstreamGetBit(bs); |
968 |
} |
} |
969 |
|
|
970 |
if (gmc_mv && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)) |
if (gmc_warp && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)) |
971 |
{ |
{ |
972 |
mcsel = BitstreamGetBit(bs); |
mcsel = BitstreamGetBit(bs); |
973 |
} |
} |
974 |
|
|
975 |
cbpy = get_cbpy(bs, intra); |
cbpy = get_cbpy(bs, intra); |
976 |
DPRINTF(DPRINTF_MB, "cbpy %i", cbpy); |
DPRINTF(DPRINTF_MB, "cbpy %i mcsel %i ", cbpy,mcsel); |
977 |
|
|
978 |
cbp = (cbpy << 2) | cbpc; |
cbp = (cbpy << 2) | cbpc; |
979 |
|
|
993 |
if (dec->interlacing) { |
if (dec->interlacing) { |
994 |
if (cbp || intra) { |
if (cbp || intra) { |
995 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
996 |
DEBUG1("decp: field_dct: ", mb->field_dct); |
DPRINTF(DPRINTF_MB,"decp: field_dct: %i", mb->field_dct); |
997 |
} |
} |
998 |
|
|
999 |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
1000 |
mb->field_pred = BitstreamGetBit(bs); |
mb->field_pred = BitstreamGetBit(bs); |
1001 |
DEBUG1("decp: field_pred: ", mb->field_pred); |
DPRINTF(DPRINTF_MB, "decp: field_pred: %i", mb->field_pred); |
1002 |
|
|
1003 |
if (mb->field_pred) { |
if (mb->field_pred) { |
1004 |
mb->field_for_top = BitstreamGetBit(bs); |
mb->field_for_top = BitstreamGetBit(bs); |
1005 |
DEBUG1("decp: field_for_top: ", mb->field_for_top); |
DPRINTF(DPRINTF_MB,"decp: field_for_top: %i", mb->field_for_top); |
1006 |
mb->field_for_bot = BitstreamGetBit(bs); |
mb->field_for_bot = BitstreamGetBit(bs); |
1007 |
DEBUG1("decp: field_for_bot: ", mb->field_for_bot); |
DPRINTF(DPRINTF_MB,"decp: field_for_bot: %i", mb->field_for_bot); |
1008 |
} |
} |
1009 |
} |
} |
1010 |
} |
} |
1011 |
|
|
1012 |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
if (mcsel) { |
1013 |
|
decoder_mbgmc(dec, mb, x, y, fcode, cbp, bs, quant, |
1014 |
|
rounding, reduced_resolution); |
1015 |
|
continue; |
1016 |
|
|
1017 |
if (mcsel) |
} else if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
|
{ |
|
|
mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = gmc_sanitize(gmc_mv[0].x, dec->quarterpel, fcode); |
|
|
mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = gmc_sanitize(gmc_mv[0].y, dec->quarterpel, fcode); |
|
1018 |
|
|
1019 |
} else if (dec->interlacing && mb->field_pred) { |
if (dec->interlacing && mb->field_pred) { |
1020 |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], |
1021 |
fcode, bound); |
fcode, bound); |
1022 |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1], |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1], |
1024 |
} else { |
} else { |
1025 |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], |
1026 |
fcode, bound); |
fcode, bound); |
1027 |
mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = |
mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; |
|
mb->mvs[0].x; |
|
|
mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = |
|
|
mb->mvs[0].y; |
|
1028 |
} |
} |
1029 |
} else if (mb->mode == MODE_INTER4V ) { |
} else if (mb->mode == MODE_INTER4V ) { |
1030 |
|
|
1039 |
mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = |
mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = |
1040 |
0; |
0; |
1041 |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
1042 |
intra_dc_threshold, bound); |
intra_dc_threshold, bound, reduced_resolution); |
1043 |
continue; |
continue; |
1044 |
} |
} |
1045 |
|
|
1046 |
decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
decoder_mbinter(dec, mb, x, y, fcode, cbp, bs, quant, |
1047 |
rounding); |
rounding, reduced_resolution); |
1048 |
|
|
1049 |
} |
} |
1050 |
else if (gmc_mv) /* not coded S_VOP macroblock */ |
else if (gmc_warp) /* a not coded S(GMC)-VOP macroblock */ |
1051 |
{ |
{ |
1052 |
mb->mode = MODE_NOT_CODED; |
mb->mode = MODE_NOT_CODED_GMC; |
1053 |
mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = gmc_sanitize(gmc_mv[0].x, dec->quarterpel, fcode); |
|
1054 |
mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = gmc_sanitize(gmc_mv[0].y, dec->quarterpel, fcode); |
start_timer(); |
1055 |
decoder_mbinter(dec, mb, x, y, 0, 0, bs, quant, rounding); |
|
1056 |
|
decoder_mbgmc(dec, mb, x, y, fcode, 0x00, bs, quant, |
1057 |
|
rounding, reduced_resolution); |
1058 |
|
|
1059 |
|
stop_transfer_timer(); |
1060 |
|
|
1061 |
|
if(dec->out_frm && cp_mb > 0) { |
1062 |
|
output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb); |
1063 |
|
cp_mb = 0; |
1064 |
|
} |
1065 |
|
st_mb = x+1; |
1066 |
} |
} |
1067 |
else /* not coded P_VOP macroblock */ |
else /* not coded P_VOP macroblock */ |
1068 |
{ |
{ |
1069 |
mb->mode = MODE_NOT_CODED; |
mb->mode = MODE_NOT_CODED; |
1070 |
|
|
1071 |
mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0; |
mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = 0; |
1072 |
mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0; |
mb->mvs[0].y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = 0; |
1073 |
// copy macroblock directly from ref to cur |
// copy macroblock directly from ref to cur |
1074 |
|
|
1075 |
start_timer(); |
start_timer(); |
1076 |
|
|
1077 |
transfer8x8_copy(dec->cur.y + (16 * y) * dec->edged_width + |
if (reduced_resolution) |
1078 |
(16 * x), |
{ |
1079 |
dec->refn[0].y + (16 * y) * dec->edged_width + |
transfer32x32_copy(dec->cur.y + (32*y)*dec->edged_width + (32*x), |
1080 |
(16 * x), dec->edged_width); |
dec->refn[0].y + (32*y)*dec->edged_width + (32*x), |
1081 |
|
dec->edged_width); |
1082 |
transfer8x8_copy(dec->cur.y + (16 * y) * dec->edged_width + |
|
1083 |
(16 * x + 8), |
transfer16x16_copy(dec->cur.u + (16*y)*dec->edged_width/2 + (16*x), |
1084 |
dec->refn[0].y + (16 * y) * dec->edged_width + |
dec->refn[0].u + (16*y)*dec->edged_width/2 + (16*x), |
1085 |
(16 * x + 8), dec->edged_width); |
dec->edged_width/2); |
1086 |
|
|
1087 |
transfer8x8_copy(dec->cur.y + (16 * y + 8) * dec->edged_width + |
transfer16x16_copy(dec->cur.v + (16*y)*dec->edged_width/2 + (16*x), |
1088 |
(16 * x), |
dec->refn[0].v + (16*y)*dec->edged_width/2 + (16*x), |
|
dec->refn[0].y + (16 * y + |
|
|
8) * dec->edged_width + |
|
|
(16 * x), dec->edged_width); |
|
|
|
|
|
transfer8x8_copy(dec->cur.y + (16 * y + 8) * dec->edged_width + |
|
|
(16 * x + 8), |
|
|
dec->refn[0].y + (16 * y + |
|
|
8) * dec->edged_width + |
|
|
(16 * x + 8), dec->edged_width); |
|
|
|
|
|
transfer8x8_copy(dec->cur.u + (8 * y) * dec->edged_width / 2 + |
|
|
(8 * x), |
|
|
dec->refn[0].u + |
|
|
(8 * y) * dec->edged_width / 2 + (8 * x), |
|
1089 |
dec->edged_width / 2); |
dec->edged_width / 2); |
1090 |
|
} |
1091 |
|
else |
1092 |
|
{ |
1093 |
|
transfer16x16_copy(dec->cur.y + (16*y)*dec->edged_width + (16*x), |
1094 |
|
dec->refn[0].y + (16*y)*dec->edged_width + (16*x), |
1095 |
|
dec->edged_width); |
1096 |
|
|
1097 |
transfer8x8_copy(dec->cur.v + (8 * y) * dec->edged_width / 2 + |
transfer8x8_copy(dec->cur.u + (8*y)*dec->edged_width/2 + (8*x), |
1098 |
(8 * x), |
dec->refn[0].u + (8*y)*dec->edged_width/2 + (8*x), |
|
dec->refn[0].v + |
|
|
(8 * y) * dec->edged_width / 2 + (8 * x), |
|
1099 |
dec->edged_width / 2); |
dec->edged_width / 2); |
1100 |
|
|
1101 |
|
transfer8x8_copy(dec->cur.v + (8*y)*dec->edged_width/2 + (8*x), |
1102 |
|
dec->refn[0].v + (8*y)*dec->edged_width/2 + (8*x), |
1103 |
|
dec->edged_width/2); |
1104 |
|
} |
1105 |
|
|
1106 |
stop_transfer_timer(); |
stop_transfer_timer(); |
1107 |
|
|
1108 |
if(dec->out_frm && cp_mb > 0) { |
if(dec->out_frm && cp_mb > 0) { |
1196 |
uv_dx = pMB->mvs[0].x; |
uv_dx = pMB->mvs[0].x; |
1197 |
uv_dy = pMB->mvs[0].y; |
uv_dy = pMB->mvs[0].y; |
1198 |
|
|
1199 |
uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2; |
if (dec->quarterpel) |
1200 |
uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2; |
{ |
1201 |
|
uv_dx /= 2; |
1202 |
|
uv_dy /= 2; |
1203 |
|
} |
1204 |
|
|
1205 |
|
uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; |
1206 |
|
uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; |
1207 |
} else { |
} else { |
1208 |
int sum; |
int sum; |
1209 |
|
|
1210 |
|
if(dec->quarterpel) |
1211 |
|
sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2); |
1212 |
|
else |
1213 |
sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
|
uv_dx = |
|
|
(sum == |
|
|
0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + |
|
|
(ABS(sum) / 16) * 2)); |
|
1214 |
|
|
1215 |
|
uv_dx = (sum >> 3) + roundtab_76[sum & 0xf]; |
1216 |
|
|
1217 |
|
if(dec->quarterpel) |
1218 |
|
sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2); |
1219 |
|
else |
1220 |
sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
1221 |
uv_dy = |
|
1222 |
(sum == |
uv_dy = (sum >> 3) + roundtab_76[sum & 0xf]; |
|
0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + |
|
|
(ABS(sum) / 16) * 2)); |
|
1223 |
} |
} |
1224 |
|
|
1225 |
start_timer(); |
start_timer(); |
1226 |
|
if(dec->quarterpel) { |
1227 |
|
interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->qtmp.y, dec->qtmp.y + 64, |
1228 |
|
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1229 |
|
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1230 |
|
} |
1231 |
|
else { |
1232 |
interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos, 16 * y_pos, |
interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos, 16 * y_pos, |
1233 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1234 |
interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos + 8, |
interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos + 8, 16*y_pos, |
1235 |
16 * y_pos, pMB->mvs[1].x, pMB->mvs[1].y, stride, 0); |
pMB->mvs[1].x, pMB->mvs[1].y, stride, 0); |
1236 |
interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos, |
interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos, 16*y_pos + 8, |
1237 |
16 * y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride, |
pMB->mvs[2].x, pMB->mvs[2].y, stride, 0); |
1238 |
0); |
interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16*x_pos + 8, 16*y_pos + 8, |
1239 |
interpolate8x8_switch(dec->cur.y, dec->refn[ref].y, 16 * x_pos + 8, |
pMB->mvs[3].x, pMB->mvs[3].y, stride, 0); |
1240 |
16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride, |
} |
1241 |
0); |
|
1242 |
interpolate8x8_switch(dec->cur.u, dec->refn[ref].u, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->cur.u, dec->refn[ref].u, 8 * x_pos, 8 * y_pos, |
1243 |
uv_dx, uv_dy, stride2, 0); |
uv_dx, uv_dy, stride2, 0); |
1244 |
interpolate8x8_switch(dec->cur.v, dec->refn[ref].v, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->cur.v, dec->refn[ref].v, 8 * x_pos, 8 * y_pos, |
1325 |
uv_dx = pMB->mvs[0].x; |
uv_dx = pMB->mvs[0].x; |
1326 |
uv_dy = pMB->mvs[0].y; |
uv_dy = pMB->mvs[0].y; |
1327 |
|
|
|
uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2; |
|
|
uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2; |
|
|
|
|
1328 |
b_uv_dx = pMB->b_mvs[0].x; |
b_uv_dx = pMB->b_mvs[0].x; |
1329 |
b_uv_dy = pMB->b_mvs[0].y; |
b_uv_dy = pMB->b_mvs[0].y; |
1330 |
|
|
1331 |
b_uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2; |
if (dec->quarterpel) |
1332 |
b_uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2; |
{ |
1333 |
|
uv_dx /= 2; |
1334 |
|
uv_dy /= 2; |
1335 |
|
|
1336 |
|
b_uv_dx /= 2; |
1337 |
|
b_uv_dy /= 2; |
1338 |
|
} |
1339 |
|
|
1340 |
|
uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; |
1341 |
|
uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; |
1342 |
|
|
1343 |
|
b_uv_dx = (b_uv_dx >> 1) + roundtab_79[b_uv_dx & 0x3]; |
1344 |
|
b_uv_dy = (b_uv_dy >> 1) + roundtab_79[b_uv_dy & 0x3]; |
1345 |
} else { |
} else { |
1346 |
int sum; |
int sum; |
1347 |
|
|
1348 |
|
if(dec->quarterpel) |
1349 |
|
sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2); |
1350 |
|
else |
1351 |
sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
sum = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
|
uv_dx = |
|
|
(sum == |
|
|
0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + |
|
|
(ABS(sum) / 16) * 2)); |
|
1352 |
|
|
1353 |
|
uv_dx = (sum >> 3) + roundtab_76[sum & 0xf]; |
1354 |
|
|
1355 |
|
if(dec->quarterpel) |
1356 |
|
sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2); |
1357 |
|
else |
1358 |
sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
sum = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
1359 |
uv_dy = |
|
1360 |
(sum == |
uv_dy = (sum >> 3) + roundtab_76[sum & 0xf]; |
1361 |
0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + |
|
1362 |
(ABS(sum) / 16) * 2)); |
|
1363 |
|
if(dec->quarterpel) |
1364 |
sum = |
sum = (pMB->b_mvs[0].x / 2) + (pMB->b_mvs[1].x / 2) + (pMB->b_mvs[2].x / 2) + (pMB->b_mvs[3].x / 2); |
1365 |
pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x + |
else |
1366 |
pMB->b_mvs[3].x; |
sum = pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x + pMB->b_mvs[3].x; |
1367 |
b_uv_dx = |
|
1368 |
(sum == |
b_uv_dx = (sum >> 3) + roundtab_76[sum & 0xf]; |
1369 |
0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + |
|
1370 |
(ABS(sum) / 16) * 2)); |
if(dec->quarterpel) |
1371 |
|
sum = (pMB->b_mvs[0].y / 2) + (pMB->b_mvs[1].y / 2) + (pMB->b_mvs[2].y / 2) + (pMB->b_mvs[3].y / 2); |
1372 |
sum = |
else |
1373 |
pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + |
sum = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y; |
1374 |
pMB->b_mvs[3].y; |
|
1375 |
b_uv_dy = |
b_uv_dy = (sum >> 3) + roundtab_76[sum & 0xf]; |
|
(sum == |
|
|
0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + |
|
|
(ABS(sum) / 16) * 2)); |
|
1376 |
} |
} |
1377 |
|
|
1378 |
|
|
1379 |
start_timer(); |
start_timer(); |
1380 |
|
if(dec->quarterpel) { |
1381 |
|
if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) |
1382 |
|
interpolate16x16_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1383 |
|
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1384 |
|
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1385 |
|
else { |
1386 |
|
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1387 |
|
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1388 |
|
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1389 |
|
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1390 |
|
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos, |
1391 |
|
pMB->mvs[1].x, pMB->mvs[1].y, stride, 0); |
1392 |
|
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1393 |
|
dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8, |
1394 |
|
pMB->mvs[2].x, pMB->mvs[2].y, stride, 0); |
1395 |
|
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1396 |
|
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
1397 |
|
pMB->mvs[3].x, pMB->mvs[3].y, stride, 0); |
1398 |
|
} |
1399 |
|
} |
1400 |
|
else { |
1401 |
interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos, |
interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos, 16 * y_pos, |
1402 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1403 |
interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8, 16 * y_pos, |
interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8, 16 * y_pos, |
1407 |
interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8, |
interpolate8x8_switch(dec->cur.y, forward.y, 16 * x_pos + 8, |
1408 |
16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride, |
16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride, |
1409 |
0); |
0); |
1410 |
|
} |
1411 |
|
|
1412 |
interpolate8x8_switch(dec->cur.u, forward.u, 8 * x_pos, 8 * y_pos, uv_dx, |
interpolate8x8_switch(dec->cur.u, forward.u, 8 * x_pos, 8 * y_pos, uv_dx, |
1413 |
uv_dy, stride2, 0); |
uv_dy, stride2, 0); |
1414 |
interpolate8x8_switch(dec->cur.v, forward.v, 8 * x_pos, 8 * y_pos, uv_dx, |
interpolate8x8_switch(dec->cur.v, forward.v, 8 * x_pos, 8 * y_pos, uv_dx, |
1415 |
uv_dy, stride2, 0); |
uv_dy, stride2, 0); |
1416 |
|
|
1417 |
|
|
1418 |
interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos, 16 * y_pos, |
if(dec->quarterpel) { |
1419 |
|
if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) |
1420 |
|
interpolate16x16_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1421 |
|
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1422 |
|
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
1423 |
|
else { |
1424 |
|
interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1425 |
|
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1426 |
|
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
1427 |
|
interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1428 |
|
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos, |
1429 |
|
pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0); |
1430 |
|
interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1431 |
|
dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8, |
1432 |
|
pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0); |
1433 |
|
interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1434 |
|
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
1435 |
|
pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0); |
1436 |
|
} |
1437 |
|
} |
1438 |
|
else { |
1439 |
|
interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos, 16 * y_pos, |
1440 |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
1441 |
interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8, |
interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8, |
1442 |
16 * y_pos, pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, |
16 * y_pos, pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, |
1443 |
0); |
0); |
1444 |
interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos, |
interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos, |
1445 |
16 * y_pos + 8, pMB->b_mvs[2].x, pMB->b_mvs[2].y, |
16 * y_pos + 8, pMB->b_mvs[2].x, pMB->b_mvs[2].y, |
1446 |
stride, 0); |
stride, 0); |
1447 |
interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8, |
interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8, |
1448 |
16 * y_pos + 8, pMB->b_mvs[3].x, pMB->b_mvs[3].y, |
16 * y_pos + 8, pMB->b_mvs[3].x, pMB->b_mvs[3].y, |
1449 |
stride, 0); |
stride, 0); |
1450 |
interpolate8x8_switch(dec->refn[2].u, backward.u, 8 * x_pos, 8 * y_pos, |
} |
1451 |
|
|
1452 |
|
interpolate8x8_switch(dec->tmp.u, backward.u, 8 * x_pos, 8 * y_pos, |
1453 |
b_uv_dx, b_uv_dy, stride2, 0); |
b_uv_dx, b_uv_dy, stride2, 0); |
1454 |
interpolate8x8_switch(dec->refn[2].v, backward.v, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->tmp.v, backward.v, 8 * x_pos, 8 * y_pos, |
1455 |
b_uv_dx, b_uv_dy, stride2, 0); |
b_uv_dx, b_uv_dy, stride2, 0); |
1456 |
|
|
1457 |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
1458 |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
1459 |
dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos, |
dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos, |
1460 |
stride, 0); |
stride, 1, 8); |
1461 |
|
|
1462 |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1463 |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1464 |
dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos + 8, |
dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1465 |
stride, 0); |
stride, 1, 8); |
1466 |
|
|
1467 |
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
1468 |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
1469 |
dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
1470 |
stride, 0); |
stride, 1, 8); |
1471 |
|
|
1472 |
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
1473 |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
1474 |
dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
1475 |
stride, 0); |
stride, 1, 8); |
1476 |
|
|
1477 |
interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
1478 |
dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
1479 |
dec->refn[2].u + (8 * y_pos * stride2) + 8 * x_pos, |
dec->tmp.u + (8 * y_pos * stride2) + 8 * x_pos, |
1480 |
stride2, 0); |
stride2, 1, 8); |
1481 |
|
|
1482 |
interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
1483 |
dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
1484 |
dec->refn[2].v + (8 * y_pos * stride2) + 8 * x_pos, |
dec->tmp.v + (8 * y_pos * stride2) + 8 * x_pos, |
1485 |
stride2, 0); |
stride2, 1, 8); |
1486 |
|
|
1487 |
stop_comp_timer(); |
stop_comp_timer(); |
1488 |
|
|
1611 |
mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = |
mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = |
1612 |
mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv; |
mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv; |
1613 |
|
|
1614 |
// the last P_VOP is skip macroblock ? |
// skip if the co-located P_VOP macroblock is not coded |
1615 |
|
// if not codec in co-located S_VOP macroblock is _not_ automatically skipped |
1616 |
|
|
1617 |
if (last_mb->mode == MODE_NOT_CODED) { |
if (last_mb->mode == MODE_NOT_CODED) { |
1618 |
//DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); |
//DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); |
1619 |
mb->cbp = 0; |
mb->cbp = 0; |
1727 |
break; |
break; |
1728 |
|
|
1729 |
default: |
default: |
1730 |
DEBUG1("Not support B-frame mb_type =", mb->mb_type); |
DPRINTF(DPRINTF_ERROR,"Not support B-frame mb_type = %i", mb->mb_type); |
1731 |
} |
} |
1732 |
|
|
1733 |
} // end of FOR |
} // end of FOR |
1752 |
*mb2 = temp; |
*mb2 = temp; |
1753 |
} |
} |
1754 |
|
|
1755 |
|
|
1756 |
|
/* perform post processing if necessary, and output the image */ |
1757 |
|
void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs, |
1758 |
|
const XVID_DEC_FRAME * frame, int pp_disable) |
1759 |
|
{ |
1760 |
|
|
1761 |
|
if ((frame->general & (XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV)) && !pp_disable) /* post process */ |
1762 |
|
{ |
1763 |
|
/* note: image is stored to tmp */ |
1764 |
|
image_copy(&dec->tmp, img, dec->edged_width, dec->height); |
1765 |
|
image_deblock_rrv(&dec->tmp, dec->edged_width, |
1766 |
|
mbs, dec->mb_width, dec->mb_height, dec->mb_width, |
1767 |
|
8, frame->general); |
1768 |
|
img = &dec->tmp; |
1769 |
|
} |
1770 |
|
|
1771 |
|
image_output(img, dec->width, dec->height, |
1772 |
|
dec->edged_width, frame->image, frame->stride, |
1773 |
|
frame->colorspace, dec->interlacing); |
1774 |
|
} |
1775 |
|
|
1776 |
|
|
1777 |
int |
int |
1778 |
decoder_decode(DECODER * dec, |
decoder_decode(DECODER * dec, |
1779 |
XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats) |
XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats) |
1786 |
uint32_t fcode_forward; |
uint32_t fcode_forward; |
1787 |
uint32_t fcode_backward; |
uint32_t fcode_backward; |
1788 |
uint32_t intra_dc_threshold; |
uint32_t intra_dc_threshold; |
1789 |
VECTOR gmc_mv[5]; |
WARPPOINTS gmc_warp; |
1790 |
uint32_t vop_type; |
uint32_t vop_type; |
1791 |
|
int success = 0; |
1792 |
|
int output = 0; |
1793 |
|
int seen_something = 0; |
1794 |
|
|
1795 |
start_global_timer(); |
start_global_timer(); |
1796 |
|
|
1797 |
|
dec->low_delay_default = (frame->general & XVID_DEC_LOWDELAY); |
1798 |
dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL; |
dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL; |
1799 |
|
|
1800 |
|
if ((frame->general & XVID_DEC_DISCONTINUITY)) |
1801 |
|
dec->frames = 0; |
1802 |
|
|
1803 |
|
if (frame->length < 0) /* decoder flush */ |
1804 |
|
{ |
1805 |
|
/* if not decoding "low_delay/packed", and this isn't low_delay and |
1806 |
|
we have a reference frame, then outout the reference frame */ |
1807 |
|
if (!(dec->low_delay_default && dec->packed_mode) && !dec->low_delay && dec->frames>0) |
1808 |
|
{ |
1809 |
|
decoder_output(dec, &dec->refn[0], dec->mbs, frame, dec->last_reduced_resolution); |
1810 |
|
output = 1; |
1811 |
|
} |
1812 |
|
|
1813 |
|
frame->length = 0; |
1814 |
|
if (stats) |
1815 |
|
{ |
1816 |
|
stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING; |
1817 |
|
stats->data.vop.time_base = (int)dec->time_base; |
1818 |
|
stats->data.vop.time_increment = 0; //XXX: todo |
1819 |
|
} |
1820 |
|
|
1821 |
|
emms(); |
1822 |
|
|
1823 |
|
stop_global_timer(); |
1824 |
|
return XVID_ERR_OK; |
1825 |
|
} |
1826 |
|
|
1827 |
BitstreamInit(&bs, frame->bitstream, frame->length); |
BitstreamInit(&bs, frame->bitstream, frame->length); |
1828 |
|
|
|
#ifdef BFRAMES_DEC |
|
1829 |
// XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's |
// XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's |
1830 |
if(BitstreamShowBits(&bs, 8) == 0x7f) |
if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f) |
1831 |
{ |
{ |
1832 |
if (stats) |
if (stats) |
1833 |
stats->notify = XVID_DEC_VOP; |
stats->notify = XVID_DEC_VOP; |
1834 |
frame->length = 1; |
frame->length = 1; |
1835 |
image_output(&dec->cur, dec->width, dec->height, dec->edged_width, |
image_output(&dec->refn[0], dec->width, dec->height, dec->edged_width, |
1836 |
frame->image, frame->stride, frame->colorspace, dec->interlacing); |
frame->image, frame->stride, frame->colorspace, dec->interlacing); |
1837 |
|
emms(); |
1838 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
1839 |
} |
} |
|
#endif |
|
1840 |
|
|
1841 |
// add by chenm001 <chenm001@163.com> |
repeat: |
|
// for support B-frame to reference last 2 frame |
|
|
dec->frames++; |
|
1842 |
|
|
1843 |
xxx: |
vop_type = BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, |
1844 |
vop_type = |
&quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, &gmc_warp); |
|
BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, |
|
|
&quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, gmc_mv); |
|
1845 |
|
|
1846 |
DPRINTF(DPRINTF_HEADER, "vop_type=%i", vop_type); |
DPRINTF(DPRINTF_HEADER, "vop_type=%i, packed=%i, time=%lli, time_pp=%i, time_bp=%i", |
1847 |
|
vop_type, dec->packed_mode, dec->time, dec->time_pp, dec->time_bp); |
1848 |
|
|
1849 |
|
if (vop_type == - 1) |
1850 |
|
{ |
1851 |
|
if (success) goto done; |
1852 |
|
emms(); |
1853 |
|
return XVID_ERR_FAIL; |
1854 |
|
} |
1855 |
|
|
1856 |
if (vop_type == -2 || vop_type == -3) |
if (vop_type == -2 || vop_type == -3) |
1857 |
{ |
{ |
1870 |
stats->data.vol.par_width = dec->par_width; |
stats->data.vol.par_width = dec->par_width; |
1871 |
stats->data.vol.par_height = dec->par_height; |
stats->data.vol.par_height = dec->par_height; |
1872 |
frame->length = BitstreamPos(&bs) / 8; |
frame->length = BitstreamPos(&bs) / 8; |
1873 |
|
emms(); |
1874 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
1875 |
} |
} |
1876 |
goto xxx; |
goto repeat; |
1877 |
} |
} |
1878 |
|
|
1879 |
dec->p_bmv.x = dec->p_bmv.y = dec->p_fmv.y = dec->p_fmv.y = 0; // init pred vector to 0 |
dec->p_bmv.x = dec->p_bmv.y = dec->p_fmv.y = dec->p_fmv.y = 0; // init pred vector to 0 |
1880 |
|
|
|
switch (vop_type) { |
|
|
case P_VOP: |
|
|
decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, |
|
|
fcode_forward, intra_dc_threshold, NULL); |
|
|
#ifdef BFRAMES_DEC |
|
|
DEBUG1("P_VOP Time=", dec->time); |
|
|
#endif |
|
|
break; |
|
1881 |
|
|
1882 |
|
/* packed_mode: special-N_VOP treament */ |
1883 |
|
if (dec->packed_mode && vop_type == N_VOP) |
1884 |
|
{ |
1885 |
|
if (dec->low_delay_default && dec->frames > 0) |
1886 |
|
{ |
1887 |
|
decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, dec->last_reduced_resolution); |
1888 |
|
output = 1; |
1889 |
|
} |
1890 |
|
/* ignore otherwise */ |
1891 |
|
} |
1892 |
|
else if (vop_type != B_VOP) |
1893 |
|
{ |
1894 |
|
switch(vop_type) |
1895 |
|
{ |
1896 |
case I_VOP: |
case I_VOP: |
1897 |
decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold); |
decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold); |
|
#ifdef BFRAMES_DEC |
|
|
DEBUG1("I_VOP Time=", dec->time); |
|
|
#endif |
|
1898 |
break; |
break; |
1899 |
|
case P_VOP : |
1900 |
case B_VOP: |
decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, |
1901 |
#ifdef BFRAMES_DEC |
fcode_forward, intra_dc_threshold, NULL); |
|
if (dec->time_pp > dec->time_bp) { |
|
|
DEBUG1("B_VOP Time=", dec->time); |
|
|
decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); |
|
|
} else { |
|
|
DEBUG("broken B-frame!"); |
|
|
} |
|
|
#else |
|
|
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
|
|
#endif |
|
1902 |
break; |
break; |
|
|
|
1903 |
case S_VOP : |
case S_VOP : |
1904 |
decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, |
decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, |
1905 |
fcode_forward, intra_dc_threshold, gmc_mv); |
fcode_forward, intra_dc_threshold, &gmc_warp); |
1906 |
break; |
break; |
1907 |
|
case N_VOP : |
|
case N_VOP: // vop not coded |
|
|
// when low_delay==0, N_VOP's should interpolate between the past and future frames |
|
1908 |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
|
#ifdef BFRAMES_DEC |
|
|
DEBUG1("N_VOP Time=", dec->time); |
|
|
#endif |
|
1909 |
break; |
break; |
1910 |
|
} |
1911 |
|
|
1912 |
default: |
if (reduced_resolution) |
1913 |
if (stats) |
{ |
1914 |
stats->notify = 0; |
image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs, |
1915 |
return XVID_ERR_FAIL; |
(dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width, |
1916 |
|
16, XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV); |
1917 |
} |
} |
1918 |
|
|
1919 |
#ifdef BFRAMES_DEC_DEBUG |
/* note: for packed_mode, output is performed when the special-N_VOP is decoded */ |
1920 |
if (frame->length != BitstreamPos(&bs) / 8){ |
if (!(dec->low_delay_default && dec->packed_mode)) |
1921 |
DEBUG2("InLen/UseLen",frame->length, BitstreamPos(&bs) / 8); |
{ |
1922 |
|
if (dec->low_delay) |
1923 |
|
{ |
1924 |
|
decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution); |
1925 |
|
output = 1; |
1926 |
|
} |
1927 |
|
else if (dec->frames > 0) /* is the reference frame valid? */ |
1928 |
|
{ |
1929 |
|
/* output the reference frame */ |
1930 |
|
decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, dec->last_reduced_resolution); |
1931 |
|
output = 1; |
1932 |
|
} |
1933 |
} |
} |
|
#endif |
|
|
frame->length = BitstreamPos(&bs) / 8; |
|
1934 |
|
|
1935 |
|
image_swap(&dec->refn[0], &dec->refn[1]); |
1936 |
|
image_swap(&dec->cur, &dec->refn[0]); |
1937 |
|
mb_swap(&dec->mbs, &dec->last_mbs); |
1938 |
|
dec->last_reduced_resolution = reduced_resolution; |
1939 |
|
|
1940 |
#ifdef BFRAMES_DEC |
dec->frames++; |
1941 |
// test if no B_VOP |
seen_something = 1; |
1942 |
if (dec->low_delay || dec->frames == 0) { |
|
1943 |
#endif |
}else{ /* B_VOP */ |
1944 |
image_output(&dec->cur, dec->width, dec->height, dec->edged_width, |
|
1945 |
frame->image, frame->stride, frame->colorspace, dec->interlacing); |
if (dec->low_delay) |
1946 |
|
{ |
1947 |
|
DPRINTF(DPRINTF_ERROR, "warning: bvop found in low_delay==1 stream"); |
1948 |
|
dec->low_delay = 1; |
1949 |
|
} |
1950 |
|
|
1951 |
#ifdef BFRAMES_DEC |
if (dec->frames < 2) |
1952 |
|
{ |
1953 |
|
/* attemping to decode a bvop without atleast 2 reference frames */ |
1954 |
|
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, |
1955 |
|
"broken b-frame, mising ref frames"); |
1956 |
|
}else if (dec->time_pp <= dec->time_bp) { |
1957 |
|
/* this occurs when dx50_bvop_compatibility==0 sequences are |
1958 |
|
decoded in vfw. */ |
1959 |
|
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, |
1960 |
|
"broken b-frame, tpp=%i tbp=%i", dec->time_pp, dec->time_bp); |
1961 |
} else { |
} else { |
1962 |
if (dec->frames >= 1) { |
decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); |
|
start_timer(); |
|
|
if ((vop_type == I_VOP || vop_type == P_VOP || vop_type == S_VOP)) { |
|
|
image_output(&dec->refn[0], dec->width, dec->height, |
|
|
dec->edged_width, frame->image, frame->stride, |
|
|
frame->colorspace, dec->interlacing); |
|
|
} else if (vop_type == B_VOP) { |
|
|
image_output(&dec->cur, dec->width, dec->height, |
|
|
dec->edged_width, frame->image, frame->stride, |
|
|
frame->colorspace, dec->interlacing); |
|
1963 |
} |
} |
1964 |
stop_conv_timer(); |
|
1965 |
|
decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution); |
1966 |
|
output = 1; |
1967 |
|
dec->frames++; |
1968 |
} |
} |
1969 |
|
|
1970 |
|
BitstreamByteAlign(&bs); |
1971 |
|
|
1972 |
|
/* low_delay_default mode: repeat in packed_mode */ |
1973 |
|
if (dec->low_delay_default && dec->packed_mode && output == 0 && success == 0) |
1974 |
|
{ |
1975 |
|
success = 1; |
1976 |
|
goto repeat; |
1977 |
} |
} |
|
#endif |
|
1978 |
|
|
1979 |
if (vop_type == I_VOP || vop_type == P_VOP || vop_type == S_VOP) { |
done : |
|
image_swap(&dec->refn[0], &dec->refn[1]); |
|
|
image_swap(&dec->cur, &dec->refn[0]); |
|
1980 |
|
|
1981 |
// swap MACROBLOCK |
/* low_delay_default mode: if we've gotten here without outputting anything, |
1982 |
// the Divx will not set the low_delay flage some times |
then output the recently decoded frame, or print an error message */ |
1983 |
// so follow code will wrong to not swap at that time |
if (dec->low_delay_default && output == 0) |
1984 |
// this will broken bitstream! so I'm change it, |
{ |
1985 |
// But that is not the best way! can anyone tell me how |
if (dec->packed_mode && seen_something) |
1986 |
// to do another way? |
{ |
1987 |
// 18-07-2002 MinChen<chenm001@163.com> |
/* output the recently decoded frame */ |
1988 |
//if (!dec->low_delay && vop_type == P_VOP) |
decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, dec->last_reduced_resolution); |
1989 |
if (vop_type == P_VOP) |
output = 1; |
|
mb_swap(&dec->mbs, &dec->last_mbs); |
|
1990 |
} |
} |
1991 |
|
else |
1992 |
|
{ |
1993 |
|
image_clear(&dec->cur, dec->width, dec->height, dec->edged_width, 0, 128, 128); |
1994 |
|
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, |
1995 |
|
"warning: nothing to output"); |
1996 |
|
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64, |
1997 |
|
"bframe decoder lag"); |
1998 |
|
|
1999 |
|
decoder_output(dec, &dec->cur, NULL, frame, 1 /*disable pp*/); |
2000 |
|
} |
2001 |
|
} |
2002 |
|
|
2003 |
|
frame->length = BitstreamPos(&bs) / 8; |
2004 |
|
|
2005 |
if (stats) |
if (stats) |
2006 |
{ |
{ |
2007 |
stats->notify = XVID_DEC_VOP; |
stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING; |
2008 |
stats->data.vop.time_base = (int)dec->time_base; |
stats->data.vop.time_base = (int)dec->time_base; |
2009 |
stats->data.vop.time_increment = 0; //XXX: todo |
stats->data.vop.time_increment = 0; //XXX: todo |
2010 |
} |
} |