Ignore:
Timestamp:
Dec 28, 2016 3:40:07 AM (4 years ago)
Author:
nanang
Message:

Re #1900: More merged from trunk (r5512 mistakenly contains merged changes in third-party dir only).

Location:
pjproject/branches/projects/uwp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/uwp

  • pjproject/branches/projects/uwp/pjlib/src/pj/os_timestamp_posix.c

    r4890 r5513  
    161161} 
    162162 
     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 
     172static int s_alarm_fd = -1; 
     173 
     174void close_alarm_fd() 
     175{ 
     176    if (s_alarm_fd != -1) 
     177        close(s_alarm_fd); 
     178    s_alarm_fd = -1; 
     179} 
     180 
     181PJ_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 
     217PJ_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 
    163225#elif defined(USE_POSIX_TIMERS) && USE_POSIX_TIMERS != 0 
    164226#include <sys/time.h> 
Note: See TracChangeset for help on using the changeset viewer.