motion_est_template.c File Reference

Motion estimation template. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LOAD_COMMON
 
#define CHECK_HALF_MV(dx, dy, x, y)
 
#define CHECK_QUARTER_MV(dx, dy, x, y)
 
#define CHECK_MV(x, y)
 
#define CHECK_CLIPPED_MV(ax, ay)
 
#define CHECK_MV_DIR(x, y, new_dir)
 
#define check(x, y, S, v)
 
#define LOAD_COMMON2
 
#define SAB_CHECK_MV(ax, ay)
 
#define MAX_SAB_SIZE   ME_MAP_SIZE
 

Functions

static int hpel_motion_search (MpegEncContext *s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
 
static int no_sub_motion_search (MpegEncContext *s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
 
static int get_mb_score (MpegEncContext *s, int mx, int my, int src_index, int ref_index, int size, int h, int add_rate)
 
int ff_get_mb_score (MpegEncContext *s, int mx, int my, int src_index, int ref_index, int size, int h, int add_rate)
 
static int qpel_motion_search (MpegEncContext *s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
 
static av_always_inline int small_diamond_search (MpegEncContext *s, int *best, int dmin, int src_index, int ref_index, int const penalty_factor, int size, int h, int flags)
 
static int funny_diamond_search (MpegEncContext *s, int *best, int dmin, int src_index, int ref_index, int const penalty_factor, int size, int h, int flags)
 
static int hex_search (MpegEncContext *s, int *best, int dmin, int src_index, int ref_index, int const penalty_factor, int size, int h, int flags, int dia_size)
 
static int l2s_dia_search (MpegEncContext *s, int *best, int dmin, int src_index, int ref_index, int const penalty_factor, int size, int h, int flags)
 
static int umh_search (MpegEncContext *s, int *best, int dmin, int src_index, int ref_index, int const penalty_factor, int size, int h, int flags)
 
static int full_search (MpegEncContext *s, int *best, int dmin, int src_index, int ref_index, int const penalty_factor, int size, int h, int flags)
 
static int sab_diamond_search (MpegEncContext *s, int *best, int dmin, int src_index, int ref_index, int const penalty_factor, int size, int h, int flags)
 
static int var_diamond_search (MpegEncContext *s, int *best, int dmin, int src_index, int ref_index, int const penalty_factor, int size, int h, int flags)
 
static av_always_inline int diamond_search (MpegEncContext *s, int *best, int dmin, int src_index, int ref_index, int const penalty_factor, int size, int h, int flags)
 
static av_always_inline int epzs_motion_search_internal (MpegEncContext *s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, int16_t(*last_mv)[2], int ref_mv_scale, int flags, int size, int h)
 
int ff_epzs_motion_search (MpegEncContext *s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, int16_t(*last_mv)[2], int ref_mv_scale, int size, int h)
 
static int epzs_motion_search4 (MpegEncContext *s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, int16_t(*last_mv)[2], int ref_mv_scale)
 
static int epzs_motion_search2 (MpegEncContext *s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, int16_t(*last_mv)[2], int ref_mv_scale)
 

Detailed Description

Motion estimation template.

Definition in file motion_est_template.c.

Macro Definition Documentation

#define check (   x,
  y,
  S,
  v 
)
Value:
if( (x)<(xmin<<(S)) ) av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d xmin" #v, xmin, (x), (y), s->mb_x, s->mb_y);\
if( (x)>(xmax<<(S)) ) av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d xmax" #v, xmax, (x), (y), s->mb_x, s->mb_y);\
if( (y)<(ymin<<(S)) ) av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d ymin" #v, ymin, (x), (y), s->mb_x, s->mb_y);\
if( (y)>(ymax<<(S)) ) av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d ymax" #v, ymax, (x), (y), s->mb_x, s->mb_y);\
float v
const char * s
Definition: avisynth_c.h:668
set threshold d
initialize output if(nPeaks >3)%at least 3 peaks in spectrum for trying to find f0 nf0peaks
Discrete Time axis x
#define S(s, c, i)
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
NULL
Definition: eval.c:55
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
function y
Definition: D.m:1

Definition at line 402 of file motion_est_template.c.

Referenced by av_tree_enumerate(), h261_decode_block(), and voc_probe().

#define CHECK_CLIPPED_MV (   ax,
  ay 
)
Value:
{\
const int Lx= ax;\
const int Ly= ay;\
const int Lx2= FFMAX(xmin, FFMIN(Lx, xmax));\
const int Ly2= FFMAX(ymin, FFMIN(Ly, ymax));\
CHECK_MV(Lx2, Ly2)\
}
#define CHECK_MV(x, y)
#define FFMAX(a, b)
Definition: common.h:56
#define FFMIN(a, b)
Definition: common.h:58

Definition at line 375 of file motion_est_template.c.

Referenced by epzs_motion_search2(), epzs_motion_search4(), epzs_motion_search_internal(), full_search(), hex_search(), l2s_dia_search(), and umh_search().

#define CHECK_HALF_MV (   dx,
  dy,
  x,
  y 
)
Value:
{\
const int hx= 2*(x)+(dx);\
const int hy= 2*(y)+(dy);\
d= cmp_hpel(s, x, y, dx, dy, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);\
d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
}
const char * s
Definition: avisynth_c.h:668
set threshold d
Discrete Time axis x
int size
static int flags
Definition: cpu.c:23
static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV *2+1]
Table of number of bits a motion vector component needs.
Definition: ituh263enc.c:45
function y
Definition: D.m:1
#define COPY3_IF_LT(x, y, a, b, c, d)
Definition: mathops.h:139
static int cmp_hpel(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
Definition: motion_est.c:266

Definition at line 38 of file motion_est_template.c.

Referenced by hpel_motion_search().

#define CHECK_MV (   x,
  y 
)
Value:
{\
const unsigned key = ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
av_assert2((x) >= xmin);\
av_assert2((x) <= xmax);\
av_assert2((y) >= ymin);\
av_assert2((y) <= ymax);\
if(map[index]!=key){\
d= cmp(s, x, y, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
map[index]= key;\
score_map[index]= d;\
d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*penalty_factor;\
COPY3_IF_LT(dmin, d, best[0], x, best[1], y)\
}\
}
const char * s
Definition: avisynth_c.h:668
static int shift(int a, int b)
Definition: sonic.c:86
#define ME_MAP_SHIFT
Definition: mpegvideo.h:69
set threshold d
initialize output if(nPeaks >3)%at least 3 peaks in spectrum for trying to find f0 nf0peaks
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:63
Discrete Time axis x
int size
#define ME_MAP_MV_BITS
Definition: mpegvideo.h:70
static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
compares a block (either a full macroblock or a partition thereof) against a proposed motion-compensa...
Definition: motion_est.c:251
#define ME_MAP_SIZE
Definition: mpegvideo.h:68
int index
Definition: gxfenc.c:89
static int flags
Definition: cpu.c:23
static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV *2+1]
Table of number of bits a motion vector component needs.
Definition: ituh263enc.c:45
function y
Definition: D.m:1
#define COPY3_IF_LT(x, y, a, b, c, d)
Definition: mathops.h:139

