macroblock.c File Reference

Process one macroblock. More...

#include "contributors.h"
#include <limits.h>
#include <math.h>
#include "global.h"
#include "enc_statistics.h"
#include "elements.h"
#include "macroblock.h"
#include "memalloc.h"
#include "mc_prediction.h"
#include "refbuf.h"
#include "fmo.h"
#include "vlc.h"
#include "image.h"
#include "mb_access.h"
#include "ratectl.h"
#include "cabac.h"
#include "biariencode.h"
#include "transform8x8.h"
#include "transform.h"
#include "me_fullsearch.h"
#include "me_fullfast.h"
#include "symbol.h"
#include "rdoq.h"
#include "mv-search.h"
#include "conformance.h"

Include dependency graph for macroblock.c:

Go to the source code of this file.

Defines

#define TRACE_SE(trace, str)

Functions

static int slice_too_big (Slice *currSlice, int rlc_bits)
static int writeChromaIntraPredMode (Slice *currSlice, Macroblock *currMB)
static int writeChromaCoeff (Slice *currSlice, Macroblock *currMB)
static int writeCBPandDquant (Slice *currSlice, Macroblock *currMB)
static int writeMotionInfo2NAL (Slice *currSlice, Macroblock *currMB)
int allocate_mb_mem (void)
void free_mb_mem (void)
void set_MB_parameters (int mb_addr)
void next_macroblock (ImageParameters *img, Macroblock *currMB)
void set_chroma_qp (ImageParameters *img, Macroblock *currMB)
void update_qp (ImageParameters *img, Macroblock *currMB)
void reset_macroblock (ImageParameters *img, Macroblock *currMB, int prev_mb)
void start_macroblock (ImageParameters *img, Slice *currSlice, Macroblock **currMB, int mb_addr, byte mb_field)
void end_macroblock (ImageParameters *img, Slice *currSlice, Macroblock *currMB, Boolean *end_of_slice, Boolean *recode_macroblock)
int LumaResidualCoding8x8 (Macroblock *currMB, int *cbp, int64 *cbp_blk, int block8x8, short p_dir, int l0_mode, int l1_mode, short l0_ref_idx, short l1_ref_idx, int is_cavlc)
void SetModesAndRefframe (Macroblock *currMB, int b8, short *p_dir, int list_mode[2], short list_ref_idx[2])
void LumaResidualCoding (Macroblock *currMB, int is_cavlc)
int TransformDecision (Macroblock *currMB, int block_check, int *cost)
void ChromaResidualCoding (Macroblock *currMB, int is_cavlc)
void IntraChromaRDDecision (Macroblock *currMB, RD_PARAMS enc_mb)
int ZeroRef (Macroblock *currMB)
int MBType2Value (Macroblock *currMB)
int writeIntra4x4Modes (Slice *currSlice, Macroblock *currMB)
int writeIntra8x8Modes (Slice *currSlice, Macroblock *currMB)
int writeIntraModes (Slice *currSlice, Macroblock *currMB)
int B8Mode2Value (short b8mode, short b8pdir)
static int writeIPCMLuma (ImageParameters *img, imgpel **imgY, Bitstream *currStream, SyntaxElement *se, int *bitCount)
static int writeIPCMChroma (ImageParameters *img, imgpel **imgUV, Bitstream *currStream, SyntaxElement *se, int *bitCount)
static int writeIPCMByteAlign (Bitstream *currStream, SyntaxElement *se, int *bitCount)
int writeMBLayer (Slice *currSlice, Macroblock *currMB, int rdopt, int *coeff_rate)
void write_terminating_bit (Slice *currSlice, short bit)
void write_macroblock (ImageParameters *img, Slice *currSlice, Macroblock *currMB, int eos_bit, Boolean prev_recode_mb)
int writeReferenceFrame (Slice *currSlice, Macroblock *currMB, int mode, int i, int j, int fwd_flag, int ref)
int writeMotionVector8x8 (Slice *currSlice, Macroblock *currMB, int i0, int j0, int i1, int j1, int refframe, int list_idx, int mv_mode, short bipred_me)
int writeCoeff4x4_CABAC (Slice *currSlice, Macroblock *currMB, ColorPlane plane, int b8, int b4, int intra4x4mode)
int writeCoeff8x8_CABAC (Slice *currSlice, Macroblock *currMB, ColorPlane plane, int b8, int intra_mode)
int writeCoeff8x8 (Slice *currSlice, Macroblock *currMB, ColorPlane pl, int block8x8, int block_mode, int transform_size_flag)
int writeCoeff16x16 (Slice *currSlice, Macroblock *currMB, ColorPlane plane, int cbp)
int predict_nnz (Macroblock *currMB, int block_type, int i, int j)
int predict_nnz_chroma (Macroblock *currMB, int i, int j)
int writeCoeff4x4_CAVLC (Slice *currSlice, Macroblock *currMB, int block_type, int b8, int b4, int param)
int distortion_hadamard (imgpel **img_org, imgpel **pred_img)
int distortion_sad (imgpel **img_org, imgpel **pred_img)
int distortion_sse (imgpel **img_org, imgpel **pred_img)
double find_sad_16x16_JM (Macroblock *currMB, int *intra_mode)
void change_plane_JV (int nplane)
void make_frame_picture_JV ()

