FFmpeg
Loading...
Searching...
No Matches
motion_est_template.c File Reference

Motion estimation template. More...

#include "libavutil/qsort.h"
#include "mpegvideoenc.h"

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 (MPVEncContext *const 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 (MPVEncContext *const s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
 
static int get_mb_score (MPVEncContext *const s, int mx, int my, int src_index, int ref_index, int size, int h, int add_rate)
 
int ff_get_mb_score (MPVEncContext *const s, int mx, int my, int src_index, int ref_index, int size, int h, int add_rate)
 
static int qpel_motion_search (MPVEncContext *const 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 (MPVEncContext *const s, int *best, int dmin, int src_index, int ref_index, const int penalty_factor, int size, int h, int flags)
 
static int funny_diamond_search (MPVEncContext *const s, int *best, int dmin, int src_index, int ref_index, const int penalty_factor, int size, int h, int flags)
 
static int hex_search (MPVEncContext *const s, int *best, int dmin, int src_index, int ref_index, const int penalty_factor, int size, int h, int flags, int dia_size)
 
static int l2s_dia_search (MPVEncContext *const s, int *best, int dmin, int src_index, int ref_index, const int penalty_factor, int size, int h, int flags)
 
static int umh_search (MPVEncContext *const s, int *best, int dmin, int src_index, int ref_index, const int penalty_factor, int size, int h, int flags)
 
static int full_search (MPVEncContext *const s, int *best, int dmin, int src_index, int ref_index, const int penalty_factor, int size, int h, int flags)
 
static int sab_diamond_search (MPVEncContext *const s, int *best, int dmin, int src_index, int ref_index, const int penalty_factor, int size, int h, int flags)
 
static int var_diamond_search (MPVEncContext *const s, int *best, int dmin, int src_index, int ref_index, const int penalty_factor, int size, int h, int flags)
 
static av_always_inline int diamond_search (MPVEncContext *const s, int *best, int dmin, int src_index, int ref_index, const int penalty_factor, int size, int h, int flags)
 
static av_always_inline int epzs_motion_search_internal (MPVEncContext *const s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, const int16_t(*last_mv)[2], int ref_mv_scale, int flags, int size, int h)
 
int ff_epzs_motion_search (MPVEncContext *const s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, const int16_t(*last_mv)[2], int ref_mv_scale, int size, int h)
 
static int epzs_motion_search2 (MPVEncContext *const s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, const int16_t(*last_mv)[2], int ref_mv_scale, const int size)
 

Detailed Description

Motion estimation template.

Definition in file motion_est_template.c.

Macro Definition Documentation

◆ LOAD_COMMON

#define LOAD_COMMON
Value:
av_unused uint32_t * const score_map= c->score_map;\
av_unused const int xmin= c->xmin;\
av_unused const int ymin= c->ymin;\
av_unused const int xmax= c->xmax;\
av_unused const int ymax= c->ymax;\
const uint8_t *mv_penalty = c->current_mv_penalty; \
const int pred_x= c->pred_x;\
const int pred_y= c->pred_y;\
static uint8_t mv_penalty[MAX_FCODE+1][MAX_DMV *2+1]
Definition h261enc.c:53
#define av_unused
Definition attributes.h:164
static double c[64]

Definition at line 31 of file motion_est_template.c.

Referenced by epzs_motion_search2(), 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().

◆ CHECK_HALF_MV

#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)\
}
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define s(width, name)
Definition cbs_vp9.c:198
static int cmp_hpel(MPVEncContext *const 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:278
int size

Definition at line 41 of file motion_est_template.c.

Referenced by hpel_motion_search().

◆ CHECK_QUARTER_MV

#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(MPVEncContext *const 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:288

Definition at line 198 of file motion_est_template.c.

Referenced by qpel_motion_search().

◆ CHECK_MV

#define CHECK_MV ( x,
y )
Value:
{\
const unsigned key = ((unsigned)(y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
const int index= (((unsigned)(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);\
score_map[index]= d;\
d += (mv_penalty[((x)*(1<<shift))-pred_x] + mv_penalty[((y)*(1<<shift))-pred_y])*penalty_factor;\
COPY3_IF_LT(dmin, d, best[0], x, best[1], y)\
}\
}
const char * key
int index
Definition gxfenc.c:90
const VDPAUPixFmtMap * map
static int shift(int a, int b)
Definition bonk.c:261
#define ME_MAP_MV_BITS
Definition motion_est.c:48
#define ME_MAP_SHIFT
Definition motion_est.c:47
static av_always_inline int cmp(MPVEncContext *const 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:263
#define ME_MAP_SIZE
Definition motion_est.h:40

Definition at line 361 of file motion_est_template.c.

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

◆ CHECK_CLIPPED_MV

#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 FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47

Definition at line 378 of file motion_est_template.c.

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

◆ CHECK_MV_DIR

#define CHECK_MV_DIR ( x,
y,
new_dir )
Value:
{\
const unsigned key = ((unsigned)(y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
const int index= (((unsigned)(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);\
score_map[index]= d;\
d += (mv_penalty[(int)((unsigned)(x)<<shift)-pred_x] + mv_penalty[(int)((unsigned)(y)<<shift)-pred_y])*penalty_factor;\
if(d<dmin){\
best[0]=x;\
best[1]=y;\
dmin=d;\
next_dir= new_dir;\
}\
}\
}

Definition at line 387 of file motion_est_template.c.

Referenced by small_diamond_search().

◆ check

#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->c.mb_x, s->c.mb_y);\
if( (x)>(xmax<<(S)) ) av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d xmax" #v, xmax, (x), (y), s->c.mb_x, s->c.mb_y);\
if( (y)<(ymin<<(S)) ) av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d ymin" #v, ymin, (x), (y), s->c.mb_x, s->c.mb_y);\
if( (y)>(ymax<<(S)) ) av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d ymax" #v, ymax, (x), (y), s->c.mb_x, s->c.mb_y);\
#define NULL
Definition coverity.c:32
#define S(s, c, i)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
#define av_log(a,...)
Examples
ffhash.c.

Definition at line 405 of file motion_est_template.c.

Referenced by check(), config_input(), dxv_decompress_dxt5(), h261_decode_block(), main(), merge_channel_layouts_internal(), merge_formats_internal(), merge_generic_internal(), merge_samplerates_internal(), mp3_read_header(), mp3_sync(), test_device_type(), and voc_probe().

◆ LOAD_COMMON2

#define LOAD_COMMON2

◆ SAB_CHECK_MV

#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);\
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;\
continue;\
}\
}\
}
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define height
Definition dsp.h:89

Definition at line 653 of file motion_est_template.c.

Referenced by sab_diamond_search().

◆ MAX_SAB_SIZE

#define MAX_SAB_SIZE   ME_MAP_SIZE

Definition at line 680 of file motion_est_template.c.

Referenced by ff_me_init(), and sab_diamond_search().

Function Documentation

◆ hpel_motion_search()

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

Definition at line 50 of file motion_est_template.c.

Referenced by direct_search(), and ff_me_init().

◆ no_sub_motion_search()

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

Definition at line 155 of file motion_est_template.c.

Referenced by ff_me_init().

◆ get_mb_score()

static int get_mb_score ( MPVEncContext *const s,
int mx,
int my,
int src_index,
int ref_index,
int size,
int h,
int add_rate )
inlinestatic

◆ ff_get_mb_score()

int ff_get_mb_score ( MPVEncContext *const s,
int mx,
int my,
int src_index,
int ref_index,
int size,
int h,
int add_rate )

Definition at line 192 of file motion_est_template.c.

Referenced by encode_q_branch().

◆ qpel_motion_search()

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

Definition at line 207 of file motion_est_template.c.

Referenced by direct_search(), and ff_me_init().

◆ small_diamond_search()

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

Definition at line 416 of file motion_est_template.c.

Referenced by diamond_search().

◆ funny_diamond_search()

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

Definition at line 457 of file motion_est_template.c.

Referenced by diamond_search().

◆ hex_search()

static int hex_search ( MPVEncContext *const s,
int * best,
int dmin,
int src_index,
int ref_index,
const int penalty_factor,
int size,
int h,
int flags,
int dia_size )
static

Definition at line 499 of file motion_est_template.c.

Referenced by diamond_search(), and umh_search().

◆ l2s_dia_search()

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

Definition at line 533 of file motion_est_template.c.

Referenced by diamond_search().

◆ umh_search()

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

Definition at line 571 of file motion_est_template.c.

Referenced by diamond_search().

◆ full_search()

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

Definition at line 618 of file motion_est_template.c.

Referenced by diamond_search().

◆ sab_diamond_search()

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

Definition at line 681 of file motion_est_template.c.

Referenced by diamond_search().

◆ var_diamond_search()

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

Definition at line 771 of file motion_est_template.c.

Referenced by diamond_search().

◆ diamond_search()

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

Definition at line 832 of file motion_est_template.c.

Referenced by epzs_motion_search2(), and epzs_motion_search_internal().

◆ epzs_motion_search_internal()

static av_always_inline int epzs_motion_search_internal ( MPVEncContext *const s,
int * mx_ptr,
int * my_ptr,
int P[10][2],
int src_index,
int ref_index,
const 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 860 of file motion_est_template.c.

Referenced by ff_epzs_motion_search().

◆ ff_epzs_motion_search()

int ff_epzs_motion_search ( MPVEncContext *const s,
int * mx_ptr,
int * my_ptr,
int P[10][2],
int src_index,
int ref_index,
const int16_t(*) last_mv[2],
int ref_mv_scale,
int size,
int h )

◆ epzs_motion_search2()

static int epzs_motion_search2 ( MPVEncContext *const s,
int * mx_ptr,
int * my_ptr,
int P[10][2],
int src_index,
int ref_index,
const int16_t(*) last_mv[2],
int ref_mv_scale,
const int size )
static

Definition at line 993 of file motion_est_template.c.

Referenced by h263_mv4_search(), and interlaced_search().