32 |
* |
* |
33 |
* History |
* History |
34 |
* |
* |
35 |
|
* 08.05.2002 fix some problem in DEBUG mode; |
36 |
|
* MinChen <chenm001@163.com> |
37 |
* 14.04.2002 added FrameCodeB() |
* 14.04.2002 added FrameCodeB() |
38 |
* |
* |
39 |
* $Id: encoder.c,v 1.32 2002-05-01 13:00:01 suxen_drol Exp $ |
* $Id: encoder.c,v 1.37 2002-06-07 10:21:48 edgomez Exp $ |
40 |
* |
* |
41 |
***************************************************************************/ |
***************************************************************************/ |
42 |
|
|
266 |
#ifdef BFRAMES |
#ifdef BFRAMES |
267 |
|
|
268 |
// TODO: handle malloc() == NULL |
// TODO: handle malloc() == NULL |
269 |
pEnc->max_bframes = pParam->max_bframes; |
pEnc->mbParam.max_bframes = pParam->max_bframes; |
270 |
pEnc->bquant_ratio = pParam->bquant_ratio; |
pEnc->bquant_ratio = pParam->bquant_ratio; |
271 |
if (pEnc->max_bframes > 0) |
if (pEnc->mbParam.max_bframes > 0) |
272 |
{ |
{ |
273 |
int n; |
int n; |
274 |
|
|
275 |
pEnc->bframes = malloc(pEnc->max_bframes * sizeof(FRAMEINFO *)); |
pEnc->bframes = malloc(pEnc->mbParam.max_bframes * sizeof(FRAMEINFO *)); |
276 |
|
|
277 |
for (n = 0; n < pEnc->max_bframes; n++) |
for (n = 0; n < pEnc->mbParam.max_bframes; n++) |
278 |
{ |
{ |
279 |
pEnc->bframes[n] = malloc(sizeof(FRAMEINFO)); |
pEnc->bframes[n] = malloc(sizeof(FRAMEINFO)); |
280 |
pEnc->bframes[n]->mbs = malloc(sizeof(MACROBLOCK) * pEnc->mbParam.mb_width * pEnc->mbParam.mb_height); |
pEnc->bframes[n]->mbs = malloc(sizeof(MACROBLOCK) * pEnc->mbParam.mb_width * pEnc->mbParam.mb_height); |
301 |
|
|
302 |
if (pParam->rc_bitrate) |
if (pParam->rc_bitrate) |
303 |
{ |
{ |
304 |
RateControlInit(pParam->rc_bitrate, pParam->rc_reaction_delay_factor, |
RateControlInit(&pEnc->rate_control, |
305 |
pParam->rc_averaging_period, pParam->rc_buffer, pParam->fbase * 1000 / pParam->fincr, |
pParam->rc_bitrate, |
306 |
pParam->max_quantizer, pParam->min_quantizer); |
pParam->rc_reaction_delay_factor, |
307 |
|
pParam->rc_averaging_period, |
308 |
|
pParam->rc_buffer, |
309 |
|
pParam->fbase * 1000 / pParam->fincr, |
310 |
|
pParam->max_quantizer, |
311 |
|
pParam->min_quantizer); |
312 |
} |
} |
313 |
|
|
314 |
init_timer(); |
init_timer(); |
323 |
|
|
324 |
// ================================================================= |
// ================================================================= |
325 |
#ifdef BFRAMES |
#ifdef BFRAMES |
326 |
if (pEnc->max_bframes > 0) |
if (pEnc->mbParam.max_bframes > 0) |
327 |
{ |
{ |
328 |
int n; |
int n; |
329 |
for (n = 0; n < pEnc->max_bframes; n++) |
for (n = 0; n < pEnc->mbParam.max_bframes; n++) |
330 |
{ |
{ |
331 |
image_destroy(&pEnc->bframes[n]->image, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height); |
image_destroy(&pEnc->bframes[n]->image, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height); |
332 |
free(pEnc->bframes[n]->mbs); |
free(pEnc->bframes[n]->mbs); |
334 |
} |
} |
335 |
free(pEnc->bframes); |
free(pEnc->bframes); |
336 |
} |
} |
337 |
#endif BFRAMES |
#endif |
338 |
//==================================================================== |
//==================================================================== |
339 |
|
|
340 |
image_destroy(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height); |
image_destroy(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height); |
372 |
Bitstream bs; |
Bitstream bs; |
373 |
uint32_t bits; |
uint32_t bits; |
374 |
|
|
375 |
|
#ifdef _DEBUG |
376 |
|
float psnr; |
377 |
|
char temp[128]; |
378 |
|
#endif |
379 |
|
|
380 |
ENC_CHECK(pEnc); |
ENC_CHECK(pEnc); |
381 |
ENC_CHECK(pFrame); |
ENC_CHECK(pFrame); |
382 |
|
|
445 |
SWAP(pEnc->current, pEnc->reference); |
SWAP(pEnc->current, pEnc->reference); |
446 |
|
|
447 |
pEnc->current->quant = (pFrame->quant == 0) ? RateControlGetQ(0) : pFrame->quant; |
pEnc->current->quant = (pFrame->quant == 0) ? RateControlGetQ(0) : pFrame->quant; |
448 |
|
|
449 |
|
if(pEnc->current->quant < 1) |
450 |
|
pEnc->current->quant = 1; |
451 |
|
|
452 |
|
if(pEnc->current->quant > 31) |
453 |
|
pEnc->current->quant = 31; |
454 |
|
|
455 |
pEnc->current->global_flags = pFrame->general; |
pEnc->current->global_flags = pFrame->general; |
456 |
pEnc->current->motion_flags = pFrame->motion; |
pEnc->current->motion_flags = pFrame->motion; |
457 |
pEnc->current->seconds = pEnc->mbParam.m_seconds; |
pEnc->current->seconds = pEnc->mbParam.m_seconds; |
469 |
stop_conv_timer(); |
stop_conv_timer(); |
470 |
|
|
471 |
#ifdef _DEBUG |
#ifdef _DEBUG |
472 |
image_copy(&pEnc->sOriginal, &pEnc->sCurrent, pEnc->mbParam.edged_width, pEnc->mbParam.height); |
image_copy(&pEnc->sOriginal, &pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height); |
473 |
#endif |
#endif |
474 |
|
|
475 |
|
|
519 |
/* note: sequences like "IIBB" decode fine with msfdam but, |
/* note: sequences like "IIBB" decode fine with msfdam but, |
520 |
go screwy with divx5.00 */ |
go screwy with divx5.00 */ |
521 |
} |
} |
522 |
else if (pEnc->bframenum_tail >= pEnc->max_bframes) |
else if (pEnc->bframenum_tail >= pEnc->mbParam.max_bframes) |
523 |
{ |
{ |
524 |
dprintf("--- PFRAME ---"); |
dprintf("--- PFRAME ---"); |
525 |
|
|
642 |
|
|
643 |
if (pFrame->quant == 0) |
if (pFrame->quant == 0) |
644 |
{ |
{ |
645 |
pEnc->current->quant = RateControlGetQ(0); |
pEnc->current->quant = RateControlGetQ(&pEnc->rate_control,0); |
646 |
} |
} |
647 |
else |
else |
648 |
{ |
{ |
735 |
|
|
736 |
if (pFrame->quant == 0) |
if (pFrame->quant == 0) |
737 |
{ |
{ |
738 |
RateControlUpdate(pEnc->current->quant, pFrame->length, pFrame->intra); |
RateControlUpdate(&pEnc->rate_control, |
739 |
|
pEnc->current->quant, |
740 |
|
pFrame->length, |
741 |
|
pFrame->intra); |
742 |
} |
} |
743 |
|
|
744 |
#ifdef _DEBUG |
#ifdef _DEBUG |