libavcodec/motion_est.c File Reference

Motion estimation. More...

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include "libavutil/intmath.h"
#include "avcodec.h"
#include "dsputil.h"
#include "mathops.h"
#include "mpegvideo.h"
#include <assert.h>
#include "motion_est_template.c"

Go to the source code of this file.

Data Structures

struct  Minima

Defines

#define SQ(a)   ((a)*(a))
#define P_LEFT   P[1]
#define P_TOP   P[2]
#define P_TOPRIGHT   P[3]
#define P_MEDIAN   P[4]
#define P_MV1   P[9]
#define FLAG_QPEL   1
#define FLAG_CHROMA   2
#define FLAG_DIRECT   4
#define Z_THRESHOLD   256
#define CHECK_SAD_HALF_MV(suffix, x, y)
#define HASH(fx, fy, bx, by)   ((fx)+17*(fy)+63*(bx)+117*(by))
#define HASH8(fx, fy, bx, by)   ((uint8_t)HASH(fx,fy,bx,by))
#define CHECK_BIDIR(fx, fy, bx, by)
#define CHECK_BIDIR2(a, b, c, d)

Functions

static int sad_hpel_motion_search (MpegEncContext *s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
static unsigned update_map_generation (MotionEstContext *c)
static int minima_cmp (const void *a, const void *b)
static void init_ref (MotionEstContext *c, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3], int x, int y, int ref_index)
static int get_flags (MotionEstContext *c, int direct, int chroma)
static av_always_inline int cmp_direct_inline (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, int qpel)
static av_always_inline int cmp_inline (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, int qpel, int chroma)
static int cmp_simple (MpegEncContext *s, const int x, const int y, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func)
static int cmp_fpel_internal (MpegEncContext *s, const int x, const int y, 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)
static int cmp_internal (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)
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-compensated prediction of that block
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)
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)
static int zero_cmp (void *s, uint8_t *a, uint8_t *b, int stride, int h)
static void zero_hpel (uint8_t *a, const uint8_t *b, int stride, int h)
int ff_init_me (MpegEncContext *s)
static void no_motion_search (MpegEncContext *s, int *mx_ptr, int *my_ptr)
static void set_p_mv_tables (MpegEncContext *s, int mx, int my, int mv4)
static void get_limits (MpegEncContext *s, int x, int y)
 get fullpel ME search limits.
static void init_mv4_ref (MotionEstContext *c)
static int h263_mv4_search (MpegEncContext *s, int mx, int my, int shift)
static void init_interlaced_ref (MpegEncContext *s, int ref_index)
static int interlaced_search (MpegEncContext *s, int ref_index, int16_t(*mv_tables[2][2])[2], uint8_t *field_select_tables[2], int mx, int my, int user_field_select)
static void clip_input_mv (MpegEncContext *s, int16_t *mv, int interlaced)
static int check_input_motion (MpegEncContext *s, int mb_x, int mb_y, int p_type)
void ff_estimate_p_frame_motion (MpegEncContext *s, int mb_x, int mb_y)
int ff_pre_estimate_p_frame_motion (MpegEncContext *s, int mb_x, int mb_y)
static int ff_estimate_motion_b (MpegEncContext *s, int mb_x, int mb_y, int16_t(*mv_table)[2], int ref_index, int f_code)
static int check_bidir_mv (MpegEncContext *s, int motion_fx, int motion_fy, int motion_bx, int motion_by, int pred_fx, int pred_fy, int pred_bx, int pred_by, int size, int h)
static int bidir_refine (MpegEncContext *s, int mb_x, int mb_y)
static int direct_search (MpegEncContext *s, int mb_x, int mb_y)
void ff_estimate_b_frame_motion (MpegEncContext *s, int mb_x, int mb_y)
int ff_get_best_fcode (MpegEncContext *s, int16_t(*mv_table)[2], int type)
void ff_fix_long_p_mvs (MpegEncContext *s)
void ff_fix_long_mvs (MpegEncContext *s, uint8_t *field_select_table, int field_select, int16_t(*mv_table)[2], int f_code, int type, int truncate)


Detailed Description

Motion estimation.

Definition in file motion_est.c.


Define Documentation

#define CHECK_BIDIR ( fx,
fy,
bx,
by   ) 

Value:

if( !map[(hashidx+HASH(fx,fy,bx,by))&255]\
       &&(fx<=0 || motion_fx+fx<=xmax) && (fy<=0 || motion_fy+fy<=ymax) && (bx<=0 || motion_bx+bx<=xmax) && (by<=0 || motion_by+by<=ymax)\
       &&(fx>=0 || motion_fx+fx>=xmin) && (fy>=0 || motion_fy+fy>=ymin) && (bx>=0 || motion_bx+bx>=xmin) && (by>=0 || motion_by+by>=ymin)){\
        int score;\
        map[(hashidx+HASH(fx,fy,bx,by))&255] = 1;\
        score= check_bidir_mv(s, motion_fx+fx, motion_fy+fy, motion_bx+bx, motion_by+by, pred_fx, pred_fy, pred_bx, pred_by, 0, 16);\
        if(score < fbmin){\
            hashidx += HASH(fx,fy,bx,by);\
            fbmin= score;\
            motion_fx+=fx;\
            motion_fy+=fy;\
            motion_bx+=bx;\
            motion_by+=by;\
            end=0;\
        }\
    }

