Changeset 5447
- Timestamp:
- Oct 6, 2016 4:05:02 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/os_timestamp_posix.c
r4890 r5447 161 161 } 162 162 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 171 172 #define NSEC_PER_SEC 1000000000 173 174 PJ_DEF(pj_status_t) pj_get_timestamp(pj_timestamp *ts) 175 { 176 struct timespec tp; 177 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) { 188 int fd = open("/dev/alarm", O_RDONLY); 189 if (fd >= 0) { 190 s_fd = fd; 191 //close(fd); 192 } else { 193 return PJ_RETURN_OS_ERROR(pj_get_native_os_error()); 194 } 195 } 196 int err = ioctl(s_fd, 197 ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &tp); 198 199 if (err != 0) { 200 return PJ_RETURN_OS_ERROR(pj_get_native_os_error()); 201 } 202 #endif 203 204 ts->u64 = tp.tv_sec; 205 ts->u64 *= NSEC_PER_SEC; 206 ts->u64 += tp.tv_nsec; 207 208 return PJ_SUCCESS; 209 } 210 211 PJ_DEF(pj_status_t) pj_get_timestamp_freq(pj_timestamp *freq) 212 { 213 freq->u32.hi = 0; 214 freq->u32.lo = NSEC_PER_SEC; 215 216 return PJ_SUCCESS; 217 } 218 163 219 #elif defined(USE_POSIX_TIMERS) && USE_POSIX_TIMERS != 0 164 220 #include <sys/time.h>
Note: See TracChangeset
for help on using the changeset viewer.