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 |
|
|
389 |
image_null(&pEnc->queue[n].image); |
image_null(&pEnc->queue[n].image); |
390 |
|
|
391 |
|
|
392 |
for (n = 0; n < pEnc->mbParam.max_bframes+1; n++) |
for (n = 0; n < pEnc->mbParam.max_bframes+1; n++) { |
|
{ |
|
393 |
if (image_create |
if (image_create |
394 |
(&pEnc->queue[n].image, pEnc->mbParam.edged_width, |
(&pEnc->queue[n].image, pEnc->mbParam.edged_width, |
395 |
pEnc->mbParam.edged_height) < 0) |
pEnc->mbParam.edged_height) < 0) |
396 |
goto xvid_err_memory5; |
goto xvid_err_memory5; |
|
|
|
397 |
} |
} |
398 |
|
|
|
|
|
399 |
/* timestamp stuff */ |
/* timestamp stuff */ |
400 |
|
|
401 |
pEnc->mbParam.m_stamp = 0; |
pEnc->mbParam.m_stamp = 0; |
420 |
|
|
421 |
xvid_err_memory5: |
xvid_err_memory5: |
422 |
|
|
423 |
if (pEnc->mbParam.max_bframes > 0) { |
for (n = 0; n < pEnc->mbParam.max_bframes+1; n++) { |
424 |
int i; |
image_destroy(&pEnc->queue[n].image, pEnc->mbParam.edged_width, |
|
|
|
|
for (i = 0; i < pEnc->mbParam.max_bframes+1; i++) { |
|
|
image_destroy(&pEnc->queue[i].image, pEnc->mbParam.edged_width, |
|
425 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
426 |
} |
} |
427 |
|
|
428 |
xvid_free(pEnc->queue); |
xvid_free(pEnc->queue); |
|
} |
|
429 |
|
|
430 |
xvid_err_memory4: |
xvid_err_memory4: |
431 |
|
|
439 |
|
|
440 |
image_destroy(&pEnc->bframes[i]->image, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->bframes[i]->image, pEnc->mbParam.edged_width, |
441 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
|
|
|
442 |
xvid_free(pEnc->bframes[i]->mbs); |
xvid_free(pEnc->bframes[i]->mbs); |
|
|
|
443 |
xvid_free(pEnc->bframes[i]); |
xvid_free(pEnc->bframes[i]); |
|
|
|
444 |
} |
} |
445 |
|
|
446 |
xvid_free(pEnc->bframes); |
xvid_free(pEnc->bframes); |
529 |
int i; |
int i; |
530 |
|
|
531 |
/* B Frames specific */ |
/* B Frames specific */ |
|
if (pEnc->mbParam.max_bframes > 0) { |
|
|
|
|
532 |
for (i = 0; i < pEnc->mbParam.max_bframes+1; i++) { |
for (i = 0; i < pEnc->mbParam.max_bframes+1; i++) { |
|
|
|
533 |
image_destroy(&pEnc->queue[i].image, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->queue[i].image, pEnc->mbParam.edged_width, |
534 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
535 |
} |
} |
|
xvid_free(pEnc->queue); |
|
|
} |
|
536 |
|
|
537 |
|
xvid_free(pEnc->queue); |
538 |
|
|
539 |
if (pEnc->mbParam.max_bframes > 0) { |
if (pEnc->mbParam.max_bframes > 0) { |
540 |
|
|
545 |
|
|
546 |
image_destroy(&pEnc->bframes[i]->image, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->bframes[i]->image, pEnc->mbParam.edged_width, |
547 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
|
|
|
548 |
xvid_free(pEnc->bframes[i]->mbs); |
xvid_free(pEnc->bframes[i]->mbs); |
|
|
|
549 |
xvid_free(pEnc->bframes[i]); |
xvid_free(pEnc->bframes[i]); |
550 |
} |
} |
551 |
|
|
648 |
data.mb_height = pEnc->mbParam.mb_height; |
data.mb_height = pEnc->mbParam.mb_height; |
649 |
data.fincr = frame->fincr; |
data.fincr = frame->fincr; |
650 |
data.fbase = pEnc->mbParam.fbase; |
data.fbase = pEnc->mbParam.fbase; |
651 |
|
data.bquant_ratio = pEnc->mbParam.bquant_ratio; |
652 |
|
data.bquant_offset = pEnc->mbParam.bquant_offset; |
653 |
|
|
654 |
for (i=0; i<3; i++) { |
for (i=0; i<3; i++) { |
655 |
data.min_quant[i] = pEnc->mbParam.min_quant[i]; |
data.min_quant[i] = pEnc->mbParam.min_quant[i]; |
727 |
|
|
728 |
for (j=0; j<pEnc->mbParam.mb_height; j++) |
for (j=0; j<pEnc->mbParam.mb_height; j++) |
729 |
for (i=0; i<pEnc->mbParam.mb_width; i++) { |
for (i=0; i<pEnc->mbParam.mb_width; i++) { |
730 |
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; |
731 |
} |
} |
732 |
} |
} |
733 |
|
|
757 |
} |
} |
758 |
|
|
759 |
/* call plugins */ |
/* call plugins */ |
760 |
for (i=0; i<pEnc->num_plugins;i++) { |
for (i=0; i<(unsigned int)pEnc->num_plugins;i++) { |
761 |
emms(); |
emms(); |
762 |
if (pEnc->plugins[i].func) { |
if (pEnc->plugins[i].func) { |
763 |
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) { |
853 |
int type; |
int type; |
854 |
Bitstream bs; |
Bitstream bs; |
855 |
|
|
856 |
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 */ |
857 |
return XVID_ERR_VERSION; |
return XVID_ERR_VERSION; |
858 |
|
|
859 |
xFrame->out_flags = 0; |
xFrame->out_flags = 0; |
890 |
|
|
891 |
if (xFrame->quant_intra_matrix) |
if (xFrame->quant_intra_matrix) |
892 |
{ |
{ |
893 |
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)); |
894 |
q->frame.quant_intra_matrix = q->quant_intra_matrix; |
q->frame.quant_intra_matrix = q->quant_intra_matrix; |
895 |
} |
} |
896 |
|
|
897 |
if (xFrame->quant_inter_matrix) |
if (xFrame->quant_inter_matrix) |
898 |
{ |
{ |
899 |
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)); |
900 |
q->frame.quant_inter_matrix = q->quant_inter_matrix; |
q->frame.quant_inter_matrix = q->quant_inter_matrix; |
901 |
} |
} |
902 |
|
|
996 |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
997 |
|
|
998 |
/* convert B-VOP to P-VOP */ |
/* convert B-VOP to P-VOP */ |
999 |
pEnc->current->quant = ((pEnc->current->quant*100) - pEnc->mbParam.bquant_offset) / pEnc->mbParam.bquant_ratio; |
pEnc->current->quant = 100*pEnc->current->quant - pEnc->mbParam.bquant_offset; |
1000 |
|
pEnc->current->quant += pEnc->mbParam.bquant_ratio - 1; /* to avoid rouding issues */ |
1001 |
|
pEnc->current->quant /= pEnc->mbParam.bquant_ratio; |
1002 |
|
|
1003 |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
1004 |
image_copy(&pEnc->sOriginal, &pEnc->current->image, |
image_copy(&pEnc->sOriginal, &pEnc->current->image, |
1086 |
|
|
1087 |
if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { |
if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { |
1088 |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 5, |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 5, |
1089 |
"%i st:%i if:%i", pEnc->current->frame_num, pEnc->current->stamp, pEnc->iFrameNum); |
"%d st:%lld if:%d", pEnc->current->frame_num, pEnc->current->stamp, pEnc->iFrameNum); |
1090 |
} |
} |
1091 |
|
|
1092 |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1165 |
} |
} |
1166 |
|
|
1167 |
/* convert B-VOP quant to P-VOP */ |
/* convert B-VOP quant to P-VOP */ |
1168 |
pEnc->current->quant = ((pEnc->current->quant*100) - pEnc->mbParam.bquant_offset) / pEnc->mbParam.bquant_ratio; |
pEnc->current->quant = 100*pEnc->current->quant - pEnc->mbParam.bquant_offset; |
1169 |
|
pEnc->current->quant += pEnc->mbParam.bquant_ratio - 1; /* to avoid rouding issues */ |
1170 |
|
pEnc->current->quant /= pEnc->mbParam.bquant_ratio; |
1171 |
type = P_VOP; |
type = P_VOP; |
1172 |
} |
} |
1173 |
|
|
1190 |
|
|
1191 |
/* ---- update vol flags at IVOP ----------- */ |
/* ---- update vol flags at IVOP ----------- */ |
1192 |
pEnc->current->vol_flags = pEnc->mbParam.vol_flags = frame->vol_flags; |
pEnc->current->vol_flags = pEnc->mbParam.vol_flags = frame->vol_flags; |
1193 |
|
switch(frame->par) { |
1194 |
|
case XVID_PAR_11_VGA: |
1195 |
|
case XVID_PAR_43_PAL: |
1196 |
|
case XVID_PAR_43_NTSC: |
1197 |
|
case XVID_PAR_169_PAL: |
1198 |
|
case XVID_PAR_169_NTSC: |
1199 |
|
case XVID_PAR_EXT: |
1200 |
|
pEnc->mbParam.par = frame->par; |
1201 |
|
break; |
1202 |
|
default: |
1203 |
|
pEnc->mbParam.par = XVID_PAR_EXT; |
1204 |
|
break; |
1205 |
|
} |
1206 |
|
pEnc->mbParam.par_width = (frame->par_width)?frame->par_width:1; |
1207 |
|
pEnc->mbParam.par_height = (frame->par_height)?frame->par_height:1; |
1208 |
|
|
1209 |
if ((pEnc->mbParam.vol_flags & XVID_VOL_MPEGQUANT)) { |
if ((pEnc->mbParam.vol_flags & XVID_VOL_MPEGQUANT)) { |
1210 |
if (frame->quant_intra_matrix != NULL) |
if (frame->quant_intra_matrix != NULL) |
1258 |
* on next enc_encode call we must flush bframes |
* on next enc_encode call we must flush bframes |
1259 |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
1260 |
|
|
1261 |
done_flush: |
/*done_flush:*/ |
1262 |
|
|
1263 |
pEnc->flush_bframes = 1; |
pEnc->flush_bframes = 1; |
1264 |
|
|
1290 |
{ |
{ |
1291 |
unsigned int i,j; |
unsigned int i,j; |
1292 |
int quant = frame->quant; |
int quant = frame->quant; |
1293 |
|
if (quant > 31) |
1294 |
|
frame->quant = quant = 31; |
1295 |
|
else if (quant < 1) |
1296 |
|
frame->quant = quant = 1; |
1297 |
|
|
1298 |
for (j=0; j<pParam->mb_height; j++) |
for (j=0; j<pParam->mb_height; j++) |
1299 |
for (i=0; i<pParam->mb_width; i++) { |
for (i=0; i<pParam->mb_width; i++) { |
1301 |
quant += pMB->dquant; |
quant += pMB->dquant; |
1302 |
if (quant > 31) |
if (quant > 31) |
1303 |
quant = 31; |
quant = 31; |
1304 |
if (quant < 1) |
else if (quant < 1) |
1305 |
quant = 1; |
quant = 1; |
1306 |
pMB->quant = quant; |
pMB->quant = quant; |
1307 |
} |
} |
1365 |
|
|
1366 |
set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); |
set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); |
1367 |
|
|
1368 |
BitstreamPadAlways(bs); |
BitstreamPad(bs); |
1369 |
|
|
1370 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1); |
1371 |
|
|
1372 |
pEnc->current->sStat.iTextBits = 0; |
pEnc->current->sStat.iTextBits = 0; |
1405 |
} |
} |
1406 |
emms(); |
emms(); |
1407 |
|
|
1408 |
/* XXX: Remove the two #if 0 blocks when we are sure we must always pad the stream */ |
BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */ |
1409 |
#if 0 |
|
|
/* for divx5 compatibility, we must always pad between the packed p and b frames */ |
|
|
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) |
|
|
#endif |
|
|
BitstreamPadAlways(bs); |
|
|
#if 0 |
|
|
else |
|
|
BitstreamPad(bs); |
|
|
#endif |
|
1410 |
pEnc->current->length = (BitstreamPos(bs) - bits) / 8; |
pEnc->current->length = (BitstreamPos(bs) - bits) / 8; |
1411 |
|
|
1412 |
pEnc->fMvPrevSigma = -1; |
pEnc->fMvPrevSigma = -1; |
1413 |
pEnc->mbParam.m_fcode = 2; |
pEnc->mbParam.m_fcode = 2; |
1414 |
|
|
1415 |
|
pEnc->current->is_edged = 0; /* not edged */ |
1416 |
|
pEnc->current->is_interpolated = -1; /* not interpolated (fake rounding -1) */ |
1417 |
|
|
1418 |
return 1; /* intra */ |
return 1; /* intra */ |
1419 |
} |
} |
1420 |
|
|
1457 |
} |
} |
1458 |
|
|
1459 |
|
|
1460 |
|
if (!reference->is_edged) { |
1461 |
start_timer(); |
start_timer(); |
1462 |
image_setedges(pRef, pParam->edged_width, pParam->edged_height, |
image_setedges(pRef, pParam->edged_width, pParam->edged_height, |
1463 |
pParam->width, pParam->height); |
pParam->width, pParam->height); |
1464 |
stop_edges_timer(); |
stop_edges_timer(); |
1465 |
|
reference->is_edged = 1; |
1466 |
|
} |
1467 |
|
|
1468 |
pParam->m_rounding_type = 1 - pParam->m_rounding_type; |
pParam->m_rounding_type = 1 - pParam->m_rounding_type; |
1469 |
current->rounding_type = pParam->m_rounding_type; |
current->rounding_type = pParam->m_rounding_type; |
1475 |
iLimit = mb_width * mb_height + 1; |
iLimit = mb_width * mb_height + 1; |
1476 |
|
|
1477 |
if ((current->vop_flags & XVID_VOP_HALFPEL)) { |
if ((current->vop_flags & XVID_VOP_HALFPEL)) { |
1478 |
|
if (reference->is_interpolated != current->rounding_type) { |
1479 |
start_timer(); |
start_timer(); |
1480 |
image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV, |
image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV, |
1481 |
&pEnc->vInterHV, pParam->edged_width, |
&pEnc->vInterHV, pParam->edged_width, |
1483 |
(pParam->vol_flags & XVID_VOL_QUARTERPEL), |
(pParam->vol_flags & XVID_VOL_QUARTERPEL), |
1484 |
current->rounding_type); |
current->rounding_type); |
1485 |
stop_inter_timer(); |
stop_inter_timer(); |
1486 |
|
reference->is_interpolated = current->rounding_type; |
1487 |
|
} |
1488 |
} |
} |
1489 |
|
|
1490 |
current->coding_type = P_VOP; |
current->coding_type = P_VOP; |
1498 |
current->warp = GlobalMotionEst( current->mbs, pParam, current, reference, |
current->warp = GlobalMotionEst( current->mbs, pParam, current, reference, |
1499 |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV); |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV); |
1500 |
|
|
1501 |
if (current->motion_flags & XVID_GME_REFINE) { |
if (current->motion_flags & XVID_ME_GME_REFINE) { |
1502 |
gmcval = GlobalMotionEstRefine(¤t->warp, |
gmcval = GlobalMotionEstRefine(¤t->warp, |
1503 |
current->mbs, pParam, |
current->mbs, pParam, |
1504 |
current, reference, |
current, reference, |
1507 |
&pEnc->vInterH, |
&pEnc->vInterH, |
1508 |
&pEnc->vInterV, |
&pEnc->vInterV, |
1509 |
&pEnc->vInterHV); |
&pEnc->vInterHV); |
1510 |
gmcval += /*current->quant */ 2 * (int)(pParam->mb_width*pParam->mb_height); |
} else { |
|
} |
|
|
|
|
1511 |
gmcval = globalSAD(¤t->warp, pParam, current->mbs, |
gmcval = globalSAD(¤t->warp, pParam, current->mbs, |
1512 |
current, |
current, |
1513 |
&reference->image, |
&reference->image, |
1514 |
¤t->image, |
¤t->image, |
1515 |
pEnc->vGMC.y); |
pEnc->vGMC.y); |
1516 |
|
} |
1517 |
|
|
1518 |
gmcval += /*current->quant*/ 2 * (int)(pParam->mb_width*pParam->mb_height); |
gmcval += /*current->quant*/ 2 * (int)(pParam->mb_width*pParam->mb_height); |
1519 |
|
|
1520 |
/* 1st '3': 3 warpoints, 2nd '3': 16th pel res (2<<3) */ |
/* 1st '3': 3 warpoints, 2nd '3': 16th pel res (2<<3) */ |
1556 |
set_timecodes(current,reference,pParam->fbase); |
set_timecodes(current,reference,pParam->fbase); |
1557 |
if (vol_header) |
if (vol_header) |
1558 |
{ BitstreamWriteVolHeader(bs, &pEnc->mbParam); |
{ BitstreamWriteVolHeader(bs, &pEnc->mbParam); |
1559 |
BitstreamPadAlways(bs); |
BitstreamPad(bs); |
1560 |
} |
} |
1561 |
|
|
1562 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1); |
1583 |
|
|
1584 |
current->sStat.kblks++; |
current->sStat.kblks++; |
1585 |
|
|
1586 |
|
if (pEnc->current->vop_flags & XVID_VOP_GREYSCALE) |
1587 |
|
{ pMB->cbp &= 0x3C; /* keep only bits 5-2 */ |
1588 |
|
qcoeff[4*64+0]=0; /* zero, because for INTRA MBs DC value is saved */ |
1589 |
|
qcoeff[5*64+0]=0; |
1590 |
|
} |
1591 |
MBCoding(current, pMB, qcoeff, bs, ¤t->sStat); |
MBCoding(current, pMB, qcoeff, bs, ¤t->sStat); |
1592 |
stop_coding_timer(); |
stop_coding_timer(); |
1593 |
continue; |
continue; |
1792 |
memcpy(current->mbs, reference->mbs, sizeof(MACROBLOCK) * mb_width * mb_height); |
memcpy(current->mbs, reference->mbs, sizeof(MACROBLOCK) * mb_width * mb_height); |
1793 |
} |
} |
1794 |
|
|
1795 |
|
pEnc->current->is_edged = 0; /* not edged */ |
1796 |
|
pEnc->current->is_interpolated = -1; /* not interpolated (fake rounding -1) */ |
1797 |
|
|
1798 |
|
/* what was this frame's interpolated reference will become |
1799 |
|
forward (past) reference in b-frame coding */ |
1800 |
|
|
1801 |
|
image_swap(&pEnc->vInterH, &pEnc->f_refh); |
1802 |
|
image_swap(&pEnc->vInterV, &pEnc->f_refv); |
1803 |
|
image_swap(&pEnc->vInterHV, &pEnc->f_refhv); |
1804 |
|
|
1805 |
|
|
1806 |
/* XXX: debug |
/* XXX: debug |
1807 |
{ |
{ |
1808 |
char s[100]; |
char s[100]; |
1818 |
} |
} |
1819 |
*/ |
*/ |
1820 |
|
|
1821 |
/* XXX: Remove the two #if 0 blocks when we are sure we must always pad the stream */ |
BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */ |
|
#if 0 |
|
|
/* for divx5 compatibility, we must always pad between the packed p and b frames */ |
|
|
if ((pParam->global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) |
|
|
#endif |
|
|
BitstreamPadAlways(bs); |
|
|
#if 0 |
|
|
else |
|
|
BitstreamPad(bs); |
|
|
#endif |
|
1822 |
|
|
1823 |
current->length = (BitstreamPos(bs) - bits) / 8; |
current->length = (BitstreamPos(bs) - bits) / 8; |
1824 |
|
|
1854 |
#endif |
#endif |
1855 |
|
|
1856 |
/* forward */ |
/* forward */ |
1857 |
|
if (!pEnc->reference->is_edged) { |
1858 |
image_setedges(f_ref, pEnc->mbParam.edged_width, |
image_setedges(f_ref, pEnc->mbParam.edged_width, |
1859 |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
1860 |
pEnc->mbParam.height); |
pEnc->mbParam.height); |
1861 |
|
pEnc->current->is_edged = 1; |
1862 |
|
} |
1863 |
|
|
1864 |
|
if (pEnc->reference->is_interpolated != 0) { |
1865 |
start_timer(); |
start_timer(); |
1866 |
image_interpolate(f_ref, &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv, |
image_interpolate(f_ref, &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv, |
1867 |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
1868 |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); |
1869 |
stop_inter_timer(); |
stop_inter_timer(); |
1870 |
|
pEnc->reference->is_interpolated = 0; |
1871 |
|
} |
1872 |
|
|
1873 |
/* backward */ |
/* backward */ |
1874 |
|
if (!pEnc->current->is_edged) { |
1875 |
image_setedges(b_ref, pEnc->mbParam.edged_width, |
image_setedges(b_ref, pEnc->mbParam.edged_width, |
1876 |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
1877 |
pEnc->mbParam.height); |
pEnc->mbParam.height); |
1878 |
|
pEnc->current->is_edged = 1; |
1879 |
|
} |
1880 |
|
|
1881 |
|
if (pEnc->current->is_interpolated != 0) { |
1882 |
start_timer(); |
start_timer(); |
1883 |
image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
1884 |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
1885 |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); |
1886 |
stop_inter_timer(); |
stop_inter_timer(); |
1887 |
|
pEnc->current->is_interpolated = 0; |
1888 |
|
} |
1889 |
|
|
1890 |
start_timer(); |
start_timer(); |
1891 |
MotionEstimationBVOP(&pEnc->mbParam, frame, |
MotionEstimationBVOP(&pEnc->mbParam, frame, |
1912 |
for (y = 0; y < pEnc->mbParam.mb_height; y++) { |
for (y = 0; y < pEnc->mbParam.mb_height; y++) { |
1913 |
for (x = 0; x < pEnc->mbParam.mb_width; x++) { |
for (x = 0; x < pEnc->mbParam.mb_width; x++) { |
1914 |
MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width]; |
MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width]; |
|
int direction = frame->vop_flags & XVID_VOP_ALTERNATESCAN ? 2 : 0; |
|
1915 |
|
|
1916 |
/* decoder ignores mb when refence block is INTER(0,0), CBP=0 */ |
/* decoder ignores mb when refence block is INTER(0,0), CBP=0 */ |
1917 |
if (mb->mode == MODE_NOT_CODED) { |
if (mb->mode == MODE_NOT_CODED) { |
1918 |
/* mb->mvs[0].x = mb->mvs[0].y = mb->cbp = 0; */ |
if (pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) { |
1919 |
|
MBMotionCompensation(mb, x, y, f_ref, NULL, f_ref, NULL, NULL, &frame->image, |
1920 |
|
NULL, 0, 0, pEnc->mbParam.edged_width, 0, 0, 0); |
1921 |
|
} |
1922 |
|
|
1923 |
continue; |
continue; |
1924 |
} |
} |
1925 |
|
|
1942 |
} |
} |
1943 |
} |
} |
1944 |
|
|
1945 |
#ifdef BFRAMES_DEC_DEBUG |
/* keep only bits 5-2 -- Chroma blocks will just be skipped by the |
1946 |
BFRAME_DEBUG |
* coding function for BFrames, that's why we don't zero teh DC |
1947 |
#endif |
* coeffs */ |
1948 |
|
if ((frame->vop_flags & XVID_VOP_GREYSCALE)) |
1949 |
|
mb->cbp &= 0x3C; |
1950 |
|
|
1951 |
start_timer(); |
start_timer(); |
1952 |
MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs, |
MBCodingBVOP(frame, mb, qcoeff, frame->fcode, frame->bcode, bs, |
1953 |
&frame->sStat, direction); |
&frame->sStat); |
1954 |
stop_coding_timer(); |
stop_coding_timer(); |
1955 |
} |
} |
1956 |
} |
} |
1959 |
|
|
1960 |
/* TODO: dynamic fcode/bcode ??? */ |
/* TODO: dynamic fcode/bcode ??? */ |
1961 |
|
|
1962 |
BitstreamPadAlways(bs); |
BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */ |
1963 |
frame->length = (BitstreamPos(bs) - bits) / 8; |
frame->length = (BitstreamPos(bs) - bits) / 8; |
1964 |
|
|
1965 |
#ifdef BFRAMES_DEC_DEBUG |
#ifdef BFRAMES_DEC_DEBUG |