55 |
* 22.12.2001 lock based interpolation |
* 22.12.2001 lock based interpolation |
56 |
* 01.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
* 01.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au> |
57 |
* |
* |
58 |
* $Id: decoder.c,v 1.37.2.15 2002-12-08 05:38:56 suxen_drol Exp $ |
* $Id: decoder.c,v 1.37.2.23 2002-12-16 08:54:44 suxen_drol Exp $ |
59 |
* |
* |
60 |
*************************************************************************/ |
*************************************************************************/ |
61 |
|
|
80 |
#include "utils/mem_transfer.h" |
#include "utils/mem_transfer.h" |
81 |
#include "image/interpolate8x8.h" |
#include "image/interpolate8x8.h" |
82 |
#include "image/reduced.h" |
#include "image/reduced.h" |
83 |
|
#include "image/font.h" |
84 |
|
|
85 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
86 |
#include "prediction/mbprediction.h" |
#include "prediction/mbprediction.h" |
97 |
{ |
{ |
98 |
/* free existing */ |
/* free existing */ |
99 |
|
|
100 |
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
101 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
102 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
103 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
104 |
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); |
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
|
105 |
|
|
106 |
if (dec->last_mbs) |
if (dec->last_mbs) |
107 |
xvid_free(dec->last_mbs); |
xvid_free(dec->last_mbs); |
135 |
xvid_free(dec); |
xvid_free(dec); |
136 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
137 |
} |
} |
138 |
if (image_create(&dec->refn[2], dec->edged_width, dec->edged_height)) { |
if (image_create(&dec->tmp, dec->edged_width, dec->edged_height)) { |
139 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
140 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
141 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
143 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
144 |
} |
} |
145 |
|
|
146 |
if (image_create(&dec->refh, dec->edged_width, dec->edged_height)) { |
if (image_create(&dec->qtmp, dec->edged_width, dec->edged_height)) { |
147 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
148 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
149 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
150 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
151 |
xvid_free(dec); |
xvid_free(dec); |
152 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
153 |
} |
} |
159 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
160 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
161 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
162 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
163 |
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); |
164 |
xvid_free(dec); |
xvid_free(dec); |
165 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
166 |
} |
} |
176 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
177 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
178 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
179 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
180 |
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); |
181 |
xvid_free(dec); |
xvid_free(dec); |
182 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
183 |
} |
} |
207 |
image_null(&dec->cur); |
image_null(&dec->cur); |
208 |
image_null(&dec->refn[0]); |
image_null(&dec->refn[0]); |
209 |
image_null(&dec->refn[1]); |
image_null(&dec->refn[1]); |
210 |
image_null(&dec->refn[2]); |
image_null(&dec->tmp); |
211 |
image_null(&dec->refh); |
image_null(&dec->qtmp); |
212 |
|
|
213 |
dec->mbs = NULL; |
dec->mbs = NULL; |
214 |
dec->last_mbs = NULL; |
dec->last_mbs = NULL; |
217 |
|
|
218 |
// add by chenm001 <chenm001@163.com> |
// add by chenm001 <chenm001@163.com> |
219 |
// for support B-frame to save reference frame's time |
// for support B-frame to save reference frame's time |
220 |
dec->frames = -1; |
dec->frames = 0; |
221 |
dec->time = dec->time_base = dec->last_time_base = 0; |
dec->time = dec->time_base = dec->last_time_base = 0; |
222 |
dec->low_delay = 0; |
dec->low_delay = 0; |
223 |
dec->packed_mode = 0; |
dec->packed_mode = 0; |
238 |
xvid_free(dec->mbs); |
xvid_free(dec->mbs); |
239 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
240 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
241 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->tmp, dec->edged_width, dec->edged_height); |
242 |
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
image_destroy(&dec->qtmp, dec->edged_width, dec->edged_height); |
243 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
244 |
xvid_free(dec); |
xvid_free(dec); |
245 |
|
|
390 |
|
|
391 |
// decode an inter macroblock |
// decode an inter macroblock |
392 |
|
|
|
static void |
|
|
set_block(uint8_t * dst, int stride, int width, int height, int color) |
|
|
{ |
|
|
int i; |
|
|
for (i = 0; i < height; i++) |
|
|
{ |
|
|
memset(dst, color, width); |
|
|
dst += stride; |
|
|
} |
|
|
} |
|
|
|
|
|
static void |
|
|
rrv_mv_scaleup(VECTOR * mv) |
|
|
{ |
|
|
if (mv->x > 0) { |
|
|
mv->x = 2*mv->x - 1; |
|
|
} else if (mv->x < 0) { |
|
|
mv->x = 2*mv->x + 1; |
|
|
} |
|
|
|
|
|
if (mv->y > 0) { |
|
|
mv->y = 2*mv->y - 1; |
|
|
} else if (mv->y < 0) { |
|
|
mv->y = 2*mv->y + 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
393 |
void |
void |
394 |
decoder_mbinter(DECODER * dec, |
decoder_mbinter(DECODER * dec, |
395 |
const MACROBLOCK * pMB, |
const MACROBLOCK * pMB, |
414 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
415 |
|
|
416 |
int uv_dx, uv_dy; |
int uv_dx, uv_dy; |
417 |
VECTOR mv[4]; |
VECTOR mv[4]; /* local copy of mvs */ |
|
|
|
|
for (i = 0; i < 4; i++) |
|
|
{ |
|
|
mv[i] = pMB->mvs[i]; |
|
|
//DPRINTF(DPRINTF_MB, "mv[%i] orig=%i,%i local=%i", i, pMB->mvs[i].x, pMB->mvs[i].y, mv[i].x, mv[i].y); |
|
|
} |
|
418 |
|
|
419 |
if (reduced_resolution) { |
if (reduced_resolution) { |
420 |
pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5); |
pY_Cur = dec->cur.y + (y_pos << 5) * stride + (x_pos << 5); |
421 |
pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4); |
pU_Cur = dec->cur.u + (y_pos << 4) * stride2 + (x_pos << 4); |
422 |
pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4); |
pV_Cur = dec->cur.v + (y_pos << 4) * stride2 + (x_pos << 4); |
423 |
DPRINTF(DPRINTF_MB,"[%i,%i] %i,%i %i,%i %i,%i %i,%i", |
for (i = 0; i < 4; i++) { |
424 |
x_pos, y_pos, |
mv[i].x = RRV_MV_SCALEUP(pMB->mvs[i].x); |
425 |
mv[0].x, mv[0].y, |
mv[i].y = RRV_MV_SCALEUP(pMB->mvs[i].y); |
426 |
mv[1].x, mv[1].y, |
} |
|
mv[2].x, mv[2].y, |
|
|
mv[3].x, mv[3].y); |
|
|
|
|
|
rrv_mv_scaleup(&mv[0]); |
|
|
rrv_mv_scaleup(&mv[1]); |
|
|
rrv_mv_scaleup(&mv[2]); |
|
|
rrv_mv_scaleup(&mv[3]); |
|
|
|
|
|
DPRINTF(DPRINTF_MB," %i,%i %i,%i %i,%i %i,%i", |
|
|
mv[0].x, mv[0].y, |
|
|
mv[1].x, mv[1].y, |
|
|
mv[2].x, mv[2].y, |
|
|
mv[3].x, mv[3].y); |
|
427 |
}else{ |
}else{ |
428 |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
429 |
pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
430 |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
431 |
|
for (i = 0; i < 4; i++) |
432 |
|
mv[i] = pMB->mvs[i]; |
433 |
} |
} |
434 |
|
|
435 |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) { |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) { |
459 |
else |
else |
460 |
{ |
{ |
461 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
462 |
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, |
463 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
464 |
mv[0].x, mv[0].y, stride, rounding); |
mv[0].x, mv[0].y, stride, rounding); |
465 |
} |
} |
466 |
else { |
else { |
513 |
else |
else |
514 |
{ |
{ |
515 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
516 |
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, |
517 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
518 |
mv[0].x, mv[0].y, stride, rounding); |
mv[0].x, mv[0].y, stride, rounding); |
519 |
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, |
520 |
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos, |
521 |
mv[1].x, mv[1].y, stride, rounding); |
mv[1].x, mv[1].y, stride, rounding); |
522 |
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, |
523 |
dec->refh.y + 128, 16*x_pos, 16*y_pos + 8, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8, |
524 |
mv[2].x, mv[2].y, stride, rounding); |
mv[2].x, mv[2].y, stride, rounding); |
525 |
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, |
526 |
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
527 |
mv[3].x, mv[3].y, stride, rounding); |
mv[3].x, mv[3].y, stride, rounding); |
528 |
} |
} |
529 |
else { |
else { |
619 |
{ |
{ |
620 |
uint32_t bound; |
uint32_t bound; |
621 |
uint32_t x, y; |
uint32_t x, y; |
622 |
int mb_width = dec->mb_width; |
uint32_t mb_width = dec->mb_width; |
623 |
int mb_height = dec->mb_height; |
uint32_t mb_height = dec->mb_height; |
624 |
|
|
625 |
if (reduced_resolution) |
if (reduced_resolution) |
626 |
{ |
{ |
627 |
mb_width /= 2; |
mb_width = (dec->width + 31) / 32; |
628 |
mb_height /= 2; |
mb_height = (dec->height + 31) / 32; |
629 |
} |
} |
630 |
|
|
631 |
bound = 0; |
bound = 0; |
678 |
|
|
679 |
if (dec->interlacing) { |
if (dec->interlacing) { |
680 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
681 |
DEBUG1("deci: field_dct: ", mb->field_dct); |
DPRINTF(DPRINTF_MB,"deci: field_dct: %i", mb->field_dct); |
682 |
} |
} |
683 |
|
|
684 |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
768 |
uint32_t x, y; |
uint32_t x, y; |
769 |
uint32_t bound; |
uint32_t bound; |
770 |
int cp_mb, st_mb; |
int cp_mb, st_mb; |
771 |
int mb_width = dec->mb_width; |
uint32_t mb_width = dec->mb_width; |
772 |
int mb_height = dec->mb_height; |
uint32_t mb_height = dec->mb_height; |
773 |
|
|
774 |
if (reduced_resolution) |
if (reduced_resolution) |
775 |
{ |
{ |
776 |
mb_width /= 2; |
mb_width = (dec->width + 31) / 32; |
777 |
mb_height /= 2; |
mb_height = (dec->height + 31) / 32; |
778 |
} |
} |
779 |
|
|
780 |
start_timer(); |
start_timer(); |
856 |
if (dec->interlacing) { |
if (dec->interlacing) { |
857 |
if (cbp || intra) { |
if (cbp || intra) { |
858 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
859 |
DEBUG1("decp: field_dct: ", mb->field_dct); |
DPRINTF(DPRINTF_MB,"decp: field_dct: %i", mb->field_dct); |
860 |
} |
} |
861 |
|
|
862 |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
863 |
mb->field_pred = BitstreamGetBit(bs); |
mb->field_pred = BitstreamGetBit(bs); |
864 |
DEBUG1("decp: field_pred: ", mb->field_pred); |
DPRINTF(DPRINTF_MB, "decp: field_pred: %i", mb->field_pred); |
865 |
|
|
866 |
if (mb->field_pred) { |
if (mb->field_pred) { |
867 |
mb->field_for_top = BitstreamGetBit(bs); |
mb->field_for_top = BitstreamGetBit(bs); |
868 |
DEBUG1("decp: field_for_top: ", mb->field_for_top); |
DPRINTF(DPRINTF_MB,"decp: field_for_top: %i", mb->field_for_top); |
869 |
mb->field_for_bot = BitstreamGetBit(bs); |
mb->field_for_bot = BitstreamGetBit(bs); |
870 |
DEBUG1("decp: field_for_bot: ", mb->field_for_bot); |
DPRINTF(DPRINTF_MB,"decp: field_for_bot: %i", mb->field_for_bot); |
871 |
} |
} |
872 |
} |
} |
873 |
} |
} |
1080 |
|
|
1081 |
start_timer(); |
start_timer(); |
1082 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
1083 |
interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->refh.y, dec->refh.y + 64, |
interpolate16x16_quarterpel(dec->cur.y, dec->refn[ref].y, dec->qtmp.y, dec->qtmp.y + 64, |
1084 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1085 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1086 |
} |
} |
1087 |
else { |
else { |
1235 |
start_timer(); |
start_timer(); |
1236 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
1237 |
if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) |
if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) |
1238 |
interpolate16x16_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64, |
interpolate16x16_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1239 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1240 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1241 |
else { |
else { |
1242 |
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1243 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1244 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, 0); |
1245 |
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1246 |
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos, |
1247 |
pMB->mvs[1].x, pMB->mvs[1].y, stride, 0); |
pMB->mvs[1].x, pMB->mvs[1].y, stride, 0); |
1248 |
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1249 |
dec->refh.y + 128, 16*x_pos, 16*y_pos + 8, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8, |
1250 |
pMB->mvs[2].x, pMB->mvs[2].y, stride, 0); |
pMB->mvs[2].x, pMB->mvs[2].y, stride, 0); |
1251 |
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->cur.y, forward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1252 |
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
1253 |
pMB->mvs[3].x, pMB->mvs[3].y, stride, 0); |
pMB->mvs[3].x, pMB->mvs[3].y, stride, 0); |
1254 |
} |
} |
1255 |
} |
} |
1273 |
|
|
1274 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
1275 |
if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) |
if((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) |
1276 |
interpolate16x16_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64, |
interpolate16x16_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1277 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1278 |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
1279 |
else { |
else { |
1280 |
interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1281 |
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1282 |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
1283 |
interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1284 |
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos, |
1285 |
pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0); |
pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0); |
1286 |
interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1287 |
dec->refh.y + 128, 16*x_pos, 16*y_pos + 8, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8, |
1288 |
pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0); |
pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0); |
1289 |
interpolate8x8_quarterpel(dec->refn[2].y, backward.y, dec->refh.y, dec->refh.y + 64, |
interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1290 |
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
1291 |
pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0); |
pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0); |
1292 |
} |
} |
1293 |
} |
} |
1294 |
else { |
else { |
1295 |
interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos, 16 * y_pos, |
interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos, 16 * y_pos, |
1296 |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
1297 |
interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8, |
interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8, |
1298 |
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, |
1299 |
0); |
0); |
1300 |
interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos, |
interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos, |
1301 |
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, |
1302 |
stride, 0); |
stride, 0); |
1303 |
interpolate8x8_switch(dec->refn[2].y, backward.y, 16 * x_pos + 8, |
interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8, |
1304 |
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, |
1305 |
stride, 0); |
stride, 0); |
1306 |
} |
} |
1307 |
|
|
1308 |
interpolate8x8_switch(dec->refn[2].u, backward.u, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->tmp.u, backward.u, 8 * x_pos, 8 * y_pos, |
1309 |
b_uv_dx, b_uv_dy, stride2, 0); |
b_uv_dx, b_uv_dy, stride2, 0); |
1310 |
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, |
1311 |
b_uv_dx, b_uv_dy, stride2, 0); |
b_uv_dx, b_uv_dy, stride2, 0); |
1312 |
|
|
1313 |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
1314 |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
1315 |
dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos, |
dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos, |
1316 |
stride, 1, 8); |
stride, 1, 8); |
1317 |
|
|
1318 |
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, |
1319 |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1320 |
dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos + 8, |
dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1321 |
stride, 1, 8); |
stride, 1, 8); |
1322 |
|
|
1323 |
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, |
1324 |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
1325 |
dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
1326 |
stride, 1, 8); |
stride, 1, 8); |
1327 |
|
|
1328 |
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, |
1329 |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
1330 |
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, |
1331 |
stride, 1, 8); |
stride, 1, 8); |
1332 |
|
|
1333 |
interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
1334 |
dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
1335 |
dec->refn[2].u + (8 * y_pos * stride2) + 8 * x_pos, |
dec->tmp.u + (8 * y_pos * stride2) + 8 * x_pos, |
1336 |
stride2, 1, 8); |
stride2, 1, 8); |
1337 |
|
|
1338 |
interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
1339 |
dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
1340 |
dec->refn[2].v + (8 * y_pos * stride2) + 8 * x_pos, |
dec->tmp.v + (8 * y_pos * stride2) + 8 * x_pos, |
1341 |
stride2, 1, 8); |
stride2, 1, 8); |
1342 |
|
|
1343 |
stop_comp_timer(); |
stop_comp_timer(); |
1581 |
break; |
break; |
1582 |
|
|
1583 |
default: |
default: |
1584 |
DEBUG1("Not support B-frame mb_type =", mb->mb_type); |
DPRINTF(DPRINTF_ERROR,"Not support B-frame mb_type = %i", mb->mb_type); |
1585 |
} |
} |
1586 |
|
|
1587 |
} // end of FOR |
} // end of FOR |
1606 |
*mb2 = temp; |
*mb2 = temp; |
1607 |
} |
} |
1608 |
|
|
1609 |
|
|
1610 |
|
/* perform post processing if necessary, and output the image */ |
1611 |
|
void decoder_output(DECODER * dec, IMAGE * img, MACROBLOCK * mbs, |
1612 |
|
const XVID_DEC_FRAME * frame, int pp_disable) |
1613 |
|
{ |
1614 |
|
|
1615 |
|
if ((frame->general & (XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV)) && !pp_disable) /* post process */ |
1616 |
|
{ |
1617 |
|
/* note: image is stored to tmp */ |
1618 |
|
image_copy(&dec->tmp, img, dec->edged_width, dec->height); |
1619 |
|
image_deblock_rrv(&dec->tmp, dec->edged_width, |
1620 |
|
mbs, dec->mb_width, dec->mb_height, dec->mb_width, |
1621 |
|
8, frame->general); |
1622 |
|
img = &dec->tmp; |
1623 |
|
} |
1624 |
|
|
1625 |
|
image_output(img, dec->width, dec->height, |
1626 |
|
dec->edged_width, frame->image, frame->stride, |
1627 |
|
frame->colorspace, dec->interlacing); |
1628 |
|
} |
1629 |
|
|
1630 |
|
|
1631 |
int |
int |
1632 |
decoder_decode(DECODER * dec, |
decoder_decode(DECODER * dec, |
1633 |
XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats) |
XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats) |
1643 |
VECTOR gmc_mv[5]; |
VECTOR gmc_mv[5]; |
1644 |
uint32_t vop_type; |
uint32_t vop_type; |
1645 |
int success = 0; |
int success = 0; |
1646 |
|
int output = 0; |
1647 |
|
int seen_something = 0; |
1648 |
|
|
1649 |
start_global_timer(); |
start_global_timer(); |
1650 |
|
|
1651 |
|
dec->low_delay_default = (frame->general & XVID_DEC_LOWDELAY); |
1652 |
dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL; |
dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL; |
1653 |
|
|
1654 |
|
if ((frame->general & XVID_DEC_DISCONTINUITY)) |
1655 |
|
dec->frames = 0; |
1656 |
|
|
1657 |
|
if (frame->length < 0) /* decoder flush */ |
1658 |
|
{ |
1659 |
|
/* if not decoding "low_delay/packed", and this isn't low_delay and |
1660 |
|
we have a reference frame, then outout the reference frame */ |
1661 |
|
if (!(dec->low_delay_default && dec->packed_mode) && !dec->low_delay && dec->frames>0) |
1662 |
|
{ |
1663 |
|
decoder_output(dec, &dec->refn[0], dec->mbs, frame, dec->last_reduced_resolution); |
1664 |
|
output = 1; |
1665 |
|
} |
1666 |
|
|
1667 |
|
frame->length = 0; |
1668 |
|
if (stats) |
1669 |
|
{ |
1670 |
|
stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING; |
1671 |
|
stats->data.vop.time_base = (int)dec->time_base; |
1672 |
|
stats->data.vop.time_increment = 0; //XXX: todo |
1673 |
|
} |
1674 |
|
|
1675 |
|
emms(); |
1676 |
|
|
1677 |
|
stop_global_timer(); |
1678 |
|
return XVID_ERR_OK; |
1679 |
|
} |
1680 |
|
|
1681 |
BitstreamInit(&bs, frame->bitstream, frame->length); |
BitstreamInit(&bs, frame->bitstream, frame->length); |
1682 |
|
|
1683 |
// XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's |
// XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's |
1684 |
if(frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f) |
if(dec->low_delay_default && frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f) |
1685 |
{ |
{ |
1686 |
if (stats) |
if (stats) |
1687 |
stats->notify = XVID_DEC_VOP; |
stats->notify = XVID_DEC_VOP; |
1692 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
1693 |
} |
} |
1694 |
|
|
1695 |
start: |
repeat: |
|
// add by chenm001 <chenm001@163.com> |
|
|
// for support B-frame to reference last 2 frame |
|
|
dec->frames++; |
|
1696 |
|
|
1697 |
xxx: |
vop_type = BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, |
|
vop_type = |
|
|
BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, |
|
1698 |
&quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, gmc_mv); |
&quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, gmc_mv); |
1699 |
|
|
1700 |
//DPRINTF(DPRINTF_HEADER, "vop_type=%i", vop_type); |
DPRINTF(DPRINTF_HEADER, "vop_type=%i, packed=%i, time=%i, time_pp=%i, time_bp=%i", |
1701 |
|
vop_type, dec->packed_mode, dec->time, dec->time_pp, dec->time_bp); |
1702 |
|
|
1703 |
if (vop_type == -1 && success) |
if (vop_type == - 1) |
1704 |
goto done; |
{ |
1705 |
|
if (success) goto done; |
1706 |
|
return XVID_ERR_FAIL; |
1707 |
|
} |
1708 |
|
|
1709 |
if (vop_type == -2 || vop_type == -3) |
if (vop_type == -2 || vop_type == -3) |
1710 |
{ |
{ |
1725 |
frame->length = BitstreamPos(&bs) / 8; |
frame->length = BitstreamPos(&bs) / 8; |
1726 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
1727 |
} |
} |
1728 |
goto xxx; |
goto repeat; |
1729 |
} |
} |
1730 |
|
|
1731 |
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 |
1732 |
|
|
|
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; |
|
1733 |
|
|
1734 |
|
/* packed_mode: special-N_VOP treament */ |
1735 |
|
if (dec->packed_mode && vop_type == N_VOP) |
1736 |
|
{ |
1737 |
|
if (dec->low_delay_default && dec->frames > 0) |
1738 |
|
{ |
1739 |
|
decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, dec->last_reduced_resolution); |
1740 |
|
output = 1; |
1741 |
|
} |
1742 |
|
/* ignore otherwise */ |
1743 |
|
} |
1744 |
|
else if (vop_type != B_VOP) |
1745 |
|
{ |
1746 |
|
switch(vop_type) |
1747 |
|
{ |
1748 |
case I_VOP: |
case I_VOP: |
1749 |
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 |
|
1750 |
break; |
break; |
1751 |
|
case P_VOP : |
1752 |
case B_VOP: |
decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, |
1753 |
#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 |
|
1754 |
break; |
break; |
|
|
|
1755 |
case S_VOP : |
case S_VOP : |
1756 |
decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, |
decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, |
1757 |
fcode_forward, intra_dc_threshold, gmc_mv); |
fcode_forward, intra_dc_threshold, gmc_mv); |
1758 |
break; |
break; |
1759 |
|
case N_VOP : |
|
case N_VOP: // vop not coded |
|
|
// when low_delay==0, N_VOP's should interpolate between the past and future frames |
|
1760 |
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 |
|
1761 |
break; |
break; |
|
|
|
|
default: |
|
|
if (stats) |
|
|
stats->notify = 0; |
|
|
|
|
|
emms(); |
|
|
return XVID_ERR_FAIL; |
|
1762 |
} |
} |
1763 |
|
|
|
|
|
|
/* reduced resolution deblocking filter */ |
|
|
|
|
1764 |
if (reduced_resolution) |
if (reduced_resolution) |
1765 |
{ |
{ |
1766 |
const int rmb_height = dec->mb_height / 2; |
image_deblock_rrv(&dec->cur, dec->edged_width, dec->mbs, |
1767 |
const int rmb_width = dec->mb_width / 2; |
(dec->width + 31) / 32, (dec->height + 31) / 32, dec->mb_width, |
1768 |
const int edged_width2 = dec->edged_width /2; |
16, XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV); |
1769 |
int i,j; |
} |
|
|
|
|
/* horizontal deblocking */ |
|
1770 |
|
|
1771 |
for (j = 1; j < rmb_height*2; j++) // luma: j,i in block units |
/* note: for packed_mode, output is performed when the special-N_VOP is decoded */ |
1772 |
for (i = 0; i < rmb_width*2; i++) |
if (!(dec->low_delay_default && dec->packed_mode)) |
1773 |
{ |
{ |
1774 |
if (dec->mbs[(j-1)/2*dec->mb_width + (i/2)].mode != MODE_NOT_CODED || |
if (dec->low_delay) |
|
dec->mbs[(j+0)/2*dec->mb_width + (i/2)].mode != MODE_NOT_CODED) |
|
1775 |
{ |
{ |
1776 |
xvid_HFilter_31_C(dec->cur.y + (j*16 - 1)*dec->edged_width + i*16, |
decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution); |
1777 |
dec->cur.y + (j*16 + 0)*dec->edged_width + i*16, 2); |
output = 1; |
1778 |
} |
} |
1779 |
} |
else if (dec->frames > 0) /* is the reference frame valid? */ |
|
|
|
|
for (j = 1; j < rmb_height; j++) // chroma |
|
|
for (i = 0; i < rmb_width; i++) |
|
1780 |
{ |
{ |
1781 |
if (dec->mbs[(j-1)*dec->mb_width + i].mode != MODE_NOT_CODED || |
/* output the reference frame */ |
1782 |
dec->mbs[(j+0)*dec->mb_width + i].mode != MODE_NOT_CODED) |
decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, dec->last_reduced_resolution); |
1783 |
{ |
output = 1; |
|
hfilter_31(dec->cur.u + (j*16 - 1)*edged_width2 + i*16, |
|
|
dec->cur.u + (j*16 + 0)*edged_width2 + i*16, 2); |
|
|
hfilter_31(dec->cur.v + (j*16 - 1)*edged_width2 + i*16, |
|
|
dec->cur.v + (j*16 + 0)*edged_width2 + i*16, 2); |
|
1784 |
} |
} |
1785 |
} |
} |
1786 |
|
|
1787 |
/* vertical deblocking */ |
image_swap(&dec->refn[0], &dec->refn[1]); |
1788 |
|
image_swap(&dec->cur, &dec->refn[0]); |
1789 |
|
mb_swap(&dec->mbs, &dec->last_mbs); |
1790 |
|
dec->last_reduced_resolution = reduced_resolution; |
1791 |
|
|
1792 |
for (j = 0; j < rmb_height*2; j++) // luma: i,j in block units |
dec->frames++; |
1793 |
for (i = 1; i < rmb_width*2; i++) |
seen_something = 1; |
|
{ |
|
|
if (dec->mbs[(j/2)*dec->mb_width + (i-1)/2].mode != MODE_NOT_CODED || |
|
|
dec->mbs[(j/2)*dec->mb_width + (i+0)/2].mode != MODE_NOT_CODED) |
|
|
{ |
|
|
vfilter_31(dec->cur.y + (j*16)*dec->edged_width + i*16 - 1, |
|
|
dec->cur.y + (j*16)*dec->edged_width + i*16 + 0, |
|
|
dec->edged_width, 2); |
|
|
} |
|
|
} |
|
1794 |
|
|
1795 |
for (j = 0; j < rmb_height; j++) // chroma |
}else{ /* B_VOP */ |
1796 |
for (i = 1; i < rmb_width; i++) |
|
1797 |
{ |
if (dec->low_delay) |
|
if (dec->mbs[j*dec->mb_width + i - 1].mode != MODE_NOT_CODED || |
|
|
dec->mbs[j*dec->mb_width + i + 0].mode != MODE_NOT_CODED) |
|
1798 |
{ |
{ |
1799 |
vfilter_31(dec->cur.u + (j*16)*edged_width2 + i*16 - 1, |
DPRINTF(DPRINTF_ERROR, "warning: bvop found in low_delay==1 stream"); |
1800 |
dec->cur.u + (j*16)*edged_width2 + i*16 + 0, |
dec->low_delay = 1; |
|
edged_width2, 2); |
|
|
vfilter_31(dec->cur.v + (j*16)*edged_width2 + i*16 - 1, |
|
|
dec->cur.v + (j*16)*edged_width2 + i*16 + 0, |
|
|
edged_width2, 2); |
|
|
} |
|
|
} |
|
1801 |
} |
} |
1802 |
|
|
1803 |
BitstreamByteAlign(&bs); |
if (dec->frames < 2) |
1804 |
|
{ |
1805 |
#ifdef BFRAMES_DEC |
/* attemping to decode a bvop without atleast 2 reference frames */ |
1806 |
// test if no B_VOP |
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, |
1807 |
if (dec->low_delay || dec->frames == 0 || ((dec->packed_mode) && !(frame->length > BitstreamPos(&bs) / 8))) { |
"broken b-frame, mising ref frames"); |
1808 |
#endif |
}else if (dec->time_pp <= dec->time_bp) { |
1809 |
image_output(&dec->cur, dec->width, dec->height, dec->edged_width, |
/* this occurs when dx50_bvop_compatibility==0 sequences are |
1810 |
frame->image, frame->stride, frame->colorspace, dec->interlacing); |
decoded in vfw. */ |
1811 |
|
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, |
1812 |
#ifdef BFRAMES_DEC |
"broken b-frame, tpp=%i tbp=%i", dec->time_pp, dec->time_bp); |
1813 |
} else { |
} else { |
1814 |
if (dec->frames >= 1 && !(dec->packed_mode)) { |
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); |
|
|
} |
|
|
stop_conv_timer(); |
|
|
} |
|
1815 |
} |
} |
|
#endif |
|
1816 |
|
|
1817 |
if (vop_type == I_VOP || vop_type == P_VOP || vop_type == S_VOP) { |
decoder_output(dec, &dec->cur, dec->mbs, frame, reduced_resolution); |
1818 |
image_swap(&dec->refn[0], &dec->refn[1]); |
output = 1; |
1819 |
image_swap(&dec->cur, &dec->refn[0]); |
dec->frames++; |
|
|
|
|
// swap MACROBLOCK |
|
|
// the Divx will not set the low_delay flage some times |
|
|
// so follow code will wrong to not swap at that time |
|
|
// this will broken bitstream! so I'm change it, |
|
|
// But that is not the best way! can anyone tell me how |
|
|
// to do another way? |
|
|
// 18-07-2002 MinChen<chenm001@163.com> |
|
|
//if (!dec->low_delay && vop_type == P_VOP) |
|
|
if (vop_type == P_VOP) |
|
|
mb_swap(&dec->mbs, &dec->last_mbs); |
|
1820 |
} |
} |
1821 |
|
|
1822 |
|
BitstreamByteAlign(&bs); |
1823 |
|
|
1824 |
if (success == 0 && dec->packed_mode) |
/* low_delay_default mode: repeat in packed_mode */ |
1825 |
|
if (dec->low_delay_default && dec->packed_mode && output == 0 && success == 0) |
1826 |
{ |
{ |
1827 |
success = 1; |
success = 1; |
1828 |
// if (frame->length > BitstreamPos(&bs) / 8) // multiple vops packed together |
goto repeat; |
|
goto start; |
|
1829 |
} |
} |
1830 |
|
|
1831 |
done : |
done : |
1832 |
|
|
1833 |
|
/* low_delay_default mode: if we've gotten here without outputting anything, |
1834 |
|
then output the recently decoded frame, or print an error message */ |
1835 |
|
if (dec->low_delay_default && output == 0) |
1836 |
|
{ |
1837 |
|
if (dec->packed_mode && seen_something) |
1838 |
|
{ |
1839 |
|
/* output the recently decoded frame */ |
1840 |
|
decoder_output(dec, &dec->refn[0], dec->last_mbs, frame, dec->last_reduced_resolution); |
1841 |
|
output = 1; |
1842 |
|
} |
1843 |
|
else |
1844 |
|
{ |
1845 |
|
image_clear(&dec->cur, dec->width, dec->height, dec->edged_width, 0, 128, 128); |
1846 |
|
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 16, |
1847 |
|
"warning: nothing to output"); |
1848 |
|
image_printf(&dec->cur, dec->edged_width, dec->height, 16, 64, |
1849 |
|
"bframe decoder lag"); |
1850 |
|
|
1851 |
|
decoder_output(dec, &dec->cur, NULL, frame, 1 /*disable pp*/); |
1852 |
|
} |
1853 |
|
} |
1854 |
|
|
1855 |
frame->length = BitstreamPos(&bs) / 8; |
frame->length = BitstreamPos(&bs) / 8; |
1856 |
|
|
1857 |
if (stats) |
if (stats) |
1858 |
{ |
{ |
1859 |
stats->notify = XVID_DEC_VOP; |
stats->notify = output ? XVID_DEC_VOP : XVID_DEC_NOTHING; |
1860 |
stats->data.vop.time_base = (int)dec->time_base; |
stats->data.vop.time_base = (int)dec->time_base; |
1861 |
stats->data.vop.time_increment = 0; //XXX: todo |
stats->data.vop.time_increment = 0; //XXX: todo |
1862 |
} |
} |