39 |
* MinChen <chenm001@163.com> |
* MinChen <chenm001@163.com> |
40 |
* 14.04.2002 added FrameCodeB() |
* 14.04.2002 added FrameCodeB() |
41 |
* |
* |
42 |
* $Id: encoder.c,v 1.76.2.7 2002-09-30 09:19:26 chl Exp $ |
* $Id: encoder.c,v 1.76.2.16 2002-11-07 10:28:15 suxen_drol Exp $ |
43 |
* |
* |
44 |
****************************************************************************/ |
****************************************************************************/ |
45 |
|
|
54 |
#include "global.h" |
#include "global.h" |
55 |
#include "utils/timer.h" |
#include "utils/timer.h" |
56 |
#include "image/image.h" |
#include "image/image.h" |
|
#ifdef BFRAMES |
|
57 |
#include "image/font.h" |
#include "image/font.h" |
58 |
#include "motion/sad.h" |
#include "motion/sad.h" |
|
#endif |
|
59 |
#include "motion/motion.h" |
#include "motion/motion.h" |
60 |
#include "bitstream/cbp.h" |
#include "bitstream/cbp.h" |
61 |
#include "utils/mbfunctions.h" |
#include "utils/mbfunctions.h" |
107 |
}; |
}; |
108 |
|
|
109 |
|
|
|
static void __inline |
|
|
image_null(IMAGE * image) |
|
|
{ |
|
|
image->y = image->u = image->v = NULL; |
|
|
} |
|
|
|
|
|
|
|
110 |
/***************************************************************************** |
/***************************************************************************** |
111 |
* Encoder creation |
* Encoder creation |
112 |
* |
* |
616 |
start_timer(); |
start_timer(); |
617 |
if (image_input |
if (image_input |
618 |
(&pEnc->queue[pEnc->queue_tail], pEnc->mbParam.width, pEnc->mbParam.height, |
(&pEnc->queue[pEnc->queue_tail], pEnc->mbParam.width, pEnc->mbParam.height, |
619 |
pEnc->mbParam.edged_width, pFrame->image, pFrame->colorspace)) |
pEnc->mbParam.edged_width, pFrame->image, pFrame->stride, pFrame->colorspace, pFrame->general & XVID_INTERLACING)) |
620 |
return; |
return; |
621 |
stop_conv_timer(); |
stop_conv_timer(); |
622 |
|
|
711 |
pFrame->length = BitstreamLength(&bs); |
pFrame->length = BitstreamLength(&bs); |
712 |
pFrame->intra = 0; |
pFrame->intra = 0; |
713 |
|
|
714 |
|
emms(); |
715 |
|
|
716 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
717 |
} |
} |
718 |
|
|
731 |
if (input_valid) |
if (input_valid) |
732 |
queue_image(pEnc, pFrame); |
queue_image(pEnc, pFrame); |
733 |
|
|
734 |
|
emms(); |
735 |
|
|
736 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
737 |
} |
} |
738 |
|
|
739 |
if (pEnc->bframenum_head > 0) { |
if (pEnc->bframenum_head > 0) { |
740 |
pEnc->bframenum_head = pEnc->bframenum_tail = 0; |
pEnc->bframenum_head = pEnc->bframenum_tail = 0; |
741 |
|
|
742 |
|
/* write an empty marker to the bitstream. |
743 |
|
|
744 |
|
for divx5 decoder compatibility, this marker must consist |
745 |
|
of a not-coded p-vop, with a time_base of zero, and time_increment |
746 |
|
indentical to the future-referece frame. |
747 |
|
*/ |
748 |
|
|
749 |
if ((pEnc->global & XVID_GLOBAL_PACKED)) { |
if ((pEnc->global & XVID_GLOBAL_PACKED)) { |
750 |
|
int tmp; |
751 |
|
|
752 |
DPRINTF(DPRINTF_DEBUG,"*** EMPTY bf: head=%i tail=%i queue: head=%i tail=%i size=%i", |
DPRINTF(DPRINTF_DEBUG,"*** EMPTY bf: head=%i tail=%i queue: head=%i tail=%i size=%i", |
753 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
754 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
755 |
|
|
|
set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); |
|
|
BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0); |
|
756 |
BitstreamPad(&bs); |
BitstreamPad(&bs); |
757 |
BitstreamPutBits(&bs, 0x7f, 8); |
|
758 |
|
tmp = pEnc->current->seconds; |
759 |
|
pEnc->current->seconds = 0; /* force time_base = 0 */ |
760 |
|
BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0); |
761 |
|
pEnc->current->seconds = tmp; |
762 |
|
|
763 |
pFrame->length = BitstreamLength(&bs); |
pFrame->length = BitstreamLength(&bs); |
764 |
pFrame->intra = 0; |
pFrame->intra = 0; |
766 |
if (input_valid) |
if (input_valid) |
767 |
queue_image(pEnc, pFrame); |
queue_image(pEnc, pFrame); |
768 |
|
|
769 |
|
emms(); |
770 |
|
|
771 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
772 |
} |
} |
773 |
} |
} |
798 |
start_timer(); |
start_timer(); |
799 |
if (image_input |
if (image_input |
800 |
(&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height, |
(&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height, |
801 |
pEnc->mbParam.edged_width, pFrame->image, pFrame->colorspace)) |
pEnc->mbParam.edged_width, pFrame->image, pFrame->stride, pFrame->colorspace, pFrame->general & XVID_INTERLACING)) |
802 |
|
{ |
803 |
|
emms(); |
804 |
return XVID_ERR_FORMAT; |
return XVID_ERR_FORMAT; |
805 |
|
} |
806 |
stop_conv_timer(); |
stop_conv_timer(); |
807 |
|
|
808 |
// queue input frame, and dequue next image |
// queue input frame, and dequue next image |
825 |
pEnc->queue_head = (pEnc->queue_head + 1) % pEnc->mbParam.max_bframes; |
pEnc->queue_head = (pEnc->queue_head + 1) % pEnc->mbParam.max_bframes; |
826 |
pEnc->queue_size--; |
pEnc->queue_size--; |
827 |
|
|
828 |
} else if (BitstreamPos(&bs) == 0) { |
} else { |
829 |
|
|
830 |
|
/* if nothing was encoded, write an 'ignore this frame' flag |
831 |
|
to the bitstream */ |
832 |
|
|
833 |
|
if (BitstreamPos(&bs) == 0) { |
834 |
|
|
835 |
DPRINTF(DPRINTF_DEBUG,"*** SKIP bf: head=%i tail=%i queue: head=%i tail=%i size=%i", |
DPRINTF(DPRINTF_DEBUG,"*** SKIP bf: head=%i tail=%i queue: head=%i tail=%i size=%i", |
836 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
837 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
838 |
|
|
839 |
|
BitstreamPutBits(&bs, 0x7f, 8); |
840 |
pFrame->intra = 0; |
pFrame->intra = 0; |
841 |
|
} |
|
set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); |
|
|
BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0); // write N_VOP |
|
|
BitstreamPad(&bs); |
|
|
pFrame->length = BitstreamLength(&bs); |
|
|
|
|
|
return XVID_ERR_OK; |
|
|
|
|
|
} else { |
|
842 |
|
|
843 |
pFrame->length = BitstreamLength(&bs); |
pFrame->length = BitstreamLength(&bs); |
844 |
|
emms(); |
845 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
846 |
} |
} |
847 |
|
|
881 |
|
|
882 |
if ((pEnc->global & XVID_GLOBAL_DEBUG)) { |
if ((pEnc->global & XVID_GLOBAL_DEBUG)) { |
883 |
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, |
884 |
"%i if:%i st:%i:%i", pEnc->m_framenum++, pEnc->iFrameNum, pEnc->current->seconds, pEnc->current->ticks); |
"%i if:%i st:%i", pEnc->m_framenum++, pEnc->iFrameNum, pEnc->current->stamp); |
885 |
} |
} |
886 |
|
|
887 |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
972 |
pEnc->flush_bframes = 1; |
pEnc->flush_bframes = 1; |
973 |
|
|
974 |
if ((pEnc->global & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) { |
if ((pEnc->global & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) { |
975 |
BitstreamPad(&bs); |
BitstreamPadAlways(&bs); |
976 |
input_valid = 0; |
input_valid = 0; |
977 |
goto ipvop_loop; |
goto ipvop_loop; |
978 |
} |
} |
999 |
pEnc->flush_bframes = 1; |
pEnc->flush_bframes = 1; |
1000 |
|
|
1001 |
if ((pEnc->global & XVID_GLOBAL_PACKED)) { |
if ((pEnc->global & XVID_GLOBAL_PACKED)) { |
1002 |
BitstreamPad(&bs); |
BitstreamPadAlways(&bs); |
1003 |
input_valid = 0; |
input_valid = 0; |
1004 |
goto ipvop_loop; |
goto ipvop_loop; |
1005 |
} |
} |
1079 |
stop_global_timer(); |
stop_global_timer(); |
1080 |
write_timer(); |
write_timer(); |
1081 |
|
|
1082 |
|
emms(); |
1083 |
return XVID_ERR_OK; |
return XVID_ERR_OK; |
1084 |
} |
} |
1085 |
|
|
1122 |
pEnc->current->motion_flags = pFrame->motion; |
pEnc->current->motion_flags = pFrame->motion; |
1123 |
pEnc->mbParam.hint = &pFrame->hint; |
pEnc->mbParam.hint = &pFrame->hint; |
1124 |
|
|
1125 |
|
inc_frame_num(pEnc); |
1126 |
|
|
1127 |
/* disable alternate scan flag if interlacing is not enabled */ |
/* disable alternate scan flag if interlacing is not enabled */ |
1128 |
if ((pEnc->current->global_flags & XVID_ALTERNATESCAN) && |
if ((pEnc->current->global_flags & XVID_ALTERNATESCAN) && |
1129 |
!(pEnc->current->global_flags & XVID_INTERLACING)) |
!(pEnc->current->global_flags & XVID_INTERLACING)) |
1134 |
start_timer(); |
start_timer(); |
1135 |
if (image_input |
if (image_input |
1136 |
(&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height, |
(&pEnc->current->image, pEnc->mbParam.width, pEnc->mbParam.height, |
1137 |
pEnc->mbParam.edged_width, pFrame->image, pFrame->colorspace) < 0) |
pEnc->mbParam.edged_width, pFrame->image, pFrame->stride, pFrame->colorspace, pFrame->general & XVID_INTERLACING) < 0) |
1138 |
return XVID_ERR_FORMAT; |
return XVID_ERR_FORMAT; |
1139 |
stop_conv_timer(); |
stop_conv_timer(); |
1140 |
|
|
1153 |
pEnc->current->quant = pFrame->quant; |
pEnc->current->quant = pFrame->quant; |
1154 |
} |
} |
1155 |
|
|
1156 |
|
if ((pEnc->current->global_flags & XVID_QUARTERPEL)) |
1157 |
|
pEnc->mbParam.m_quarterpel = 1; |
1158 |
|
else |
1159 |
|
pEnc->mbParam.m_quarterpel = 0; |
1160 |
|
|
1161 |
if ((pEnc->current->global_flags & XVID_LUMIMASKING)) { |
if ((pEnc->current->global_flags & XVID_LUMIMASKING)) { |
1162 |
int *temp_dquants = |
int *temp_dquants = |
1163 |
(int *) xvid_malloc(pEnc->mbParam.mb_width * |
(int *) xvid_malloc(pEnc->mbParam.mb_width * |
1263 |
DEBUG(temp); |
DEBUG(temp); |
1264 |
#endif |
#endif |
1265 |
|
|
|
inc_frame_num(pEnc); |
|
1266 |
pEnc->iFrameNum++; |
pEnc->iFrameNum++; |
1267 |
|
|
1268 |
stop_global_timer(); |
stop_global_timer(); |
1511 |
pEnc->iFrameNum = 0; |
pEnc->iFrameNum = 0; |
1512 |
pEnc->mbParam.m_rounding_type = 1; |
pEnc->mbParam.m_rounding_type = 1; |
1513 |
pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type; |
pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type; |
1514 |
|
pEnc->current->quarterpel = pEnc->mbParam.m_quarterpel; |
1515 |
pEnc->current->coding_type = I_VOP; |
pEnc->current->coding_type = I_VOP; |
1516 |
|
|
1517 |
BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current); |
BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current); |
1521 |
BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P)); |
BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P)); |
1522 |
} |
} |
1523 |
|
|
1524 |
|
#define XVID_ID "XviD" XVID_BS_VERSION |
1525 |
|
BitstreamWriteUserData(bs, XVID_ID, strlen(XVID_ID)); |
1526 |
|
|
1527 |
set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); |
set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); |
1528 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1); |
1529 |
|
|
1591 |
int iLimit; |
int iLimit; |
1592 |
int x, y, k; |
int x, y, k; |
1593 |
int iSearchRange; |
int iSearchRange; |
1594 |
int bIntra; |
int bIntra, skip_possible; |
1595 |
|
|
1596 |
/* IMAGE *pCurrent = &pEnc->current->image; */ |
/* IMAGE *pCurrent = &pEnc->current->image; */ |
1597 |
IMAGE *pRef = &pEnc->reference->image; |
IMAGE *pRef = &pEnc->reference->image; |
1603 |
|
|
1604 |
pEnc->mbParam.m_rounding_type = 1 - pEnc->mbParam.m_rounding_type; |
pEnc->mbParam.m_rounding_type = 1 - pEnc->mbParam.m_rounding_type; |
1605 |
pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type; |
pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type; |
1606 |
|
pEnc->current->quarterpel = pEnc->mbParam.m_quarterpel; |
1607 |
pEnc->current->fcode = pEnc->mbParam.m_fcode; |
pEnc->current->fcode = pEnc->mbParam.m_fcode; |
1608 |
|
|
1609 |
if (!force_inter) |
if (!force_inter) |
1618 |
image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV, |
image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV, |
1619 |
&pEnc->vInterHV, pEnc->mbParam.edged_width, |
&pEnc->vInterHV, pEnc->mbParam.edged_width, |
1620 |
pEnc->mbParam.edged_height, |
pEnc->mbParam.edged_height, |
1621 |
|
pEnc->mbParam.m_quarterpel, |
1622 |
pEnc->current->rounding_type); |
pEnc->current->rounding_type); |
1623 |
stop_inter_timer(); |
stop_inter_timer(); |
1624 |
} |
} |
1625 |
|
|
1626 |
|
if (pEnc->current->global_flags & XVID_GMC) { |
1627 |
|
// printf("Global Motion = %d %d quarterpel=%d\n", pEnc->current->GMC_MV.x, pEnc->current->GMC_MV.y,pEnc->current->quarterpel); |
1628 |
|
DPRINTF(DPRINTF_HEADER, "Global Motion = %d %d quarterpel=%d\n", pEnc->current->GMC_MV.x, pEnc->current->GMC_MV.y,pEnc->current->quarterpel); |
1629 |
|
pEnc->current->coding_type = S_VOP; |
1630 |
|
} else |
1631 |
|
pEnc->current->coding_type = P_VOP; |
1632 |
|
|
1633 |
start_timer(); |
start_timer(); |
1634 |
if (pEnc->current->global_flags & XVID_HINTEDME_SET) { |
if (pEnc->current->global_flags & XVID_HINTEDME_SET) { |
1635 |
HintedMESet(pEnc, &bIntra); |
HintedMESet(pEnc, &bIntra); |
1636 |
if (bIntra == 0) MotionEstimationHinted(&pEnc->mbParam, pEnc->current, pEnc->reference, |
if (bIntra == 0) { |
1637 |
|
pEnc->current->fcode = FindFcode(&pEnc->mbParam, pEnc->current); |
1638 |
|
MotionEstimationHinted(&pEnc->mbParam, pEnc->current, pEnc->reference, |
1639 |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV); |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV); |
1640 |
|
} |
1641 |
|
|
1642 |
} else { |
} else { |
1643 |
|
|
1645 |
MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference, |
MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference, |
1646 |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
1647 |
iLimit); |
iLimit); |
|
|
|
1648 |
} |
} |
1649 |
stop_motion_timer(); |
stop_motion_timer(); |
1650 |
|
|
1651 |
if (bIntra == 1) return FrameCodeI(pEnc, bs, pBits); |
if (bIntra == 1) return FrameCodeI(pEnc, bs, pBits); |
1652 |
|
|
1653 |
pEnc->current->coding_type = P_VOP; |
if ( (pEnc->current->GMC_MV.x == 0) && (pEnc->current->GMC_MV.y == 0) ) |
1654 |
|
pEnc->current->coding_type = P_VOP; /* no global motion -> no GMC */ |
1655 |
|
|
1656 |
|
|
1657 |
if (vol_header) |
if (vol_header) |
1658 |
BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current); |
BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current); |
1681 |
dct_codes, pEnc->mbParam.width, |
dct_codes, pEnc->mbParam.width, |
1682 |
pEnc->mbParam.height, |
pEnc->mbParam.height, |
1683 |
pEnc->mbParam.edged_width, |
pEnc->mbParam.edged_width, |
1684 |
|
pEnc->mbParam.m_quarterpel, |
1685 |
pEnc->current->rounding_type); |
pEnc->current->rounding_type); |
1686 |
stop_comp_timer(); |
stop_comp_timer(); |
1687 |
|
|
1727 |
|
|
1728 |
/* Finished processing the MB, now check if to CODE or SKIP */ |
/* Finished processing the MB, now check if to CODE or SKIP */ |
1729 |
|
|
1730 |
if ((pMB->mode == MODE_NOT_CODED) || |
skip_possible = (pMB->cbp == 0) & (pMB->mode == MODE_INTER) & |
1731 |
(pMB->cbp == 0 && pMB->mode == MODE_INTER && pMB->mvs[0].x == 0 && |
(pMB->dquant == NO_CHANGE); |
1732 |
pMB->mvs[0].y == 0 && pMB->dquant == NO_CHANGE)) { |
|
1733 |
|
if(pEnc->mbParam.m_quarterpel) |
1734 |
|
{ skip_possible &= (pMB->qmvs[0].x == pEnc->current->GMC_MV.x) & (pMB->qmvs[0].y == pEnc->current->GMC_MV.y); |
1735 |
|
} |
1736 |
|
else |
1737 |
|
{ skip_possible &= (pMB->mvs[0].x == pEnc->current->GMC_MV.x) & (pMB->mvs[0].y == pEnc->current->GMC_MV.y); |
1738 |
|
} |
1739 |
|
|
1740 |
/* This is a candidate for SKIPping, but check intermediate B-frames first */ |
if ( (pMB->mode == MODE_NOT_CODED) || (skip_possible)) { |
1741 |
|
|
1742 |
|
/* This is a candidate for SKIPping, but for P-VOPs check intermediate B-frames first */ |
1743 |
int bSkip = 1; |
int bSkip = 1; |
|
pMB->mode = MODE_NOT_CODED; |
|
1744 |
|
|
1745 |
|
if (pEnc->current->coding_type == P_VOP) /* special rule for P-VOP's SKIP */ |
1746 |
for (k=pEnc->bframenum_head; k< pEnc->bframenum_tail; k++) |
for (k=pEnc->bframenum_head; k< pEnc->bframenum_tail; k++) |
1747 |
{ |
{ |
1748 |
int iSAD; |
int iSAD; |
1754 |
break; |
break; |
1755 |
} |
} |
1756 |
} |
} |
1757 |
|
|
1758 |
if (!bSkip) |
if (!bSkip) |
1759 |
{ |
{ |
1760 |
VECTOR predMV; |
VECTOR predMV; |
1761 |
|
if(pEnc->mbParam.m_quarterpel) { |
1762 |
|
predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0); |
1763 |
|
pMB->pmvs[0].x = pMB->qmvs[0].x - predMV.x; /* with GMC, qmvs doesn't have to be (0,0)! */ |
1764 |
|
pMB->pmvs[0].y = pMB->qmvs[0].y - predMV.y; |
1765 |
|
} |
1766 |
|
else { |
1767 |
predMV = get_pmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0); |
predMV = get_pmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0); |
1768 |
pMB->pmvs[0].x = -predMV.x; pMB->pmvs[0].y = -predMV.y; |
pMB->pmvs[0].x = pMB->mvs[0].x - predMV.x; /* with GMC, mvs doesn't have to be (0,0)! */ |
1769 |
|
pMB->pmvs[0].y = pMB->mvs[0].y - predMV.y; |
1770 |
|
} |
1771 |
pMB->mode = MODE_INTER; |
pMB->mode = MODE_INTER; |
1772 |
pMB->cbp = 0; |
pMB->cbp = 0; |
1773 |
MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat); |
MBCoding(pEnc->current, pMB, qcoeff, bs, &pEnc->sStat); |
1774 |
} |
} |
1775 |
else MBSkip(bs); |
else |
1776 |
|
{ |
1777 |
|
pMB->mode = MODE_NOT_CODED; |
1778 |
|
MBSkip(bs); |
1779 |
|
} |
1780 |
|
|
1781 |
} else { |
} else { |
1782 |
if (pEnc->current->global_flags & XVID_GREYSCALE) |
if (pEnc->current->global_flags & XVID_GREYSCALE) |
1805 |
iSearchRange = 1 << (3 + pEnc->mbParam.m_fcode); |
iSearchRange = 1 << (3 + pEnc->mbParam.m_fcode); |
1806 |
|
|
1807 |
if ((fSigma > iSearchRange / 3) |
if ((fSigma > iSearchRange / 3) |
1808 |
&& (pEnc->mbParam.m_fcode <= 3)) // maximum search range 128 |
&& (pEnc->mbParam.m_fcode <= (3 + pEnc->mbParam.m_quarterpel))) // maximum search range 128 |
1809 |
{ |
{ |
1810 |
pEnc->mbParam.m_fcode++; |
pEnc->mbParam.m_fcode++; |
1811 |
iSearchRange *= 2; |
iSearchRange *= 2; |
1812 |
} else if ((fSigma < iSearchRange / 6) |
} else if ((fSigma < iSearchRange / 6) |
1813 |
&& (pEnc->sStat.fMvPrevSigma >= 0) |
&& (pEnc->sStat.fMvPrevSigma >= 0) |
1814 |
&& (pEnc->sStat.fMvPrevSigma < iSearchRange / 6) |
&& (pEnc->sStat.fMvPrevSigma < iSearchRange / 6) |
1815 |
&& (pEnc->mbParam.m_fcode >= 2)) // minimum search range 16 |
&& (pEnc->mbParam.m_fcode >= (2 + pEnc->mbParam.m_quarterpel))) // minimum search range 16 |
1816 |
{ |
{ |
1817 |
pEnc->mbParam.m_fcode--; |
pEnc->mbParam.m_fcode--; |
1818 |
iSearchRange /= 2; |
iSearchRange /= 2; |
1838 |
pEnc->current->quant = pEnc->reference->quant; |
pEnc->current->quant = pEnc->reference->quant; |
1839 |
pEnc->current->motion_flags = pEnc->reference->motion_flags; |
pEnc->current->motion_flags = pEnc->reference->motion_flags; |
1840 |
pEnc->current->rounding_type = pEnc->reference->rounding_type; |
pEnc->current->rounding_type = pEnc->reference->rounding_type; |
1841 |
|
pEnc->current->quarterpel = pEnc->reference->quarterpel; |
1842 |
pEnc->current->fcode = pEnc->reference->fcode; |
pEnc->current->fcode = pEnc->reference->fcode; |
1843 |
pEnc->current->bcode = pEnc->reference->bcode; |
pEnc->current->bcode = pEnc->reference->bcode; |
1844 |
image_copy(&pEnc->current->image, &pEnc->reference->image, pEnc->mbParam.edged_width, pEnc->mbParam.height); |
image_copy(&pEnc->current->image, &pEnc->reference->image, pEnc->mbParam.edged_width, pEnc->mbParam.height); |
1878 |
} |
} |
1879 |
#endif |
#endif |
1880 |
|
|
1881 |
|
frame->quarterpel = pEnc->mbParam.m_quarterpel; |
1882 |
|
|
1883 |
// forward |
// forward |
1884 |
image_setedges(f_ref, pEnc->mbParam.edged_width, |
image_setedges(f_ref, pEnc->mbParam.edged_width, |
1885 |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
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 |
0); |
pEnc->mbParam.m_quarterpel, 0); |
1891 |
stop_inter_timer(); |
stop_inter_timer(); |
1892 |
|
|
1893 |
// backward |
// backward |
1897 |
start_timer(); |
start_timer(); |
1898 |
image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
1899 |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
1900 |
0); |
pEnc->mbParam.m_quarterpel, 0); |
1901 |
stop_inter_timer(); |
stop_inter_timer(); |
1902 |
|
|
1903 |
start_timer(); |
start_timer(); |