203 |
|
|
204 |
memset(&pinfo, 0, sizeof(xvid_plg_info_t)); |
memset(&pinfo, 0, sizeof(xvid_plg_info_t)); |
205 |
pinfo.version = XVID_VERSION; |
pinfo.version = XVID_VERSION; |
206 |
if (create->plugins[n].func(0, XVID_PLG_INFO, &pinfo, 0) >= 0) { |
if (create->plugins[n].func(NULL, XVID_PLG_INFO, &pinfo, NULL) >= 0) { |
207 |
pEnc->mbParam.plugin_flags |= pinfo.flags; |
pEnc->mbParam.plugin_flags |= pinfo.flags; |
208 |
} |
} |
209 |
|
|
220 |
pcreate.param = create->plugins[n].param; |
pcreate.param = create->plugins[n].param; |
221 |
|
|
222 |
pEnc->plugins[n].func = NULL; /* disable plugins that fail */ |
pEnc->plugins[n].func = NULL; /* disable plugins that fail */ |
223 |
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) { |
224 |
pEnc->plugins[n].func = create->plugins[n].func; |
pEnc->plugins[n].func = create->plugins[n].func; |
225 |
} |
} |
226 |
} |
} |
238 |
goto xvid_err_memory1a; |
goto xvid_err_memory1a; |
239 |
} |
} |
240 |
|
|
241 |
|
/* temp lambdas */ |
242 |
|
if (pEnc->mbParam.plugin_flags & XVID_REQLAMBDA) { |
243 |
|
pEnc->temp_lambda = (float *) xvid_malloc(pEnc->mbParam.mb_width * |
244 |
|
pEnc->mbParam.mb_height * 6 * sizeof(float), CACHE_LINE); |
245 |
|
if (pEnc->temp_lambda == NULL) |
246 |
|
goto xvid_err_memory1a; |
247 |
|
} |
248 |
|
|
249 |
/* bframes */ |
/* bframes */ |
250 |
pEnc->mbParam.max_bframes = MAX(create->max_bframes, 0); |
pEnc->mbParam.max_bframes = MAX(create->max_bframes, 0); |
251 |
pEnc->mbParam.bquant_ratio = MAX(create->bquant_ratio, 0); |
pEnc->mbParam.bquant_ratio = MAX(create->bquant_ratio, 0); |
527 |
xvid_free(pEnc->temp_dquants); |
xvid_free(pEnc->temp_dquants); |
528 |
} |
} |
529 |
|
|
530 |
|
if(pEnc->mbParam.plugin_flags & XVID_REQLAMBDA) { |
531 |
|
xvid_free(pEnc->temp_lambda); |
532 |
|
} |
533 |
|
|
534 |
xvid_err_memory0: |
xvid_err_memory0: |
535 |
for (n=0; n<pEnc->num_plugins;n++) { |
for (n=0; n<pEnc->num_plugins;n++) { |
536 |
if (pEnc->plugins[n].func) { |
if (pEnc->plugins[n].func) { |
537 |
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); |
538 |
} |
} |
539 |
} |
} |
540 |
xvid_free(pEnc->plugins); |
xvid_free(pEnc->plugins); |
639 |
|
|
640 |
for (i=0; i<pEnc->num_plugins;i++) { |
for (i=0; i<pEnc->num_plugins;i++) { |
641 |
if (pEnc->plugins[i].func) { |
if (pEnc->plugins[i].func) { |
642 |
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); |
643 |
} |
} |
644 |
} |
} |
645 |
xvid_free(pEnc->plugins); |
xvid_free(pEnc->plugins); |
663 |
static void call_plugins(Encoder * pEnc, FRAMEINFO * frame, IMAGE * original, |
static void call_plugins(Encoder * pEnc, FRAMEINFO * frame, IMAGE * original, |
664 |
int opt, int * type, int * quant, xvid_enc_stats_t * stats) |
int opt, int * type, int * quant, xvid_enc_stats_t * stats) |
665 |
{ |
{ |
666 |
unsigned int i, j; |
unsigned int i, j, k; |
667 |
xvid_plg_data_t data; |
xvid_plg_data_t data; |
668 |
|
|
669 |
/* set data struct */ |
/* set data struct */ |
725 |
memset(data.dquant, 0, data.mb_width*data.mb_height); |
memset(data.dquant, 0, data.mb_width*data.mb_height); |
726 |
} |
} |
727 |
|
|
728 |
|
if(pEnc->mbParam.plugin_flags & XVID_REQLAMBDA) { |
729 |
|
int block = 0; |
730 |
|
data.lambda = pEnc->temp_lambda; |
731 |
|
for(i = 0;i < pEnc->mbParam.mb_height; i++) |
732 |
|
for(j = 0;j < pEnc->mbParam.mb_width; j++) |
733 |
|
for (k = 0; k < 6; k++) |
734 |
|
data.lambda[block++] = 1.0f; |
735 |
|
} |
736 |
|
|
737 |
} else { /* XVID_PLG_AFTER */ |
} else { /* XVID_PLG_AFTER */ |
738 |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
739 |
data.original.csp = XVID_CSP_PLANAR; |
data.original.csp = XVID_CSP_PLANAR; |
808 |
for (i=0; i<(unsigned int)pEnc->num_plugins;i++) { |
for (i=0; i<(unsigned int)pEnc->num_plugins;i++) { |
809 |
emms(); |
emms(); |
810 |
if (pEnc->plugins[i].func) { |
if (pEnc->plugins[i].func) { |
811 |
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) { |
812 |
continue; |
continue; |
813 |
} |
} |
814 |
} |
} |
837 |
frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0; |
frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0; |
838 |
} |
} |
839 |
} |
} |
840 |
|
|
841 |
|
if (pEnc->mbParam.plugin_flags & XVID_REQLAMBDA) { |
842 |
|
for (j = 0; j < pEnc->mbParam.mb_height; j++) |
843 |
|
for (i = 0; i < pEnc->mbParam.mb_width; i++) |
844 |
|
for (k = 0; k < 6; k++) { |
845 |
|
frame->mbs[j*pEnc->mbParam.mb_width + i].lambda[k] = |
846 |
|
(int) ((float)(1<<LAMBDA_EXP) * data.lambda[6 * (j * data.mb_width + i) + k]); |
847 |
|
} |
848 |
|
} else { |
849 |
|
for (j = 0; j<pEnc->mbParam.mb_height; j++) |
850 |
|
for (i = 0; i<pEnc->mbParam.mb_width; i++) |
851 |
|
for (k = 0; k < 6; k++) { |
852 |
|
frame->mbs[j*pEnc->mbParam.mb_width + i].lambda[k] = 1<<LAMBDA_EXP; |
853 |
|
} |
854 |
|
} |
855 |
|
|
856 |
|
|
857 |
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 */ |
858 |
} |
} |
859 |
|
|
1048 |
} |
} |
1049 |
|
|
1050 |
FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs); |
FrameCodeB(pEnc, pEnc->bframes[pEnc->bframenum_head], &bs); |
1051 |
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); |
1052 |
pEnc->bframenum_head++; |
pEnc->bframenum_head++; |
1053 |
|
|
1054 |
goto done; |
goto done; |
1080 |
|
|
1081 |
/* add the not-coded length to the reference frame size */ |
/* add the not-coded length to the reference frame size */ |
1082 |
pEnc->current->length += (BitstreamPos(&bs) - bits) / 8; |
pEnc->current->length += (BitstreamPos(&bs) - bits) / 8; |
1083 |
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); |
1084 |
|
|
1085 |
/* flush complete: reset counters */ |
/* flush complete: reset counters */ |
1086 |
pEnc->flush_bframes = 0; |
pEnc->flush_bframes = 0; |
1108 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
1109 |
|
|
1110 |
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) { |
1111 |
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); |
1112 |
} |
} |
1113 |
|
|
1114 |
/* 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 */ |
1137 |
|
|
1138 |
|
|
1139 |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail==0) { |
if ((pEnc->mbParam.global_flags & XVID_GLOBAL_PACKED) && pEnc->bframenum_tail==0) { |
1140 |
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); |
1141 |
}else{ |
}else{ |
1142 |
pEnc->flush_bframes = 1; |
pEnc->flush_bframes = 1; |
1143 |
goto done; |
goto done; |
1261 |
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) |
1262 |
{ |
{ |
1263 |
if (pEnc->current->stamp > 0) { |
if (pEnc->current->stamp > 0) { |
1264 |
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); |
1265 |
} |
} |
1266 |
else |
else |
1267 |
stats->type = XVID_TYPE_NOTHING; |
stats->type = XVID_TYPE_NOTHING; |
1384 |
|
|
1385 |
if ( FrameCodeP(pEnc, &bs) == 0 ) { |
if ( FrameCodeP(pEnc, &bs) == 0 ) { |
1386 |
/* N-VOP, we mustn't code b-frames yet */ |
/* N-VOP, we mustn't code b-frames yet */ |
1387 |
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); |
1388 |
goto done; |
goto done; |
1389 |
} |
} |
1390 |
} |
} |
1405 |
|
|
1406 |
/* packed or no-bframes or no-bframes-queued: output stats */ |
/* packed or no-bframes or no-bframes-queued: output stats */ |
1407 |
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 ) { |
1408 |
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); |
1409 |
} |
} |
1410 |
|
|
1411 |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1592 |
if ((current->vop_flags & XVID_VOP_HALFPEL)) { |
if ((current->vop_flags & XVID_VOP_HALFPEL)) { |
1593 |
if (reference->is_interpolated != current->rounding_type) { |
if (reference->is_interpolated != current->rounding_type) { |
1594 |
start_timer(); |
start_timer(); |
1595 |
image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV, |
image_interpolate(pRef->y, pEnc->vInterH.y, pEnc->vInterV.y, |
1596 |
&pEnc->vInterHV, pParam->edged_width, |
pEnc->vInterHV.y, pParam->edged_width, |
1597 |
pParam->edged_height, |
pParam->edged_height, |
1598 |
(pParam->vol_flags & XVID_VOL_QUARTERPEL), |
(pParam->vol_flags & XVID_VOL_QUARTERPEL), |
1599 |
current->rounding_type); |
current->rounding_type); |
1885 |
|
|
1886 |
if (pEnc->reference->is_interpolated != 0) { |
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->y, pEnc->f_refh.y, pEnc->f_refv.y, pEnc->f_refhv.y, |
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(); |
1902 |
|
|
1903 |
if (pEnc->current->is_interpolated != 0) { |
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->y, pEnc->vInterH.y, pEnc->vInterV.y, pEnc->vInterHV.y, |
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(); |
1910 |
} |
} |
1911 |
|
|
1912 |
frame->coding_type = B_VOP; |
frame->coding_type = B_VOP; |
1913 |
call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL); |
call_plugins(pEnc, frame, NULL, XVID_PLG_FRAME, NULL, NULL, NULL); |
1914 |
|
|
1915 |
start_timer(); |
start_timer(); |
1916 |
MotionEstimationBVOP(&pEnc->mbParam, frame, |
MotionEstimationBVOP(&pEnc->mbParam, frame, |