Skip to content

Commit

Permalink
[core] Added SRT time API
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Jun 23, 2020
1 parent 6c847ba commit 06d8ecb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
9 changes: 9 additions & 0 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11186,6 +11186,15 @@ int CUDT::rejectReason(SRTSOCKET u, int value)
return 0;
}

int64_t CUDT::socketStartTime(SRTSOCKET u)
{
CUDTSocket* s = s_UDTUnited.locateSocket(u);
if (!s || !s->m_pUDT)
return APIError(MJ_NOTSUP, MN_SIDINVAL);

return count_microseconds(s->m_pUDT->m_stats.tsStartTime.time_since_epoch());
}

bool CUDT::runAcceptHook(CUDT *acore, const sockaddr* peer, const CHandShake& hs, const CPacket& hspkt)
{
// Prepare the information for the hook.
Expand Down
1 change: 1 addition & 0 deletions srtcore/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@ class CUDT
static int getsndbuffer(SRTSOCKET u, size_t* blocks, size_t* bytes);
static int rejectReason(SRTSOCKET s);
static int rejectReason(SRTSOCKET s, int value);
static int64_t socketStartTime(SRTSOCKET s);

public: // internal API
// This is public so that it can be used directly in API implementation functions.
Expand Down
6 changes: 5 additions & 1 deletion srtcore/srt.h
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ typedef struct SRT_MsgCtrl_
int msgttl; // TTL for a message, default -1 (no TTL limitation)
int inorder; // Whether a message is allowed to supersede partially lost one. Unused in stream and live mode.
int boundary; // 0:mid pkt, 1(01b):end of frame, 2(11b):complete frame, 3(10b): start of frame
uint64_t srctime; // source timestamp (usec), 0: use internal time
uint64_t srctime; // source time since epoch (usec), 0: use internal time
int32_t pktseq; // sequence number of the first packet in received message (unused for sending)
int32_t msgno; // message number (output value for both sending and receiving)
SRT_SOCKGROUPDATA* grpdata;
Expand Down Expand Up @@ -987,6 +987,10 @@ const char* srt_rejectreason_str(int id);

SRT_API uint32_t srt_getversion();

SRT_API int64_t srt_time_now();

SRT_API int64_t srt_connection_uptime(SRTSOCKET sock);

#ifdef __cplusplus
}
#endif
Expand Down
10 changes: 10 additions & 0 deletions srtcore/srt_c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,14 @@ uint32_t srt_getversion()
return SrtVersion(SRT_VERSION_MAJOR, SRT_VERSION_MINOR, SRT_VERSION_PATCH);
}

int64_t srt_time_now()
{
return srt::sync::count_microseconds(srt::sync::steady_clock::now().time_since_epoch());
}

int64_t srt_connection_uptime(SRTSOCKET sock)
{
return CUDT::socketStartTime(sock);
}

}

0 comments on commit 06d8ecb

Please sign in to comment.