diff --git a/trunk/src/app/srs_app_bandwidth.cpp b/trunk/src/app/srs_app_bandwidth.cpp index a490811b7..f0a843bc2 100644 --- a/trunk/src/app/srs_app_bandwidth.cpp +++ b/trunk/src/app/srs_app_bandwidth.cpp @@ -37,17 +37,17 @@ using namespace std; #include #include -#define _SRS_BANDWIDTH_LIMIT_INTERVAL_MS 100 +#define _SRS_BANDWIDTH_LIMIT_INTERVAL 100 * SRS_UTIME_MILLISECONDS // default sample duration, in ms -#define _SRS_BANDWIDTH_SAMPLE_DURATION_MS 3000 +#define _SRS_BANDWIDTH_SAMPLE_DURATION 3000 * SRS_UTIME_MILLISECONDS // wait for a while for flash to got all packets. -#define _SRS_BANDWIDTH_FINAL_WAIT_MS 600 +#define _SRS_BANDWIDTH_FINAL_WAIT 600 * SRS_UTIME_MILLISECONDS SrsBandwidthSample::SrsBandwidthSample() { - duration_ms = _SRS_BANDWIDTH_SAMPLE_DURATION_MS; + duration_ms = _SRS_BANDWIDTH_SAMPLE_DURATION; kbps = interval_ms = actual_duration_ms = bytes = 0; } @@ -223,7 +223,7 @@ srs_error_t SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit) return srs_error_wrap(err, "final"); } - srs_usleep(_SRS_BANDWIDTH_FINAL_WAIT_MS * 1000); + srs_usleep(_SRS_BANDWIDTH_FINAL_WAIT); return err; } @@ -457,7 +457,7 @@ void SrsKbpsLimit::recv_limit() while (_kbps->get_recv_kbps() > _limit_kbps) { _kbps->sample(); - srs_usleep(_SRS_BANDWIDTH_LIMIT_INTERVAL_MS * 1000); + srs_usleep(_SRS_BANDWIDTH_LIMIT_INTERVAL); } } @@ -468,7 +468,7 @@ void SrsKbpsLimit::send_limit() while (_kbps->get_send_kbps() > _limit_kbps) { _kbps->sample(); - srs_usleep(_SRS_BANDWIDTH_LIMIT_INTERVAL_MS * 1000); + srs_usleep(_SRS_BANDWIDTH_LIMIT_INTERVAL); } } diff --git a/trunk/src/app/srs_app_edge.cpp b/trunk/src/app/srs_app_edge.cpp index e9873bc49..ae01b7b49 100644 --- a/trunk/src/app/srs_app_edge.cpp +++ b/trunk/src/app/srs_app_edge.cpp @@ -48,10 +48,10 @@ using namespace std; #include // when edge timeout, retry next. -#define SRS_EDGE_INGESTER_TMMS (5*1000) +#define SRS_EDGE_INGESTER_TMMS (5 * SRS_UTIME_MILLISECONDS) // when edge error, wait for quit -#define SRS_EDGE_FORWARDER_TMMS (150) +#define SRS_EDGE_FORWARDER_TMMS (150 * SRS_UTIME_MILLISECONDS) SrsEdgeUpstream::SrsEdgeUpstream() { @@ -114,7 +114,7 @@ srs_error_t SrsEdgeRtmpUpstream::connect(SrsRequest* r, SrsLbRoundRobin* lb) } srs_freep(sdk); - int64_t cto = SRS_EDGE_INGESTER_TMMS; + int64_t cto = SRS_EDGE_INGESTER_TMMS / SRS_UTIME_MILLISECONDS; int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS; sdk = new SrsSimpleRtmpClient(url, cto, sto); @@ -218,7 +218,7 @@ string SrsEdgeIngester::get_curr_origin() } // when error, edge ingester sleep for a while and retry. -#define SRS_EDGE_INGESTER_CIMS (3*1000) +#define SRS_EDGE_INGESTER_CIMS (3 * SRS_UTIME_MILLISECONDS) srs_error_t SrsEdgeIngester::cycle() { @@ -234,7 +234,7 @@ srs_error_t SrsEdgeIngester::cycle() return srs_error_wrap(err, "edge ingester"); } - srs_usleep(SRS_EDGE_INGESTER_CIMS * 1000); + srs_usleep(SRS_EDGE_INGESTER_CIMS); } return err; @@ -294,7 +294,7 @@ srs_error_t SrsEdgeIngester::ingest() SrsAutoFree(SrsPithyPrint, pprint); // set to larger timeout to read av data from origin. - upstream->set_recv_timeout(SRS_EDGE_INGESTER_TMMS); + upstream->set_recv_timeout(SRS_EDGE_INGESTER_TMMS / SRS_UTIME_MILLISECONDS); while (true) { srs_error_t err = srs_success; @@ -474,7 +474,7 @@ srs_error_t SrsEdgeForwarder::start() // open socket. srs_freep(sdk); - int64_t cto = SRS_EDGE_FORWARDER_TMMS; + int64_t cto = SRS_EDGE_FORWARDER_TMMS / SRS_UTIME_MILLISECONDS; int64_t sto = SRS_CONSTS_RTMP_TMMS; sdk = new SrsSimpleRtmpClient(url, cto, sto); @@ -505,7 +505,7 @@ void SrsEdgeForwarder::stop() } // when error, edge ingester sleep for a while and retry. -#define SRS_EDGE_FORWARDER_CIMS (3*1000) +#define SRS_EDGE_FORWARDER_CIMS (3 * SRS_UTIME_MILLISECONDS) srs_error_t SrsEdgeForwarder::cycle() { @@ -520,7 +520,7 @@ srs_error_t SrsEdgeForwarder::cycle() return srs_error_wrap(err, "thread pull"); } - srs_usleep(SRS_EDGE_FORWARDER_CIMS * 1000); + srs_usleep(SRS_EDGE_FORWARDER_CIMS); } return err; @@ -545,7 +545,7 @@ srs_error_t SrsEdgeForwarder::do_cycle() } if (send_error_code != ERROR_SUCCESS) { - srs_usleep(SRS_EDGE_FORWARDER_TMMS * 1000); + srs_usleep(SRS_EDGE_FORWARDER_TMMS); continue; } diff --git a/trunk/src/app/srs_app_encoder.cpp b/trunk/src/app/srs_app_encoder.cpp index eabe754ec..a1cb485ee 100644 --- a/trunk/src/app/srs_app_encoder.cpp +++ b/trunk/src/app/srs_app_encoder.cpp @@ -87,7 +87,7 @@ void SrsEncoder::on_unpublish() } // when error, encoder sleep for a while and retry. -#define SRS_RTMP_ENCODER_CIMS (3000) +#define SRS_RTMP_ENCODER_CIMS (3000 * SRS_UTIME_MILLISECONDS) srs_error_t SrsEncoder::cycle() { @@ -104,7 +104,7 @@ srs_error_t SrsEncoder::cycle() break; } - srs_usleep(SRS_RTMP_ENCODER_CIMS * 1000); + srs_usleep(SRS_RTMP_ENCODER_CIMS); } // kill ffmpeg when finished and it alive diff --git a/trunk/src/app/srs_app_forward.cpp b/trunk/src/app/srs_app_forward.cpp index 10eb96bb9..c81dc5d19 100755 --- a/trunk/src/app/srs_app_forward.cpp +++ b/trunk/src/app/srs_app_forward.cpp @@ -174,7 +174,7 @@ srs_error_t SrsForwarder::on_video(SrsSharedPtrMessage* shared_video) } // when error, forwarder sleep for a while and retry. -#define SRS_FORWARDER_CIMS (3000) +#define SRS_FORWARDER_CIMS (3000 * SRS_UTIME_MILLISECONDS) srs_error_t SrsForwarder::cycle() { @@ -190,7 +190,7 @@ srs_error_t SrsForwarder::cycle() return srs_error_wrap(err, "forwarder"); } - srs_usleep(SRS_FORWARDER_CIMS * 1000); + srs_usleep(SRS_FORWARDER_CIMS); } return err; @@ -213,7 +213,7 @@ srs_error_t SrsForwarder::do_cycle() } srs_freep(sdk); - int64_t cto = SRS_FORWARDER_CIMS; + int64_t cto = SRS_FORWARDER_CIMS / SRS_UTIME_MILLISECONDS; int64_t sto = SRS_CONSTS_RTMP_TMMS; sdk = new SrsSimpleRtmpClient(url, cto, sto); diff --git a/trunk/src/app/srs_app_http_hooks.cpp b/trunk/src/app/srs_app_http_hooks.cpp index f7ee8473a..5d9a5e8ed 100644 --- a/trunk/src/app/srs_app_http_hooks.cpp +++ b/trunk/src/app/srs_app_http_hooks.cpp @@ -46,7 +46,7 @@ using namespace std; #define SRS_HTTP_BODY_BUFFER (32 * 1024) // the timeout for hls notify, in ms. -#define SRS_HLS_NOTIFY_TMMS (10 * 1000) +#define SRS_HLS_NOTIFY_TMMS (10 * SRS_UTIME_MILLISECONDS) SrsHttpHooks::SrsHttpHooks() { diff --git a/trunk/src/app/srs_app_http_stream.cpp b/trunk/src/app/srs_app_http_stream.cpp index a291a0bd6..df9806636 100755 --- a/trunk/src/app/srs_app_http_stream.cpp +++ b/trunk/src/app/srs_app_http_stream.cpp @@ -23,7 +23,7 @@ #include -#define SRS_STREAM_CACHE_CYCLE_SECONDS 30 +#define SRS_STREAM_CACHE_CYCLE (30 * SRS_UTIME_SECONDS) #include #include @@ -119,7 +119,7 @@ srs_error_t SrsBufferCache::cycle() // TODO: FIXME: support reload. if (fast_cache <= 0) { - srs_usleep(SRS_STREAM_CACHE_CYCLE_SECONDS * 1000 * 1000); + srs_usleep(SRS_STREAM_CACHE_CYCLE); return err; } @@ -157,7 +157,7 @@ srs_error_t SrsBufferCache::cycle() if (count <= 0) { srs_info("http: sleep %dms for no msg", SRS_CONSTS_RTMP_PULSE_TMMS); // directly use sleep, donot use consumer wait. - srs_usleep(SRS_CONSTS_RTMP_PULSE_TMMS * 1000); + srs_usleep(SRS_CONSTS_RTMP_PULSE_TMMS * SRS_UTIME_MILLISECONDS); // ignore when nothing got. continue; @@ -622,7 +622,7 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess if (count <= 0) { // Directly use sleep, donot use consumer wait, because we couldn't awake consumer. - srs_usleep(mw_sleep * 1000); + srs_usleep(mw_sleep * SRS_UTIME_MILLISECONDS); // ignore when nothing got. continue; } diff --git a/trunk/src/app/srs_app_ingest.cpp b/trunk/src/app/srs_app_ingest.cpp index 656b35a66..391613185 100644 --- a/trunk/src/app/srs_app_ingest.cpp +++ b/trunk/src/app/srs_app_ingest.cpp @@ -168,7 +168,7 @@ void SrsIngester::fast_stop() // when error, ingester sleep for a while and retry. // ingest never sleep a long time, for we must start the stream ASAP. -#define SRS_AUTO_INGESTER_CIMS (3000) +#define SRS_AUTO_INGESTER_CIMS (3000 * SRS_UTIME_MILLISECONDS) srs_error_t SrsIngester::cycle() { @@ -184,7 +184,7 @@ srs_error_t SrsIngester::cycle() return srs_error_wrap(err, "ingester"); } - srs_usleep(SRS_AUTO_INGESTER_CIMS * 1000); + srs_usleep(SRS_AUTO_INGESTER_CIMS); } return err; diff --git a/trunk/src/app/srs_app_kafka.cpp b/trunk/src/app/srs_app_kafka.cpp index d192ab4a8..de5974fc6 100644 --- a/trunk/src/app/srs_app_kafka.cpp +++ b/trunk/src/app/srs_app_kafka.cpp @@ -485,7 +485,7 @@ srs_error_t SrsKafkaProducer::on_close(int key) return worker->execute(new SrsKafkaMessage(this, key, obj)); } -#define SRS_KAKFA_CIMS 3000 +#define SRS_KAKFA_CIMS (3000 * SRS_UTIME_MILLISECONDS) srs_error_t SrsKafkaProducer::cycle() { @@ -510,7 +510,7 @@ srs_error_t SrsKafkaProducer::cycle() return srs_error_wrap(err, "kafka cycle"); } - srs_usleep(SRS_KAKFA_CIMS * 1000); + srs_usleep(SRS_KAKFA_CIMS); } return err; diff --git a/trunk/src/app/srs_app_listener.cpp b/trunk/src/app/srs_app_listener.cpp index 1ee437448..d901e6ed9 100755 --- a/trunk/src/app/srs_app_listener.cpp +++ b/trunk/src/app/srs_app_listener.cpp @@ -174,7 +174,7 @@ srs_error_t SrsUdpListener::cycle() } if (SrsUdpPacketRecvCycleMS > 0) { - srs_usleep(SrsUdpPacketRecvCycleMS * 1000); + srs_usleep(SrsUdpPacketRecvCycleMS * SRS_UTIME_MILLISECONDS); } } diff --git a/trunk/src/app/srs_app_ng_exec.cpp b/trunk/src/app/srs_app_ng_exec.cpp index 16393b6c9..585989796 100644 --- a/trunk/src/app/srs_app_ng_exec.cpp +++ b/trunk/src/app/srs_app_ng_exec.cpp @@ -76,7 +76,7 @@ void SrsNgExec::on_unpublish() } // when error, ng-exec sleep for a while and retry. -#define SRS_RTMP_EXEC_CIMS (3000) +#define SRS_RTMP_EXEC_CIMS (3000 * SRS_UTIME_MILLISECONDS) srs_error_t SrsNgExec::cycle() { srs_error_t err = srs_success; @@ -92,7 +92,7 @@ srs_error_t SrsNgExec::cycle() break; } - srs_usleep(SRS_RTMP_EXEC_CIMS * 1000); + srs_usleep(SRS_RTMP_EXEC_CIMS); } std::vector::iterator it; diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index 22c0d7712..512daaa05 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -64,15 +64,15 @@ using namespace std; // the timeout in ms to wait encoder to republish // if timeout, close the connection. -#define SRS_REPUBLISH_SEND_TMMS (3 * 60 * 1000) +#define SRS_REPUBLISH_SEND_TMMS (3 * SRS_UTIME_MINUTES) // if timeout, close the connection. -#define SRS_REPUBLISH_RECV_TMMS (3 * 60 * 1000) +#define SRS_REPUBLISH_RECV_TMMS (3 * SRS_UTIME_MINUTES) // the timeout in ms to wait client data, when client paused // if timeout, close the connection. -#define SRS_PAUSED_SEND_TMMS (3 * 60 * 1000) +#define SRS_PAUSED_SEND_TMMS (3 * SRS_UTIME_MINUTES) // if timeout, close the connection. -#define SRS_PAUSED_RECV_TMMS (3 * 60 * 1000) +#define SRS_PAUSED_RECV_TMMS (3 * SRS_UTIME_MINUTES) // when edge timeout, retry next. #define SRS_EDGE_TOKEN_TRAVERSE_TMMS (3000) diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 96aa8ea5e..647b52c83 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -60,7 +60,7 @@ using namespace std; // the meminfo canbe 6*x, for instance, 6*1=6s, // for performance refine, @see: https://github.com/ossrs/srs/issues/194 // @remark, recomment to 1000ms. -#define SRS_SYS_CYCLE_INTERVAL 1000 +#define SRS_SYS_CYCLE_INTERVAL (1000 * SRS_UTIME_MILLISECONDS) // update time interval: // SRS_SYS_CYCLE_INTERVAL * SRS_SYS_TIME_RESOLUTION_MS_TIMES @@ -910,13 +910,13 @@ srs_error_t SrsServer::do_cycle() } // the interval in config. - int heartbeat_max_resolution = (int)(_srs_config->get_heartbeat_interval() / SRS_SYS_CYCLE_INTERVAL); + int heartbeat_max_resolution = (int)(_srs_config->get_heartbeat_interval() * SRS_UTIME_MILLISECONDS / SRS_SYS_CYCLE_INTERVAL); // dynamic fetch the max. int dynamic_max = srs_max(max, heartbeat_max_resolution); for (int i = 0; i < dynamic_max; i++) { - srs_usleep(SRS_SYS_CYCLE_INTERVAL * 1000); + srs_usleep(SRS_SYS_CYCLE_INTERVAL); // asprocess check. if (asprocess && ::getppid() != ppid) { diff --git a/trunk/src/kernel/srs_kernel_consts.hpp b/trunk/src/kernel/srs_kernel_consts.hpp index 08710690b..15a40aa45 100644 --- a/trunk/src/kernel/srs_kernel_consts.hpp +++ b/trunk/src/kernel/srs_kernel_consts.hpp @@ -226,7 +226,7 @@ #define SRS_CONSTS_HTTP_QUERY_SEP '?' // the default recv timeout. -#define SRS_HTTP_RECV_TMMS (60 * 1000) +#define SRS_HTTP_RECV_TMMS (60 * SRS_UTIME_SECONDS) // 6.1.1 Status Code and Reason Phrase #define SRS_CONSTS_HTTP_Continue 100 diff --git a/trunk/src/main/srs_main_ingest_hls.cpp b/trunk/src/main/srs_main_ingest_hls.cpp index 9fda82968..11f3acace 100644 --- a/trunk/src/main/srs_main_ingest_hls.cpp +++ b/trunk/src/main/srs_main_ingest_hls.cpp @@ -216,7 +216,7 @@ int SrsIngestHlsInput::connect() int64_t now = srs_update_system_time_ms(); if (now < next_connect_time) { srs_trace("input hls wait for %dms", next_connect_time - now); - srs_usleep((next_connect_time - now) * 1000); + srs_usleep((next_connect_time - now) * SRS_UTIME_MILLISECONDS); } // set all ts to dirty. @@ -559,7 +559,7 @@ int SrsIngestHlsInput::fetch_all_ts(bool fresh_m3u8) // only wait for a duration of last piece. if (i == (int)pieces.size() - 1) { - next_connect_time = srs_update_system_time_ms() + (int)tp->duration * 1000; + next_connect_time = srs_update_system_time_ms() + (int)tp->duration * SRS_UTIME_MILLISECONDS; } } diff --git a/trunk/src/utest/srs_utest_app.cpp b/trunk/src/utest/srs_utest_app.cpp index 7a526296a..f7f46730f 100644 --- a/trunk/src/utest/srs_utest_app.cpp +++ b/trunk/src/utest/srs_utest_app.cpp @@ -108,7 +108,7 @@ public: cid = _srs_context->get_id(); while (!quit && (r0 = trd->pull()) == srs_success && err == srs_success) { - srs_usleep(10 * 1000); + srs_usleep(10 * SRS_UTIME_MILLISECONDS); } srs_cond_signal(exited); @@ -297,7 +297,7 @@ VOID TEST(AppCoroutineTest, StartThread) _ST_THREAD_CREATE_PFN ov = _pfn_st_thread_create; _pfn_st_thread_create = (_ST_THREAD_CREATE_PFN)mock_st_thread_create; - + srs_error_t err = sc.start(); _pfn_st_thread_create = ov;