32 |
* |
* |
33 |
* History: |
* History: |
34 |
* |
* |
35 |
|
* 15.07.2002 fix a bug in B-frame decode at DIRECT mode |
36 |
|
* MinChen <chenm001@163.com> |
37 |
|
* 10.07.2002 added BFRAMES_DEC_DEBUG support |
38 |
|
* Fix a little bug for low_delay flage |
39 |
|
* MinChen <chenm001@163.com> |
40 |
|
* 28.06.2002 added basic resync support to iframe/pframe_decode() |
41 |
* 22.06.2002 added primative N_VOP support |
* 22.06.2002 added primative N_VOP support |
42 |
* #define BFRAMES_DEC now enables Minchenm's bframe decoder |
* #define BFRAMES_DEC now enables Minchen's bframe decoder |
43 |
* 08.05.2002 add low_delay support for B_VOP decode |
* 08.05.2002 add low_delay support for B_VOP decode |
44 |
* MinChen <chenm001@163.com> |
* MinChen <chenm001@163.com> |
45 |
* 05.05.2002 fix some B-frame decode problem |
* 05.05.2002 fix some B-frame decode problem |
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.25 2002-07-09 01:09:33 chenm001 Exp $ |
* $Id: decoder.c,v 1.37.2.12 2002-11-19 13:21:24 suxen_drol Exp $ |
59 |
* |
* |
60 |
*************************************************************************/ |
*************************************************************************/ |
61 |
|
|
62 |
#include <stdlib.h> |
#include <stdlib.h> |
63 |
#include <string.h> |
#include <string.h> |
64 |
|
|
65 |
|
#ifdef BFRAMES_DEC_DEBUG |
66 |
|
#define BFRAMES_DEC |
67 |
|
#endif |
68 |
|
|
69 |
#include "xvid.h" |
#include "xvid.h" |
70 |
#include "portab.h" |
#include "portab.h" |
71 |
|
|
84 |
#include "prediction/mbprediction.h" |
#include "prediction/mbprediction.h" |
85 |
#include "utils/timer.h" |
#include "utils/timer.h" |
86 |
#include "utils/emms.h" |
#include "utils/emms.h" |
87 |
|
#include "motion/motion.h" |
88 |
|
|
89 |
#include "image/image.h" |
#include "image/image.h" |
90 |
#include "image/colorspace.h" |
#include "image/colorspace.h" |
91 |
#include "utils/mem_align.h" |
#include "utils/mem_align.h" |
92 |
|
|
93 |
int |
int |
94 |
decoder_create(XVID_DEC_PARAM * param) |
decoder_resize(DECODER * dec) |
95 |
{ |
{ |
96 |
DECODER *dec; |
/* free existing */ |
97 |
|
|
98 |
dec = xvid_malloc(sizeof(DECODER), CACHE_LINE); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
99 |
if (dec == NULL) { |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
100 |
return XVID_ERR_MEMORY; |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
101 |
} |
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
102 |
param->handle = dec; |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
103 |
|
|
104 |
dec->width = param->width; |
if (dec->last_mbs) |
105 |
dec->height = param->height; |
xvid_free(dec->last_mbs); |
106 |
|
if (dec->mbs) |
107 |
|
xvid_free(dec->mbs); |
108 |
|
|
109 |
|
/* realloc */ |
110 |
|
|
111 |
dec->mb_width = (dec->width + 15) / 16; |
dec->mb_width = (dec->width + 15) / 16; |
112 |
dec->mb_height = (dec->height + 15) / 16; |
dec->mb_height = (dec->height + 15) / 16; |
113 |
|
|
114 |
dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE; |
dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE; |
115 |
dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE; |
dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE; |
|
dec->low_delay = 0; |
|
116 |
|
|
117 |
if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) { |
if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) { |
118 |
xvid_free(dec); |
xvid_free(dec); |
124 |
xvid_free(dec); |
xvid_free(dec); |
125 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
126 |
} |
} |
127 |
|
|
128 |
// add by chenm001 <chenm001@163.com> |
// add by chenm001 <chenm001@163.com> |
129 |
// for support B-frame to reference last 2 frame |
// for support B-frame to reference last 2 frame |
130 |
if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) { |
if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) { |
141 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
142 |
} |
} |
143 |
|
|
144 |
|
if (image_create(&dec->refh, dec->edged_width, dec->edged_height)) { |
145 |
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
146 |
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
147 |
|
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
148 |
|
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
149 |
|
xvid_free(dec); |
150 |
|
return XVID_ERR_MEMORY; |
151 |
|
} |
152 |
|
|
153 |
dec->mbs = |
dec->mbs = |
154 |
xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, |
xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, |
155 |
CACHE_LINE); |
CACHE_LINE); |
158 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
159 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
160 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
161 |
|
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
162 |
xvid_free(dec); |
xvid_free(dec); |
163 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
164 |
} |
} |
|
|
|
165 |
memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
166 |
|
|
167 |
// add by chenm001 <chenm001@163.com> |
// add by chenm001 <chenm001@163.com> |
175 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
176 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
177 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
178 |
|
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
179 |
xvid_free(dec); |
xvid_free(dec); |
180 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
181 |
} |
} |
182 |
|
|
183 |
memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
184 |
|
|
|
init_timer(); |
|
|
|
|
|
// add by chenm001 <chenm001@163.com> |
|
|
// for support B-frame to save reference frame's time |
|
|
dec->frames = -1; |
|
|
dec->time = dec->time_base = dec->last_time_base = 0; |
|
|
|
|
185 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
186 |
} |
} |
187 |
|
|
188 |
|
|
|
|
|
|
/* **************************************************************** |
|
|
NIC 28.06.2002 |
|
|
riscritta la 'decoder_create' per cambiarne l'interfaccia e poterla |
|
|
usare nella dll caricata dall'IM1 player |
|
|
IM1_decoder_create(XVID_DEC_PARAM * param,XVID_DEC_FRAME * frame) |
|
|
**************************************************************** */ |
|
|
//XVID_DEC_FRAME * frame |
|
|
|
|
189 |
int |
int |
190 |
IM1_decoder_create(XVID_DEC_PARAM * param,XVID_DEC_FRAME * frame) |
decoder_create(XVID_DEC_PARAM * param) |
191 |
{ |
{ |
192 |
DECODER *dec; |
DECODER *dec; |
|
Bitstream bs; |
|
|
uint32_t rounding; |
|
|
uint32_t quant; |
|
|
uint32_t fcode_forward; |
|
|
uint32_t fcode_backward; |
|
|
uint32_t intra_dc_threshold; |
|
193 |
|
|
194 |
dec = xvid_malloc(sizeof(DECODER), CACHE_LINE); |
dec = xvid_malloc(sizeof(DECODER), CACHE_LINE); |
195 |
if (dec == NULL) { |
if (dec == NULL) { |
196 |
return XVID_ERR_MEMORY; |
return XVID_ERR_MEMORY; |
197 |
} |
} |
198 |
param->handle = dec; |
memset(dec, 0, sizeof(DECODER)); |
|
|
|
|
|
|
|
BitstreamInit(&bs, frame->bitstream, frame->length);//NIC |
|
|
|
|
|
//NIC |
|
|
BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode_forward, |
|
|
&fcode_backward, &intra_dc_threshold); |
|
|
|
|
|
|
|
|
param->width = dec->width; //NIC added |
|
|
param->height = dec->height; //NIC added |
|
|
//dec->width = param->width; //NIC commentate |
|
|
//dec->height = param->height; //NIC commentate |
|
|
|
|
|
dec->mb_width = (dec->width + 15) / 16; |
|
|
dec->mb_height = (dec->height + 15) / 16; |
|
|
|
|
|
dec->edged_width = 16 * dec->mb_width + 2 * EDGE_SIZE; |
|
|
dec->edged_height = 16 * dec->mb_height + 2 * EDGE_SIZE; |
|
|
dec->low_delay = 0; |
|
|
|
|
|
if (image_create(&dec->cur, dec->edged_width, dec->edged_height)) { |
|
|
xvid_free(dec); |
|
|
return XVID_ERR_MEMORY; |
|
|
} |
|
199 |
|
|
200 |
if (image_create(&dec->refn[0], dec->edged_width, dec->edged_height)) { |
param->handle = dec; |
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
|
|
xvid_free(dec); |
|
|
return XVID_ERR_MEMORY; |
|
|
} |
|
|
// add by chenm001 <chenm001@163.com> |
|
|
// for support B-frame to reference last 2 frame |
|
|
if (image_create(&dec->refn[1], dec->edged_width, dec->edged_height)) { |
|
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
|
|
xvid_free(dec); |
|
|
return XVID_ERR_MEMORY; |
|
|
} |
|
|
if (image_create(&dec->refn[2], dec->edged_width, dec->edged_height)) { |
|
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
|
|
xvid_free(dec); |
|
|
return XVID_ERR_MEMORY; |
|
|
} |
|
201 |
|
|
202 |
dec->mbs = |
dec->width = param->width; |
203 |
xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, |
dec->height = param->height; |
|
CACHE_LINE); |
|
|
if (dec->mbs == NULL) { |
|
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
|
|
xvid_free(dec); |
|
|
return XVID_ERR_MEMORY; |
|
|
} |
|
204 |
|
|
205 |
memset(dec->mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
image_null(&dec->cur); |
206 |
|
image_null(&dec->refn[0]); |
207 |
|
image_null(&dec->refn[1]); |
208 |
|
image_null(&dec->refn[2]); |
209 |
|
image_null(&dec->refh); |
210 |
|
|
211 |
// add by chenm001 <chenm001@163.com> |
dec->mbs = NULL; |
212 |
// for skip MB flag |
dec->last_mbs = NULL; |
|
dec->last_mbs = |
|
|
xvid_malloc(sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height, |
|
|
CACHE_LINE); |
|
|
if (dec->last_mbs == NULL) { |
|
|
xvid_free(dec->mbs); |
|
|
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
|
|
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
|
|
xvid_free(dec); |
|
|
return XVID_ERR_MEMORY; |
|
|
} |
|
|
|
|
|
memset(dec->last_mbs, 0, sizeof(MACROBLOCK) * dec->mb_width * dec->mb_height); |
|
213 |
|
|
214 |
init_timer(); |
init_timer(); |
215 |
|
|
217 |
// for support B-frame to save reference frame's time |
// for support B-frame to save reference frame's time |
218 |
dec->frames = -1; |
dec->frames = -1; |
219 |
dec->time = dec->time_base = dec->last_time_base = 0; |
dec->time = dec->time_base = dec->last_time_base = 0; |
220 |
|
dec->low_delay = 0; |
221 |
|
|
222 |
|
dec->fixed_dimensions = (dec->width > 0 && dec->height > 0); |
223 |
|
|
224 |
|
if (dec->fixed_dimensions) |
225 |
|
return decoder_resize(dec); |
226 |
|
else |
227 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
228 |
} |
} |
229 |
/* **************************************************************** |
|
|
END NIC |
|
|
**************************************************************** */ |
|
230 |
|
|
231 |
int |
int |
232 |
decoder_destroy(DECODER * dec) |
decoder_destroy(DECODER * dec) |
236 |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[0], dec->edged_width, dec->edged_height); |
237 |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[1], dec->edged_width, dec->edged_height); |
238 |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
image_destroy(&dec->refn[2], dec->edged_width, dec->edged_height); |
239 |
|
image_destroy(&dec->refh, dec->edged_width, dec->edged_height); |
240 |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
image_destroy(&dec->cur, dec->edged_width, dec->edged_height); |
241 |
xvid_free(dec); |
xvid_free(dec); |
242 |
|
|
264 |
const uint32_t cbp, |
const uint32_t cbp, |
265 |
Bitstream * bs, |
Bitstream * bs, |
266 |
const uint32_t quant, |
const uint32_t quant, |
267 |
const uint32_t intra_dc_threshold) |
const uint32_t intra_dc_threshold, |
268 |
|
const unsigned int bound) |
269 |
{ |
{ |
270 |
|
|
271 |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(block, 6, 64, int16_t, CACHE_LINE); |
291 |
|
|
292 |
start_timer(); |
start_timer(); |
293 |
predict_acdc(dec->mbs, x_pos, y_pos, dec->mb_width, i, &block[i * 64], |
predict_acdc(dec->mbs, x_pos, y_pos, dec->mb_width, i, &block[i * 64], |
294 |
iQuant, iDcScaler, predictors); |
iQuant, iDcScaler, predictors, bound); |
295 |
if (!acpred_flag) { |
if (!acpred_flag) { |
296 |
pMB->acpred_directions[i] = 0; |
pMB->acpred_directions[i] = 0; |
297 |
} |
} |
310 |
|
|
311 |
block[i * 64 + 0] = dc_dif; |
block[i * 64 + 0] = dc_dif; |
312 |
start_coeff = 1; |
start_coeff = 1; |
313 |
|
|
314 |
|
DPRINTF(DPRINTF_COEFF,"block[0] %i", dc_dif); |
315 |
} else { |
} else { |
316 |
start_coeff = 0; |
start_coeff = 0; |
317 |
} |
} |
319 |
start_timer(); |
start_timer(); |
320 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) // coded |
321 |
{ |
{ |
322 |
get_intra_block(bs, &block[i * 64], pMB->acpred_directions[i], |
int direction = dec->alternate_vertical_scan ? |
323 |
start_coeff); |
2 : pMB->acpred_directions[i]; |
324 |
|
|
325 |
|
get_intra_block(bs, &block[i * 64], direction, start_coeff); |
326 |
} |
} |
327 |
stop_coding_timer(); |
stop_coding_timer(); |
328 |
|
|
364 |
|
|
365 |
#define SIGN(X) (((X)>0)?1:-1) |
#define SIGN(X) (((X)>0)?1:-1) |
366 |
#define ABS(X) (((X)>0)?(X):-(X)) |
#define ABS(X) (((X)>0)?(X):-(X)) |
|
static const uint32_t roundtab[16] = |
|
|
{ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2 }; |
|
|
|
|
367 |
|
|
368 |
// decode an inter macroblock |
// decode an inter macroblock |
369 |
|
|
398 |
uv_dx = pMB->mvs[0].x; |
uv_dx = pMB->mvs[0].x; |
399 |
uv_dy = pMB->mvs[0].y; |
uv_dy = pMB->mvs[0].y; |
400 |
|
|
401 |
uv_dx = (uv_dx & 3) ? (uv_dx >> 1) | 1 : uv_dx / 2; |
if (dec->quarterpel) |
402 |
uv_dy = (uv_dy & 3) ? (uv_dy >> 1) | 1 : uv_dy / 2; |
{ |
403 |
|
uv_dx /= 2; |
404 |
|
uv_dy /= 2; |
405 |
|
} |
406 |
|
|
407 |
|
uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; |
408 |
|
uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; |
409 |
|
|
410 |
|
start_timer(); |
411 |
|
if(dec->quarterpel) { |
412 |
|
interpolate16x16_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
413 |
|
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
414 |
|
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
415 |
|
} |
416 |
|
else { |
417 |
|
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos, |
418 |
|
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
419 |
|
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos, |
420 |
|
pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
421 |
|
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8, |
422 |
|
pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
423 |
|
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8, |
424 |
|
pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
425 |
|
} |
426 |
|
|
427 |
|
interpolate8x8_switch(dec->cur.u, dec->refn[0].u, 8 * x_pos, 8 * y_pos, |
428 |
|
uv_dx, uv_dy, stride2, rounding); |
429 |
|
interpolate8x8_switch(dec->cur.v, dec->refn[0].v, 8 * x_pos, 8 * y_pos, |
430 |
|
uv_dx, uv_dy, stride2, rounding); |
431 |
|
stop_comp_timer(); |
432 |
|
|
433 |
} else { |
} else { |
434 |
int sum; |
int sum; |
435 |
|
|
436 |
|
if(dec->quarterpel) |
437 |
|
sum = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2); |
438 |
|
else |
439 |
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)); |
|
440 |
|
|
441 |
|
uv_dx = (sum >> 3) + roundtab_76[sum & 0xf]; |
442 |
|
|
443 |
|
if(dec->quarterpel) |
444 |
|
sum = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2); |
445 |
|
else |
446 |
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; |
447 |
uv_dy = |
|
448 |
(sum == |
uv_dy = (sum >> 3) + roundtab_76[sum & 0xf]; |
|
0 ? 0 : SIGN(sum) * (roundtab[ABS(sum) % 16] + |
|
|
(ABS(sum) / 16) * 2)); |
|
|
} |
|
449 |
|
|
450 |
start_timer(); |
start_timer(); |
451 |
|
if(dec->quarterpel) { |
452 |
|
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
453 |
|
dec->refh.y + 128, 16*x_pos, 16*y_pos, |
454 |
|
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
455 |
|
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
456 |
|
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos, |
457 |
|
pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
458 |
|
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
459 |
|
dec->refh.y + 128, 16*x_pos, 16*y_pos + 8, |
460 |
|
pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
461 |
|
interpolate8x8_quarterpel(dec->cur.y, dec->refn[0].y, dec->refh.y, dec->refh.y + 64, |
462 |
|
dec->refh.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
463 |
|
pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
464 |
|
} |
465 |
|
else { |
466 |
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, |
467 |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
pMB->mvs[0].x, pMB->mvs[0].y, stride, rounding); |
468 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos + 8, |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos, |
469 |
16 * y_pos, pMB->mvs[1].x, pMB->mvs[1].y, stride, |
pMB->mvs[1].x, pMB->mvs[1].y, stride, rounding); |
470 |
rounding); |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos, 16*y_pos + 8, |
471 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos, |
pMB->mvs[2].x, pMB->mvs[2].y, stride, rounding); |
472 |
16 * y_pos + 8, pMB->mvs[2].x, pMB->mvs[2].y, stride, |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16*x_pos + 8, 16*y_pos + 8, |
473 |
rounding); |
pMB->mvs[3].x, pMB->mvs[3].y, stride, rounding); |
474 |
interpolate8x8_switch(dec->cur.y, dec->refn[0].y, 16 * x_pos + 8, |
} |
475 |
16 * y_pos + 8, pMB->mvs[3].x, pMB->mvs[3].y, stride, |
|
|
rounding); |
|
476 |
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, |
477 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
478 |
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, |
479 |
uv_dx, uv_dy, stride2, rounding); |
uv_dx, uv_dy, stride2, rounding); |
480 |
stop_comp_timer(); |
stop_comp_timer(); |
481 |
|
} |
482 |
|
|
483 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
484 |
|
int direction = dec->alternate_vertical_scan ? 2 : 0; |
485 |
|
|
486 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) // coded |
487 |
{ |
{ |
488 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
489 |
|
|
490 |
start_timer(); |
start_timer(); |
491 |
get_inter_block(bs, &block[i * 64]); |
get_inter_block(bs, &block[i * 64], direction); |
492 |
stop_coding_timer(); |
stop_coding_timer(); |
493 |
|
|
494 |
start_timer(); |
start_timer(); |
530 |
void |
void |
531 |
decoder_iframe(DECODER * dec, |
decoder_iframe(DECODER * dec, |
532 |
Bitstream * bs, |
Bitstream * bs, |
533 |
|
int reduced_resolution, |
534 |
int quant, |
int quant, |
535 |
int intra_dc_threshold) |
int intra_dc_threshold) |
536 |
{ |
{ |
537 |
|
uint32_t bound; |
538 |
uint32_t x, y; |
uint32_t x, y; |
539 |
|
int mb_width = dec->mb_width; |
540 |
|
int mb_height = dec->mb_height; |
541 |
|
|
542 |
for (y = 0; y < dec->mb_height; y++) { |
if (reduced_resolution) |
543 |
for (x = 0; x < dec->mb_width; x++) { |
{ |
544 |
MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x]; |
mb_width /= 2; |
545 |
|
mb_height /= 2; |
546 |
|
} |
547 |
|
|
548 |
|
bound = 0; |
549 |
|
|
550 |
|
for (y = 0; y < mb_height; y++) { |
551 |
|
for (x = 0; x < mb_width; x++) { |
552 |
|
MACROBLOCK *mb; |
553 |
uint32_t mcbpc; |
uint32_t mcbpc; |
554 |
uint32_t cbpc; |
uint32_t cbpc; |
555 |
uint32_t acpred_flag; |
uint32_t acpred_flag; |
556 |
uint32_t cbpy; |
uint32_t cbpy; |
557 |
uint32_t cbp; |
uint32_t cbp; |
558 |
|
|
559 |
|
while (BitstreamShowBits(bs, 9) == 1) |
560 |
|
BitstreamSkip(bs, 9); |
561 |
|
|
562 |
|
if (check_resync_marker(bs, 0)) |
563 |
|
{ |
564 |
|
bound = read_video_packet_header(bs, dec, 0, |
565 |
|
&quant, NULL, NULL, &intra_dc_threshold); |
566 |
|
x = bound % dec->mb_width; |
567 |
|
y = bound / dec->mb_width; |
568 |
|
} |
569 |
|
mb = &dec->mbs[y * dec->mb_width + x]; |
570 |
|
|
571 |
|
DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32)); |
572 |
|
|
573 |
mcbpc = get_mcbpc_intra(bs); |
mcbpc = get_mcbpc_intra(bs); |
574 |
mb->mode = mcbpc & 7; |
mb->mode = mcbpc & 7; |
575 |
cbpc = (mcbpc >> 4); |
cbpc = (mcbpc >> 4); |
576 |
|
|
577 |
acpred_flag = BitstreamGetBit(bs); |
acpred_flag = BitstreamGetBit(bs); |
578 |
|
|
|
if (mb->mode == MODE_STUFFING) { |
|
|
DEBUG("-- STUFFING ?"); |
|
|
continue; |
|
|
} |
|
|
|
|
579 |
cbpy = get_cbpy(bs, 1); |
cbpy = get_cbpy(bs, 1); |
580 |
cbp = (cbpy << 2) | cbpc; |
cbp = (cbpy << 2) | cbpc; |
581 |
|
|
588 |
} |
} |
589 |
} |
} |
590 |
mb->quant = quant; |
mb->quant = quant; |
591 |
|
mb->mvs[0].x = mb->mvs[0].y = |
592 |
|
mb->mvs[1].x = mb->mvs[1].y = |
593 |
|
mb->mvs[2].x = mb->mvs[2].y = |
594 |
|
mb->mvs[3].x = mb->mvs[3].y =0; |
595 |
|
|
596 |
if (dec->interlacing) { |
if (dec->interlacing) { |
597 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
599 |
} |
} |
600 |
|
|
601 |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
602 |
intra_dc_threshold); |
intra_dc_threshold, bound); |
603 |
|
|
604 |
} |
} |
605 |
|
if(dec->out_frm) |
606 |
|
output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,0,y,dec->mb_width); |
607 |
} |
} |
608 |
|
|
609 |
} |
} |
616 |
int y, |
int y, |
617 |
int k, |
int k, |
618 |
VECTOR * mv, |
VECTOR * mv, |
619 |
int fcode) |
int fcode, |
620 |
|
const int bound) |
621 |
{ |
{ |
622 |
|
|
623 |
int scale_fac = 1 << (fcode - 1); |
int scale_fac = 1 << (fcode - 1); |
625 |
int low = ((-32) * scale_fac); |
int low = ((-32) * scale_fac); |
626 |
int range = (64 * scale_fac); |
int range = (64 * scale_fac); |
627 |
|
|
628 |
VECTOR pmv[4]; |
VECTOR pmv; |
|
int32_t psad[4]; |
|
|
|
|
629 |
int mv_x, mv_y; |
int mv_x, mv_y; |
|
int pmv_x, pmv_y; |
|
630 |
|
|
631 |
|
pmv = get_pmv2(dec->mbs, dec->mb_width, bound, x, y, k); |
|
get_pmvdata(dec->mbs, x, y, dec->mb_width, k, pmv, psad); |
|
|
|
|
|
pmv_x = pmv[0].x; |
|
|
pmv_y = pmv[0].y; |
|
632 |
|
|
633 |
mv_x = get_mv(bs, fcode); |
mv_x = get_mv(bs, fcode); |
634 |
mv_y = get_mv(bs, fcode); |
mv_y = get_mv(bs, fcode); |
635 |
|
|
636 |
mv_x += pmv_x; |
DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i)", mv_x, mv_y, pmv.x, pmv.y); |
637 |
mv_y += pmv_y; |
|
638 |
|
mv_x += pmv.x; |
639 |
|
mv_y += pmv.y; |
640 |
|
|
641 |
if (mv_x < low) { |
if (mv_x < low) { |
642 |
mv_x += range; |
mv_x += range; |
652 |
|
|
653 |
mv->x = mv_x; |
mv->x = mv_x; |
654 |
mv->y = mv_y; |
mv->y = mv_y; |
655 |
|
} |
656 |
|
|
657 |
|
|
658 |
|
|
659 |
|
static __inline int gmc_sanitize(int value, int quarterpel, int fcode) |
660 |
|
{ |
661 |
|
int length = 1 << (fcode+4); |
662 |
|
|
663 |
|
if (quarterpel) value *= 2; |
664 |
|
|
665 |
|
if (value < -length) |
666 |
|
return -length; |
667 |
|
else if (value >= length) |
668 |
|
return length-1; |
669 |
|
else return value; |
670 |
} |
} |
671 |
|
|
672 |
|
|
673 |
|
/* for P_VOP set gmc_mv to NULL */ |
674 |
void |
void |
675 |
decoder_pframe(DECODER * dec, |
decoder_pframe(DECODER * dec, |
676 |
Bitstream * bs, |
Bitstream * bs, |
677 |
int rounding, |
int rounding, |
678 |
|
int reduced_resolution, |
679 |
int quant, |
int quant, |
680 |
int fcode, |
int fcode, |
681 |
int intra_dc_threshold) |
int intra_dc_threshold, |
682 |
|
VECTOR * gmc_mv) |
683 |
{ |
{ |
684 |
|
|
685 |
uint32_t x, y; |
uint32_t x, y; |
686 |
|
uint32_t bound; |
687 |
|
int cp_mb, st_mb; |
688 |
|
|
689 |
start_timer(); |
start_timer(); |
690 |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
691 |
dec->width, dec->height, dec->interlacing); |
dec->width, dec->height); |
692 |
stop_edges_timer(); |
stop_edges_timer(); |
693 |
|
|
694 |
|
bound = 0; |
695 |
|
|
696 |
for (y = 0; y < dec->mb_height; y++) { |
for (y = 0; y < dec->mb_height; y++) { |
697 |
|
cp_mb = st_mb = 0; |
698 |
for (x = 0; x < dec->mb_width; x++) { |
for (x = 0; x < dec->mb_width; x++) { |
699 |
MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x]; |
MACROBLOCK *mb; |
700 |
|
|
701 |
|
// skip stuffing |
702 |
|
while (BitstreamShowBits(bs, 10) == 1) |
703 |
|
BitstreamSkip(bs, 10); |
704 |
|
|
705 |
|
if (check_resync_marker(bs, fcode - 1)) |
706 |
|
{ |
707 |
|
bound = read_video_packet_header(bs, dec, fcode - 1, |
708 |
|
&quant, &fcode, NULL, &intra_dc_threshold); |
709 |
|
x = bound % dec->mb_width; |
710 |
|
y = bound / dec->mb_width; |
711 |
|
} |
712 |
|
mb = &dec->mbs[y * dec->mb_width + x]; |
713 |
|
|
714 |
|
DPRINTF(DPRINTF_MB, "macroblock (%i,%i) %08x", x, y, BitstreamShowBits(bs, 32)); |
715 |
|
|
716 |
//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 |
717 |
if (!(BitstreamGetBit(bs))) // not_coded |
if (!(BitstreamGetBit(bs))) // not_coded |
722 |
uint32_t cbpy; |
uint32_t cbpy; |
723 |
uint32_t cbp; |
uint32_t cbp; |
724 |
uint32_t intra; |
uint32_t intra; |
725 |
|
int mcsel = 0; // mcsel: '0'=local motion, '1'=GMC |
726 |
|
|
727 |
|
cp_mb++; |
728 |
mcbpc = get_mcbpc_inter(bs); |
mcbpc = get_mcbpc_inter(bs); |
729 |
mb->mode = mcbpc & 7; |
mb->mode = mcbpc & 7; |
730 |
cbpc = (mcbpc >> 4); |
cbpc = (mcbpc >> 4); |
731 |
|
|
732 |
|
DPRINTF(DPRINTF_MB, "mode %i", mb->mode); |
733 |
|
DPRINTF(DPRINTF_MB, "cbpc %i", cbpc); |
734 |
acpred_flag = 0; |
acpred_flag = 0; |
735 |
|
|
736 |
intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q); |
intra = (mb->mode == MODE_INTRA || mb->mode == MODE_INTRA_Q); |
739 |
acpred_flag = BitstreamGetBit(bs); |
acpred_flag = BitstreamGetBit(bs); |
740 |
} |
} |
741 |
|
|
742 |
if (mb->mode == MODE_STUFFING) { |
if (gmc_mv && (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q)) |
743 |
DEBUG("-- STUFFING ?"); |
{ |
744 |
continue; |
mcsel = BitstreamGetBit(bs); |
745 |
} |
} |
746 |
|
|
747 |
cbpy = get_cbpy(bs, intra); |
cbpy = get_cbpy(bs, intra); |
748 |
|
DPRINTF(DPRINTF_MB, "cbpy %i", cbpy); |
749 |
|
|
750 |
cbp = (cbpy << 2) | cbpc; |
cbp = (cbpy << 2) | cbpc; |
751 |
|
|
752 |
if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) { |
if (mb->mode == MODE_INTER_Q || mb->mode == MODE_INTRA_Q) { |
753 |
quant += dquant_table[BitstreamGetBits(bs, 2)]; |
int dquant = dquant_table[BitstreamGetBits(bs, 2)]; |
754 |
|
DPRINTF(DPRINTF_MB, "dquant %i", dquant); |
755 |
|
quant += dquant; |
756 |
if (quant > 31) { |
if (quant > 31) { |
757 |
quant = 31; |
quant = 31; |
758 |
} else if (mb->quant < 1) { |
} else if (quant < 1) { |
759 |
quant = 1; |
quant = 1; |
760 |
} |
} |
761 |
|
DPRINTF(DPRINTF_MB, "quant %i", quant); |
762 |
} |
} |
763 |
mb->quant = quant; |
mb->quant = quant; |
764 |
|
|
765 |
if (dec->interlacing) { |
if (dec->interlacing) { |
766 |
|
if (cbp || intra) { |
767 |
mb->field_dct = BitstreamGetBit(bs); |
mb->field_dct = BitstreamGetBit(bs); |
768 |
DEBUG1("decp: field_dct: ", mb->field_dct); |
DEBUG1("decp: field_dct: ", mb->field_dct); |
769 |
|
} |
770 |
|
|
771 |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
772 |
mb->field_pred = BitstreamGetBit(bs); |
mb->field_pred = BitstreamGetBit(bs); |
782 |
} |
} |
783 |
|
|
784 |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
if (mb->mode == MODE_INTER || mb->mode == MODE_INTER_Q) { |
785 |
if (dec->interlacing && mb->field_pred) { |
|
786 |
|
if (mcsel) |
787 |
|
{ |
788 |
|
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); |
789 |
|
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); |
790 |
|
|
791 |
|
} else if (dec->interlacing && mb->field_pred) { |
792 |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], |
793 |
fcode); |
fcode, bound); |
794 |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1], |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[1], |
795 |
fcode); |
fcode, bound); |
796 |
} else { |
} else { |
797 |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], |
798 |
fcode); |
fcode, bound); |
799 |
mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = |
mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = |
800 |
mb->mvs[0].x; |
mb->mvs[0].x; |
801 |
mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = |
mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = |
802 |
mb->mvs[0].y; |
mb->mvs[0].y; |
803 |
} |
} |
804 |
} else if (mb->mode == |
} else if (mb->mode == MODE_INTER4V ) { |
805 |
MODE_INTER4V /* || mb->mode == MODE_INTER4V_Q */ ) { |
|
806 |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode); |
get_motion_vector(dec, bs, x, y, 0, &mb->mvs[0], fcode, bound); |
807 |
get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode); |
get_motion_vector(dec, bs, x, y, 1, &mb->mvs[1], fcode, bound); |
808 |
get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode); |
get_motion_vector(dec, bs, x, y, 2, &mb->mvs[2], fcode, bound); |
809 |
get_motion_vector(dec, bs, x, y, 3, &mb->mvs[3], fcode); |
get_motion_vector(dec, bs, x, y, 3, &mb->mvs[3], fcode, bound); |
810 |
} else // MODE_INTRA, MODE_INTRA_Q |
} else // MODE_INTRA, MODE_INTRA_Q |
811 |
{ |
{ |
812 |
mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = |
mb->mvs[0].x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = |
814 |
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 = |
815 |
0; |
0; |
816 |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
decoder_mbintra(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
817 |
intra_dc_threshold); |
intra_dc_threshold, bound); |
818 |
continue; |
continue; |
819 |
} |
} |
820 |
|
|
821 |
decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
decoder_mbinter(dec, mb, x, y, acpred_flag, cbp, bs, quant, |
822 |
rounding); |
rounding); |
823 |
} else // not coded |
|
824 |
|
} |
825 |
|
else if (gmc_mv) /* not coded S_VOP macroblock */ |
826 |
|
{ |
827 |
|
mb->mode = MODE_NOT_CODED; |
828 |
|
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); |
829 |
|
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); |
830 |
|
decoder_mbinter(dec, mb, x, y, 0, 0, bs, quant, rounding); |
831 |
|
} |
832 |
|
else /* not coded P_VOP macroblock */ |
833 |
{ |
{ |
|
//DEBUG2("P-frame MB at (X,Y)=",x,y); |
|
834 |
mb->mode = MODE_NOT_CODED; |
mb->mode = MODE_NOT_CODED; |
835 |
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; |
836 |
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; |
|
|
|
837 |
// copy macroblock directly from ref to cur |
// copy macroblock directly from ref to cur |
838 |
|
|
839 |
start_timer(); |
start_timer(); |
873 |
dec->edged_width / 2); |
dec->edged_width / 2); |
874 |
|
|
875 |
stop_transfer_timer(); |
stop_transfer_timer(); |
876 |
|
|
877 |
|
if(dec->out_frm && cp_mb > 0) { |
878 |
|
output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb); |
879 |
|
cp_mb = 0; |
880 |
|
} |
881 |
|
st_mb = x+1; |
882 |
} |
} |
883 |
} |
} |
884 |
|
if(dec->out_frm && cp_mb > 0) |
885 |
|
output_slice(&dec->cur, dec->edged_width,dec->width,dec->out_frm,st_mb,y,cp_mb); |
886 |
} |
} |
887 |
} |
} |
888 |
|
|
960 |
pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
961 |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
962 |
|
|
963 |
|
|
964 |
if (!(pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) { |
if (!(pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) { |
965 |
uv_dx = pMB->mvs[0].x; |
uv_dx = pMB->mvs[0].x; |
966 |
uv_dy = pMB->mvs[0].y; |
uv_dy = pMB->mvs[0].y; |
1001 |
stop_comp_timer(); |
stop_comp_timer(); |
1002 |
|
|
1003 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
1004 |
|
int direction = dec->alternate_vertical_scan ? 2 : 0; |
1005 |
|
|
1006 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) // coded |
1007 |
{ |
{ |
1008 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
1009 |
|
|
1010 |
start_timer(); |
start_timer(); |
1011 |
get_inter_block(bs, &block[i * 64]); |
get_inter_block(bs, &block[i * 64], direction); |
1012 |
stop_coding_timer(); |
stop_coding_timer(); |
1013 |
|
|
1014 |
start_timer(); |
start_timer(); |
1046 |
stop_transfer_timer(); |
stop_transfer_timer(); |
1047 |
} |
} |
1048 |
|
|
|
|
|
1049 |
// add by MinChen <chenm001@163.com> |
// add by MinChen <chenm001@163.com> |
1050 |
// decode an B-frame direct & inter macroblock |
// decode an B-frame direct & inter macroblock |
1051 |
void |
void |
1055 |
const MACROBLOCK * pMB, |
const MACROBLOCK * pMB, |
1056 |
const uint32_t x_pos, |
const uint32_t x_pos, |
1057 |
const uint32_t y_pos, |
const uint32_t y_pos, |
|
const uint32_t cbp, |
|
1058 |
Bitstream * bs) |
Bitstream * bs) |
1059 |
{ |
{ |
1060 |
|
|
1069 |
int b_uv_dx, b_uv_dy; |
int b_uv_dx, b_uv_dy; |
1070 |
uint32_t i; |
uint32_t i; |
1071 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
1072 |
|
const uint32_t cbp = pMB->cbp; |
1073 |
|
|
1074 |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
1075 |
pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
pU_Cur = dec->cur.u + (y_pos << 3) * stride2 + (x_pos << 3); |
1076 |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
pV_Cur = dec->cur.v + (y_pos << 3) * stride2 + (x_pos << 3); |
1077 |
|
|
1078 |
|
|
1079 |
if ((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) { |
if ((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)) { |
1080 |
uv_dx = pMB->mvs[0].x; |
uv_dx = pMB->mvs[0].x; |
1081 |
uv_dy = pMB->mvs[0].y; |
uv_dy = pMB->mvs[0].y; |
1153 |
interpolate8x8_switch(dec->refn[2].v, backward.v, 8 * x_pos, 8 * y_pos, |
interpolate8x8_switch(dec->refn[2].v, backward.v, 8 * x_pos, 8 * y_pos, |
1154 |
b_uv_dx, b_uv_dy, stride2, 0); |
b_uv_dx, b_uv_dy, stride2, 0); |
1155 |
|
|
1156 |
interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos, 16 * y_pos, |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
1157 |
stride); |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
1158 |
interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos + 8, 16 * y_pos, |
dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos, |
1159 |
stride); |
stride, 0); |
1160 |
interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos, 16 * y_pos + 8, |
|
1161 |
stride); |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1162 |
interpolate8x8_c(dec->cur.y, dec->refn[2].y, 16 * x_pos + 8, |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1163 |
16 * y_pos + 8, stride); |
dec->refn[2].y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1164 |
interpolate8x8_c(dec->cur.u, dec->refn[2].u, 8 * x_pos, 8 * y_pos, |
stride, 0); |
1165 |
stride2); |
|
1166 |
interpolate8x8_c(dec->cur.v, dec->refn[2].v, 8 * x_pos, 8 * y_pos, |
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
1167 |
stride2); |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
1168 |
|
dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
1169 |
|
stride, 0); |
1170 |
|
|
1171 |
|
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
1172 |
|
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
1173 |
|
dec->refn[2].y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
1174 |
|
stride, 0); |
1175 |
|
|
1176 |
|
interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
1177 |
|
dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
1178 |
|
dec->refn[2].u + (8 * y_pos * stride2) + 8 * x_pos, |
1179 |
|
stride2, 0); |
1180 |
|
|
1181 |
|
interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
1182 |
|
dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
1183 |
|
dec->refn[2].v + (8 * y_pos * stride2) + 8 * x_pos, |
1184 |
|
stride2, 0); |
1185 |
|
|
1186 |
stop_comp_timer(); |
stop_comp_timer(); |
1187 |
|
|
1188 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
1189 |
|
int direction = dec->alternate_vertical_scan ? 2 : 0; |
1190 |
|
|
1191 |
if (cbp & (1 << (5 - i))) // coded |
if (cbp & (1 << (5 - i))) // coded |
1192 |
{ |
{ |
1193 |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
memset(&block[i * 64], 0, 64 * sizeof(int16_t)); // clear |
1194 |
|
|
1195 |
start_timer(); |
start_timer(); |
1196 |
get_inter_block(bs, &block[i * 64]); |
get_inter_block(bs, &block[i * 64], direction); |
1197 |
stop_coding_timer(); |
stop_coding_timer(); |
1198 |
|
|
1199 |
start_timer(); |
start_timer(); |
1275 |
int fcode_forward, |
int fcode_forward, |
1276 |
int fcode_backward) |
int fcode_backward) |
1277 |
{ |
{ |
|
|
|
1278 |
uint32_t x, y; |
uint32_t x, y; |
1279 |
VECTOR mv, zeromv; |
VECTOR mv; |
1280 |
|
const VECTOR zeromv = {0,0}; |
1281 |
|
#ifdef BFRAMES_DEC_DEBUG |
1282 |
|
FILE *fp; |
1283 |
|
static char first=0; |
1284 |
|
#define BFRAME_DEBUG if (!first && fp){ \ |
1285 |
|
fprintf(fp,"Y=%3d X=%3d MB=%2d CBP=%02X\n",y,x,mb->mb_type,mb->cbp); \ |
1286 |
|
} |
1287 |
|
#endif |
1288 |
|
|
1289 |
start_timer(); |
start_timer(); |
1290 |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
1291 |
dec->width, dec->height, dec->interlacing); |
dec->width, dec->height); |
1292 |
//image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, dec->width, dec->height, dec->interlacing); |
image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, |
1293 |
|
dec->width, dec->height); |
1294 |
stop_edges_timer(); |
stop_edges_timer(); |
1295 |
|
|
1296 |
|
#ifdef BFRAMES_DEC_DEBUG |
1297 |
|
if (!first){ |
1298 |
|
fp=fopen("C:\\XVIDDBG.TXT","w"); |
1299 |
|
} |
1300 |
|
#endif |
1301 |
|
|
1302 |
for (y = 0; y < dec->mb_height; y++) { |
for (y = 0; y < dec->mb_height; y++) { |
1303 |
// Initialize Pred Motion Vector |
// Initialize Pred Motion Vector |
1304 |
dec->p_fmv.x = dec->p_fmv.y = dec->p_bmv.x = dec->p_bmv.y = 0; |
dec->p_fmv = dec->p_bmv = zeromv; |
1305 |
for (x = 0; x < dec->mb_width; x++) { |
for (x = 0; x < dec->mb_width; x++) { |
1306 |
MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x]; |
MACROBLOCK *mb = &dec->mbs[y * dec->mb_width + x]; |
1307 |
MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x]; |
MACROBLOCK *last_mb = &dec->last_mbs[y * dec->mb_width + x]; |
1308 |
|
|
1309 |
mb->mvs[0].x = mb->mvs[0].y = zeromv.x = zeromv.y = mv.x = mv.y = |
mv = |
1310 |
0; |
mb->b_mvs[0] = mb->b_mvs[1] = mb->b_mvs[2] = mb->b_mvs[3] = |
1311 |
|
mb->mvs[0] = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = zeromv; |
1312 |
|
|
1313 |
// the last P_VOP is skip macroblock ? |
// the last P_VOP is skip macroblock ? |
1314 |
if (last_mb->mode == MODE_NOT_CODED) { |
if (last_mb->mode == MODE_NOT_CODED) { |
1315 |
//DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); |
//DEBUG2("Skip MB in B-frame at (X,Y)=!",x,y); |
|
mb->mb_type = MODE_FORWARD; |
|
1316 |
mb->cbp = 0; |
mb->cbp = 0; |
1317 |
mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x; |
#ifdef BFRAMES_DEC_DEBUG |
1318 |
mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y; |
mb->mb_type = MODE_NOT_CODED; |
1319 |
mb->quant = 8; |
BFRAME_DEBUG |
1320 |
|
#endif |
1321 |
|
mb->mb_type = MODE_FORWARD; |
1322 |
|
mb->quant = last_mb->quant; |
1323 |
|
//mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = mb->mvs[0].x; |
1324 |
|
//mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = mb->mvs[0].y; |
1325 |
|
|
1326 |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1); |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, mb->quant, 1); |
1327 |
continue; |
continue; |
1328 |
} |
} |
|
//t=BitstreamShowBits(bs,32); |
|
1329 |
|
|
1330 |
if (!BitstreamGetBit(bs)) { // modb=='0' |
if (!BitstreamGetBit(bs)) { // modb=='0' |
1331 |
const uint8_t modb2 = BitstreamGetBit(bs); |
const uint8_t modb2 = BitstreamGetBit(bs); |
1342 |
|
|
1343 |
if (quant > 31) { |
if (quant > 31) { |
1344 |
quant = 31; |
quant = 31; |
1345 |
} else if (mb->quant < 1) { |
} else if (quant < 1) { |
1346 |
quant = 1; |
quant = 1; |
1347 |
} |
} |
|
} else { |
|
|
quant = 8; |
|
1348 |
} |
} |
|
mb->quant = quant; |
|
1349 |
} else { |
} else { |
1350 |
mb->mb_type = MODE_DIRECT_NONE_MV; |
mb->mb_type = MODE_DIRECT_NONE_MV; |
1351 |
mb->cbp = 0; |
mb->cbp = 0; |
1352 |
} |
} |
1353 |
|
|
1354 |
mb->mode = MODE_INTER; |
mb->quant = quant; |
1355 |
|
mb->mode = MODE_INTER4V; |
1356 |
//DEBUG1("Switch bm_type=",mb->mb_type); |
//DEBUG1("Switch bm_type=",mb->mb_type); |
1357 |
|
|
1358 |
|
#ifdef BFRAMES_DEC_DEBUG |
1359 |
|
BFRAME_DEBUG |
1360 |
|
#endif |
1361 |
|
|
1362 |
switch (mb->mb_type) { |
switch (mb->mb_type) { |
1363 |
case MODE_DIRECT: |
case MODE_DIRECT: |
1364 |
get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], 1, zeromv); |
get_b_motion_vector(dec, bs, x, y, &mv, 1, zeromv); |
1365 |
|
|
1366 |
case MODE_DIRECT_NONE_MV: |
case MODE_DIRECT_NONE_MV: |
1367 |
{ // Because this file is a C file not C++ so I use '{' to define var |
{ |
1368 |
const int64_t TRB = dec->time_pp - dec->time_bp, TRD = |
const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp; |
|
dec->time_pp; |
|
1369 |
int i; |
int i; |
1370 |
|
|
1371 |
for (i = 0; i < 4; i++) { |
for (i = 0; i < 4; i++) { |
1372 |
mb->mvs[i].x = |
mb->mvs[i].x = (int32_t) ((TRB * last_mb->mvs[i].x) |
1373 |
(int32_t) ((TRB * last_mb->mvs[i].x) / TRD + |
/ TRD + mv.x); |
1374 |
mb->mvs[0].x); |
mb->b_mvs[i].x = (int32_t) ((mv.x == 0) |
1375 |
mb->b_mvs[i].x = |
? ((TRB - TRD) * last_mb->mvs[i].x) |
1376 |
(int32_t) ((mb->mvs[0].x == |
/ TRD |
1377 |
0) ? ((TRB - |
: mb->mvs[i].x - last_mb->mvs[i].x); |
1378 |
TRD) * last_mb->mvs[i].x) / |
mb->mvs[i].y = (int32_t) ((TRB * last_mb->mvs[i].y) |
1379 |
TRD : mb->mvs[i].x - last_mb->mvs[i].x); |
/ TRD + mv.y); |
1380 |
mb->mvs[i].y = |
mb->b_mvs[i].y = (int32_t) ((mv.y == 0) |
1381 |
(int32_t) ((TRB * last_mb->mvs[i].y) / TRD + |
? ((TRB - TRD) * last_mb->mvs[i].y) |
1382 |
mb->mvs[0].y); |
/ TRD |
1383 |
mb->b_mvs[i].y = |
: mb->mvs[i].y - last_mb->mvs[i].y); |
|
(int32_t) ((mb->mvs[0].y == |
|
|
0) ? ((TRB - |
|
|
TRD) * last_mb->mvs[i].y) / |
|
|
TRD : mb->mvs[i].y - last_mb->mvs[i].y); |
|
1384 |
} |
} |
1385 |
//DEBUG("B-frame Direct!\n"); |
//DEBUG("B-frame Direct!\n"); |
1386 |
} |
} |
|
mb->mode = MODE_INTER4V; |
|
1387 |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
1388 |
mb, x, y, mb->cbp, bs); |
mb, x, y, bs); |
1389 |
break; |
break; |
1390 |
|
|
1391 |
case MODE_INTERPOLATE: |
case MODE_INTERPOLATE: |
1392 |
get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], fcode_forward, |
get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], fcode_forward, |
1393 |
dec->p_fmv); |
dec->p_fmv); |
1394 |
dec->p_fmv.x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = |
dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; |
|
mb->mvs[0].x; |
|
|
dec->p_fmv.y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = |
|
|
mb->mvs[0].y; |
|
1395 |
|
|
1396 |
get_b_motion_vector(dec, bs, x, y, &mb->b_mvs[0], |
get_b_motion_vector(dec, bs, x, y, &mb->b_mvs[0], |
1397 |
fcode_backward, dec->p_bmv); |
fcode_backward, dec->p_bmv); |
1398 |
dec->p_bmv.x = mb->b_mvs[1].x = mb->b_mvs[2].x = |
dec->p_bmv = mb->b_mvs[1] = mb->b_mvs[2] = |
1399 |
mb->b_mvs[3].x = mb->b_mvs[0].x; |
mb->b_mvs[3] = mb->b_mvs[0]; |
|
dec->p_bmv.y = mb->b_mvs[1].y = mb->b_mvs[2].y = |
|
|
mb->b_mvs[3].y = mb->b_mvs[0].y; |
|
1400 |
|
|
1401 |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
1402 |
mb, x, y, mb->cbp, bs); |
mb, x, y, bs); |
1403 |
//DEBUG("B-frame Bidir!\n"); |
//DEBUG("B-frame Bidir!\n"); |
1404 |
break; |
break; |
1405 |
|
|
1406 |
case MODE_BACKWARD: |
case MODE_BACKWARD: |
1407 |
get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], fcode_backward, |
get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], fcode_backward, |
1408 |
dec->p_bmv); |
dec->p_bmv); |
1409 |
dec->p_bmv.x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = |
dec->p_bmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; |
|
mb->mvs[0].x; |
|
|
dec->p_bmv.y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = |
|
|
mb->mvs[0].y; |
|
1410 |
|
|
1411 |
|
mb->mode = MODE_INTER; |
1412 |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0); |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 0); |
1413 |
//DEBUG("B-frame Backward!\n"); |
//DEBUG("B-frame Backward!\n"); |
1414 |
break; |
break; |
1416 |
case MODE_FORWARD: |
case MODE_FORWARD: |
1417 |
get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], fcode_forward, |
get_b_motion_vector(dec, bs, x, y, &mb->mvs[0], fcode_forward, |
1418 |
dec->p_fmv); |
dec->p_fmv); |
1419 |
dec->p_fmv.x = mb->mvs[1].x = mb->mvs[2].x = mb->mvs[3].x = |
dec->p_fmv = mb->mvs[1] = mb->mvs[2] = mb->mvs[3] = mb->mvs[0]; |
|
mb->mvs[0].x; |
|
|
dec->p_fmv.y = mb->mvs[1].y = mb->mvs[2].y = mb->mvs[3].y = |
|
|
mb->mvs[0].y; |
|
1420 |
|
|
1421 |
|
mb->mode = MODE_INTER; |
1422 |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1); |
decoder_bf_mbinter(dec, mb, x, y, mb->cbp, bs, quant, 1); |
1423 |
//DEBUG("B-frame Forward!\n"); |
//DEBUG("B-frame Forward!\n"); |
1424 |
break; |
break; |
1429 |
|
|
1430 |
} // end of FOR |
} // end of FOR |
1431 |
} |
} |
1432 |
|
#ifdef BFRAMES_DEC_DEBUG |
1433 |
|
if (!first){ |
1434 |
|
first=1; |
1435 |
|
if (fp) |
1436 |
|
fclose(fp); |
1437 |
|
} |
1438 |
|
#endif |
1439 |
} |
} |
1440 |
|
|
1441 |
// swap two MACROBLOCK array |
// swap two MACROBLOCK array |
1451 |
|
|
1452 |
int |
int |
1453 |
decoder_decode(DECODER * dec, |
decoder_decode(DECODER * dec, |
1454 |
XVID_DEC_FRAME * frame) |
XVID_DEC_FRAME * frame, XVID_DEC_STATS * stats) |
1455 |
{ |
{ |
1456 |
|
|
1457 |
Bitstream bs; |
Bitstream bs; |
1458 |
uint32_t rounding; |
uint32_t rounding; |
1459 |
|
uint32_t reduced_resolution; |
1460 |
uint32_t quant; |
uint32_t quant; |
1461 |
uint32_t fcode_forward; |
uint32_t fcode_forward; |
1462 |
uint32_t fcode_backward; |
uint32_t fcode_backward; |
1463 |
uint32_t intra_dc_threshold; |
uint32_t intra_dc_threshold; |
1464 |
|
VECTOR gmc_mv[5]; |
1465 |
uint32_t vop_type; |
uint32_t vop_type; |
1466 |
|
int success = 0; |
1467 |
|
|
1468 |
start_global_timer(); |
start_global_timer(); |
1469 |
|
|
1470 |
|
dec->out_frm = (frame->colorspace == XVID_CSP_EXTERN) ? frame->image : NULL; |
1471 |
|
|
1472 |
BitstreamInit(&bs, frame->bitstream, frame->length); |
BitstreamInit(&bs, frame->bitstream, frame->length); |
1473 |
|
|
1474 |
|
// XXX: 0x7f is only valid whilst decoding vfw xvid/divx5 avi's |
1475 |
|
if(frame->length == 1 && BitstreamShowBits(&bs, 8) == 0x7f) |
1476 |
|
{ |
1477 |
|
if (stats) |
1478 |
|
stats->notify = XVID_DEC_VOP; |
1479 |
|
frame->length = 1; |
1480 |
|
image_output(&dec->refn[0], dec->width, dec->height, dec->edged_width, |
1481 |
|
frame->image, frame->stride, frame->colorspace, dec->interlacing); |
1482 |
|
emms(); |
1483 |
|
return XVID_ERR_OK; |
1484 |
|
} |
1485 |
|
|
1486 |
|
start: |
1487 |
// add by chenm001 <chenm001@163.com> |
// add by chenm001 <chenm001@163.com> |
1488 |
// for support B-frame to reference last 2 frame |
// for support B-frame to reference last 2 frame |
1489 |
dec->frames++; |
dec->frames++; |
1490 |
|
|
1491 |
|
xxx: |
1492 |
vop_type = |
vop_type = |
1493 |
BitstreamReadHeaders(&bs, dec, &rounding, &quant, &fcode_forward, |
BitstreamReadHeaders(&bs, dec, &rounding, &reduced_resolution, |
1494 |
&fcode_backward, &intra_dc_threshold); |
&quant, &fcode_forward, &fcode_backward, &intra_dc_threshold, gmc_mv); |
1495 |
|
|
1496 |
|
DPRINTF(DPRINTF_HEADER, "vop_type=%i", vop_type); |
1497 |
|
|
1498 |
|
if (vop_type == -1 && success) |
1499 |
|
goto done; |
1500 |
|
|
1501 |
|
if (vop_type == -2 || vop_type == -3) |
1502 |
|
{ |
1503 |
|
if (vop_type == -3) |
1504 |
|
decoder_resize(dec); |
1505 |
|
|
1506 |
|
if (stats) |
1507 |
|
{ |
1508 |
|
stats->notify = XVID_DEC_VOL; |
1509 |
|
stats->data.vol.general = 0; |
1510 |
|
if (dec->interlacing) |
1511 |
|
stats->data.vol.general |= XVID_INTERLACING; |
1512 |
|
stats->data.vol.width = dec->width; |
1513 |
|
stats->data.vol.height = dec->height; |
1514 |
|
stats->data.vol.aspect_ratio = dec->aspect_ratio; |
1515 |
|
stats->data.vol.par_width = dec->par_width; |
1516 |
|
stats->data.vol.par_height = dec->par_height; |
1517 |
|
frame->length = BitstreamPos(&bs) / 8; |
1518 |
|
return XVID_ERR_OK; |
1519 |
|
} |
1520 |
|
goto xxx; |
1521 |
|
} |
1522 |
|
|
1523 |
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 |
1524 |
|
|
1525 |
switch (vop_type) { |
switch (vop_type) { |
1526 |
case P_VOP: |
case P_VOP: |
1527 |
decoder_pframe(dec, &bs, rounding, quant, fcode_forward, |
decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, |
1528 |
intra_dc_threshold); |
fcode_forward, intra_dc_threshold, NULL); |
1529 |
printf("P_VOP Time=%ld\n",dec->time); |
#ifdef BFRAMES_DEC |
1530 |
DEBUG1("P_VOP Time=", dec->time); |
DEBUG1("P_VOP Time=", dec->time); |
1531 |
|
#endif |
1532 |
break; |
break; |
1533 |
|
|
1534 |
case I_VOP: |
case I_VOP: |
1535 |
decoder_iframe(dec, &bs, quant, intra_dc_threshold); |
decoder_iframe(dec, &bs, reduced_resolution, quant, intra_dc_threshold); |
1536 |
printf("I_VOP Time=%ld\n",dec->time); |
#ifdef BFRAMES_DEC |
1537 |
DEBUG1("I_VOP Time=", dec->time); |
DEBUG1("I_VOP Time=", dec->time); |
1538 |
|
#endif |
1539 |
break; |
break; |
1540 |
|
|
1541 |
case B_VOP: |
case B_VOP: |
1542 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1543 |
if (dec->time_pp > dec->time_bp) { |
if (dec->time_pp > dec->time_bp) { |
|
printf("I_VOP Time=%ld\n",dec->time); |
|
1544 |
DEBUG1("B_VOP Time=", dec->time); |
DEBUG1("B_VOP Time=", dec->time); |
1545 |
decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); |
decoder_bframe(dec, &bs, quant, fcode_forward, fcode_backward); |
1546 |
} else { |
} else { |
1547 |
DEBUG("broken B-frame!"); |
DEBUG("broken B-frame!"); |
1548 |
} |
} |
1549 |
#else |
#else |
|
printf("Che minchia ne so\n"); |
|
1550 |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
1551 |
#endif |
#endif |
1552 |
break; |
break; |
1553 |
|
|
1554 |
|
case S_VOP : |
1555 |
|
decoder_pframe(dec, &bs, rounding, reduced_resolution, quant, |
1556 |
|
fcode_forward, intra_dc_threshold, gmc_mv); |
1557 |
|
break; |
1558 |
|
|
1559 |
case N_VOP: // vop not coded |
case N_VOP: // vop not coded |
1560 |
// when low_delay==0, N_VOP's should interpolate between the past and future frames |
// when low_delay==0, N_VOP's should interpolate between the past and future frames |
1561 |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
image_copy(&dec->cur, &dec->refn[0], dec->edged_width, dec->height); |
1562 |
printf("N_VOP vop not coded\n"); |
#ifdef BFRAMES_DEC |
1563 |
|
DEBUG1("N_VOP Time=", dec->time); |
1564 |
|
#endif |
1565 |
break; |
break; |
1566 |
|
|
1567 |
default: |
default: |
1568 |
|
if (stats) |
1569 |
|
stats->notify = 0; |
1570 |
|
|
1571 |
|
emms(); |
1572 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
1573 |
} |
} |
1574 |
|
|
1575 |
frame->length = BitstreamPos(&bs) / 8; |
BitstreamByteAlign(&bs); |
1576 |
|
|
1577 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1578 |
// test if no B_VOP |
// test if no B_VOP |
1579 |
if (dec->low_delay) { |
if (dec->low_delay || dec->frames == 0 || ((dec->packed_mode) && !(frame->length > BitstreamPos(&bs) / 8))) { |
1580 |
#endif |
#endif |
1581 |
image_output(&dec->cur, dec->width, dec->height, dec->edged_width, |
image_output(&dec->cur, dec->width, dec->height, dec->edged_width, |
1582 |
frame->image, frame->stride, frame->colorspace); |
frame->image, frame->stride, frame->colorspace, dec->interlacing); |
1583 |
|
|
1584 |
#ifdef BFRAMES_DEC |
#ifdef BFRAMES_DEC |
1585 |
} else { |
} else { |
1586 |
if (dec->frames >= 1) { |
if (dec->frames >= 1 && !(dec->packed_mode)) { |
1587 |
start_timer(); |
start_timer(); |
1588 |
if ((vop_type == I_VOP || vop_type == P_VOP)) { |
if ((vop_type == I_VOP || vop_type == P_VOP || vop_type == S_VOP)) { |
1589 |
image_output(&dec->refn[0], dec->width, dec->height, |
image_output(&dec->refn[0], dec->width, dec->height, |
1590 |
dec->edged_width, frame->image, frame->stride, |
dec->edged_width, frame->image, frame->stride, |
1591 |
frame->colorspace); |
frame->colorspace, dec->interlacing); |
1592 |
} else if (vop_type == B_VOP) { |
} else if (vop_type == B_VOP) { |
1593 |
image_output(&dec->cur, dec->width, dec->height, |
image_output(&dec->cur, dec->width, dec->height, |
1594 |
dec->edged_width, frame->image, frame->stride, |
dec->edged_width, frame->image, frame->stride, |
1595 |
frame->colorspace); |
frame->colorspace, dec->interlacing); |
1596 |
} |
} |
1597 |
stop_conv_timer(); |
stop_conv_timer(); |
1598 |
} |
} |
1599 |
} |
} |
1600 |
#endif |
#endif |
1601 |
|
|
1602 |
if (vop_type == I_VOP || vop_type == P_VOP) { |
if (vop_type == I_VOP || vop_type == P_VOP || vop_type == S_VOP) { |
1603 |
image_swap(&dec->refn[0], &dec->refn[1]); |
image_swap(&dec->refn[0], &dec->refn[1]); |
1604 |
image_swap(&dec->cur, &dec->refn[0]); |
image_swap(&dec->cur, &dec->refn[0]); |
1605 |
|
|
1606 |
// swap MACROBLOCK |
// swap MACROBLOCK |
1607 |
if (dec->low_delay && vop_type == P_VOP) |
// the Divx will not set the low_delay flage some times |
1608 |
|
// so follow code will wrong to not swap at that time |
1609 |
|
// this will broken bitstream! so I'm change it, |
1610 |
|
// But that is not the best way! can anyone tell me how |
1611 |
|
// to do another way? |
1612 |
|
// 18-07-2002 MinChen<chenm001@163.com> |
1613 |
|
//if (!dec->low_delay && vop_type == P_VOP) |
1614 |
|
if (vop_type == P_VOP) |
1615 |
mb_swap(&dec->mbs, &dec->last_mbs); |
mb_swap(&dec->mbs, &dec->last_mbs); |
1616 |
} |
} |
1617 |
|
|
1618 |
|
success = 1; |
1619 |
|
|
1620 |
|
if (frame->length > BitstreamPos(&bs) / 8) // multiple vops packed together |
1621 |
|
goto start; |
1622 |
|
|
1623 |
|
done : |
1624 |
|
|
1625 |
|
frame->length = BitstreamPos(&bs) / 8; |
1626 |
|
|
1627 |
|
if (stats) |
1628 |
|
{ |
1629 |
|
stats->notify = XVID_DEC_VOP; |
1630 |
|
stats->data.vop.time_base = (int)dec->time_base; |
1631 |
|
stats->data.vop.time_increment = 0; //XXX: todo |
1632 |
|
} |
1633 |
|
|
1634 |
emms(); |
emms(); |
1635 |
|
|
1636 |
stop_global_timer(); |
stop_global_timer(); |