rdopt.c File Reference

Rate-Distortion optimized mode decision. More...

#include <math.h>
#include <limits.h>
#include "global.h"
#include "rdopt.h"
#include "q_around.h"
#include "rdopt_coding_state.h"
#include "memalloc.h"
#include "mb_access.h"
#include "elements.h"
#include "intrarefresh.h"
#include "image.h"
#include "transform8x8.h"
#include "cabac.h"
#include "biariencode.h"
#include "vlc.h"
#include "me_umhex.h"
#include "ratectl.h"
#include "mode_decision.h"
#include "rd_intra_jm.h"
#include "fmo.h"
#include "macroblock.h"
#include "symbol.h"
#include "q_offsets.h"
#include "conformance.h"
#include "errdo.h"
#include "mv-search.h"
#include "md_common.h"

Include dependency graph for rdopt.c:

Go to the source code of this file.

Defines

#define FASTMODE   1
#define IS_FW   ((b8x8info->best8x8pdir[mode][k]==0 || b8x8info->best8x8pdir[mode][k]==2) && (mode!=P8x8 || b8x8info->best8x8mode[k]!=0 || !bslice))
#define IS_BW   ((b8x8info->best8x8pdir[mode][k]==1 || b8x8info->best8x8pdir[mode][k]==2) && (mode!=P8x8 || b8x8info->best8x8mode[k]!=0))

Functions

void StoreMV8x8 (int dir)
void RestoreMV8x8 (int dir)
void alloc_rd8x8data (RD_8x8DATA *rd_data)
void free_rd8x8data (RD_8x8DATA *rd_data)
void clear_rdopt (InputParameters *params)
void init_rdopt (InputParameters *params)
void UpdatePixelMap ()
int CheckReliabilityOfRef (int block, int list_idx, int ref, int mode)
double RDCost_for_4x4IntraBlocks (Slice *currSlice, Macroblock *currMB, int *nonzero, int b8, int b4, int ipmode, double lambda, int mostProbableMode, int c_nzCbCr[3], int is_cavlc)
double RDCost_for_8x8blocks (Slice *currSlice, Macroblock *currMB, int *cnt_nonz, int64 *cbp_blk, double lambda, int block, int mode, short pdir, short l0_ref, short l1_ref, short bipred_me, int is_cavlc)
int I16Offset (int cbp, int i16mode)
void SetModesAndRefframeForBlocks (Macroblock *currMB, int mode)
void SetCoeffAndReconstruction8x8 (Macroblock *currMB)
int RDCost_for_macroblocks (Slice *currSlice, Macroblock *currMB, double lambda, int mode, double *min_rdcost, double *min_dcost, double *min_rate, int i16mode, int is_cavlc)
void store_macroblock_parameters (Macroblock *currMB, int mode)
void set_stored_macroblock_parameters (Macroblock *currMB)
void SetRefAndMotionVectors (PicMotionParams *motion, Macroblock *currMB, int block, int mode, int pdir, int fwref, int bwref, short bipred_me)
byte field_flag_inference (Macroblock *currMB)
void StoreMVBlock8x8 (int dir, int block8x8, int mode, int l0_ref, int l1_ref, int pdir8, int bipred_me, int bslice)
void RestoreMVBlock8x8 (int dir, int block8x8, RD_8x8DATA *tr, int bslice)
void StoreNewMotionVectorsBlock8x8 (int dir, int block8x8, int mode, int l0_ref, int l1_ref, int pdir8, int bipred_me, int bslice)
int GetBestTransformP8x8 ()
void set_mbaff_parameters (Macroblock *currMB)
void store_coding_state_cs_cm (Slice *currSlice, Macroblock *currMB)
void reset_coding_state_cs_cm (Slice *currSlice, Macroblock *currMB)
void assign_enc_picture_params (int mode, char best_pdir, int block, int list_offset, int best_l0_ref, int best_l1_ref, int bslice, short bipred_me)
void copy_4x4block (imgpel **oblock, imgpel **iblock, int o_xoffset, int i_xoffset)
void set_block8x8_info (Block8x8Info *b8x8info, int mode, int block, char best_ref[2], char best_pdir, short bipred_me)
void set_subblock8x8_info (Block8x8Info *b8x8info, int mode, int block, RD_8x8DATA *tr)
void update_refresh_map (int intra, int intra1, Macroblock *currMB)
int valid_intra_mode (int ipmode)
void compute_comp_cost (imgpel **cur_img, imgpel **prd_img, int pic_opix_x, int *cost)
void generate_pred_error (imgpel **cur_img, imgpel **prd_img, imgpel **cur_prd, int **m7, int pic_opix_x, int block_x)
void update_qp_cbp_tmp (Macroblock *currMB, int cbp, int best_mode)
void update_qp_cbp (Macroblock *currMB, short best_mode)

Variables

static int diff [16]
static int diff4x4 [64]
static int diff8x8 [64]
RD_8x8DATA tr4x4
RD_8x8DATA tr8x8
imgpel *** rec8x8 = NULL
imgpel *** rec4x4 = NULL
imgpel *** rec4x4CbCr = NULL
imgpel ** pred = NULL
imgpel ** rec_mbY = NULL
imgpel *** rec_mb_cr = NULL
static int ** lrec_rec = NULL
static int *** lrec_rec_uv = NULL
int **** cofAC = NULL
int *** cofDC = NULL
int ** cofAC4x4 = NULL
int **** cofAC4x4intern = NULL
int cbp
int cbp8x8
int cnt_nonz_8x8
int cbp_blk8x8
char ** l0_refframe
char ** l1_refframe
short b8mode [4]
short b8pdir [4]
short b8bipred_me [4]
CSptr cs_mb = NULL
CSptr cs_b8 = NULL
CSptr cs_cm = NULL
CSptr cs_ib8 = NULL
CSptr cs_ib4 = NULL
int best_c_imode
int best_i16offset
short best_mode
int luma_transform_size_8x8_flag
short ***** all_mv8x8 = NULL
int ***** cofAC4x4CbCrintern = NULL
int ***** cofAC8x8ts = NULL
int ***** coefAC8x8 = NULL
int ** cofAC4x4CbCr [2]
int64 cbp_blk8_8x8ts
int cbp8_8x8ts
int cost8_8x8ts
int cnt_nonz8_8x8ts
double mb16x16_cost
double lambda_mf_factor
char b4_ipredmode [16]
char b4_intra_pred_modes [16]


Detailed Description

Rate-Distortion optimized mode decision.

Author:
Date:
12. April 2001

Definition in file rdopt.c.


Function Documentation

int CheckReliabilityOfRef ( int  block,
int  list_idx,
int  ref,
int  mode 
)

Checks if a given reference frame is reliable for the current macroblock, given the motion vectors that the motion search has returned.

Returns:
If the return value is 1, the reference frame is reliable. If it is 0, then it is not reliable.
Note:
A specific area in each reference frame is assumed to be unreliable if the same area has been intra-refreshed in a subsequent frame. The information about intra-refreshed areas is kept in the pixel_map.

Definition at line 324 of file rdopt.c.

References ImageParameters::all_mv, ImageParameters::block_x, ImageParameters::block_y, ImageParameters::height, pixel_map, and ImageParameters::width.

Referenced by list_prediction_cost().

void clear_rdopt ( InputParameters *  params  ) 

delete structure for RD-optimized mode decision

Definition at line 127 of file rdopt.c.

References delete_coding_state(), free_mem2D(), free_mem2Dint(), free_mem2Dpel(), free_mem3Dint(), free_mem3Dpel(), free_mem5Dshort(), free_mem_ACcoeff(), free_mem_ACcoeff_new(), free_mem_DCcoeff(), and InputParameters::Transform8x8Mode.

Referenced by free_encoder_memory().

Here is the call graph for this function:

void copy_4x4block ( imgpel **  oblock,
imgpel **  iblock,
int  o_xoffset,
int  i_xoffset 
)

copy data in iblock to oblock

Definition at line 2664 of file rdopt.c.

Referenced by Mode_Decision_for_4x4IntraBlocks_JM_High().

byte field_flag_inference ( Macroblock *  currMB  ) 

int GetBestTransformP8x8 ( void   ) 

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

Definition at line 2405 of file rdopt.c.

References distortion4x4(), distortion8x8(), ImageParameters::opix_x, ImageParameters::opix_y, pCurImg, and InputParameters::Transform8x8Mode.

Referenced by encode_one_macroblock_low().

Here is the call graph for this function:

int I16Offset ( int  cbp,
int  i16mode 
)

Gets mode offset for intra16x16 mode.

Definition at line 739 of file rdopt.c.

Referenced by encode_one_macroblock_low(), and RDCost_for_macroblocks().

void init_rdopt ( InputParameters *  params  ) 

double RDCost_for_4x4IntraBlocks ( Slice *  currSlice,
Macroblock *  currMB,
int *  nonzero,
int  b8,
int  b4,
int  ipmode,
double  lambda,
int  mostProbableMode,
int  c_nzCbCr[3],
int  is_cavlc 
)

double RDCost_for_8x8blocks ( Slice *  currSlice,
Macroblock *  currMB,
int *  cnt_nonz,
int64 *  cbp_blk,
double  lambda,
int  block,
int  mode,
short  pdir,
short  l0_ref,
short  l1_ref,
short  bipred_me,
int  is_cavlc 
)

int RDCost_for_macroblocks ( Slice *  currSlice,
Macroblock *  currMB,
double  lambda,
int  mode,
double *  min_rdcost,
double *  min_dcost,
double *  min_rate,
int  i16mode,
int  is_cavlc 
)

R-D Cost for a macroblock.

Definition at line 1310 of file rdopt.c.

References ImageParameters::all_mv, ImageParameters::block_x, ImageParameters::block_y, macroblock::cbp, ChromaResidualCoding(), ImageParameters::cod_counter, compute_residue_block(), decode_one_mb(), direct_pdir, field_flag_inference(), I16Offset(), ImageParameters::i16offset, storable_picture::imgUV, storable_picture::imgY, Intra16x16_Mode_Decision(), ImageParameters::lossless_qpprime_flag, LumaResidualCoding(), ImageParameters::mb_cr_size_x, ImageParameters::mb_cr_size_y, macroblock::mb_field, macroblock::mb_nr, ImageParameters::mb_pred, macroblock::mb_type, ImageParameters::MbaffFrameFlag, Mode_Decision_for_Intra4x4Macroblock(), Mode_Decision_for_Intra8x8Macroblock(), storable_picture::motion, ImageParameters::mpr_16x16, InputParameters::NoOfDecoders, ImageParameters::num_blk8x8_uv, ImageParameters::nz_coeff, ImageParameters::opix_c_x, ImageParameters::opix_c_y, ImageParameters::opix_x, ImageParameters::opix_y, out_of_bounds_mvs(), storable_picture::p_curr_img, storable_picture::p_dec_img, pCurImg, ImageParameters::pix_c_x, ImageParameters::pix_c_y, ImageParameters::pix_y, macroblock::PrevMB, InputParameters::ProfileIDC, macroblock::qp_scaled, InputParameters::RCEnable, InputParameters::rdopt, Decoders::res_img, reset_coding_state(), SetCoeffAndReconstruction8x8(), SetModesAndRefframeForBlocks(), SetMotionVectorsMB(), store_coding_state(), ImageParameters::type, ue_linfo(), writeMBLayer(), YUV400, YUV444, and ImageParameters::yuv_format.

Referenced by compute_mode_RD_cost().

Here is the call graph for this function:

void reset_coding_state_cs_cm ( Slice *  currSlice,
Macroblock *  currMB 
)

restore coding state (for rd-optimized mode decision), used for 8x8 transformation

Definition at line 2567 of file rdopt.c.

References reset_coding_state().

Referenced by Mode_Decision_for_8x8IntraBlocks_JM_High().

Here is the call graph for this function:

void RestoreMV8x8 ( int  dir  ) 

Restore motion vectors of 8x8 partitions of one macroblock.

Definition at line 2320 of file rdopt.c.

References RestoreMVBlock8x8(), and ImageParameters::type.

Referenced by set_stored_macroblock_parameters(), and SetCoeffAndReconstruction8x8().

Here is the call graph for this function:

void RestoreMVBlock8x8 ( int  dir,
int  block8x8,
RD_8x8DATA *  tr,
int  bslice 
)

Restore motion vectors for 8x8 partition.

Definition at line 2259 of file rdopt.c.

References ImageParameters::all_mv, ImageParameters::bipred_mv, and error().

Referenced by RestoreMV8x8().

Here is the call graph for this function:

void set_block8x8_info ( Block8x8Info *  b8x8info,
int  mode,
int  block,
char  best_ref[2],
char  best_pdir,
short  bipred_me 
)

void set_mbaff_parameters ( Macroblock *  currMB  ) 

void set_stored_macroblock_parameters ( Macroblock *  currMB  ) 

Set stored macroblock parameters.

Definition at line 1669 of file rdopt.c.

References ImageParameters::AdaptiveRounding, ImageParameters::all_mv, RD_DATA::b8mode, macroblock::b8mode, RD_DATA::b8pdir, macroblock::b8pdir, macroblock::bipred_me, ImageParameters::bipred_mv, ImageParameters::block_x, ImageParameters::block_y, RD_DATA::c_ipred_mode, macroblock::c_ipred_mode, RD_DATA::cbp, macroblock::cbp, RD_DATA::cbp_blk, macroblock::cbp_blk, RD_DATA::cofAC, ImageParameters::cofAC, RD_DATA::cofDC, ImageParameters::cofDC, Decoders::dec_mbY_best, macroblock::delta_qp, RD_DATA::delta_qp, errdo_get_best_block(), ImageParameters::i16offset, RD_DATA::i16offset, storable_picture::imgUV, storable_picture::imgY, RD_DATA::intra_pred_modes, macroblock::intra_pred_modes, RD_DATA::intra_pred_modes8x8, macroblock::intra_pred_modes8x8, RD_DATA::ipredmode, ImageParameters::ipredmode, ImageParameters::ipredmode8x8, is_bipred_enabled(), macroblock::list_offset, RD_DATA::luma_transform_size_8x8_flag, macroblock::luma_transform_size_8x8_flag, ImageParameters::mb_cr_size_x, ImageParameters::mb_cr_size_y, RD_DATA::mb_type, macroblock::mb_type, ImageParameters::MbaffFrameFlag, RD_DATA::mode, storable_picture::motion, pic_motion_params::mv, ImageParameters::num_blk8x8_uv, ImageParameters::P444_joined, storable_picture::p_dec_img, ImageParameters::pix_c_x, ImageParameters::pix_c_y, ImageParameters::pix_x, ImageParameters::pix_y, macroblock::prev_cbp, RD_DATA::prev_cbp, macroblock::prev_dqp, RD_DATA::prev_dqp, macroblock::prev_qp, RD_DATA::prev_qp, macroblock::qp, RD_DATA::qp, InputParameters::rdopt, InputParameters::RDOQ_QP_Num, RD_DATA::rec_mb_cr, RD_DATA::rec_mbY, pic_motion_params::ref_idx, pic_motion_params::ref_pic_id, storable_picture::ref_pic_num, RD_DATA::refar, RestoreMV8x8(), SetMotionVectorsMB(), InputParameters::Transform8x8Mode, ImageParameters::type, update_offset_params(), InputParameters::UseRDOQuant, macroblock::valid_8x8, YUV400, and ImageParameters::yuv_format.

Referenced by encode_one_macroblock_high(), encode_one_macroblock_highfast(), and encode_one_macroblock_highloss().

Here is the call graph for this function:

void set_subblock8x8_info ( Block8x8Info *  b8x8info,
int  mode,
int  block,
RD_8x8DATA *  tr 
)

void SetCoeffAndReconstruction8x8 ( Macroblock *  currMB  ) 

void SetModesAndRefframeForBlocks ( Macroblock *  currMB,
int  mode 
)

void SetRefAndMotionVectors ( PicMotionParams *  motion,
Macroblock *  currMB,
int  block,
int  mode,
int  pdir,
int  fwref,
int  bwref,
short  bipred_me 
)

void store_coding_state_cs_cm ( Slice *  currSlice,
Macroblock *  currMB 
)

store coding state (for rd-optimized mode decision), used for 8x8 transformation

Definition at line 2556 of file rdopt.c.

References store_coding_state().

Here is the call graph for this function:

void store_macroblock_parameters ( Macroblock *  currMB,
int  mode 
)

void StoreMV8x8 ( int  dir  ) 

Store motion vectors of 8x8 partitions of one macroblock.

void StoreMVBlock8x8 ( int  dir,
int  block8x8,
int  mode,
int  l0_ref,
int  l1_ref,
int  pdir8,
int  bipred_me,
int  bslice 
)

Store motion vectors for 8x8 partition.

Definition at line 2187 of file rdopt.c.

References ImageParameters::all_mv, ImageParameters::bipred_mv, and error().

Referenced by StoreMV8x8().

Here is the call graph for this function:

void StoreNewMotionVectorsBlock8x8 ( int  dir,
int  block8x8,
int  mode,
int  l0_ref,
int  l1_ref,
int  pdir8,
int  bipred_me,
int  bslice 
)

Store predictors for 8x8 partition.

Definition at line 2338 of file rdopt.c.

References ImageParameters::all_mv, and ImageParameters::bipred_mv.

Referenced by submacroblock_mode_decision(), and submacroblock_mode_decision_low().

void update_qp_cbp ( Macroblock *  currMB,
short  best_mode 
)

void UpdatePixelMap ( void   ) 

Updates the pixel map that shows, which reference frames are reliable for each MB-area of the picture.

Note:
The new values of the pixel_map are taken from the temporary buffer refresh_map

Definition at line 275 of file rdopt.c.

References ImageParameters::height, InputParameters::num_ref_frames, pixel_map, refresh_map, ImageParameters::type, and ImageParameters::width.

Referenced by encode_one_frame().


Documentation generated with DoxyGen