3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Encoder main module - |
* - Encoder main module - |
5 |
* |
* |
6 |
* This program is an implementation of a part of one or more MPEG-4 |
* Copyright(C) 2002 Michael Militzer <isibaar@xvid.org> |
7 |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
* 2002-2003 Peter Ross <pross@xvid.org> |
8 |
* to use this software module in hardware or software products are |
* 2002 Daniel Smith <danielsmith@astroboymail.com> |
|
* advised that its use may infringe existing patents or copyrights, and |
|
|
* any such use would be at such party's own risk. The original |
|
|
* developer of this software module and his/her company, and subsequent |
|
|
* editors and their companies, will have no liability for use of this |
|
|
* software or modifications or derivatives thereof. |
|
9 |
* |
* |
10 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
11 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
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.23 2003-05-16 17:16:21 suxen_drol Exp $ |
* $Id: encoder.c,v 1.95.2.29 2003-06-11 12:37:41 suxen_drol Exp $ |
25 |
* |
* |
26 |
****************************************************************************/ |
****************************************************************************/ |
27 |
|
|
44 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
45 |
#include "utils/emms.h" |
#include "utils/emms.h" |
46 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
|
#include "quant/adapt_quant.h" |
|
47 |
#include "quant/quant_matrix.h" |
#include "quant/quant_matrix.h" |
48 |
#include "utils/mem_align.h" |
#include "utils/mem_align.h" |
49 |
|
|
205 |
if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) { |
206 |
pEnc->temp_dquants = (int *) xvid_malloc(pEnc->mbParam.mb_width * |
pEnc->temp_dquants = (int *) xvid_malloc(pEnc->mbParam.mb_width * |
207 |
pEnc->mbParam.mb_height * sizeof(int), CACHE_LINE); |
pEnc->mbParam.mb_height * sizeof(int), CACHE_LINE); |
208 |
|
if (pEnc->temp_dquants==NULL) |
209 |
|
goto xvid_err_memory1a; |
210 |
} |
} |
|
/* XXX: error checking */ |
|
211 |
|
|
212 |
/* bframes */ |
/* bframes */ |
213 |
pEnc->mbParam.max_bframes = MAX(create->max_bframes, 0); |
pEnc->mbParam.max_bframes = MAX(create->max_bframes, 0); |
225 |
|
|
226 |
/* max keyframe interval */ |
/* max keyframe interval */ |
227 |
pEnc->mbParam.iMaxKeyInterval = create->max_key_interval <= 0 ? |
pEnc->mbParam.iMaxKeyInterval = create->max_key_interval <= 0 ? |
228 |
10 * pEnc->mbParam.fbase / pEnc->mbParam.fincr : create->max_key_interval; |
(10 * pEnc->mbParam.fbase) / pEnc->mbParam.fincr : create->max_key_interval; |
|
|
|
|
/* Bitrate allocator defaults |
|
|
|
|
|
if ((create->min_quantizer <= 0) || (create->min_quantizer > 31)) |
|
|
create->min_quantizer = 1; |
|
|
|
|
|
if ((create->max_quantizer <= 0) || (create->max_quantizer > 31)) |
|
|
create->max_quantizer = 31; |
|
|
|
|
|
if (create->max_quantizer < create->min_quantizer) |
|
|
create->max_quantizer = create->min_quantizer; */ |
|
|
|
|
229 |
|
|
230 |
/* allocate working frame-image memory */ |
/* allocate working frame-image memory */ |
231 |
|
|
498 |
xvid_free(pEnc->current); |
xvid_free(pEnc->current); |
499 |
xvid_free(pEnc->reference); |
xvid_free(pEnc->reference); |
500 |
|
|
501 |
|
xvid_err_memory1a: |
502 |
if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) { |
503 |
xvid_free(pEnc->temp_dquants); |
xvid_free(pEnc->temp_dquants); |
504 |
} |
} |
696 |
memset(data.dquant, 0, data.mb_width*data.mb_height); |
memset(data.dquant, 0, data.mb_width*data.mb_height); |
697 |
} |
} |
698 |
|
|
699 |
/* todo: [vol,vop,motion]_flags*/ |
data.vol_flags = frame->vol_flags; |
700 |
|
data.vop_flags = frame->vop_flags; |
701 |
|
data.motion_flags = frame->motion_flags; |
702 |
|
|
703 |
} else { // XVID_PLG_AFTER |
} else { /* XVID_PLG_AFTER */ |
704 |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
705 |
data.original.csp = XVID_CSP_USER; |
data.original.csp = XVID_CSP_USER; |
706 |
data.original.plane[0] = original->y; |
data.original.plane[0] = original->y; |
795 |
frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0; |
frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0; |
796 |
} |
} |
797 |
} |
} |
798 |
/* todo: [vol,vop,motion]_flags*/ |
|
799 |
|
frame->vol_flags = data.vol_flags; |
800 |
|
frame->vop_flags = data.vop_flags; |
801 |
|
frame->motion_flags = data.motion_flags; |
802 |
} |
} |
803 |
} |
} |
804 |
|
|
927 |
{ |
{ |
928 |
if (pEnc->bframenum_head < pEnc->bframenum_tail) { |
if (pEnc->bframenum_head < pEnc->bframenum_tail) { |
929 |
|
|
930 |
DPRINTF(DPRINTF_DEBUG,"*** BFRAME (flush) bf: head=%i tail=%i queue: head=%i tail=%i size=%i", |
DPRINTF(XVID_DEBUG_DEBUG,"*** BFRAME (flush) bf: head=%i tail=%i queue: head=%i tail=%i size=%i\n", |
931 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
932 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
933 |
|
|
954 |
int tmp; |
int tmp; |
955 |
int bits; |
int bits; |
956 |
|
|
957 |
DPRINTF(DPRINTF_DEBUG,"*** EMPTY bf: head=%i tail=%i queue: head=%i tail=%i size=%i", |
DPRINTF(XVID_DEBUG_DEBUG,"*** EMPTY bf: head=%i tail=%i queue: head=%i tail=%i size=%i\n", |
958 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
959 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
960 |
|
|
992 |
if (xFrame->input.csp == XVID_CSP_NULL) /* no futher input */ |
if (xFrame->input.csp == XVID_CSP_NULL) /* no futher input */ |
993 |
{ |
{ |
994 |
|
|
995 |
|
DPRINTF(XVID_DEBUG_DEBUG,"*** FINISH bf: head=%i tail=%i queue: head=%i tail=%i size=%i\n", |
996 |
|
pEnc->bframenum_head, pEnc->bframenum_tail, |
997 |
|
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
998 |
|
|
999 |
if (!(pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->mbParam.max_bframes > 0) { |
if (!(pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->mbParam.max_bframes > 0) { |
1000 |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
1001 |
} |
} |
1002 |
|
|
1003 |
/* if the very last frame is to be b-vop, we must change it to a p-vop */ |
/* if the very last frame is to be b-vop, we must change it to a p-vop */ |
1004 |
if (pEnc->bframenum_tail > 0) |
if (pEnc->bframenum_tail > 0) { |
|
{ |
|
1005 |
|
|
1006 |
SWAP(FRAMEINFO*, pEnc->current, pEnc->reference); |
SWAP(FRAMEINFO*, pEnc->current, pEnc->reference); |
1007 |
pEnc->bframenum_tail--; |
pEnc->bframenum_tail--; |
1015 |
pEnc->mbParam.edged_width, pEnc->mbParam.height); |
pEnc->mbParam.edged_width, pEnc->mbParam.height); |
1016 |
} |
} |
1017 |
|
|
1018 |
|
DPRINTF(XVID_DEBUG_DEBUG,"*** PFRAME bf: head=%i tail=%i queue: head=%i tail=%i size=%i\n", |
1019 |
|
pEnc->bframenum_head, pEnc->bframenum_tail, |
1020 |
|
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
1021 |
|
|
1022 |
FrameCodeP(pEnc, &bs, 1, 0); |
FrameCodeP(pEnc, &bs, 1, 0); |
1023 |
|
|
1024 |
goto done_flush; |
|
1025 |
|
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail==0) { |
1026 |
|
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
1027 |
|
}else{ |
1028 |
|
pEnc->flush_bframes = 1; |
1029 |
|
goto done; |
1030 |
|
} |
1031 |
} |
} |
1032 |
|
DPRINTF(XVID_DEBUG_DEBUG, "*** END\n"); |
1033 |
|
|
1034 |
emms(); |
emms(); |
1035 |
return XVID_ERR_END; /* end of stream reached */ |
return XVID_ERR_END; /* end of stream reached */ |
1037 |
goto done; /* nothing to encode yet; encoder lag */ |
goto done; /* nothing to encode yet; encoder lag */ |
1038 |
} |
} |
1039 |
|
|
1040 |
// the current FRAME becomes the reference |
/* the current FRAME becomes the reference */ |
1041 |
SWAP(FRAMEINFO*, pEnc->current, pEnc->reference); |
SWAP(FRAMEINFO*, pEnc->current, pEnc->reference); |
1042 |
|
|
1043 |
// remove frame from encoding-queue (head), and move it into the current |
/* remove frame from encoding-queue (head), and move it into the current */ |
1044 |
image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head].image); |
image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head].image); |
1045 |
frame = &pEnc->queue[pEnc->queue_head].frame; |
frame = &pEnc->queue[pEnc->queue_head].frame; |
1046 |
pEnc->queue_head = (pEnc->queue_head + 1) % (pEnc->mbParam.max_bframes+1); |
pEnc->queue_head = (pEnc->queue_head + 1) % (pEnc->mbParam.max_bframes+1); |
1069 |
* frame type & quant selection |
* frame type & quant selection |
1070 |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
1071 |
|
|
|
call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_BEFORE, &type, &pEnc->current->quant, stats); |
|
|
|
|
|
if (frame->type > 0) |
|
1072 |
type = frame->type; |
type = frame->type; |
|
|
|
|
if (frame->quant > 0) |
|
1073 |
pEnc->current->quant = frame->quant; |
pEnc->current->quant = frame->quant; |
1074 |
|
|
1075 |
|
call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_BEFORE, &type, &pEnc->current->quant, stats); |
1076 |
|
|
1077 |
if (type > 0){ /* XVID_TYPE_?VOP */ |
if (type > 0){ /* XVID_TYPE_?VOP */ |
1078 |
type = type2coding(type); /* convert XVID_TYPE_?VOP to bitstream coding type */ |
type = type2coding(type); /* convert XVID_TYPE_?VOP to bitstream coding type */ |
1079 |
} else{ /* XVID_TYPE_AUTO */ |
} else{ /* XVID_TYPE_AUTO */ |
1121 |
else if (pEnc->current->quant > 31) |
else if (pEnc->current->quant > 31) |
1122 |
pEnc->current->quant = 31; |
pEnc->current->quant = 31; |
1123 |
|
|
1124 |
DPRINTF(DPRINTF_DEBUG,"*** BFRAME (store) bf: head=%i tail=%i queue: head=%i tail=%i size=%i quant=%i", |
DPRINTF(XVID_DEBUG_DEBUG,"*** BFRAME (store) bf: head=%i tail=%i queue: head=%i tail=%i size=%i quant=%i\n", |
1125 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
1126 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size,pEnc->current->quant); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size,pEnc->current->quant); |
1127 |
|
|
1134 |
goto repeat; |
goto repeat; |
1135 |
} |
} |
1136 |
|
|
1137 |
|
|
1138 |
|
DPRINTF(XVID_DEBUG_DEBUG,"*** XXXXXX bf: head=%i tail=%i queue: head=%i tail=%i size=%i\n", |
1139 |
|
pEnc->bframenum_head, pEnc->bframenum_tail, |
1140 |
|
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
1141 |
|
|
1142 |
/* for unpacked bframes, output the stats for the last encoded frame */ |
/* for unpacked bframes, output the stats for the last encoded frame */ |
1143 |
if (!(pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) |
if (!(pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->mbParam.max_bframes > 0) |
1144 |
{ |
{ |
1145 |
if (pEnc->current->stamp > 0) { |
if (pEnc->current->stamp > 0) { |
1146 |
call_plugins(pEnc, pEnc->reference, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
call_plugins(pEnc, pEnc->reference, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
1156 |
|
|
1157 |
if (type == I_VOP && (pEnc->mbParam.global_flags & XVID_GLOBAL_CLOSED_GOP) && pEnc->bframenum_tail > 0) { |
if (type == I_VOP && (pEnc->mbParam.global_flags & XVID_GLOBAL_CLOSED_GOP) && pEnc->bframenum_tail > 0) { |
1158 |
|
|
1159 |
// place this frame back on the encoding-queue (head) |
/* place this frame back on the encoding-queue (head) */ |
1160 |
// we will deal with it next time |
/* we will deal with it next time */ |
1161 |
dec_frame_num(pEnc); |
dec_frame_num(pEnc); |
1162 |
pEnc->iFrameNum--; |
pEnc->iFrameNum--; |
1163 |
|
|
1165 |
pEnc->queue_size++; |
pEnc->queue_size++; |
1166 |
image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head].image); |
image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head].image); |
1167 |
|
|
1168 |
// grab the last frame from the bframe-queue |
/* grab the last frame from the bframe-queue */ |
1169 |
|
|
1170 |
pEnc->bframenum_tail--; |
pEnc->bframenum_tail--; |
1171 |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
1186 |
|
|
1187 |
if (type == I_VOP) { |
if (type == I_VOP) { |
1188 |
|
|
1189 |
DPRINTF(DPRINTF_DEBUG,"*** IFRAME bf: head=%i tail=%i queue: head=%i tail=%i size=%i", |
DPRINTF(XVID_DEBUG_DEBUG,"*** IFRAME bf: head=%i tail=%i queue: head=%i tail=%i size=%i\n", |
1190 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
1191 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
1192 |
|
|
1227 |
* encode this frame as an p-vop |
* encode this frame as an p-vop |
1228 |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
1229 |
|
|
1230 |
} else { // (type == P_VOP || type == S_VOP) |
} else { /* (type == P_VOP || type == S_VOP) */ |
1231 |
|
|
1232 |
DPRINTF(DPRINTF_DEBUG,"*** PFRAME bf: head=%i tail=%i queue: head=%i tail=%i size=%i", |
DPRINTF(XVID_DEBUG_DEBUG,"*** PFRAME bf: head=%i tail=%i queue: head=%i tail=%i size=%i\n", |
1233 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
1234 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
1235 |
|
|
1254 |
|
|
1255 |
pEnc->flush_bframes = 1; |
pEnc->flush_bframes = 1; |
1256 |
|
|
1257 |
/* packed & queued_bframes: dont bother outputting stats, we do so after the flush */ |
/* packed & queued_bframes: dont bother outputting stats here, we do so after the flush */ |
1258 |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) { |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail > 0) { |
1259 |
goto repeat; |
goto repeat; |
1260 |
} |
} |
1261 |
|
|
1262 |
/* packed or no-bframes: output stats */ |
/* packed or no-bframes or no-bframes-queued: output stats */ |
1263 |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) || pEnc->mbParam.max_bframes == 0) { |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) || pEnc->mbParam.max_bframes == 0) { |
1264 |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
1265 |
} |
} |
1407 |
pEnc->fMvPrevSigma = -1; |
pEnc->fMvPrevSigma = -1; |
1408 |
pEnc->mbParam.m_fcode = 2; |
pEnc->mbParam.m_fcode = 2; |
1409 |
|
|
|
/* XXX: hinted me |
|
|
if (pEnc->current->global_flags & XVID_HINTEDME_GET) { |
|
|
HintedMEGet(pEnc, 1); |
|
|
}*/ |
|
|
|
|
1410 |
return 1; /* intra */ |
return 1; /* intra */ |
1411 |
} |
} |
1412 |
|
|
1453 |
|
|
1454 |
pEnc->mbParam.m_rounding_type = 1 - pEnc->mbParam.m_rounding_type; |
pEnc->mbParam.m_rounding_type = 1 - pEnc->mbParam.m_rounding_type; |
1455 |
pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type; |
pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type; |
|
//pEnc->current->quarterpel = pEnc->mbParam.m_quarterpel; |
|
1456 |
pEnc->current->fcode = pEnc->mbParam.m_fcode; |
pEnc->current->fcode = pEnc->mbParam.m_fcode; |
1457 |
|
|
1458 |
if (!force_inter) |
if (!force_inter) |
1476 |
SetMacroblockQuants(&pEnc->mbParam, pEnc->current); |
SetMacroblockQuants(&pEnc->mbParam, pEnc->current); |
1477 |
|
|
1478 |
start_timer(); |
start_timer(); |
1479 |
/*if (pEnc->current->global_flags & XVID_HINTEDME_SET) |
bIntra = MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference, |
|
HintedMESet(pEnc, &bIntra); |
|
|
else*/ |
|
|
bIntra = |
|
|
MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference, |
|
1480 |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
1481 |
iLimit); |
iLimit); |
1482 |
|
|
1678 |
VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0); |
VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0); |
1679 |
pMB->pmvs[0].x = pMB->qmvs[0].x - predMV.x; |
pMB->pmvs[0].x = pMB->qmvs[0].x - predMV.x; |
1680 |
pMB->pmvs[0].y = pMB->qmvs[0].y - predMV.y; |
pMB->pmvs[0].y = pMB->qmvs[0].y - predMV.y; |
1681 |
DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)", pMB->pmvs[0].x, pMB->pmvs[0].y, predMV.x, predMV.y, pMB->mvs[0].x, pMB->mvs[0].y); |
DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", pMB->pmvs[0].x, pMB->pmvs[0].y, predMV.x, predMV.y, pMB->mvs[0].x, pMB->mvs[0].y); |
1682 |
} else { |
} else { |
1683 |
VECTOR predMV = get_pmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0); |
VECTOR predMV = get_pmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, 0); |
1684 |
pMB->pmvs[0].x = pMB->mvs[0].x - predMV.x; |
pMB->pmvs[0].x = pMB->mvs[0].x - predMV.x; |
1685 |
pMB->pmvs[0].y = pMB->mvs[0].y - predMV.y; |
pMB->pmvs[0].y = pMB->mvs[0].y - predMV.y; |
1686 |
DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)", pMB->pmvs[0].x, pMB->pmvs[0].y, predMV.x, predMV.y, pMB->mvs[0].x, pMB->mvs[0].y); |
DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", pMB->pmvs[0].x, pMB->pmvs[0].y, predMV.x, predMV.y, pMB->mvs[0].x, pMB->mvs[0].y); |
1687 |
} |
} |
1688 |
|
|
1689 |
|
|
1695 |
VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, k); |
VECTOR predMV = get_qpmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, k); |
1696 |
pMB->pmvs[k].x = pMB->qmvs[k].x - predMV.x; |
pMB->pmvs[k].x = pMB->qmvs[k].x - predMV.x; |
1697 |
pMB->pmvs[k].y = pMB->qmvs[k].y - predMV.y; |
pMB->pmvs[k].y = pMB->qmvs[k].y - predMV.y; |
1698 |
DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)", pMB->pmvs[k].x, pMB->pmvs[k].y, predMV.x, predMV.y, pMB->mvs[k].x, pMB->mvs[k].y); |
DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", pMB->pmvs[k].x, pMB->pmvs[k].y, predMV.x, predMV.y, pMB->mvs[k].x, pMB->mvs[k].y); |
1699 |
} else { |
} else { |
1700 |
VECTOR predMV = get_pmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, k); |
VECTOR predMV = get_pmv2(pEnc->current->mbs, pEnc->mbParam.mb_width, 0, x, y, k); |
1701 |
pMB->pmvs[k].x = pMB->mvs[k].x - predMV.x; |
pMB->pmvs[k].x = pMB->mvs[k].x - predMV.x; |
1702 |
pMB->pmvs[k].y = pMB->mvs[k].y - predMV.y; |
pMB->pmvs[k].y = pMB->mvs[k].y - predMV.y; |
1703 |
DPRINTF(DPRINTF_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)", pMB->pmvs[k].x, pMB->pmvs[k].y, predMV.x, predMV.y, pMB->mvs[k].x, pMB->mvs[k].y); |
DPRINTF(XVID_DEBUG_MV,"mv_diff (%i,%i) pred (%i,%i) result (%i,%i)\n", pMB->pmvs[k].x, pMB->pmvs[k].y, predMV.x, predMV.y, pMB->mvs[k].x, pMB->mvs[k].y); |
1704 |
} |
} |
1705 |
|
|
1706 |
} |
} |
1721 |
|
|
1722 |
emms(); |
emms(); |
1723 |
|
|
|
/* XXX: hinted me |
|
|
if (pEnc->current->global_flags & XVID_HINTEDME_GET) { |
|
|
HintedMEGet(pEnc, 0); |
|
|
}*/ |
|
|
|
|
1724 |
if (pEnc->current->sStat.iMvCount == 0) |
if (pEnc->current->sStat.iMvCount == 0) |
1725 |
pEnc->current->sStat.iMvCount = 1; |
pEnc->current->sStat.iMvCount = 1; |
1726 |
|
|
1745 |
pEnc->fMvPrevSigma = fSigma; |
pEnc->fMvPrevSigma = fSigma; |
1746 |
|
|
1747 |
/* frame drop code */ |
/* frame drop code */ |
1748 |
DPRINTF(DPRINTF_DEBUG, "kmu %i %i %i", pEnc->current->sStat.kblks, pEnc->current->sStat.mblks, pEnc->current->sStat.ublks); |
#if 0 |
1749 |
|
DPRINTF(XVID_DEBUG_DEBUG, "kmu %i %i %i\n", pEnc->current->sStat.kblks, pEnc->current->sStat.mblks, pEnc->current->sStat.ublks); |
1750 |
|
#endif |
1751 |
if (pEnc->current->sStat.kblks + pEnc->current->sStat.mblks < |
if (pEnc->current->sStat.kblks + pEnc->current->sStat.mblks < |
1752 |
(pEnc->mbParam.frame_drop_ratio * mb_width * mb_height) / 100) |
(pEnc->mbParam.frame_drop_ratio * mb_width * mb_height) / 100) |
1753 |
{ |
{ |
1763 |
pEnc->current->quant = pEnc->reference->quant; |
pEnc->current->quant = pEnc->reference->quant; |
1764 |
pEnc->current->motion_flags = pEnc->reference->motion_flags; |
pEnc->current->motion_flags = pEnc->reference->motion_flags; |
1765 |
pEnc->current->rounding_type = pEnc->reference->rounding_type; |
pEnc->current->rounding_type = pEnc->reference->rounding_type; |
|
//pEnc->current->quarterpel = pEnc->reference->quarterpel; |
|
1766 |
pEnc->current->fcode = pEnc->reference->fcode; |
pEnc->current->fcode = pEnc->reference->fcode; |
1767 |
pEnc->current->bcode = pEnc->reference->bcode; |
pEnc->current->bcode = pEnc->reference->bcode; |
1768 |
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); |
1828 |
} |
} |
1829 |
#endif |
#endif |
1830 |
|
|
|
//frame->quarterpel = pEnc->mbParam.m_quarterpel; |
|
|
|
|
1831 |
/* forward */ |
/* forward */ |
1832 |
image_setedges(f_ref, pEnc->mbParam.edged_width, |
image_setedges(f_ref, pEnc->mbParam.edged_width, |
1833 |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
1849 |
stop_inter_timer(); |
stop_inter_timer(); |
1850 |
|
|
1851 |
start_timer(); |
start_timer(); |
|
|
|
1852 |
MotionEstimationBVOP(&pEnc->mbParam, frame, |
MotionEstimationBVOP(&pEnc->mbParam, frame, |
1853 |
((int32_t)(pEnc->current->stamp - frame->stamp)), /* time_bp */ |
((int32_t)(pEnc->current->stamp - frame->stamp)), /* time_bp */ |
1854 |
((int32_t)(pEnc->current->stamp - pEnc->reference->stamp)), /* time_pp */ |
((int32_t)(pEnc->current->stamp - pEnc->reference->stamp)), /* time_pp */ |
1856 |
&pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv, |
&pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv, |
1857 |
pEnc->current, b_ref, &pEnc->vInterH, |
pEnc->current, b_ref, &pEnc->vInterH, |
1858 |
&pEnc->vInterV, &pEnc->vInterHV); |
&pEnc->vInterV, &pEnc->vInterHV); |
|
|
|
|
|
|
1859 |
stop_motion_timer(); |
stop_motion_timer(); |
1860 |
|
|
|
/* |
|
|
if (test_quant_type(&pEnc->mbParam, pEnc->current)) { |
|
|
BitstreamWriteVolHeader(bs, pEnc->mbParam.width, pEnc->mbParam.height, pEnc->mbParam.quant_type); |
|
|
} |
|
|
*/ |
|
|
|
|
1861 |
frame->coding_type = B_VOP; |
frame->coding_type = B_VOP; |
1862 |
|
|
1863 |
set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase); |
set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase); |