mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix #109: fix the system jump time, adjust system startup time. 0.9.135
This commit is contained in:
parent
7de95c12e0
commit
b357504b1d
6 changed files with 48 additions and 11 deletions
|
@ -242,6 +242,7 @@ Supported operating systems and hardware:
|
|||
* 2013-10-17, Created.<br/>
|
||||
|
||||
## History
|
||||
* v1.0, 2014-06-25, fix [#109](https://github.com/winlinvip/simple-rtmp-server/issues/109), fix the system jump time, adjust system startup time. 0.9.135
|
||||
* <strong>v1.0, 2014-06-27, [1.0 mainline5(0.9.134)](https://github.com/winlinvip/simple-rtmp-server/releases/tag/1.0.mainline5) released. 41573 lines.</strong>
|
||||
* v1.0, 2014-06-27, SRS online 30days with RTMP/HLS.
|
||||
* v1.0, 2014-06-25, fix [#108](https://github.com/winlinvip/simple-rtmp-server/issues/108), support config time jitter for encoder non-monotonical stream. 0.9.133
|
||||
|
|
|
@ -61,6 +61,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
// update time interval:
|
||||
// SRS_SYS_CYCLE_INTERVAL * SRS_SYS_TIME_RESOLUTION_MS_TIMES
|
||||
// @see SYS_TIME_RESOLUTION_US
|
||||
#define SRS_SYS_TIME_RESOLUTION_MS_TIMES 3
|
||||
|
||||
// update rusage interval:
|
||||
|
@ -399,6 +400,9 @@ int SrsServer::initialize()
|
|||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// ensure the time is ok.
|
||||
srs_update_system_time_ms();
|
||||
|
||||
// for the main objects(server, config, log, context),
|
||||
// never subscribe handler in constructor,
|
||||
// instead, subscribe handler in initialize method.
|
||||
|
|
|
@ -76,8 +76,7 @@ void srs_update_system_rusage()
|
|||
srs_warn("getrusage failed, ignore");
|
||||
return;
|
||||
}
|
||||
|
||||
srs_update_system_time_ms();
|
||||
|
||||
_srs_system_rusage.sample_time = srs_get_system_time_ms();
|
||||
|
||||
_srs_system_rusage.ok = true;
|
||||
|
@ -233,8 +232,6 @@ bool get_proc_self_stat(SrsProcSelfStat& r)
|
|||
|
||||
void srs_update_proc_stat()
|
||||
{
|
||||
srs_update_system_time_ms();
|
||||
|
||||
// system cpu stat
|
||||
if (true) {
|
||||
SrsProcSystemStat r;
|
||||
|
@ -266,7 +263,6 @@ void srs_update_proc_stat()
|
|||
return;
|
||||
}
|
||||
|
||||
srs_update_system_time_ms();
|
||||
r.sample_time = srs_get_system_time_ms();
|
||||
|
||||
// calc usage in percent
|
||||
|
@ -390,7 +386,7 @@ SrsPlatformInfo::SrsPlatformInfo()
|
|||
{
|
||||
ok = false;
|
||||
|
||||
srs_startup_time = srs_get_system_time_ms();
|
||||
srs_startup_time = 0;
|
||||
|
||||
os_uptime = 0;
|
||||
os_ilde_time = 0;
|
||||
|
@ -412,6 +408,8 @@ void srs_update_platform_info()
|
|||
SrsPlatformInfo& r = _srs_system_platform_info;
|
||||
r.ok = true;
|
||||
|
||||
r.srs_startup_time = srs_get_system_startup_time_ms();
|
||||
|
||||
if (true) {
|
||||
FILE* f = fopen("/proc/uptime", "r");
|
||||
if (f == NULL) {
|
||||
|
|
|
@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
// current release version
|
||||
#define VERSION_MAJOR "0"
|
||||
#define VERSION_MINOR "9"
|
||||
#define VERSION_REVISION "134"
|
||||
#define VERSION_REVISION "135"
|
||||
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
|
||||
// server info.
|
||||
#define RTMP_SIG_SRS_KEY "SRS"
|
||||
|
|
|
@ -33,7 +33,13 @@ using namespace std;
|
|||
|
||||
#include <srs_kernel_log.hpp>
|
||||
|
||||
// this value must:
|
||||
// equals to (SRS_SYS_CYCLE_INTERVAL*SRS_SYS_TIME_RESOLUTION_MS_TIMES)*1000
|
||||
// @see SRS_SYS_TIME_RESOLUTION_MS_TIMES
|
||||
#define SYS_TIME_RESOLUTION_US 300*1000
|
||||
|
||||
static int64_t _srs_system_time_us_cache = 0;
|
||||
static int64_t _srs_system_time_startup_time = 0;
|
||||
|
||||
int64_t srs_get_system_time_ms()
|
||||
{
|
||||
|
@ -43,7 +49,14 @@ int64_t srs_get_system_time_ms()
|
|||
|
||||
return _srs_system_time_us_cache / 1000;
|
||||
}
|
||||
|
||||
int64_t srs_get_system_startup_time_ms()
|
||||
{
|
||||
if (_srs_system_time_startup_time <= 0) {
|
||||
srs_update_system_time_ms();
|
||||
}
|
||||
|
||||
return _srs_system_time_startup_time / 1000;
|
||||
}
|
||||
void srs_update_system_time_ms()
|
||||
{
|
||||
timeval now;
|
||||
|
@ -56,12 +69,32 @@ void srs_update_system_time_ms()
|
|||
// @see: https://github.com/winlinvip/simple-rtmp-server/issues/35
|
||||
// we must convert the tv_sec/tv_usec to int64_t.
|
||||
int64_t now_us = ((int64_t)now.tv_sec) * 1000 * 1000 + (int64_t)now.tv_usec;
|
||||
if (now_us < _srs_system_time_us_cache) {
|
||||
srs_warn("system time negative, "
|
||||
"history=%"PRId64"us, now=%"PRId64"", _srs_system_time_us_cache, now_us);
|
||||
|
||||
// for some ARM os, the starttime maybe invalid,
|
||||
// for example, on the cubieboard2, the srs_startup_time is 1262304014640,
|
||||
// while now is 1403842979210 in ms, diff is 141538964570 ms, 1638 days
|
||||
// it's impossible, and maybe the problem of startup time is invalid.
|
||||
// use date +%s to get system time is 1403844851.
|
||||
// so we use relative time.
|
||||
if (_srs_system_time_us_cache <= 0) {
|
||||
_srs_system_time_us_cache = now_us;
|
||||
_srs_system_time_startup_time = now_us;
|
||||
return;
|
||||
}
|
||||
|
||||
// use relative time.
|
||||
int64_t diff = now_us - _srs_system_time_us_cache;
|
||||
diff = srs_max(0, diff);
|
||||
if (diff < 0 || diff > 1000 * SYS_TIME_RESOLUTION_US) {
|
||||
srs_warn("system time jump, history=%"PRId64"us, now=%"PRId64"us, diff=%"PRId64"us",
|
||||
_srs_system_time_us_cache, now_us, diff);
|
||||
// @see: https://github.com/winlinvip/simple-rtmp-server/issues/109
|
||||
_srs_system_time_startup_time += diff;
|
||||
}
|
||||
|
||||
_srs_system_time_us_cache = now_us;
|
||||
srs_info("system time updated, startup=%"PRId64"us, now=%"PRId64"us",
|
||||
_srs_system_time_startup_time, _srs_system_time_us_cache);
|
||||
}
|
||||
|
||||
string srs_dns_resolve(string host)
|
||||
|
|
|
@ -38,6 +38,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
// get current system time in ms, use cache to avoid performance problem
|
||||
extern int64_t srs_get_system_time_ms();
|
||||
extern int64_t srs_get_system_startup_time_ms();
|
||||
// the deamon st-thread will update it.
|
||||
extern void srs_update_system_time_ms();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue