mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-05 13:29:57 -05:00
tests/rtstutter: Use pa_rtclock
This commit is contained in:
parent
aebf66bef6
commit
30c7c95184
1 changed files with 11 additions and 22 deletions
|
|
@ -41,6 +41,7 @@
|
||||||
#include <pulsecore/macro.h>
|
#include <pulsecore/macro.h>
|
||||||
#include <pulsecore/thread.h>
|
#include <pulsecore/thread.h>
|
||||||
#include <pulsecore/core-util.h>
|
#include <pulsecore/core-util.h>
|
||||||
|
#include <pulsecore/core-rtclock.h>
|
||||||
|
|
||||||
static int msec_lower, msec_upper;
|
static int msec_lower, msec_upper;
|
||||||
|
|
||||||
|
|
@ -63,36 +64,24 @@ static void work(void *p) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
struct timespec now, end;
|
struct timeval now, end;
|
||||||
uint64_t nsec;
|
uint64_t usec;
|
||||||
|
|
||||||
pa_log_notice("CPU%i: Sleeping for 1s", PA_PTR_TO_UINT(p));
|
pa_log_notice("CPU%i: Sleeping for 1s", PA_PTR_TO_UINT(p));
|
||||||
pa_msleep(1000);
|
pa_msleep(1000);
|
||||||
|
|
||||||
#ifdef CLOCK_REALTIME
|
usec =
|
||||||
pa_assert_se(clock_gettime(CLOCK_REALTIME, &end) == 0);
|
(uint64_t) ((((double) rand())*(double)(msec_upper-msec_lower)*PA_USEC_PER_MSEC)/RAND_MAX) +
|
||||||
#endif
|
(uint64_t) ((uint64_t) msec_lower*PA_USEC_PER_MSEC);
|
||||||
|
|
||||||
nsec =
|
pa_log_notice("CPU%i: Freezing for %ims", PA_PTR_TO_UINT(p), (int) (usec/PA_USEC_PER_MSEC));
|
||||||
(uint64_t) ((((double) rand())*(double)(msec_upper-msec_lower)*PA_NSEC_PER_MSEC)/RAND_MAX) +
|
|
||||||
(uint64_t) ((uint64_t) msec_lower*PA_NSEC_PER_MSEC);
|
|
||||||
|
|
||||||
pa_log_notice("CPU%i: Freezing for %ims", PA_PTR_TO_UINT(p), (int) (nsec/PA_NSEC_PER_MSEC));
|
pa_rtclock_get(&end);
|
||||||
|
pa_timeval_add(&end, usec);
|
||||||
end.tv_sec += (time_t) (nsec / PA_NSEC_PER_SEC);
|
|
||||||
end.tv_nsec += (long int) (nsec % PA_NSEC_PER_SEC);
|
|
||||||
|
|
||||||
while ((pa_usec_t) end.tv_nsec > PA_NSEC_PER_SEC) {
|
|
||||||
end.tv_sec++;
|
|
||||||
end.tv_nsec -= (long int) PA_NSEC_PER_SEC;
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
#ifdef CLOCK_REALTIME
|
pa_rtclock_get(&now);
|
||||||
pa_assert_se(clock_gettime(CLOCK_REALTIME, &now) == 0);
|
} while (pa_timeval_cmp(&now, &end) < 0);
|
||||||
#endif
|
|
||||||
} while (now.tv_sec < end.tv_sec ||
|
|
||||||
(now.tv_sec == end.tv_sec && now.tv_nsec < end.tv_nsec));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue