me_epzs.c File Reference

Motion Estimation using EPZS. More...

#include "contributors.h"
#include <limits.h>
#include "global.h"
#include "image.h"
#include "memalloc.h"
#include "mb_access.h"
#include "refbuf.h"
#include "me_distortion.h"
#include "me_epzs.h"
#include "mv-search.h"

Include dependency graph for me_epzs.c:

Go to the source code of this file.

Defines

#define EPZSREF   1

Functions

static int EPZSDetermineStopCriterion (int *prevSad, PixelPos *block_a, PixelPos *block_b, PixelPos *block_c, int pic_pix_x2, int blocktype, int blockshape_x)
static EPZSColocParams * allocEPZScolocated (int size_x, int size_y, int mb_adaptive_frame_field_flag)
static void freeEPZScolocated (EPZSColocParams *p)
static EPZSStructure * allocEPZSpattern (int searchpoints)
static void freeEPZSpattern (EPZSStructure *p)
static void assignEPZSpattern (EPZSStructure *pattern, int type, int stopSearch, int nextLast, EPZSStructure *nextpattern)
static int RoundLog2 (int iValue)
static int add_predictor (MotionVector *cur_mv, MotionVector prd_mv, int mvScale, int shift_mv)
static void EPZSWindowPredictorInit (short search_range, EPZSStructure *predictor, short mode)
int EPZSInit (InputParameters *params, ImageParameters *img)
void EPZSDelete (InputParameters *params)
void EPZSSliceInit (InputParameters *params, ImageParameters *img, EPZSColocParams *p, StorablePicture **listX[6])
static short EPZSSpatialPredictors (PixelPos *block_a, PixelPos *block_b, PixelPos *block_c, PixelPos *block_d, int list, int list_offset, short ref, char **refPic, short ***tmp_mv, SPoint *point)
static void EPZSSpatialMemPredictors (int list, short ref, int blocktype, int pic_x, int bs_x, int bs_y, int by, int *prednum, int img_width, SPoint *point)
static void EPZSTemporalPredictors (int list, int list_offset, short ref, int o_block_x, int o_block_y, SPoint *point, int *prednum, int block_available_left, int block_available_up, int block_available_right, int block_available_below, int blockshape_x, int blockshape_y, int stopCriterion, int min_mcost)
static void EPZSBlockTypePredictors (int block_x, int block_y, int blocktype, int ref, int list, SPoint *point, int *prednum)
static void EPZSWindowPredictors (MotionVector *mv, EPZSStructure *predictor, int *prednum, int extended)
int EPZSPelBlockMotionSearch (Macroblock *currMB, imgpel *cur_pic, short ref, int list, char ***refPic, short ****tmp_mv, int pic_pix_x, int pic_pix_y, int blocktype, MotionVector *pred_mv, MotionVector *mv, int search_range, int min_mcost, int lambda_factor, int apply_weights)
int EPZSBiPredBlockMotionSearch (Macroblock *currMB, imgpel *cur_pic, short ref, int list, char ***refPic, short ****tmp_mv, int pic_pix_x, int pic_pix_y, int blocktype, MotionVector *pred_mv1, MotionVector *pred_mv2, MotionVector *mv1, MotionVector *mv2, int search_range, int min_mcost, int iteration_no, int lambda_factor, int apply_weights)
void EPZSOutputStats (InputParameters *params, FILE *stat, short stats_file)
int EPZSSubPelBlockMotionSearch (imgpel *orig_pic, short ref, int list, int list_offset, int pic_pix_x, int pic_pix_y, int blocktype, MotionVector *pred, MotionVector *mv, int search_pos2, int search_pos4, int min_mcost, int *lambda, int apply_weights)
int EPZSSubPelBlockSearchBiPred (imgpel *orig_pic, short ref, int list, int pic_pix_x, int pic_pix_y, int blocktype, MotionVector *pred_mv1, MotionVector *pred_mv2, MotionVector *mv1, MotionVector *mv2, int search_pos2, int search_pos4, int min_mcost, int *lambda, int apply_weights)

