123 |
if (create->width%2 || create->height%2) |
if (create->width%2 || create->height%2) |
124 |
return XVID_ERR_FAIL; |
return XVID_ERR_FAIL; |
125 |
|
|
126 |
|
if (create->width<=0 || create->height<=0) |
127 |
|
return XVID_ERR_FAIL; |
128 |
|
|
129 |
/* allocate encoder struct */ |
/* allocate encoder struct */ |
130 |
|
|
131 |
pEnc = (Encoder *) xvid_malloc(sizeof(Encoder), CACHE_LINE); |
pEnc = (Encoder *) xvid_malloc(sizeof(Encoder), CACHE_LINE); |
191 |
pcreate.zones = pEnc->zones; |
pcreate.zones = pEnc->zones; |
192 |
pcreate.width = pEnc->mbParam.width; |
pcreate.width = pEnc->mbParam.width; |
193 |
pcreate.height = pEnc->mbParam.height; |
pcreate.height = pEnc->mbParam.height; |
194 |
|
pcreate.mb_width = pEnc->mbParam.mb_width; |
195 |
|
pcreate.mb_height = pEnc->mbParam.mb_height; |
196 |
pcreate.fincr = pEnc->mbParam.fincr; |
pcreate.fincr = pEnc->mbParam.fincr; |
197 |
pcreate.fbase = pEnc->mbParam.fbase; |
pcreate.fbase = pEnc->mbParam.fbase; |
198 |
pcreate.param = create->plugins[n].param; |
pcreate.param = create->plugins[n].param; |
253 |
if (pEnc->current->mbs == NULL || pEnc->reference->mbs == NULL) |
if (pEnc->current->mbs == NULL || pEnc->reference->mbs == NULL) |
254 |
goto xvid_err_memory2; |
goto xvid_err_memory2; |
255 |
|
|
256 |
|
/* allocate quant matrix memory */ |
257 |
|
|
258 |
|
pEnc->mbParam.mpeg_quant_matrices = |
259 |
|
xvid_malloc(sizeof(uint16_t) * 64 * 8, CACHE_LINE); |
260 |
|
|
261 |
|
if (pEnc->mbParam.mpeg_quant_matrices == NULL) |
262 |
|
goto xvid_err_memory2a; |
263 |
|
|
264 |
/* allocate interpolation image memory */ |
/* allocate interpolation image memory */ |
265 |
|
|
266 |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
276 |
image_null(&pEnc->reference->image); |
image_null(&pEnc->reference->image); |
277 |
image_null(&pEnc->vInterH); |
image_null(&pEnc->vInterH); |
278 |
image_null(&pEnc->vInterV); |
image_null(&pEnc->vInterV); |
|
image_null(&pEnc->vInterVf); |
|
279 |
image_null(&pEnc->vInterHV); |
image_null(&pEnc->vInterHV); |
|
image_null(&pEnc->vInterHVf); |
|
280 |
|
|
281 |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
282 |
if (image_create |
if (image_create |
320 |
pEnc->mbParam.edged_height) < 0) |
pEnc->mbParam.edged_height) < 0) |
321 |
goto xvid_err_memory3; |
goto xvid_err_memory3; |
322 |
if (image_create |
if (image_create |
|
(&pEnc->vInterVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height) < 0) |
|
|
goto xvid_err_memory3; |
|
|
if (image_create |
|
323 |
(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
324 |
pEnc->mbParam.edged_height) < 0) |
pEnc->mbParam.edged_height) < 0) |
325 |
goto xvid_err_memory3; |
goto xvid_err_memory3; |
|
if (image_create |
|
|
(&pEnc->vInterHVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height) < 0) |
|
|
goto xvid_err_memory3; |
|
326 |
|
|
327 |
/* Create full bitplane for GMC, this might be wasteful */ |
/* Create full bitplane for GMC, this might be wasteful */ |
328 |
if (image_create |
if (image_create |
414 |
create->handle = (void *) pEnc; |
create->handle = (void *) pEnc; |
415 |
|
|
416 |
init_timer(); |
init_timer(); |
417 |
|
init_mpeg_matrix(pEnc->mbParam.mpeg_quant_matrices); |
418 |
|
|
419 |
return 0; /* ok */ |
return 0; /* ok */ |
420 |
|
|
474 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
475 |
image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width, |
476 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
|
image_destroy(&pEnc->vInterVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height); |
|
477 |
image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
478 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
|
image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height); |
|
479 |
|
|
480 |
/* destroy GMC image */ |
/* destroy GMC image */ |
481 |
image_destroy(&pEnc->vGMC, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vGMC, pEnc->mbParam.edged_width, |
482 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
483 |
|
|
484 |
|
xvid_err_memory2a: |
485 |
|
xvid_free(pEnc->mbParam.mpeg_quant_matrices); |
486 |
|
|
487 |
xvid_err_memory2: |
xvid_err_memory2: |
488 |
xvid_free(pEnc->current->mbs); |
xvid_free(pEnc->current->mbs); |
565 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
566 |
image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vInterV, pEnc->mbParam.edged_width, |
567 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
|
image_destroy(&pEnc->vInterVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height); |
|
568 |
image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vInterHV, pEnc->mbParam.edged_width, |
569 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
|
image_destroy(&pEnc->vInterHVf, pEnc->mbParam.edged_width, |
|
|
pEnc->mbParam.edged_height); |
|
|
|
|
570 |
image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->f_refh, pEnc->mbParam.edged_width, |
571 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
572 |
image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->f_refv, pEnc->mbParam.edged_width, |
611 |
xvid_free(pEnc->plugins); |
xvid_free(pEnc->plugins); |
612 |
} |
} |
613 |
|
|
614 |
|
xvid_free(pEnc->mbParam.mpeg_quant_matrices); |
615 |
|
|
616 |
if (pEnc->num_plugins>0) |
if (pEnc->num_plugins>0) |
617 |
xvid_free(pEnc->zones); |
xvid_free(pEnc->zones); |
618 |
|
|
647 |
data.mb_height = pEnc->mbParam.mb_height; |
data.mb_height = pEnc->mbParam.mb_height; |
648 |
data.fincr = frame->fincr; |
data.fincr = frame->fincr; |
649 |
data.fbase = pEnc->mbParam.fbase; |
data.fbase = pEnc->mbParam.fbase; |
650 |
|
data.bquant_ratio = pEnc->mbParam.bquant_ratio; |
651 |
|
data.bquant_offset = pEnc->mbParam.bquant_offset; |
652 |
|
|
653 |
for (i=0; i<3; i++) { |
for (i=0; i<3; i++) { |
654 |
data.min_quant[i] = pEnc->mbParam.min_quant[i]; |
data.min_quant[i] = pEnc->mbParam.min_quant[i]; |
655 |
data.max_quant[i] = pEnc->mbParam.max_quant[i]; |
data.max_quant[i] = pEnc->mbParam.max_quant[i]; |
656 |
} |
} |
657 |
|
|
658 |
data.reference.csp = XVID_CSP_USER; |
data.reference.csp = XVID_CSP_PLANAR; |
659 |
data.reference.plane[0] = pEnc->reference->image.y; |
data.reference.plane[0] = pEnc->reference->image.y; |
660 |
data.reference.plane[1] = pEnc->reference->image.u; |
data.reference.plane[1] = pEnc->reference->image.u; |
661 |
data.reference.plane[2] = pEnc->reference->image.v; |
data.reference.plane[2] = pEnc->reference->image.v; |
663 |
data.reference.stride[1] = pEnc->mbParam.edged_width/2; |
data.reference.stride[1] = pEnc->mbParam.edged_width/2; |
664 |
data.reference.stride[2] = pEnc->mbParam.edged_width/2; |
data.reference.stride[2] = pEnc->mbParam.edged_width/2; |
665 |
|
|
666 |
data.current.csp = XVID_CSP_USER; |
data.current.csp = XVID_CSP_PLANAR; |
667 |
data.current.plane[0] = frame->image.y; |
data.current.plane[0] = frame->image.y; |
668 |
data.current.plane[1] = frame->image.u; |
data.current.plane[1] = frame->image.u; |
669 |
data.current.plane[2] = frame->image.v; |
data.current.plane[2] = frame->image.v; |
677 |
data.type = *type; |
data.type = *type; |
678 |
data.quant = *quant; |
data.quant = *quant; |
679 |
|
|
680 |
|
data.vol_flags = frame->vol_flags; |
681 |
|
data.vop_flags = frame->vop_flags; |
682 |
|
data.motion_flags = frame->motion_flags; |
683 |
|
|
684 |
|
} else if (opt == XVID_PLG_FRAME) { |
685 |
|
data.type = coding2type(frame->coding_type); |
686 |
|
data.quant = frame->quant; |
687 |
|
|
688 |
if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) { |
689 |
data.dquant = pEnc->temp_dquants; |
data.dquant = pEnc->temp_dquants; |
690 |
data.dquant_stride = pEnc->mbParam.mb_width; |
data.dquant_stride = pEnc->mbParam.mb_width; |
691 |
memset(data.dquant, 0, data.mb_width*data.mb_height); |
memset(data.dquant, 0, data.mb_width*data.mb_height); |
692 |
} |
} |
693 |
|
|
|
data.vol_flags = frame->vol_flags; |
|
|
data.vop_flags = frame->vop_flags; |
|
|
data.motion_flags = frame->motion_flags; |
|
|
|
|
694 |
} else { /* XVID_PLG_AFTER */ |
} else { /* XVID_PLG_AFTER */ |
695 |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
696 |
data.original.csp = XVID_CSP_USER; |
data.original.csp = XVID_CSP_PLANAR; |
697 |
data.original.plane[0] = original->y; |
data.original.plane[0] = original->y; |
698 |
data.original.plane[1] = original->u; |
data.original.plane[1] = original->u; |
699 |
data.original.plane[2] = original->v; |
data.original.plane[2] = original->v; |
743 |
data.mblks = frame->sStat.mblks; |
data.mblks = frame->sStat.mblks; |
744 |
data.ublks = frame->sStat.ublks; |
data.ublks = frame->sStat.ublks; |
745 |
|
|
746 |
if (stats) { |
/* New code */ |
747 |
stats->type = coding2type(frame->coding_type); |
data.stats.type = coding2type(frame->coding_type); |
748 |
stats->quant = frame->quant; |
data.stats.quant = frame->quant; |
749 |
stats->vol_flags = frame->vol_flags; |
data.stats.vol_flags = frame->vol_flags; |
750 |
stats->vop_flags = frame->vop_flags; |
data.stats.vop_flags = frame->vop_flags; |
751 |
stats->length = frame->length; |
data.stats.length = frame->length; |
752 |
stats->hlength = frame->length - (frame->sStat.iTextBits / 8); |
data.stats.hlength = frame->length - (frame->sStat.iTextBits / 8); |
753 |
stats->kblks = frame->sStat.kblks; |
data.stats.kblks = frame->sStat.kblks; |
754 |
stats->mblks = frame->sStat.mblks; |
data.stats.mblks = frame->sStat.mblks; |
755 |
stats->ublks = frame->sStat.ublks; |
data.stats.ublks = frame->sStat.ublks; |
756 |
stats->sse_y = data.sse_y; |
data.stats.sse_y = data.sse_y; |
757 |
stats->sse_u = data.sse_u; |
data.stats.sse_u = data.sse_u; |
758 |
stats->sse_v = data.sse_v; |
data.stats.sse_v = data.sse_v; |
759 |
} |
|
760 |
|
if (stats) |
761 |
|
*stats = data.stats; |
762 |
} |
} |
763 |
|
|
764 |
/* call plugins */ |
/* call plugins */ |
777 |
*type = data.type; |
*type = data.type; |
778 |
*quant = data.quant > 0 ? data.quant : 2; /* default */ |
*quant = data.quant > 0 ? data.quant : 2; /* default */ |
779 |
|
|
780 |
|
frame->vol_flags = data.vol_flags; |
781 |
|
frame->vop_flags = data.vop_flags; |
782 |
|
frame->motion_flags = data.motion_flags; |
783 |
|
|
784 |
|
} else if (opt == XVID_PLG_FRAME) { |
785 |
|
|
786 |
if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQDQUANTS)) { |
787 |
for (j=0; j<pEnc->mbParam.mb_height; j++) |
for (j=0; j<pEnc->mbParam.mb_height; j++) |
788 |
for (i=0; i<pEnc->mbParam.mb_width; i++) { |
for (i=0; i<pEnc->mbParam.mb_width; i++) { |
794 |
frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0; |
frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0; |
795 |
} |
} |
796 |
} |
} |
797 |
|
frame->mbs[0].quant = data.quant; /* FRAME will not affect the quant in stats */ |
|
frame->vol_flags = data.vol_flags; |
|
|
frame->vop_flags = data.vop_flags; |
|
|
frame->motion_flags = data.motion_flags; |
|
|
} |
|
798 |
} |
} |
799 |
|
|
800 |
|
|
801 |
|
} |
802 |
|
|
803 |
|
|
804 |
static __inline void inc_frame_num(Encoder * pEnc) |
static __inline void inc_frame_num(Encoder * pEnc) |
816 |
pEnc->m_framenum--; /* debug ticker */ |
pEnc->m_framenum--; /* debug ticker */ |
817 |
} |
} |
818 |
|
|
819 |
|
static __inline void |
820 |
|
MBSetDquant(MACROBLOCK * pMB, int x, int y, MBParam * mbParam) |
821 |
|
{ |
822 |
|
if (pMB->cbp == 0) { |
823 |
|
/* we want to code dquant but the quantizer value will not be used yet |
824 |
|
let's find out if we can postpone dquant to next MB |
825 |
|
*/ |
826 |
|
if (x == mbParam->mb_width-1 && y == mbParam->mb_height-1) { |
827 |
|
pMB->dquant = 0; /* it's the last MB of all, the easiest case */ |
828 |
|
return; |
829 |
|
} else { |
830 |
|
MACROBLOCK * next = pMB + 1; |
831 |
|
const MACROBLOCK * prev = pMB - 1; |
832 |
|
if (next->mode != MODE_INTER4V && next->mode != MODE_NOT_CODED) |
833 |
|
/* mode allows dquant change in the future */ |
834 |
|
if (abs(next->quant - prev->quant) <= 2) { |
835 |
|
/* quant change is not out of range */ |
836 |
|
pMB->quant = prev->quant; |
837 |
|
pMB->dquant = 0; |
838 |
|
next->dquant = next->quant - prev->quant; |
839 |
|
return; |
840 |
|
} |
841 |
|
} |
842 |
|
} |
843 |
|
/* couldn't skip this dquant */ |
844 |
|
pMB->mode = MODE_INTER_Q; |
845 |
|
} |
846 |
|
|
847 |
|
|
848 |
|
|
849 |
static __inline void |
static __inline void |
853 |
pCur->ticks = (int32_t)pCur->stamp % time_base; |
pCur->ticks = (int32_t)pCur->stamp % time_base; |
854 |
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) ; |
855 |
|
|
856 |
/* HEAVY DEBUG OUTPUT remove when timecodes prove to be stable */ |
#if 0 /* HEAVY DEBUG OUTPUT */ |
857 |
|
fprintf(stderr,"WriteVop: %d - %d \n", |
|
/* fprintf(stderr,"WriteVop: %d - %d \n", |
|
858 |
((int32_t)pCur->stamp / time_base), ((int32_t)pRef->stamp / time_base)); |
((int32_t)pCur->stamp / time_base), ((int32_t)pRef->stamp / time_base)); |
859 |
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", |
860 |
pCur->coding_type, pCur->stamp, pRef->stamp, time_base); |
pCur->coding_type, pCur->stamp, pRef->stamp, time_base); |
861 |
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", |
862 |
pCur->coding_type, pCur->seconds, pCur->ticks, pRef->seconds, pRef->ticks); |
pCur->coding_type, pCur->seconds, pCur->ticks, pRef->seconds, pRef->ticks); |
863 |
|
#endif |
864 |
|
} |
865 |
|
|
866 |
*/ |
static int |
867 |
|
gcd(int a, int b) |
868 |
|
{ |
869 |
|
int r ; |
870 |
|
|
871 |
|
if (b > a) { |
872 |
|
r = a; |
873 |
|
a = b; |
874 |
|
b = r; |
875 |
} |
} |
876 |
|
|
877 |
|
while ((r = a % b)) { |
878 |
|
a = b; |
879 |
|
b = r; |
880 |
|
} |
881 |
|
return b; |
882 |
|
} |
883 |
|
|
884 |
|
static void |
885 |
|
simplify_par(int *par_width, int *par_height) |
886 |
|
{ |
887 |
|
|
888 |
|
int _par_width = (!*par_width) ? 1 : (*par_width<0) ? -*par_width: *par_width; |
889 |
|
int _par_height = (!*par_height) ? 1 : (*par_height<0) ? -*par_height: *par_height; |
890 |
|
int divisor = gcd(_par_width, _par_height); |
891 |
|
|
892 |
|
_par_width /= divisor; |
893 |
|
_par_height /= divisor; |
894 |
|
|
895 |
|
/* 2^8 precision maximum */ |
896 |
|
if (_par_width>255 || _par_height>255) { |
897 |
|
float div; |
898 |
|
emms(); |
899 |
|
if (_par_width>_par_height) |
900 |
|
div = (float)_par_width/255; |
901 |
|
else |
902 |
|
div = (float)_par_height/255; |
903 |
|
|
904 |
|
_par_width = (int)((float)_par_width/div); |
905 |
|
_par_height = (int)((float)_par_height/div); |
906 |
|
} |
907 |
|
|
908 |
|
*par_width = _par_width; |
909 |
|
*par_height = _par_height; |
910 |
|
|
911 |
|
return; |
912 |
|
} |
913 |
|
|
914 |
|
|
915 |
/***************************************************************************** |
/***************************************************************************** |
1032 |
tmp = pEnc->current->seconds; |
tmp = pEnc->current->seconds; |
1033 |
pEnc->current->seconds = 0; /* force time_base = 0 */ |
pEnc->current->seconds = 0; /* force time_base = 0 */ |
1034 |
|
|
1035 |
BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0); |
BitstreamWriteVopHeader(&bs, &pEnc->mbParam, pEnc->current, 0, pEnc->current->quant); |
1036 |
BitstreamPad(&bs); |
BitstreamPad(&bs); |
1037 |
pEnc->current->seconds = tmp; |
pEnc->current->seconds = tmp; |
1038 |
|
|
1077 |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
1078 |
|
|
1079 |
/* convert B-VOP to P-VOP */ |
/* convert B-VOP to P-VOP */ |
1080 |
pEnc->current->quant = ((pEnc->current->quant*100) - pEnc->mbParam.bquant_offset) / pEnc->mbParam.bquant_ratio; |
pEnc->current->quant = 100*pEnc->current->quant - pEnc->mbParam.bquant_offset; |
1081 |
|
pEnc->current->quant += pEnc->mbParam.bquant_ratio - 1; /* to avoid rouding issues */ |
1082 |
|
pEnc->current->quant /= pEnc->mbParam.bquant_ratio; |
1083 |
|
|
1084 |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
1085 |
image_copy(&pEnc->sOriginal, &pEnc->current->image, |
image_copy(&pEnc->sOriginal, &pEnc->current->image, |
1089 |
DPRINTF(XVID_DEBUG_DEBUG,"*** PFRAME bf: head=%i tail=%i queue: head=%i tail=%i size=%i\n", |
DPRINTF(XVID_DEBUG_DEBUG,"*** PFRAME bf: head=%i tail=%i queue: head=%i tail=%i size=%i\n", |
1090 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
1091 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
1092 |
|
pEnc->mbParam.frame_drop_ratio = -1; /* it must be a coded vop */ |
1093 |
|
|
1094 |
FrameCodeP(pEnc, &bs, 1, 0); |
FrameCodeP(pEnc, &bs, 1, 0); |
1095 |
|
|
1125 |
|
|
1126 |
pEnc->current->fincr = pEnc->mbParam.fincr>0 ? pEnc->mbParam.fincr : frame->fincr; |
pEnc->current->fincr = pEnc->mbParam.fincr>0 ? pEnc->mbParam.fincr : frame->fincr; |
1127 |
inc_frame_num(pEnc); |
inc_frame_num(pEnc); |
1128 |
pEnc->current->vol_flags = pEnc->mbParam.vol_flags; |
pEnc->current->vol_flags = frame->vol_flags; |
1129 |
pEnc->current->vop_flags = frame->vop_flags; |
pEnc->current->vop_flags = frame->vop_flags; |
1130 |
pEnc->current->motion_flags = frame->motion; |
pEnc->current->motion_flags = frame->motion; |
1131 |
pEnc->current->fcode = pEnc->mbParam.m_fcode; |
pEnc->current->fcode = pEnc->mbParam.m_fcode; |
1155 |
}else{ |
}else{ |
1156 |
type = MEanalysis(&pEnc->reference->image, pEnc->current, |
type = MEanalysis(&pEnc->reference->image, pEnc->current, |
1157 |
&pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval, |
&pEnc->mbParam, pEnc->mbParam.iMaxKeyInterval, |
1158 |
pEnc->iFrameNum, pEnc->bframenum_tail, xFrame->bframe_threshold); |
pEnc->iFrameNum, pEnc->bframenum_tail, xFrame->bframe_threshold, |
1159 |
|
(pEnc->bframes) ? pEnc->bframes[pEnc->bframenum_head]->mbs: NULL); |
1160 |
} |
} |
1161 |
} |
} |
1162 |
|
|
1163 |
|
if (type != I_VOP) |
1164 |
|
pEnc->current->vol_flags = pEnc->mbParam.vol_flags; /* don't allow VOL changes here */ |
1165 |
|
|
1166 |
/* bframes buffer overflow check */ |
/* bframes buffer overflow check */ |
1167 |
if (type == B_VOP && pEnc->bframenum_tail >= pEnc->mbParam.max_bframes) { |
if (type == B_VOP && pEnc->bframenum_tail >= pEnc->mbParam.max_bframes) { |
1168 |
type = P_VOP; |
type = P_VOP; |
1172 |
|
|
1173 |
if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { |
if ((pEnc->current->vop_flags & XVID_VOP_DEBUG)) { |
1174 |
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, |
1175 |
"%i st:%i if:%i", pEnc->current->frame_num, pEnc->current->stamp, pEnc->iFrameNum); |
"%d st:%lld if:%d", pEnc->current->frame_num, pEnc->current->stamp, pEnc->iFrameNum); |
1176 |
} |
} |
1177 |
|
|
1178 |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1251 |
} |
} |
1252 |
|
|
1253 |
/* convert B-VOP quant to P-VOP */ |
/* convert B-VOP quant to P-VOP */ |
1254 |
pEnc->current->quant = ((pEnc->current->quant*100) - pEnc->mbParam.bquant_offset) / pEnc->mbParam.bquant_ratio; |
pEnc->current->quant = 100*pEnc->current->quant - pEnc->mbParam.bquant_offset; |
1255 |
|
pEnc->current->quant += pEnc->mbParam.bquant_ratio - 1; /* to avoid rouding issues */ |
1256 |
|
pEnc->current->quant /= pEnc->mbParam.bquant_ratio; |
1257 |
type = P_VOP; |
type = P_VOP; |
1258 |
} |
} |
1259 |
|
|
1275 |
pEnc->iFrameNum = 1; |
pEnc->iFrameNum = 1; |
1276 |
|
|
1277 |
/* ---- update vol flags at IVOP ----------- */ |
/* ---- update vol flags at IVOP ----------- */ |
1278 |
pEnc->current->vol_flags = pEnc->mbParam.vol_flags = frame->vol_flags; |
pEnc->mbParam.vol_flags = pEnc->current->vol_flags; |
1279 |
|
|
1280 |
|
/* Aspect ratio */ |
1281 |
switch(frame->par) { |
switch(frame->par) { |
1282 |
case XVID_PAR_11_VGA: |
case XVID_PAR_11_VGA: |
1283 |
case XVID_PAR_43_PAL: |
case XVID_PAR_43_PAL: |
1288 |
pEnc->mbParam.par = frame->par; |
pEnc->mbParam.par = frame->par; |
1289 |
break; |
break; |
1290 |
default: |
default: |
1291 |
pEnc->mbParam.par = XVID_PAR_EXT; |
pEnc->mbParam.par = XVID_PAR_11_VGA; |
1292 |
break; |
break; |
1293 |
} |
} |
1294 |
pEnc->mbParam.par_width = (frame->par_width)?frame->par_width:1; |
|
1295 |
pEnc->mbParam.par_height = (frame->par_height)?frame->par_height:1; |
/* For extended PAR only, we try to sanityse/simplify par values */ |
1296 |
|
if (pEnc->mbParam.par == XVID_PAR_EXT) { |
1297 |
|
pEnc->mbParam.par_width = frame->par_width; |
1298 |
|
pEnc->mbParam.par_height = frame->par_height; |
1299 |
|
simplify_par(&pEnc->mbParam.par_width, &pEnc->mbParam.par_height); |
1300 |
|
} |
1301 |
|
|
1302 |
if ((pEnc->mbParam.vol_flags & XVID_VOL_MPEGQUANT)) { |
if ((pEnc->mbParam.vol_flags & XVID_VOL_MPEGQUANT)) { |
1303 |
if (frame->quant_intra_matrix != NULL) |
if (frame->quant_intra_matrix != NULL) |
1304 |
set_intra_matrix(frame->quant_intra_matrix); |
set_intra_matrix(pEnc->mbParam.mpeg_quant_matrices, frame->quant_intra_matrix); |
1305 |
if (frame->quant_inter_matrix != NULL) |
if (frame->quant_inter_matrix != NULL) |
1306 |
set_inter_matrix(frame->quant_inter_matrix); |
set_inter_matrix(pEnc->mbParam.mpeg_quant_matrices, frame->quant_inter_matrix); |
1307 |
} |
} |
1308 |
|
|
1309 |
/* prevent vol/vop misuse */ |
/* prevent vol/vop misuse */ |
1343 |
pEnc->mbParam.edged_width, pEnc->mbParam.height); |
pEnc->mbParam.edged_width, pEnc->mbParam.height); |
1344 |
} |
} |
1345 |
|
|
1346 |
FrameCodeP(pEnc, &bs, 1, 0); |
if ( FrameCodeP(pEnc, &bs, 1, 0) == 0 ) { |
1347 |
|
/* N-VOP, we mustn't code b-frames yet */ |
1348 |
|
call_plugins(pEnc, pEnc->current, &pEnc->sOriginal, XVID_PLG_AFTER, 0, 0, stats); |
1349 |
|
goto done; |
1350 |
|
} |
1351 |
} |
} |
1352 |
|
|
1353 |
|
|
1385 |
|
|
1386 |
static void SetMacroblockQuants(MBParam * const pParam, FRAMEINFO * frame) |
static void SetMacroblockQuants(MBParam * const pParam, FRAMEINFO * frame) |
1387 |
{ |
{ |
1388 |
unsigned int i,j; |
unsigned int i; |
1389 |
int quant = frame->quant; |
MACROBLOCK * pMB = frame->mbs; |
1390 |
|
int quant = frame->mbs[0].quant; /* set by XVID_PLG_FRAME */ |
1391 |
if (quant > 31) |
if (quant > 31) |
1392 |
frame->quant = quant = 31; |
frame->quant = quant = 31; |
1393 |
else if (quant < 1) |
else if (quant < 1) |
1394 |
frame->quant = quant = 1; |
frame->quant = quant = 1; |
1395 |
|
|
1396 |
for (j=0; j<pParam->mb_height; j++) |
for (i = 0; i < pParam->mb_height * pParam->mb_width; i++) { |
|
for (i=0; i<pParam->mb_width; i++) { |
|
|
MACROBLOCK * pMB = &frame->mbs[j*pParam->mb_width + i]; |
|
1397 |
quant += pMB->dquant; |
quant += pMB->dquant; |
1398 |
if (quant > 31) |
if (quant > 31) |
1399 |
quant = 31; |
quant = 31; |
1400 |
else if (quant < 1) |
else if (quant < 1) |
1401 |
quant = 1; |
quant = 1; |
1402 |
pMB->quant = quant; |
pMB->quant = quant; |
1403 |
|
pMB++; |
1404 |
} |
} |
1405 |
} |
} |
1406 |
|
|
1448 |
start_timer(); |
start_timer(); |
1449 |
image_setedges(&pEnc->current->image, |
image_setedges(&pEnc->current->image, |
1450 |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
1451 |
pEnc->mbParam.width, pEnc->mbParam.height); |
pEnc->mbParam.width, pEnc->mbParam.height, 0); |
1452 |
stop_edges_timer(); |
stop_edges_timer(); |
1453 |
} |
} |
1454 |
|
|
1456 |
pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type; |
pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type; |
1457 |
pEnc->current->coding_type = I_VOP; |
pEnc->current->coding_type = I_VOP; |
1458 |
|
|
1459 |
|
call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL); |
1460 |
|
|
1461 |
SetMacroblockQuants(&pEnc->mbParam, pEnc->current); |
SetMacroblockQuants(&pEnc->mbParam, pEnc->current); |
1462 |
|
|
1463 |
BitstreamWriteVolHeader(bs, &pEnc->mbParam); |
BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current); |
1464 |
|
|
1465 |
set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); |
set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); |
1466 |
|
|
1467 |
BitstreamPad(bs); |
BitstreamPad(bs); |
1468 |
|
|
1469 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1, pEnc->current->mbs[0].quant); |
1470 |
|
|
1471 |
pEnc->current->sStat.iTextBits = 0; |
pEnc->current->sStat.iTextBits = 0; |
1472 |
pEnc->current->sStat.kblks = mb_width * mb_height; |
pEnc->current->sStat.kblks = mb_width * mb_height; |
1511 |
pEnc->fMvPrevSigma = -1; |
pEnc->fMvPrevSigma = -1; |
1512 |
pEnc->mbParam.m_fcode = 2; |
pEnc->mbParam.m_fcode = 2; |
1513 |
|
|
1514 |
|
pEnc->current->is_edged = 0; /* not edged */ |
1515 |
|
pEnc->current->is_interpolated = -1; /* not interpolated (fake rounding -1) */ |
1516 |
|
|
1517 |
return 1; /* intra */ |
return 1; /* intra */ |
1518 |
} |
} |
1519 |
|
|
1544 |
MBParam * const pParam = &pEnc->mbParam; |
MBParam * const pParam = &pEnc->mbParam; |
1545 |
int mb_width = pParam->mb_width; |
int mb_width = pParam->mb_width; |
1546 |
int mb_height = pParam->mb_height; |
int mb_height = pParam->mb_height; |
1547 |
|
int coded = 1; |
1548 |
|
|
1549 |
|
|
1550 |
/* IMAGE *pCurrent = ¤t->image; */ |
/* IMAGE *pCurrent = ¤t->image; */ |
1557 |
} |
} |
1558 |
|
|
1559 |
|
|
1560 |
|
if (!reference->is_edged) { |
1561 |
start_timer(); |
start_timer(); |
1562 |
image_setedges(pRef, pParam->edged_width, pParam->edged_height, |
image_setedges(pRef, pParam->edged_width, pParam->edged_height, |
1563 |
pParam->width, pParam->height); |
pParam->width, pParam->height, 0); |
1564 |
stop_edges_timer(); |
stop_edges_timer(); |
1565 |
|
reference->is_edged = 1; |
1566 |
|
} |
1567 |
|
|
1568 |
pParam->m_rounding_type = 1 - pParam->m_rounding_type; |
pParam->m_rounding_type = 1 - pParam->m_rounding_type; |
1569 |
current->rounding_type = pParam->m_rounding_type; |
current->rounding_type = pParam->m_rounding_type; |
1575 |
iLimit = mb_width * mb_height + 1; |
iLimit = mb_width * mb_height + 1; |
1576 |
|
|
1577 |
if ((current->vop_flags & XVID_VOP_HALFPEL)) { |
if ((current->vop_flags & XVID_VOP_HALFPEL)) { |
1578 |
|
if (reference->is_interpolated != current->rounding_type) { |
1579 |
start_timer(); |
start_timer(); |
1580 |
image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV, |
image_interpolate(pRef, &pEnc->vInterH, &pEnc->vInterV, |
1581 |
&pEnc->vInterHV, pParam->edged_width, |
&pEnc->vInterHV, pParam->edged_width, |
1583 |
(pParam->vol_flags & XVID_VOL_QUARTERPEL), |
(pParam->vol_flags & XVID_VOL_QUARTERPEL), |
1584 |
current->rounding_type); |
current->rounding_type); |
1585 |
stop_inter_timer(); |
stop_inter_timer(); |
1586 |
|
reference->is_interpolated = current->rounding_type; |
1587 |
|
} |
1588 |
} |
} |
1589 |
|
|
1590 |
current->coding_type = P_VOP; |
current->coding_type = P_VOP; |
1591 |
|
|
1592 |
|
call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL); |
1593 |
|
|
1594 |
SetMacroblockQuants(&pEnc->mbParam, current); |
SetMacroblockQuants(&pEnc->mbParam, current); |
1595 |
|
|
1608 |
&pEnc->vInterH, |
&pEnc->vInterH, |
1609 |
&pEnc->vInterV, |
&pEnc->vInterV, |
1610 |
&pEnc->vInterHV); |
&pEnc->vInterHV); |
1611 |
gmcval += /*current->quant */ 2 * (int)(pParam->mb_width*pParam->mb_height); |
} else { |
|
} |
|
|
|
|
1612 |
gmcval = globalSAD(¤t->warp, pParam, current->mbs, |
gmcval = globalSAD(¤t->warp, pParam, current->mbs, |
1613 |
current, |
current, |
1614 |
&reference->image, |
&reference->image, |
1615 |
¤t->image, |
¤t->image, |
1616 |
pEnc->vGMC.y); |
pEnc->vGMC.y); |
1617 |
|
} |
1618 |
|
|
1619 |
gmcval += /*current->quant*/ 2 * (int)(pParam->mb_width*pParam->mb_height); |
gmcval += /*current->quant*/ 2 * (int)(pParam->mb_width*pParam->mb_height); |
1620 |
|
|
1621 |
/* 1st '3': 3 warpoints, 2nd '3': 16th pel res (2<<3) */ |
/* 1st '3': 3 warpoints, 2nd '3': 16th pel res (2<<3) */ |
1656 |
|
|
1657 |
set_timecodes(current,reference,pParam->fbase); |
set_timecodes(current,reference,pParam->fbase); |
1658 |
if (vol_header) |
if (vol_header) |
1659 |
{ BitstreamWriteVolHeader(bs, &pEnc->mbParam); |
{ BitstreamWriteVolHeader(bs, &pEnc->mbParam, current); |
1660 |
BitstreamPad(bs); |
BitstreamPad(bs); |
1661 |
} |
} |
1662 |
|
|
1663 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 1, current->mbs[0].quant); |
1664 |
|
|
1665 |
current->sStat.iTextBits = current->sStat.iMvSum = current->sStat.iMvCount = |
current->sStat.iTextBits = current->sStat.iMvSum = current->sStat.iMvCount = |
1666 |
current->sStat.kblks = current->sStat.mblks = current->sStat.ublks = 0; |
current->sStat.kblks = current->sStat.mblks = current->sStat.ublks = 0; |
1708 |
|
|
1709 |
stop_comp_timer(); |
stop_comp_timer(); |
1710 |
|
|
|
if (pMB->dquant != 0) { |
|
|
pMB->mode = MODE_INTER_Q; |
|
|
} |
|
|
|
|
1711 |
pMB->field_pred = 0; |
pMB->field_pred = 0; |
1712 |
|
|
1713 |
if (pMB->mode != MODE_NOT_CODED) |
if (pMB->mode != MODE_NOT_CODED) |
1716 |
dct_codes, qcoeff); |
dct_codes, qcoeff); |
1717 |
} |
} |
1718 |
|
|
1719 |
|
if (pMB->dquant != 0) |
1720 |
|
MBSetDquant(pMB, x, y, &pEnc->mbParam); |
1721 |
|
|
1722 |
|
|
1723 |
if (pMB->cbp || pMB->mvs[0].x || pMB->mvs[0].y || |
if (pMB->cbp || pMB->mvs[0].x || pMB->mvs[0].y || |
1724 |
pMB->mvs[1].x || pMB->mvs[1].y || pMB->mvs[2].x || |
pMB->mvs[1].x || pMB->mvs[1].y || pMB->mvs[2].x || |
1725 |
pMB->mvs[2].y || pMB->mvs[3].x || pMB->mvs[3].y) { |
pMB->mvs[2].y || pMB->mvs[3].x || pMB->mvs[3].y) { |
1872 |
#if 0 |
#if 0 |
1873 |
DPRINTF(XVID_DEBUG_DEBUG, "kmu %i %i %i\n", current->sStat.kblks, current->sStat.mblks, current->sStat.ublks); |
DPRINTF(XVID_DEBUG_DEBUG, "kmu %i %i %i\n", current->sStat.kblks, current->sStat.mblks, current->sStat.ublks); |
1874 |
#endif |
#endif |
1875 |
if (current->sStat.kblks + current->sStat.mblks < |
if (current->sStat.kblks + current->sStat.mblks <= |
1876 |
(pParam->frame_drop_ratio * mb_width * mb_height) / 100) |
(pParam->frame_drop_ratio * mb_width * mb_height) / 100) |
1877 |
{ |
{ |
1878 |
current->sStat.kblks = current->sStat.mblks = 0; |
current->sStat.kblks = current->sStat.mblks = 0; |
1881 |
BitstreamReset(bs); |
BitstreamReset(bs); |
1882 |
|
|
1883 |
set_timecodes(current,reference,pParam->fbase); |
set_timecodes(current,reference,pParam->fbase); |
1884 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 0); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, current, 0, current->mbs[0].quant); |
1885 |
|
|
1886 |
/* copy reference frame details into the current frame */ |
/* copy reference frame details into the current frame */ |
1887 |
current->quant = reference->quant; |
current->quant = reference->quant; |
1889 |
current->rounding_type = reference->rounding_type; |
current->rounding_type = reference->rounding_type; |
1890 |
current->fcode = reference->fcode; |
current->fcode = reference->fcode; |
1891 |
current->bcode = reference->bcode; |
current->bcode = reference->bcode; |
1892 |
|
current->stamp = reference->stamp; |
1893 |
image_copy(¤t->image, &reference->image, pParam->edged_width, pParam->height); |
image_copy(¤t->image, &reference->image, pParam->edged_width, pParam->height); |
1894 |
memcpy(current->mbs, reference->mbs, sizeof(MACROBLOCK) * mb_width * mb_height); |
memcpy(current->mbs, reference->mbs, sizeof(MACROBLOCK) * mb_width * mb_height); |
1895 |
|
coded = 0; |
1896 |
|
|
1897 |
|
} else { |
1898 |
|
|
1899 |
|
pEnc->current->is_edged = 0; /* not edged */ |
1900 |
|
pEnc->current->is_interpolated = -1; /* not interpolated (fake rounding -1) */ |
1901 |
|
|
1902 |
|
/* what was this frame's interpolated reference will become |
1903 |
|
forward (past) reference in b-frame coding */ |
1904 |
|
|
1905 |
|
image_swap(&pEnc->vInterH, &pEnc->f_refh); |
1906 |
|
image_swap(&pEnc->vInterV, &pEnc->f_refv); |
1907 |
|
image_swap(&pEnc->vInterHV, &pEnc->f_refhv); |
1908 |
} |
} |
1909 |
|
|
1910 |
/* XXX: debug |
/* XXX: debug |
1926 |
|
|
1927 |
current->length = (BitstreamPos(bs) - bits) / 8; |
current->length = (BitstreamPos(bs) - bits) / 8; |
1928 |
|
|
1929 |
return 0; /* inter */ |
return coded; |
1930 |
} |
} |
1931 |
|
|
1932 |
|
|
1958 |
#endif |
#endif |
1959 |
|
|
1960 |
/* forward */ |
/* forward */ |
1961 |
|
if (!pEnc->reference->is_edged) { |
1962 |
image_setedges(f_ref, pEnc->mbParam.edged_width, |
image_setedges(f_ref, pEnc->mbParam.edged_width, |
1963 |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
1964 |
pEnc->mbParam.height); |
pEnc->mbParam.height, 0); |
1965 |
|
pEnc->current->is_edged = 1; |
1966 |
|
} |
1967 |
|
|
1968 |
|
if (pEnc->reference->is_interpolated != 0) { |
1969 |
start_timer(); |
start_timer(); |
1970 |
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, |
1971 |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
1972 |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); |
1973 |
stop_inter_timer(); |
stop_inter_timer(); |
1974 |
|
pEnc->reference->is_interpolated = 0; |
1975 |
|
} |
1976 |
|
|
1977 |
/* backward */ |
/* backward */ |
1978 |
|
if (!pEnc->current->is_edged) { |
1979 |
image_setedges(b_ref, pEnc->mbParam.edged_width, |
image_setedges(b_ref, pEnc->mbParam.edged_width, |
1980 |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
pEnc->mbParam.edged_height, pEnc->mbParam.width, |
1981 |
pEnc->mbParam.height); |
pEnc->mbParam.height, 0); |
1982 |
|
pEnc->current->is_edged = 1; |
1983 |
|
} |
1984 |
|
|
1985 |
|
if (pEnc->current->is_interpolated != 0) { |
1986 |
start_timer(); |
start_timer(); |
1987 |
image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
image_interpolate(b_ref, &pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
1988 |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
pEnc->mbParam.edged_width, pEnc->mbParam.edged_height, |
1989 |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); |
(pEnc->mbParam.vol_flags & XVID_VOL_QUARTERPEL), 0); |
1990 |
stop_inter_timer(); |
stop_inter_timer(); |
1991 |
|
pEnc->current->is_interpolated = 0; |
1992 |
|
} |
1993 |
|
|
1994 |
|
frame->coding_type = B_VOP; |
1995 |
|
call_plugins(pEnc, pEnc->current, NULL, XVID_PLG_FRAME, NULL, NULL, NULL); |
1996 |
|
|
1997 |
start_timer(); |
start_timer(); |
1998 |
MotionEstimationBVOP(&pEnc->mbParam, frame, |
MotionEstimationBVOP(&pEnc->mbParam, frame, |
2004 |
&pEnc->vInterV, &pEnc->vInterHV); |
&pEnc->vInterV, &pEnc->vInterHV); |
2005 |
stop_motion_timer(); |
stop_motion_timer(); |
2006 |
|
|
|
frame->coding_type = B_VOP; |
|
|
|
|
2007 |
set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase); |
set_timecodes(frame, pEnc->reference,pEnc->mbParam.fbase); |
2008 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, frame, 1, frame->quant); |
2009 |
|
|
2010 |
frame->sStat.iTextBits = 0; |
frame->sStat.iTextBits = 0; |
2011 |
frame->sStat.iMvSum = 0; |
frame->sStat.iMvSum = 0; |
2017 |
for (y = 0; y < pEnc->mbParam.mb_height; y++) { |
for (y = 0; y < pEnc->mbParam.mb_height; y++) { |
2018 |
for (x = 0; x < pEnc->mbParam.mb_width; x++) { |
for (x = 0; x < pEnc->mbParam.mb_width; x++) { |
2019 |
MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width]; |
MACROBLOCK * const mb = &frame->mbs[x + y * pEnc->mbParam.mb_width]; |
|
int direction = frame->vop_flags & XVID_VOP_ALTERNATESCAN ? 2 : 0; |
|
2020 |
|
|
2021 |
/* decoder ignores mb when refence block is INTER(0,0), CBP=0 */ |
/* decoder ignores mb when refence block is INTER(0,0), CBP=0 */ |
2022 |
if (mb->mode == MODE_NOT_CODED) { |
if (mb->mode == MODE_NOT_CODED) { |
2023 |
/* mb->mvs[0].x = mb->mvs[0].y = mb->cbp = 0; */ |
if (pEnc->mbParam.plugin_flags & XVID_REQORIGINAL) { |
2024 |
|
MBMotionCompensation(mb, x, y, f_ref, NULL, f_ref, NULL, NULL, &frame->image, |
2025 |
|
NULL, 0, 0, pEnc->mbParam.edged_width, 0, 0, 0); |
2026 |
|
} |
2027 |
|
|
2028 |
continue; |
continue; |
2029 |
} |
} |
2030 |
|
|