| 1 |
#ifndef RIST_TIME_H |
| 2 |
#define RIST_TIME_H |
| 3 |
|
| 4 |
#include "common/attributes.h" |
| 5 |
#include "proto/rtp.h" |
| 6 |
|
| 7 |
#include <stdint.h> |
| 8 |
|
| 9 |
|
| 10 |
#define RIST_CLOCK (4294967LL) |
| 11 |
#define ONE_SECOND (1000 * RIST_CLOCK) |
| 12 |
#define RIST_LOG_QUIESCE_TIMER ONE_SECOND |
| 13 |
#define SEVENTY_YEARS_OFFSET (2208988800ULL) |
| 14 |
|
| 15 |
RIST_PRIV uint64_t timestampNTP_u64(void); |
| 16 |
RIST_PRIV uint64_t timestampNTP_RTC_u64(void); |
| 17 |
RIST_PRIV uint64_t convertRTPtoNTP(uint8_t ptype, uint32_t time_extension, uint32_t i_rtp); |
| 18 |
RIST_PRIV uint64_t calculate_rtt_delay(uint64_t request, uint64_t response, uint32_t delay); |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
static inline uint32_t timestampRTP_u32(int advanced, uint64_t i_ntp) |
| 27 |
{ |
| 28 |
uint64_t hz = advanced ? 1000000ULL : (uint64_t)RTP_PTYPE_MPEGTS_CLOCKHZ; |
| 29 |
return (uint32_t)((i_ntp * hz) >> 32); |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
static inline uint64_t timestampNTP_to_ns(uint64_t i_ntp) |
| 36 |
{ |
| 37 |
return (i_ntp >> 32) * 1000000000ULL + |
| 38 |
(((i_ntp & 0xFFFFFFFFULL) * 1000000000ULL) >> 32); |
| 39 |
} |
| 40 |
|
| 41 |
static inline uint64_t timestampNTP_to_us(uint64_t i_ntp) |
| 42 |
{ |
| 43 |
return (i_ntp >> 32) * 1000000ULL + |
| 44 |
(((i_ntp & 0xFFFFFFFFULL) * 1000000ULL) >> 32); |
| 45 |
} |
| 46 |
|
| 47 |
#endif |