Variables

const byte QP_SCALE_CR [52]
static const int block8x8_idx [3][4][4]
static int ** M7 = NULL
static int ** M4 = NULL
static int **** M0 = NULL
static int diff [16]
static int diff64 [64]
const unsigned char subblk_offset_x [3][8][4]
const unsigned char subblk_offset_y [3][8][4]
ColocatedParams * Co_located
ColocatedParams * Co_located_JV [MAX_PLANE]


Detailed Description

Process one macroblock.

Author:
Main contributors (see contributors.h for copyright, address and affiliation details)

Definition in file macroblock.c.


Function Documentation

int B8Mode2Value ( short  b8mode,
short  b8pdir 
)

Converts 8x8 block type to coding value.

Definition at line 1678 of file macroblock.c.

References ImageParameters::type.

Referenced by RDCost_for_8x8blocks(), submacroblock_mode_decision_low(), and writeMBLayer().

void change_plane_JV ( int  nplane  ) 

Change color plane for 4:4:4 Independent Mode.

Input:
plane number

Definition at line 3858 of file macroblock.c.

References ImageParameters::colour_plane_id, enc_frame_picture_JV, ImageParameters::mb_data, ImageParameters::mb_data_JV, and pCurImg.

Referenced by encode_one_slice(), and encode_one_slice_MBAFF().

void ChromaResidualCoding ( Macroblock *  currMB,
int  is_cavlc 
)

void end_macroblock ( ImageParameters *  img,
Slice *  currSlice,
Macroblock *  currMB,
Boolean *  end_of_slice,
Boolean *  recode_macroblock 
)

terminates processing of the current macroblock depending on the chosen slice mode

Check end-of-slice group condition first

Now check maximum # of MBs in slice

Check if the last coded macroblock fits into the size of the slice But only if this is not the first macroblock of this slice

(first MB OR first MB in a slice) AND bigger that maximum size of slice

MB that did not fit in this slice anymore is not a Skip MB

Parameters:
currSlice  Current slice
currMB  Current Macroblock
end_of_slice  returns true for last macroblock of a slice, otherwise false
recode_macroblock  returns true if max. slice size is exceeded an macroblock must be recoded in next slice

Definition at line 579 of file macroblock.c.

References assignSE2partition, macroblock::bitcounter, Bitstream::bits_to_go, Bitstream::bits_to_go_skip, datapartition::bitstream, Bitstream::byte_buf, Bitstream::byte_buf_skip, Bitstream::byte_pos, Bitstream::byte_pos_skip, ImageParameters::cod_counter, ImageParameters::current_slice_nr, datapartition::ee_cabac, datapartition::ee_recode, error(), errortext, ET_SIZE, FmoGetLastCodedMBOfSliceGroup(), FmoMB2SliceGroup(), syntaxelement::len, Slice::max_part_nr, macroblock::mb_nr, Slice::num_mb, Slice::partArr, InputParameters::partition_mode, ImageParameters::PicSizeInMbs, macroblock::PrevMB, InputParameters::slice_argument, InputParameters::slice_mode, macroblock::slice_nr, Slice::slice_too_big, slice_too_big(), Bitstream::stored_bits_to_go, Bitstream::stored_byte_buf, Bitstream::stored_byte_pos, Slice::symbol_mode, syntaxelement::type, syntaxelement::value1, syntaxelement::value2, and writeSE_UVLC().

Referenced by encode_one_slice(), and encode_one_slice_MBAFF().

Here is the call graph for this function:

double find_sad_16x16_JM ( Macroblock *  currMB,
int *  intra_mode 
)

