FFmpeg
Macros | Functions | Variables
me_cmp.c File Reference
#include "libavutil/attributes.h"
#include "libavutil/internal.h"
#include "libavutil/mem_internal.h"
#include "avcodec.h"
#include "copy_block.h"
#include "simple_idct.h"
#include "me_cmp.h"
#include "mpegvideo.h"
#include "config.h"

Go to the source code of this file.

Macros

#define avg2(a, b)   (((a) + (b) + 1) >> 1)
 
#define avg4(a, b, c, d)   (((a) + (b) + (c) + (d) + 2) >> 2)
 
#define V(x)   (pix1[x] - pix2[x])
 
#define V(x)   (pix1[x] - pix2[x])
 
#define BUTTERFLY2(o1, o2, i1, i2)
 
#define BUTTERFLY1(x, y)
 
#define BUTTERFLYA(x, y)   (FFABS((x) + (y)) + FFABS((x) - (y)))
 
#define VSAD_INTRA(size)
 
#define VSAD(size)
 
#define SQ(a)   ((a) * (a))
 
#define VSSE_INTRA(size)
 
#define VSSE(size)
 
#define WRAPPER8_16_SQ(name8, name16)
 
#define SET_CMP_FUNC(name)
 

Functions

static int sse4_c (MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, ptrdiff_t stride, int h)
 
static int sse8_c (MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, ptrdiff_t stride, int h)
 
static int sse16_c (MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, ptrdiff_t stride, int h)
 
static int sum_abs_dctelem_c (int16_t *block)
 
static int pix_abs16_c (MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, ptrdiff_t stride, int h)
 
static int pix_median_abs16_c (MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, ptrdiff_t stride, int h)
 
static int pix_abs16_x2_c (MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, ptrdiff_t stride, int h)
 
static int pix_abs16_y2_c (MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, ptrdiff_t stride, int h)
 
static int pix_abs16_xy2_c (MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, ptrdiff_t stride, int h)
 
static int pix_abs8_c (MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, ptrdiff_t stride, int h)
 
static int pix_median_abs8_c (MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, ptrdiff_t stride, int h)
 
static int pix_abs8_x2_c (MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, ptrdiff_t stride, int h)
 
static int pix_abs8_y2_c (MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, ptrdiff_t stride, int h)
 
static int pix_abs8_xy2_c (MpegEncContext *v, uint8_t *pix1, uint8_t *pix2, ptrdiff_t stride, int h)
 
static int nsse16_c (MpegEncContext *c, uint8_t *s1, uint8_t *s2, ptrdiff_t stride, int h)
 
static int nsse8_c (MpegEncContext *c, uint8_t *s1, uint8_t *s2, ptrdiff_t stride, int h)
 
static int zero_cmp (MpegEncContext *s, uint8_t *a, uint8_t *b, ptrdiff_t stride, int h)
 
void ff_set_cmp (MECmpContext *c, me_cmp_func *cmp, int type)
 
static int hadamard8_diff8x8_c (MpegEncContext *s, uint8_t *dst, uint8_t *src, ptrdiff_t stride, int h)
 
static int hadamard8_intra8x8_c (MpegEncContext *s, uint8_t *src, uint8_t *dummy, ptrdiff_t stride, int h)
 
static int dct_sad8x8_c (MpegEncContext *s, uint8_t *src1, uint8_t *src2, ptrdiff_t stride, int h)
 
static int dct_max8x8_c (MpegEncContext *s, uint8_t *src1, uint8_t *src2, ptrdiff_t stride, int h)
 
static int quant_psnr8x8_c (MpegEncContext *s, uint8_t *src1, uint8_t *src2, ptrdiff_t stride, int h)
 
static int rd8x8_c (MpegEncContext *s, uint8_t *src1, uint8_t *src2, ptrdiff_t stride, int h)
 
static int bit8x8_c (MpegEncContext *s, uint8_t *src1, uint8_t *src2, ptrdiff_t stride, int h)
 
