20 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
21 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 |
* |
* |
23 |
* $Id: decoder.c,v 1.86 2010-12-24 13:49:58 Isibaar Exp $ |
* $Id$ |
24 |
* |
* |
25 |
****************************************************************************/ |
****************************************************************************/ |
26 |
|
|
149 |
int |
int |
150 |
decoder_create(xvid_dec_create_t * create) |
decoder_create(xvid_dec_create_t * create) |
151 |
{ |
{ |
152 |
|
int ret = 0; |
153 |
DECODER *dec; |
DECODER *dec; |
154 |
|
|
155 |
if (XVID_VERSION_MAJOR(create->version) != 1) /* v1.x.x */ |
if (XVID_VERSION_MAJOR(create->version) != 1) /* v1.x.x */ |
170 |
|
|
171 |
create->handle = dec; |
create->handle = dec; |
172 |
|
|
173 |
dec->width = create->width; |
dec->width = MAX(0, create->width); |
174 |
dec->height = create->height; |
dec->height = MAX(0, create->height); |
175 |
|
|
176 |
dec->num_threads = MAX(0, create->num_threads); |
dec->num_threads = MAX(0, create->num_threads); |
177 |
|
|
210 |
|
|
211 |
dec->fixed_dimensions = (dec->width > 0 && dec->height > 0); |
dec->fixed_dimensions = (dec->width > 0 && dec->height > 0); |
212 |
|
|
213 |
if (dec->fixed_dimensions) { |
ret = decoder_resize(dec); |
|
int ret = decoder_resize(dec); |
|
214 |
if (ret == XVID_ERR_MEMORY) create->handle = NULL; |
if (ret == XVID_ERR_MEMORY) create->handle = NULL; |
215 |
|
|
216 |
return ret; |
return ret; |
217 |
} |
} |
|
else |
|
|
return 0; |
|
|
} |
|
218 |
|
|
219 |
|
|
220 |
int |
int |
264 |
uint32_t stride2 = stride / 2; |
uint32_t stride2 = stride / 2; |
265 |
uint32_t next_block = stride * 8; |
uint32_t next_block = stride * 8; |
266 |
uint32_t i; |
uint32_t i; |
267 |
uint32_t iQuant = pMB->quant; |
uint32_t iQuant = MAX(1, pMB->quant); |
268 |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
269 |
|
|
270 |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
pY_Cur = dec->cur.y + (y_pos << 4) * stride + (x_pos << 4); |
361 |
|
|
362 |
int stride = dec->edged_width; |
int stride = dec->edged_width; |
363 |
int i; |
int i; |
364 |
const uint32_t iQuant = pMB->quant; |
const uint32_t iQuant = MAX(1, pMB->quant); |
365 |
const int direction = dec->alternate_vertical_scan ? 2 : 0; |
const int direction = dec->alternate_vertical_scan ? 2 : 0; |
366 |
typedef void (*get_inter_block_function_t)( |
typedef void (*get_inter_block_function_t)( |
367 |
Bitstream * bs, |
Bitstream * bs, |
1411 |
int bound = read_video_packet_header(bs, dec, resync_len, &quant, |
int bound = read_video_packet_header(bs, dec, resync_len, &quant, |
1412 |
&fcode_forward, &fcode_backward, &intra_dc_threshold); |
&fcode_forward, &fcode_backward, &intra_dc_threshold); |
1413 |
|
|
1414 |
bound = MAX(0, bound--); /* valid bound must always be >0 */ |
bound = MAX(0, bound-1); /* valid bound must always be >0 */ |
1415 |
x = bound % dec->mb_width; |
x = bound % dec->mb_width; |
1416 |
y = MIN((bound / dec->mb_width), (dec->mb_height-1)); |
y = MIN((bound / dec->mb_width), (dec->mb_height-1)); |
1417 |
/* reset predicted macroblocks */ |
/* reset predicted macroblocks */ |
1538 |
img = &dec->tmp; |
img = &dec->tmp; |
1539 |
} |
} |
1540 |
|
|
1541 |
|
if ((frame->output.csp == XVID_CSP_INTERNAL) || |
1542 |
|
((frame->output.plane[0] != NULL) && (frame->output.stride[0] >= dec->width))) { |
1543 |
image_output(img, dec->width, dec->height, |
image_output(img, dec->width, dec->height, |
1544 |
dec->edged_width, (uint8_t**)frame->output.plane, frame->output.stride, |
dec->edged_width, (uint8_t**)frame->output.plane, frame->output.stride, |
1545 |
frame->output.csp, dec->interlacing); |
frame->output.csp, dec->interlacing); |
1546 |
|
} |
1547 |
|
|
1548 |
if (stats) { |
if (stats) { |
1549 |
stats->type = coding2type(coding_type); |
stats->type = coding2type(coding_type); |
1566 |
{ |
{ |
1567 |
|
|
1568 |
Bitstream bs; |
Bitstream bs; |
1569 |
uint32_t rounding; |
uint32_t rounding = 0; |
1570 |
uint32_t quant = 2; |
uint32_t quant = 2; |
1571 |
uint32_t fcode_forward; |
uint32_t fcode_forward = 0; |
1572 |
uint32_t fcode_backward; |
uint32_t fcode_backward = 0; |
1573 |
uint32_t intra_dc_threshold; |
uint32_t intra_dc_threshold = 0; |
1574 |
WARPPOINTS gmc_warp; |
WARPPOINTS gmc_warp; |
1575 |
int coding_type; |
int coding_type = -1; |
1576 |
int success, output, seen_something; |
int success, output, seen_something; |
1577 |
|
|
1578 |
if (XVID_VERSION_MAJOR(frame->version) != 1 || (stats && XVID_VERSION_MAJOR(stats->version) != 1)) /* v1.x.x */ |
if (XVID_VERSION_MAJOR(frame->version) != 1 || (stats && XVID_VERSION_MAJOR(stats->version) != 1)) /* v1.x.x */ |
1579 |
return XVID_ERR_VERSION; |
return XVID_ERR_VERSION; |
1580 |
|
|
1581 |
start_global_timer(); |
start_global_timer(); |
1582 |
|
memset((void *)&gmc_warp, 0, sizeof(WARPPOINTS)); |
1583 |
|
|
1584 |
dec->low_delay_default = (frame->general & XVID_LOWDELAY); |
dec->low_delay_default = (frame->general & XVID_LOWDELAY); |
1585 |
if ((frame->general & XVID_DISCONTINUITY)) |
if ((frame->general & XVID_DISCONTINUITY)) |
1649 |
if(stats) { |
if(stats) { |
1650 |
stats->type = XVID_TYPE_VOL; |
stats->type = XVID_TYPE_VOL; |
1651 |
stats->data.vol.general = 0; |
stats->data.vol.general = 0; |
1652 |
/*XXX: if (dec->interlacing) |
stats->data.vop.general = 0; |
1653 |
stats->data.vol.general |= ++INTERLACING; */ |
if (dec->interlacing) { |
1654 |
stats->data.vol.width = dec->width; |
stats->data.vol.general |= XVID_VOL_INTERLACING; |
1655 |
|
if (dec->top_field_first) { |
1656 |
|
stats->data.vop.general |= XVID_VOP_TOPFIELDFIRST; |
1657 |
|
} |
1658 |
|
} stats->data.vol.width = dec->width; |
1659 |
stats->data.vol.height = dec->height; |
stats->data.vol.height = dec->height; |
1660 |
stats->data.vol.par = dec->aspect_ratio; |
stats->data.vol.par = dec->aspect_ratio; |
1661 |
stats->data.vol.par_width = dec->par_width; |
stats->data.vol.par_width = dec->par_width; |
1666 |
goto repeat; |
goto repeat; |
1667 |
} |
} |
1668 |
|
|
1669 |
if(dec->frames == 0 && coding_type != I_VOP) { |
if((dec->frames == 0 && coding_type != I_VOP) || (!dec->width || !dec->height)) { |
1670 |
/* 1st frame is not an i-vop */ |
/* 1st frame is not an i-vop */ |
1671 |
goto repeat; |
goto repeat; |
1672 |
} |
} |