diff options
author | wm4 <wm4@nowhere> | 2013-02-02 20:32:59 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-02-03 15:41:18 +0100 |
commit | 74b66862d776f81a6da374b7e6cc54d2d5e8e16e (patch) | |
tree | 90f23ae5ee6a5d10ae4c845fd089b451b30348ed | |
parent | 37c83abe61b468810624f12374e5faced4efb70b (diff) | |
download | mpv-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.)
-rw-r--r-- | core/mp_common.c | 15 |
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; } |