diff options
author | Bastien Nocera <hadess@hadess.net> | 2019-02-19 04:00:13 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2019-02-19 04:11:39 +0100 |
commit | 0250e711accc6cd48885d7ea41fc337d5bd2a92d (patch) | |
tree | a0a5f9c7169fa793c61fc2f6f2c008175ca49cbc /src/gst | |
parent | e7edac8add711a5b2cc1973f92c10ce0af59c88b (diff) | |
download | totem-0250e711accc6cd48885d7ea41fc337d5bd2a92d.tar.gz |
gst: Fix "elapsed + remaining = total" in a different way
When making sure that:
current time + time remaining = total run time
don't blindly add 1 second to the runtime. Instead, round down the
elapsed time, and round up the remaining time.
Diffstat (limited to 'src/gst')
-rw-r--r-- | src/gst/meson.build | 4 | ||||
-rw-r--r-- | src/gst/totem-time-helpers.c | 9 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/gst/meson.build b/src/gst/meson.build index 209fb6fd5..6ac3b0ab9 100644 --- a/src/gst/meson.build +++ b/src/gst/meson.build @@ -38,7 +38,7 @@ libtotem_gst_pixbuf_helpers_dep = declare_dependency( libtotem_time_helpers = static_library( 'totemtimehelpers', sources: 'totem-time-helpers.c', - dependencies: glib_dep + dependencies: [ glib_dep, m_dep ] ) libtotem_time_helpers_dep = declare_dependency( @@ -53,7 +53,7 @@ exe = executable( gst_test, gst_test + '.c', include_directories: top_inc, - dependencies: glib_dep, + dependencies: [ glib_dep, m_dep ], link_with: libtotem_time_helpers ) diff --git a/src/gst/totem-time-helpers.c b/src/gst/totem-time-helpers.c index 0d7754d4e..eed2bb2e6 100644 --- a/src/gst/totem-time-helpers.c +++ b/src/gst/totem-time-helpers.c @@ -25,6 +25,7 @@ * */ +#include <math.h> #include <glib/gi18n.h> #include <libintl.h> @@ -38,15 +39,19 @@ totem_time_to_string (gint64 msecs, gboolean force_hour) { int sec, min, hour, _time; + double time_f; g_return_val_if_fail (msecs >= 0, NULL); - _time = (int) (msecs / 1000); /* When calculating the remaining time, * we want to make sure that: * current time + time remaining = total run time */ + time_f = (double) msecs / 1000; if (remaining) - _time++; + time_f = ceil (time_f); + else + time_f = round (time_f); + _time = (int) time_f; sec = _time % 60; _time = _time - sec; |