Find best 16x16 based intra mode.

Input:
Image parameters, pointer to best 16x16 intra mode
Output:
best 16x16 based SAD

< pixel position p(0,-1)

< pixel positions p(-1, -1..15)

Definition at line 3761 of file macroblock.c.

References pix_pos::available, InputParameters::Intra16x16ParDisable, InputParameters::Intra16x16PlaneDisable, ImageParameters::intra_block, InputParameters::IntraDisableInterOnly, pix_pos::mb_addr, ImageParameters::mb_size, InputParameters::ModeDecisionMetric, ImageParameters::mpr_16x16, ImageParameters::P444_joined, pCurImg, ImageParameters::type, and InputParameters::UseConstrainedIntraPred.

Referenced by init_rdopt().

void IntraChromaRDDecision ( Macroblock *  currMB,
RD_PARAMS  enc_mb 
)

void LumaResidualCoding ( Macroblock *  currMB,
int  is_cavlc 
)

int LumaResidualCoding8x8 ( Macroblock *  currMB,
int *  cbp,
int64 *  cbp_blk,
int  block8x8,
short  p_dir,
int  l0_mode,
int  l1_mode,
short  l0_ref_idx,
short  l1_ref_idx,
int  is_cavlc 
)

Residual Coding of an 8x8 Luma block (not for intra).

Returns:
coefficient cost
Parameters:
currMB  Current Macroblock to be coded
cbp  Output: cbp (updated according to processed 8x8 luminance block)
cbp_blk  Output: block cbp (updated according to processed 8x8 luminance block)
block8x8  block number of 8x8 block
p_dir  prediction direction
l0_mode  list0 prediction mode (1-7, 0=DIRECT)
l1_mode  list1 prediction mode (1-7, 0=DIRECT)
l0_ref_idx  reference picture for list0 prediction
l1_ref_idx  reference picture for list0 prediction
is_cavlc  entropy mode?

Definition at line 855 of file macroblock.c.

References _LUMA_COEFF_COST_, macroblock::bipred_me, ChromaPrediction(), ImageParameters::cofAC, copyblock_sp(), storable_picture::imgUV, storable_picture::imgY, ImageParameters::lossless_qpprime_flag, macroblock::luma_transform_size_8x8_flag, LumaPrediction(), ImageParameters::mb_ores, ImageParameters::mb_pred, ImageParameters::NoResidueDirect, ImageParameters::opix_x, ImageParameters::opix_y, ImageParameters::P444_joined, pCurImg, ImageParameters::pix_x, ImageParameters::pix_y, macroblock::qp_scaled, select_plane(), and ImageParameters::type.

Referenced by LumaResidualCoding(), RDCost_for_8x8blocks(), and submacroblock_mode_decision_low().

Here is the call graph for this function:

void make_frame_picture_JV ( void   ) 

Make one frame picture from 4:4:4 plane.

Definition at line 3872 of file macroblock.c.

References copy_storable_param_JV(), enc_frame_picture_JV, free_storable_picture(), ImageParameters::height, and ImageParameters::width.

Referenced by frame_picture().

Here is the call graph for this function:

int MBType2Value ( Macroblock *  currMB  ) 

Converts macroblock type to coding value.

Definition at line 1525 of file macroblock.c.

References macroblock::b8pdir, ImageParameters::currentSlice, ImageParameters::i16offset, macroblock::mb_type, Slice::symbol_mode, ImageParameters::type, and ZeroRef().

Referenced by writeMBLayer().

Here is the call graph for this function:

void next_macroblock ( ImageParameters *  img,
Macroblock *  currMB 
)

int predict_nnz ( Macroblock *  currMB,
int  block_type,
int  i,
int  j 
)

Get the Prediction from the Neighboring Blocks for Number of Nonzero Coefficients.

Luma Blocks

Definition at line 3081 of file macroblock.c.

References pix_pos::available, ImageParameters::currentPicture, error(), get4x4Neighbour(), ImageParameters::intra_block, pix_pos::mb_addr, ImageParameters::mb_size, ImageParameters::nz_coeff, InputParameters::partition_mode, pix_pos::x, and pix_pos::y.

Referenced by est_RunLevel_CAVLC(), and writeCoeff4x4_CAVLC().

Here is the call graph for this function:

int predict_nnz_chroma ( Macroblock *  currMB,
int  i,
int  j 
)

Get the Prediction from the Neighboring Blocks for Number of Nonzero Coefficients.