av_cold void ff_me_cmp_init (MECmpContext *c, AVCodecContext *avctx)
 

Variables

const uint32_t ff_square_tab [512]
 

Macro Definition Documentation

#define avg2 (   a,
  b 
)    (((a) + (b) + 1) >> 1)

Definition at line 146 of file me_cmp.c.

Referenced by pix_abs16_x2_c(), pix_abs16_y2_c(), pix_abs8_x2_c(), and pix_abs8_y2_c().

#define avg4 (   a,
  b,
  c,
 
)    (((a) + (b) + (c) + (d) + 2) >> 2)

Definition at line 147 of file me_cmp.c.

Referenced by avg2(), pix_abs16_xy2_c(), and pix_abs8_xy2_c().

#define V (   x)    (pix1[x] - pix2[x])
#define V (   x)    (pix1[x] - pix2[x])
#define BUTTERFLY2 (   o1,
  o2,
  i1,
  i2 
)
Value:
o1 = (i1) + (i2); \
o2 = (i1) - (i2);

Definition at line 540 of file me_cmp.c.

Referenced by hadamard8_diff8x8_c(), and hadamard8_intra8x8_c().

#define BUTTERFLY1 (   x,
 
)
Value:
{ \
int a, b; \
a = x; \
b = y; \
x = a + b; \
y = a - b; \
}
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:36
#define b
Definition: input.c:41
int

Definition at line 544 of file me_cmp.c.

Referenced by hadamard8_diff8x8_c(), and hadamard8_intra8x8_c().

#define BUTTERFLYA (   x,
 
)    (FFABS((x) + (y)) + FFABS((x) - (y)))

Definition at line 553 of file me_cmp.c.

Referenced by hadamard8_diff8x8_c(), and hadamard8_intra8x8_c().

#define VSAD_INTRA (   size)
Value:
static int vsad_intra ## size ## _c(MpegEncContext *c, \
ptrdiff_t stride, int h) \
{ \
int score = 0, x, y; \
for (y = 1; y < h; y++) { \
for (x = 0; x < size; x += 4) { \
score += FFABS(s[x] - s[x + stride]) + \
FFABS(s[x + 1] - s[x + stride + 1]) + \
FFABS(s[x + 2] - s[x + 2 + stride]) + \
FFABS(s[x + 3] - s[x + 3 + stride]); \
} \
s += stride; \
} \
\
return score; \
}
uint8_t
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ptrdiff_t size
Definition: opengl_enc.c:100
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
#define s(width, name)
Definition: cbs_vp9.c:257
int dummy
Definition: motion.c:64
MpegEncContext.
Definition: mpegvideo.h:81
int
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:104
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a it should return
#define stride
for(j=16;j >0;--j)

Definition at line 905 of file me_cmp.c.

#define VSAD (   size)
Value:
static int vsad ## size ## _c(MpegEncContext *c, \
ptrdiff_t stride, int h) \
{ \
int score = 0, x, y; \
for (y = 1; y < h; y++) { \
for (x = 0; x < size; x++) \
score += FFABS(s1[x] - s2[x] - s1[x + stride] + s2[x + stride]); \
s2 += stride; \
} \
\
return score; \
}
uint8_t
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ptrdiff_t size
Definition: opengl_enc.c:100
#define s2
Definition: regdef.h:39
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
#define s1
Definition: regdef.h:38
MpegEncContext.
Definition: mpegvideo.h:81
int
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:104
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a it should return
#define stride
for(j=16;j >0;--j)

Definition at line 927 of file me_cmp.c.

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

Definition at line 946 of file me_cmp.c.

