You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.7KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * Libav is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "config.h"
  19. #include <stddef.h>
  20. #include <stdint.h>
  21. #include <time.h>
  22. #if HAVE_GETTIMEOFDAY
  23. #include <sys/time.h>
  24. #endif
  25. #if HAVE_UNISTD_H
  26. #include <unistd.h>
  27. #endif
  28. #if HAVE_WINDOWS_H
  29. #include <windows.h>
  30. #endif
  31. #include "libavutil/time.h"
  32. #include "error.h"
  33. int64_t av_gettime(void)
  34. {
  35. #if HAVE_GETTIMEOFDAY
  36. struct timeval tv;
  37. gettimeofday(&tv, NULL);
  38. return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
  39. #elif HAVE_GETSYSTEMTIMEASFILETIME
  40. FILETIME ft;
  41. int64_t t;
  42. GetSystemTimeAsFileTime(&ft);
  43. t = (int64_t)ft.dwHighDateTime << 32 | ft.dwLowDateTime;
  44. return t / 10 - 11644473600000000; /* Jan 1, 1601 */
  45. #else
  46. return -1;
  47. #endif
  48. }
  49. int av_usleep(unsigned usec)
  50. {
  51. #if HAVE_NANOSLEEP
  52. struct timespec ts = { usec / 1000000, usec % 1000000 * 1000 };
  53. while (nanosleep(&ts, &ts) < 0 && errno == EINTR);
  54. return 0;
  55. #elif HAVE_USLEEP
  56. return usleep(usec);
  57. #elif HAVE_SLEEP
  58. Sleep(usec / 1000);
  59. return 0;
  60. #else
  61. return AVERROR(ENOSYS);
  62. #endif
  63. }