Definition at line 358 of file motion_est_template.c.

Referenced by epzs_motion_search2(), epzs_motion_search4(), epzs_motion_search_internal(), full_search(), funny_diamond_search(), sab_diamond_search(), umh_search(), and var_diamond_search().

#define CHECK_MV_DIR (   x,
  y,
  new_dir 
)
Value:
{\
const unsigned key = ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
if(map[index]!=key){\
d= cmp(s, x, y, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
map[index]= key;\
score_map[index]= d;\
d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*penalty_factor;\
if(d<dmin){\
best[0]=x;\
best[1]=y;\
dmin=d;\
next_dir= new_dir;\
}\
}\
}
const char * s
Definition: avisynth_c.h:668
static int shift(int a, int b)
Definition: sonic.c:86
#define ME_MAP_SHIFT
Definition: mpegvideo.h:69
set threshold d
initialize output if(nPeaks >3)%at least 3 peaks in spectrum for trying to find f0 nf0peaks
Discrete Time axis x
int size
#define ME_MAP_MV_BITS
Definition: mpegvideo.h:70
static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
compares a block (either a full macroblock or a partition thereof) against a proposed motion-compensa...
Definition: motion_est.c:251
#define ME_MAP_SIZE
Definition: mpegvideo.h:68
int index
Definition: gxfenc.c:89
static int flags
Definition: cpu.c:23
static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV *2+1]
Table of number of bits a motion vector component needs.
Definition: ituh263enc.c:45
function y
Definition: D.m:1

Definition at line 384 of file motion_est_template.c.

Referenced by small_diamond_search().

#define CHECK_QUARTER_MV (   dx,
  dy,
  x,
  y 
)
Value:
{\
const int hx= 4*(x)+(dx);\
const int hy= 4*(y)+(dy);\
d= cmp_qpel(s, x, y, dx, dy, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
d += (mv_penalty[hx - pred_x] + mv_penalty[hy - pred_y])*penalty_factor;\
COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
}
static int cmp_qpel(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
Definition: motion_est.c:276
const char * s
Definition: avisynth_c.h:668
set threshold d
Discrete Time axis x
int size
static int flags
Definition: cpu.c:23
static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV *2+1]
Table of number of bits a motion vector component needs.
Definition: ituh263enc.c:45
function y
Definition: D.m:1
#define COPY3_IF_LT(x, y, a, b, c, d)
Definition: mathops.h:139

Definition at line 196 of file motion_est_template.c.

Referenced by qpel_motion_search().

#define LOAD_COMMON
Value:
uint32_t av_unused * const score_map= c->score_map;\
const int av_unused xmin= c->xmin;\
const int av_unused ymin= c->ymin;\
const int av_unused xmax= c->xmax;\
const int av_unused ymax= c->ymax;\
uint8_t *mv_penalty= c->current_mv_penalty;\
const int pred_x= c->pred_x;\
const int pred_y= c->pred_y;\
uint8_t
static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV *2+1]
Table of number of bits a motion vector component needs.
Definition: ituh263enc.c:45
static double c[64]
#define av_unused
Definition: attributes.h:114

