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 "block.h"
#include "elements.h"
#include "macroblock.h"
#include "memalloc.h"
#include "mc_prediction.h"
#include "fmo.h"
#include "vlc.h"
#include "image.h"
#include "mb_access.h"
#include "ratectl.h"
#include "cabac.h"
#include "biariencode.h"
#include "me_fullsearch.h"
#include "me_fullfast.h"
#include "symbol.h"
#include "conformance.h"
#include "md_common.h"
#include "mv_prediction.h"
#include "rdopt.h"
#include "transform.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 (Macroblock *currMB)
static int writeChromaCoeff (Macroblock *currMB)
static int writeCBPandDquant (Macroblock *currMB)
void set_MB_parameters (Slice *currSlice, Macroblock *currMB)
void next_macroblock (Macroblock *currMB)
static void set_chroma_qp (Macroblock *currMB)
void update_qp (Macroblock *currMB)
void reset_macroblock (Macroblock *currMB)
void start_macroblock (Slice *currSlice, Macroblock **currMB, int mb_addr, Boolean mb_field)
void end_macroblock (Macroblock *currMB, Boolean *end_of_slice, Boolean *recode_macroblock)
int luma_residual_coding_16x16 (Macroblock *currMB, int block8x8, int list_mode[2])
int luma_residual_coding_8x8 (Macroblock *currMB, int *cbp, int64 *cbp_blk, int block8x8, short p_dir, int list_mode[2], char *ref_idx)
void set_modes_and_reframe (Macroblock *currMB, int b8, short *p_dir, int list_mode[2], char *list_ref_idx)
void set_modes_and_reframe_p_slice (Macroblock *currMB, int b8, short *p_dir, int list_mode[2], char *list_ref_idx)
void set_modes_and_reframe_b_slice (Macroblock *currMB, int b8, short *p_dir, int list_mode[2], char *list_ref_idx)
void luma_residual_coding (Macroblock *currMB)
byte TransformDecision (Macroblock *currMB, int block_check, int *cost)
void chroma_residual_coding (Macroblock *currMB)
void intra_chroma_RD_decision (Macroblock *currMB, RD_PARAMS enc_mb)
int ZeroRef (Macroblock *currMB)
int MBType2Value (Macroblock *currMB)
static int writeIntra4x4Modes (Macroblock *currMB)
static int writeIntra8x8Modes (Macroblock *currMB)
static int writeIntraModes (Macroblock *currMB)
int B8Mode2Value (Slice *currSlice, short b8mode, short b8pdir)
static int writeIPCMLuma (Macroblock *currMB, imgpel **imgY, Bitstream *currStream, SyntaxElement *se, int *bitCount)
static int writeIPCMChroma (Macroblock *currMB, imgpel **imgUV, Bitstream *currStream, SyntaxElement *se, int *bitCount)
static int writeIPCMByteAlign (Bitstream *currStream, SyntaxElement *se, int *bitCount)
static int writeIPCMData (Macroblock *currMB, DataPartition *dataPart)
int writeMBLayerBSlice (Macroblock *currMB, int rdopt, int *coeff_rate)
int writeMBLayerPSlice (Macroblock *currMB, int rdopt, int *coeff_rate)
int writeMBLayerISlice (Macroblock *currMB, int rdopt, int *coeff_rate)
void write_terminating_bit (Slice *currSlice, short bit)
void write_macroblock (Macroblock *currMB, int eos_bit, Boolean prev_recode_mb)
int writeReferenceFrame (Macroblock *currMB, int i, int j, int list_idx, int ref)
int writeMotionVector8x8 (Macroblock *currMB, int i0, int j0, int i1, int j1, int refframe, int list_idx, int mv_mode, short bipred_me)
int write_bslice_motion_info_to_NAL (Macroblock *currMB)
int write_pslice_motion_info_to_NAL (Macroblock *currMB)
int writeMotionInfo2NAL (Macroblock *currMB)
int writeCoeff4x4_CABAC (Macroblock *currMB, ColorPlane plane, int b8, int b4, int intra4x4mode)
int writeCoeff8x8_CABAC (Macroblock *currMB, ColorPlane plane, int b8, int intra_mode)
int writeCoeff8x8 (Macroblock *currMB, ColorPlane pl, int block8x8, int block_mode, int transform_size_flag)
int writeCoeff16x16_CAVLC (Macroblock *currMB, ColorPlane plane)
int writeCoeff16x16_CABAC (Macroblock *currMB, ColorPlane plane)
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_normal (Macroblock *currMB, int block_type, int b8, int b4, int param)
int writeCoeff4x4_CAVLC_444 (Macroblock *currMB, int block_type, int b8, int b4, int param)
int distI16x16_satd (Macroblock *currMB, imgpel **img_org, imgpel **pred_img, double min_cost)
int distI16x16_sad (Macroblock *currMB, imgpel **img_org, imgpel **pred_img, double min_cost)
int distI16x16_sse (Macroblock *currMB, imgpel **img_org, imgpel **pred_img, double min_cost)
double find_sad_16x16_JM (Macroblock *currMB)
void change_plane_JV (ImageParameters *p_Img, int nplane)
void make_frame_picture_JV (ImageParameters *p_Img, InputParameters *p_Inp)

