summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-02-02 20:32:59 +0100
committerwm4 <wm4@nowhere>2013-02-03 15:41:18 +0100
commit74b66862d776f81a6da374b7e6cc54d2d5e8e16e (patch)
tree90f23ae5ee6a5d10ae4c845fd089b451b30348ed /core
parent37c83abe61b468810624f12374e5faced4efb70b (diff)
downloadmpv-74b66862d776f81a6da374b7e6cc54d2d5e8e16e.tar.bz2
mpv-74b66862d776f81a6da374b7e6cc54d2d5e8e16e.tar.xz
mp_common: improve OSD/status time formatting
Allow negative times. Timestamps can be negative, and we actually display negative time for other reasons too, such as when waiting for the old audio to drain with gapless audio.) Avoid overflows with relatively large time values. (We still don't handle values too large for int64_t.)
Diffstat (limited to 'core')
-rw-r--r--core/mp_common.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/core/mp_common.c b/core/mp_common.c
index c931c29065..4fef9c37dd 100644
--- a/core/mp_common.c
+++ b/core/mp_common.c
@@ -23,17 +23,24 @@
char *mp_format_time(double time, bool fractions)
{
- if (time < 0)
+ if (time == MP_NOPTS_VALUE)
return talloc_strdup(NULL, "unknown");
- int h, m, s = time;
+ char sign[2] = {0};
+ if (time < 0) {
+ time = -time;
+ sign[0] = '-';
+ }
+ long long int itime = time;
+ int64_t h, m, s;
+ s = itime;
h = s / 3600;
s -= h * 3600;
m = s / 60;
s -= m * 60;
- char *res = talloc_asprintf(NULL, "%02d:%02d:%02d", h, m, s);
+ char *res = talloc_asprintf(NULL, "%s%02lld:%02lld:%02lld", sign, h, m, s);
if (fractions)
res = talloc_asprintf_append(res, ".%03d",
- (int)((time - (int)time) * 1000));
+ (int)((time - itime) * 1000));
return res;
}