Skip to content

Commit

Permalink
[core] New API function srt_clock_type() (#1887)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko authored Apr 27, 2021
1 parent 5dbceb2 commit 291e010
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
30 changes: 30 additions & 0 deletions docs/API/API-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
|:------------------------------------------------- |:-------------------------------------------------------------------------------------------------------------- |
| [srt_time_now](#srt_time_now) | Get time in microseconds elapsed since epoch using SRT internal clock <br/> (steady or monotonic clock) |
| [srt_connection_time](#srt_connection_time) | Get connection time in microseconds elapsed since epoch using SRT internal clock <br/> (steady or monotonic clock) |
| [srt_clock_type](#srt_clock_type) | Get the type of clock used internally by SRT |
| <img width=290px height=1px/> | <img width=720px height=1px/> |

<h3 id="diagnostics">Diagnostics</h3>
Expand Down Expand Up @@ -2646,7 +2647,36 @@ and `msTimeStamp` value of the `SRT_TRACEBSTATS` (see [SRT Statistics](statistic
---
### srt_clock_type
```c
int srt_clock_type(void);
```

Get the type of clock used internally by SRT to be used only for informtational peurpose.
Using any time source except for [`srt_time_now()`](#srt_time_now) and [`srt_connection_time(SRTSOCKET)`](#srt_connection_time)
to timestamp packets submitted to SRT is not recommended and must be done with awareness and at your own risk.

| Returns | Clock Type | Description |
| :------ | :---------------------------------- | :------------------------------------------|
| 0 | `SRT_SYNC_CLOCK_STDCXX_STEADY` | C++11 `std::chrono::steady_clock` |
| 1 | `SRT_SYNC_CLOCK_GETTIME_MONOTONIC` | `clock_gettime` with `CLOCK_MONOTONIC` |
| 2 | `SRT_SYNC_CLOCK_WINQPC` | Windows `QueryPerformanceCounter(..)` |
| 3 | `SRT_SYNC_CLOCK_MACH_ABSTIME` | `mach_absolute_time()` |
| 4 | `SRT_SYNC_CLOCK_POSIX_GETTIMEOFDAY` | POSIX `gettimeofday(..)` |
| 5 | `SRT_SYNC_CLOCK_AMD64_RDTSC` | `asm("rdtsc" ..)` |
| 6 | `SRT_SYNC_CLOCK_IA32_RDTSC` | `asm volatile("rdtsc" ..)` |
| 7 | `SRT_SYNC_CLOCK_IA64_ITC` | `asm("mov %0=ar.itc" ..)` |

| Errors | |
|:--------------------------------- |:---------------------------------------------------------- |
| None | |
| <img width=240px height=1px/> | <img width=710px height=1px/> |


[:arrow_up: &nbsp; Back to List of Functions & Structures](#srt-api-functions)

---


## Diagnostics
Expand Down
12 changes: 12 additions & 0 deletions srtcore/srt.h
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,18 @@ SRT_API int64_t srt_time_now(void);

SRT_API int64_t srt_connection_time(SRTSOCKET sock);

// Possible internal clock types
#define SRT_SYNC_CLOCK_STDCXX_STEADY 0 // C++11 std::chrono::steady_clock
#define SRT_SYNC_CLOCK_GETTIME_MONOTONIC 1 // clock_gettime with CLOCK_MONOTONIC
#define SRT_SYNC_CLOCK_WINQPC 2
#define SRT_SYNC_CLOCK_MACH_ABSTIME 3
#define SRT_SYNC_CLOCK_POSIX_GETTIMEOFDAY 4
#define SRT_SYNC_CLOCK_AMD64_RDTSC 5
#define SRT_SYNC_CLOCK_IA32_RDTSC 6
#define SRT_SYNC_CLOCK_IA64_ITC 7

SRT_API int srt_clock_type(void);

#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 5 additions & 0 deletions srtcore/srt_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,9 @@ int64_t srt_connection_time(SRTSOCKET sock)
return CUDT::socketStartTime(sock);
}

int srt_clock_type()
{
return SRT_SYNC_CLOCK;
}

}
10 changes: 0 additions & 10 deletions srtcore/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@
#ifndef INC_SRT_SYNC_H
#define INC_SRT_SYNC_H

// Possible internal clock types
#define SRT_SYNC_CLOCK_STDCXX_STEADY 0 // C++11 std::chrono::steady_clock
#define SRT_SYNC_CLOCK_GETTIME_MONOTONIC 1 // clock_gettime with CLOCK_MONOTONIC
#define SRT_SYNC_CLOCK_WINQPC 2
#define SRT_SYNC_CLOCK_MACH_ABSTIME 3
#define SRT_SYNC_CLOCK_POSIX_GETTIMEOFDAY 4
#define SRT_SYNC_CLOCK_AMD64_RDTSC 5
#define SRT_SYNC_CLOCK_IA32_RDTSC 6
#define SRT_SYNC_CLOCK_IA64_ITC 7

#include <cstdlib>
#include <limits>
#ifdef ENABLE_STDCXX_SYNC
Expand Down

0 comments on commit 291e010

Please sign in to comment.