Variables

static const short blk_parent [8] = {1, 1, 1, 1, 2, 4, 4, 5}
static const int minthres_base [8] = {0, 64, 32, 32, 16, 8, 8, 4}
static const int medthres_base [8] = {0, 256, 128, 128, 64, 32, 32, 16}
static const int maxthres_base [8] = {0, 768, 384, 384, 192, 96, 96, 48}
static const short search_point_hp [10][2] = {{0,0},{-2,0}, {0,2}, {2,0}, {0,-2}, {-2,2}, {2,2}, {2,-2}, {-2,-2}, {-2,2}}
static const short search_point_qp [10][2] = {{0,0},{-1,0}, {0,1}, {1,0}, {0,-1}, {-1,1}, {1,1}, {1,-1}, {-1,-1}, {-1,1}}
static int(* computePred )(imgpel *, int, int, int, int, int)
static unsigned short EPZSBlkCount
static int searcharray
static int mv_rescale
static int pattern_data [5][12][4]
static const char c_EPZSPattern [6][20] = { "Diamond", "Square", "Extended Diamond", "Large Diamond", "SBP Large Diamond", "PMVFAST"}
static const char c_EPZSDualPattern [7][20] = { "Disabled","Diamond", "Square", "Extended Diamond", "Large Diamond", "SBP Large Diamond", "PMVFAST"}
static const char c_EPZSFixed [3][20] = { "Disabled","All P", "All P + B"}
static const char c_EPZSOther [2][20] = { "Disabled","Enabled"}
static int medthres [8]
static int maxthres [8]
static int minthres [8]
static int subthres [8]
static int mv_scale [6][MAX_REFERENCE_PICTURES][MAX_REFERENCE_PICTURES]
static unsigned short ** EPZSMap
int *** EPZSDistortion
int *** EPZSBiDistortion
MotionVector ***** EPZS_Motion
EPZSStructure * searchPattern
EPZSStructure * searchPatternD
EPZSStructure * predictor
EPZSStructure * window_predictor
EPZSStructure * window_predictor_extended
EPZSStructure * sdiamond
EPZSStructure * square
EPZSStructure * ediamond
EPZSStructure * ldiamond
EPZSStructure * sbdiamond
EPZSStructure * pmvfast
EPZSColocParams * EPZSCo_located


Detailed Description

Motion Estimation using EPZS.

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

Definition in file me_epzs.c.


Function Documentation

static int add_predictor ( MotionVector *  cur_mv,
MotionVector  prd_mv,
int  mvScale,
int  shift_mv 
) [inline, static]

Add Predictor function.

Definition at line 281 of file me_epzs.c.

Referenced by EPZSTemporalPredictors().

static EPZSColocParams* allocEPZScolocated ( int  size_x,
int  size_y,
int  mb_adaptive_frame_field_flag 
) [static]

Allocate co-located memory.

Parameters:
size_x horizontal luma size
size_y vertical luma size
mb_adaptive_frame_field_flag flag that indicates macroblock adaptive frame/field coding
Returns:
the allocated EPZSColocParams structure

Definition at line 142 of file me_epzs.c.

References get_mem3Dmv(), and no_mem_exit().

Referenced by EPZSInit().

Here is the call graph for this function:

static EPZSStructure* allocEPZSpattern ( int  searchpoints  )  [static]

Allocate EPZS pattern memory.

Parameters:
searchpoints number of searchpoints to allocate
Returns:
the allocated EPZSStructure structure

Definition at line 205 of file me_epzs.c.

References no_mem_exit().

Referenced by EPZSInit().

Here is the call graph for this function:

int EPZSBiPredBlockMotionSearch ( Macroblock *  currMB,
imgpel *  cur_pic,
short  ref,
int  list,
char ***  refPic,
short ****  tmp_mv,
int  pic_pix_x,
int  pic_pix_y,
int  blocktype,
MotionVector *  pred_mv1,
MotionVector *  pred_mv2,
MotionVector *  mv1,
MotionVector *  mv2,
int  search_range,
int  min_mcost,
int  iteration_no,
int  lambda_factor,
int  apply_weights 
)

