This function simply calls usleep() if this is available. On Windows, the Sleep() function can be used as a fallback. The conditional #includes in time.c are simplified by including unistd.h and windows.h whenever these are available rather than having these lines triggered by specific functions.
Signed-off-by: Mans Rullgard <[email protected]> --- configure | 6 ++++++ libavutil/time.c | 19 ++++++++++++++++++- libavutil/time.h | 7 +++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 73efe4f..f9b242d 100755 --- a/configure +++ b/configure @@ -1131,6 +1131,7 @@ HAVE_LIST=" sdl_video_size setmode setrlimit + Sleep sndio_h socklen_t soundcard_h @@ -1159,8 +1160,10 @@ HAVE_LIST=" trunc truncf unistd_h + usleep vfp_args VirtualAlloc + windows_h winsock2_h WSAPoll xform_asm @@ -2891,12 +2894,14 @@ check_func strtok_r check_func sched_getaffinity check_func sysconf check_func sysctl +check_func usleep check_func_headers io.h setmode check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi check_func_headers windows.h GetProcessAffinityMask check_func_headers windows.h GetProcessTimes check_func_headers windows.h GetSystemTimeAsFileTime check_func_headers windows.h MapViewOfFile +check_func_headers windows.h Sleep check_func_headers windows.h VirtualAlloc check_header dlfcn.h @@ -2910,6 +2915,7 @@ check_header sys/select.h check_header unistd.h check_header vdpau/vdpau.h check_header vdpau/vdpau_x11.h +check_header windows.h check_header X11/extensions/XvMClib.h disabled zlib || check_lib zlib.h zlibVersion -lz || disable zlib diff --git a/libavutil/time.c b/libavutil/time.c index 80c4029..0ae79b6 100644 --- a/libavutil/time.c +++ b/libavutil/time.c @@ -22,11 +22,16 @@ #include <stdint.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 +49,15 @@ int64_t av_gettime(void) return -1; #endif } + +int av_usleep(unsigned usec) +{ +#if 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 2ee7e08..a1be5a0 100644 --- a/libavutil/time.h +++ b/libavutil/time.h @@ -26,4 +26,11 @@ */ int64_t av_gettime(void); +/** + * Sleep for a period of time. + * @param usec Number of microseconds to sleep. + * @return zero on success or (negative) error code. + */ +int av_usleep(unsigned usec); + #endif /* AVUTIL_TIME_H */ -- 1.7.10.2 _______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
