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.

75 lines
1.9KB

  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_CLOCK_GETTIME
  23. #include <time.h>
  24. #elif HAVE_GETTIMEOFDAY
  25. #include <sys/time.h>
  26. #endif
  27. #if HAVE_UNISTD_H
  28. #include <unistd.h>
  29. #endif
  30. #if HAVE_WINDOWS_H
  31. #include <windows.h>
  32. #endif
  33. #include "time.h"
  34. #include "error.h"
  35. int64_t av_gettime(void)
  36. {
  37. #if HAVE_CLOCK_GETTIME
  38. struct timespec ts;
  39. clock_gettime(CLOCK_MONOTONIC, &ts);
  40. return (int64_t)ts.tv_sec * 100000 + ts.tv_nsec / 1000;
  41. #elif HAVE_GETTIMEOFDAY
  42. struct timeval tv;
  43. gettimeofday(&tv, NULL);
  44. return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
  45. #elif HAVE_GETSYSTEMTIMEASFILETIME
  46. FILETIME ft;
  47. int64_t t;
  48. GetSystemTimeAsFileTime(&ft);
  49. t = (int64_t)ft.dwHighDateTime << 32 | ft.dwLowDateTime;
  50. return t / 10 - 11644473600000000; /* Jan 1, 1601 */
  51. #else
  52. return -1;
  53. #endif
  54. }
  55. int av_usleep(unsigned usec)
  56. {
  57. #if HAVE_NANOSLEEP
  58. struct timespec ts = { usec / 1000000, usec % 1000000 * 1000 };
  59. while (nanosleep(&ts, &ts) < 0 && errno == EINTR);
  60. return 0;
  61. #elif HAVE_USLEEP
  62. return usleep(usec);
  63. #elif HAVE_SLEEP
  64. Sleep(usec / 1000);
  65. return 0;
  66. #else
  67. return AVERROR(ENOSYS);
  68. #endif
  69. }