Variables

static const byte QP_SCALE_CR [52]
static const int block8x8_idx [3][4][4]


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 ( Slice currSlice,
short  b8mode,
short  b8pdir 
)

Converts 8x8 block type to coding value.

Definition at line 1757 of file macroblock.c.

References slice::slice_type.

Referenced by RDCost_for_8x8blocks(), submacroblock_mode_decision_low(), writeMBLayerBSlice(), and writeMBLayerPSlice().

void change_plane_JV ( ImageParameters p_Img,
int  nplane 
)

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

Input:
plane number

Definition at line 4868 of file macroblock.c.

References img_par::colour_plane_id, img_par::enc_frame_picture_JV, img_par::imgData, img_par::mb_data, img_par::mb_data_JV, and img_par::pCurImg.

Referenced by encode_one_slice(), and encode_one_slice_MBAFF().

void chroma_residual_coding ( Macroblock currMB  ) 

void end_macroblock ( 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:
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 536 of file macroblock.c.

References assignSE2partition, Bitstream::bits_to_go, Bitstream::bits_to_go_skip, Bitstream::byte_buf, Bitstream::byte_buf_skip, Bitstream::byte_pos, Bitstream::byte_pos_skip, img_par::cod_counter, error(), errortext, ET_SIZE, FmoGetLastCodedMBOfSliceGroup(), FmoMB2SliceGroup(), syntaxelement::len, slice::max_part_nr, macroblock::mbAddrX, slice::num_mb, macroblock::p_Img, macroblock::p_slice, slice::partArr, inp_par_enc::slice_argument, inp_par_enc::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, 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  ) 

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 4789 of file macroblock.c.

References slice::mpr_16x16, macroblock::p_Img, macroblock::p_slice, img_par::pCurImg, slice::slice_type, and inp_par_enc::UseConstrainedIntraPred.

Referenced by init_rdopt().

void intra_chroma_RD_decision ( Macroblock currMB,
RD_PARAMS  enc_mb 
)

RD Decision for Intra prediction mode of the chrominance layers of one macroblock.

< pixel position p(0,-1)

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

Definition at line 1468 of file macroblock.c.

References macroblock::c_ipred_mode, img_par::field_mode, slice::mpr_16x16, macroblock::p_Img, macroblock::p_slice, Q_PEL, and inp_par_enc::UseConstrainedIntraPred.

Referenced by SetChromaPredMode().

void luma_residual_coding ( Macroblock currMB  ) 

int luma_residual_coding_16x16 ( Macroblock currMB,
int  block8x8,
int  list_mode[2] 
)

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

Returns:
coefficient cost
Parameters:
currMB Current Macroblock to be coded
block8x8 block number of 8x8 block
list_mode list prediction mode (1-7, 0=DIRECT)

Definition at line 814 of file macroblock.c.