Chroma Blocks

Definition at line 3170 of file macroblock.c.

References pix_pos::available, ImageParameters::currentPicture, get4x4Neighbour(), ImageParameters::intra_block, pix_pos::mb_addr, ImageParameters::mb_size, ImageParameters::nz_coeff, InputParameters::partition_mode, pix_pos::x, pix_pos::y, YUV444, and ImageParameters::yuv_format.

Referenced by est_RunLevel_CAVLC(), and writeCoeff4x4_CAVLC().

Here is the call graph for this function:

void reset_macroblock ( ImageParameters *  img,
Macroblock *  currMB,
int  prev_mb 
)

void set_MB_parameters ( int  mb_addr  ) 

void SetModesAndRefframe ( Macroblock *  currMB,
int  b8,
short *  p_dir,
int  list_mode[2],
short  list_ref_idx[2] 
)

int slice_too_big ( Slice *  currSlice,
int  rlc_bits 
) [static]

For Slice Mode 2: Checks if one partition of one slice exceeds the allowed size.

Returns:
FALSE if all Partitions of this slice are smaller than the allowed size TRUE is at least one Partition exceeds the limit
Side effects
none
Date:
4 November 2001
Author:
Tobias Oelbaum drehvial@gmx.net

CAVLC

CABAC

Definition at line 805 of file macroblock.c.

References arienco_bits_written(), Bitstream::bits_to_go, datapartition::bitstream, Bitstream::byte_pos, datapartition::ee_cabac, Slice::max_part_nr, Slice::partArr, InputParameters::slice_argument, and Slice::symbol_mode.

Referenced by end_macroblock().

Here is the call graph for this function:

void start_macroblock ( ImageParameters *  img,
Slice *  currSlice,
Macroblock **  currMB,
int  mb_addr,
byte  mb_field 
)

int TransformDecision ( Macroblock *  currMB,
int  block_check,
int *  cost 
)

Makes the decision if 8x8 tranform will be used (for RD-off).

Definition at line 1229 of file macroblock.c.

References macroblock::bipred_me, distortion4x4(), distortion8x8(), LumaPrediction(), ImageParameters::mb_pred, ImageParameters::opix_x, ImageParameters::opix_y, pCurImg, SetModesAndRefframe(), and InputParameters::Transform8x8Mode.

Referenced by encode_one_macroblock_low().

Here is the call graph for this function:

void update_qp ( ImageParameters *  img,
Macroblock *  currMB 
)

updates chroma QP according to luma QP and bit depth

Definition at line 355 of file macroblock.c.

References ImageParameters::bitdepth_luma_qp_scale, macroblock::qp, and macroblock::qp_scaled.

Referenced by copy_rdopt_data(), start_macroblock(), and update_qp_cbp().

void write_macroblock ( ImageParameters *  img,
Slice *  currSlice,
Macroblock *  currMB,
int  eos_bit,
Boolean  prev_recode_mb 
)

int writeCBPandDquant ( Slice *  currSlice,
Macroblock *  currMB 
) [static]

static int writeChromaCoeff ( Slice *  currSlice,
Macroblock *  currMB 
) [static]

int writeChromaIntraPredMode ( Slice *  currSlice,
Macroblock *  currMB 
) [static]

int writeCoeff16x16 ( Slice *  currSlice,
Macroblock *  currMB,
ColorPlane  plane,
int  cbp 
)

int writeCoeff4x4_CABAC ( Slice *  currSlice,
Macroblock *  currMB,
ColorPlane  plane,
int  b8,
int  b4,
int  intra4x4mode 
)

int writeCoeff4x4_CAVLC ( Slice *  currSlice,
Macroblock *  currMB,
int  block_type,
int  b8,
int  b4,
int  param 
)

int writeCoeff8x8 ( Slice *  currSlice,
Macroblock *  currMB,
ColorPlane  pl,
int  block8x8,
int  block_mode,
int  transform_size_flag 
)

Writes Luma Coeff of an 8x8 block.

Definition at line 2753 of file macroblock.c.

References Slice::symbol_mode, writeCoeff4x4_CABAC(), writeCoeff4x4_CAVLC(), and writeCoeff8x8_CABAC().

Referenced by RDCost_for_8x8blocks(), and writeCoeff16x16().

Here is the call graph for this function:

int writeCoeff8x8_CABAC ( Slice *  currSlice,
Macroblock *  currMB,
ColorPlane  plane,
int  b8,
int  intra_mode 
)

