diff options
author | Marton Balint <cus@passwd.hu> | 2016-02-04 02:09:48 +0100 |
---|---|---|
committer | Marton Balint <cus@passwd.hu> | 2016-02-14 01:46:35 +0100 |
commit | 3235241061d6a7d79b261b13596620e5dcf015bf (patch) | |
tree | 96b99960c21a1184fb116985b540171ee835babc | |
parent | 35890aaa653a249e3f8253f11b85ed29c408259d (diff) | |
download | ffmpeg-3235241061d6a7d79b261b13596620e5dcf015bf.tar.gz |
avutil/parseutils: use microsecond precision when parsing "now" in av_parse_time()
Use av_gettime() instead of time(0) for querying current time.
Signed-off-by: Marton Balint <cus@passwd.hu>
-rw-r--r-- | libavutil/parseutils.c | 12 | ||||
-rw-r--r-- | tests/ref/fate/parseutils | 4 |
2 files changed, 9 insertions, 7 deletions
diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c index 9fb8d0adb7..fd8cf2bdc6 100644 --- a/libavutil/parseutils.c +++ b/libavutil/parseutils.c @@ -31,13 +31,14 @@ #include "random_seed.h" #include "time_internal.h" #include "parseutils.h" +#include "time.h" #ifdef TEST #define av_get_random_seed av_get_random_seed_deterministic static uint32_t av_get_random_seed_deterministic(void); -#define time(t) 1331972053 +#define av_gettime() 1331972053200000 #endif @@ -558,7 +559,7 @@ time_t av_timegm(struct tm *tm) int av_parse_time(int64_t *timeval, const char *timestr, int duration) { const char *p, *q; - int64_t t; + int64_t t, now64; time_t now; struct tm dt = { 0 }, tmbuf; int today = 0, negative = 0, microseconds = 0; @@ -576,10 +577,11 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration) q = NULL; *timeval = INT64_MIN; if (!duration) { - now = time(0); + now64 = av_gettime(); + now = now64 / 1000000; if (!av_strcasecmp(timestr, "now")) { - *timeval = (int64_t) now * 1000000; + *timeval = now64; return 0; } @@ -870,7 +872,7 @@ int main(void) av_log_set_level(AV_LOG_DEBUG); putenv(tzstr); - printf("(now is 2012-03-17 09:14:13 +0100, local time is UTC+1)\n"); + printf("(now is 2012-03-17 09:14:13.2 +0100, local time is UTC+1)\n"); for (i = 0; i < FF_ARRAY_ELEMS(time_string); i++) { printf("%-24s -> ", time_string[i]); if (av_parse_time(&tv, time_string[i], 0)) { diff --git a/tests/ref/fate/parseutils b/tests/ref/fate/parseutils index 1482452857..176140ce8c 100644 --- a/tests/ref/fate/parseutils +++ b/tests/ref/fate/parseutils @@ -70,8 +70,8 @@ fmt:'%Y-%m-%d %H:%M:%S' spec:'2012-12-21 20:12:21' -> 2012-12-21 20:12:21 fmt:' %Y - %m - %d %H : %M : %S' spec:' 2012 - 12 - 21 20 : 12 : 21' -> 2012-12-21 20:12:21 Testing av_parse_time() -(now is 2012-03-17 09:14:13 +0100, local time is UTC+1) -now -> 1331972053.000000 = 2012-03-17T08:14:13Z +(now is 2012-03-17 09:14:13.2 +0100, local time is UTC+1) +now -> 1331972053.200000 = 2012-03-17T08:14:13Z 12:35:46 -> 1331984146.000000 = 2012-03-17T11:35:46Z 2000-12-20 0:02:47.5z -> 977270567.500000 = 2000-12-20T00:02:47Z 2000-12-20T010247.6 -> 977270567.600000 = 2000-12-20T00:02:47Z |