ossrs / srs

SRS is a simple, high-efficiency, real-time video server supporting RTMP, WebRTC, HLS, HTTP-FLV, SRT, MPEG-DASH, and GB28181.
https://ossrs.io
MIT License
24.72k stars 5.28k forks source link

change system time backward will let st-srs behavior abnormal #3978

Open suzp1984 opened 3 months ago

suzp1984 commented 3 months ago

Root Cause

https://github.com/ossrs/srs/blob/fa8096ad0117a085515729e12a3758ca26036552/trunk/3rdparty/st-srs/md.h#L113-L116 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.

https://github.com/ossrs/srs/blob/fa8096ad0117a085515729e12a3758ca26036552/trunk/3rdparty/st-srs/sync.c#L57-L85

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.

winlinvip commented 3 months ago

Nice work! Welcome to patch it.