1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2010-2014 L-SMASH project
6 * Authors: Yusuke Nakamura <muken.the.vfrmaniac@gmail.com>
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 *****************************************************************************/
21 /* This file is available under an ISC license. */
26 #define debug_if(x) if(x)
28 #define LSMASH_MAX( a, b ) ((a) > (b) ? (a) : (b))
29 #define LSMASH_MIN( a, b ) ((a) < (b) ? (a) : (b))
32 * Use only CALL_FUNC_DEFAULT_ARGS().
33 * The defined macros can't be passed a macro argument requiring the empty parameter list.
35 * The following is an example.
36 * #define TEMPLATE_A( ... ) CALL_FUNC_DEFAULT_ARGS( TEMPLATE_A, __VA_ARGS__ )
37 * #define TEMPLATE_A_1( _1 ) _1( 1 )
38 * #define TEMPLATE_B( ... ) CALL_FUNC_DEFAULT_ARGS( TEMPLATE_B, __VA_ARGS__ )
39 * #define TEMPLATE_B_2( _1, _2 ) ((_1) + (_2))
40 * #define TEMPLATE_B_1( _1 ) TEMPLATE_B_2( _1, 0 )
41 * #define TEMPLATE_B_0()
44 * TEMPLATE_A( TEMPLATE_B_1 ); // OK
45 * TEMPLATE_A( TEMPLATE_B ); // NG
46 * TEMPLATE_B( 1, 2 ); // OK
51 #define NUM_ARGS( _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, ... ) _10
52 #define COUNT_NUM_ARGS( ... ) NUM_ARGS( __VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 0 )
53 #define GET_FUNC_BY_NUM_ARGS_EXN( func_name, N ) func_name ## _ ## N
54 #define GET_FUNC_BY_NUM_ARGS_EX0( func_name, N ) GET_FUNC_BY_NUM_ARGS_EXN( func_name, N )
55 #define GET_FUNC_BY_NUM_ARGS_EX1( func_name, ... ) GET_FUNC_BY_NUM_ARGS_EX0( func_name, COUNT_NUM_ARGS( __VA_ARGS__ ) )
56 #define CALL_FUNC_DEFAULT_ARGS( func_name, ... ) GET_FUNC_BY_NUM_ARGS_EX1( func_name, __VA_ARGS__ ) ( __VA_ARGS__ )
62 size_t log_level_offset
; /* offset in the struct where 'log_level' is placed
63 * If set to 0, 'log_level' is unavailable and implicitly set to LSMASH_LOG_INFO. */
67 double lsmash_fixed2double( uint64_t value
, int frac_width
);
68 float lsmash_int2float32( uint32_t value
);
69 double lsmash_int2float64( uint64_t value
);
84 } lsmash_rational_u64_t
;
90 } lsmash_rational_s64_t
;
95 lsmash_log_level level
,
100 void lsmash_log_refresh_line
105 uint32_t lsmash_count_bits
114 const char *format
, ...
122 int lsmash_compare_dts
124 const lsmash_media_ts_t
*a
,
125 const lsmash_media_ts_t
*b
128 int lsmash_compare_cts
130 const lsmash_media_ts_t
*a
,
131 const lsmash_media_ts_t
*b
134 static inline uint64_t lsmash_get_gcd
152 static inline uint64_t lsmash_get_lcm
160 return (a
/ lsmash_get_gcd( a
, b
)) * b
;
163 static inline void lsmash_reduce_fraction
171 uint64_t gcd
= lsmash_get_gcd( *a
, *b
);
179 static inline void lsmash_reduce_fraction_su
187 uint64_t c
= *a
> 0 ? *a
: -(*a
);
188 uint64_t gcd
= lsmash_get_gcd( c
, *b
);
193 *a
= *a
> 0 ? c
: -c
;