3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Encoder main module - |
* - Encoder main module - |
5 |
* |
* |
6 |
* This program is an implementation of a part of one or more MPEG-4 |
* Copyright(C) 2002 Michael Militzer <isibaar@xvid.org> |
7 |
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
* 2002-2003 Peter Ross <pross@xvid.org> |
8 |
* to use this software module in hardware or software products are |
* 2002 Daniel Smith <danielsmith@astroboymail.com> |
|
* advised that its use may infringe existing patents or copyrights, and |
|
|
* any such use would be at such party's own risk. The original |
|
|
* developer of this software module and his/her company, and subsequent |
|
|
* editors and their companies, will have no liability for use of this |
|
|
* software or modifications or derivatives thereof. |
|
9 |
* |
* |
10 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
11 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
21 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
22 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 |
* |
* |
24 |
* $Id: encoder.c,v 1.95.2.25 2003-05-22 16:34:47 edgomez Exp $ |
* $Id: encoder.c,v 1.95.2.28 2003-06-09 19:20:56 edgomez Exp $ |
25 |
* |
* |
26 |
****************************************************************************/ |
****************************************************************************/ |
27 |
|
|
44 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
45 |
#include "utils/emms.h" |
#include "utils/emms.h" |
46 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
|
#include "quant/adapt_quant.h" |
|
47 |
#include "quant/quant_matrix.h" |
#include "quant/quant_matrix.h" |
48 |
#include "utils/mem_align.h" |
#include "utils/mem_align.h" |
49 |
|
|
708 |
|
|
709 |
/* todo: [vol,vop,motion]_flags*/ |
/* todo: [vol,vop,motion]_flags*/ |
710 |
|
|
711 |
} else { // XVID_PLG_AFTER |
} else { /* XVID_PLG_AFTER */ |
712 |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
if ((pEnc->mbParam.plugin_flags & XVID_REQORIGINAL)) { |
713 |
data.original.csp = XVID_CSP_USER; |
data.original.csp = XVID_CSP_USER; |
714 |
data.original.plane[0] = original->y; |
data.original.plane[0] = original->y; |
1042 |
goto done; /* nothing to encode yet; encoder lag */ |
goto done; /* nothing to encode yet; encoder lag */ |
1043 |
} |
} |
1044 |
|
|
1045 |
// the current FRAME becomes the reference |
/* the current FRAME becomes the reference */ |
1046 |
SWAP(FRAMEINFO*, pEnc->current, pEnc->reference); |
SWAP(FRAMEINFO*, pEnc->current, pEnc->reference); |
1047 |
|
|
1048 |
// remove frame from encoding-queue (head), and move it into the current |
/* remove frame from encoding-queue (head), and move it into the current */ |
1049 |
image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head].image); |
image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head].image); |
1050 |
frame = &pEnc->queue[pEnc->queue_head].frame; |
frame = &pEnc->queue[pEnc->queue_head].frame; |
1051 |
pEnc->queue_head = (pEnc->queue_head + 1) % (pEnc->mbParam.max_bframes+1); |
pEnc->queue_head = (pEnc->queue_head + 1) % (pEnc->mbParam.max_bframes+1); |
1161 |
|
|
1162 |
if (type == I_VOP && (pEnc->mbParam.global_flags & XVID_GLOBAL_CLOSED_GOP) && pEnc->bframenum_tail > 0) { |
if (type == I_VOP && (pEnc->mbParam.global_flags & XVID_GLOBAL_CLOSED_GOP) && pEnc->bframenum_tail > 0) { |
1163 |
|
|
1164 |
// place this frame back on the encoding-queue (head) |
/* place this frame back on the encoding-queue (head) */ |
1165 |
// we will deal with it next time |
/* we will deal with it next time */ |
1166 |
dec_frame_num(pEnc); |
dec_frame_num(pEnc); |
1167 |
pEnc->iFrameNum--; |
pEnc->iFrameNum--; |
1168 |
|
|
1170 |
pEnc->queue_size++; |
pEnc->queue_size++; |
1171 |
image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head].image); |
image_swap(&pEnc->current->image, &pEnc->queue[pEnc->queue_head].image); |
1172 |
|
|
1173 |
// grab the last frame from the bframe-queue |
/* grab the last frame from the bframe-queue */ |
1174 |
|
|
1175 |
pEnc->bframenum_tail--; |
pEnc->bframenum_tail--; |
1176 |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
SWAP(FRAMEINFO*, pEnc->current, pEnc->bframes[pEnc->bframenum_tail]); |
1232 |
* encode this frame as an p-vop |
* encode this frame as an p-vop |
1233 |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ |
1234 |
|
|
1235 |
} else { // (type == P_VOP || type == S_VOP) |
} else { /* (type == P_VOP || type == S_VOP) */ |
1236 |
|
|
1237 |
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", |
1238 |
pEnc->bframenum_head, pEnc->bframenum_tail, |
pEnc->bframenum_head, pEnc->bframenum_tail, |
1463 |
|
|
1464 |
pEnc->mbParam.m_rounding_type = 1 - pEnc->mbParam.m_rounding_type; |
pEnc->mbParam.m_rounding_type = 1 - pEnc->mbParam.m_rounding_type; |
1465 |
pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type; |
pEnc->current->rounding_type = pEnc->mbParam.m_rounding_type; |
1466 |
//pEnc->current->quarterpel = pEnc->mbParam.m_quarterpel; |
/* pEnc->current->quarterpel = pEnc->mbParam.m_quarterpel; */ |
1467 |
pEnc->current->fcode = pEnc->mbParam.m_fcode; |
pEnc->current->fcode = pEnc->mbParam.m_fcode; |
1468 |
|
|
1469 |
if (!force_inter) |
if (!force_inter) |
1765 |
pEnc->fMvPrevSigma = fSigma; |
pEnc->fMvPrevSigma = fSigma; |
1766 |
|
|
1767 |
/* frame drop code */ |
/* frame drop code */ |
1768 |
//DPRINTF(XVID_DEBUG_DEBUG, "kmu %i %i %i\n", pEnc->current->sStat.kblks, pEnc->current->sStat.mblks, pEnc->current->sStat.ublks); |
#if 0 |
1769 |
|
DPRINTF(XVID_DEBUG_DEBUG, "kmu %i %i %i\n", pEnc->current->sStat.kblks, pEnc->current->sStat.mblks, pEnc->current->sStat.ublks); |
1770 |
|
#endif |
1771 |
if (pEnc->current->sStat.kblks + pEnc->current->sStat.mblks < |
if (pEnc->current->sStat.kblks + pEnc->current->sStat.mblks < |
1772 |
(pEnc->mbParam.frame_drop_ratio * mb_width * mb_height) / 100) |
(pEnc->mbParam.frame_drop_ratio * mb_width * mb_height) / 100) |
1773 |
{ |
{ |
1783 |
pEnc->current->quant = pEnc->reference->quant; |
pEnc->current->quant = pEnc->reference->quant; |
1784 |
pEnc->current->motion_flags = pEnc->reference->motion_flags; |
pEnc->current->motion_flags = pEnc->reference->motion_flags; |
1785 |
pEnc->current->rounding_type = pEnc->reference->rounding_type; |
pEnc->current->rounding_type = pEnc->reference->rounding_type; |
1786 |
//pEnc->current->quarterpel = pEnc->reference->quarterpel; |
/* pEnc->current->quarterpel = pEnc->reference->quarterpel; */ |
1787 |
pEnc->current->fcode = pEnc->reference->fcode; |
pEnc->current->fcode = pEnc->reference->fcode; |
1788 |
pEnc->current->bcode = pEnc->reference->bcode; |
pEnc->current->bcode = pEnc->reference->bcode; |
1789 |
image_copy(&pEnc->current->image, &pEnc->reference->image, pEnc->mbParam.edged_width, pEnc->mbParam.height); |
image_copy(&pEnc->current->image, &pEnc->reference->image, pEnc->mbParam.edged_width, pEnc->mbParam.height); |
1849 |
} |
} |
1850 |
#endif |
#endif |
1851 |
|
|
1852 |
//frame->quarterpel = pEnc->mbParam.m_quarterpel; |
/* frame->quarterpel = pEnc->mbParam.m_quarterpel; */ |
1853 |
|
|
1854 |
/* forward */ |
/* forward */ |
1855 |
image_setedges(f_ref, pEnc->mbParam.edged_width, |
image_setedges(f_ref, pEnc->mbParam.edged_width, |