Definition at line 28 of file motion_est_template.c.

Referenced by epzs_motion_search2(), epzs_motion_search4(), epzs_motion_search_internal(), full_search(), funny_diamond_search(), get_mb_score(), hex_search(), hpel_motion_search(), l2s_dia_search(), qpel_motion_search(), sab_diamond_search(), sad_hpel_motion_search(), small_diamond_search(), umh_search(), and var_diamond_search().

#define LOAD_COMMON2
Value:
uint32_t *map= c->map;\
const int qpel= flags&FLAG_QPEL;\
const int shift= 1+qpel;\
static int shift(int a, int b)
Definition: sonic.c:86
#define FLAG_QPEL
Definition: motion_est.c:76
static int flags
Definition: cpu.c:23
static double c[64]

Definition at line 408 of file motion_est_template.c.

Referenced by epzs_motion_search2(), epzs_motion_search4(), epzs_motion_search_internal(), full_search(), funny_diamond_search(), hex_search(), l2s_dia_search(), sab_diamond_search(), small_diamond_search(), umh_search(), and var_diamond_search().

#define MAX_SAB_SIZE   ME_MAP_SIZE

Definition at line 677 of file motion_est_template.c.

Referenced by ff_init_me(), and sab_diamond_search().

#define SAB_CHECK_MV (   ax,
  ay 
)
Value:
{\
const unsigned key = ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
const int index= (((ay)<<ME_MAP_SHIFT) + (ax))&(ME_MAP_SIZE-1);\
if(map[index]!=key){\
d= cmp(s, ax, ay, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
map[index]= key;\
score_map[index]= d;\
d += (mv_penalty[((ax)<<shift)-pred_x] + mv_penalty[((ay)<<shift)-pred_y])*penalty_factor;\
if(d < minima[minima_count-1].height){\
int j=0;\
while(d >= minima[j].height) j++;\
\
memmove(&minima [j+1], &minima [j], (minima_count - j - 1)*sizeof(Minima));\
\
minima[j].checked= 0;\
minima[j].height= d;\
minima[j].x= ax;\
minima[j].y= ay;\
\
i=-1;\
}\
}\
}
const char * s
Definition: avisynth_c.h:668
static int shift(int a, int b)
Definition: sonic.c:86
#define ME_MAP_SHIFT
Definition: mpegvideo.h:69
set threshold d
initialize output if(nPeaks >3)%at least 3 peaks in spectrum for trying to find f0 nf0peaks
int size
loc<=1||loc >=hN-1 continue()
#define ME_MAP_MV_BITS
Definition: mpegvideo.h:70
static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
compares a block (either a full macroblock or a partition thereof) against a proposed motion-compensa...
Definition: motion_est.c:251
#define ME_MAP_SIZE
Definition: mpegvideo.h:68
BYTE int const BYTE int int int height
Definition: avisynth_c.h:713
int index
Definition: gxfenc.c:89
synthesis window for stochastic i
static int flags
Definition: cpu.c:23
Synth Windw Norm while(pin< pend)%Until the end...%---Analysis x_w
static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV *2+1]
Table of number of bits a motion vector component needs.
Definition: ituh263enc.c:45

Definition at line 650 of file motion_est_template.c.

Referenced by sab_diamond_search().

Function Documentation

static av_always_inline int diamond_search ( MpegEncContext s,
int *  best,
int  dmin,
int  src_index,
int  ref_index,
int const  penalty_factor,
int  size,
int  h,
int  flags 
)
static
static int epzs_motion_search2 ( MpegEncContext s,
int *  mx_ptr,
int *  my_ptr,
int  P[10][2],
int  src_index,
int  ref_index,
int16_t(*)  last_mv[2],
int  ref_mv_scale 
)
static

Definition at line 1047 of file motion_est_template.c.

Referenced by interlaced_search().

static int epzs_motion_search4 ( MpegEncContext s,
int *  mx_ptr,
int *  my_ptr,
int  P[10][2],
int  src_index,
int  ref_index,
int16_t(*)  last_mv[2],
int  ref_mv_scale 
)
static

Definition at line 988 of file motion_est_template.c.

