[FFmpeg-cvslog] lavu: Add av_gettime_relative

Martin Storsjö git at videolan.org
Fri Oct 24 11:34:06 CEST 2014


ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Wed Oct 22 12:14:37 2014 +0300| [1bd0bdcdc236099d5c0d179696951f35f5310fa5] | committer: Martin Storsjö

lavu: Add av_gettime_relative

Since av_gettime() is used in a number of places where actual
real time clock is required, the monotonic clock introduced in
ebef9f5a5 would have consequences that are hard to handle. Instead
split it into a separate function that can be used in the cases
where only relative time is desired.

On platform where no monotonic clock is available, the difference
between the two av_gettime functions is not clear, and one could
mistakenly use the relative clock where an absolute one is
required. Therefore add an offset, to make it evident that the
time returned from av_gettime_relative never is actual current
real time, even though it is based on av_gettime.

Based on a patch by Olivier Langlois.

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1bd0bdcdc236099d5c0d179696951f35f5310fa5
---

 doc/APIchanges      |    3 +++
 libavutil/time.c    |   20 ++++++++++++++------
 libavutil/time.h    |    9 +++++++++
 libavutil/version.h |    2 +-
 4 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index a8b7091..ad444e1 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil:     2014-08-09
 
 API changes, most recent first:
 
+2014-10-xx - xxxxxxx - lavu 54.5.0 - time.h
+  Add av_gettime_relative().
+
 2014-10-xx - xxxxxxx - lavc 56.5.0 - avcodec.h
   Replace AVCodecContext.time_base used for decoding
   with AVCodecContext.framerate.
diff --git a/libavutil/time.c b/libavutil/time.c
index 42497da..7a3604e 100644
--- a/libavutil/time.c
+++ b/libavutil/time.c
@@ -23,7 +23,8 @@
 #include <time.h>
 #if HAVE_CLOCK_GETTIME
 #include <time.h>
-#elif HAVE_GETTIMEOFDAY
+#endif
+#if HAVE_GETTIMEOFDAY
 #include <sys/time.h>
 #endif
 #if HAVE_UNISTD_H
@@ -38,11 +39,7 @@
 
 int64_t av_gettime(void)
 {
-#if HAVE_CLOCK_GETTIME
-    struct timespec ts;
-    clock_gettime(CLOCK_MONOTONIC, &ts);
-    return (int64_t)ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
-#elif HAVE_GETTIMEOFDAY
+#if HAVE_GETTIMEOFDAY
     struct timeval tv;
     gettimeofday(&tv, NULL);
     return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
@@ -57,6 +54,17 @@ int64_t av_gettime(void)
 #endif
 }
 
+int64_t av_gettime_relative(void)
+{
+#if HAVE_CLOCK_GETTIME
+    struct timespec ts;
+    clock_gettime(CLOCK_MONOTONIC, &ts);
+    return (int64_t)ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
+#else
+    return av_gettime() + 42 * 60 * 60 * INT64_C(1000000);
+#endif
+}
+
 int av_usleep(unsigned usec)
 {
 #if HAVE_NANOSLEEP
diff --git a/libavutil/time.h b/libavutil/time.h
index b01a97d..463bcfc 100644
--- a/libavutil/time.h
+++ b/libavutil/time.h
@@ -27,6 +27,15 @@
 int64_t av_gettime(void);
 
 /**
+ * Get the current time in microseconds since some unspecified starting point.
+ * On platforms that support it, the time comes from a monotonic clock
+ * This property makes this time source ideal for measuring relative time.
+ * The returned values may not be monotonic on platforms where a monotonic
+ * clock is not available.
+ */
+int64_t av_gettime_relative(void);
+
+/**
  * Sleep for a period of time.  Although the duration is expressed in
  * microseconds, the actual delay may be rounded to the precision of the
  * system timer.
diff --git a/libavutil/version.h b/libavutil/version.h
index 8279635..b40009e 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -54,7 +54,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 54
-#define LIBAVUTIL_VERSION_MINOR  4
+#define LIBAVUTIL_VERSION_MINOR  5
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list