FAST Motion Estimation using EPZS AMT/HYC.

If medthres satisfied, then terminate, otherwise generate Predictors

Add Spatial Predictors in predictor list. Scheme adds zero, left, top-left, top, top-right. Note that top-left adds very little in terms of performance and could be removed with little penalty if any.

Check all predictors

Refine using EPZS pattern if needed Note that we are using a conservative threshold method. Threshold could be tested after checking only a certain number of predictors instead of the full set. Code could be easily modified for this task.

Adapt pattern based on different conditions.

center on best predictor

Check Second best predictor with EPZS pattern

Second best. Note that following code is identical as for best predictor.

Definition at line 1995 of file me_epzs.c.

References InputParameters::blc_size, EPZSBiDistortion, EPZSDetermineStopCriterion(), InputParameters::EPZSDual, InputParameters::EPZSGrid, EPZSMap, InputParameters::EPZSPattern, EPZSSpatialPredictors(), F_PEL, get_neighbors(), IMG_PAD_SIZE_TIMES4, storable_picture::imgUV_sub, macroblock::list_offset, ImageParameters::mb_x, ImageParameters::mb_y, ImageParameters::opix_x, ImageParameters::opix_y, storable_picture::p_curr_img_sub, storable_picture::size_x, storable_picture::size_x_cr_pad, storable_picture::size_x_pad, storable_picture::size_y, storable_picture::size_y_cr_pad, and storable_picture::size_y_pad.

Referenced by init_ME_engine().

Here is the call graph for this function:

static void EPZSBlockTypePredictors ( int  block_x,
int  block_y,
int  blocktype,
int  ref,
int  list,
SPoint *  point,
int *  prednum 
) [static]

EPZS Block Type Predictors.

Definition at line 1502 of file me_epzs.c.

References ImageParameters::all_mv, blk_parent, and ImageParameters::structure.

Referenced by EPZSPelBlockMotionSearch().

void EPZSDelete ( InputParameters *  params  ) 

static int EPZSDetermineStopCriterion ( int *  prevSad,
PixelPos *  block_a,
PixelPos *  block_b,
PixelPos *  block_c,
int  pic_pix_x2,
int  blocktype,
int  blockshape_x 
) [static]

Determine stop criterion for EPZS.

Definition at line 110 of file me_epzs.c.

References pix_pos::available.

Referenced by EPZSBiPredBlockMotionSearch(), and EPZSPelBlockMotionSearch().

int EPZSInit ( InputParameters *  params,
ImageParameters *  img 
)

EPZS Global Initialization.

In this implementation we keep threshold limits fixed. However one could adapt these limits based on lagrangian optimization considerations (i.e. qp), while also allow adaptation of the limits themselves based on content or complexity.