#define VSSE_INTRA (   size)
Value:
static int vsse_intra ## size ## _c(MpegEncContext *c, \
ptrdiff_t stride, int h) \
{ \
int score = 0, x, y; \
for (y = 1; y < h; y++) { \
for (x = 0; x < size; x += 4) { \
score += SQ(s[x] - s[x + stride]) + \
SQ(s[x + 1] - s[x + stride + 1]) + \
SQ(s[x + 2] - s[x + stride + 2]) + \
SQ(s[x + 3] - s[x + stride + 3]); \
} \
s += stride; \
} \
\
return score; \
}
uint8_t
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ptrdiff_t size
Definition: opengl_enc.c:100
#define s(width, name)
Definition: cbs_vp9.c:257
int dummy
Definition: motion.c:64
#define SQ(a)
Definition: me_cmp.c:946
MpegEncContext.
Definition: mpegvideo.h:81
int
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:104
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a it should return
#define stride
for(j=16;j >0;--j)

Definition at line 947 of file me_cmp.c.

#define VSSE (   size)
Value:
static int vsse ## size ## _c(MpegEncContext *c, uint8_t *s1, uint8_t *s2, \
ptrdiff_t stride, int h) \
{ \
int score = 0, x, y; \
for (y = 1; y < h; y++) { \
for (x = 0; x < size; x++) \
score += SQ(s1[x] - s2[x] - s1[x + stride] + s2[x + stride]); \
s2 += stride; \
} \
\
return score; \
}
uint8_t
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
ptrdiff_t size
Definition: opengl_enc.c:100
#define s2
Definition: regdef.h:39
#define s1
Definition: regdef.h:38
#define SQ(a)
Definition: me_cmp.c:946
MpegEncContext.
Definition: mpegvideo.h:81
int
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:104
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a it should return
#define stride
for(j=16;j >0;--j)

Definition at line 969 of file me_cmp.c.

#define WRAPPER8_16_SQ (   name8,
  name16 
)
Value:
static int name16(MpegEncContext *s, uint8_t *dst, uint8_t *src, \
ptrdiff_t stride, int h) \
{ \
int score = 0; \
\
score += name8(s, dst, src, stride, 8); \
score += name8(s, dst + 8, src + 8, stride, 8); \
if (h == 16) { \
dst += 8 * stride; \
src += 8 * stride; \
score += name8(s, dst, src, stride, 8); \
score += name8(s, dst + 8, src + 8, stride, 8); \
} \
return score; \
}
uint8_t
#define src
Definition: vp8dsp.c:255
#define s(width, name)
Definition: cbs_vp9.c:257
if(ret)
MpegEncContext.
Definition: mpegvideo.h:81
int
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:104
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a it should return
#define stride

Definition at line 987 of file me_cmp.c.

#define SET_CMP_FUNC (   name)
Value:
c->name[0] = name ## 16_c; \
c->name[1] = name ## 8x8_c;
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
const char * name
Definition: opengl_enc.c:102

Referenced by ff_me_cmp_init().

Function Documentation

