49 |
#include "quant/quant_matrix.h" |
#include "quant/quant_matrix.h" |
50 |
#include "utils/mem_align.h" |
#include "utils/mem_align.h" |
51 |
|
|
52 |
|
# include "motion/motion_smp.h" |
53 |
|
|
54 |
|
|
55 |
/***************************************************************************** |
/***************************************************************************** |
56 |
* Local function prototypes |
* Local function prototypes |
57 |
****************************************************************************/ |
****************************************************************************/ |
206 |
|
|
207 |
memset(&pinfo, 0, sizeof(xvid_plg_info_t)); |
memset(&pinfo, 0, sizeof(xvid_plg_info_t)); |
208 |
pinfo.version = XVID_VERSION; |
pinfo.version = XVID_VERSION; |
209 |
if (create->plugins[n].func(0, XVID_PLG_INFO, &pinfo, 0) >= 0) { |
if (create->plugins[n].func(NULL, XVID_PLG_INFO, &pinfo, NULL) >= 0) { |
210 |
pEnc->mbParam.plugin_flags |= pinfo.flags; |
pEnc->mbParam.plugin_flags |= pinfo.flags; |
211 |
} |
} |
212 |
|
|
223 |
pcreate.param = create->plugins[n].param; |
pcreate.param = create->plugins[n].param; |
224 |
|
|
225 |
pEnc->plugins[n].func = NULL; /* disable plugins that fail */ |
pEnc->plugins[n].func = NULL; /* disable plugins that fail */ |
226 |
if (create->plugins[n].func(0, XVID_PLG_CREATE, &pcreate, &pEnc->plugins[n].param) >= 0) { |
if (create->plugins[n].func(NULL, XVID_PLG_CREATE, &pcreate, &pEnc->plugins[n].param) >= 0) { |
227 |
pEnc->plugins[n].func = create->plugins[n].func; |
pEnc->plugins[n].func = create->plugins[n].func; |
228 |
} |
} |
229 |
} |
} |
241 |
goto xvid_err_memory1a; |
goto xvid_err_memory1a; |
242 |
} |
} |
243 |
|
|
244 |
|
/* temp lambdas */ |
245 |
|
if (pEnc->mbParam.plugin_flags & XVID_REQLAMBDA) { |
246 |
|
pEnc->temp_lambda = (float *) xvid_malloc(pEnc->mbParam.mb_width * |
247 |
|
pEnc->mbParam.mb_height * 6 * sizeof(float), CACHE_LINE); |
248 |
|
if (pEnc->temp_lambda == NULL) |
249 |
|
goto xvid_err_memory1a; |
250 |
|
} |
251 |
|
|
252 |
/* bframes */ |
/* bframes */ |
253 |
pEnc->mbParam.max_bframes = MAX(create->max_bframes, 0); |
pEnc->mbParam.max_bframes = MAX(create->max_bframes, 0); |
254 |
pEnc->mbParam.bquant_ratio = MAX(create->bquant_ratio, 0); |
pEnc->mbParam.bquant_ratio = MAX(create->bquant_ratio, 0); |
444 |
pEnc->iFrameNum = 0; |
pEnc->iFrameNum = 0; |
445 |
pEnc->fMvPrevSigma = -1; |
pEnc->fMvPrevSigma = -1; |
446 |
|
|
447 |
|
/* multithreaded stuff */ |
448 |
|
if (create->num_threads > 0) { |
449 |
|
int t = create->num_threads; |
450 |
|
int rows_per_thread = (pEnc->mbParam.mb_height+t-1)/t; |
451 |
|
pEnc->num_threads = t; |
452 |
|
pEnc->motionData = xvid_malloc(t*sizeof(SMPmotionData), CACHE_LINE); |
453 |
|
if (!pEnc->motionData) |
454 |
|
goto xvid_err_nosmp; |
455 |
|
|
456 |
|
for (n = 0; n < t; n++) { |
457 |
|
pEnc->motionData[n].complete_count_self = |
458 |
|
xvid_malloc(rows_per_thread * sizeof(int), CACHE_LINE); |
459 |
|
|
460 |
|
if (!pEnc->motionData[n].complete_count_self) |
461 |
|
goto xvid_err_nosmp; |
462 |
|
|
463 |
|
if (n != 0) |
464 |
|
pEnc->motionData[n].complete_count_above = |
465 |
|
pEnc->motionData[n-1].complete_count_self; |
466 |
|
} |
467 |
|
pEnc->motionData[0].complete_count_above = |
468 |
|
pEnc->motionData[t-1].complete_count_self - 1; |
469 |
|
|
470 |
|
} else { |
471 |
|
xvid_err_nosmp: |
472 |
|
/* no SMP */ |
473 |
|
create->num_threads = 0; |
474 |
|
pEnc->motionData = NULL; |
475 |
|
} |
476 |
|
|
477 |
create->handle = (void *) pEnc; |
create->handle = (void *) pEnc; |
478 |
|
|
479 |
init_timer(); |
init_timer(); |
560 |
xvid_free(pEnc->temp_dquants); |
xvid_free(pEnc->temp_dquants); |
561 |
} |
} |
562 |
|
|
563 |
|
if(pEnc->mbParam.plugin_flags & XVID_REQLAMBDA) { |
564 |
|
xvid_free(pEnc->temp_lambda); |
565 |
|
} |
566 |
|
|
567 |
xvid_err_memory0: |
xvid_err_memory0: |
568 |
for (n=0; n<pEnc->num_plugins;n++) { |
for (n=0; n<pEnc->num_plugins;n++) { |
569 |
if (pEnc->plugins[n].func) { |
if (pEnc->plugins[n].func) { |
570 |
pEnc->plugins[n].func(pEnc->plugins[n].param, XVID_PLG_DESTROY, 0, 0); |
pEnc->plugins[n].func(pEnc->plugins[n].param, XVID_PLG_DESTROY, NULL, NULL); |
571 |
} |
} |
572 |
} |
} |
573 |
xvid_free(pEnc->plugins); |
xvid_free(pEnc->plugins); |
672 |
|
|
673 |
for (i=0; i<pEnc->num_plugins;i++) { |
for (i=0; i<pEnc->num_plugins;i++) { |
674 |
if (pEnc->plugins[i].func) { |
if (pEnc->plugins[i].func) { |
675 |
pEnc->plugins[i].func(pEnc->plugins[i].param, XVID_PLG_DESTROY, &pdestroy, 0); |
pEnc->plugins[i].func(pEnc->plugins[i].param, XVID_PLG_DESTROY, &pdestroy, NULL); |
676 |
} |
} |
677 |
} |
} |
678 |
xvid_free(pEnc->plugins); |
xvid_free(pEnc->plugins); |
680 |
|
|
681 |
xvid_free(pEnc->mbParam.mpeg_quant_matrices); |
xvid_free(pEnc->mbParam.mpeg_quant_matrices); |
682 |
|
|
683 |
if (pEnc->num_plugins>0) |
if (pEnc->num_zones > 0) |
684 |
xvid_free(pEnc->zones); |
xvid_free(pEnc->zones); |
685 |
|
|
686 |
|
if (pEnc->num_threads > 0) { |
687 |
|
for (i = 0; i < pEnc->num_threads; i++) |
688 |
|
xvid_free(pEnc->motionData[i].complete_count_self); |
689 |
|
|
690 |
|
xvid_free(pEnc->motionData); |
691 |
|
} |
692 |
|
|
693 |
xvid_free(pEnc); |
xvid_free(pEnc); |
694 |
|
|
695 |
return 0; /* ok */ |
return 0; /* ok */ |
703 |
static void call_plugins(Encoder * pEnc, FRAMEINFO * frame, IMAGE * original, |
static void call_plugins(Encoder * pEnc, FRAMEINFO * frame, IMAGE * original, |
704 |
int opt, int * type, int * quant, xvid_enc_stats_t * stats) |
int opt, int * type, int * quant, xvid_enc_stats_t * stats) |
705 |
{ |
{ |
706 |
unsigned int i, j; |
unsigned int i, j, k; |
707 |
xvid_plg_data_t data; |
xvid_plg_data_t data; |
708 |
|
|
709 |
/* set data struct */ |
/* set data struct */ |
762 |
if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) { |
763 |
data.dquant = pEnc->temp_dquants; |
data.dquant = pEnc->temp_dquants; |
764 |
data.dquant_stride = pEnc->mbParam.mb_width; |
data.dquant_stride = pEnc->mbParam.mb_width; |
765 |
memset(data.dquant, 0, data.mb_width*data.mb_height); |
memset(data.dquant, 0, data.mb_width*data.mb_height*sizeof(int)); |
766 |
|
} |
767 |
|
|
768 |
|
if(pEnc->mbParam.plugin_flags & XVID_REQLAMBDA) { |
769 |
|
int block = 0; |
770 |
|
data.lambda = pEnc->temp_lambda; |
771 |
|
for(i = 0;i < pEnc->mbParam.mb_height; i++) |
772 |
|
for(j = 0;j < pEnc->mbParam.mb_width; j++) |
773 |
|
for (k = 0; k < 6; k++) |
774 |
|
data.lambda[block++] = 1.0f; |
775 |
} |
} |
776 |
|
|
777 |
} else { /* XVID_PLG_AFTER */ |
} else { /* XVID_PLG_AFTER */ |
848 |
for (i=0; i<(unsigned int)pEnc->num_plugins;i++) { |
for (i=0; i<(unsigned int)pEnc->num_plugins;i++) { |
849 |
emms(); |
emms(); |
850 |
if (pEnc->plugins[i].func) { |
if (pEnc->plugins[i].func) { |
851 |
if (pEnc->plugins[i].func(pEnc->plugins[i].param, opt, &data, 0) < 0) { |
if (pEnc->plugins[i].func(pEnc->plugins[i].param, opt, &data, NULL) < 0) { |
852 |
continue; |
continue; |
853 |
} |
} |
854 |
} |
} |
877 |
frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0; |
frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0; |
878 |
} |
} |
879 |
} |
} |
880 |
|
|
881 |
|
if (pEnc->mbParam.plugin_flags & XVID_REQLAMBDA) { |
882 |
|
for (j = 0; j < pEnc->mbParam.mb_height; j++) |
883 |
|
for (i = 0; i < pEnc->mbParam.mb_width; i++) |
884 |
|
for (k = 0; k < 6; k++) { |
885 |
|
frame->mbs[j*pEnc->mbParam.mb_width + i].lambda[k] = |
886 |
|
(int) ((float)(1<<LAMBDA_EXP) * data.lambda[6 * (j * data.mb_width + i) + k]); |
887 |
|
} |
888 |
|
} else { |
889 |
|
for (j = 0; j<pEnc->mbParam.mb_height; j++) |
890 |
|
for (i = 0; i<pEnc->mbParam.mb_width; i++) |
891 |
|
for (k = 0; k < 6; k++) { |
892 |
|
frame->mbs[j*pEnc->mbParam.mb_width + i].lambda[k] = 1<<LAMBDA_EXP; |
893 |
|
} |
894 |
|
} |
895 |
|
|
896 |
|
|
897 |
frame->mbs[0].quant = data.quant; /* FRAME will not affect the quant in stats */ |
frame->mbs[0].quant = data.quant; /* FRAME will not affect the quant in stats */ |
898 |
} |
} |
899 |
|
|
1088 |
} |
} |
1089 |
|
|
1090 |
FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs); |
FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs); |
1091 |
call_plugins(pEnc, pEnc->bframes[pEnc->bframenum_head], &pEnc->sOriginal2, XVID_PLG_AFTER, 0, 0, stats); |
call_plugins(pEnc, pEnc->bframes[pEnc->bframenum_head], &pEnc->sOriginal2, XVID_PLG_AFTER, NULL, NULL, stats); |
1092 |
pEnc->bframenum_head++; |
pEnc->bframenum_head++; |
1093 |
|
|
1094 |
goto done; |
goto done; |
1120 |
|
|
1121 |
/* add the not-coded length to the reference frame size */ |
/* add the not-coded length to the reference frame size */ |
1122 |
pEnc->current->length += (BitstreamPos(&bs) - bits) / 8; |
pEnc->current->length += (BitstreamPos(&bs) - bits) / 8; |
1123 |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, NULL, NULL, stats); |
1124 |
|
|
1125 |
/* flush complete: reset counters */ |
/* flush complete: reset counters */ |
1126 |
pEnc->flush_bframes = 0; |
pEnc->flush_bframes = 0; |
1148 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
1149 |
|
|
1150 |
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) { |
1151 |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, NULL, NULL, stats); |
1152 |
} |
} |
1153 |
|
|
1154 |
/* 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 */ |
1177 |
|
|
1178 |
|
|
1179 |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail==0) { |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail==0) { |
1180 |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, NULL, NULL, stats); |
1181 |
}else{ |
}else{ |
1182 |
pEnc->flush_bframes = 1; |
pEnc->flush_bframes = 1; |
1183 |
goto done; |
goto done; |
1301 |
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) |
1302 |
{ |
{ |
1303 |
if (pEnc->current->stamp > 0) { |
if (pEnc->current->stamp > 0) { |
1304 |
call_plugins(pEnc, pEnc->reference, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
call_plugins(pEnc, pEnc->reference, &pEnc->sOriginal, XVID_PLG_AFTER, NULL, NULL, stats); |
1305 |
} |
} |
1306 |
else |
else |
1307 |
stats->type = XVID_TYPE_NOTHING; |
stats->type = XVID_TYPE_NOTHING; |
1424 |
|
|
1425 |
if ( FrameCodeP(pEnc, &bs) == 0 ) { |
if ( FrameCodeP(pEnc, &bs) == 0 ) { |
1426 |
/* N-VOP, we mustn't code b-frames yet */ |
/* N-VOP, we mustn't code b-frames yet */ |
1427 |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) || |
1428 |
|
pEnc->mbParam.max_bframes == 0) |
1429 |
|
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, NULL, NULL, stats); |
1430 |
goto done; |
goto done; |
1431 |
} |
} |
1432 |
} |
} |
1447 |
|
|
1448 |
/* packed or no-bframes or no-bframes-queued: output stats */ |
/* packed or no-bframes or no-bframes-queued: output stats */ |
1449 |
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 ) { |
1450 |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, NULL, NULL, stats); |
1451 |
} |
} |
1452 |
|
|
1453 |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1536 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1, pEnc->current->mbs[0].quant); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1, pEnc->current->mbs[0].quant); |
1537 |
|
|
1538 |
pEnc->current->sStat.iTextBits = 0; |
pEnc->current->sStat.iTextBits = 0; |
1539 |
|
pEnc->current->sStat.iMVBits = 0; |
1540 |
pEnc->current->sStat.kblks = mb_width * mb_height; |
pEnc->current->sStat.kblks = mb_width * mb_height; |
1541 |
pEnc->current->sStat.mblks = pEnc->current->sStat.ublks = 0; |
pEnc->current->sStat.mblks = pEnc->current->sStat.ublks = 0; |
1542 |
|
|
1635 |
if ((current->vop_flags & XVID_VOP_HALFPEL)) { |
if ((current->vop_flags & XVID_VOP_HALFPEL)) { |
1636 |
if (reference->is_interpolated != current->rounding_type) { |
if (reference->is_interpolated != current->rounding_type) { |
1637 |
start_timer(); |
start_timer(); |
1638 |
image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV, |
image_interpolate(pRef->y, pEnc->vInterH.y, pEnc->vInterV.y, |
1639 |
&pEnc->vInterHV, pParam->edged_width, |
pEnc->vInterHV.y, pParam->edged_width, |
1640 |
pParam->edged_height, |
pParam->edged_height, |
1641 |
(pParam->vol_flags & XVID_VOL_QUARTERPEL), |
(pParam->vol_flags & XVID_VOL_QUARTERPEL), |
1642 |
current->rounding_type); |
current->rounding_type); |
1646 |
} |
} |
1647 |
|
|
1648 |
current->sStat.iTextBits = current->sStat.iMvSum = current->sStat.iMvCount = |
current->sStat.iTextBits = current->sStat.iMvSum = current->sStat.iMvCount = |
1649 |
current->sStat.kblks = current->sStat.mblks = current->sStat.ublks = 0; |
current->sStat.kblks = current->sStat.mblks = current->sStat.ublks = |
1650 |
|
current->sStat.iMVBits = 0; |
1651 |
|
|
1652 |
current->coding_type = P_VOP; |
current->coding_type = P_VOP; |
1653 |
|
|
1706 |
} |
} |
1707 |
} |
} |
1708 |
|
|
1709 |
|
|
1710 |
|
if (pEnc->num_threads > 0) { |
1711 |
|
/* multithreaded motion estimation - dispatch threads */ |
1712 |
|
|
1713 |
|
void * status; |
1714 |
|
int rows_per_thread = (pParam->mb_height + pEnc->num_threads - 1)/pEnc->num_threads; |
1715 |
|
|
1716 |
|
for (k = 0; k < pEnc->num_threads; k++) { |
1717 |
|
memset(pEnc->motionData[k].complete_count_self, 0, rows_per_thread * sizeof(int)); |
1718 |
|
pEnc->motionData[k].pParam = &pEnc->mbParam; |
1719 |
|
pEnc->motionData[k].current = current; |
1720 |
|
pEnc->motionData[k].reference = reference; |
1721 |
|
pEnc->motionData[k].pRefH = &pEnc->vInterH; |
1722 |
|
pEnc->motionData[k].pRefV = &pEnc->vInterV; |
1723 |
|
pEnc->motionData[k].pRefHV = &pEnc->vInterHV; |
1724 |
|
pEnc->motionData[k].pGMC = &pEnc->vGMC; |
1725 |
|
pEnc->motionData[k].y_step = pEnc->num_threads; |
1726 |
|
pEnc->motionData[k].start_y = k; |
1727 |
|
/* todo: sort out temp space once and for all */ |
1728 |
|
pEnc->motionData[k].RefQ = pEnc->vInterH.u + 16*k*pParam->edged_width; |
1729 |
|
} |
1730 |
|
|
1731 |
|
for (k = 1; k < pEnc->num_threads; k++) { |
1732 |
|
pthread_create(&pEnc->motionData[k].handle, NULL, |
1733 |
|
(void*)MotionEstimateSMP, (void*)&pEnc->motionData[k]); |
1734 |
|
} |
1735 |
|
|
1736 |
|
MotionEstimateSMP(&pEnc->motionData[0]); |
1737 |
|
|
1738 |
|
for (k = 1; k < pEnc->num_threads; k++) { |
1739 |
|
pthread_join(pEnc->motionData[k].handle, &status); |
1740 |
|
} |
1741 |
|
|
1742 |
|
current->fcode = 0; |
1743 |
|
for (k = 0; k < pEnc->num_threads; k++) { |
1744 |
|
current->sStat.iMvSum += pEnc->motionData[k].mvSum; |
1745 |
|
current->sStat.iMvCount += pEnc->motionData[k].mvCount; |
1746 |
|
if (pEnc->motionData[k].minfcode > current->fcode) |
1747 |
|
current->fcode = pEnc->motionData[k].minfcode; |
1748 |
|
} |
1749 |
|
|
1750 |
|
} else { |
1751 |
|
/* regular ME */ |
1752 |
|
|
1753 |
MotionEstimation(&pEnc->mbParam, current, reference, |
MotionEstimation(&pEnc->mbParam, current, reference, |
1754 |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
1755 |
&pEnc->vGMC, 256*4096); |
&pEnc->vGMC, 256*4096); |
1756 |
|
} |
1757 |
|
|
1758 |
stop_motion_timer(); |
stop_motion_timer(); |
1759 |
|
|
1883 |
(pParam->frame_drop_ratio * mb_width * mb_height) / 100 && |
(pParam->frame_drop_ratio * mb_width * mb_height) / 100 && |
1884 |
( (pEnc->bframenum_head >= pEnc->bframenum_tail) || !(pEnc->mbParam.global_flags & XVID_GLOBAL_CLOSED_GOP)) ) |
( (pEnc->bframenum_head >= pEnc->bframenum_tail) || !(pEnc->mbParam.global_flags & XVID_GLOBAL_CLOSED_GOP)) ) |
1885 |
{ |
{ |
1886 |
current->sStat.kblks = current->sStat.mblks = 0; |
current->sStat.kblks = current->sStat.mblks = current->sStat.iTextBits = 0; |
1887 |
current->sStat.ublks = mb_width * mb_height; |
current->sStat.ublks = mb_width * mb_height; |
1888 |
|
|
1889 |
BitstreamReset(bs); |
BitstreamReset(bs); |
1973 |
|
|
1974 |
if (pEnc->reference->is_interpolated != 0) { |
if (pEnc->reference->is_interpolated != 0) { |
1975 |
start_timer(); |
start_timer(); |
1976 |
image_interpolate(f_ref, &pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv, |
image_interpolate(f_ref->y, pEnc->f_refh.y, pEnc->f_refv.y, pEnc->f_refhv.y, |
1977 |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
1978 |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); |
1979 |
stop_inter_timer(); |
stop_inter_timer(); |
1990 |
|
|
1991 |
if (pEnc->current->is_interpolated != 0) { |
if (pEnc->current->is_interpolated != 0) { |
1992 |
start_timer(); |
start_timer(); |
1993 |
image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
image_interpolate(b_ref->y, pEnc->vInterH.y, pEnc->vInterV.y, pEnc->vInterHV.y, |
1994 |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
1995 |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); |
1996 |
stop_inter_timer(); |
stop_inter_timer(); |
1998 |
} |
} |
1999 |
|
|
2000 |
frame->coding_type = B_VOP; |
frame->coding_type = B_VOP; |
2001 |
call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL); |
call_plugins(pEnc, frame, NULL, XVID_PLG_FRAME, NULL, NULL, NULL); |
2002 |
|
|
2003 |
|
frame->fcode = frame->bcode = pEnc->current->fcode; |
2004 |
|
|
2005 |
start_timer(); |
start_timer(); |
2006 |
|
if (pEnc->num_threads > 0) { |
2007 |
|
void * status; |
2008 |
|
int k; |
2009 |
|
/* multithreaded motion estimation - dispatch threads */ |
2010 |
|
int rows_per_thread = (pEnc->mbParam.mb_height + pEnc->num_threads - 1)/pEnc->num_threads; |
2011 |
|
|
2012 |
|
for (k = 0; k < pEnc->num_threads; k++) { |
2013 |
|
memset(pEnc->motionData[k].complete_count_self, 0, rows_per_thread * sizeof(int)); |
2014 |
|
pEnc->motionData[k].pParam = &pEnc->mbParam; |
2015 |
|
pEnc->motionData[k].current = frame; |
2016 |
|
pEnc->motionData[k].reference = pEnc->current; |
2017 |
|
pEnc->motionData[k].fRef = f_ref; |
2018 |
|
pEnc->motionData[k].fRefH = &pEnc->f_refh; |
2019 |
|
pEnc->motionData[k].fRefV = &pEnc->f_refv; |
2020 |
|
pEnc->motionData[k].fRefHV = &pEnc->f_refhv; |
2021 |
|
pEnc->motionData[k].pRef = b_ref; |
2022 |
|
pEnc->motionData[k].pRefH = &pEnc->vInterH; |
2023 |
|
pEnc->motionData[k].pRefV = &pEnc->vInterV; |
2024 |
|
pEnc->motionData[k].pRefHV = &pEnc->vInterHV; |
2025 |
|
pEnc->motionData[k].time_bp = (int32_t)(pEnc->current->stamp - frame->stamp); |
2026 |
|
pEnc->motionData[k].time_pp = (int32_t)(pEnc->current->stamp - pEnc->reference->stamp); |
2027 |
|
pEnc->motionData[k].y_step = pEnc->num_threads; |
2028 |
|
pEnc->motionData[k].start_y = k; |
2029 |
|
/* todo: sort out temp space once and for all */ |
2030 |
|
pEnc->motionData[k].RefQ = pEnc->vInterH.u + 16*k*pEnc->mbParam.edged_width; |
2031 |
|
} |
2032 |
|
|
2033 |
|
for (k = 1; k < pEnc->num_threads; k++) { |
2034 |
|
pthread_create(&pEnc->motionData[k].handle, NULL, |
2035 |
|
(void*)SMPMotionEstimationBVOP, (void*)&pEnc->motionData[k]); |
2036 |
|
} |
2037 |
|
|
2038 |
|
SMPMotionEstimationBVOP(&pEnc->motionData[0]); |
2039 |
|
|
2040 |
|
for (k = 1; k < pEnc->num_threads; k++) { |
2041 |
|
pthread_join(pEnc->motionData[k].handle, &status); |
2042 |
|
} |
2043 |
|
|
2044 |
|
frame->fcode = frame->bcode = 0; |
2045 |
|
for (k = 0; k < pEnc->num_threads; k++) { |
2046 |
|
if (pEnc->motionData[k].minfcode > frame->fcode) |
2047 |
|
frame->fcode = pEnc->motionData[k].minfcode; |
2048 |
|
if (pEnc->motionData[k].minbcode > frame->bcode) |
2049 |
|
frame->bcode = pEnc->motionData[k].minbcode; |
2050 |
|
} |
2051 |
|
} else { |
2052 |
MotionEstimationBVOP(&pEnc->mbParam, frame, |
MotionEstimationBVOP(&pEnc->mbParam, frame, |
2053 |
((int32_t)(pEnc->current->stamp - frame->stamp)), /* time_bp */ |
((int32_t)(pEnc->current->stamp - frame->stamp)), /* time_bp */ |
2054 |
((int32_t)(pEnc->current->stamp - pEnc->reference->stamp)), /* time_pp */ |
((int32_t)(pEnc->current->stamp - pEnc->reference->stamp)), /* time_pp */ |
2056 |
&pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv, |
&pEnc->f_refh, &pEnc->f_refv, &pEnc->f_refhv, |
2057 |
pEnc->current, b_ref, &pEnc->vInterH, |
pEnc->current, b_ref, &pEnc->vInterH, |
2058 |
&pEnc->vInterV, &pEnc->vInterHV); |
&pEnc->vInterV, &pEnc->vInterHV); |
2059 |
|
} |
2060 |
stop_motion_timer(); |
stop_motion_timer(); |
2061 |
|
|
2062 |
set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase); |
set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase); |
2063 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1, frame->quant); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1, frame->quant); |
2064 |
|
|
2065 |
frame->sStat.iTextBits = 0; |
frame->sStat.iTextBits = 0; |
2066 |
|
frame->sStat.iMVBits = 0; |
2067 |
frame->sStat.iMvSum = 0; |
frame->sStat.iMvSum = 0; |
2068 |
frame->sStat.iMvCount = 0; |
frame->sStat.iMvCount = 0; |
2069 |
frame->sStat.kblks = frame->sStat.mblks = frame->sStat.ublks = 0; |
frame->sStat.kblks = frame->sStat.mblks = frame->sStat.ublks = 0; |
2114 |
stop_coding_timer(); |
stop_coding_timer(); |
2115 |
} |
} |
2116 |
} |
} |
|
|
|
2117 |
emms(); |
emms(); |
2118 |
|
|
2119 |
BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */ |
BitstreamPadAlways(bs); /* next_start_code() at the end of VideoObjectPlane() */ |