-static void
-gst_duration_to_fraction (guint64 duration, gint * dest_n, gint * dest_d)
-{
- static const int common_den[] = { 1, 2, 3, 4, 1001 };
- int n, d;
- int i;
- guint64 a;
-
- for (i = 0; i < G_N_ELEMENTS (common_den); i++) {
- d = common_den[i];
- n = floor (0.5 + (d * 1e9) / duration);
- if (n > 0) {
- a = gst_util_uint64_scale_int (1000000000, d, n);
- if (duration >= a - 2 && duration <= a + 2) {
- goto out;
- }
- }
- }
-
- gst_util_double_to_fraction (1e9 / duration, &n, &d);
-
-out:
- /* set results */
- *dest_n = n;
- *dest_d = d;
-}
-