Fix #1961: Updated Android timestamp to use CLOCK_BOOTTIME (or ANDROID_ALARM_ELAPSED_REALTIME for older NDK version), to avoid suspended clock when CPU is in deep sleep.
git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@5447 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
parent
5a6c810022
commit
6f96a93a9b
|
@ -160,6 +160,62 @@ PJ_DEF(pj_status_t) pj_get_timestamp_freq(pj_timestamp *freq)
|
||||||
return PJ_SUCCESS;
|
return PJ_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#elif defined(__ANDROID__)
|
||||||
|
#include <errno.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#if !defined(CLOCK_BOOTTIME)
|
||||||
|
# include <linux/android_alarm.h>
|
||||||
|
# include <fcntl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define NSEC_PER_SEC 1000000000
|
||||||
|
|
||||||
|
PJ_DEF(pj_status_t) pj_get_timestamp(pj_timestamp *ts)
|
||||||
|
{
|
||||||
|
struct timespec tp;
|
||||||
|
|
||||||
|
#if defined(CLOCK_BOOTTIME)
|
||||||
|
/* Use CLOCK_BOOTTIME if supported */
|
||||||
|
if (clock_gettime(CLOCK_BOOTTIME, &tp) != 0) {
|
||||||
|
return PJ_RETURN_OS_ERROR(pj_get_native_os_error());
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/* For older NDK version, use ANDROID_ALARM_ELAPSED_REALTIME */
|
||||||
|
static int s_fd = -1;
|
||||||
|
|
||||||
|
if (s_fd == -1) {
|
||||||
|
int fd = open("/dev/alarm", O_RDONLY);
|
||||||
|
if (fd >= 0) {
|
||||||
|
s_fd = fd;
|
||||||
|
//close(fd);
|
||||||
|
} else {
|
||||||
|
return PJ_RETURN_OS_ERROR(pj_get_native_os_error());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int err = ioctl(s_fd,
|
||||||
|
ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &tp);
|
||||||
|
|
||||||
|
if (err != 0) {
|
||||||
|
return PJ_RETURN_OS_ERROR(pj_get_native_os_error());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ts->u64 = tp.tv_sec;
|
||||||
|
ts->u64 *= NSEC_PER_SEC;
|
||||||
|
ts->u64 += tp.tv_nsec;
|
||||||
|
|
||||||
|
return PJ_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
PJ_DEF(pj_status_t) pj_get_timestamp_freq(pj_timestamp *freq)
|
||||||
|
{
|
||||||
|
freq->u32.hi = 0;
|
||||||
|
freq->u32.lo = NSEC_PER_SEC;
|
||||||
|
|
||||||
|
return PJ_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
#elif defined(USE_POSIX_TIMERS) && USE_POSIX_TIMERS != 0
|
#elif defined(USE_POSIX_TIMERS) && USE_POSIX_TIMERS != 0
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
Loading…
Reference in New Issue