annotate src/ffmpeg/libavutil/rational.h @ 818:07107d476f32 trunk

[svn] - remove some more stuff - build libavcodec directly into the module
author nenolod
date Mon, 12 Mar 2007 13:49:56 -0700
parents e8776388b02a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1 /*
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
2 * Rational numbers
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
4 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
5 * This file is part of FFmpeg.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
6 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
11 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
15 * Lesser General Public License for more details.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
16 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
20 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
21 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
22
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
23 /**
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
24 * @file rational.h
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
25 * Rational numbers.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
26 * @author Michael Niedermayer <michaelni@gmx.at>
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
27 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
28
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
29 #ifndef RATIONAL_H
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
30 #define RATIONAL_H
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
31
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
32 /**
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
33 * Rational number num/den.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
34 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
35 typedef struct AVRational{
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
36 int num; ///< numerator
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
37 int den; ///< denominator
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
38 } AVRational;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
39
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
40 /**
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
41 * returns 0 if a==b, 1 if a>b and -1 if a<b.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
42 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
43 static inline int av_cmp_q(AVRational a, AVRational b){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
44 const int64_t tmp= a.num * (int64_t)b.den - b.num * (int64_t)a.den;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
45
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
46 if(tmp) return (tmp>>63)|1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
47 else return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
48 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
49
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
50 /**
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
51 * converts the given AVRational to a double.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
52 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
53 static inline double av_q2d(AVRational a){
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
54 return a.num / (double) a.den;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
55 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
56
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
57 /**
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
58 * reduce a fraction.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
59 * this is usefull for framerate calculations
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
60 * @param max the maximum allowed for dst_nom & dst_den
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
61 * @return 1 if exact, 0 otherwise
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
62 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
63 int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
64
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
65 AVRational av_mul_q(AVRational b, AVRational c);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
66 AVRational av_div_q(AVRational b, AVRational c);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
67 AVRational av_add_q(AVRational b, AVRational c);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
68 AVRational av_sub_q(AVRational b, AVRational c);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
69 AVRational av_d2q(double d, int max);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
70
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
71 #endif // RATIONAL_H