- Timestamp:
- Dec 28, 2016 3:40:07 AM (8 years ago)
- Location:
- pjproject/branches/projects/uwp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/uwp
- Property svn:mergeinfo changed
/pjproject/trunk (added) merged: 5209,5212-5234,5237-5253,5255,5257-5292,5294-5297,5299-5332,5334-5394,5396-5438,5440-5469,5471-5496,5498-5510
- Property svn:mergeinfo changed
-
pjproject/branches/projects/uwp/pjlib/src/pj/os_timestamp_posix.c
r4890 r5513 161 161 } 162 162 163 #elif defined(__ANDROID__) 164 165 #include <errno.h> 166 #include <linux/android_alarm.h> 167 #include <fcntl.h> 168 #include <time.h> 169 170 #define NSEC_PER_SEC 1000000000 171 172 static int s_alarm_fd = -1; 173 174 void close_alarm_fd() 175 { 176 if (s_alarm_fd != -1) 177 close(s_alarm_fd); 178 s_alarm_fd = -1; 179 } 180 181 PJ_DEF(pj_status_t) pj_get_timestamp(pj_timestamp *ts) 182 { 183 struct timespec tp; 184 int err = -1; 185 186 if (s_alarm_fd == -1) { 187 int fd = open("/dev/alarm", O_RDONLY); 188 if (fd >= 0) { 189 s_alarm_fd = fd; 190 pj_atexit(&close_alarm_fd); 191 } 192 } 193 194 if (s_alarm_fd != -1) { 195 err = ioctl(s_alarm_fd, 196 ANDROID_ALARM_GET_TIME(ANDROID_ALARM_ELAPSED_REALTIME), &tp); 197 } 198 199 if (err != 0) { 200 /* Fallback to CLOCK_MONOTONIC if /dev/alarm is not found, or 201 * getting ANDROID_ALARM_ELAPSED_REALTIME fails. 202 */ 203 err = clock_gettime(CLOCK_MONOTONIC, &tp); 204 } 205 206 if (err != 0) { 207 return PJ_RETURN_OS_ERROR(pj_get_native_os_error()); 208 } 209 210 ts->u64 = tp.tv_sec; 211 ts->u64 *= NSEC_PER_SEC; 212 ts->u64 += tp.tv_nsec; 213 214 return PJ_SUCCESS; 215 } 216 217 PJ_DEF(pj_status_t) pj_get_timestamp_freq(pj_timestamp *freq) 218 { 219 freq->u32.hi = 0; 220 freq->u32.lo = NSEC_PER_SEC; 221 222 return PJ_SUCCESS; 223 } 224 163 225 #elif defined(USE_POSIX_TIMERS) && USE_POSIX_TIMERS != 0 164 226 #include <sys/time.h>
Note: See TracChangeset
for help on using the changeset viewer.