28 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
29 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
30 |
* |
* |
31 |
|
* $Id: encoder.c,v 1.84 2002-09-25 23:37:08 h Exp $ |
32 |
|
* |
33 |
****************************************************************************/ |
****************************************************************************/ |
34 |
|
|
35 |
#include <stdlib.h> |
#include <stdlib.h> |
102 |
* Encoder creation |
* Encoder creation |
103 |
* |
* |
104 |
* This function creates an Encoder instance, it allocates all necessary |
* This function creates an Encoder instance, it allocates all necessary |
105 |
* image buffers (reference, current and bframes) and initialize the internal |
* image buffers (reference, current) and initialize the internal xvid |
106 |
* xvid encoder paremeters according to the XVID_ENC_PARAM input parameter. |
* encoder paremeters according to the XVID_ENC_PARAM input parameter. |
107 |
* |
* |
108 |
* The code seems to be very long but is very basic, mainly memory allocation |
* The code seems to be very long but is very basic, mainly memory allocation |
109 |
* and cleaning code. |
* and cleaning code. |
257 |
image_null(&pEnc->reference->image); |
image_null(&pEnc->reference->image); |
258 |
image_null(&pEnc->vInterH); |
image_null(&pEnc->vInterH); |
259 |
image_null(&pEnc->vInterV); |
image_null(&pEnc->vInterV); |
|
image_null(&pEnc->vInterVf); |
|
260 |
image_null(&pEnc->vInterHV); |
image_null(&pEnc->vInterHV); |
|
image_null(&pEnc->vInterHVf); |
|
261 |
|
|
262 |
#ifdef _DEBUG_PSNR |
#ifdef _DEBUG_PSNR |
263 |
if (image_create |
if (image_create |
282 |
pEnc->mbParam.edged_height) < 0) |
pEnc->mbParam.edged_height) < 0) |
283 |
goto xvid_err_memory3; |
goto xvid_err_memory3; |
284 |
if (image_create |
if (image_create |
|
(&pEnc->vInterVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height) < 0) |
|
|
goto xvid_err_memory3; |
|
|
if (image_create |
|
285 |
(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
286 |
pEnc->mbParam.edged_height) < 0) |
pEnc->mbParam.edged_height) < 0) |
287 |
goto xvid_err_memory3; |
goto xvid_err_memory3; |
|
if (image_create |
|
|
(&pEnc->vInterHVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height) < 0) |
|
|
goto xvid_err_memory3; |
|
288 |
|
|
289 |
pParam->handle = (void *) pEnc; |
pParam->handle = (void *) pEnc; |
290 |
|
|
318 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
319 |
image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width, |
320 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
|
image_destroy(&pEnc->vInterVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height); |
|
321 |
image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
322 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
|
image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height); |
|
323 |
|
|
324 |
xvid_err_memory2: |
xvid_err_memory2: |
325 |
xvid_free(pEnc->current->mbs); |
xvid_free(pEnc->current->mbs); |
361 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
362 |
image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width, |
363 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
|
image_destroy(&pEnc->vInterVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height); |
|
364 |
image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
365 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
|
image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height); |
|
366 |
|
|
367 |
#ifdef _DEBUG_PSNR |
#ifdef _DEBUG_PSNR |
368 |
image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->sOriginal, pEnc->mbParam.edged_width, |
542 |
emms(); |
emms(); |
543 |
|
|
544 |
if (pFrame->quant == 0) { |
if (pFrame->quant == 0) { |
545 |
RateControlUpdate(&pEnc->rate_control, pEnc->current->quant, |
RateControlUpdate(&pEnc->rate_control, (int16_t)pEnc->current->quant, |
546 |
pFrame->length, pFrame->intra); |
pFrame->length, pFrame->intra); |
547 |
} |
} |
548 |
#ifdef _DEBUG_PSNR |
#ifdef _DEBUG_PSNR |
871 |
DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE); |
872 |
|
|
873 |
int iLimit; |
int iLimit; |
874 |
int x, y, k; |
unsigned int x, y; |
875 |
int iSearchRange; |
int iSearchRange; |
876 |
int bIntra; |
int bIntra; |
877 |
|
|
880 |
|
|
881 |
start_timer(); |
start_timer(); |
882 |
image_setedges(pRef, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
image_setedges(pRef, pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
883 |
pEnc->mbParam.width, pEnc->mbParam.height, |
pEnc->mbParam.width, pEnc->mbParam.height); |
|
pEnc->current->global_flags & XVID_INTERLACING); |
|
884 |
stop_edges_timer(); |
stop_edges_timer(); |
885 |
|
|
886 |
pEnc->mbParam.m_rounding_type = 1 - pEnc->mbParam.m_rounding_type; |
pEnc->mbParam.m_rounding_type = 1 - pEnc->mbParam.m_rounding_type; |
981 |
CodeIntraMB(pEnc, pMB); |
CodeIntraMB(pEnc, pMB); |
982 |
MBTransQuantIntra(&pEnc->mbParam, pEnc->current, pMB, x, y, |
MBTransQuantIntra(&pEnc->mbParam, pEnc->current, pMB, x, y, |
983 |
dct_codes, qcoeff); |
dct_codes, qcoeff); |
|
} |
|
984 |
|
|
985 |
start_timer(); |
start_timer(); |
986 |
MBPrediction(pEnc->current, x, y, pEnc->mbParam.mb_width, qcoeff); |
MBPrediction(pEnc->current, x, y, pEnc->mbParam.mb_width, qcoeff); |
987 |
stop_prediction_timer(); |
stop_prediction_timer(); |
988 |
|
} |
989 |
|
|
990 |
if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) { |
if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) { |
991 |
pEnc->sStat.kblks++; |
pEnc->sStat.kblks++; |