51 |
#include "global.h" |
#include "global.h" |
52 |
#include "utils/timer.h" |
#include "utils/timer.h" |
53 |
#include "image/image.h" |
#include "image/image.h" |
54 |
|
#include "image/font.h" |
55 |
#include "motion/motion.h" |
#include "motion/motion.h" |
56 |
#include "bitstream/cbp.h" |
#include "bitstream/cbp.h" |
57 |
#include "utils/mbfunctions.h" |
#include "utils/mbfunctions.h" |
331 |
/* B Frames specific init */ |
/* B Frames specific init */ |
332 |
#ifdef BFRAMES |
#ifdef BFRAMES |
333 |
|
|
334 |
pEnc->packed = pParam->packed; |
pEnc->global = pParam->global; |
335 |
pEnc->mbParam.max_bframes = pParam->max_bframes; |
pEnc->mbParam.max_bframes = pParam->max_bframes; |
336 |
pEnc->bquant_ratio = pParam->bquant_ratio; |
pEnc->bquant_ratio = pParam->bquant_ratio; |
337 |
pEnc->bframes = NULL; |
pEnc->bframes = NULL; |
409 |
|
|
410 |
pEnc->mbParam.m_seconds = 0; |
pEnc->mbParam.m_seconds = 0; |
411 |
pEnc->mbParam.m_ticks = 0; |
pEnc->mbParam.m_ticks = 0; |
412 |
|
pEnc->m_framenum = 0; |
413 |
#endif |
#endif |
414 |
|
|
415 |
pParam->handle = (void *) pEnc; |
pParam->handle = (void *) pEnc; |
610 |
{ |
{ |
611 |
pEnc->iFrameNum++; |
pEnc->iFrameNum++; |
612 |
pEnc->mbParam.m_ticks += pEnc->mbParam.fincr; |
pEnc->mbParam.m_ticks += pEnc->mbParam.fincr; |
613 |
if (pEnc->mbParam.m_ticks > pEnc->mbParam.fbase) { |
|
614 |
pEnc->mbParam.m_seconds = pEnc->mbParam.m_ticks % pEnc->mbParam.fbase; |
pEnc->mbParam.m_seconds = pEnc->mbParam.m_ticks / pEnc->mbParam.fbase; |
615 |
pEnc->mbParam.m_ticks = pEnc->mbParam.m_ticks % pEnc->mbParam.fbase; |
pEnc->mbParam.m_ticks = pEnc->mbParam.m_ticks % pEnc->mbParam.fbase; |
616 |
} |
} |
|
} |
|
617 |
#endif |
#endif |
618 |
|
|
619 |
|
|
733 |
if (pEnc->bframenum_head > 0) { |
if (pEnc->bframenum_head > 0) { |
734 |
pEnc->bframenum_head = pEnc->bframenum_tail = 0; |
pEnc->bframenum_head = pEnc->bframenum_tail = 0; |
735 |
|
|
736 |
if (pEnc->packed) { |
if ((pEnc->global & XVID_GLOBAL_PACKED)) { |
737 |
|
|
738 |
DPRINTF("*** EMPTY bf: head=%i tail=%i queue: head=%i tail=%i size=%i", |
DPRINTF("*** EMPTY bf: head=%i tail=%i queue: head=%i tail=%i size=%i", |
739 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
853 |
|
|
854 |
emms(); |
emms(); |
855 |
|
|
856 |
|
if ((pEnc->global & XVID_GLOBAL_DEBUG)) { |
857 |
|
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 5, |
858 |
|
"%i if:%i st:%i:%i", pEnc->m_framenum++, pEnc->iFrameNum, pEnc->current->seconds, pEnc->current->ticks); |
859 |
|
} |
860 |
|
|
861 |
|
|
862 |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
863 |
* Luminance masking |
* Luminance masking |
864 |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
913 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
914 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
915 |
|
|
916 |
|
if ((pEnc->global & XVID_GLOBAL_DEBUG)) { |
917 |
|
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "IVOP"); |
918 |
|
} |
919 |
|
|
920 |
FrameCodeI(pEnc, &bs, &bits); |
FrameCodeI(pEnc, &bs, &bits); |
921 |
|
|
922 |
pFrame->intra = 1; |
pFrame->intra = 1; |
924 |
|
|
925 |
inc_frame_num(pEnc); |
inc_frame_num(pEnc); |
926 |
|
|
927 |
if (pEnc->packed) { |
if ((pEnc->global & XVID_GLOBAL_PACKED)) { |
928 |
BitstreamPad(&bs); |
BitstreamPad(&bs); |
929 |
input_valid = 0; |
input_valid = 0; |
930 |
goto ipvop_loop; |
goto ipvop_loop; |
943 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
944 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
945 |
|
|
946 |
|
if ((pEnc->global & XVID_GLOBAL_DEBUG)) { |
947 |
|
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "PVOP"); |
948 |
|
} |
949 |
|
|
950 |
FrameCodeP(pEnc, &bs, &bits, 1, 0); |
FrameCodeP(pEnc, &bs, &bits, 1, 0); |
951 |
pFrame->intra = 0; |
pFrame->intra = 0; |
952 |
pEnc->flush_bframes = 1; |
pEnc->flush_bframes = 1; |
953 |
|
|
954 |
inc_frame_num(pEnc); |
inc_frame_num(pEnc); |
955 |
|
|
956 |
if (pEnc->packed) { |
if ((pEnc->global & XVID_GLOBAL_PACKED)) { |
957 |
BitstreamPad(&bs); |
BitstreamPad(&bs); |
958 |
input_valid = 0; |
input_valid = 0; |
959 |
goto ipvop_loop; |
goto ipvop_loop; |
968 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
969 |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
pEnc->queue_head, pEnc->queue_tail, pEnc->queue_size); |
970 |
|
|
971 |
|
if ((pEnc->global & XVID_GLOBAL_DEBUG)) { |
972 |
|
image_printf(&pEnc->current->image, pEnc->mbParam.edged_width, pEnc->mbParam.height, 5, 200, "BVOP"); |
973 |
|
} |
974 |
|
|
975 |
if (pFrame->bquant < 1) { |
if (pFrame->bquant < 1) { |
976 |
pEnc->current->quant = |
pEnc->current->quant = |
977 |
((pEnc->reference->quant + |
((pEnc->reference->quant + |
1463 |
BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current); |
BitstreamWriteVolHeader(bs, &pEnc->mbParam, pEnc->current); |
1464 |
#ifdef BFRAMES |
#ifdef BFRAMES |
1465 |
#define DIVX501B481P "DivX501b481p" |
#define DIVX501B481P "DivX501b481p" |
1466 |
if (pEnc->packed) { |
if ((pEnc->global & XVID_GLOBAL_PACKED)) { |
1467 |
BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P)); |
BitstreamWriteUserData(bs, DIVX501B481P, strlen(DIVX501B481P)); |
1468 |
} |
} |
1469 |
#endif |
#endif |
1799 |
backward.x = mb->b_mvs[0].x; |
backward.x = mb->b_mvs[0].x; |
1800 |
backward.y = mb->b_mvs[0].y; |
backward.y = mb->b_mvs[0].y; |
1801 |
} |
} |
1802 |
// printf("[%i %i] M=%i CBP=%i MVX=%i MVY=%i %i,%i %i,%i\n", x, y, pMB->mode, pMB->cbp, pMB->mvs[0].x, bmb->pmvs[0].x, bmb->pmvs[0].y, forward.x, forward.y); |
// DPRINTF("%05i : [%i %i] M=%i CBP=%i MVS=%i,%i forward=%i,%i", pEnc->m_framenum, x, y, mb->mode, mb->cbp, mb->mvs[0].x, mb->mvs[0].y, forward.x, forward.y); |
1803 |
|
|
1804 |
start_timer(); |
start_timer(); |
1805 |
MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs, |
MBCodingBVOP(mb, qcoeff, frame->fcode, frame->bcode, bs, |