73 |
****************************************************************************/ |
****************************************************************************/ |
74 |
|
|
75 |
#define ENC_CHECK(X) if(!(X)) return XVID_ERR_FORMAT |
#define ENC_CHECK(X) if(!(X)) return XVID_ERR_FORMAT |
76 |
#define SWAP(A,B) { void * tmp = A; A = B; B = tmp; } |
#define SWAP(_T_,A,B) { _T_ tmp = A; A = B; B = tmp; } |
77 |
|
|
78 |
/***************************************************************************** |
/***************************************************************************** |
79 |
* Local function prototypes |
* Local function prototypes |
713 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
714 |
|
|
715 |
pEnc->bframenum_tail--; |
pEnc->bframenum_tail--; |
716 |
SWAP(pEnc->current, pEnc->reference); |
SWAP(FRAMEINFO *, pEnc->current, pEnc->reference); |
717 |
|
|
718 |
SWAP(pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
SWAP(FRAMEINFO *, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
719 |
|
|
720 |
FrameCodeP(pEnc, &bs, &bits, 1, 0); |
FrameCodeP(pEnc, &bs, &bits, 1, 0); |
721 |
bframes_count = 0; |
bframes_count = 0; |
791 |
if (pEnc->bframenum_dx50bvop != -1) |
if (pEnc->bframenum_dx50bvop != -1) |
792 |
{ |
{ |
793 |
|
|
794 |
SWAP(pEnc->current, pEnc->reference); |
SWAP(FRAMEINFO *, pEnc->current, pEnc->reference); |
795 |
SWAP(pEnc->current, pEnc->bframes[pEnc->bframenum_dx50bvop]); |
SWAP(FRAMEINFO *, pEnc->current, pEnc->bframes[pEnc->bframenum_dx50bvop]); |
796 |
|
|
797 |
if ((pEnc->mbParam.global & XVID_GLOBAL_DEBUG)) { |
if ((pEnc->mbParam.global & XVID_GLOBAL_DEBUG)) { |
798 |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 IVOP"); |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 IVOP"); |
806 |
|
|
807 |
} else if (input_valid) { |
} else if (input_valid) { |
808 |
|
|
809 |
SWAP(pEnc->current, pEnc->reference); |
SWAP(FRAMEINFO *, pEnc->current, pEnc->reference); |
810 |
|
|
811 |
start_timer(); |
start_timer(); |
812 |
if (image_input |
if (image_input |
832 |
|
|
833 |
} else if (pEnc->queue_size > 0) { |
} else if (pEnc->queue_size > 0) { |
834 |
|
|
835 |
SWAP(pEnc->current, pEnc->reference); |
SWAP(FRAMEINFO *, pEnc->current, pEnc->reference); |
836 |
|
|
837 |
image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head]); |
image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head]); |
838 |
pEnc->queue_head = (pEnc->queue_head + 1) % pEnc->mbParam.max_bframes; |
pEnc->queue_head = (pEnc->queue_head + 1) % pEnc->mbParam.max_bframes; |
985 |
pEnc->bframenum_tail--; |
pEnc->bframenum_tail--; |
986 |
pEnc->bframenum_dx50bvop = pEnc->bframenum_tail; |
pEnc->bframenum_dx50bvop = pEnc->bframenum_tail; |
987 |
|
|
988 |
SWAP(pEnc->current, pEnc->bframes[pEnc->bframenum_dx50bvop]); |
SWAP(FRAMEINFO *, pEnc->current, pEnc->bframes[pEnc->bframenum_dx50bvop]); |
989 |
if ((pEnc->mbParam.global & XVID_GLOBAL_DEBUG)) { |
if ((pEnc->mbParam.global & XVID_GLOBAL_DEBUG)) { |
990 |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 BVOP->PVOP"); |
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 100, "DX50 BVOP->PVOP"); |
991 |
} |
} |
1066 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size,pEnc->current->quant); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size,pEnc->current->quant); |
1067 |
|
|
1068 |
/* store frame into bframe buffer & swap ref back to current */ |
/* store frame into bframe buffer & swap ref back to current */ |
1069 |
SWAP(pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
SWAP(FRAMEINFO *, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
1070 |
SWAP(pEnc->current, pEnc->reference); |
SWAP(FRAMEINFO *, pEnc->current, pEnc->reference); |
1071 |
|
|
1072 |
pEnc->bframenum_tail++; |
pEnc->bframenum_tail++; |
1073 |
|
|
1147 |
ENC_CHECK(pFrame->bitstream); |
ENC_CHECK(pFrame->bitstream); |
1148 |
ENC_CHECK(pFrame->image); |
ENC_CHECK(pFrame->image); |
1149 |
|
|
1150 |
SWAP(pEnc->current, pEnc->reference); |
SWAP(FRAMEINFO *, pEnc->current, pEnc->reference); |
1151 |
|
|
1152 |
pEnc->current->global_flags = pFrame->general; |
pEnc->current->global_flags = pFrame->general; |
1153 |
pEnc->current->motion_flags = pFrame->motion; |
pEnc->current->motion_flags = pFrame->motion; |
1563 |
|
|
1564 |
BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current); |
BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current); |
1565 |
|
|
|
/* XXX: move this stuff to BitstreamWriteVolHeader */ |
|
|
#define DIVX501B481P "DivX501b481p" |
|
|
if ((pEnc->mbParam.global & XVID_GLOBAL_PACKED)) { |
|
|
BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P)); |
|
|
} |
|
|
|
|
|
#define XVID_ID "XviD" XVID_BS_VERSION |
|
|
BitstreamWriteUserData(bs, XVID_ID, strlen(XVID_ID)); |
|
|
|
|
1566 |
set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); |
set_timecodes(pEnc->current,pEnc->reference,pEnc->mbParam.fbase); |
1567 |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1); |
BitstreamWriteVopHeader(bs, &pEnc->mbParam, pEnc->current, 1); |
1568 |
|
|
1599 |
if ((pEnc->current->global_flags & XVID_REDUCED)) |
if ((pEnc->current->global_flags & XVID_REDUCED)) |
1600 |
{ |
{ |
1601 |
image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width, |
image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width, |
1602 |
pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width); |
pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width, |
1603 |
|
16, XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV); |
1604 |
} |
} |
1605 |
emms(); |
emms(); |
1606 |
|
|
1682 |
pEnc->current->coding_type = P_VOP; |
pEnc->current->coding_type = P_VOP; |
1683 |
|
|
1684 |
start_timer(); |
start_timer(); |
1685 |
if (pEnc->current->global_flags & XVID_HINTEDME_SET) { |
if (pEnc->current->global_flags & XVID_HINTEDME_SET) |
1686 |
HintedMESet(pEnc, &bIntra); |
HintedMESet(pEnc, &bIntra); |
1687 |
if (bIntra == 0) { |
else |
|
MotionEstimationHinted(&pEnc->mbParam, pEnc->current, pEnc->reference, |
|
|
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV); |
|
|
} |
|
|
|
|
|
} else { |
|
1688 |
|
|
1689 |
bIntra = |
bIntra = |
1690 |
MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference, |
MotionEstimation(&pEnc->mbParam, pEnc->current, pEnc->reference, |
1691 |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
&pEnc->vInterH, &pEnc->vInterV, &pEnc->vInterHV, |
1692 |
iLimit); |
iLimit); |
1693 |
} |
|
1694 |
stop_motion_timer(); |
stop_motion_timer(); |
1695 |
|
|
1696 |
if (bIntra == 1) return FrameCodeI(pEnc, bs, pBits); |
if (bIntra == 1) return FrameCodeI(pEnc, bs, pBits); |
1840 |
if ((pEnc->current->global_flags & XVID_REDUCED)) |
if ((pEnc->current->global_flags & XVID_REDUCED)) |
1841 |
{ |
{ |
1842 |
image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width, |
image_deblock_rrv(&pEnc->current->image, pEnc->mbParam.edged_width, |
1843 |
pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width); |
pEnc->current->mbs, mb_width, mb_height, pEnc->mbParam.mb_width, |
1844 |
|
16, XVID_DEC_DEBLOCKY|XVID_DEC_DEBLOCKUV); |
1845 |
} |
} |
1846 |
|
|
1847 |
emms(); |
emms(); |
1925 |
Bitstream * bs, |
Bitstream * bs, |
1926 |
uint32_t * pBits) |
uint32_t * pBits) |
1927 |
{ |
{ |
1928 |
int16_t dct_codes[6 * 64]; |
DECLARE_ALIGNED_MATRIX(dct_codes, 6, 64, int16_t, CACHE_LINE); |
1929 |
int16_t qcoeff[6 * 64]; |
DECLARE_ALIGNED_MATRIX(qcoeff, 6, 64, int16_t, CACHE_LINE); |
1930 |
uint32_t x, y; |
uint32_t x, y; |
1931 |
|
|
1932 |
IMAGE *f_ref = &pEnc->reference->image; |
IMAGE *f_ref = &pEnc->reference->image; |