#define CHECK_BIDIR2 ( a,
b,
c,
 ) 

Value:

CHECK_BIDIR(a,b,c,d)\
CHECK_BIDIR(-(a),-(b),-(c),-(d))

Referenced by bidir_refine().

#define CHECK_SAD_HALF_MV ( suffix,
x,
 ) 

Value:

{\
    d= s->dsp.pix_abs[size][(x?1:0)+(y?2:0)](NULL, pix, ptr+((x)>>1), stride, h);\
    d += (mv_penalty[pen_x + x] + mv_penalty[pen_y + y])*penalty_factor;\
    COPY3_IF_LT(dminh, d, dx, x, dy, y)\
}

Definition at line 410 of file motion_est.c.

Referenced by sad_hpel_motion_search().

#define FLAG_CHROMA   2

#define FLAG_DIRECT   4

#define FLAG_QPEL   1

#define HASH ( fx,
fy,
bx,
by   )     ((fx)+17*(fy)+63*(bx)+117*(by))

Referenced by bidir_refine().

#define HASH8 ( fx,
fy,
bx,
by   )     ((uint8_t)HASH(fx,fy,bx,by))

Referenced by bidir_refine().

#define P_LEFT   P[1]

#define P_MEDIAN   P[4]

#define P_MV1   P[9]

#define P_TOP   P[2]

#define P_TOPRIGHT   P[3]

#define SQ (  )     ((a)*(a))

Definition at line 42 of file motion_est.c.

#define Z_THRESHOLD   256

Definition at line 408 of file motion_est.c.


Function Documentation

static int bidir_refine ( MpegEncContext s,
int  mb_x,
int  mb_y 
) [inline, static]

Definition at line 1453 of file motion_est.c.

Referenced by ff_estimate_b_frame_motion(), and update_context_from_user().

static int check_bidir_mv ( MpegEncContext s,
int  motion_fx,
int  motion_fy,
int  motion_bx,
int  motion_by,
int  pred_fx,
int  pred_fy,
int  pred_bx,
int  pred_by,
int  size,
int  h 
) [inline, static]

Definition at line 1388 of file motion_est.c.

Referenced by bidir_refine().

static int check_input_motion ( MpegEncContext s,
int  mb_x,
int  mb_y,
int  p_type 
) [inline, static]

Definition at line 877 of file motion_est.c.

Referenced by ff_estimate_b_frame_motion(), and ff_estimate_p_frame_motion().

static void clip_input_mv ( MpegEncContext s,
int16_t *  mv,
int  interlaced 
) [static]

Definition at line 867 of file motion_est.c.

Referenced by check_input_motion().

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 
) [static]

compares a block (either a full macroblock or a partition thereof) against a proposed motion-compensated prediction of that block

Definition at line 254 of file motion_est.c.

Referenced by av_tree_enumerate(), av_tree_find(), av_tree_insert(), check_input_motion(), epzs_motion_search_internal(), ff_get_mb_score(), hpel_motion_search(), qpel_motion_search(), and small_diamond_search().

static av_always_inline int cmp_direct_inline ( 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,
int  qpel 
) [static]

Definition at line 107 of file motion_est.c.

Referenced by cmp_fpel_internal(), cmp_hpel(), cmp_internal(), and cmp_qpel().

static int cmp_fpel_internal ( MpegEncContext s,
const int  x,
const int  y,
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 
) [static]

Definition at line 231 of file motion_est.c.

Referenced by cmp().

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 
) [static]

Definition at line 269 of file motion_est.c.

static av_always_inline int cmp_inline ( 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,
int  qpel,
int  chroma 
) [static]

Definition at line 179 of file motion_est.c.

Referenced by cmp_fpel_internal(), cmp_hpel(), cmp_internal(), cmp_qpel(), and cmp_simple().

static int cmp_internal ( 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 
) [static]

Definition at line 241 of file motion_est.c.

Referenced by cmp().

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 
) [static]

Definition at line 279 of file motion_est.c.

static int cmp_simple ( MpegEncContext s,
const int  x,
const int  y,
int  ref_index,
int  src_index,
me_cmp_func  cmp_func,
me_cmp_func  chroma_cmp_func 
) [static]

Definition at line 225 of file motion_est.c.

Referenced by cmp().

static int direct_search ( MpegEncContext s,
int  mb_x,
int  mb_y 
) [inline, static]

Definition at line 1601 of file motion_est.c.

Referenced by ff_estimate_b_frame_motion().

