ossrs / srs

SRS is a simple, high-efficiency, real-time video server supporting RTMP, WebRTC, HLS, HTTP-FLV, SRT, MPEG-DASH, and GB28181.

Home Page:https://ossrs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

change system time backward will let st-srs behavior abnormal

suzp1984 opened this issue · comments

Root Cause

#define MD_GET_UTIME() \
struct timeval tv; \
(void) gettimeofday(&tv, NULL); \
return (tv.tv_sec * 1000000LL + tv.tv_usec)

the default implementation of get timestamp of microseconds is depends on system time.

man gettimeofday

the st-srs has api that let us to config our own get timestamp function, but srs didn't config it.

/*****************************************
* Time functions
*/
st_utime_t st_utime(void)
{
if (_st_utime == NULL) {
#ifdef MD_GET_UTIME
MD_GET_UTIME();
#else
#error Unknown OS
#endif
}
return (*_st_utime)();
}
int st_set_utime_function(st_utime_t (*func)(void))
{
if (_st_active_count) {
errno = EINVAL;
return -1;
}
_st_utime = func;
return 0;
}

Solutions

refactor MD_GET_UTIME or Config a time function based on more robust solutions, e.g. system uptime, the timestamp since the system boot.

Version
All version

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'trunk/3rdparty/st-srs/tools/helloword/'
  2. run make
  3. run ./helloword
  4. change system time backward, e.g. change system time to one year before;
  5. check the Hello print will stuck.

Expected behavior
Change the system time should not impact the st-srs behavior.

Nice work! Welcome to patch it.