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.45 2003-10-07 13:02:35 edgomez Exp $ |
* $Id: encoder.c,v 1.95.2.55 2003-11-20 12:07:19 syskin Exp $ |
25 |
* |
* |
26 |
****************************************************************************/ |
****************************************************************************/ |
27 |
|
|
188 |
pcreate.zones = pEnc->zones; |
pcreate.zones = pEnc->zones; |
189 |
pcreate.width = pEnc->mbParam.width; |
pcreate.width = pEnc->mbParam.width; |
190 |
pcreate.height = pEnc->mbParam.height; |
pcreate.height = pEnc->mbParam.height; |
191 |
|
pcreate.mb_width = pEnc->mbParam.mb_width; |
192 |
|
pcreate.mb_height = pEnc->mbParam.mb_height; |
193 |
pcreate.fincr = pEnc->mbParam.fincr; |
pcreate.fincr = pEnc->mbParam.fincr; |
194 |
pcreate.fbase = pEnc->mbParam.fbase; |
pcreate.fbase = pEnc->mbParam.fbase; |
195 |
pcreate.param = create->plugins[n].param; |
pcreate.param = create->plugins[n].param; |
265 |
image_null(&pEnc->reference->image); |
image_null(&pEnc->reference->image); |
266 |
image_null(&pEnc->vInterH); |
image_null(&pEnc->vInterH); |
267 |
image_null(&pEnc->vInterV); |
image_null(&pEnc->vInterV); |
|
image_null(&pEnc->vInterVf); |
|
268 |
image_null(&pEnc->vInterHV); |
image_null(&pEnc->vInterHV); |
|
image_null(&pEnc->vInterHVf); |
|
269 |
|
|
270 |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
271 |
if (image_create |
if (image_create |
309 |
pEnc->mbParam.edged_height) < 0) |
pEnc->mbParam.edged_height) < 0) |
310 |
goto xvid_err_memory3; |
goto xvid_err_memory3; |
311 |
if (image_create |
if (image_create |
|
(&pEnc->vInterVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height) < 0) |
|
|
goto xvid_err_memory3; |
|
|
if (image_create |
|
312 |
(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
313 |
pEnc->mbParam.edged_height) < 0) |
pEnc->mbParam.edged_height) < 0) |
314 |
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; |
|
315 |
|
|
316 |
/* Create full bitplane for GMC, this might be wasteful */ |
/* Create full bitplane for GMC, this might be wasteful */ |
317 |
if (image_create |
if (image_create |
462 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
463 |
image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width, |
464 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
|
image_destroy(&pEnc->vInterVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height); |
|
465 |
image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
466 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
|
image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height); |
|
467 |
|
|
468 |
/* destroy GMC image */ |
/* destroy GMC image */ |
469 |
image_destroy(&pEnc->vGMC, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vGMC, pEnc->mbParam.edged_width, |
551 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
552 |
image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width, |
553 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
|
image_destroy(&pEnc->vInterVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height); |
|
554 |
image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
555 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
|
image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height); |
|
|
|
|
556 |
image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width, |
557 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
558 |
image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width, |
631 |
data.mb_height = pEnc->mbParam.mb_height; |
data.mb_height = pEnc->mbParam.mb_height; |
632 |
data.fincr = frame->fincr; |
data.fincr = frame->fincr; |
633 |
data.fbase = pEnc->mbParam.fbase; |
data.fbase = pEnc->mbParam.fbase; |
634 |
|
data.bquant_ratio = pEnc->mbParam.bquant_ratio; |
635 |
|
data.bquant_offset = pEnc->mbParam.bquant_offset; |
636 |
|
|
637 |
for (i=0; i<3; i++) { |
for (i=0; i<3; i++) { |
638 |
data.min_quant[i] = pEnc->mbParam.min_quant[i]; |
data.min_quant[i] = pEnc->mbParam.min_quant[i]; |
661 |
data.type = *type; |
data.type = *type; |
662 |
data.quant = *quant; |
data.quant = *quant; |
663 |
|
|
664 |
|
data.vol_flags = frame->vol_flags; |
665 |
|
data.vop_flags = frame->vop_flags; |
666 |
|
data.motion_flags = frame->motion_flags; |
667 |
|
|
668 |
|
} else if (opt == XVID_PLG_FRAME) { |
669 |
|
data.type = coding2type(frame->coding_type); |
670 |
|
data.quant = frame->quant; |
671 |
|
|
672 |
if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) { |
673 |
data.dquant = pEnc->temp_dquants; |
data.dquant = pEnc->temp_dquants; |
674 |
data.dquant_stride = pEnc->mbParam.mb_width; |
data.dquant_stride = pEnc->mbParam.mb_width; |
675 |
memset(data.dquant, 0, data.mb_width*data.mb_height); |
memset(data.dquant, 0, data.mb_width*data.mb_height); |
676 |
} |
} |
677 |
|
|
|
data.vol_flags = frame->vol_flags; |
|
|
data.vop_flags = frame->vop_flags; |
|
|
data.motion_flags = frame->motion_flags; |
|
|
|
|
678 |
} else { /* XVID_PLG_AFTER */ |
} else { /* XVID_PLG_AFTER */ |
679 |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
680 |
data.original.csp = XVID_CSP_USER; |
data.original.csp = XVID_CSP_USER; |
759 |
*type = data.type; |
*type = data.type; |
760 |
*quant = data.quant > 0 ? data.quant : 2; /* default */ |
*quant = data.quant > 0 ? data.quant : 2; /* default */ |
761 |
|
|
762 |
|
frame->vol_flags = data.vol_flags; |
763 |
|
frame->vop_flags = data.vop_flags; |
764 |
|
frame->motion_flags = data.motion_flags; |
765 |
|
|
766 |
|
} else if (opt == XVID_PLG_FRAME) { |
767 |
|
|
768 |
if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) { |
769 |
for (j=0; j<pEnc->mbParam.mb_height; j++) |
for (j=0; j<pEnc->mbParam.mb_height; j++) |
770 |
for (i=0; i<pEnc->mbParam.mb_width; i++) { |
for (i=0; i<pEnc->mbParam.mb_width; i++) { |
776 |
frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0; |
frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0; |
777 |
} |
} |
778 |
} |
} |
779 |
|
frame->mbs[0].quant = data.quant; /* FRAME will not affect the quant in stats */ |
|
frame->vol_flags = data.vol_flags; |
|
|
frame->vop_flags = data.vop_flags; |
|
|
frame->motion_flags = data.motion_flags; |
|
|
} |
|
780 |
} |
} |
781 |
|
|
782 |
|
|
783 |
|
} |
784 |
|
|
785 |
|
|
786 |
static __inline void inc_frame_num(Encoder * pEnc) |
static __inline void inc_frame_num(Encoder * pEnc) |
798 |
pEnc->m_framenum--; /* debug ticker */ |
pEnc->m_framenum--; /* debug ticker */ |
799 |
} |
} |
800 |
|
|
801 |
|
static __inline void |
802 |
|
MBSetDquant(MACROBLOCK * pMB, int x, int y, MBParam * mbParam) |
803 |
|
{ |
804 |
|
if (pMB->cbp == 0) { |
805 |
|
/* we want to code dquant but the quantizer value will not be used yet |
806 |
|
let's find out if we can postpone dquant to next MB |
807 |
|
*/ |
808 |
|
if (x == mbParam->mb_width-1 && y == mbParam->mb_height-1) { |
809 |
|
pMB->dquant = 0; /* it's the last MB of all, the easiest case */ |
810 |
|
return; |
811 |
|
} else { |
812 |
|
MACROBLOCK * next = pMB + 1; |
813 |
|
const MACROBLOCK * prev = pMB - 1; |
814 |
|
if (next->mode != MODE_INTER4V && next->mode != MODE_NOT_CODED) |
815 |
|
/* mode allows dquant change in the future */ |
816 |
|
if (abs(next->quant - prev->quant) <= 2) { |
817 |
|
/* quant change is not out of range */ |
818 |
|
pMB->quant = prev->quant; |
819 |
|
pMB->dquant = 0; |
820 |
|
next->dquant = next->quant - prev->quant; |
821 |
|
return; |
822 |
|
} |
823 |
|
} |
824 |
|
} |
825 |
|
/* couldn't skip this dquant */ |
826 |
|
pMB->mode = MODE_INTER_Q; |
827 |
|
} |
828 |
|
|
829 |
|
|
830 |
|
|
831 |
static __inline void |
static __inline void |
969 |
tmp = pEnc->current->seconds; |
tmp = pEnc->current->seconds; |
970 |
pEnc->current->seconds = 0; /* force time_base = 0 */ |
pEnc->current->seconds = 0; /* force time_base = 0 */ |
971 |
|
|
972 |
BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0); |
BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0, pEnc->current->quant); |
973 |
BitstreamPad(&bs); |
BitstreamPad(&bs); |
974 |
pEnc->current->seconds = tmp; |
pEnc->current->seconds = tmp; |
975 |
|
|
1014 |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
1015 |
|
|
1016 |
/* convert B-VOP to P-VOP */ |
/* convert B-VOP to P-VOP */ |
1017 |
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; |
1018 |
|
pEnc->current->quant += pEnc->mbParam.bquant_ratio - 1; /* to avoid rouding issues */ |
1019 |
|
pEnc->current->quant /= pEnc->mbParam.bquant_ratio; |
1020 |
|
|
1021 |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
1022 |
image_copy(&pEnc->sOriginal, &pEnc->current->image, |
image_copy(&pEnc->sOriginal, &pEnc->current->image, |
1091 |
}else{ |
}else{ |
1092 |
type = MEanalysis(&pEnc->reference->image, pEnc->current, |
type = MEanalysis(&pEnc->reference->image, pEnc->current, |
1093 |
&pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval, |
&pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval, |
1094 |
pEnc->iFrameNum, pEnc->bframenum_tail, xFrame->bframe_threshold); |
pEnc->iFrameNum, pEnc->bframenum_tail, xFrame->bframe_threshold, |
1095 |
|
(pEnc->bframes) ? pEnc->bframes[pEnc->bframenum_head]->mbs: NULL); |
1096 |
} |
} |
1097 |
} |
} |
1098 |
|
|
1184 |
} |
} |
1185 |
|
|
1186 |
/* convert B-VOP quant to P-VOP */ |
/* convert B-VOP quant to P-VOP */ |
1187 |
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; |
1188 |
|
pEnc->current->quant += pEnc->mbParam.bquant_ratio - 1; /* to avoid rouding issues */ |
1189 |
|
pEnc->current->quant /= pEnc->mbParam.bquant_ratio; |
1190 |
type = P_VOP; |
type = P_VOP; |
1191 |
} |
} |
1192 |
|
|
1307 |
|
|
1308 |
static void SetMacroblockQuants(MBParam * const pParam, FRAMEINFO * frame) |
static void SetMacroblockQuants(MBParam * const pParam, FRAMEINFO * frame) |
1309 |
{ |
{ |
1310 |
unsigned int i,j; |
unsigned int i; |
1311 |
int quant = frame->quant; |
MACROBLOCK * pMB = frame->mbs; |
1312 |
|
int quant = frame->mbs[0].quant; /* set by XVID_PLG_FRAME */ |
1313 |
if (quant > 31) |
if (quant > 31) |
1314 |
frame->quant = quant = 31; |
frame->quant = quant = 31; |
1315 |
else if (quant < 1) |
else if (quant < 1) |
1316 |
frame->quant = quant = 1; |
frame->quant = quant = 1; |
1317 |
|
|
1318 |
for (j=0; j<pParam->mb_height; j++) |
for (i = 0; i < pParam->mb_height * pParam->mb_width; i++) { |
|
for (i=0; i<pParam->mb_width; i++) { |
|
|
MACROBLOCK * pMB = &frame->mbs[j*pParam->mb_width + i]; |
|
1319 |
quant += pMB->dquant; |
quant += pMB->dquant; |
1320 |
if (quant > 31) |
if (quant > 31) |
1321 |
quant = 31; |
quant = 31; |
1322 |
else if (quant < 1) |
else if (quant < 1) |
1323 |
quant = 1; |
quant = 1; |
1324 |
pMB->quant = quant; |
pMB->quant = quant; |
1325 |
|
pMB++; |
1326 |
} |
} |
1327 |
} |
} |
1328 |
|
|
1378 |
pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type; |
pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type; |
1379 |
pEnc->current->coding_type = I_VOP; |
pEnc->current->coding_type = I_VOP; |
1380 |
|
|
1381 |
|
call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL); |
1382 |
|
|
1383 |
SetMacroblockQuants(&pEnc->mbParam, pEnc->current); |
SetMacroblockQuants(&pEnc->mbParam, pEnc->current); |
1384 |
|
|
1385 |
BitstreamWriteVolHeader(bs, &pEnc->mbParam); |
BitstreamWriteVolHeader(bs, &pEnc->mbParam); |
1388 |
|
|
1389 |
BitstreamPad(bs); |
BitstreamPad(bs); |
1390 |
|
|
1391 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1, pEnc->current->mbs[0].quant); |
1392 |
|
|
1393 |
pEnc->current->sStat.iTextBits = 0; |
pEnc->current->sStat.iTextBits = 0; |
1394 |
pEnc->current->sStat.kblks = mb_width * mb_height; |
pEnc->current->sStat.kblks = mb_width * mb_height; |
1433 |
pEnc->fMvPrevSigma = -1; |
pEnc->fMvPrevSigma = -1; |
1434 |
pEnc->mbParam.m_fcode = 2; |
pEnc->mbParam.m_fcode = 2; |
1435 |
|
|
1436 |
|
pEnc->current->is_edged = 0; /* not edged */ |
1437 |
|
pEnc->current->is_interpolated = -1; /* not interpolated (fake rounding -1) */ |
1438 |
|
|
1439 |
return 1; /* intra */ |
return 1; /* intra */ |
1440 |
} |
} |
1441 |
|
|
1478 |
} |
} |
1479 |
|
|
1480 |
|
|
1481 |
|
if (!reference->is_edged) { |
1482 |
start_timer(); |
start_timer(); |
1483 |
image_setedges(pRef, pParam->edged_width, pParam->edged_height, |
image_setedges(pRef, pParam->edged_width, pParam->edged_height, |
1484 |
pParam->width, pParam->height); |
pParam->width, pParam->height); |
1485 |
stop_edges_timer(); |
stop_edges_timer(); |
1486 |
|
reference->is_edged = 1; |
1487 |
|
} |
1488 |
|
|
1489 |
pParam->m_rounding_type = 1 - pParam->m_rounding_type; |
pParam->m_rounding_type = 1 - pParam->m_rounding_type; |
1490 |
current->rounding_type = pParam->m_rounding_type; |
current->rounding_type = pParam->m_rounding_type; |
1496 |
iLimit = mb_width * mb_height + 1; |
iLimit = mb_width * mb_height + 1; |
1497 |
|
|
1498 |
if ((current->vop_flags & XVID_VOP_HALFPEL)) { |
if ((current->vop_flags & XVID_VOP_HALFPEL)) { |
1499 |
|
if (reference->is_interpolated != current->rounding_type) { |
1500 |
start_timer(); |
start_timer(); |
1501 |
image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV, |
image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV, |
1502 |
&pEnc->vInterHV, pParam->edged_width, |
&pEnc->vInterHV, pParam->edged_width, |
1504 |
(pParam->vol_flags & XVID_VOL_QUARTERPEL), |
(pParam->vol_flags & XVID_VOL_QUARTERPEL), |
1505 |
current->rounding_type); |
current->rounding_type); |
1506 |
stop_inter_timer(); |
stop_inter_timer(); |
1507 |
|
reference->is_interpolated = current->rounding_type; |
1508 |
|
} |
1509 |
} |
} |
1510 |
|
|
1511 |
current->coding_type = P_VOP; |
current->coding_type = P_VOP; |
1512 |
|
|
1513 |
|
call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL); |
1514 |
|
|
1515 |
SetMacroblockQuants(&pEnc->mbParam, current); |
SetMacroblockQuants(&pEnc->mbParam, current); |
1516 |
|
|
1529 |
&pEnc->vInterH, |
&pEnc->vInterH, |
1530 |
&pEnc->vInterV, |
&pEnc->vInterV, |
1531 |
&pEnc->vInterHV); |
&pEnc->vInterHV); |
1532 |
gmcval += /*current->quant */ 2 * (int)(pParam->mb_width*pParam->mb_height); |
} else { |
|
} |
|
|
|
|
1533 |
gmcval = globalSAD(¤t->warp, pParam, current->mbs, |
gmcval = globalSAD(¤t->warp, pParam, current->mbs, |
1534 |
current, |
current, |
1535 |
&reference->image, |
&reference->image, |
1536 |
¤t->image, |
¤t->image, |
1537 |
pEnc->vGMC.y); |
pEnc->vGMC.y); |
1538 |
|
} |
1539 |
|
|
1540 |
gmcval += /*current->quant*/ 2 * (int)(pParam->mb_width*pParam->mb_height); |
gmcval += /*current->quant*/ 2 * (int)(pParam->mb_width*pParam->mb_height); |
1541 |
|
|
1542 |
/* 1st '3': 3 warpoints, 2nd '3': 16th pel res (2<<3) */ |
/* 1st '3': 3 warpoints, 2nd '3': 16th pel res (2<<3) */ |
1581 |
BitstreamPad(bs); |
BitstreamPad(bs); |
1582 |
} |
} |
1583 |
|
|
1584 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant); |
1585 |
|
|
1586 |
current->sStat.iTextBits = current->sStat.iMvSum = current->sStat.iMvCount = |
current->sStat.iTextBits = current->sStat.iMvSum = current->sStat.iMvCount = |
1587 |
current->sStat.kblks = current->sStat.mblks = current->sStat.ublks = 0; |
current->sStat.kblks = current->sStat.mblks = current->sStat.ublks = 0; |
1629 |
|
|
1630 |
stop_comp_timer(); |
stop_comp_timer(); |
1631 |
|
|
|
if (pMB->dquant != 0) { |
|
|
pMB->mode = MODE_INTER_Q; |
|
|
} |
|
|
|
|
1632 |
pMB->field_pred = 0; |
pMB->field_pred = 0; |
1633 |
|
|
1634 |
if (pMB->mode != MODE_NOT_CODED) |
if (pMB->mode != MODE_NOT_CODED) |
1637 |
dct_codes, qcoeff); |
dct_codes, qcoeff); |
1638 |
} |
} |
1639 |
|
|
1640 |
|
if (pMB->dquant != 0) |
1641 |
|
MBSetDquant(pMB, x, y, &pEnc->mbParam); |
1642 |
|
|
1643 |
|
|
1644 |
if (pMB->cbp || pMB->mvs[0].x || pMB->mvs[0].y || |
if (pMB->cbp || pMB->mvs[0].x || pMB->mvs[0].y || |
1645 |
pMB->mvs[1].x || pMB->mvs[1].y || pMB->mvs[2].x || |
pMB->mvs[1].x || pMB->mvs[1].y || pMB->mvs[2].x || |
1646 |
pMB->mvs[2].y || pMB->mvs[3].x || pMB->mvs[3].y) { |
pMB->mvs[2].y || pMB->mvs[3].x || pMB->mvs[3].y) { |
1802 |
BitstreamReset(bs); |
BitstreamReset(bs); |
1803 |
|
|
1804 |
set_timecodes(current,reference,pParam->fbase); |
set_timecodes(current,reference,pParam->fbase); |
1805 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 0); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 0, current->mbs[0].quant); |
1806 |
|
|
1807 |
/* copy reference frame details into the current frame */ |
/* copy reference frame details into the current frame */ |
1808 |
current->quant = reference->quant; |
current->quant = reference->quant; |
1814 |
memcpy(current->mbs, reference->mbs, sizeof(MACROBLOCK) * mb_width * mb_height); |
memcpy(current->mbs, reference->mbs, sizeof(MACROBLOCK) * mb_width * mb_height); |
1815 |
} |
} |
1816 |
|
|
1817 |
|
pEnc->current->is_edged = 0; /* not edged */ |
1818 |
|
pEnc->current->is_interpolated = -1; /* not interpolated (fake rounding -1) */ |
1819 |
|
|
1820 |
|
/* what was this frame's interpolated reference will become |
1821 |
|
forward (past) reference in b-frame coding */ |
1822 |
|
|
1823 |
|
image_swap(&pEnc->vInterH, &pEnc->f_refh); |
1824 |
|
image_swap(&pEnc->vInterV, &pEnc->f_refv); |
1825 |
|
image_swap(&pEnc->vInterHV, &pEnc->f_refhv); |
1826 |
|
|
1827 |
|
|
1828 |
/* XXX: debug |
/* XXX: debug |
1829 |
{ |
{ |
1830 |
char s[100]; |
char s[100]; |
1876 |
#endif |
#endif |
1877 |
|
|
1878 |
/* forward */ |
/* forward */ |
1879 |
|
if (!pEnc->reference->is_edged) { |
1880 |
image_setedges(f_ref, pEnc->mbParam.edged_width, |
image_setedges(f_ref, pEnc->mbParam.edged_width, |
1881 |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
1882 |
pEnc->mbParam.height); |
pEnc->mbParam.height); |
1883 |
|
pEnc->current->is_edged = 1; |
1884 |
|
} |
1885 |
|
|
1886 |
|
if (pEnc->reference->is_interpolated != 0) { |
1887 |
start_timer(); |
start_timer(); |
1888 |
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, |
1889 |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
1890 |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); |
1891 |
stop_inter_timer(); |
stop_inter_timer(); |
1892 |
|
pEnc->reference->is_interpolated = 0; |
1893 |
|
} |
1894 |
|
|
1895 |
/* backward */ |
/* backward */ |
1896 |
|
if (!pEnc->current->is_edged) { |
1897 |
image_setedges(b_ref, pEnc->mbParam.edged_width, |
image_setedges(b_ref, pEnc->mbParam.edged_width, |
1898 |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
1899 |
pEnc->mbParam.height); |
pEnc->mbParam.height); |
1900 |
|
pEnc->current->is_edged = 1; |
1901 |
|
} |
1902 |
|
|
1903 |
|
if (pEnc->current->is_interpolated != 0) { |
1904 |
start_timer(); |
start_timer(); |
1905 |
image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
1906 |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
1907 |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); |
1908 |
stop_inter_timer(); |
stop_inter_timer(); |
1909 |
|
pEnc->current->is_interpolated = 0; |
1910 |
|
} |
1911 |
|
|
1912 |
|
frame->coding_type = B_VOP; |
1913 |
|
call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL); |
1914 |
|
|
1915 |
start_timer(); |
start_timer(); |
1916 |
MotionEstimationBVOP(&pEnc->mbParam, frame, |
MotionEstimationBVOP(&pEnc->mbParam, frame, |
1922 |
&pEnc->vInterV, &pEnc->vInterHV); |
&pEnc->vInterV, &pEnc->vInterHV); |
1923 |
stop_motion_timer(); |
stop_motion_timer(); |
1924 |
|
|
|
frame->coding_type = B_VOP; |
|
|
|
|
1925 |
set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase); |
set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase); |
1926 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1, frame->quant); |
1927 |
|
|
1928 |
frame->sStat.iTextBits = 0; |
frame->sStat.iTextBits = 0; |
1929 |
frame->sStat.iMvSum = 0; |
frame->sStat.iMvSum = 0; |
1938 |
|
|
1939 |
/* decoder ignores mb when refence block is INTER(0,0), CBP=0 */ |
/* decoder ignores mb when refence block is INTER(0,0), CBP=0 */ |
1940 |
if (mb->mode == MODE_NOT_CODED) { |
if (mb->mode == MODE_NOT_CODED) { |
1941 |
/* mb->mvs[0].x = mb->mvs[0].y = mb->cbp = 0; */ |
if (pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) { |
1942 |
|
MBMotionCompensation(mb, x, y, f_ref, NULL, f_ref, NULL, NULL, &frame->image, |
1943 |
|
NULL, 0, 0, pEnc->mbParam.edged_width, 0, 0, 0); |
1944 |
|
} |
1945 |
|
|
1946 |
continue; |
continue; |
1947 |
} |
} |
1948 |
|
|