From d0199321c2768370bb8349c70bdd57dc844b61d6 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Tue, 6 Jun 2017 07:45:08 +0200 Subject: [PATCH] playback example: Prettify time reporting for big values When dealing with streams/contents which have large duration, it is more user-friendly to show more details in the high values (hours or days) than in the microseconds. This patch will use the following formatting schemes: * Below 1hour : MM:SS.SSS * Below 24hours : HHhMMmSSs * Above : DDdHHhMMm --- tests/examples/playback/playback-test.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/examples/playback/playback-test.c b/tests/examples/playback/playback-test.c index 9ec2cb3d74..08e83ffc9d 100644 --- a/tests/examples/playback/playback-test.c +++ b/tests/examples/playback/playback-test.c @@ -310,14 +310,29 @@ format_value (GtkScale * scale, gdouble value, PlaybackApp * app) { gint64 real; gint64 seconds; - gint64 subseconds; real = value * app->duration / N_GRAD; seconds = (gint64) real / GST_SECOND; - subseconds = (gint64) real / (GST_MSECOND); + /* Use two different formatting depending on the amount */ + if (seconds < 60 * 60) { + gint64 subseconds = (gint64) real / (GST_MSECOND); - return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%03" - G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 1000); + /* Sub hour positioning */ + return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%03" + G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 1000); + } else { + gint64 days = seconds / (24 * 60 * 60); + gint64 hours = (seconds / (60 * 60)) % 60; + gint64 minutes = (seconds / 60) % 60; + + if (days) { + return g_strdup_printf ("%02" G_GINT64_FORMAT "d%02" G_GINT64_FORMAT + "h%02" G_GINT64_FORMAT "m", days, hours, minutes); + } else { + return g_strdup_printf ("%02" G_GINT64_FORMAT "h%02" G_GINT64_FORMAT + "m%02" G_GINT64_FORMAT "s", hours, minutes, seconds % 60); + } + } } static gchar *