References _LUMA_COEFF_COST_, macroblock::cbp_blk, slice::cofAC, copy_image_data_8x8(), copyblock_sp(), storable_picture::imgY, slice::mb_pred, macroblock::p_Img, macroblock::p_slice, macroblock::pix_x, macroblock::pix_y, macroblock::qp_scaled, and slice::slice_type.

Referenced by luma_residual_coding().

Here is the call graph for this function:

int luma_residual_coding_8x8 ( Macroblock currMB,
int *  cbp,
int64 *  cbp_blk,
int  block8x8,
short  p_dir,
int  list_mode[2],
char *  ref_idx 
)

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
list_mode list0 prediction mode (1-7, 0=DIRECT)
ref_idx reference pictures for each list

Definition at line 933 of file macroblock.c.

References _LUMA_COEFF_COST_, slice::cofAC, copy_image_data_8x8(), copyblock_sp(), storable_picture::imgY, luma_prediction(), slice::mb_ores, slice::mb_pred, macroblock::opix_y, macroblock::p_slice, img_par::pCurImg, macroblock::pix_x, macroblock::pix_y, macroblock::qp_scaled, and slice::slice_type.

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

Here is the call graph for this function:

void make_frame_picture_JV ( ImageParameters p_Img,
InputParameters p_Inp 
)

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

Definition at line 4881 of file macroblock.c.

References copy_storable_param_JV(), img_par::enc_frame_picture_JV, free_storable_picture(), img_par::height, storable_picture::imgUV, storable_picture::imgY, and img_par::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 1602 of file macroblock.c.

References macroblock::mb_type, macroblock::p_slice, slice::slice_type, and ZeroRef().

Referenced by min_rdcost_16x16(), writeMBLayerBSlice(), and writeMBLayerPSlice().

Here is the call graph for this function:

void next_macroblock ( Macroblock currMB  ) 

updates the coordinates and statistics parameter for the next macroblock

Definition at line 182 of file macroblock.c.

References macroblock::c_ipred_mode, macroblock::mb_type, macroblock::p_Img, macroblock::p_slice, macroblock::qp, inp_par_enc::slice_mode, and slice::slice_type.

Referenced by encode_one_slice(), and encode_one_slice_MBAFF().

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 3740 of file macroblock.c.

References error(), get4x4Neighbour(), img_par::nz_coeff, macroblock::p_Img, and macroblock::p_slice.

Referenced by est_RunLevel_CAVLC(), writeCoeff4x4_CAVLC_444(), and writeCoeff4x4_CAVLC_normal().

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 3831 of file macroblock.c.

References get4x4Neighbour(), img_par::nz_coeff, macroblock::p_Img, macroblock::p_slice, and YUV444.

Referenced by est_RunLevel_CAVLC(), writeCoeff4x4_CAVLC_444(), and writeCoeff4x4_CAVLC_normal().

Here is the call graph for this function:

void reset_macroblock ( Macroblock currMB  ) 

void set_MB_parameters ( Slice currSlice,
Macroblock currMB 
)

updates the coordinates for the next macroblock to be processed

Parameters:
currSlice current slice pointer
currMB macroblock structure to be set

Definition at line 102 of file macroblock.c.

References macroblock::block_x, macroblock::block_y, img_par::imgData, macroblock::mb_x, macroblock::mb_y, macroblock::mbAddrX, macroblock::opix_c_y, macroblock::opix_y, img_par::pCurImg, macroblock::pix_c_x, macroblock::pix_c_y, macroblock::pix_x, macroblock::pix_y, and YUV400.

Referenced by start_macroblock().

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

Set mode parameters and reference frames for an 8x8 block.

Definition at line 1077 of file macroblock.c.

References macroblock::block_x, macroblock::block_y, storable_picture::motion, macroblock::p_Img, macroblock::p_slice, pic_motion_params::ref_idx, and slice::slice_type.

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

Set mode parameters and reference frames for an 8x8 block.

Definition at line 1161 of file macroblock.c.

References macroblock::block_x, macroblock::block_y, storable_picture::motion, macroblock::p_Img, and pic_motion_params::ref_idx.

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

Set mode parameters and reference frames for an 8x8 block.

Definition at line 1136 of file macroblock.c.

