diff options
author | Mans Rullgard <mans@mansr.com> | 2012-06-21 17:00:25 +0100 |
---|---|---|
committer | Mans Rullgard <mans@mansr.com> | 2012-06-22 17:15:18 +0100 |
commit | d3d3a32c9d389cc0d6a91b389988a225ae01c948 (patch) | |
tree | 5115c574ba6da03bca2679cbdc073437de5dfc24 /libavutil | |
parent | f6b4624fcf9a8f4966b495b9c769ff0796839d57 (diff) | |
download | ffmpeg-d3d3a32c9d389cc0d6a91b389988a225ae01c948.tar.gz |
lavu: add av_usleep() function
This function implements a delay using the first available
of the following functions:
- nanosleep()
- usleep()
- Sleep() (Windows)
The conditional #includes in time.c are simplified by including
unistd.h and windows.h whenever they are available rather than
having these lines triggered by specific functions.
Signed-off-by: Mans Rullgard <mans@mansr.com>
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/avutil.h | 2 | ||||
-rw-r--r-- | libavutil/time.c | 24 | ||||
-rw-r--r-- | libavutil/time.h | 10 |
3 files changed, 34 insertions, 2 deletions
diff --git a/libavutil/avutil.h b/libavutil/avutil.h index ce73754ead..351e8279ac 100644 --- a/libavutil/avutil.h +++ b/libavutil/avutil.h @@ -152,7 +152,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 51 -#define LIBAVUTIL_VERSION_MINOR 33 +#define LIBAVUTIL_VERSION_MINOR 34 #define LIBAVUTIL_VERSION_MICRO 0 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ diff --git a/libavutil/time.c b/libavutil/time.c index 80c4029d9b..51779c5d17 100644 --- a/libavutil/time.c +++ b/libavutil/time.c @@ -20,13 +20,19 @@ #include <stddef.h> #include <stdint.h> +#include <time.h> #if HAVE_GETTIMEOFDAY #include <sys/time.h> -#elif HAVE_GETSYSTEMTIMEASFILETIME +#endif +#if HAVE_UNISTD_H +#include <unistd.h> +#endif +#if HAVE_WINDOWS_H #include <windows.h> #endif #include "libavutil/time.h" +#include "error.h" int64_t av_gettime(void) { @@ -44,3 +50,19 @@ int64_t av_gettime(void) return -1; #endif } + +int av_usleep(unsigned usec) +{ +#if HAVE_NANOSLEEP + struct timespec ts = { usec / 1000000, usec % 1000000 * 1000 }; + while (nanosleep(&ts, &ts) < 0 && errno == EINTR); + return 0; +#elif HAVE_USLEEP + return usleep(usec); +#elif HAVE_SLEEP + Sleep(usec / 1000); + return 0; +#else + return AVERROR(ENOSYS); +#endif +} diff --git a/libavutil/time.h b/libavutil/time.h index 2ee7e08caf..b01a97d770 100644 --- a/libavutil/time.h +++ b/libavutil/time.h @@ -26,4 +26,14 @@ */ int64_t av_gettime(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. + * + * @param usec Number of microseconds to sleep. + * @return zero on success or (negative) error code. + */ +int av_usleep(unsigned usec); + #endif /* AVUTIL_TIME_H */ |