250 |
if (pEnc->current->mbs == NULL || pEnc->reference->mbs == NULL) |
if (pEnc->current->mbs == NULL || pEnc->reference->mbs == NULL) |
251 |
goto xvid_err_memory2; |
goto xvid_err_memory2; |
252 |
|
|
253 |
|
/* allocate quant matrix memory */ |
254 |
|
|
255 |
|
pEnc->mbParam.mpeg_quant_matrices = |
256 |
|
xvid_malloc(sizeof(uint16_t) * 64 * 8, CACHE_LINE); |
257 |
|
|
258 |
|
if (pEnc->mbParam.mpeg_quant_matrices == NULL) |
259 |
|
goto xvid_err_memory2a; |
260 |
|
|
261 |
/* allocate interpolation image memory */ |
/* allocate interpolation image memory */ |
262 |
|
|
263 |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
411 |
create->handle = (void *) pEnc; |
create->handle = (void *) pEnc; |
412 |
|
|
413 |
init_timer(); |
init_timer(); |
414 |
|
init_mpeg_matrix(pEnc->mbParam.mpeg_quant_matrices); |
415 |
|
|
416 |
return 0; /* ok */ |
return 0; /* ok */ |
417 |
|
|
478 |
image_destroy(&pEnc->vGMC, pEnc->mbParam.edged_width, |
image_destroy(&pEnc->vGMC, pEnc->mbParam.edged_width, |
479 |
pEnc->mbParam.edged_height); |
pEnc->mbParam.edged_height); |
480 |
|
|
481 |
|
xvid_err_memory2a: |
482 |
|
xvid_free(pEnc->mbParam.mpeg_quant_matrices); |
483 |
|
|
484 |
xvid_err_memory2: |
xvid_err_memory2: |
485 |
xvid_free(pEnc->current->mbs); |
xvid_free(pEnc->current->mbs); |
608 |
xvid_free(pEnc->plugins); |
xvid_free(pEnc->plugins); |
609 |
} |
} |
610 |
|
|
611 |
|
xvid_free(pEnc->mbParam.mpeg_quant_matrices); |
612 |
|
|
613 |
if (pEnc->num_plugins>0) |
if (pEnc->num_plugins>0) |
614 |
xvid_free(pEnc->zones); |
xvid_free(pEnc->zones); |
615 |
|
|
789 |
frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0; |
frame->mbs[j*pEnc->mbParam.mb_width + i].dquant = 0; |
790 |
} |
} |
791 |
} |
} |
792 |
frame->mbs[0].quant = data.quant; /* BEFORE2 will not affect the quant in stats */ |
frame->mbs[0].quant = data.quant; /* FRAME will not affect the quant in stats */ |
793 |
} |
} |
794 |
|
|
795 |
|
|
796 |
} |
} |
797 |
|
|
798 |
|
|
|
|
|
|
|
|
799 |
static __inline void inc_frame_num(Encoder * pEnc) |
static __inline void inc_frame_num(Encoder * pEnc) |
800 |
{ |
{ |
801 |
pEnc->current->frame_num = pEnc->m_framenum; |
pEnc->current->frame_num = pEnc->m_framenum; |
811 |
pEnc->m_framenum--; /* debug ticker */ |
pEnc->m_framenum--; /* debug ticker */ |
812 |
} |
} |
813 |
|
|
814 |
|
static __inline void |
815 |
|
MBSetDquant(MACROBLOCK * pMB, int x, int y, MBParam * mbParam) |
816 |
|
{ |
817 |
|
if (pMB->cbp == 0) { |
818 |
|
/* we want to code dquant but the quantizer value will not be used yet |
819 |
|
let's find out if we can postpone dquant to next MB |
820 |
|
*/ |
821 |
|
if (x == mbParam->mb_width-1 && y == mbParam->mb_height-1) { |
822 |
|
pMB->dquant = 0; /* it's the last MB of all, the easiest case */ |
823 |
|
return; |
824 |
|
} else { |
825 |
|
MACROBLOCK * next = pMB + 1; |
826 |
|
const MACROBLOCK * prev = pMB - 1; |
827 |
|
if (next->mode != MODE_INTER4V && next->mode != MODE_NOT_CODED) |
828 |
|
/* mode allows dquant change in the future */ |
829 |
|
if (abs(next->quant - prev->quant) <= 2) { |
830 |
|
/* quant change is not out of range */ |
831 |
|
pMB->quant = prev->quant; |
832 |
|
pMB->dquant = 0; |
833 |
|
next->dquant = next->quant - prev->quant; |
834 |
|
return; |
835 |
|
} |
836 |
|
} |
837 |
|
} |
838 |
|
/* couldn't skip this dquant */ |
839 |
|
pMB->mode = MODE_INTER_Q; |
840 |
|
} |
841 |
|
|
842 |
|
|
843 |
|
|
844 |
static __inline void |
static __inline void |
1240 |
|
|
1241 |
if ((pEnc->mbParam.vol_flags & XVID_VOL_MPEGQUANT)) { |
if ((pEnc->mbParam.vol_flags & XVID_VOL_MPEGQUANT)) { |
1242 |
if (frame->quant_intra_matrix != NULL) |
if (frame->quant_intra_matrix != NULL) |
1243 |
set_intra_matrix(frame->quant_intra_matrix); |
set_intra_matrix(pEnc->mbParam.mpeg_quant_matrices, frame->quant_intra_matrix); |
1244 |
if (frame->quant_inter_matrix != NULL) |
if (frame->quant_inter_matrix != NULL) |
1245 |
set_inter_matrix(frame->quant_inter_matrix); |
set_inter_matrix(pEnc->mbParam.mpeg_quant_matrices, frame->quant_inter_matrix); |
1246 |
} |
} |
1247 |
|
|
1248 |
/* prevent vol/vop misuse */ |
/* prevent vol/vop misuse */ |
1642 |
|
|
1643 |
stop_comp_timer(); |
stop_comp_timer(); |
1644 |
|
|
|
if (pMB->dquant != 0) { |
|
|
pMB->mode = MODE_INTER_Q; |
|
|
} |
|
|
|
|
1645 |
pMB->field_pred = 0; |
pMB->field_pred = 0; |
1646 |
|
|
1647 |
if (pMB->mode != MODE_NOT_CODED) |
if (pMB->mode != MODE_NOT_CODED) |
1650 |
dct_codes, qcoeff); |
dct_codes, qcoeff); |
1651 |
} |
} |
1652 |
|
|
1653 |
|
if (pMB->dquant != 0) |
1654 |
|
MBSetDquant(pMB, x, y, &pEnc->mbParam); |
1655 |
|
|
1656 |
|
|
1657 |
if (pMB->cbp || pMB->mvs[0].x || pMB->mvs[0].y || |
if (pMB->cbp || pMB->mvs[0].x || pMB->mvs[0].y || |
1658 |
pMB->mvs[1].x || pMB->mvs[1].y || pMB->mvs[2].x || |
pMB->mvs[1].x || pMB->mvs[1].y || pMB->mvs[2].x || |
1659 |
pMB->mvs[2].y || pMB->mvs[3].x || pMB->mvs[3].y) { |
pMB->mvs[2].y || pMB->mvs[3].x || pMB->mvs[3].y) { |