References macroblock::block_x, macroblock::block_y, storable_picture::motion, macroblock::p_Img, and pic_motion_params::ref_idx.

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 763 of file macroblock.c.

References arienco_bits_written(), Bitstream::bits_to_go, Bitstream::byte_pos, slice::max_part_nr, slice::partArr, and inp_par_enc::slice_argument.

Referenced by end_macroblock().

Here is the call graph for this function:

void start_macroblock ( Slice currSlice,
Macroblock **  currMB,
int  mb_addr,
Boolean  mb_field 
)

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

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

Definition at line 1293 of file macroblock.c.

References luma_prediction(), slice::mb_pred, macroblock::opix_y, macroblock::p_Img, macroblock::p_slice, img_par::pCurImg, and macroblock::pix_x.

Referenced by encode_one_macroblock_low().

Here is the call graph for this function:

void update_qp ( Macroblock currMB  ) 

updates chroma QP according to luma QP and bit depth

Definition at line 271 of file macroblock.c.

References macroblock::p_Img, macroblock::qp, and macroblock::qp_scaled.

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

int write_bslice_motion_info_to_NAL ( Macroblock currMB  ) 

Writes motion info (b slice).

Definition at line 2814 of file macroblock.c.

References macroblock::block_x, macroblock::block_y, macroblock::mb_type, storable_picture::motion, macroblock::p_slice, pic_motion_params::ref_idx, writeMotionVector8x8(), and writeReferenceFrame().

Here is the call graph for this function:

void write_macroblock ( Macroblock currMB,
int  eos_bit,
Boolean  prev_recode_mb 
)

int write_pslice_motion_info_to_NAL ( Macroblock currMB  ) 

int writeCBPandDquant ( Macroblock currMB  )  [static]

static int writeChromaCoeff ( Macroblock currMB  )  [static]

int writeChromaIntraPredMode ( Macroblock currMB  )  [static]

int writeCoeff16x16_CABAC ( Macroblock currMB,
ColorPlane  plane 
)

int writeCoeff16x16_CAVLC ( Macroblock currMB,
ColorPlane  plane 
)

Write Luma Coeffcients, as well as Cb and Cr Coefficients in the case of 444 common mode, of an macroblock.

Definition at line 3477 of file macroblock.c.

References macroblock::mb_type, macroblock::mbAddrX, img_par::nz_coeff, macroblock::p_Img, macroblock::p_slice, reset_mb_nz_coeff(), and writeCoeff8x8().

Here is the call graph for this function:

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

int writeCoeff4x4_CAVLC_444 ( Macroblock currMB,
int  block_type,
int  b8,
int  b4,
int  param 
)

int writeCoeff4x4_CAVLC_normal ( Macroblock currMB,
int  block_type,
int  b8,
int  b4,
int  param 
)

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

Writes Luma Coeff of an 8x8 block.

Definition at line 3353 of file macroblock.c.

References macroblock::p_slice, writeCoeff4x4_CABAC(), and writeCoeff8x8_CABAC().

Referenced by RDCost_for_8x8blocks(), writeCoeff16x16_CABAC(), and writeCoeff16x16_CAVLC().

Here is the call graph for this function:

int writeCoeff8x8_CABAC ( Macroblock currMB,
ColorPlane  plane,
int  b8,
int  intra_mode 
)

static int writeIntra4x4Modes ( Macroblock currMB  )  [static]

static int writeIntra8x8Modes ( Macroblock currMB  )  [static]

static int writeIPCMData ( Macroblock currMB,
DataPartition dataPart 
) [static]

int writeMBLayerBSlice ( Macroblock currMB,
int  rdopt,
int *  coeff_rate 
)

int writeMBLayerPSlice ( Macroblock currMB,
int  rdopt,
int *  coeff_rate 
)

int writeMotionInfo2NAL ( Macroblock currMB  ) 

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

int writeReferenceFrame ( Macroblock currMB,
int  i,
int  j,
int  list_idx,
int  ref 
)

int ZeroRef ( Macroblock currMB  ) 


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 63 of file macroblock.c.

const byte QP_SCALE_CR[52] [static]

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 57 of file macroblock.c.


Documentation generated with DoxyGen