1 |
/****************************************************************************** |
/***************************************************************************** |
2 |
* * |
* |
3 |
* This file is part of XviD, a free MPEG-4 video encoder/decoder * |
* XVID MPEG-4 VIDEO CODEC |
4 |
* * |
* - MB coding - |
5 |
* XviD is an implementation of a part of one or more MPEG-4 Video tools * |
* |
6 |
* as specified in ISO/IEC 14496-2 standard. Those intending to use this * |
* Copyright (C) 2002 Michael Militzer <isibaar@xvid.org> |
7 |
* software module in hardware or software products are advised that its * |
* |
8 |
* use may infringe existing patents or copyrights, and any such use * |
* This program is free software ; you can redistribute it and/or modify |
9 |
* would be at such party's own risk. The original developer of this * |
* it under the terms of the GNU General Public License as published by |
10 |
* software module and his/her company, and subsequent editors and their * |
* the Free Software Foundation ; either version 2 of the License, or |
11 |
* companies, will have no liability for use of this software or * |
* (at your option) any later version. |
12 |
* modifications or derivatives thereof. * |
* |
13 |
* * |
* This program is distributed in the hope that it will be useful, |
14 |
* XviD is free software; you can redistribute it and/or modify it * |
* but WITHOUT ANY WARRANTY ; without even the implied warranty of |
15 |
* under the terms of the GNU General Public License as published by * |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
* the Free Software Foundation; either version 2 of the License, or * |
* GNU General Public License for more details. |
17 |
* (at your option) any later version. * |
* |
18 |
* * |
* You should have received a copy of the GNU General Public License |
19 |
* XviD is distributed in the hope that it will be useful, but * |
* along with this program ; if not, write to the Free Software |
20 |
* WITHOUT ANY WARRANTY; without even the implied warranty of * |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
* |
22 |
* GNU General Public License for more details. * |
* $Id$ |
23 |
* * |
* |
24 |
* You should have received a copy of the GNU General Public License * |
****************************************************************************/ |
|
* along with this program; if not, write to the Free Software * |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
|
|
* * |
|
|
******************************************************************************/ |
|
|
|
|
|
/****************************************************************************** |
|
|
* * |
|
|
* mbcoding.c * |
|
|
* * |
|
|
* Copyright (C) 2002 - Michael Militzer <isibaar@xvid.org> * |
|
|
* * |
|
|
* For more information visit the XviD homepage: http://www.xvid.org * |
|
|
* * |
|
|
******************************************************************************/ |
|
|
|
|
|
/****************************************************************************** |
|
|
* * |
|
|
* Revision history: * |
|
|
* * |
|
|
* 28.10.2002 GMC support - gruel * |
|
|
* 28.06.2002 added check_resync_marker() * |
|
|
* 14.04.2002 bframe encoding * |
|
|
* 08.03.2002 initial version; isibaar * |
|
|
* * |
|
|
******************************************************************************/ |
|
|
|
|
25 |
|
|
26 |
#include <stdio.h> |
#include <stdio.h> |
27 |
#include <stdlib.h> |
#include <stdlib.h> |
717 |
DPRINTF(XVID_DEBUG_MB,"codep: field_dct: %i\n", pMB->field_dct); |
DPRINTF(XVID_DEBUG_MB,"codep: field_dct: %i\n", pMB->field_dct); |
718 |
} |
} |
719 |
|
|
720 |
/* if inter block, write field ME flag */ |
/* if inter block, write field ME flag ** not implemented yet */ |
721 |
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) { |
if ((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) && (pMB->mcsel == 0)) { |
722 |
BitstreamPutBit(bs, pMB->field_pred); |
BitstreamPutBit(bs, 0 /*pMB->field_pred*/); |
723 |
DPRINTF(XVID_DEBUG_MB,"codep: field_pred: %i\n", pMB->field_pred); |
DPRINTF(XVID_DEBUG_MB,"codep: field_pred: %i\n", pMB->field_pred); |
724 |
|
|
725 |
/* write field prediction references */ |
/* write field prediction references */ |
726 |
if (pMB->field_pred) { |
/* if (pMB->field_pred) { |
727 |
BitstreamPutBit(bs, pMB->field_for_top); |
BitstreamPutBit(bs, pMB->field_for_top); |
728 |
BitstreamPutBit(bs, pMB->field_for_bot); |
BitstreamPutBit(bs, pMB->field_for_bot); |
729 |
} |
} */ |
730 |
} |
} |
731 |
} |
} |
732 |
/* code motion vector(s) if motion is local */ |
/* code motion vector(s) if motion is local */ |
775 |
|
|
776 |
} |
} |
777 |
|
|
|
|
|
|
/* moved to mbcoding.h so that in can be 'static __inline' */ |
|
|
#if 0 |
|
|
void |
|
|
MBSkip(Bitstream * bs) |
|
|
{ |
|
|
BitstreamPutBit(bs, 1); /* not coded */ |
|
|
} |
|
|
#endif |
|
|
|
|
778 |
/*************************************************************** |
/*************************************************************** |
779 |
* bframe encoding start |
* bframe encoding start |
780 |
***************************************************************/ |
***************************************************************/ |
838 |
|
|
839 |
|
|
840 |
void |
void |
841 |
MBCodingBVOP(const MACROBLOCK * mb, |
MBCodingBVOP(const FRAMEINFO * const frame, |
842 |
|
const MACROBLOCK * mb, |
843 |
const int16_t qcoeff[6 * 64], |
const int16_t qcoeff[6 * 64], |
844 |
const int32_t fcode, |
const int32_t fcode, |
845 |
const int32_t bcode, |
const int32_t bcode, |
846 |
Bitstream * bs, |
Bitstream * bs, |
847 |
Statistics * pStat, |
Statistics * pStat) |
|
int direction) |
|
848 |
{ |
{ |
849 |
int vcode = fcode; |
int vcode = fcode; |
850 |
unsigned int i; |
unsigned int i; |
851 |
|
|
852 |
|
const uint16_t *scan_table = |
853 |
|
frame->vop_flags & XVID_VOP_ALTERNATESCAN ? |
854 |
|
scan_tables[2] : scan_tables[0]; |
855 |
|
|
856 |
|
|
857 |
/* ------------------------------------------------------------------ |
/* ------------------------------------------------------------------ |
858 |
when a block is skipped it is decoded DIRECT(0,0) |
when a block is skipped it is decoded DIRECT(0,0) |
859 |
hence is interpolated from forward & backward frames |
hence is interpolated from forward & backward frames |
882 |
put_bvop_dbquant(bs, 0); /* todo: mb->dquant = 0 */ |
put_bvop_dbquant(bs, 0); /* todo: mb->dquant = 0 */ |
883 |
} |
} |
884 |
|
|
885 |
|
if (frame->vol_flags & XVID_VOL_INTERLACING) { |
886 |
|
if (mb->cbp) { |
887 |
|
BitstreamPutBit(bs, mb->field_dct); |
888 |
|
DPRINTF(XVID_DEBUG_MB,"codep: field_dct: %i\n", mb->field_dct); |
889 |
|
} |
890 |
|
|
891 |
|
/* if not direct block, write field ME flag */ |
892 |
|
if (mb->mode != MODE_DIRECT) { |
893 |
|
BitstreamPutBit(bs, 0 /*mb->field_pred*/); /* field ME not implemented */ |
894 |
|
|
895 |
|
/* write field prediction references */ |
896 |
|
/* if (mb->field_pred) { |
897 |
|
BitstreamPutBit(bs, mb->field_for_top); |
898 |
|
BitstreamPutBit(bs, mb->field_for_bot); |
899 |
|
}*/ |
900 |
|
} |
901 |
|
} |
902 |
|
|
903 |
|
|
904 |
switch (mb->mode) { |
switch (mb->mode) { |
905 |
case MODE_INTERPOLATE: |
case MODE_INTERPOLATE: |
906 |
CodeVector(bs, mb->pmvs[1].x, vcode, pStat); /* forward vector of interpolate mode */ |
CodeVector(bs, mb->pmvs[1].x, vcode, pStat); /* forward vector of interpolate mode */ |
1595 |
VLC sprite_trajectory_len[15] = { |
VLC sprite_trajectory_len[15] = { |
1596 |
{ 0x00 , 2}, |
{ 0x00 , 2}, |
1597 |
{ 0x02 , 3}, { 0x03, 3}, { 0x04, 3}, { 0x05, 3}, { 0x06, 3}, |
{ 0x02 , 3}, { 0x03, 3}, { 0x04, 3}, { 0x05, 3}, { 0x06, 3}, |
1598 |
{ 0x0E , 4}, { 0x1E, 5}, { 0x3E, 6}, { 0x7F, 7}, { 0xFE, 8}, |
{ 0x0E , 4}, { 0x1E, 5}, { 0x3E, 6}, { 0x7E, 7}, { 0xFE, 8}, |
1599 |
{ 0x1FE, 9}, {0x3FE,10}, {0x7FE,11}, {0xFFE,12} }; |
{ 0x1FE, 9}, {0x3FE,10}, {0x7FE,11}, {0xFFE,12} }; |
1600 |
|
|
1601 |
|
|