annotate rational.h @ 2648:c3a06b0b00e2 libavcodec

set time_base for variable fps too
author michael
date Fri, 06 May 2005 14:36:15 +0000
parents 2c2f738772b7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1548
dd544554ed42 AVRational
michael
parents:
diff changeset
1 /*
dd544554ed42 AVRational
michael
parents:
diff changeset
2 * Rational numbers
dd544554ed42 AVRational
michael
parents:
diff changeset
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
dd544554ed42 AVRational
michael
parents:
diff changeset
4 *
dd544554ed42 AVRational
michael
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
dd544554ed42 AVRational
michael
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
dd544554ed42 AVRational
michael
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
dd544554ed42 AVRational
michael
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
dd544554ed42 AVRational
michael
parents:
diff changeset
9 *
dd544554ed42 AVRational
michael
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
dd544554ed42 AVRational
michael
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
dd544554ed42 AVRational
michael
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dd544554ed42 AVRational
michael
parents:
diff changeset
13 * Lesser General Public License for more details.
dd544554ed42 AVRational
michael
parents:
diff changeset
14 *
dd544554ed42 AVRational
michael
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
dd544554ed42 AVRational
michael
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
dd544554ed42 AVRational
michael
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dd544554ed42 AVRational
michael
parents:
diff changeset
18 *
dd544554ed42 AVRational
michael
parents:
diff changeset
19 */
dd544554ed42 AVRational
michael
parents:
diff changeset
20
dd544554ed42 AVRational
michael
parents:
diff changeset
21 /**
dd544554ed42 AVRational
michael
parents:
diff changeset
22 * @file rational.h
dd544554ed42 AVRational
michael
parents:
diff changeset
23 * Rational numbers.
dd544554ed42 AVRational
michael
parents:
diff changeset
24 * @author Michael Niedermayer <michaelni@gmx.at>
dd544554ed42 AVRational
michael
parents:
diff changeset
25 */
dd544554ed42 AVRational
michael
parents:
diff changeset
26
dd544554ed42 AVRational
michael
parents:
diff changeset
27 #ifndef RATIONAL_H
dd544554ed42 AVRational
michael
parents:
diff changeset
28 #define RATIONAL_H
dd544554ed42 AVRational
michael
parents:
diff changeset
29
2127
2c2f738772b7 more comments
michael
parents: 1548
diff changeset
30 /**
2c2f738772b7 more comments
michael
parents: 1548
diff changeset
31 * Rational number num/den.
2c2f738772b7 more comments
michael
parents: 1548
diff changeset
32 */
1548
dd544554ed42 AVRational
michael
parents:
diff changeset
33 typedef struct AVRational{
2127
2c2f738772b7 more comments
michael
parents: 1548
diff changeset
34 int num; ///< numerator
2c2f738772b7 more comments
michael
parents: 1548
diff changeset
35 int den; ///< denominator
1548
dd544554ed42 AVRational
michael
parents:
diff changeset
36 } AVRational;
dd544554ed42 AVRational
michael
parents:
diff changeset
37
2127
2c2f738772b7 more comments
michael
parents: 1548
diff changeset
38 /**
2c2f738772b7 more comments
michael
parents: 1548
diff changeset
39 * returns 0 if a==b, 1 if a>b and -1 if a<b.
2c2f738772b7 more comments
michael
parents: 1548
diff changeset
40 */
1548
dd544554ed42 AVRational
michael
parents:
diff changeset
41 static inline int av_cmp_q(AVRational a, AVRational b){
dd544554ed42 AVRational
michael
parents:
diff changeset
42 const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den;
dd544554ed42 AVRational
michael
parents:
diff changeset
43
2127
2c2f738772b7 more comments
michael
parents: 1548
diff changeset
44 if(tmp) return (tmp>>63)|1;
2c2f738772b7 more comments
michael
parents: 1548
diff changeset
45 else return 0;
1548
dd544554ed42 AVRational
michael
parents:
diff changeset
46 }
dd544554ed42 AVRational
michael
parents:
diff changeset
47
2127
2c2f738772b7 more comments
michael
parents: 1548
diff changeset
48 /**
2c2f738772b7 more comments
michael
parents: 1548
diff changeset
49 * converts the given AVRational to a double.
2c2f738772b7 more comments
michael
parents: 1548
diff changeset
50 */
1548
dd544554ed42 AVRational
michael
parents:
diff changeset
51 static inline double av_q2d(AVRational a){
dd544554ed42 AVRational
michael
parents:
diff changeset
52 return a.num / (double) a.den;
dd544554ed42 AVRational
michael
parents:
diff changeset
53 }
dd544554ed42 AVRational
michael
parents:
diff changeset
54
dd544554ed42 AVRational
michael
parents:
diff changeset
55 AVRational av_mul_q(AVRational b, AVRational c);
dd544554ed42 AVRational
michael
parents:
diff changeset
56 AVRational av_div_q(AVRational b, AVRational c);
dd544554ed42 AVRational
michael
parents:
diff changeset
57 AVRational av_add_q(AVRational b, AVRational c);
dd544554ed42 AVRational
michael
parents:
diff changeset
58 AVRational av_sub_q(AVRational b, AVRational c);
dd544554ed42 AVRational
michael
parents:
diff changeset
59 AVRational av_d2q(double d, int max);
dd544554ed42 AVRational
michael
parents:
diff changeset
60
dd544554ed42 AVRational
michael
parents:
diff changeset
61 #endif // RATIONAL_H