21 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
22 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 |
* |
* |
24 |
* $Id: encoder.c,v 1.95.2.34 2003-07-28 12:28:55 edgomez Exp $ |
* $Id: encoder.c,v 1.95.2.38 2003-08-07 15:41:33 chl Exp $ |
25 |
* |
* |
26 |
****************************************************************************/ |
****************************************************************************/ |
27 |
|
|
117 |
Encoder *pEnc; |
Encoder *pEnc; |
118 |
int n; |
int n; |
119 |
|
|
120 |
if (XVID_MAJOR(create->version) != 1) /* v1.x.x */ |
if (XVID_VERSION_MAJOR(create->version) != 1) /* v1.x.x */ |
121 |
return XVID_ERR_VERSION; |
return XVID_ERR_VERSION; |
122 |
|
|
123 |
if (create->width%2 || create->height%2) |
if (create->width%2 || create->height%2) |
226 |
pEnc->mbParam.frame_drop_ratio = MAX(create->frame_drop_ratio, 0); |
pEnc->mbParam.frame_drop_ratio = MAX(create->frame_drop_ratio, 0); |
227 |
|
|
228 |
/* max keyframe interval */ |
/* max keyframe interval */ |
229 |
pEnc->mbParam.iMaxKeyInterval = create->max_key_interval <= 0 ? |
pEnc->mbParam.iMaxKeyInterval = create->max_key_interval <= 0 ? (10 * (int)pEnc->mbParam.fbase) / (int)pEnc->mbParam.fincr : create->max_key_interval; |
|
(10 * pEnc->mbParam.fbase) / pEnc->mbParam.fincr : create->max_key_interval; |
|
230 |
|
|
231 |
/* allocate working frame-image memory */ |
/* allocate working frame-image memory */ |
232 |
|
|
740 |
|
|
741 |
for (j=0; j<pEnc->mbParam.mb_height; j++) |
for (j=0; j<pEnc->mbParam.mb_height; j++) |
742 |
for (i=0; i<pEnc->mbParam.mb_width; i++) { |
for (i=0; i<pEnc->mbParam.mb_width; i++) { |
743 |
data.dquant[j*data.dquant_stride + i] = frame->mbs[j*pEnc->mbParam.mb_width + i].dquant;; |
data.dquant[j*data.dquant_stride + i] = frame->mbs[j*pEnc->mbParam.mb_width + i].dquant; |
744 |
} |
} |
745 |
} |
} |
746 |
|
|
770 |
} |
} |
771 |
|
|
772 |
/* call plugins */ |
/* call plugins */ |
773 |
for (i=0; i<pEnc->num_plugins;i++) { |
for (i=0; i<(unsigned int)pEnc->num_plugins;i++) { |
774 |
emms(); |
emms(); |
775 |
if (pEnc->plugins[i].func) { |
if (pEnc->plugins[i].func) { |
776 |
if (pEnc->plugins[i].func(pEnc->plugins[i].param, opt, &data, 0) < 0) { |
if (pEnc->plugins[i].func(pEnc->plugins[i].param, opt, &data, 0) < 0) { |
866 |
int type; |
int type; |
867 |
Bitstream bs; |
Bitstream bs; |
868 |
|
|
869 |
if (XVID_MAJOR(xFrame->version) != 1 || (stats && XVID_MAJOR(stats->version) != 1)) /* v1.x.x */ |
if (XVID_VERSION_MAJOR(xFrame->version) != 1 || (stats && XVID_VERSION_MAJOR(stats->version) != 1)) /* v1.x.x */ |
870 |
return XVID_ERR_VERSION; |
return XVID_ERR_VERSION; |
871 |
|
|
872 |
xFrame->out_flags = 0; |
xFrame->out_flags = 0; |
903 |
|
|
904 |
if (xFrame->quant_intra_matrix) |
if (xFrame->quant_intra_matrix) |
905 |
{ |
{ |
906 |
memcpy(q->quant_intra_matrix, xFrame->quant_intra_matrix, sizeof(xFrame->quant_intra_matrix)); |
memcpy(q->quant_intra_matrix, xFrame->quant_intra_matrix, 64*sizeof(unsigned char)); |
907 |
q->frame.quant_intra_matrix = q->quant_intra_matrix; |
q->frame.quant_intra_matrix = q->quant_intra_matrix; |
908 |
} |
} |
909 |
|
|
910 |
if (xFrame->quant_inter_matrix) |
if (xFrame->quant_inter_matrix) |
911 |
{ |
{ |
912 |
memcpy(q->quant_inter_matrix, xFrame->quant_inter_matrix, sizeof(xFrame->quant_inter_matrix)); |
memcpy(q->quant_inter_matrix, xFrame->quant_inter_matrix, 64*sizeof(unsigned char)); |
913 |
q->frame.quant_inter_matrix = q->quant_inter_matrix; |
q->frame.quant_inter_matrix = q->quant_inter_matrix; |
914 |
} |
} |
915 |
|
|
1252 |
* on next enc_encode call we must flush bframes |
* on next enc_encode call we must flush bframes |
1253 |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
1254 |
|
|
1255 |
done_flush: |
/*done_flush:*/ |
1256 |
|
|
1257 |
pEnc->flush_bframes = 1; |
pEnc->flush_bframes = 1; |
1258 |
|
|
1284 |
{ |
{ |
1285 |
unsigned int i,j; |
unsigned int i,j; |
1286 |
int quant = frame->quant; |
int quant = frame->quant; |
1287 |
|
if (quant > 31) |
1288 |
|
frame->quant = quant = 31; |
1289 |
|
else if (quant < 1) |
1290 |
|
frame->quant = quant = 1; |
1291 |
|
|
1292 |
for (j=0; j<pParam->mb_height; j++) |
for (j=0; j<pParam->mb_height; j++) |
1293 |
for (i=0; i<pParam->mb_width; i++) { |
for (i=0; i<pParam->mb_width; i++) { |
1295 |
quant += pMB->dquant; |
quant += pMB->dquant; |
1296 |
if (quant > 31) |
if (quant > 31) |
1297 |
quant = 31; |
quant = 31; |
1298 |
if (quant < 1) |
else if (quant < 1) |
1299 |
quant = 1; |
quant = 1; |
1300 |
pMB->quant = quant; |
pMB->quant = quant; |
1301 |
} |
} |
1483 |
current->warp = GlobalMotionEst( current->mbs, pParam, current, reference, |
current->warp = GlobalMotionEst( current->mbs, pParam, current, reference, |
1484 |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV); |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV); |
1485 |
|
|
1486 |
if (current->motion_flags & XVID_GME_REFINE) { |
if (current->motion_flags & XVID_ME_GME_REFINE) { |
1487 |
gmcval = GlobalMotionEstRefine(¤t->warp, |
gmcval = GlobalMotionEstRefine(¤t->warp, |
1488 |
current->mbs, pParam, |
current->mbs, pParam, |
1489 |
current, reference, |
current, reference, |