1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Refine srs_update_system_time in time unit

This commit is contained in:
winlin 2019-04-10 08:32:46 +08:00
parent 9b1222a79c
commit 9b7c0802a9
17 changed files with 64 additions and 47 deletions

View file

@ -147,7 +147,7 @@ srs_error_t SrsBandwidth::bandwidth_check(SrsRtmpServer* rtmp, ISrsProtocolStati
static srs_utime_t last_check_time = 0;
srs_utime_t interval = _srs_config->get_bw_check_interval(_req->vhost);
srs_utime_t time_now = srs_update_system_time_ms() * SRS_UTIME_MILLISECONDS;
srs_utime_t time_now = srs_update_system_time();
// reject the connection in the interval window.
if (last_check_time > 0 && time_now - last_check_time < interval) {
_rtmp->response_connect_reject(_req, "bandcheck rejected");
@ -184,7 +184,7 @@ srs_error_t SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit)
_rtmp->set_recv_timeout(publish_sample.duration_ms * 2);
// start test.
srs_update_system_time_ms();
srs_update_system_time();
int64_t start_time = srs_get_system_time_ms();
// sample play
@ -210,7 +210,7 @@ srs_error_t SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit)
}
// stop test.
srs_update_system_time_ms();
srs_update_system_time();
int64_t end_time = srs_get_system_time_ms();
srs_trace("bandwidth ok. duartion=%dms(%d+%d), play=%dkbps, publish=%dkbps",
@ -261,7 +261,7 @@ srs_error_t SrsBandwidth::play_checking(SrsBandwidthSample* sample, SrsKbpsLimit
memset(random_data, 'A', size);
int data_count = 1;
srs_update_system_time_ms();
srs_update_system_time();
int64_t starttime = srs_get_system_time_ms();
while ((srs_get_system_time_ms() - starttime) < sample->duration_ms) {
srs_usleep(sample->interval_ms);
@ -284,7 +284,7 @@ srs_error_t SrsBandwidth::play_checking(SrsBandwidthSample* sample, SrsKbpsLimit
limit->send_limit();
}
srs_update_system_time_ms();
srs_update_system_time();
sample->calc_kbps((int)_rtmp->get_send_bytes(), (int)(srs_get_system_time_ms() - starttime));
return err;
@ -344,7 +344,7 @@ srs_error_t SrsBandwidth::publish_checking(SrsBandwidthSample* sample, SrsKbpsLi
srs_error_t err = srs_success;
// recv publish msgs until @duration_ms ms
srs_update_system_time_ms();
srs_update_system_time();
int64_t starttime = srs_get_system_time_ms();
while ((srs_get_system_time_ms() - starttime) < sample->duration_ms) {
SrsCommonMessage* msg = NULL;
@ -363,7 +363,7 @@ srs_error_t SrsBandwidth::publish_checking(SrsBandwidthSample* sample, SrsKbpsLi
limit->recv_limit();
}
srs_update_system_time_ms();
srs_update_system_time();
sample->calc_kbps((int)_rtmp->get_recv_bytes(), (int)(srs_get_system_time_ms() - starttime));
return err;

View file

@ -6524,9 +6524,9 @@ string SrsConfig::get_dvr_plan(string vhost)
return conf->arg0();
}
int SrsConfig::get_dvr_duration(string vhost)
srs_utime_t SrsConfig::get_dvr_duration(string vhost)
{
static int DEFAULT = 30;
static srs_utime_t DEFAULT = 30 * SRS_UTIME_SECONDS;
SrsConfDirective* conf = get_dvr(vhost);
if (!conf) {
@ -6538,7 +6538,7 @@ int SrsConfig::get_dvr_duration(string vhost)
return DEFAULT;
}
return ::atoi(conf->arg0().c_str());
return (srs_utime_t)(::atoi(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
}
bool SrsConfig::get_dvr_wait_keyframe(string vhost)

View file

@ -1313,7 +1313,7 @@ public:
/**
* get the duration of dvr flv.
*/
virtual int get_dvr_duration(std::string vhost);
virtual srs_utime_t get_dvr_duration(std::string vhost);
/**
* whether wait keyframe to reap segment.
*/

View file

@ -265,7 +265,7 @@ srs_error_t SrsMpdWriter::get_fragment(bool video, std::string& home, std::strin
home = fragment_home;
sn = srs_update_system_time_ms() * SRS_UTIME_MILLISECONDS / fragment;
sn = srs_update_system_time() / fragment;
basetime = sn * srsu2ms(fragment);
if (video) {

View file

@ -740,7 +740,7 @@ void SrsDvrSessionPlan::on_unpublish()
SrsDvrSegmentPlan::SrsDvrSegmentPlan()
{
cduration = -1;
cduration = 0;
wait_keyframe = false;
}
@ -759,8 +759,6 @@ srs_error_t SrsDvrSegmentPlan::initialize(SrsOriginHub* h, SrsDvrSegmenter* s, S
wait_keyframe = _srs_config->get_dvr_wait_keyframe(req->vhost);
cduration = _srs_config->get_dvr_duration(req->vhost);
// to ms
cduration *= 1000;
return srs_success;
}
@ -833,7 +831,7 @@ srs_error_t SrsDvrSegmentPlan::update_duration(SrsSharedPtrMessage* msg)
// ignore if duration ok.
SrsFragment* fragment = segment->current();
if (cduration <= 0 || fragment->duration() < cduration) {
if (cduration <= 0 || fragment->duration() < int64_t(srsu2ms(cduration))) {
return err;
}
@ -881,8 +879,6 @@ srs_error_t SrsDvrSegmentPlan::on_reload_vhost_dvr(string vhost)
wait_keyframe = _srs_config->get_dvr_wait_keyframe(req->vhost);
cduration = _srs_config->get_dvr_duration(req->vhost);
// to ms
cduration *= 1000;
return err;
}

View file

@ -227,8 +227,8 @@ public:
class SrsDvrSegmentPlan : public SrsDvrPlan
{
private:
// in config, in ms
int cduration;
// in config, in srs_utime_t
srs_utime_t cduration;
bool wait_keyframe;
public:
SrsDvrSegmentPlan();

View file

@ -390,7 +390,7 @@ srs_error_t SrsHlsMuxer::segment_open()
ts_file = srs_path_build_stream(ts_file, req->vhost, req->app, req->stream);
if (hls_ts_floor) {
// accept the floor ts for the first piece.
int64_t current_floor_ts = (int64_t)(srs_update_system_time_ms() / (1000 * hls_fragment));
int64_t current_floor_ts = (int64_t)(srsu2ms(srs_update_system_time()) / (1000 * hls_fragment));
if (!accept_floor_ts) {
accept_floor_ts = current_floor_ts - 1;
} else {

View file

@ -363,7 +363,7 @@ srs_error_t SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* re
url = srs_string_replace(url, "[ts_url]", ts_url);
url = srs_string_replace(url, "[param]", req->param);
int64_t starttime = srs_update_system_time_ms();
int64_t starttime = srsu2ms(srs_update_system_time());
SrsHttpUri uri;
if ((err = uri.initialize(url)) != srs_success) {
@ -405,7 +405,7 @@ srs_error_t SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* re
nb_read += nb_bytes;
}
int spenttime = (int)(srs_update_system_time_ms() - starttime);
int spenttime = (int)(srsu2ms(srs_update_system_time()) - starttime);
srs_trace("http hook on_hls_notify success. client_id=%d, url=%s, code=%d, spent=%dms, read=%dB, err=%s",
client_id, url.c_str(), msg->status_code(), spenttime, nb_read, srs_error_desc(err).c_str());

View file

@ -381,7 +381,7 @@ srs_error_t SrsPublishRecvThread::consume(SrsCommonMessage* msg)
// log to show the time of recv thread.
srs_verbose("recv thread now=%" PRId64 "us, got msg time=%" PRId64 "ms, size=%d",
srs_update_system_time_ms(), msg->header.timestamp, msg->size);
srs_update_system_time(), msg->header.timestamp, msg->size);
// the rtmp connection will handle this message
err = _conn->handle_publish_message(_source, msg);

View file

@ -542,7 +542,7 @@ srs_error_t SrsServer::initialize(ISrsServerCycle* ch)
srs_error_t err = srs_success;
// ensure the time is ok.
srs_update_system_time_ms();
srs_update_system_time();
// for the main objects(server, config, log, context),
// never subscribe handler in constructor,
@ -971,7 +971,7 @@ srs_error_t SrsServer::do_cycle()
// update the cache time
if ((i % SRS_SYS_TIME_RESOLUTION_MS_TIMES) == 0) {
srs_info("update current time cache.");
srs_update_system_time_ms();
srs_update_system_time();
}
if ((i % SRS_SYS_RUSAGE_RESOLUTION_TIMES) == 0) {