Miam-Player  0.8.0
A nice music player
AVRational

Files

file  rational.h
 

Classes

struct  AVRational
 

Typedefs

typedef struct AVRational AVRational
 

Functions

int av_reduce (int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
 
AVRational av_mul_q (AVRational b, AVRational c) av_const
 
AVRational av_div_q (AVRational b, AVRational c) av_const
 
AVRational av_add_q (AVRational b, AVRational c) av_const
 
AVRational av_sub_q (AVRational b, AVRational c) av_const
 
AVRational av_d2q (double d, int max) av_const
 
int av_nearer_q (AVRational q, AVRational q1, AVRational q2)
 
int av_find_nearest_q_idx (AVRational q, const AVRational *q_list)
 
uint32_t av_q2intfloat (AVRational q)
 

Detailed Description

Rational number calculation.

While rational numbers can be expressed as floating-point numbers, the conversion process is a lossy one, so are floating-point operations. On the other hand, the nature of FFmpeg demands highly accurate calculation of timestamps. This set of rational number utilities serves as a generic interface for manipulating rational numbers as pairs of numerators and denominators.

Many of the functions that operate on AVRational's have the suffix _q, in reference to the mathematical symbol "ℚ" (Q) which denotes the set of all rational numbers.

Typedef Documentation

typedef struct AVRational AVRational

Rational number (pair of numerator and denominator).

Function Documentation

AVRational av_add_q ( AVRational  b,
AVRational  c 
) const

Add two rationals.

Parameters
bFirst rational
cSecond rational
Returns
b+c
AVRational av_d2q ( double  d,
int  max 
) const

Convert a double precision floating point number to a rational.

In case of infinity, the returned value is expressed as {1, 0} or {-1, 0} depending on the sign.

Parameters
ddouble to convert
maxMaximum allowed numerator and denominator
Returns
d in AVRational form
See also
av_q2d()
AVRational av_div_q ( AVRational  b,
AVRational  c 
) const

Divide one rational by another.

Parameters
bFirst rational
cSecond rational
Returns
b/c
int av_find_nearest_q_idx ( AVRational  q,
const AVRational q_list 
)

Find the value in a list of rationals nearest a given reference rational.

Parameters
qReference rational
q_listArray of rationals terminated by {0, 0}
Returns
Index of the nearest value found in the array
AVRational av_mul_q ( AVRational  b,
AVRational  c 
) const

Multiply two rationals.

Parameters
bFirst rational
cSecond rational
Returns
b*c
int av_nearer_q ( AVRational  q,
AVRational  q1,
AVRational  q2 
)

Find which of the two rationals is closer to another rational.

Parameters
qRational to be compared against
q1,q2Rationals to be tested
Returns
One of the following values:
  • 1 if q1 is nearer to q than q2
  • -1 if q2 is nearer to q than q1
  • 0 if they have the same distance
uint32_t av_q2intfloat ( AVRational  q)

Convert an AVRational to a IEEE 32-bit float expressed in fixed-point format.

Parameters
qRational to be converted
Returns
Equivalent floating-point value, expressed as an unsigned 32-bit integer.
Note
The returned value is platform-indepedant.
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
[out]dst_numDestination numerator
[out]dst_denDestination denominator
[in]numSource numerator
[in]denSource denominator
[in]maxMaximum allowed values for dst_num & dst_den
Returns
1 if the operation is exact, 0 otherwise
AVRational av_sub_q ( AVRational  b,
AVRational  c 
) const

Subtract one rational from another.

Parameters
bFirst rational
cSecond rational
Returns
b-c