1 /* 2 * Copyright (c) 2019 The WebM project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef VPX_VPX_UTIL_VPX_TIMESTAMP_H_ 12 #define VPX_VPX_UTIL_VPX_TIMESTAMP_H_ 13 14 #include <assert.h> 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif // __cplusplus 19 20 // Rational Number with an int64 numerator 21 typedef struct vpx_rational64 { 22 int64_t num; // fraction numerator 23 int den; // fraction denominator 24 } vpx_rational64_t; // alias for struct vpx_rational64_t 25 gcd(int64_t a,int b)26static INLINE int gcd(int64_t a, int b) { 27 int r; // remainder 28 assert(a >= 0); 29 assert(b > 0); 30 while (b != 0) { 31 r = (int)(a % b); 32 a = b; 33 b = r; 34 } 35 36 return (int)a; 37 } 38 reduce_ratio(vpx_rational64_t * ratio)39static INLINE void reduce_ratio(vpx_rational64_t *ratio) { 40 const int denom = gcd(ratio->num, ratio->den); 41 ratio->num /= denom; 42 ratio->den /= denom; 43 } 44 45 #ifdef __cplusplus 46 } // extern "C" 47 #endif // __cplusplus 48 49 #endif // VPX_VPX_UTIL_VPX_TIMESTAMP_H_ 50