Referenced by h263_mv4_search().

static av_always_inline int epzs_motion_search_internal ( MpegEncContext s,
int *  mx_ptr,
int *  my_ptr,
int  P[10][2],
int  src_index,
int  ref_index,
int16_t(*)  last_mv[2],
int  ref_mv_scale,
int  flags,
int  size,
int  h 
)
static
Parameters
Pa list of candidate mvs to check before starting the iterative search. If one of the candidates is close to the optimal mv, then it takes fewer iterations. And it increases the chance that we find the optimal mv.

< x and y coordinates of the best motion vector. i.e. the difference between the position of the block currently being encoded and the position of the block chosen to predict it from.

< the score (cmp + penalty) of any given mv

< the best value of d, i.e. the score corresponding to the mv stored in best[].

Definition at line 856 of file motion_est_template.c.

Referenced by ff_epzs_motion_search().

int ff_epzs_motion_search ( MpegEncContext s,
int *  mx_ptr,
int *  my_ptr,
int  P[10][2],
int  src_index,
int  ref_index,
int16_t(*)  last_mv[2],
int  ref_mv_scale,
int  size,
int  h 
)
int ff_get_mb_score ( MpegEncContext s,
int  mx,
int  my,
int  src_index,
int  ref_index,
int  size,
int  h,
int  add_rate 
)

Definition at line 190 of file motion_est_template.c.

Referenced by encode_q_branch(), and ff_h263_round_chroma().

static int full_search ( MpegEncContext s,
int *  best,
int  dmin,
int  src_index,
int  ref_index,
int const  penalty_factor,
int  size,
int  h,
int  flags 
)
static

Definition at line 615 of file motion_est_template.c.

Referenced by diamond_search().

static int funny_diamond_search ( MpegEncContext s,
int *  best,
int  dmin,
int  src_index,
int  ref_index,
int const  penalty_factor,
int  size,
int  h,
int  flags 
)
static

Definition at line 454 of file motion_est_template.c.

Referenced by diamond_search().

static int get_mb_score ( MpegEncContext s,
int  mx,
int  my,
int  src_index,
int  ref_index,
int  size,
int  h,
int  add_rate 
)
inlinestatic
static int hex_search ( MpegEncContext s,
int *  best,
int  dmin,
int  src_index,
int  ref_index,
int const  penalty_factor,
int  size,
int  h,
int  flags,
int  dia_size 
)
static

Definition at line 496 of file motion_est_template.c.

Referenced by diamond_search(), and umh_search().

static int hpel_motion_search ( MpegEncContext s,
int *  mx_ptr,
int *  my_ptr,
int  dmin,
int  src_index,
int  ref_index,
int  size,
int  h 
)
static

Definition at line 47 of file motion_est_template.c.

Referenced by direct_search(), and ff_init_me().

static int l2s_dia_search ( MpegEncContext s,
int *  best,
int  dmin,
int  src_index,
int  ref_index,
int const  penalty_factor,
int  size,
int  h,
int  flags 
)
static

Definition at line 530 of file motion_est_template.c.

Referenced by diamond_search().

static int no_sub_motion_search ( MpegEncContext s,
int *  mx_ptr,
int *  my_ptr,
int  dmin,
int  src_index,
int  ref_index,
int  size,
int  h 
)
static

Definition at line 152 of file motion_est_template.c.

Referenced by ff_init_me().

static int qpel_motion_search ( MpegEncContext s,
int *  mx_ptr,
int *  my_ptr,
int  dmin,
int  src_index,
int  ref_index,
int  size,
int  h 
)
static

Definition at line 205 of file motion_est_template.c.

Referenced by direct_search(), and ff_init_me().

static int sab_diamond_search ( MpegEncContext s,
int *  best,
int  dmin,
int  src_index,
int  ref_index,
int const  penalty_factor,
int  size,
int  h,
int  flags 
)
static

Definition at line 678 of file motion_est_template.c.

Referenced by diamond_search().

static av_always_inline int small_diamond_search ( MpegEncContext s,
int *  best,
int  dmin,
int  src_index,
int  ref_index,
int const  penalty_factor,
int  size,
int  h,
int  flags 
)
static

Definition at line 413 of file motion_est_template.c.

Referenced by diamond_search().

static int umh_search ( MpegEncContext s,
int *  best,
int  dmin,
int  src_index,
int  ref_index,
int const  penalty_factor,
int  size,
int  h,
int  flags 
)
static

Definition at line 568 of file motion_est_template.c.

Referenced by diamond_search().

static int var_diamond_search ( MpegEncContext s,
int *  best,
int  dmin,
int  src_index,
int  ref_index,
int const  penalty_factor,
int  size,
int  h,
int  flags 
)
static

Definition at line 767 of file motion_est_template.c.

Referenced by diamond_search().