summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pjlib/src/pj/os_timestamp_posix.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/pjlib/src/pj/os_timestamp_posix.c b/pjlib/src/pj/os_timestamp_posix.c
index 8758d4d7..0cb4035f 100644
--- a/pjlib/src/pj/os_timestamp_posix.c
+++ b/pjlib/src/pj/os_timestamp_posix.c
@@ -180,18 +180,27 @@ void close_alarm_fd()
PJ_DEF(pj_status_t) pj_get_timestamp(pj_timestamp *ts)
{
struct timespec tp;
+ int err = -1;
if (s_alarm_fd == -1) {
int fd = open("/dev/alarm", O_RDONLY);
if (fd >= 0) {
s_alarm_fd = fd;
pj_atexit(&close_alarm_fd);
- } else {
- return PJ_RETURN_OS_ERROR(pj_get_native_os_error());
- }
+ }
+ }
+
+ if (s_alarm_fd != -1) {
+ err = ioctl(s_alarm_fd,
+ ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &tp);
+ }
+
+ if (err != 0) {
+ /* Fallback to CLOCK_MONOTONIC if /dev/alarm is not found, or
+ * getting ANDROID_ALARM_ELAPSED_REALTIME fails.
+ */
+ err = clock_gettime(CLOCK_MONOTONIC, &tp);
}
- int err = ioctl(s_alarm_fd,
- ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &tp);
if (err != 0) {
return PJ_RETURN_OS_ERROR(pj_get_native_os_error());