void ff_estimate_b_frame_motion ( MpegEncContext s,
int  mb_x,
int  mb_y 
)

Definition at line 1703 of file motion_est.c.

Referenced by estimate_motion_thread().

static int ff_estimate_motion_b ( MpegEncContext s,
int  mb_x,
int  mb_y,
int16_t(*)  mv_table[2],
int  ref_index,
int  f_code 
) [static]

Definition at line 1312 of file motion_est.c.

Referenced by ff_estimate_b_frame_motion().

void ff_estimate_p_frame_motion ( MpegEncContext s,
int  mb_x,
int  mb_y 
)

< the variance of the block (sum of squared (p[y][x]-average))

< sum of squared differences with the estimated motion vector

Definition at line 1013 of file motion_est.c.

Referenced by estimate_motion_thread(), and svq1_encode_plane().

void ff_fix_long_mvs ( MpegEncContext s,
uint8_t *  field_select_table,
int  field_select,
int16_t(*)  mv_table[2],
int  f_code,
int  type,
int  truncate 
)

Parameters:
truncate 1 for truncation, 0 for using intra

Definition at line 1972 of file motion_est.c.

Referenced by encode_picture(), and svq1_encode_plane().

void ff_fix_long_p_mvs ( MpegEncContext s  ) 

Definition at line 1921 of file motion_est.c.

Referenced by encode_picture(), and svq1_encode_plane().

int ff_get_best_fcode ( MpegEncContext s,
int16_t(*)  mv_table[2],
int  type 
)

Definition at line 1862 of file motion_est.c.

Referenced by encode_picture().

int ff_init_me ( MpegEncContext s  ) 

Definition at line 298 of file motion_est.c.

Referenced by encode_picture(), and svq1_encode_plane().

int ff_pre_estimate_p_frame_motion ( MpegEncContext s,
int  mb_x,
int  mb_y 
)

Definition at line 1259 of file motion_est.c.

Referenced by pre_estimate_motion_thread().

static int get_flags ( MotionEstContext c,
int  direct,
int  chroma 
) [static]

Definition at line 101 of file motion_est.c.

Referenced by ff_init_me().

static void get_limits ( MpegEncContext s,
int  x,
int  y 
) [inline, static]

static int h263_mv4_search ( MpegEncContext s,
int  mx,
int  my,
int  shift 
) [inline, static]

Definition at line 596 of file motion_est.c.

Referenced by ff_estimate_p_frame_motion().

static void init_interlaced_ref ( MpegEncContext s,
int  ref_index 
) [inline, static]

Definition at line 732 of file motion_est.c.

Referenced by check_input_motion(), and interlaced_search().

static void init_mv4_ref ( MotionEstContext c  )  [inline, static]

Definition at line 585 of file motion_est.c.

Referenced by check_input_motion(), and h263_mv4_search().

static void init_ref ( MotionEstContext c,
uint8_t *  src[3],
uint8_t *  ref[3],
uint8_t *  ref2[3],
int  x,
int  y,
int  ref_index 
) [inline, static]

static int interlaced_search ( MpegEncContext s,
int  ref_index,
int16_t(*[2][2])  mv_tables[2],
uint8_t *  field_select_tables[2],
int  mx,
int  my,
int  user_field_select 
) [static]

Definition at line 745 of file motion_est.c.

Referenced by ff_estimate_b_frame_motion(), and ff_estimate_p_frame_motion().

static int minima_cmp ( const void *  a,
const void *  b 
) [static]

Definition at line 72 of file motion_est.c.

Referenced by sab_diamond_search().

static void no_motion_search ( MpegEncContext s,
int *  mx_ptr,
int *  my_ptr 
) [inline, static]

Definition at line 401 of file motion_est.c.

Referenced by ff_estimate_motion_b(), and ff_estimate_p_frame_motion().

static int sad_hpel_motion_search ( MpegEncContext s,
int *  mx_ptr,
int *  my_ptr,
int  dmin,
int  src_index,
int  ref_index,
int  size,
int  h 
) [inline, static]

Definition at line 417 of file motion_est.c.

Referenced by ff_init_me().

static void set_p_mv_tables ( MpegEncContext s,
int  mx,
int  my,
int  mv4 
) [inline, static]

Definition at line 525 of file motion_est.c.

Referenced by ff_estimate_p_frame_motion().

static unsigned update_map_generation ( MotionEstContext c  )  [inline, static]

static int zero_cmp ( void *  s,
uint8_t *  a,
uint8_t *  b,
int  stride,
int  h 
) [static]

Definition at line 291 of file motion_est.c.

static void zero_hpel ( uint8_t *  a,
const uint8_t *  b,
int  stride,
int  h 
) [static]

Definition at line 295 of file motion_est.c.

Referenced by ff_init_me().


Generated on Fri Oct 26 02:38:17 2012 for FFmpeg by  doxygen 1.5.8