int writeIntra4x4Modes ( Slice *  currSlice,
Macroblock *  currMB 
)

int writeIntra8x8Modes ( Slice *  currSlice,
Macroblock *  currMB 
)

int writeMBLayer ( Slice *  currSlice,
Macroblock *  currMB,
int  rdopt,
int *  coeff_rate 
)

Codes macroblock header.

Parameters:
currSlice current slice
currMB current macroblock
rdopt true for calls during RD-optimization
coeff_rate bitrate of Luma and Chroma coeff

Definition at line 1768 of file macroblock.c.

References arienco_bits_written(), arienco_done_encoding(), arienco_start_encoding(), assignSE2partition, macroblock::b8mode, B8Mode2Value(), macroblock::b8pdir, macroblock::bitcounter, datapartition::bitstream, Bitstream::byte_pos, macroblock::c_ipred_mode, macroblock::cbp, CheckAvailabilityOfNeighborsCABAC(), ImageParameters::cod_counter, ImageParameters::current_mb_nr, datapartition::ee_cabac, field_flag_inference(), FmoGetNextMBNr(), FmoGetPreviousMBNr(), storable_picture::imgUV, storable_picture::imgY, macroblock::IntraChromaPredModeFlag, syntaxelement::len, macroblock::luma_transform_size_8x8_flag, ImageParameters::mb_data, macroblock::mb_field, macroblock::mb_nr, macroblock::mb_type, ImageParameters::mb_x, ImageParameters::mb_y, ImageParameters::MbaffFrameFlag, MBType2Value(), macroblock::NoMbPartLessThan8x8Flag, Slice::partArr, InputParameters::partition_mode, macroblock::PrevMB, reset_mb_nz_coeff(), macroblock::skip_flag, Bitstream::streamBuffer, Slice::symbol_mode, InputParameters::Transform8x8Mode, syntaxelement::type, ImageParameters::type, syntaxelement::value1, syntaxelement::value2, writeCBPandDquant(), writeChromaCoeff(), writeChromaIntraPredMode(), writeCoeff16x16(), writeMB_skip_flagInfo_CABAC(), writeMotionInfo2NAL(), writeSE_Flag(), writeSE_UVLC(), YUV400, and YUV444.

Referenced by RDCost_for_macroblocks(), and write_macroblock().

Here is the call graph for this function:

int writeMotionInfo2NAL ( Slice *  currSlice,
Macroblock *  currMB 
) [static]

int writeMotionVector8x8 ( Slice *  currSlice,
Macroblock *  currMB,
int  i0,
int  j0,
int  i1,
int  j1,
int  refframe,
int  list_idx,
int  mv_mode,
short  bipred_me 
)

int writeReferenceFrame ( Slice *  currSlice,
Macroblock *  currMB,
int  mode,
int  i,
int  j,
int  fwd_flag,
int  ref 
)

int ZeroRef ( Macroblock *  currMB  ) 

Check if all reference frames for a macroblock are zero.

Definition at line 1503 of file macroblock.c.

References ImageParameters::block_x, ImageParameters::block_y, storable_picture::motion, and pic_motion_params::ref_idx.

Referenced by MBType2Value(), and writeMotionInfo2NAL().


Variable Documentation

const int block8x8_idx[3][4][4] [static]

Initial value:

 
{
  { {0, 1, 0, 0},
  {2, 3, 0, 0},
  {0, 0, 0, 0},
  {0, 0, 0, 0},
  },
  { {0, 1, 0, 0},
  {0, 1, 0, 0},
  {2, 3, 0, 0},
  {2, 3, 0, 0},
  },
  { {0, 0, 1, 1},
  {0, 0, 1, 1},
  {2, 2, 3, 3},
  {2, 2, 3, 3}
  }
}

Definition at line 66 of file macroblock.c.

Co_located to be used during 4:4:4 independent mode encoding.

Definition at line 42 of file mbuffer.c.

const byte QP_SCALE_CR[52]

Initial value:

{
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,
  12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,
  28,29,29,30,31,32,32,33,34,34,35,35,36,36,37,37,
  37,38,38,38,39,39,39,39
}

Definition at line 58 of file macroblock.c.

const unsigned char subblk_offset_x[3][8][4]

look up tables for FRExt_chroma support

Definition at line 115 of file macroblock.c.

Referenced by dct_chroma(), and IntraChromaPrediction().


Documentation generated with DoxyGen