Changeset 5457
- Timestamp:
- Oct 10, 2016 8:20:54 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/os_timestamp_posix.c
r5447 r5457 162 162 163 163 #elif defined(__ANDROID__) 164 #include <errno.h> 165 #include <time.h> 166 167 #if !defined(CLOCK_BOOTTIME) 168 # include <linux/android_alarm.h> 169 # include <fcntl.h> 170 #endif 164 165 #include <errno.h> 166 #include <linux/android_alarm.h> 167 #include <fcntl.h> 171 168 172 169 #define NSEC_PER_SEC 1000000000 173 170 171 static int s_alarm_fd = -1; 172 173 void close_alarm_fd() 174 { 175 if (s_alarm_fd != -1) 176 close(s_alarm_fd); 177 s_alarm_fd = -1; 178 } 179 174 180 PJ_DEF(pj_status_t) pj_get_timestamp(pj_timestamp *ts) 175 181 { 176 182 struct timespec tp; 177 183 178 #if defined(CLOCK_BOOTTIME) 179 /* Use CLOCK_BOOTTIME if supported */ 180 if (clock_gettime(CLOCK_BOOTTIME, &tp) != 0) { 181 return PJ_RETURN_OS_ERROR(pj_get_native_os_error()); 182 } 183 #else 184 /* For older NDK version, use ANDROID_ALARM_ELAPSED_REALTIME */ 185 static int s_fd = -1; 186 187 if (s_fd == -1) { 184 if (s_alarm_fd == -1) { 188 185 int fd = open("/dev/alarm", O_RDONLY); 189 186 if (fd >= 0) { 190 s_ fd = fd;191 //close(fd);187 s_alarm_fd = fd; 188 pj_atexit(&close_alarm_fd); 192 189 } else { 193 190 return PJ_RETURN_OS_ERROR(pj_get_native_os_error()); 194 191 } 195 192 } 196 int err = ioctl(s_ fd,193 int err = ioctl(s_alarm_fd, 197 194 ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &tp); 198 195 … … 200 197 return PJ_RETURN_OS_ERROR(pj_get_native_os_error()); 201 198 } 202 #endif203 199 204 200 ts->u64 = tp.tv_sec;
Note: See TracChangeset
for help on using the changeset viewer.