Definition of pottential EPZS patterns. It is possible to also define other patterns, or even use resizing patterns (such as the PMVFAST scheme. These patterns are only shown here as reference, while the same also holds for this implementation (i.e. new conditions could be added on adapting predictors, or thresholds etc. Note that search could also be performed on subpel positions directly while pattern needs not be restricted on integer positions only.

Allocate memory and assign search patterns

Allocate and assign window based predictors. Other window types could also be used, while method could be made a bit more adaptive (i.e. patterns could be assigned based on neighborhood

Also assing search predictor memory

Finally assign memory for all other elements (distortion, EPZSMap, and temporal predictors)

Definition at line 368 of file me_epzs.c.

References allocEPZScolocated(), allocEPZSpattern(), InputParameters::BiPredMESearchRange, InputParameters::BiPredMotionEstimation, ImageParameters::bitdepth_chroma, ImageParameters::bitdepth_luma, InputParameters::ChromaMEEnable, InputParameters::ChromaMEWeight, EPZS_Motion, EPZSBiDistortion, EPZSDistortion, InputParameters::EPZSDual, InputParameters::EPZSGrid, EPZSMap, InputParameters::EPZSMaxThresScale, InputParameters::EPZSMedThresScale, InputParameters::EPZSMinThresScale, InputParameters::EPZSPattern, InputParameters::EPZSSpatialMem, InputParameters::EPZSSubPelGrid, InputParameters::EPZSSubPelThresScale, InputParameters::EPZSTemporal, EPZSWindowPredictorInit(), get_mem2Dshort(), get_mem3Dint(), get_mem4Dmv(), get_mem5Dmv(), ImageParameters::height, ImageParameters::height_cr, ImageParameters::max_num_references, RoundLog2(), InputParameters::search_range, ImageParameters::width, and ImageParameters::width_cr.

Referenced by init_global_buffers().

Here is the call graph for this function:

void EPZSOutputStats ( InputParameters *  params,
FILE *  stat,
short  stats_file 
)

int EPZSPelBlockMotionSearch ( Macroblock *  currMB,
imgpel *  cur_pic,
short  ref,
int  list,
char ***  refPic,
short ****  tmp_mv,
int  pic_pix_x,
int  pic_pix_y,
int  blocktype,
MotionVector *  pred_mv,
MotionVector *  mv,
int  search_range,
int  min_mcost,
int  lambda_factor,
int  apply_weights 
)

FAST Motion Estimation using EPZS AMT/HYC.

If medthres satisfied, then terminate, otherwise generate Predictors Condition could be strengthened by consideration distortion of adjacent partitions.

Add Spatial Predictors in predictor list. Scheme adds zero, left, top-left, top, top-right. Note that top-left adds very little in terms of performance and could be removed with little penalty if any.

Window Size Based Predictors Basically replaces a Hierarchical ME concept and helps escaping local minima, or determining large motion variations. Following predictors can be adjusted further (i.e. removed, conditioned etc) based on distortion, correlation of adjacent MVs, complexity etc. These predictors and their conditioning could also be moved after all other predictors have been tested. Adaptation could also be based on type of material and coding mode (i.e. field/frame coding,MBAFF etc considering the higher dependency with opposite parity field

Blocktype/Reference dependent predictors. Since already mvs for other blocktypes/references have been computed, we can reuse them in order to easier determine the optimal point. Use of predictors could depend on cost,

Check all predictors

Refine using EPZS pattern if needed Note that we are using a conservative threshold method. Threshold could be tested after checking only a certain number of predictors instead of the full set. Code could be easily modified for this task.

Adapt pattern based on different conditions.

center on best predictor

Check Second best predictor with EPZS pattern

Second best. Note that following code is identical as for best predictor.

Definition at line 1577 of file me_epzs.c.

References pix_pos::available, InputParameters::blc_size, EPZS_Motion, InputParameters::EPZSBlockType, EPZSBlockTypePredictors(), EPZSDetermineStopCriterion(), EPZSDistortion, InputParameters::EPZSDual, InputParameters::EPZSFixed, InputParameters::EPZSGrid, EPZSMap, InputParameters::EPZSPattern, InputParameters::EPZSSpatialMem, EPZSSpatialMemPredictors(), EPZSSpatialPredictors(), InputParameters::EPZSTemporal, EPZSTemporalPredictors(), EPZSWindowPredictors(), F_PEL, get_neighbors(), IMG_PAD_SIZE_TIMES4, storable_picture::imgUV_sub, macroblock::list_offset, macroblock::mb_nr, ImageParameters::mb_x, ImageParameters::mb_y, ImageParameters::opix_x, ImageParameters::opix_y, storable_picture::p_curr_img_sub, storable_picture::size_x, storable_picture::size_x_cr_pad, storable_picture::size_x_pad, storable_picture::size_y, storable_picture::size_y_cr_pad, storable_picture::size_y_pad, ImageParameters::structure, and ImageParameters::type.

Referenced by init_ME_engine().

Here is the call graph for this function:

void EPZSSliceInit ( InputParameters *  params,
ImageParameters *  img,
EPZSColocParams *  p,
StorablePicture **  listX[6] 
)

For ME purposes restricting the co-located partition is not necessary.

EPZS Slice Level Initialization

Assign frame buffers for field MBs Check whether we should use top or bottom field mvs. Depending on the assigned poc values.

Generate field MVs from Frame MVs

Use inference flag to remap mvs/references Frame with field co-located

Definition at line 541 of file me_epzs.c.

References storable_picture::bottom_field, storable_picture::bottom_poc, storable_picture::coded_frame, InputParameters::EPZSTemporal, pic_motion_params::field_frame, storable_picture::frame, ImageParameters::MbaffFrameFlag, storable_picture::motion, pic_motion_params::mv, ImageParameters::num_ref_idx_l0_active, storable_picture::poc, pic_motion_params::ref_id, storable_picture::ref_pic_num, storable_picture::size_x, storable_picture::size_y, storable_picture::structure, ImageParameters::structure, storable_picture::top_field, storable_picture::top_poc, and ImageParameters::type.

Referenced by init_slice().

static void EPZSSpatialMemPredictors ( int  list,
short  ref,
int  blocktype,
int  pic_x,
int  bs_x,
int  bs_y,
int  by,
int *  prednum,
int  img_width,
SPoint *  point 
) [static]

Spatial Predictors AMT/HYC.

Definition at line 1345 of file me_epzs.c.

References EPZS_Motion.

Referenced by EPZSPelBlockMotionSearch().

static short EPZSSpatialPredictors ( PixelPos *  block_a,
PixelPos *  block_b,
PixelPos *  block_c,
PixelPos *  block_d,
int  list,
int  list_offset,
short  ref,
char **  refPic,
short ***  tmp_mv,
SPoint *  point 
) [static]

int EPZSSubPelBlockMotionSearch ( imgpel *  orig_pic,
short  ref,
int  list,
int  list_offset,
int  pic_pix_x,
int  pic_pix_y,
int  blocktype,
MotionVector *  pred,
MotionVector *  mv,
int  search_pos2,
int  search_pos4,
int  min_mcost,
int *  lambda,
int  apply_weights 
)

int EPZSSubPelBlockSearchBiPred ( imgpel *  orig_pic,
short  ref,
int  list,
int  pic_pix_x,
int  pic_pix_y,
int  blocktype,
MotionVector *  pred_mv1,
MotionVector *  pred_mv2,
MotionVector *  mv1,
MotionVector *  mv2,
int  search_pos2,
int  search_pos4,
int  min_mcost,
int *  lambda,
int  apply_weights 
)

static void EPZSTemporalPredictors ( int  list,
int  list_offset,
short  ref,
int  o_block_x,
int  o_block_y,
SPoint *  point,
int *  prednum,
int  block_available_left,
int  block_available_up,
int  block_available_right,
int  block_available_below,
int  blockshape_x,
int  blockshape_y,
int  stopCriterion,
int  min_mcost 
) [static]

Temporal Predictors AMT/HYC.

Definition at line 1427 of file me_epzs.c.

References add_predictor().

Referenced by EPZSPelBlockMotionSearch().

Here is the call graph for this function:

static void EPZSWindowPredictorInit ( short  search_range,
EPZSStructure *  predictor,
short  mode 
) [static]

EPZS Search Window Predictor Initialization.

Definition at line 295 of file me_epzs.c.

References InputParameters::EPZSSubPelGrid, and RoundLog2().

Referenced by EPZSInit().

Here is the call graph for this function:

static void EPZSWindowPredictors ( MotionVector *  mv,
EPZSStructure *  predictor,
int *  prednum,
int  extended 
) [static]

EPZS Window Based Predictors.

Definition at line 1554 of file me_epzs.c.

Referenced by EPZSPelBlockMotionSearch().

static void freeEPZScolocated ( EPZSColocParams *  p  )  [static]

Free co-located memory.

Parameters:
p structure to be freed

Definition at line 175 of file me_epzs.c.

References free_mem3Dmv().

Referenced by EPZSDelete().

Here is the call graph for this function:

static void freeEPZSpattern ( EPZSStructure *  p  )  [static]

Free EPZS pattern memory.

Parameters:
p structure to be freed

Definition at line 229 of file me_epzs.c.

Referenced by EPZSDelete().

static int RoundLog2 ( int  iValue  )  [static]

calculate RoundLog2(uiVal)

Definition at line 261 of file me_epzs.c.

Referenced by EPZSInit(), and EPZSWindowPredictorInit().


Variable Documentation

const short blk_parent[8] = {1, 1, 1, 1, 2, 4, 4, 5} [static]

{skip, 16x16, 16x8, 8x16, 8x8, 8x4, 4x8, 4x4}

Definition at line 34 of file me_epzs.c.

Referenced by EPZSBlockTypePredictors().

MotionVector***** EPZS_Motion

Array for storing Motion Vectors.

Definition at line 92 of file me_epzs.c.

Referenced by EPZSDelete(), EPZSInit(), EPZSPelBlockMotionSearch(), and EPZSSpatialMemPredictors().

Array for storing SAD Values.

Definition at line 90 of file me_epzs.c.

Referenced by EPZSBiPredBlockMotionSearch(), EPZSDelete(), and EPZSInit().

Array for storing SAD Values.

Definition at line 89 of file me_epzs.c.

Referenced by BlockMotionSearch(), EPZSDelete(), EPZSInit(), and EPZSPelBlockMotionSearch().

unsigned short** EPZSMap [static]

Memory Map definition.

Definition at line 88 of file me_epzs.c.

Referenced by EPZSBiPredBlockMotionSearch(), EPZSDelete(), EPZSInit(), and EPZSPelBlockMotionSearch().

int pattern_data[5][12][4] [static]

Initial value:

{
  { 
    {  0,  4,  3, 3 }, {  4,  0,  0, 3 }, {  0, -4,  1, 3 }, { -4,  0, 2, 3 }
  },
  { 
    {  0,  4,  7, 3 }, {  4,  4,  7, 5 }, {  4,  0,  1, 3 }, {  4, -4, 1, 5 },
    {  0, -4,  3, 3 }, { -4, -4,  3, 5 }, { -4,  0,  5, 3 }, { -4,  4, 5, 5 }
  },
  { 
    { -4,  4, 10, 5 }, {  0,  8, 10, 8 }, {  0,  4, 10, 7 }, {  4,  4, 1, 5 },
    {  8,  0, 1,  8 }, {  4,  0,  1, 7 }, {  4, -4,  4, 5 }, {  0, -8, 4, 8 },
    {  0, -4, 4,  7 }, { -4, -4, 7,  5 }, { -8,  0,  7, 8 }, { -4,  0, 7, 7 }

  },
  { 
    {  0,  8, 6,  5 }, {  4,  4, 0,  3 }, {  8,  0, 0,  5 }, {  4, -4, 2, 3 },
    {  0, -8, 2,  5 }, { -4, -4, 4,  3 }, { -8,  0, 4,  5 }, { -4,  4, 6, 3 }
  },
  { 
    {  0,  8, 6, 12 }, {  4,  4, 0, 12 }, {  8,  0, 0, 12 }, {  4, -4, 2, 12 },
    {  0, -8, 2, 12 }, { -4, -4, 4, 12 }, { -8,  0, 4, 12 }, { -4,  4, 6, 12 },
    {  0,  2, 6, 12 }, {  2,  0, 0, 12 }, {  0, -2, 2, 12 }, { -2,  0, 4, 12 }
  }
}
Define EPZS Refinement patterns.

Definition at line 50 of file me_epzs.c.


Documentation generated with DoxyGen