Unified · Split
| @@ -16,7 +16,6 @@ · 15 unmodified lines | ||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | #include <stdlib.h> |
| 19 | −#include <pthread.h> | |
| 20 | 19 | #include <time.h> |
| 21 | 20 | #include <unistd.h> |
| 22 | 21 | #include <sys/time.h> |
| @@ -66,32 +65,3 @@ int64_t mp_time_ns_add(int64_t time_ns, double timeout_sec) · 43 unmodified lines | ||
| 66 | 65 | return 1; |
| 67 | 66 | return time_ns + ti; |
| 68 | 67 | } |
| 69 | − | |
| 70 | −#if !HAVE_WIN32_THREADS | |
| 71 | − | |
| 72 | −struct timespec mp_time_ns_to_realtime(int64_t time_ns) | |
| 73 | −{ | |
| 74 | − struct timespec ts = {0}; | |
| 75 | − if (clock_gettime(CLOCK_REALTIME, &ts) != 0) | |
| 76 | − return ts; | |
| 77 | − int64_t time_rel = time_ns - mp_time_ns(); | |
| 78 | − | |
| 79 | − // clamp to 1000 days in the future | |
| 80 | − time_rel = MPMIN(time_rel, 1000 * 24 * 60 * 60 * INT64_C(1000000000)); | |
| 81 | − ts.tv_sec += time_rel / INT64_C(1000000000); | |
| 82 | − ts.tv_nsec += time_rel % INT64_C(1000000000); | |
| 83 | − | |
| 84 | − if (ts.tv_nsec >= INT64_C(1000000000)) { | |
| 85 | − ts.tv_sec++; | |
| 86 | − ts.tv_nsec -= INT64_C(1000000000); | |
| 87 | − } | |
| 88 | − | |
| 89 | − return ts; | |
| 90 | −} | |
| 91 | − | |
| 92 | −struct timespec mp_rel_time_to_timespec(double timeout_sec) | |
| 93 | −{ | |
| 94 | − return mp_time_ns_to_realtime(mp_time_ns_add(mp_time_ns(), timeout_sec)); | |
| 95 | −} | |
| 96 | − | |
| 97 | −#endif | |
| @@ -60,11 +60,4 @@ void mp_end_hires_timers(int resolution_ms); · 59 unmodified lines | ||
| 60 | 60 | // Takes care of possible overflows. Never returns a negative or 0 time. |
| 61 | 61 | int64_t mp_time_ns_add(int64_t time_ns, double timeout_sec); |
| 62 | 62 | |
| 63 | −// Convert the mp time in nanoseconds to a timespec using CLOCK_REALTIME. | |
| 64 | −struct timespec mp_time_ns_to_realtime(int64_t time_ns); | |
| 65 | − | |
| 66 | −// Convert the relative timeout in seconds to a timespec. | |
| 67 | −// The timespec is absolute, using CLOCK_REALTIME. | |
| 68 | −struct timespec mp_rel_time_to_timespec(double timeout_sec); | |
| 69 | − | |
| 70 | 63 | #endif /* MPLAYER_TIMER_H */ |
| @@ -1,7 +1,6 @@ | ||
| 1 | 1 | #include "common/common.h" |
| 2 | 2 | #include "osdep/timer.h" |
| 3 | 3 | #include "test_utils.h" |
| 4 | −#include "config.h" | |
| 5 | 4 | |
| 6 | 5 | #include <time.h> |
| 7 | 6 | #include <sys/time.h> |
| @@ -38,20 +37,5 @@ int main(void) · 30 unmodified lines | ||
| 38 | 37 | assert_int_equal(mp_time_ns_add(test2, 20.44), INT64_MAX); |
| 39 | 38 | } |
| 40 | 39 | |
| 41 | −#if !HAVE_WIN32_THREADS | |
| 42 | − /* conversion */ | |
| 43 | − { | |
| 44 | − struct timeval tv; | |
| 45 | − struct timespec ts; | |
| 46 | − gettimeofday(&tv, NULL); | |
| 47 | − ts = mp_time_ns_to_realtime(mp_time_ns()); | |
| 48 | − assert_true(llabs(tv.tv_sec - ts.tv_sec) <= 1); | |
| 49 | − | |
| 50 | − gettimeofday(&tv, NULL); | |
| 51 | − ts = mp_rel_time_to_timespec(0.0); | |
| 52 | − assert_true(llabs(tv.tv_sec - ts.tv_sec) <= 1); | |
| 53 | − } | |
| 54 | −#endif | |
| 55 | − | |
| 56 | 40 | return 0; |
| 57 | 41 | } |