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 #ifdef __cplusplus 15 extern "C" { 16 #endif // __cplusplus 17 18 // Rational Number with an int64 numerator 19 typedef struct vpx_rational64 { 20 int64_t num; // fraction numerator 21 int den; // fraction denominator 22 } vpx_rational64_t; // alias for struct vpx_rational64_t 23 gcd(int64_t a,int b)24static INLINE int gcd(int64_t a, int b) { 25 int r; // remainder 26 while (b > 0) { 27 r = (int)(a % b); 28 a = b; 29 b = r; 30 } 31 32 return (int)a; 33 } 34 reduce_ratio(vpx_rational64_t * ratio)35static INLINE void reduce_ratio(vpx_rational64_t *ratio) { 36 const int denom = gcd(ratio->num, ratio->den); 37 ratio->num /= denom; 38 ratio->den /= denom; 39 } 40 41 #ifdef __cplusplus 42 } // extern "C" 43 #endif // __cplusplus 44 45 #endif // VPX_VPX_UTIL_VPX_TIMESTAMP_H_ 46