diff --git a/trunk/auto/auto_headers.sh b/trunk/auto/auto_headers.sh index 029613dd7..bfd650e7d 100755 --- a/trunk/auto/auto_headers.sh +++ b/trunk/auto/auto_headers.sh @@ -103,6 +103,12 @@ else srs_undefine_macro "SRS_AUTO_MEM_WATCH" $SRS_AUTO_HEADERS_H fi +if [ $SRS_UTEST = YES ]; then + srs_define_macro "SRS_AUTO_UTEST" $SRS_AUTO_HEADERS_H +else + srs_undefine_macro "SRS_AUTO_UTEST" $SRS_AUTO_HEADERS_H +fi + # whether compile ffmpeg tool if [ $SRS_FFMPEG_TOOL = YES ]; then srs_define_macro "SRS_AUTO_FFMPEG_TOOL" $SRS_AUTO_HEADERS_H diff --git a/trunk/src/app/srs_app_bandwidth.cpp b/trunk/src/app/srs_app_bandwidth.cpp index 8fb851df8..c7963fe9b 100644 --- a/trunk/src/app/srs_app_bandwidth.cpp +++ b/trunk/src/app/srs_app_bandwidth.cpp @@ -184,8 +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(); - int64_t start_time = srs_get_system_time_ms(); + srs_utime_t start_time = srs_update_system_time(); // sample play if ((err = play_start(&play_sample, limit)) != srs_success) { @@ -210,17 +209,16 @@ srs_error_t SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit) } // stop test. - 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", - (int)(end_time - start_time), play_sample.actual_duration_ms, - publish_sample.actual_duration_ms, play_sample.kbps, - publish_sample.kbps); + srs_utime_t end_time = srs_update_system_time(); if ((err = do_final(play_sample, publish_sample, start_time, end_time)) != srs_success) { return srs_error_wrap(err, "final"); } + + srs_trace("bandwidth ok. duartion=%dms(%d+%d), play=%dkbps, publish=%dkbps", + srsu2msi(end_time - start_time), play_sample.actual_duration_ms, + publish_sample.actual_duration_ms, play_sample.kbps, + publish_sample.kbps); srs_usleep(_SRS_BANDWIDTH_FINAL_WAIT); @@ -261,10 +259,9 @@ srs_error_t SrsBandwidth::play_checking(SrsBandwidthSample* sample, SrsKbpsLimit memset(random_data, 'A', size); int data_count = 1; - 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); + srs_utime_t starttime = srs_update_system_time(); + while (srsu2ms(srs_get_system_time() - starttime) < sample->duration_ms) { + srs_usleep(sample->interval_ms * SRS_UTIME_MILLISECONDS); // TODO: FIXME: use shared ptr message. SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_playing(); @@ -285,7 +282,7 @@ srs_error_t SrsBandwidth::play_checking(SrsBandwidthSample* sample, SrsKbpsLimit limit->send_limit(); } srs_update_system_time(); - sample->calc_kbps((int)_rtmp->get_send_bytes(), (int)(srs_get_system_time_ms() - starttime)); + sample->calc_kbps((int)_rtmp->get_send_bytes(), srsu2msi(srs_get_system_time() - starttime)); return err; } @@ -344,9 +341,8 @@ 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(); - int64_t starttime = srs_get_system_time_ms(); - while ((srs_get_system_time_ms() - starttime) < sample->duration_ms) { + srs_utime_t starttime = srs_update_system_time(); + while (srsu2ms(srs_get_system_time() - starttime) < sample->duration_ms) { SrsCommonMessage* msg = NULL; SrsBandwidthPacket* pkt = NULL; if ((err = _rtmp->expect_message(&msg, &pkt)) != srs_success) { @@ -364,7 +360,7 @@ srs_error_t SrsBandwidth::publish_checking(SrsBandwidthSample* sample, SrsKbpsLi limit->recv_limit(); } srs_update_system_time(); - sample->calc_kbps((int)_rtmp->get_recv_bytes(), (int)(srs_get_system_time_ms() - starttime)); + sample->calc_kbps((int)_rtmp->get_recv_bytes(), srsu2msi(srs_get_system_time() - starttime)); return err; } @@ -401,7 +397,7 @@ srs_error_t SrsBandwidth::publish_stop(SrsBandwidthSample* sample, SrsKbpsLimit* return err; } -srs_error_t SrsBandwidth::do_final(SrsBandwidthSample& play_sample, SrsBandwidthSample& publish_sample, int64_t start_time, int64_t& end_time) +srs_error_t SrsBandwidth::do_final(SrsBandwidthSample& play_sample, SrsBandwidthSample& publish_sample, srs_utime_t start_time, srs_utime_t& end_time) { srs_error_t err = srs_success; @@ -409,8 +405,8 @@ srs_error_t SrsBandwidth::do_final(SrsBandwidthSample& play_sample, SrsBandwidth // flash client will close connection when got this packet, // for the publish queue may contains packets. SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_finish(); - pkt->data->set("start_time", SrsAmf0Any::number(start_time)); - pkt->data->set("end_time", SrsAmf0Any::number(end_time)); + pkt->data->set("start_time", SrsAmf0Any::number(srsu2ms(start_time))); + pkt->data->set("end_time", SrsAmf0Any::number(srsu2ms(end_time))); pkt->data->set("play_kbps", SrsAmf0Any::number(play_sample.kbps)); pkt->data->set("publish_kbps", SrsAmf0Any::number(publish_sample.kbps)); pkt->data->set("play_bytes", SrsAmf0Any::number(play_sample.bytes)); diff --git a/trunk/src/app/srs_app_bandwidth.hpp b/trunk/src/app/srs_app_bandwidth.hpp index 0573ad423..0afdf9e07 100644 --- a/trunk/src/app/srs_app_bandwidth.hpp +++ b/trunk/src/app/srs_app_bandwidth.hpp @@ -193,7 +193,7 @@ private: * for flash client, the sent queue is fullfill with publishing call messages, * so server never expect the final packet from it. */ - virtual srs_error_t do_final(SrsBandwidthSample& play_sample, SrsBandwidthSample& publish_sample, int64_t start_time, int64_t& end_time); + virtual srs_error_t do_final(SrsBandwidthSample& play_sample, SrsBandwidthSample& publish_sample, srs_utime_t start_time, srs_utime_t& end_time); }; /** diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 9bb15ae7c..644eb0ee5 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -6247,9 +6247,9 @@ bool SrsConfig::get_hls_cleanup(string vhost) return SRS_CONF_PERFER_TRUE(conf->arg0()); } -int SrsConfig::get_hls_dispose(string vhost) +srs_utime_t SrsConfig::get_hls_dispose(string vhost) { - static int DEFAULT = 0; + static srs_utime_t DEFAULT = 0; SrsConfDirective* conf = get_hls(vhost); if (!conf) { @@ -6261,7 +6261,7 @@ int SrsConfig::get_hls_dispose(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_hls_wait_keyframe(string vhost) diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 35ca1dc62..b2ffa60a5 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -1230,9 +1230,9 @@ public: */ virtual bool get_hls_cleanup(std::string vhost); /** - * the timeout to dispose the hls. + * the timeout in srs_utime_t to dispose the hls. */ - virtual int get_hls_dispose(std::string vhost); + virtual srs_utime_t get_hls_dispose(std::string vhost); /** * whether reap the ts when got keyframe. */ diff --git a/trunk/src/app/srs_app_conn.cpp b/trunk/src/app/srs_app_conn.cpp index d274ff8d9..79188ea95 100644 --- a/trunk/src/app/srs_app_conn.cpp +++ b/trunk/src/app/srs_app_conn.cpp @@ -36,7 +36,7 @@ SrsConnection::SrsConnection(IConnectionManager* cm, srs_netfd_t c, string cip) manager = cm; stfd = c; ip = cip; - create_time = srs_get_system_time_ms(); + create_time = srsu2ms(srs_get_system_time()); skt = new SrsStSocket(); clk = new SrsWallClock(); diff --git a/trunk/src/app/srs_app_dash.cpp b/trunk/src/app/srs_app_dash.cpp index 3e74134c3..7a45589e3 100644 --- a/trunk/src/app/srs_app_dash.cpp +++ b/trunk/src/app/srs_app_dash.cpp @@ -162,7 +162,7 @@ SrsMpdWriter::SrsMpdWriter() { req = NULL; timeshit = update_period = fragment = 0; - last_update_mpd = -1; + last_update_mpd = 0; } SrsMpdWriter::~SrsMpdWriter() @@ -190,10 +190,10 @@ srs_error_t SrsMpdWriter::write(SrsFormat* format) srs_error_t err = srs_success; // MPD is not expired? - if (last_update_mpd != -1 && srs_get_system_time_ms() - last_update_mpd < int64_t(srsu2ms(update_period))) { + if (last_update_mpd != 0 && srs_get_system_time() - last_update_mpd < update_period) { return err; } - last_update_mpd = srs_get_system_time_ms(); + last_update_mpd = srs_get_system_time(); string mpd_path = srs_path_build_stream(mpd_file, req->vhost, req->app, req->stream); string full_path = home + "/" + mpd_path; diff --git a/trunk/src/app/srs_app_dash.hpp b/trunk/src/app/srs_app_dash.hpp index 23ed315ce..dd4467393 100644 --- a/trunk/src/app/srs_app_dash.hpp +++ b/trunk/src/app/srs_app_dash.hpp @@ -84,7 +84,7 @@ class SrsMpdWriter { private: SrsRequest* req; - int64_t last_update_mpd; + srs_utime_t last_update_mpd; private: // The duration of fragment in srs_utime_t. srs_utime_t fragment; diff --git a/trunk/src/app/srs_app_hls.cpp b/trunk/src/app/srs_app_hls.cpp index 0b9058a52..8e27cf5c8 100644 --- a/trunk/src/app/srs_app_hls.cpp +++ b/trunk/src/app/srs_app_hls.cpp @@ -870,7 +870,7 @@ srs_error_t SrsHlsController::on_publish(SrsRequest* req) // whether use floor(timestamp/hls_fragment) for variable timestamp bool ts_floor = _srs_config->get_hls_ts_floor(vhost); // the seconds to dispose the hls. - int hls_dispose = _srs_config->get_hls_dispose(vhost); + srs_utime_t hls_dispose = _srs_config->get_hls_dispose(vhost); bool hls_keys = _srs_config->get_hls_keys(vhost); int hls_fragments_per_key = _srs_config->get_hls_fragments_per_key(vhost); @@ -891,9 +891,9 @@ srs_error_t SrsHlsController::on_publish(SrsRequest* req) if ((err = muxer->segment_open()) != srs_success) { return srs_error_wrap(err, "hls: segment open"); } - srs_trace("hls: win=%.2f, frag=%.2f, prefix=%s, path=%s, m3u8=%s, ts=%s, aof=%.2f, floor=%d, clean=%d, waitk=%d, dispose=%d", + srs_trace("hls: win=%.2f, frag=%.2f, prefix=%s, path=%s, m3u8=%s, ts=%s, aof=%.2f, floor=%d, clean=%d, waitk=%d, dispose=%dms", hls_window, hls_fragment, entry_prefix.c_str(), path.c_str(), m3u8_file.c_str(), - ts_file.c_str(), hls_aof_ratio, ts_floor, cleanup, wait_keyframe, hls_dispose); + ts_file.c_str(), hls_aof_ratio, ts_floor, cleanup, wait_keyframe, srsu2msi(hls_dispose)); return err; } @@ -1061,7 +1061,7 @@ void SrsHls::dispose() // Ignore when hls_dispose disabled. // @see https://github.com/ossrs/srs/issues/865 - int hls_dispose = _srs_config->get_hls_dispose(req->vhost); + srs_utime_t hls_dispose = _srs_config->get_hls_dispose(req->vhost); if (!hls_dispose) { return; } @@ -1074,21 +1074,21 @@ srs_error_t SrsHls::cycle() srs_error_t err = srs_success; if (last_update_time <= 0) { - last_update_time = srs_get_system_time_ms(); + last_update_time = srs_get_system_time(); } if (!req) { return err; } - int hls_dispose = _srs_config->get_hls_dispose(req->vhost) * 1000; + srs_utime_t hls_dispose = _srs_config->get_hls_dispose(req->vhost); if (hls_dispose <= 0) { return err; } - if (srs_get_system_time_ms() - last_update_time <= hls_dispose) { + if (srs_get_system_time() - last_update_time <= hls_dispose) { return err; } - last_update_time = srs_get_system_time_ms(); + last_update_time = srs_get_system_time(); if (!disposable) { return err; @@ -1120,7 +1120,7 @@ srs_error_t SrsHls::on_publish() srs_error_t err = srs_success; // update the hls time, for hls_dispose. - last_update_time = srs_get_system_time_ms(); + last_update_time = srs_get_system_time(); // support multiple publish. if (enabled) { @@ -1170,7 +1170,7 @@ srs_error_t SrsHls::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* forma } // update the hls time, for hls_dispose. - last_update_time = srs_get_system_time_ms(); + last_update_time = srs_get_system_time(); SrsSharedPtrMessage* audio = shared_audio->copy(); SrsAutoFree(SrsSharedPtrMessage, audio); @@ -1227,7 +1227,7 @@ srs_error_t SrsHls::on_video(SrsSharedPtrMessage* shared_video, SrsFormat* forma } // update the hls time, for hls_dispose. - last_update_time = srs_get_system_time_ms(); + last_update_time = srs_get_system_time(); SrsSharedPtrMessage* video = shared_video->copy(); SrsAutoFree(SrsSharedPtrMessage, video); diff --git a/trunk/src/app/srs_app_hls.hpp b/trunk/src/app/srs_app_hls.hpp index a51a232f7..0abb0a2dc 100644 --- a/trunk/src/app/srs_app_hls.hpp +++ b/trunk/src/app/srs_app_hls.hpp @@ -33,6 +33,7 @@ #include #include #include +#include class SrsFormat; class SrsSharedPtrMessage; @@ -319,7 +320,7 @@ private: SrsRequest* req; bool enabled; bool disposable; - int64_t last_update_time; + srs_utime_t last_update_time; private: // If the diff=dts-previous_audio_dts is about 23, // that's the AAC samples is 1024, and we use the samples to calc the dts. diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index d8c9f8d2d..86a3698ac 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -681,7 +681,7 @@ srs_error_t SrsGoApiRequests::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess server->set("sigature", SrsJsonAny::str(RTMP_SIG_SRS_KEY)); server->set("version", SrsJsonAny::str(RTMP_SIG_SRS_VERSION)); server->set("link", SrsJsonAny::str(RTMP_SIG_SRS_URL)); - server->set("time", SrsJsonAny::integer(srs_get_system_time_ms())); + server->set("time", SrsJsonAny::integer(srsu2ms(srs_get_system_time()))); return srs_api_response(w, r, obj->dumps()); } diff --git a/trunk/src/app/srs_app_ingest.cpp b/trunk/src/app/srs_app_ingest.cpp index 391613185..3518cb789 100644 --- a/trunk/src/app/srs_app_ingest.cpp +++ b/trunk/src/app/srs_app_ingest.cpp @@ -52,7 +52,7 @@ srs_error_t SrsIngesterFFMPEG::initialize(SrsFFMPEG* ff, string v, string i) ffmpeg = ff; vhost = v; id = i; - starttime = srs_get_system_time_ms(); + starttime = srs_get_system_time(); return err; } @@ -64,7 +64,7 @@ string SrsIngesterFFMPEG::uri() int SrsIngesterFFMPEG::alive() { - return (int)(srs_get_system_time_ms() - starttime); + return srsu2msi(srs_get_system_time() - starttime); } bool SrsIngesterFFMPEG::equals(string v) diff --git a/trunk/src/app/srs_app_ingest.hpp b/trunk/src/app/srs_app_ingest.hpp index 9922127d0..f1ed8ab30 100644 --- a/trunk/src/app/srs_app_ingest.hpp +++ b/trunk/src/app/srs_app_ingest.hpp @@ -30,6 +30,7 @@ #include #include +#include class SrsFFMPEG; class SrsConfDirective; @@ -44,7 +45,7 @@ private: std::string vhost; std::string id; SrsFFMPEG* ffmpeg; - int64_t starttime; + srs_utime_t starttime; public: SrsIngesterFFMPEG(); virtual ~SrsIngesterFFMPEG(); diff --git a/trunk/src/app/srs_app_pithy_print.cpp b/trunk/src/app/srs_app_pithy_print.cpp index 1bbd18d79..e87847705 100644 --- a/trunk/src/app/srs_app_pithy_print.cpp +++ b/trunk/src/app/srs_app_pithy_print.cpp @@ -81,7 +81,7 @@ SrsPithyPrint::SrsPithyPrint(int _stage_id) { stage_id = _stage_id; client_id = enter_stage(); - previous_tick = srs_get_system_time_ms(); + previous_tick = srs_get_system_time(); _age = 0; } @@ -208,12 +208,12 @@ void SrsPithyPrint::elapse() SrsStageInfo* stage = _srs_stages[stage_id]; srs_assert(stage != NULL); - int64_t diff = srs_get_system_time_ms() - previous_tick; + srs_utime_t diff = srs_get_system_time() - previous_tick; diff = srs_max(0, diff); - stage->elapse(diff * SRS_UTIME_MILLISECONDS); + stage->elapse(diff); _age += diff; - previous_tick = srs_get_system_time_ms(); + previous_tick = srs_get_system_time(); } bool SrsPithyPrint::can_print() @@ -226,7 +226,7 @@ bool SrsPithyPrint::can_print() int64_t SrsPithyPrint::age() { - return _age; + return srsu2ms(_age); } diff --git a/trunk/src/app/srs_app_pithy_print.hpp b/trunk/src/app/srs_app_pithy_print.hpp index b4414811d..cd4ace26b 100644 --- a/trunk/src/app/srs_app_pithy_print.hpp +++ b/trunk/src/app/srs_app_pithy_print.hpp @@ -76,9 +76,8 @@ class SrsPithyPrint private: int client_id; int stage_id; - // in ms. - int64_t _age; - int64_t previous_tick; + srs_utime_t _age; + srs_utime_t previous_tick; private: SrsPithyPrint(int _stage_id); public: diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index f4807183a..a54f1f430 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -61,8 +61,8 @@ using namespace std; // when got these videos or audios, pure audio or video, mix ok. #define SRS_MIX_CORRECT_PURE_AV 10 -// the time to cleanup source in ms. -#define SRS_SOURCE_CLEANUP 30000 +// the time to cleanup source. +#define SRS_SOURCE_CLEANUP (30 * SRS_UTIME_SECONDS) int _srs_time_jitter_string2int(std::string time_jitter) { @@ -1767,7 +1767,7 @@ SrsSource::SrsSource() _can_publish = true; _pre_source_id = _source_id = -1; - die_at = -1; + die_at = 0; play_edge = new SrsPlayEdge(); publish_edge = new SrsPublishEdge(); @@ -1821,7 +1821,7 @@ srs_error_t SrsSource::cycle() bool SrsSource::expired() { // unknown state? - if (die_at == -1) { + if (die_at == 0) { return false; } @@ -1835,7 +1835,7 @@ bool SrsSource::expired() return false; } - int64_t now = srs_get_system_time_ms(); + srs_utime_t now = srs_get_system_time(); if (now > die_at + SRS_SOURCE_CLEANUP) { return true; } @@ -2433,7 +2433,7 @@ void SrsSource::on_unpublish() // no consumer, stream is die. if (consumers.empty()) { - die_at = srs_get_system_time_ms(); + die_at = srs_get_system_time(); } } @@ -2498,7 +2498,7 @@ void SrsSource::on_consumer_destroy(SrsConsumer* consumer) if (consumers.empty()) { play_edge->on_all_client_stop(); - die_at = srs_get_system_time_ms(); + die_at = srs_get_system_time(); } } diff --git a/trunk/src/app/srs_app_source.hpp b/trunk/src/app/srs_app_source.hpp index 28f041c7c..d79e041b2 100644 --- a/trunk/src/app/srs_app_source.hpp +++ b/trunk/src/app/srs_app_source.hpp @@ -33,6 +33,7 @@ #include #include #include +#include class SrsFormat; class SrsRtmpFormat; @@ -606,7 +607,7 @@ private: bool _can_publish; // The last die time, when all consumers quit and no publisher, // we will remove the source when source die. - int64_t die_at; + srs_utime_t die_at; public: SrsSource(); virtual ~SrsSource(); diff --git a/trunk/src/app/srs_app_statistic.cpp b/trunk/src/app/srs_app_statistic.cpp index 7b48b5bd0..c649c342a 100644 --- a/trunk/src/app/srs_app_statistic.cpp +++ b/trunk/src/app/srs_app_statistic.cpp @@ -138,7 +138,7 @@ srs_error_t SrsStatisticStream::dumps(SrsJsonObject* obj) obj->set("name", SrsJsonAny::str(stream.c_str())); obj->set("vhost", SrsJsonAny::integer(vhost->id)); obj->set("app", SrsJsonAny::str(app.c_str())); - obj->set("live_ms", SrsJsonAny::integer(srs_get_system_time_ms())); + obj->set("live_ms", SrsJsonAny::integer(srsu2ms(srs_get_system_time()))); obj->set("clients", SrsJsonAny::integer(nb_clients)); obj->set("frames", SrsJsonAny::integer(nb_frames)); obj->set("send_bytes", SrsJsonAny::integer(kbps->get_send_bytes())); @@ -208,7 +208,7 @@ SrsStatisticClient::SrsStatisticClient() conn = NULL; req = NULL; type = SrsRtmpConnUnknown; - create = srs_get_system_time_ms(); + create = srs_get_system_time(); } SrsStatisticClient::~SrsStatisticClient() @@ -229,7 +229,7 @@ srs_error_t SrsStatisticClient::dumps(SrsJsonObject* obj) obj->set("url", SrsJsonAny::str(req->get_stream_url().c_str())); obj->set("type", SrsJsonAny::str(srs_client_type_string(type).c_str())); obj->set("publish", SrsJsonAny::boolean(srs_client_type_is_publish(type))); - obj->set("alive", SrsJsonAny::number((srs_get_system_time_ms() - create) / 1000.0)); + obj->set("alive", SrsJsonAny::number(srsu2ms(srs_get_system_time() - create) / 1000.0)); return err; } diff --git a/trunk/src/app/srs_app_statistic.hpp b/trunk/src/app/srs_app_statistic.hpp index f722c82fb..c9d5661c0 100644 --- a/trunk/src/app/srs_app_statistic.hpp +++ b/trunk/src/app/srs_app_statistic.hpp @@ -124,7 +124,7 @@ public: SrsRequest* req; SrsRtmpConnType type; int id; - int64_t create; + srs_utime_t create; public: SrsStatisticClient(); virtual ~SrsStatisticClient(); diff --git a/trunk/src/app/srs_app_utility.cpp b/trunk/src/app/srs_app_utility.cpp index 76672346e..c3f5520bf 100644 --- a/trunk/src/app/srs_app_utility.cpp +++ b/trunk/src/app/srs_app_utility.cpp @@ -236,7 +236,7 @@ void srs_update_system_rusage() return; } - _srs_system_rusage.sample_time = srs_get_system_time_ms(); + _srs_system_rusage.sample_time = srsu2ms(srs_get_system_time()); _srs_system_rusage.ok = true; } @@ -427,7 +427,7 @@ void srs_update_proc_stat() return; } - r.sample_time = srs_get_system_time_ms(); + r.sample_time = srsu2ms(srs_get_system_time()); // calc usage in percent SrsProcSystemStat& o = _srs_system_cpu_system_stat; @@ -453,7 +453,7 @@ void srs_update_proc_stat() return; } - r.sample_time = srs_get_system_time_ms(); + r.sample_time = srsu2ms(srs_get_system_time()); // calc usage in percent SrsProcSelfStat& o = _srs_system_cpu_self_stat; @@ -505,7 +505,7 @@ bool srs_get_disk_vmstat_stat(SrsDiskStat& r) return false; } - r.sample_time = srs_get_system_time_ms(); + r.sample_time = srsu2ms(srs_get_system_time()); static char buf[1024]; while (fgets(buf, sizeof(buf), f)) { @@ -531,7 +531,7 @@ bool srs_get_disk_vmstat_stat(SrsDiskStat& r) bool srs_get_disk_diskstats_stat(SrsDiskStat& r) { r.ok = true; - r.sample_time = srs_get_system_time_ms(); + r.sample_time = srsu2ms(srs_get_system_time()); // if disabled, ignore all devices. SrsConfDirective* conf = _srs_config->get_stats_disk_device(); @@ -731,7 +731,7 @@ void srs_update_meminfo() // Fuck all of you who use osx for a long time and never patch the osx features for srs. #endif - r.sample_time = srs_get_system_time_ms(); + r.sample_time = srsu2ms(srs_get_system_time()); r.MemActive = r.MemTotal - r.MemFree; r.RealInUse = r.MemActive - r.Buffers - r.Cached; r.NotInUse = r.MemTotal - r.RealInUse; @@ -795,7 +795,7 @@ void srs_update_platform_info() { SrsPlatformInfo& r = _srs_system_platform_info; - r.srs_startup_time = srs_get_system_startup_time_ms(); + r.srs_startup_time = srsu2ms(srs_get_system_startup_time()); #ifndef SRS_OSX if (true) { @@ -940,7 +940,7 @@ void srs_update_network_devices() _nb_srs_system_network_devices = i + 1; srs_info("scan network device ifname=%s, total=%d", r.name, _nb_srs_system_network_devices); - r.sample_time = srs_get_system_time_ms(); + r.sample_time = srsu2ms(srs_get_system_time()); r.ok = true; } @@ -1090,7 +1090,7 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps) r.ok = true; r.nb_conn_srs = nb_conn; - r.sample_time = srs_get_system_time_ms(); + r.sample_time = srsu2ms(srs_get_system_time()); r.rbytes = kbps->get_recv_bytes(); r.rkbps = kbps->get_recv_kbps(); @@ -1199,7 +1199,7 @@ void srs_api_dump_summaries(SrsJsonObject* obj) self_mem_percent = (float)(r->r.ru_maxrss / (double)m->MemTotal); } - int64_t now = srs_get_system_time_ms(); + int64_t now = srsu2ms(srs_get_system_time()); double srs_uptime = (now - p->srs_startup_time) / 100 / 10.0; int64_t n_sample_time = 0; diff --git a/trunk/src/kernel/srs_kernel_utility.cpp b/trunk/src/kernel/srs_kernel_utility.cpp index b00a1740a..5dce8fd38 100644 --- a/trunk/src/kernel/srs_kernel_utility.cpp +++ b/trunk/src/kernel/srs_kernel_utility.cpp @@ -101,25 +101,25 @@ srs_error_t srs_avc_nalu_read_bit(SrsBitBuffer* stream, int8_t& v) return err; } -int64_t _srs_system_time_us_cache = 0; -int64_t _srs_system_time_startup_time = 0; +srs_utime_t _srs_system_time_us_cache = 0; +srs_utime_t _srs_system_time_startup_time = 0; -int64_t srs_get_system_time_ms() +srs_utime_t srs_get_system_time() { if (_srs_system_time_us_cache <= 0) { srs_update_system_time(); } - return _srs_system_time_us_cache / 1000; + return _srs_system_time_us_cache; } -int64_t srs_get_system_startup_time_ms() +srs_utime_t srs_get_system_startup_time_ms() { if (_srs_system_time_startup_time <= 0) { srs_update_system_time(); } - return _srs_system_time_startup_time / 1000; + return _srs_system_time_startup_time; } srs_utime_t srs_update_system_time() diff --git a/trunk/src/kernel/srs_kernel_utility.hpp b/trunk/src/kernel/srs_kernel_utility.hpp index 36e67cbb8..f0ddf8662 100644 --- a/trunk/src/kernel/srs_kernel_utility.hpp +++ b/trunk/src/kernel/srs_kernel_utility.hpp @@ -42,9 +42,9 @@ class SrsBitBuffer; extern srs_error_t srs_avc_nalu_read_uev(SrsBitBuffer* stream, int32_t& v); extern srs_error_t srs_avc_nalu_read_bit(SrsBitBuffer* stream, int8_t& v); -// 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(); +// get current system time in srs_utime_t, use cache to avoid performance problem +extern srs_utime_t srs_get_system_time(); +extern srs_utime_t srs_get_system_startup_time_ms(); // the deamon st-thread will update it. extern srs_utime_t srs_update_system_time(); diff --git a/trunk/src/libs/srs_lib_bandwidth.cpp b/trunk/src/libs/srs_lib_bandwidth.cpp index e24672ddf..3ef379d6b 100644 --- a/trunk/src/libs/srs_lib_bandwidth.cpp +++ b/trunk/src/libs/srs_lib_bandwidth.cpp @@ -137,8 +137,7 @@ int SrsBandwidthClient::bandwidth_check( ) { int ret = ERROR_SUCCESS; - srs_update_system_time(); - *start_time = srs_get_system_time_ms(); + *start_time = srsu2ms(srs_update_system_time()); // play if ((ret = play_start()) != ERROR_SUCCESS) { @@ -193,8 +192,7 @@ int SrsBandwidthClient::bandwidth_check( } } - srs_update_system_time(); - *end_time = srs_get_system_time_ms(); + *end_time = srsu2ms(srs_update_system_time()); return ret; } @@ -313,9 +311,8 @@ int SrsBandwidthClient::publish_checking(int duration_ms, int play_kbps) } int data_count = 1; - srs_update_system_time(); - int64_t starttime = srs_get_system_time_ms(); - while ((srs_get_system_time_ms() - starttime) < duration_ms) { + int64_t starttime = srsu2ms(srs_update_system_time()); + while ((srsu2ms(srs_get_system_time()) - starttime) < duration_ms) { // TODO: FIXME: use shared ptr message. SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_publishing(); @@ -336,13 +333,12 @@ int SrsBandwidthClient::publish_checking(int duration_ms, int play_kbps) } // use the play kbps to control the publish - srs_update_system_time(); - int elaps = (int)(srs_get_system_time_ms() - starttime); + int elaps = (int)(srsu2ms(srs_update_system_time()) - starttime); if (elaps > 0) { int current_kbps = (int)(_rtmp->get_send_bytes() * 8 / elaps); while (current_kbps > play_kbps) { srs_update_system_time(); - elaps = (int)(srs_get_system_time_ms() - starttime); + elaps = (int)(srsu2ms(srs_get_system_time()) - starttime); current_kbps = (int)(_rtmp->get_send_bytes() * 8 / elaps); usleep(100 * 1000); // TODO: FIXME: magic number. } diff --git a/trunk/src/protocol/srs_protocol_kbps.cpp b/trunk/src/protocol/srs_protocol_kbps.cpp index eb7167227..943bad189 100644 --- a/trunk/src/protocol/srs_protocol_kbps.cpp +++ b/trunk/src/protocol/srs_protocol_kbps.cpp @@ -113,7 +113,7 @@ SrsWallClock::~SrsWallClock() int64_t SrsWallClock::time_ms() { - return srs_get_system_time_ms(); + return srsu2ms(srs_get_system_time()); } SrsKbps::SrsKbps(SrsWallClock* c) : is(c), os(c) diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index 811e9d0b6..0779411dc 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -1867,6 +1867,14 @@ VOID TEST(ConfigUnitTest, CheckDefaultValues) EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_dvr_duration("v")); } + if (true) { + EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF)); + EXPECT_EQ(0, conf.get_hls_dispose("")); + + EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{hls{hls_dispose 10;}}")); + EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_hls_dispose("v")); + } + if (true) { srs_utime_t t0 = srs_update_system_time(); srs_usleep(10 * SRS_UTIME_MILLISECONDS); @@ -1874,5 +1882,13 @@ VOID TEST(ConfigUnitTest, CheckDefaultValues) EXPECT_TRUE(t1 - t0 >= 10 * SRS_UTIME_MILLISECONDS); } + + if (true) { + srs_utime_t t0 = srs_get_system_time(); + srs_utime_t t1 = srs_update_system_time(); + + EXPECT_TRUE(t0 > 0); + EXPECT_TRUE(t1 >= t0); + } } diff --git a/trunk/src/utest/srs_utest_kernel.cpp b/trunk/src/utest/srs_utest_kernel.cpp index dea42914b..990754ce1 100644 --- a/trunk/src/utest/srs_utest_kernel.cpp +++ b/trunk/src/utest/srs_utest_kernel.cpp @@ -1482,15 +1482,14 @@ VOID TEST(KernelBufferTest, CoverAll) */ VOID TEST(KernelUtilityTest, UtilityTime) { - int64_t time = srs_get_system_time_ms(); + srs_utime_t time = srs_get_system_time(); EXPECT_TRUE(time > 0); - int64_t time1 = srs_get_system_time_ms(); + srs_utime_t time1 = srs_get_system_time(); EXPECT_EQ(time, time1); - usleep(1000); - srs_update_system_time(); - time1 = srs_get_system_time_ms(); + usleep(1 * SRS_UTIME_MILLISECONDS); + time1 = srs_update_system_time(); EXPECT_TRUE(time1 > time); } @@ -1499,15 +1498,15 @@ VOID TEST(KernelUtilityTest, UtilityTime) */ VOID TEST(KernelUtilityTest, UtilityStartupTime) { - int64_t time = srs_get_system_startup_time_ms(); + srs_utime_t time = srs_get_system_startup_time(); EXPECT_TRUE(time > 0); - int64_t time1 = srs_get_system_startup_time_ms(); + srs_utime_t time1 = srs_get_system_startup_time(); EXPECT_EQ(time, time1); - usleep(1000); + usleep(1 * SRS_UTIME_MILLISECONDS); srs_update_system_time(); - time1 = srs_get_system_startup_time_ms(); + time1 = srs_get_system_startup_time(); EXPECT_EQ(time, time1); } @@ -3182,7 +3181,7 @@ VOID TEST(KernelUtilityTest, CoverTimeUtilityAll) { _srs_system_time_us_cache = 0; _srs_system_time_startup_time = 0; - EXPECT_TRUE(srs_get_system_startup_time_ms() > 0); + EXPECT_TRUE(srs_get_system_startup_time() > 0); _srs_system_time_us_cache -= 300*1000 * 1000 + 1; EXPECT_TRUE(srs_update_system_time() > 0);