652 |
data.max_quant[i] = pEnc->mbParam.max_quant[i]; |
data.max_quant[i] = pEnc->mbParam.max_quant[i]; |
653 |
} |
} |
654 |
|
|
655 |
data.reference.csp = XVID_CSP_USER; |
data.reference.csp = XVID_CSP_PLANAR; |
656 |
data.reference.plane[0] = pEnc->reference->image.y; |
data.reference.plane[0] = pEnc->reference->image.y; |
657 |
data.reference.plane[1] = pEnc->reference->image.u; |
data.reference.plane[1] = pEnc->reference->image.u; |
658 |
data.reference.plane[2] = pEnc->reference->image.v; |
data.reference.plane[2] = pEnc->reference->image.v; |
660 |
data.reference.stride[1] = pEnc->mbParam.edged_width/2; |
data.reference.stride[1] = pEnc->mbParam.edged_width/2; |
661 |
data.reference.stride[2] = pEnc->mbParam.edged_width/2; |
data.reference.stride[2] = pEnc->mbParam.edged_width/2; |
662 |
|
|
663 |
data.current.csp = XVID_CSP_USER; |
data.current.csp = XVID_CSP_PLANAR; |
664 |
data.current.plane[0] = frame->image.y; |
data.current.plane[0] = frame->image.y; |
665 |
data.current.plane[1] = frame->image.u; |
data.current.plane[1] = frame->image.u; |
666 |
data.current.plane[2] = frame->image.v; |
data.current.plane[2] = frame->image.v; |
690 |
|
|
691 |
} else { /* XVID_PLG_AFTER */ |
} else { /* XVID_PLG_AFTER */ |
692 |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
693 |
data.original.csp = XVID_CSP_USER; |
data.original.csp = XVID_CSP_PLANAR; |
694 |
data.original.plane[0] = original->y; |
data.original.plane[0] = original->y; |
695 |
data.original.plane[1] = original->u; |
data.original.plane[1] = original->u; |
696 |
data.original.plane[2] = original->v; |
data.original.plane[2] = original->v; |
740 |
data.mblks = frame->sStat.mblks; |
data.mblks = frame->sStat.mblks; |
741 |
data.ublks = frame->sStat.ublks; |
data.ublks = frame->sStat.ublks; |
742 |
|
|
743 |
if (stats) { |
/* New code */ |
744 |
stats->type = coding2type(frame->coding_type); |
data.stats.type = coding2type(frame->coding_type); |
745 |
stats->quant = frame->quant; |
data.stats.quant = frame->quant; |
746 |
stats->vol_flags = frame->vol_flags; |
data.stats.vol_flags = frame->vol_flags; |
747 |
stats->vop_flags = frame->vop_flags; |
data.stats.vop_flags = frame->vop_flags; |
748 |
stats->length = frame->length; |
data.stats.length = frame->length; |
749 |
stats->hlength = frame->length - (frame->sStat.iTextBits / 8); |
data.stats.hlength = frame->length - (frame->sStat.iTextBits / 8); |
750 |
stats->kblks = frame->sStat.kblks; |
data.stats.kblks = frame->sStat.kblks; |
751 |
stats->mblks = frame->sStat.mblks; |
data.stats.mblks = frame->sStat.mblks; |
752 |
stats->ublks = frame->sStat.ublks; |
data.stats.ublks = frame->sStat.ublks; |
753 |
stats->sse_y = data.sse_y; |
data.stats.sse_y = data.sse_y; |
754 |
stats->sse_u = data.sse_u; |
data.stats.sse_u = data.sse_u; |
755 |
stats->sse_v = data.sse_v; |
data.stats.sse_v = data.sse_v; |
756 |
} |
|
757 |
|
if (stats) |
758 |
|
*stats = data.stats; |
759 |
} |
} |
760 |
|
|
761 |
/* call plugins */ |
/* call plugins */ |
850 |
pCur->ticks = (int32_t)pCur->stamp % time_base; |
pCur->ticks = (int32_t)pCur->stamp % time_base; |
851 |
pCur->seconds = ((int32_t)pCur->stamp / time_base) - ((int32_t)pRef->stamp / time_base) ; |
pCur->seconds = ((int32_t)pCur->stamp / time_base) - ((int32_t)pRef->stamp / time_base) ; |
852 |
|
|
853 |
/* HEAVY DEBUG OUTPUT remove when timecodes prove to be stable */ |
#if 0 /* HEAVY DEBUG OUTPUT */ |
854 |
|
fprintf(stderr,"WriteVop: %d - %d \n", |
|
/* fprintf(stderr,"WriteVop: %d - %d \n", |
|
855 |
((int32_t)pCur->stamp / time_base), ((int32_t)pRef->stamp / time_base)); |
((int32_t)pCur->stamp / time_base), ((int32_t)pRef->stamp / time_base)); |
856 |
fprintf(stderr,"set_timecodes: VOP %1d stamp=%lld ref_stamp=%lld base=%d\n", |
fprintf(stderr,"set_timecodes: VOP %1d stamp=%lld ref_stamp=%lld base=%d\n", |
857 |
pCur->coding_type, pCur->stamp, pRef->stamp, time_base); |
pCur->coding_type, pCur->stamp, pRef->stamp, time_base); |
858 |
fprintf(stderr,"set_timecodes: VOP %1d seconds=%d ticks=%d (ref-sec=%d ref-tick=%d)\n", |
fprintf(stderr,"set_timecodes: VOP %1d seconds=%d ticks=%d (ref-sec=%d ref-tick=%d)\n", |
859 |
pCur->coding_type, pCur->seconds, pCur->ticks, pRef->seconds, pRef->ticks); |
pCur->coding_type, pCur->seconds, pCur->ticks, pRef->seconds, pRef->ticks); |
860 |
|
#endif |
861 |
|
} |
862 |
|
|
863 |
*/ |
static int |
864 |
|
gcd(int a, int b) |
865 |
|
{ |
866 |
|
int r ; |
867 |
|
|
868 |
|
if (b > a) { |
869 |
|
r = a; |
870 |
|
a = b; |
871 |
|
b = r; |
872 |
|
} |
873 |
|
|
874 |
|
while ((r = a % b)) { |
875 |
|
a = b; |
876 |
|
b = r; |
877 |
|
} |
878 |
|
return b; |
879 |
} |
} |
880 |
|
|
881 |
|
static void |
882 |
|
simplify_par(int *par_width, int *par_height) |
883 |
|
{ |
884 |
|
|
885 |
|
int _par_width = (!*par_width) ? 1 : (*par_width<0) ? -*par_width: *par_width; |
886 |
|
int _par_height = (!*par_height) ? 1 : (*par_height<0) ? -*par_height: *par_height; |
887 |
|
int divisor = gcd(_par_width, _par_height); |
888 |
|
|
889 |
|
_par_width /= divisor; |
890 |
|
_par_height /= divisor; |
891 |
|
|
892 |
|
/* 2^8 precision maximum */ |
893 |
|
if (_par_width>255 || _par_height>255) { |
894 |
|
float div; |
895 |
|
emms(); |
896 |
|
if (_par_width>_par_height) |
897 |
|
div = (float)_par_width/255; |
898 |
|
else |
899 |
|
div = (float)_par_height/255; |
900 |
|
|
901 |
|
_par_width = (int)((float)_par_width/div); |
902 |
|
_par_height = (int)((float)_par_height/div); |
903 |
|
} |
904 |
|
|
905 |
|
*par_width = _par_width; |
906 |
|
*par_height = _par_height; |
907 |
|
|
908 |
|
return; |
909 |
|
} |
910 |
|
|
911 |
|
|
912 |
/***************************************************************************** |
/***************************************************************************** |
1121 |
|
|
1122 |
pEnc->current->fincr = pEnc->mbParam.fincr>0 ? pEnc->mbParam.fincr : frame->fincr; |
pEnc->current->fincr = pEnc->mbParam.fincr>0 ? pEnc->mbParam.fincr : frame->fincr; |
1123 |
inc_frame_num(pEnc); |
inc_frame_num(pEnc); |
1124 |
pEnc->current->vol_flags = pEnc->mbParam.vol_flags; |
pEnc->current->vol_flags = frame->vol_flags; |
1125 |
pEnc->current->vop_flags = frame->vop_flags; |
pEnc->current->vop_flags = frame->vop_flags; |
1126 |
pEnc->current->motion_flags = frame->motion; |
pEnc->current->motion_flags = frame->motion; |
1127 |
pEnc->current->fcode = pEnc->mbParam.m_fcode; |
pEnc->current->fcode = pEnc->mbParam.m_fcode; |
1156 |
} |
} |
1157 |
} |
} |
1158 |
|
|
1159 |
|
if (type != I_VOP) |
1160 |
|
pEnc->current->vol_flags = pEnc->mbParam.vol_flags; /* don't allow VOL changes here */ |
1161 |
|
|
1162 |
/* bframes buffer overflow check */ |
/* bframes buffer overflow check */ |
1163 |
if (type == B_VOP && pEnc->bframenum_tail >= pEnc->mbParam.max_bframes) { |
if (type == B_VOP && pEnc->bframenum_tail >= pEnc->mbParam.max_bframes) { |
1164 |
type = P_VOP; |
type = P_VOP; |
1271 |
pEnc->iFrameNum = 1; |
pEnc->iFrameNum = 1; |
1272 |
|
|
1273 |
/* ---- update vol flags at IVOP ----------- */ |
/* ---- update vol flags at IVOP ----------- */ |
1274 |
pEnc->current->vol_flags = pEnc->mbParam.vol_flags = frame->vol_flags; |
pEnc->mbParam.vol_flags = pEnc->current->vol_flags; |
1275 |
|
|
1276 |
|
/* Aspect ratio */ |
1277 |
switch(frame->par) { |
switch(frame->par) { |
1278 |
case XVID_PAR_11_VGA: |
case XVID_PAR_11_VGA: |
1279 |
case XVID_PAR_43_PAL: |
case XVID_PAR_43_PAL: |
1284 |
pEnc->mbParam.par = frame->par; |
pEnc->mbParam.par = frame->par; |
1285 |
break; |
break; |
1286 |
default: |
default: |
1287 |
pEnc->mbParam.par = XVID_PAR_EXT; |
pEnc->mbParam.par = XVID_PAR_11_VGA; |
1288 |
break; |
break; |
1289 |
} |
} |
1290 |
pEnc->mbParam.par_width = (frame->par_width)?frame->par_width:1; |
|
1291 |
pEnc->mbParam.par_height = (frame->par_height)?frame->par_height:1; |
/* For extended PAR only, we try to sanityse/simplify par values */ |
1292 |
|
if (pEnc->mbParam.par == XVID_PAR_EXT) { |
1293 |
|
pEnc->mbParam.par_width = frame->par_width; |
1294 |
|
pEnc->mbParam.par_height = frame->par_height; |
1295 |
|
simplify_par(&pEnc->mbParam.par_width, &pEnc->mbParam.par_height); |
1296 |
|
} |
1297 |
|
|
1298 |
if ((pEnc->mbParam.vol_flags & XVID_VOL_MPEGQUANT)) { |
if ((pEnc->mbParam.vol_flags & XVID_VOL_MPEGQUANT)) { |
1299 |
if (frame->quant_intra_matrix != NULL) |
if (frame->quant_intra_matrix != NULL) |
1440 |
start_timer(); |
start_timer(); |
1441 |
image_setedges(&pEnc->current->image, |
image_setedges(&pEnc->current->image, |
1442 |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
1443 |
pEnc->mbParam.width, pEnc->mbParam.height); |
pEnc->mbParam.width, pEnc->mbParam.height, 0); |
1444 |
stop_edges_timer(); |
stop_edges_timer(); |
1445 |
} |
} |
1446 |
|
|
1452 |
|
|
1453 |
SetMacroblockQuants(&pEnc->mbParam, pEnc->current); |
SetMacroblockQuants(&pEnc->mbParam, pEnc->current); |
1454 |
|
|
1455 |
BitstreamWriteVolHeader(bs, &pEnc->mbParam); |
BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current); |
1456 |
|
|
1457 |
set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); |
set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); |
1458 |
|
|
1551 |
if (!reference->is_edged) { |
if (!reference->is_edged) { |
1552 |
start_timer(); |
start_timer(); |
1553 |
image_setedges(pRef, pParam->edged_width, pParam->edged_height, |
image_setedges(pRef, pParam->edged_width, pParam->edged_height, |
1554 |
pParam->width, pParam->height); |
pParam->width, pParam->height, 0); |
1555 |
stop_edges_timer(); |
stop_edges_timer(); |
1556 |
reference->is_edged = 1; |
reference->is_edged = 1; |
1557 |
} |
} |
1647 |
|
|
1648 |
set_timecodes(current,reference,pParam->fbase); |
set_timecodes(current,reference,pParam->fbase); |
1649 |
if (vol_header) |
if (vol_header) |
1650 |
{ BitstreamWriteVolHeader(bs, &pEnc->mbParam); |
{ BitstreamWriteVolHeader(bs, &pEnc->mbParam, current); |
1651 |
BitstreamPad(bs); |
BitstreamPad(bs); |
1652 |
} |
} |
1653 |
|
|
1949 |
if (!pEnc->reference->is_edged) { |
if (!pEnc->reference->is_edged) { |
1950 |
image_setedges(f_ref, pEnc->mbParam.edged_width, |
image_setedges(f_ref, pEnc->mbParam.edged_width, |
1951 |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
1952 |
pEnc->mbParam.height); |
pEnc->mbParam.height, 0); |
1953 |
pEnc->current->is_edged = 1; |
pEnc->current->is_edged = 1; |
1954 |
} |
} |
1955 |
|
|
1966 |
if (!pEnc->current->is_edged) { |
if (!pEnc->current->is_edged) { |
1967 |
image_setedges(b_ref, pEnc->mbParam.edged_width, |
image_setedges(b_ref, pEnc->mbParam.edged_width, |
1968 |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
1969 |
pEnc->mbParam.height); |
pEnc->mbParam.height, 0); |
1970 |
pEnc->current->is_edged = 1; |
pEnc->current->is_edged = 1; |
1971 |
} |
} |
1972 |
|
|