00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 #include "config.h"
00022 
00023 #include <stddef.h>
00024 #include <stdint.h>
00025 #include <time.h>
00026 #if HAVE_GETTIMEOFDAY
00027 #include <sys/time.h>
00028 #endif
00029 #if HAVE_UNISTD_H
00030 #include <unistd.h>
00031 #endif
00032 #if HAVE_WINDOWS_H
00033 #include <windows.h>
00034 #endif
00035 
00036 #include "libavutil/time.h"
00037 #include "error.h"
00038 
00039 int64_t av_gettime(void)
00040 {
00041 #if HAVE_GETTIMEOFDAY
00042     struct timeval tv;
00043     gettimeofday(&tv, NULL);
00044     return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
00045 #elif HAVE_GETSYSTEMTIMEASFILETIME
00046     FILETIME ft;
00047     int64_t t;
00048     GetSystemTimeAsFileTime(&ft);
00049     t = (int64_t)ft.dwHighDateTime << 32 | ft.dwLowDateTime;
00050     return t / 10 - 11644473600000000; 
00051 #else
00052     return -1;
00053 #endif
00054 }
00055 
00056 int av_usleep(unsigned usec)
00057 {
00058 #if HAVE_NANOSLEEP
00059     struct timespec ts = { usec / 1000000, usec % 1000000 * 1000 };
00060     while (nanosleep(&ts, &ts) < 0 && errno == EINTR);
00061     return 0;
00062 #elif HAVE_USLEEP
00063     return usleep(usec);
00064 #elif HAVE_SLEEP
00065     Sleep(usec / 1000);
00066     return 0;
00067 #else
00068     return AVERROR(ENOSYS);
00069 #endif
00070 }