3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Encoder main module - |
* - Encoder main module - |
5 |
* |
* |
6 |
|
* Copyright(C) 2002 Michael Militzer |
7 |
|
* |
8 |
* This program is an implementation of a part of one or more MPEG-4 |
* This program is an implementation of a part of one or more MPEG-4 |
9 |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
10 |
* to use this software module in hardware or software products are |
* to use this software module in hardware or software products are |
30 |
* |
* |
31 |
****************************************************************************/ |
****************************************************************************/ |
32 |
|
|
|
/***************************************************************************** |
|
|
* |
|
|
* History |
|
|
* |
|
|
* 10.07.2002 added BFRAMES_DEC_DEBUG support |
|
|
* MinChen <chenm001@163.com> |
|
|
* 20.06.2002 bframe patch |
|
|
* 08.05.2002 fix some problem in DEBUG mode; |
|
|
* MinChen <chenm001@163.com> |
|
|
* 14.04.2002 added FrameCodeB() |
|
|
* |
|
|
* $Id$ |
|
|
* |
|
|
****************************************************************************/ |
|
|
|
|
|
|
|
33 |
#include <stdlib.h> |
#include <stdlib.h> |
34 |
#include <stdio.h> |
#include <stdio.h> |
35 |
#include <math.h> |
#include <math.h> |
607 |
} |
} |
608 |
|
|
609 |
|
|
|
#ifdef BFRAMES |
|
610 |
void inc_frame_num(Encoder * pEnc) |
void inc_frame_num(Encoder * pEnc) |
611 |
{ |
{ |
612 |
pEnc->mbParam.m_ticks += pEnc->mbParam.fincr; |
pEnc->mbParam.m_ticks += pEnc->mbParam.fincr; |
613 |
|
|
614 |
|
#ifdef BFRAMES |
615 |
pEnc->mbParam.m_ticks = pEnc->mbParam.m_ticks % pEnc->mbParam.fbase; |
pEnc->mbParam.m_ticks = pEnc->mbParam.m_ticks % pEnc->mbParam.fbase; |
|
|
|
|
/* fprintf(stderr, "ENC %c %i:%i %i\n", |
|
|
pEnc->current->coding_type == I_VOP ? 'I' : pEnc->current->coding_type == P_VOP ? 'P' : 'B', |
|
|
pEnc->mbParam.m_seconds, pEnc->mbParam.m_ticks,pEnc->last_sync); |
|
|
*/ |
|
|
|
|
616 |
if (pEnc->mbParam.m_ticks < pEnc->last_sync) |
if (pEnc->mbParam.m_ticks < pEnc->last_sync) |
617 |
pEnc->mbParam.m_seconds = 1; // more than 1 second since last I or P is not supported. |
pEnc->mbParam.m_seconds = 1; // more than 1 second since last I or P is not supported. |
618 |
else |
else |
620 |
|
|
621 |
if (pEnc->current->coding_type != B_VOP) |
if (pEnc->current->coding_type != B_VOP) |
622 |
pEnc->last_sync = pEnc->mbParam.m_ticks; |
pEnc->last_sync = pEnc->mbParam.m_ticks; |
623 |
|
#else |
624 |
|
|
625 |
|
pEnc->mbParam.m_seconds = pEnc->mbParam.m_ticks / pEnc->mbParam.fbase; |
626 |
|
pEnc->mbParam.m_ticks = pEnc->mbParam.m_ticks % pEnc->mbParam.fbase; |
627 |
|
|
|
} |
|
628 |
#endif |
#endif |
629 |
|
|
630 |
|
} |
631 |
|
|
632 |
|
|
633 |
#ifdef BFRAMES |
#ifdef BFRAMES |
634 |
void queue_image(Encoder * pEnc, XVID_ENC_FRAME * pFrame) |
void queue_image(Encoder * pEnc, XVID_ENC_FRAME * pFrame) |
1118 |
|
|
1119 |
pEnc->current->global_flags = pFrame->general; |
pEnc->current->global_flags = pFrame->general; |
1120 |
pEnc->current->motion_flags = pFrame->motion; |
pEnc->current->motion_flags = pFrame->motion; |
|
#ifdef BFRAMES |
|
1121 |
pEnc->current->seconds = pEnc->mbParam.m_seconds; |
pEnc->current->seconds = pEnc->mbParam.m_seconds; |
1122 |
pEnc->current->ticks = pEnc->mbParam.m_ticks; |
pEnc->current->ticks = pEnc->mbParam.m_ticks; |
|
#endif |
|
1123 |
pEnc->mbParam.hint = &pFrame->hint; |
pEnc->mbParam.hint = &pFrame->hint; |
1124 |
|
|
1125 |
start_timer(); |
start_timer(); |
1249 |
DEBUG(temp); |
DEBUG(temp); |
1250 |
#endif |
#endif |
1251 |
|
|
|
#ifdef BFRAMES |
|
1252 |
inc_frame_num(pEnc); |
inc_frame_num(pEnc); |
|
#endif |
|
1253 |
pEnc->iFrameNum++; |
pEnc->iFrameNum++; |
1254 |
|
|
1255 |
stop_global_timer(); |
stop_global_timer(); |
1930 |
|
|
1931 |
mb->quant = frame->quant; |
mb->quant = frame->quant; |
1932 |
mb->cbp = |
mb->cbp = |
1933 |
MBTransQuantInter(&pEnc->mbParam, frame, mb, x, y, dct_codes, |
MBTransQuantInterBVOP(&pEnc->mbParam, frame, mb, dct_codes, qcoeff); |
|
qcoeff); |
|
1934 |
//mb->cbp = MBTransQuantBVOP(&pEnc->mbParam, x, y, dct_codes, qcoeff, &frame->image, frame->quant); |
//mb->cbp = MBTransQuantBVOP(&pEnc->mbParam, x, y, dct_codes, qcoeff, &frame->image, frame->quant); |
1935 |
|
|
1936 |
if ( (mb->mode == MODE_DIRECT) && (mb->cbp == 0) |
if ( (mb->mode == MODE_DIRECT) && (mb->cbp == 0) |