static int sse4_c ( MpegEncContext v,
uint8_t pix1,
uint8_t pix2,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 69 of file me_cmp.c.

Referenced by ff_me_cmp_init().

static int sse8_c ( MpegEncContext v,
uint8_t pix1,
uint8_t pix2,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 86 of file me_cmp.c.

Referenced by ff_me_cmp_init().

static int sse16_c ( MpegEncContext v,
uint8_t pix1,
uint8_t pix2,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 107 of file me_cmp.c.

Referenced by ff_me_cmp_init().

static int sum_abs_dctelem_c ( int16_t *  block)
static

Definition at line 137 of file me_cmp.c.

Referenced by ff_me_cmp_init().

static int pix_abs16_c ( MpegEncContext v,
uint8_t pix1,
uint8_t pix2,
ptrdiff_t  stride,
int  h 
)
inlinestatic

Definition at line 149 of file me_cmp.c.

Referenced by ff_me_cmp_init().

static int pix_median_abs16_c ( MpegEncContext v,
uint8_t pix1,
uint8_t pix2,
ptrdiff_t  stride,
int  h 
)
inlinestatic

Definition at line 177 of file me_cmp.c.

Referenced by ff_me_cmp_init().

static int pix_abs16_x2_c ( MpegEncContext v,
uint8_t pix1,
uint8_t pix2,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 216 of file me_cmp.c.

Referenced by ff_me_cmp_init().

static int pix_abs16_y2_c ( MpegEncContext v,
uint8_t pix1,
uint8_t pix2,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 244 of file me_cmp.c.

Referenced by ff_me_cmp_init().

static int pix_abs16_xy2_c ( MpegEncContext v,
uint8_t pix1,
uint8_t pix2,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 274 of file me_cmp.c.

Referenced by ff_me_cmp_init().

static int pix_abs8_c ( MpegEncContext v,
uint8_t pix1,
uint8_t pix2,
ptrdiff_t  stride,
int  h 
)
inlinestatic

Definition at line 304 of file me_cmp.c.

Referenced by ff_me_cmp_init().

static int pix_median_abs8_c ( MpegEncContext v,
uint8_t pix1,
uint8_t pix2,
ptrdiff_t  stride,
int  h 
)
inlinestatic

Definition at line 324 of file me_cmp.c.

Referenced by ff_me_cmp_init().

static int pix_abs8_x2_c ( MpegEncContext v,
uint8_t pix1,
uint8_t pix2,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 355 of file me_cmp.c.

Referenced by ff_me_cmp_init().

static int pix_abs8_y2_c ( MpegEncContext v,
uint8_t pix1,
uint8_t pix2,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 375 of file me_cmp.c.

Referenced by ff_me_cmp_init().

static int pix_abs8_xy2_c ( MpegEncContext v,
uint8_t pix1,
uint8_t pix2,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 397 of file me_cmp.c.

Referenced by ff_me_cmp_init().

static int nsse16_c ( MpegEncContext c,
uint8_t s1,
uint8_t s2,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 419 of file me_cmp.c.

Referenced by ff_me_cmp_init().

static int nsse8_c ( MpegEncContext c,
uint8_t s1,
uint8_t s2,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 444 of file me_cmp.c.

Referenced by ff_me_cmp_init().

static int zero_cmp ( MpegEncContext s,
uint8_t a,
uint8_t b,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 469 of file me_cmp.c.

Referenced by ff_set_cmp().

void ff_set_cmp ( MECmpContext c,
me_cmp_func cmp,
int  type 
)

Definition at line 475 of file me_cmp.c.

Referenced by dvvideo_encode_init(), encode_init(), ff_init_me(), and ff_mpv_encode_init().

static int hadamard8_diff8x8_c ( MpegEncContext s,
uint8_t dst,
uint8_t src,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 555 of file me_cmp.c.

static int hadamard8_intra8x8_c ( MpegEncContext s,
uint8_t src,
uint8_t dummy,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 607 of file me_cmp.c.

Referenced by ff_me_cmp_init().

static int dct_sad8x8_c ( MpegEncContext s,
uint8_t src1,
uint8_t src2,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 659 of file me_cmp.c.

static int dct_max8x8_c ( MpegEncContext s,
uint8_t src1,
uint8_t src2,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 725 of file me_cmp.c.

static int quant_psnr8x8_c ( MpegEncContext s,
uint8_t src1,
uint8_t src2,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 742 of file me_cmp.c.

static int rd8x8_c ( MpegEncContext s,
uint8_t src1,
uint8_t src2,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 767 of file me_cmp.c.

static int bit8x8_c ( MpegEncContext s,
uint8_t src1,
uint8_t src2,
ptrdiff_t  stride,
int  h 
)
static

Definition at line 844 of file me_cmp.c.

av_cold void ff_me_cmp_init ( MECmpContext c,
AVCodecContext avctx 
)

Variable Documentation

const uint32_t ff_square_tab[512]

Definition at line 34 of file me_cmp.c.

Referenced by pix_norm1(), pix_norm1_c(), sse(), sse16_c(), sse4_c(), and sse8_c().