[totem/wip/hadess/remaining-time: 5/8] gst: Fix "elapsed + remaining = total" in a different way
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem/wip/hadess/remaining-time: 5/8] gst: Fix "elapsed + remaining = total" in a different way
- Date: Tue, 19 Feb 2019 03:13:25 +0000 (UTC)
commit 0250e711accc6cd48885d7ea41fc337d5bd2a92d
Author: Bastien Nocera <hadess hadess net>
Date: Tue Feb 19 04:00:13 2019 +0100
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.
src/gst/meson.build | 4 ++--
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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]