video: Use simple fraction multiplication functions instead of going through GValues

This commit is contained in:
Sebastian Dröge 2010-05-13 08:05:09 +02:00
parent 303566654e
commit 30b67cda5d

View file

@ -173,38 +173,21 @@ gst_video_calculate_display_ratio (guint * dar_n, guint * dar_d,
guint display_par_n, guint display_par_d) guint display_par_n, guint display_par_d)
{ {
gint num, den; gint num, den;
gint tmp_n, tmp_d;
GValue display_ratio = { 0, };
GValue tmp = { 0, };
GValue tmp2 = { 0, };
g_return_val_if_fail (dar_n != NULL, FALSE); g_return_val_if_fail (dar_n != NULL, FALSE);
g_return_val_if_fail (dar_d != NULL, FALSE); g_return_val_if_fail (dar_d != NULL, FALSE);
g_value_init (&display_ratio, GST_TYPE_FRACTION);
g_value_init (&tmp, GST_TYPE_FRACTION);
g_value_init (&tmp2, GST_TYPE_FRACTION);
/* Calculate (video_width * video_par_n * display_par_d) / /* Calculate (video_width * video_par_n * display_par_d) /
* (video_height * video_par_d * display_par_n) */ * (video_height * video_par_d * display_par_n) */
gst_value_set_fraction (&display_ratio, video_width, video_height); if (!gst_util_fraction_multiply (video_width, video_height, video_par_n,
gst_value_set_fraction (&tmp, video_par_n, video_par_d); video_par_d, &tmp_n, &tmp_d))
if (!gst_value_fraction_multiply (&tmp2, &display_ratio, &tmp))
goto error_overflow; goto error_overflow;
gst_value_set_fraction (&tmp, display_par_d, display_par_n); if (!gst_util_fraction_multiply (tmp_n, tmp_d, display_par_d, display_par_n,
&num, &den))
if (!gst_value_fraction_multiply (&display_ratio, &tmp2, &tmp))
goto error_overflow; goto error_overflow;
num = gst_value_get_fraction_numerator (&display_ratio);
den = gst_value_get_fraction_denominator (&display_ratio);
g_value_unset (&display_ratio);
g_value_unset (&tmp);
g_value_unset (&tmp2);
g_return_val_if_fail (num > 0, FALSE); g_return_val_if_fail (num > 0, FALSE);
g_return_val_if_fail (den > 0, FALSE); g_return_val_if_fail (den > 0, FALSE);
@ -213,9 +196,6 @@ gst_video_calculate_display_ratio (guint * dar_n, guint * dar_d,
return TRUE; return TRUE;
error_overflow: error_overflow:
g_value_unset (&display_ratio);
g_value_unset (&tmp);
g_value_unset (&tmp2);
return FALSE; return FALSE;
} }