# Maths [Common utility functions]

## Data Structures

struct  AVRational
rational number numerator/denominator More...

## Enumerations

enum  AVRounding {
AV_ROUND_ZERO = 0, AV_ROUND_INF = 1, AV_ROUND_DOWN = 2, AV_ROUND_UP = 3,
AV_ROUND_NEAR_INF = 5
}

## Functions

int64_t av_const av_gcd (int64_t a, int64_t b)
Return the greatest common divisor of a and b.
int64_t av_rescale (int64_t a, int64_t b, int64_t c) av_const
Rescale a 64-bit integer with rounding to nearest.
int64_t av_rescale_rnd (int64_t a, int64_t b, int64_t c, enum AVRounding) av_const
Rescale a 64-bit integer with specified rounding.
int64_t av_rescale_q (int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
int64_t av_rescale_q_rnd (int64_t a, AVRational bq, AVRational cq, enum AVRounding) av_const
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
int av_compare_ts (int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare 2 timestamps each in its own timebases.
int64_t av_compare_mod (uint64_t a, uint64_t b, uint64_t mod)
Compare 2 integers modulo mod.
static int av_cmp_q (AVRational a, AVRational b)
Compare two rationals.
static double av_q2d (AVRational a)
Convert rational to double.
int av_reduce (int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
AVRational av_mul_q (AVRational b, AVRational c) av_const
Multiply two rationals.
AVRational av_div_q (AVRational b, AVRational c) av_const
Divide one rational by another.
AVRational av_add_q (AVRational b, AVRational c) av_const
AVRational av_sub_q (AVRational b, AVRational c) av_const
Subtract one rational from another.
AVRational av_d2q (double d, int max) av_const
Convert a double precision floating point number to a rational.
int av_nearer_q (AVRational q, AVRational q1, AVRational q2)
int av_find_nearest_q_idx (AVRational q, const AVRational *q_list)
Find the nearest value in q_list to q.

## Enumeration Type Documentation

 enum AVRounding

Enumerator:
 AV_ROUND_ZERO Round toward zero. AV_ROUND_INF Round away from zero. AV_ROUND_DOWN Round toward -infinity. AV_ROUND_UP Round toward +infinity. AV_ROUND_NEAR_INF Round to nearest and halfway cases away from zero.

Definition at line 66 of file mathematics.h.

## Function Documentation

 AVRational av_add_q ( AVRational b, AVRational c ) const

Parameters:
 b first rational c second rational
Returns:
b+c

Definition at line 93 of file rational.c.

Referenced by av_sub_q().

 static int av_cmp_q ( AVRational a, AVRational b ) ` [inline, static]`

Compare two rationals.

Parameters:
 a first rational b second rational
Returns:
0 if a==b, 1 if a>b, -1 if a<b, and INT_MIN if one of the values is of the form 0/0

Definition at line 55 of file rational.h.

 int64_t av_compare_mod ( uint64_t a, uint64_t b, uint64_t mod )

Compare 2 integers modulo mod.

That is we compare integers a and b for which only the least significant log2(mod) bits are known.

Parameters:
 mod must be a power of 2
Returns:
a negative value if a is smaller than b a positive value if a is greater than b 0 if a equals b

Definition at line 157 of file mathematics.c.

 int av_compare_ts ( int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b )

Compare 2 timestamps each in its own timebases.

The result of the function is undefined if one of the timestamps is outside the int64_t range when represented in the others timebase.

Returns:
-1 if ts_a is before ts_b, 1 if ts_a is after ts_b or 0 if they represent the same position

Definition at line 147 of file mathematics.c.

 AVRational av_d2q ( double d, int max ) const

Convert a double precision floating point number to a rational.

inf is expressed as {1,0} or {-1,0} depending on the sign.

Parameters:
 d double to convert max the maximum allowed numerator and denominator
Returns:
(AVRational) d

Definition at line 106 of file rational.c.

 AVRational av_div_q ( AVRational b, AVRational c ) const

Divide one rational by another.

Parameters:
 b first rational c second rational
Returns:
b/c

Definition at line 88 of file rational.c.

 int av_find_nearest_q_idx ( AVRational q, const AVRational * q_list )

Find the nearest value in q_list to q.

Parameters:
 q_list an array of rationals terminated by {0, 0}
Returns:
the index of the nearest value found in the array

Definition at line 138 of file rational.c.

Referenced by transcode_init().

 int64_t av_const av_gcd ( int64_t a, int64_t b )

Return the greatest common divisor of a and b.

If both a and b are 0 or either or both are <0 then behavior is undefined.

Definition at line 73 of file mathematics.c.

 AVRational av_mul_q ( AVRational b, AVRational c ) const

Multiply two rationals.

Parameters:
 b first rational c second rational
Returns:
b*c

Definition at line 80 of file rational.c.

 int av_nearer_q ( AVRational q, AVRational q1, AVRational q2 )

Returns:
1 if q1 is nearer to q than q2, -1 if q2 is nearer than q1, 0 if they have the same distance.

Definition at line 123 of file rational.c.

Referenced by av_find_nearest_q_idx().

 static double av_q2d ( AVRational a ) ` [inline, static]`

Convert rational to double.

Parameters:
 a rational to convert
Returns:
(double) a

Definition at line 69 of file rational.h.

 int av_reduce ( int * dst_num, int * dst_den, int64_t num, int64_t den, int64_t max )

Reduce a fraction.

This is useful for framerate calculations.

Parameters:
 dst_num destination numerator dst_den destination denominator num source numerator den source denominator max the maximum allowed for dst_num & dst_den
Returns:
1 if exact, 0 otherwise

Definition at line 36 of file rational.c.

 int64_t av_rescale ( int64_t a, int64_t b, int64_t c ) const

Rescale a 64-bit integer with rounding to nearest.

A simple a*b/c isn't possible as it can overflow.

Definition at line 130 of file mathematics.c.

 int64_t av_rescale_q ( int64_t a, AVRational bq, AVRational cq ) const

 int64_t av_rescale_q_rnd ( int64_t a, AVRational bq, AVRational cq, enum AVRounding ) const

Rescale a 64-bit integer by 2 rational numbers with specified rounding.

Definition at line 134 of file mathematics.c.

Referenced by av_rescale_q(), parse_packet(), and rtp_write_header().

 int64_t av_rescale_rnd ( int64_t a, int64_t b, int64_t c, enum AVRounding ) const

Rescale a 64-bit integer with specified rounding.

A simple a*b/c isn't possible as it can overflow.

Definition at line 78 of file mathematics.c.

 AVRational av_sub_q ( AVRational b, AVRational c ) const

Subtract one rational from another.

Parameters:
 b first rational c second rational
Returns:
b-c

Definition at line 101 of file rational.c.

Generated on Fri Oct 26 02:48:04 2012 for FFmpeg by  1.5.8