From 3fe338d1c544371857458133efc202dd1fa5bf3f Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 17 Jan 2017 12:25:30 +0800 Subject: [PATCH] for #742, use ms for application clock tbn. --- trunk/src/app/srs_app_async_call.cpp | 6 +- trunk/src/app/srs_app_bandwidth.cpp | 4 +- trunk/src/app/srs_app_caster_flv.cpp | 6 +- trunk/src/app/srs_app_edge.cpp | 37 +++++----- trunk/src/app/srs_app_edge.hpp | 4 +- trunk/src/app/srs_app_encoder.cpp | 4 +- trunk/src/app/srs_app_forward.cpp | 10 +-- trunk/src/app/srs_app_http_api.cpp | 2 +- trunk/src/app/srs_app_http_client.cpp | 20 +++--- trunk/src/app/srs_app_http_client.hpp | 13 ++-- trunk/src/app/srs_app_http_conn.cpp | 2 +- trunk/src/app/srs_app_http_hooks.cpp | 12 ++-- trunk/src/app/srs_app_http_stream.cpp | 12 ++-- trunk/src/app/srs_app_ingest.cpp | 4 +- trunk/src/app/srs_app_kafka.cpp | 6 +- trunk/src/app/srs_app_mpegts_udp.cpp | 6 +- trunk/src/app/srs_app_ng_exec.cpp | 4 +- trunk/src/app/srs_app_recv_thread.cpp | 6 +- trunk/src/app/srs_app_recv_thread.hpp | 5 +- trunk/src/app/srs_app_rtmp_conn.cpp | 38 +++++----- trunk/src/app/srs_app_rtsp.cpp | 6 +- trunk/src/app/srs_app_server.cpp | 1 - trunk/src/app/srs_app_source.cpp | 2 +- trunk/src/app/srs_app_st.cpp | 87 ++++++++++++++-------- trunk/src/app/srs_app_st.hpp | 32 +++++---- trunk/src/app/srs_app_thread.cpp | 8 +-- trunk/src/app/srs_app_thread.hpp | 8 +-- trunk/src/app/srs_app_utility.cpp | 7 +- trunk/src/app/srs_app_utility.hpp | 3 +- trunk/src/kernel/srs_kernel_consts.hpp | 12 ++-- trunk/src/kernel/srs_kernel_utility.cpp | 9 +-- trunk/src/libs/srs_lib_simple_socket.cpp | 91 +++++++++++++----------- trunk/src/libs/srs_lib_simple_socket.hpp | 6 +- trunk/src/libs/srs_librtmp.cpp | 20 +++--- trunk/src/libs/srs_librtmp.hpp | 13 ++-- trunk/src/main/srs_main_ingest_hls.cpp | 6 +- trunk/src/protocol/srs_http_stack.cpp | 82 ++++++++++----------- trunk/src/protocol/srs_protocol_io.hpp | 28 ++++---- trunk/src/protocol/srs_rtmp_stack.cpp | 28 ++++---- trunk/src/protocol/srs_rtmp_stack.hpp | 70 +++--------------- trunk/src/protocol/srs_rtsp_stack.cpp | 88 +++++++++++------------ trunk/src/utest/srs_utest_protocol.cpp | 42 +++++------ trunk/src/utest/srs_utest_protocol.hpp | 22 +++--- 43 files changed, 437 insertions(+), 435 deletions(-) diff --git a/trunk/src/app/srs_app_async_call.cpp b/trunk/src/app/srs_app_async_call.cpp index 48ffd3d9f..fb4ebe67c 100644 --- a/trunk/src/app/srs_app_async_call.cpp +++ b/trunk/src/app/srs_app_async_call.cpp @@ -28,8 +28,8 @@ using namespace std; #include #include -// the sleep interval for http async callback. -#define SRS_AUTO_ASYNC_CALLBACL_SLEEP_US 300000 +// the sleep interval in ms for http async callback. +#define SRS_AUTO_ASYNC_CALLBACL_CIMS 30 ISrsAsyncCallTask::ISrsAsyncCallTask() { @@ -41,7 +41,7 @@ ISrsAsyncCallTask::~ISrsAsyncCallTask() SrsAsyncCallWorker::SrsAsyncCallWorker() { - pthread = new SrsReusableThread("async", this, SRS_AUTO_ASYNC_CALLBACL_SLEEP_US); + pthread = new SrsReusableThread("async", this, SRS_AUTO_ASYNC_CALLBACL_CIMS); wait = st_cond_new(); } diff --git a/trunk/src/app/srs_app_bandwidth.cpp b/trunk/src/app/srs_app_bandwidth.cpp index 2cd57f973..462bfe25f 100644 --- a/trunk/src/app/srs_app_bandwidth.cpp +++ b/trunk/src/app/srs_app_bandwidth.cpp @@ -190,8 +190,8 @@ int SrsBandwidth::do_bandwidth_check(SrsKbpsLimit* limit) SrsBandwidthSample publish_sample; // timeout for a packet. - _rtmp->set_send_timeout(play_sample.duration_ms * 1000 * 2); - _rtmp->set_recv_timeout(publish_sample.duration_ms * 1000 * 2); + _rtmp->set_send_timeout(play_sample.duration_ms * 2); + _rtmp->set_recv_timeout(publish_sample.duration_ms * 2); // start test. srs_update_system_time_ms(); diff --git a/trunk/src/app/srs_app_caster_flv.cpp b/trunk/src/app/srs_app_caster_flv.cpp index 9de9f0908..f2ffe44e9 100644 --- a/trunk/src/app/srs_app_caster_flv.cpp +++ b/trunk/src/app/srs_app_caster_flv.cpp @@ -183,9 +183,9 @@ int SrsDynamicHttpConn::do_proxy(ISrsHttpResponseReader* rr, SrsFlvDecoder* dec) srs_freep(sdk); - int64_t cto = SRS_CONSTS_RTMP_TIMEOUT_US; - int64_t sto = SRS_CONSTS_RTMP_PULSE_TIMEOUT_US; - sdk = new SrsSimpleRtmpClient(output, cto / 1000, sto / 1000); + int64_t cto = SRS_CONSTS_RTMP_TMMS; + int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS; + sdk = new SrsSimpleRtmpClient(output, cto, sto); if ((ret = sdk->connect()) != ERROR_SUCCESS) { srs_error("flv: connect %s failed, cto=%"PRId64", sto=%"PRId64". ret=%d", output.c_str(), cto, sto, ret); diff --git a/trunk/src/app/srs_app_edge.cpp b/trunk/src/app/srs_app_edge.cpp index ba36ab827..f9baa5913 100644 --- a/trunk/src/app/srs_app_edge.cpp +++ b/trunk/src/app/srs_app_edge.cpp @@ -48,19 +48,16 @@ using namespace std; #include // when error, edge ingester sleep for a while and retry. -#define SRS_EDGE_INGESTER_SLEEP_US (int64_t)(3*1000*1000LL) +#define SRS_EDGE_INGESTER_CIMS (3*1000) // when edge timeout, retry next. -#define SRS_EDGE_INGESTER_TIMEOUT_US (int64_t)(5*1000*1000LL) +#define SRS_EDGE_INGESTER_TMMS (5*1000) // when error, edge ingester sleep for a while and retry. -#define SRS_EDGE_FORWARDER_SLEEP_US (int64_t)(3*1000*1000LL) - -// when edge timeout, retry next. -#define SRS_EDGE_FORWARDER_TIMEOUT_US (int64_t)(5*1000*1000LL) +#define SRS_EDGE_FORWARDER_CIMS (3*1000) // when edge error, wait for quit -#define SRS_EDGE_FORWARDER_ERROR_US (int64_t)(50*1000LL) +#define SRS_EDGE_FORWARDER_TMMS (150) SrsEdgeUpstream::SrsEdgeUpstream() { @@ -125,9 +122,9 @@ int SrsEdgeRtmpUpstream::connect(SrsRequest* r, SrsLbRoundRobin* lb) } srs_freep(sdk); - int64_t cto = SRS_EDGE_INGESTER_TIMEOUT_US; - int64_t sto = SRS_CONSTS_RTMP_PULSE_TIMEOUT_US; - sdk = new SrsSimpleRtmpClient(url, cto/1000, sto/1000); + int64_t cto = SRS_EDGE_INGESTER_TMMS; + int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS; + sdk = new SrsSimpleRtmpClient(url, cto, sto); if ((ret = sdk->connect()) != ERROR_SUCCESS) { srs_error("edge pull %s failed, cto=%"PRId64", sto=%"PRId64". ret=%d", url.c_str(), cto, sto, ret); @@ -157,9 +154,9 @@ void SrsEdgeRtmpUpstream::close() srs_freep(sdk); } -void SrsEdgeRtmpUpstream::set_recv_timeout(int64_t timeout) +void SrsEdgeRtmpUpstream::set_recv_timeout(int64_t tm) { - sdk->set_recv_timeout(timeout); + sdk->set_recv_timeout(tm); } void SrsEdgeRtmpUpstream::kbps_sample(const char* label, int64_t age) @@ -175,7 +172,7 @@ SrsEdgeIngester::SrsEdgeIngester() upstream = new SrsEdgeRtmpUpstream(redirect); lb = new SrsLbRoundRobin(); - pthread = new SrsReusableThread2("edge-igs", this, SRS_EDGE_INGESTER_SLEEP_US); + pthread = new SrsReusableThread2("edge-igs", this, SRS_EDGE_INGESTER_CIMS); } SrsEdgeIngester::~SrsEdgeIngester() @@ -274,7 +271,7 @@ int SrsEdgeIngester::ingest() SrsAutoFree(SrsPithyPrint, pprint); // set to larger timeout to read av data from origin. - upstream->set_recv_timeout(SRS_EDGE_INGESTER_TIMEOUT_US); + upstream->set_recv_timeout(SRS_EDGE_INGESTER_TMMS); while (!pthread->interrupted()) { pprint->elapse(); @@ -409,7 +406,7 @@ SrsEdgeForwarder::SrsEdgeForwarder() sdk = NULL; lb = new SrsLbRoundRobin(); - pthread = new SrsReusableThread2("edge-fwr", this, SRS_EDGE_FORWARDER_SLEEP_US); + pthread = new SrsReusableThread2("edge-fwr", this, SRS_EDGE_FORWARDER_CIMS); queue = new SrsMessageQueue(); } @@ -465,9 +462,9 @@ int SrsEdgeForwarder::start() // open socket. srs_freep(sdk); - int64_t cto = SRS_EDGE_FORWARDER_TIMEOUT_US; - int64_t sto = SRS_CONSTS_RTMP_TIMEOUT_US; - sdk = new SrsSimpleRtmpClient(url, cto/1000, sto/1000); + int64_t cto = SRS_EDGE_FORWARDER_TMMS; + int64_t sto = SRS_CONSTS_RTMP_TMMS; + sdk = new SrsSimpleRtmpClient(url, cto, sto); if ((ret = sdk->connect()) != ERROR_SUCCESS) { srs_warn("edge push %s failed, cto=%"PRId64", sto=%"PRId64". ret=%d", url.c_str(), cto, sto, ret); @@ -496,7 +493,7 @@ int SrsEdgeForwarder::cycle() { int ret = ERROR_SUCCESS; - sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US); + sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TMMS); SrsPithyPrint* pprint = SrsPithyPrint::create_edge(); SrsAutoFree(SrsPithyPrint, pprint); @@ -505,7 +502,7 @@ int SrsEdgeForwarder::cycle() while (!pthread->interrupted()) { if (send_error_code != ERROR_SUCCESS) { - st_usleep(SRS_EDGE_FORWARDER_ERROR_US); + st_usleep(SRS_EDGE_FORWARDER_TMMS * 1000); continue; } diff --git a/trunk/src/app/srs_app_edge.hpp b/trunk/src/app/srs_app_edge.hpp index 9def7c7a9..f81935923 100644 --- a/trunk/src/app/srs_app_edge.hpp +++ b/trunk/src/app/srs_app_edge.hpp @@ -90,7 +90,7 @@ public: virtual int decode_message(SrsCommonMessage* msg, SrsPacket** ppacket) = 0; virtual void close() = 0; public: - virtual void set_recv_timeout(int64_t timeout) = 0; + virtual void set_recv_timeout(int64_t tm) = 0; virtual void kbps_sample(const char* label, int64_t age) = 0; }; @@ -111,7 +111,7 @@ public: virtual int decode_message(SrsCommonMessage* msg, SrsPacket** ppacket); virtual void close(); public: - virtual void set_recv_timeout(int64_t timeout); + virtual void set_recv_timeout(int64_t tm); virtual void kbps_sample(const char* label, int64_t age); }; diff --git a/trunk/src/app/srs_app_encoder.cpp b/trunk/src/app/srs_app_encoder.cpp index ed4b44d0e..1bfc28eb6 100644 --- a/trunk/src/app/srs_app_encoder.cpp +++ b/trunk/src/app/srs_app_encoder.cpp @@ -37,14 +37,14 @@ using namespace std; #ifdef SRS_AUTO_TRANSCODE // when error, encoder sleep for a while and retry. -#define SRS_RTMP_ENCODER_SLEEP_US (int64_t)(3*1000*1000LL) +#define SRS_RTMP_ENCODER_CIMS (3000) // for encoder to detect the dead loop static std::vector _transcoded_url; SrsEncoder::SrsEncoder() { - pthread = new SrsReusableThread("encoder", this, SRS_RTMP_ENCODER_SLEEP_US); + pthread = new SrsReusableThread("encoder", this, SRS_RTMP_ENCODER_CIMS); pprint = SrsPithyPrint::create_encoder(); } diff --git a/trunk/src/app/srs_app_forward.cpp b/trunk/src/app/srs_app_forward.cpp index 65b449f45..d132348c6 100755 --- a/trunk/src/app/srs_app_forward.cpp +++ b/trunk/src/app/srs_app_forward.cpp @@ -48,7 +48,7 @@ using namespace std; #include // when error, forwarder sleep for a while and retry. -#define SRS_FORWARDER_SLEEP_US (int64_t)(3*1000*1000LL) +#define SRS_FORWARDER_CIMS (3000) SrsForwarder::SrsForwarder(SrsSource* s) { @@ -58,7 +58,7 @@ SrsForwarder::SrsForwarder(SrsSource* s) sh_video = sh_audio = NULL; sdk = NULL; - pthread = new SrsReusableThread2("forward", this, SRS_FORWARDER_SLEEP_US); + pthread = new SrsReusableThread2("forward", this, SRS_FORWARDER_CIMS); queue = new SrsMessageQueue(); jitter = new SrsRtmpJitter(); } @@ -237,8 +237,8 @@ int SrsForwarder::cycle() } srs_freep(sdk); - int64_t cto = SRS_FORWARDER_SLEEP_US; - int64_t sto = SRS_CONSTS_RTMP_TIMEOUT_US; + int64_t cto = SRS_FORWARDER_CIMS; + int64_t sto = SRS_CONSTS_RTMP_TMMS; sdk = new SrsSimpleRtmpClient(url, cto, sto); if ((ret = sdk->connect()) != ERROR_SUCCESS) { @@ -267,7 +267,7 @@ int SrsForwarder::forward() { int ret = ERROR_SUCCESS; - sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US); + sdk->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TMMS); SrsPithyPrint* pprint = SrsPithyPrint::create_forwarder(); SrsAutoFree(SrsPithyPrint, pprint); diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index e443d463b..72642fccb 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -1365,7 +1365,7 @@ int SrsHttpApi::do_cycle() // set the recv timeout, for some clients never disconnect the connection. // @see https://github.com/ossrs/srs/issues/398 - skt.set_recv_timeout(SRS_HTTP_RECV_TIMEOUT_US); + skt.set_recv_timeout(SRS_HTTP_RECV_TMMS); // initialize the cors, which will proxy to mux. bool crossdomain_enabled = _srs_config->get_http_api_crossdomain(); diff --git a/trunk/src/app/srs_app_http_client.cpp b/trunk/src/app/srs_app_http_client.cpp index 5f6408961..0754bf341 100644 --- a/trunk/src/app/srs_app_http_client.cpp +++ b/trunk/src/app/srs_app_http_client.cpp @@ -43,7 +43,7 @@ SrsHttpClient::SrsHttpClient() transport = NULL; kbps = new SrsKbps(); parser = NULL; - timeout_us = 0; + timeout = SRS_CONSTS_NO_TMMS; port = 0; } @@ -56,7 +56,7 @@ SrsHttpClient::~SrsHttpClient() } // TODO: FIXME: use ms for timeout. -int SrsHttpClient::initialize(string h, int p, int64_t t_us) +int SrsHttpClient::initialize(string h, int p, int64_t tm) { int ret = ERROR_SUCCESS; @@ -71,7 +71,7 @@ int SrsHttpClient::initialize(string h, int p, int64_t t_us) // Always disconnect the transport. host = h; port = p; - timeout_us = t_us; + timeout = tm; disconnect(); // ep used for host in header. @@ -196,9 +196,9 @@ int SrsHttpClient::get(string path, string req, ISrsHttpMessage** ppmsg) return ret; } -void SrsHttpClient::set_recv_timeout(int64_t timeout) +void SrsHttpClient::set_recv_timeout(int64_t tm) { - transport->set_recv_timeout(timeout); + transport->set_recv_timeout(tm); } void SrsHttpClient::kbps_sample(const char* label, int64_t age) @@ -232,17 +232,17 @@ int SrsHttpClient::connect() return ret; } - transport = new SrsTcpClient(host, port, timeout_us / 1000); + transport = new SrsTcpClient(host, port, timeout); if ((ret = transport->connect()) != ERROR_SUCCESS) { disconnect(); - srs_warn("http client failed, server=%s, port=%d, timeout=%"PRId64", ret=%d", host.c_str(), port, timeout_us, ret); + srs_warn("http client failed, server=%s, port=%d, timeout=%"PRId64", ret=%d", host.c_str(), port, timeout, ret); return ret; } srs_info("connect to server success. server=%s, port=%d", host.c_str(), port); - // set the recv/send timeout in us. - transport->set_recv_timeout(timeout_us); - transport->set_send_timeout(timeout_us); + // Set the recv/send timeout in ms. + transport->set_recv_timeout(timeout); + transport->set_send_timeout(timeout); kbps->set_io(transport, transport); diff --git a/trunk/src/app/srs_app_http_client.hpp b/trunk/src/app/srs_app_http_client.hpp index 494d93255..715d24d27 100644 --- a/trunk/src/app/srs_app_http_client.hpp +++ b/trunk/src/app/srs_app_http_client.hpp @@ -43,7 +43,7 @@ class SrsStSocket; class SrsKbps; // the default timeout for http client. -#define SRS_HTTP_CLIENT_TIMEOUT_US (int64_t)(30*1000*1000LL) +#define SRS_HTTP_CLIENT_TMMS (30*1000) /** * The client to GET/POST/PUT/DELETE over HTTP. @@ -64,8 +64,9 @@ private: std::map headers; SrsKbps* kbps; private: - int64_t timeout_us; - // host name or ip. + // The timeout in ms. + int64_t timeout; + // The host name or ip. std::string host; int port; public: @@ -74,9 +75,10 @@ public: public: /** * Initliaze the client, disconnect the transport, renew the HTTP parser. + * @param tm The underlayer TCP transport timeout in ms. * @remark we will set default values in headers, which can be override by set_header. */ - virtual int initialize(std::string h, int p, int64_t t_us = SRS_HTTP_CLIENT_TIMEOUT_US); + virtual int initialize(std::string h, int p, int64_t tm = SRS_HTTP_CLIENT_TMMS); /** * Set HTTP request header in header[k]=v. * @return the HTTP client itself. @@ -99,8 +101,9 @@ public: * @remark user must free the ppmsg if not NULL. */ virtual int get(std::string path, std::string req, ISrsHttpMessage** ppmsg); +private: + virtual void set_recv_timeout(int64_t tm); public: - virtual void set_recv_timeout(int64_t timeout); virtual void kbps_sample(const char* label, int64_t age); private: virtual void disconnect(); diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp index 997d642ce..8af239da0 100644 --- a/trunk/src/app/srs_app_http_conn.cpp +++ b/trunk/src/app/srs_app_http_conn.cpp @@ -1137,7 +1137,7 @@ int SrsHttpConn::do_cycle() // set the recv timeout, for some clients never disconnect the connection. // @see https://github.com/ossrs/srs/issues/398 - skt->set_recv_timeout(SRS_HTTP_RECV_TIMEOUT_US); + skt->set_recv_timeout(SRS_HTTP_RECV_TMMS); SrsRequest* last_req = NULL; SrsAutoFree(SrsRequest, last_req); diff --git a/trunk/src/app/srs_app_http_hooks.cpp b/trunk/src/app/srs_app_http_hooks.cpp index 6f7f0b1b0..9889ef3a5 100644 --- a/trunk/src/app/srs_app_http_hooks.cpp +++ b/trunk/src/app/srs_app_http_hooks.cpp @@ -43,12 +43,12 @@ using namespace std; #define SRS_HTTP_RESPONSE_OK SRS_XSTR(ERROR_SUCCESS) -#define SRS_HTTP_HEADER_BUFFER 1024 -#define SRS_HTTP_READ_BUFFER 4096 -#define SRS_HTTP_BODY_BUFFER 32 * 1024 +#define SRS_HTTP_HEADER_BUFFER 1024 +#define SRS_HTTP_READ_BUFFER 4096 +#define SRS_HTTP_BODY_BUFFER (32 * 1024) -// the timeout for hls notify, in us. -#define SRS_HLS_NOTIFY_TIMEOUT_US (int64_t)(10*1000*1000LL) +// the timeout for hls notify, in ms. +#define SRS_HLS_NOTIFY_TMMS (10 * 1000) SrsHttpHooks::SrsHttpHooks() { @@ -383,7 +383,7 @@ int SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* req, std:: } SrsHttpClient http; - if ((ret = http.initialize(uri.get_host(), uri.get_port(), SRS_HLS_NOTIFY_TIMEOUT_US)) != ERROR_SUCCESS) { + if ((ret = http.initialize(uri.get_host(), uri.get_port(), SRS_HLS_NOTIFY_TMMS)) != ERROR_SUCCESS) { return ret; } diff --git a/trunk/src/app/srs_app_http_stream.cpp b/trunk/src/app/srs_app_http_stream.cpp index 37d32a8d2..51f17b26d 100755 --- a/trunk/src/app/srs_app_http_stream.cpp +++ b/trunk/src/app/srs_app_http_stream.cpp @@ -155,9 +155,9 @@ int SrsBufferCache::cycle() } if (count <= 0) { - srs_info("http: sleep %dms for no msg", SRS_CONSTS_RTMP_PULSE_TIMEOUT_US); + srs_info("http: sleep %dms for no msg", SRS_CONSTS_RTMP_PULSE_TMMS); // directly use sleep, donot use consumer wait. - st_usleep(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US); + st_usleep(SRS_CONSTS_RTMP_PULSE_TMMS * 1000); // ignore when nothing got. continue; @@ -165,7 +165,7 @@ int SrsBufferCache::cycle() if (pprint->can_print()) { srs_trace("-> "SRS_CONSTS_LOG_HTTP_STREAM_CACHE" http: got %d msgs, age=%d, min=%d, mw=%d", - count, pprint->age(), SRS_PERF_MW_MIN_MSGS, SRS_CONSTS_RTMP_PULSE_TIMEOUT_US / 1000); + count, pprint->age(), SRS_PERF_MW_MIN_MSGS, SRS_CONSTS_RTMP_PULSE_TMMS); } // free the messages. @@ -557,9 +557,9 @@ int SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) } if (count <= 0) { - srs_info("http: sleep %dms for no msg", SRS_CONSTS_RTMP_PULSE_TIMEOUT_US); + srs_info("http: sleep %dms for no msg", SRS_CONSTS_RTMP_PULSE_TMMS); // directly use sleep, donot use consumer wait. - st_usleep(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US); + st_usleep(SRS_CONSTS_RTMP_PULSE_TMMS); // ignore when nothing got. continue; @@ -567,7 +567,7 @@ int SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) if (pprint->can_print()) { srs_info("-> "SRS_CONSTS_LOG_HTTP_STREAM" http: got %d msgs, age=%d, min=%d, mw=%d", - count, pprint->age(), SRS_PERF_MW_MIN_MSGS, SRS_CONSTS_RTMP_PULSE_TIMEOUT_US / 1000); + count, pprint->age(), SRS_PERF_MW_MIN_MSGS, SRS_CONSTS_RTMP_PULSE_TMMS); } // sendout all messages. diff --git a/trunk/src/app/srs_app_ingest.cpp b/trunk/src/app/srs_app_ingest.cpp index ce0cb28d7..cca6d1414 100644 --- a/trunk/src/app/srs_app_ingest.cpp +++ b/trunk/src/app/srs_app_ingest.cpp @@ -39,7 +39,7 @@ using namespace std; // 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_SLEEP_US (int64_t)(3*1000*1000LL) +#define SRS_AUTO_INGESTER_CIMS (3000) SrsIngesterFFMPEG::SrsIngesterFFMPEG() { @@ -109,7 +109,7 @@ SrsIngester::SrsIngester() expired = false; - pthread = new SrsReusableThread("ingest", this, SRS_AUTO_INGESTER_SLEEP_US); + pthread = new SrsReusableThread("ingest", this, SRS_AUTO_INGESTER_CIMS); pprint = SrsPithyPrint::create_ingester(); } diff --git a/trunk/src/app/srs_app_kafka.cpp b/trunk/src/app/srs_app_kafka.cpp index d5e303836..e99133306 100644 --- a/trunk/src/app/srs_app_kafka.cpp +++ b/trunk/src/app/srs_app_kafka.cpp @@ -40,7 +40,7 @@ using namespace std; #ifdef SRS_AUTO_KAFKA -#define SRS_KAKFA_CYCLE_INTERVAL_MS 3000 +#define SRS_KAKFA_CIMS 3000 #define SRS_KAFKA_PRODUCER_TIMEOUT 30000 #define SRS_KAFKA_PRODUCER_AGGREGATE_SIZE 1 @@ -366,7 +366,7 @@ SrsKafkaProducer::SrsKafkaProducer() metadata_expired = st_cond_new(); lock = st_mutex_new(); - pthread = new SrsReusableThread("kafka", this, SRS_KAKFA_CYCLE_INTERVAL_MS * 1000); + pthread = new SrsReusableThread("kafka", this, SRS_KAKFA_CIMS); worker = new SrsAsyncCallWorker(); cache = new SrsKafkaCache(); @@ -585,7 +585,7 @@ int SrsKafkaProducer::request_metadata() senabled.c_str(), sbrokers.c_str(), lb->current(), server.c_str(), port, topic.c_str()); } - SrsTcpClient* transport = new SrsTcpClient(server, port, SRS_CONSTS_KAFKA_TIMEOUT_US / 1000); + SrsTcpClient* transport = new SrsTcpClient(server, port, SRS_CONSTS_KAFKA_TMMS); SrsAutoFree(SrsTcpClient, transport); SrsKafkaClient* kafka = new SrsKafkaClient(transport); diff --git a/trunk/src/app/srs_app_mpegts_udp.cpp b/trunk/src/app/srs_app_mpegts_udp.cpp index 1b3f84582..c1e312379 100644 --- a/trunk/src/app/srs_app_mpegts_udp.cpp +++ b/trunk/src/app/srs_app_mpegts_udp.cpp @@ -616,9 +616,9 @@ int SrsMpegtsOverUdp::connect() return ret; } - int64_t cto = SRS_CONSTS_RTMP_TIMEOUT_US; - int64_t sto = SRS_CONSTS_RTMP_PULSE_TIMEOUT_US; - sdk = new SrsSimpleRtmpClient(output, cto/1000, sto/1000); + int64_t cto = SRS_CONSTS_RTMP_TMMS; + int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS; + sdk = new SrsSimpleRtmpClient(output, cto, sto); if ((ret = sdk->connect()) != ERROR_SUCCESS) { close(); diff --git a/trunk/src/app/srs_app_ng_exec.cpp b/trunk/src/app/srs_app_ng_exec.cpp index c2c7a7741..d04ec762c 100644 --- a/trunk/src/app/srs_app_ng_exec.cpp +++ b/trunk/src/app/srs_app_ng_exec.cpp @@ -37,11 +37,11 @@ using namespace std; #include // when error, ng-exec sleep for a while and retry. -#define SRS_RTMP_EXEC_SLEEP_US (int64_t)(3*1000*1000LL) +#define SRS_RTMP_EXEC_CIMS (3000) SrsNgExec::SrsNgExec() { - pthread = new SrsReusableThread("encoder", this, SRS_RTMP_EXEC_SLEEP_US); + pthread = new SrsReusableThread("encoder", this, SRS_RTMP_EXEC_CIMS); pprint = SrsPithyPrint::create_exec(); } diff --git a/trunk/src/app/srs_app_recv_thread.cpp b/trunk/src/app/srs_app_recv_thread.cpp index 7ae8b9dd6..df5eb5625 100644 --- a/trunk/src/app/srs_app_recv_thread.cpp +++ b/trunk/src/app/srs_app_recv_thread.cpp @@ -45,9 +45,9 @@ ISrsMessageHandler::~ISrsMessageHandler() { } -SrsRecvThread::SrsRecvThread(ISrsMessageHandler* msg_handler, SrsRtmpServer* rtmp_sdk, int timeout_ms) +SrsRecvThread::SrsRecvThread(ISrsMessageHandler* msg_handler, SrsRtmpServer* rtmp_sdk, int tm) { - timeout = timeout_ms; + timeout = tm; handler = msg_handler; rtmp = rtmp_sdk; trd = new SrsReusableThread2("recv", this); @@ -126,7 +126,7 @@ void SrsRecvThread::on_thread_start() // to use isolate thread to recv, can improve about 33% performance. // @see https://github.com/ossrs/srs/issues/194 // @see: https://github.com/ossrs/srs/issues/217 - rtmp->set_recv_timeout(ST_UTIME_NO_TIMEOUT); + rtmp->set_recv_timeout(SRS_CONSTS_NO_TMMS); handler->on_thread_start(); } diff --git a/trunk/src/app/srs_app_recv_thread.hpp b/trunk/src/app/srs_app_recv_thread.hpp index 12dae5c25..2f713c4f7 100644 --- a/trunk/src/app/srs_app_recv_thread.hpp +++ b/trunk/src/app/srs_app_recv_thread.hpp @@ -86,9 +86,12 @@ protected: SrsReusableThread2* trd; ISrsMessageHandler* handler; SrsRtmpServer* rtmp; + // The recv timeout in ms. int timeout; public: - SrsRecvThread(ISrsMessageHandler* msg_handler, SrsRtmpServer* rtmp_sdk, int timeout_ms); + // Constructor. + // @param tm The receive timeout in ms. + SrsRecvThread(ISrsMessageHandler* msg_handler, SrsRtmpServer* rtmp_sdk, int tm); virtual ~SrsRecvThread(); public: virtual int cid(); diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index 10da46f86..2cea530cd 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -60,22 +60,22 @@ using namespace std; // when stream is busy, for example, streaming is already // publishing, when a new client to request to publish, // sleep a while and close the connection. -#define SRS_STREAM_BUSY_SLEEP_US (int64_t)(3*1000*1000LL) +#define SRS_STREAM_BUSY_CIMS (3000) -// the timeout to wait encoder to republish +// the timeout in ms to wait encoder to republish // if timeout, close the connection. -#define SRS_REPUBLISH_SEND_TIMEOUT_US (int64_t)(3*60*1000*1000LL) +#define SRS_REPUBLISH_SEND_TMMS (3 * 60 * 1000) // if timeout, close the connection. -#define SRS_REPUBLISH_RECV_TIMEOUT_US (int64_t)(3*60*1000*1000LL) +#define SRS_REPUBLISH_RECV_TMMS (3 * 60 * 1000) -// the timeout to wait client data, when client paused +// the timeout in ms to wait client data, when client paused // if timeout, close the connection. -#define SRS_PAUSED_SEND_TIMEOUT_US (int64_t)(30*60*1000*1000LL) +#define SRS_PAUSED_SEND_TMMS (3 * 60 * 1000) // if timeout, close the connection. -#define SRS_PAUSED_RECV_TIMEOUT_US (int64_t)(30*60*1000*1000LL) +#define SRS_PAUSED_RECV_TMMS (3 * 60 * 1000) // when edge timeout, retry next. -#define SRS_EDGE_TOKEN_TRAVERSE_TIMEOUT_US (int64_t)(3*1000*1000LL) +#define SRS_EDGE_TOKEN_TRAVERSE_TMMS (3000) SrsSimpleRtmpClient::SrsSimpleRtmpClient(string u, int64_t ctm, int64_t stm) { @@ -348,8 +348,8 @@ int SrsRtmpConn::do_cycle() } #endif - rtmp->set_recv_timeout(SRS_CONSTS_RTMP_TIMEOUT_US); - rtmp->set_send_timeout(SRS_CONSTS_RTMP_TIMEOUT_US); + rtmp->set_recv_timeout(SRS_CONSTS_RTMP_TMMS); + rtmp->set_send_timeout(SRS_CONSTS_RTMP_TMMS); if ((ret = rtmp->handshake()) != ERROR_SUCCESS) { srs_error("rtmp handshake failed. ret=%d", ret); @@ -634,8 +634,8 @@ int SrsRtmpConn::service_cycle() // for republish, continue service if (ret == ERROR_CONTROL_REPUBLISH) { // set timeout to a larger value, wait for encoder to republish. - rtmp->set_send_timeout(SRS_REPUBLISH_RECV_TIMEOUT_US); - rtmp->set_recv_timeout(SRS_REPUBLISH_SEND_TIMEOUT_US); + rtmp->set_send_timeout(SRS_REPUBLISH_RECV_TMMS); + rtmp->set_recv_timeout(SRS_REPUBLISH_SEND_TMMS); srs_trace("control message(unpublish) accept, retry stream service."); continue; @@ -647,8 +647,8 @@ int SrsRtmpConn::service_cycle() // TODO: FIXME: use ping message to anti-death of socket. // @see: https://github.com/ossrs/srs/issues/39 // set timeout to a larger value, for user paused. - rtmp->set_recv_timeout(SRS_PAUSED_RECV_TIMEOUT_US); - rtmp->set_send_timeout(SRS_PAUSED_SEND_TIMEOUT_US); + rtmp->set_recv_timeout(SRS_PAUSED_RECV_TMMS); + rtmp->set_send_timeout(SRS_PAUSED_SEND_TMMS); srs_trace("control message(close) accept, retry stream service."); continue; @@ -685,8 +685,8 @@ int SrsRtmpConn::stream_service_cycle() srs_info("security check ok"); // client is identified, set the timeout to service timeout. - rtmp->set_recv_timeout(SRS_CONSTS_RTMP_TIMEOUT_US); - rtmp->set_send_timeout(SRS_CONSTS_RTMP_TIMEOUT_US); + rtmp->set_recv_timeout(SRS_CONSTS_RTMP_TMMS); + rtmp->set_send_timeout(SRS_CONSTS_RTMP_TMMS); // find a source to serve. SrsSource* source = NULL; @@ -1465,7 +1465,7 @@ int SrsRtmpConn::check_edge_token_traverse_auth() int port = SRS_CONSTS_RTMP_DEFAULT_PORT; srs_parse_hostport(hostport, server, port); - SrsTcpClient* transport = new SrsTcpClient(server, port, SRS_EDGE_TOKEN_TRAVERSE_TIMEOUT_US / 1000); + SrsTcpClient* transport = new SrsTcpClient(server, port, SRS_EDGE_TOKEN_TRAVERSE_TMMS); SrsAutoFree(SrsTcpClient, transport); if ((ret = transport->connect()) != ERROR_SUCCESS) { @@ -1490,8 +1490,8 @@ int SrsRtmpConn::do_token_traverse_auth(SrsRtmpClient* client) srs_assert(client); - client->set_recv_timeout(SRS_CONSTS_RTMP_TIMEOUT_US); - client->set_send_timeout(SRS_CONSTS_RTMP_TIMEOUT_US); + client->set_recv_timeout(SRS_CONSTS_RTMP_TMMS); + client->set_send_timeout(SRS_CONSTS_RTMP_TMMS); if ((ret = client->handshake()) != ERROR_SUCCESS) { srs_error("handshake with server failed. ret=%d", ret); diff --git a/trunk/src/app/srs_app_rtsp.cpp b/trunk/src/app/srs_app_rtsp.cpp index 731d688f6..91a2f2640 100644 --- a/trunk/src/app/srs_app_rtsp.cpp +++ b/trunk/src/app/srs_app_rtsp.cpp @@ -669,9 +669,9 @@ int SrsRtspConn::connect() } // connect host. - int64_t cto = SRS_CONSTS_RTMP_TIMEOUT_US; - int64_t sto = SRS_CONSTS_RTMP_PULSE_TIMEOUT_US; - sdk = new SrsSimpleRtmpClient(url, cto/1000, sto/1000); + int64_t cto = SRS_CONSTS_RTMP_TMMS; + int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS; + sdk = new SrsSimpleRtmpClient(url, cto, sto); if ((ret = sdk->connect()) != ERROR_SUCCESS) { close(); diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index d578f9971..f26a061f6 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -62,7 +62,6 @@ using namespace std; // 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 1 // update rusage interval: diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index 0b7d4256b..fdbde22c4 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -538,7 +538,7 @@ int SrsConsumer::dump_packets(SrsMessageArray* msgs, int& count) void SrsConsumer::wait(int nb_msgs, int duration) { if (paused) { - st_usleep(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US); + st_usleep(SRS_CONSTS_RTMP_PULSE_TMMS); return; } diff --git a/trunk/src/app/srs_app_st.cpp b/trunk/src/app/srs_app_st.cpp index a3f093510..5c03bdf83 100755 --- a/trunk/src/app/srs_app_st.cpp +++ b/trunk/src/app/srs_app_st.cpp @@ -61,11 +61,11 @@ namespace internal { } - SrsThread::SrsThread(const char* name, ISrsThreadHandler* thread_handler, int64_t interval_us, bool joinable) + SrsThread::SrsThread(const char* name, ISrsThreadHandler* thread_handler, int64_t ims, bool joinable) { _name = name; handler = thread_handler; - cycle_interval_us = interval_us; + cims = ims; tid = NULL; loop = false; @@ -231,10 +231,11 @@ namespace internal break; } + // Should never use no timeout, just ignore it. // to improve performance, donot sleep when interval is zero. // @see: https://github.com/ossrs/srs/issues/237 - if (cycle_interval_us != 0) { - st_usleep(cycle_interval_us); + if (cims != 0 && cims != SRS_CONSTS_NO_TMMS) { + st_usleep(cims * 1000); } } @@ -268,54 +269,60 @@ namespace internal SrsStSocket::SrsStSocket(st_netfd_t client_stfd) { stfd = client_stfd; - send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT; - recv_bytes = send_bytes = 0; + stm = rtm = SRS_CONSTS_NO_TMMS; + rbytes = sbytes = 0; } SrsStSocket::~SrsStSocket() { } -bool SrsStSocket::is_never_timeout(int64_t timeout_us) +bool SrsStSocket::is_never_timeout(int64_t tm) { - return timeout_us == (int64_t)ST_UTIME_NO_TIMEOUT; + return tm == SRS_CONSTS_NO_TMMS; } -void SrsStSocket::set_recv_timeout(int64_t timeout_us) +void SrsStSocket::set_recv_timeout(int64_t tm) { - recv_timeout = timeout_us; + rtm = tm; } int64_t SrsStSocket::get_recv_timeout() { - return recv_timeout; + return rtm; } -void SrsStSocket::set_send_timeout(int64_t timeout_us) +void SrsStSocket::set_send_timeout(int64_t tm) { - send_timeout = timeout_us; + stm = tm; } int64_t SrsStSocket::get_send_timeout() { - return send_timeout; + return stm; } int64_t SrsStSocket::get_recv_bytes() { - return recv_bytes; + return rbytes; } int64_t SrsStSocket::get_send_bytes() { - return send_bytes; + return sbytes; } int SrsStSocket::read(void* buf, size_t size, ssize_t* nread) { int ret = ERROR_SUCCESS; - ssize_t nb_read = st_read(stfd, buf, size, recv_timeout); + ssize_t nb_read; + if (rtm == SRS_CONSTS_NO_TMMS) { + nb_read = st_read(stfd, buf, size, ST_UTIME_NO_TIMEOUT); + } else { + nb_read = st_read(stfd, buf, size, rtm); + } + if (nread) { *nread = nb_read; } @@ -336,7 +343,7 @@ int SrsStSocket::read(void* buf, size_t size, ssize_t* nread) return ERROR_SOCKET_READ; } - recv_bytes += nb_read; + rbytes += nb_read; return ret; } @@ -345,7 +352,13 @@ int SrsStSocket::read_fully(void* buf, size_t size, ssize_t* nread) { int ret = ERROR_SUCCESS; - ssize_t nb_read = st_read_fully(stfd, buf, size, recv_timeout); + ssize_t nb_read; + if (rtm == SRS_CONSTS_NO_TMMS) { + nb_read = st_read_fully(stfd, buf, size, ST_UTIME_NO_TIMEOUT); + } else { + nb_read = st_read_fully(stfd, buf, size, rtm); + } + if (nread) { *nread = nb_read; } @@ -366,7 +379,7 @@ int SrsStSocket::read_fully(void* buf, size_t size, ssize_t* nread) return ERROR_SOCKET_READ_FULLY; } - recv_bytes += nb_read; + rbytes += nb_read; return ret; } @@ -375,7 +388,13 @@ int SrsStSocket::write(void* buf, size_t size, ssize_t* nwrite) { int ret = ERROR_SUCCESS; - ssize_t nb_write = st_write(stfd, buf, size, send_timeout); + ssize_t nb_write; + if (stm == SRS_CONSTS_NO_TMMS) { + nb_write = st_write(stfd, buf, size, ST_UTIME_NO_TIMEOUT); + } else { + nb_write = st_write(stfd, buf, size, stm); + } + if (nwrite) { *nwrite = nb_write; } @@ -391,7 +410,7 @@ int SrsStSocket::write(void* buf, size_t size, ssize_t* nwrite) return ERROR_SOCKET_WRITE; } - send_bytes += nb_write; + sbytes += nb_write; return ret; } @@ -400,7 +419,13 @@ int SrsStSocket::writev(const iovec *iov, int iov_size, ssize_t* nwrite) { int ret = ERROR_SUCCESS; - ssize_t nb_write = st_writev(stfd, iov, iov_size, send_timeout); + ssize_t nb_write; + if (stm == SRS_CONSTS_NO_TMMS) { + nb_write = st_writev(stfd, iov, iov_size, ST_UTIME_NO_TIMEOUT); + } else { + nb_write = st_writev(stfd, iov, iov_size, stm); + } + if (nwrite) { *nwrite = nb_write; } @@ -416,7 +441,7 @@ int SrsStSocket::writev(const iovec *iov, int iov_size, ssize_t* nwrite) return ERROR_SOCKET_WRITE; } - send_bytes += nb_write; + sbytes += nb_write; return ret; } @@ -443,7 +468,7 @@ int SrsTcpClient::connect() close(); srs_assert(stfd == NULL); - if ((ret = srs_socket_connect(host, port, timeout * 1000, &stfd)) != ERROR_SUCCESS) { + if ((ret = srs_socket_connect(host, port, timeout, &stfd)) != ERROR_SUCCESS) { srs_error("connect tcp://%s:%d failed, to=%"PRId64"ms. ret=%d", host.c_str(), port, timeout, ret); return ret; } @@ -465,14 +490,14 @@ void SrsTcpClient::close() srs_close_stfd(stfd); } -bool SrsTcpClient::is_never_timeout(int64_t timeout_us) +bool SrsTcpClient::is_never_timeout(int64_t tm) { - return io->is_never_timeout(timeout_us); + return io->is_never_timeout(tm); } -void SrsTcpClient::set_recv_timeout(int64_t timeout_us) +void SrsTcpClient::set_recv_timeout(int64_t tm) { - io->set_recv_timeout(timeout_us); + io->set_recv_timeout(tm); } int64_t SrsTcpClient::get_recv_timeout() @@ -480,9 +505,9 @@ int64_t SrsTcpClient::get_recv_timeout() return io->get_recv_timeout(); } -void SrsTcpClient::set_send_timeout(int64_t timeout_us) +void SrsTcpClient::set_send_timeout(int64_t tm) { - io->set_send_timeout(timeout_us); + io->set_send_timeout(tm); } int64_t SrsTcpClient::get_send_timeout() diff --git a/trunk/src/app/srs_app_st.hpp b/trunk/src/app/srs_app_st.hpp index 53ebeaa2a..606a6d947 100644 --- a/trunk/src/app/srs_app_st.hpp +++ b/trunk/src/app/srs_app_st.hpp @@ -110,13 +110,14 @@ namespace internal bool disposed; private: ISrsThreadHandler* handler; - int64_t cycle_interval_us; + // The cycle interval in ms. + int64_t cims; public: /** * initialize the thread. * @param name, human readable name for st debug. * @param thread_handler, the cycle handler for the thread. - * @param interval_us, the sleep interval when cycle finished. + * @param ims, the sleep interval in ms when cycle finished. * @param joinable, if joinable, other thread must stop the thread. * @remark if joinable, thread never quit itself, or memory leak. * @see: https://github.com/ossrs/srs/issues/78 @@ -126,7 +127,7 @@ namespace internal * TODO: FIXME: maybe all thread must be reap by others threads, * @see: https://github.com/ossrs/srs/issues/77 */ - SrsThread(const char* name, ISrsThreadHandler* thread_handler, int64_t interval_us, bool joinable); + SrsThread(const char* name, ISrsThreadHandler* thread_handler, int64_t ims, bool joinable); virtual ~SrsThread(); public: /** @@ -175,19 +176,23 @@ namespace internal class SrsStSocket : public ISrsProtocolReaderWriter { private: - int64_t recv_timeout; - int64_t send_timeout; - int64_t recv_bytes; - int64_t send_bytes; + // The recv/send timeout in ms. + // @remark Use SRS_CONSTS_NO_TMMS for never timeout in ms. + int64_t rtm; + int64_t stm; + // The recv/send data in bytes + int64_t rbytes; + int64_t sbytes; + // The underlayer st fd. st_netfd_t stfd; public: SrsStSocket(st_netfd_t client_stfd); virtual ~SrsStSocket(); public: - virtual bool is_never_timeout(int64_t timeout_us); - virtual void set_recv_timeout(int64_t timeout_us); + virtual bool is_never_timeout(int64_t tm); + virtual void set_recv_timeout(int64_t tm); virtual int64_t get_recv_timeout(); - virtual void set_send_timeout(int64_t timeout_us); + virtual void set_send_timeout(int64_t tm); virtual int64_t get_send_timeout(); virtual int64_t get_recv_bytes(); virtual int64_t get_send_bytes(); @@ -221,6 +226,7 @@ private: private: std::string host; int port; + // The timeout in ms. int64_t timeout; public: /** @@ -244,10 +250,10 @@ public: virtual void close(); // interface ISrsProtocolReaderWriter public: - virtual bool is_never_timeout(int64_t timeout_us); - virtual void set_recv_timeout(int64_t timeout_us); + virtual bool is_never_timeout(int64_t tm); + virtual void set_recv_timeout(int64_t tm); virtual int64_t get_recv_timeout(); - virtual void set_send_timeout(int64_t timeout_us); + virtual void set_send_timeout(int64_t tm); virtual int64_t get_send_timeout(); virtual int64_t get_recv_bytes(); virtual int64_t get_send_bytes(); diff --git a/trunk/src/app/srs_app_thread.cpp b/trunk/src/app/srs_app_thread.cpp index f950da9ab..da36c71df 100755 --- a/trunk/src/app/srs_app_thread.cpp +++ b/trunk/src/app/srs_app_thread.cpp @@ -190,10 +190,10 @@ void ISrsReusableThreadHandler::on_thread_stop() { } -SrsReusableThread::SrsReusableThread(const char* n, ISrsReusableThreadHandler* h, int64_t interval_us) +SrsReusableThread::SrsReusableThread(const char* n, ISrsReusableThreadHandler* h, int64_t cims) { handler = h; - pthread = new internal::SrsThread(n, this, interval_us, true); + pthread = new internal::SrsThread(n, this, cims, true); } SrsReusableThread::~SrsReusableThread() @@ -273,10 +273,10 @@ void ISrsReusableThread2Handler::on_thread_stop() { } -SrsReusableThread2::SrsReusableThread2(const char* n, ISrsReusableThread2Handler* h, int64_t interval_us) +SrsReusableThread2::SrsReusableThread2(const char* n, ISrsReusableThread2Handler* h, int64_t cims) { handler = h; - pthread = new internal::SrsThread(n, this, interval_us, true); + pthread = new internal::SrsThread(n, this, cims, true); } SrsReusableThread2::~SrsReusableThread2() diff --git a/trunk/src/app/srs_app_thread.hpp b/trunk/src/app/srs_app_thread.hpp index 04487071f..e2b6e0bd9 100644 --- a/trunk/src/app/srs_app_thread.hpp +++ b/trunk/src/app/srs_app_thread.hpp @@ -162,7 +162,7 @@ public: * 2. must manually stop the thread when started it. * for example: * class SrsIngester : public ISrsReusableThreadHandler { - * public: SrsIngester() { pthread = new SrsReusableThread("ingest", this, SRS_AUTO_INGESTER_SLEEP_US); } + * public: SrsIngester() { pthread = new SrsReusableThread("ingest", this, SRS_AUTO_INGESTER_CIMS); } * public: virtual int start() { return pthread->start(); } * public: virtual void stop() { pthread->stop(); } * public: virtual int cycle() { @@ -198,7 +198,7 @@ private: internal::SrsThread* pthread; ISrsReusableThreadHandler* handler; public: - SrsReusableThread(const char* n, ISrsReusableThreadHandler* h, int64_t interval_us = 0); + SrsReusableThread(const char* n, ISrsReusableThreadHandler* h, int64_t cims = 0); virtual ~SrsReusableThread(); public: /** @@ -244,7 +244,7 @@ public: * 2. must manually stop the thread when started it. * for example: * class SrsIngester : public ISrsReusableThreadHandler { - * public: SrsIngester() { pthread = new SrsReusableThread("ingest", this, SRS_AUTO_INGESTER_SLEEP_US); } + * public: SrsIngester() { pthread = new SrsReusableThread("ingest", this, SRS_AUTO_INGESTER_CIMS); } * public: virtual int start() { return pthread->start(); } * public: virtual void stop() { pthread->stop(); } * public: virtual int cycle() { @@ -287,7 +287,7 @@ private: internal::SrsThread* pthread; ISrsReusableThread2Handler* handler; public: - SrsReusableThread2(const char* n, ISrsReusableThread2Handler* h, int64_t interval_us = 0); + SrsReusableThread2(const char* n, ISrsReusableThread2Handler* h, int64_t cims = 0); virtual ~SrsReusableThread2(); public: /** diff --git a/trunk/src/app/srs_app_utility.cpp b/trunk/src/app/srs_app_utility.cpp index 22f0e3930..51dacc9f5 100644 --- a/trunk/src/app/srs_app_utility.cpp +++ b/trunk/src/app/srs_app_utility.cpp @@ -53,10 +53,15 @@ using namespace std; // the longest time to wait for a process to quit. #define SRS_PROCESS_QUIT_TIMEOUT_MS 1000 -int srs_socket_connect(string server, int port, int64_t timeout, st_netfd_t* pstfd) +int srs_socket_connect(string server, int port, int64_t tm, st_netfd_t* pstfd) { int ret = ERROR_SUCCESS; + st_utime_t timeout = ST_UTIME_NO_TIMEOUT; + if (tm != SRS_CONSTS_NO_TMMS) { + timeout = (st_utime_t)(tm * 1000); + } + *pstfd = NULL; st_netfd_t stfd = NULL; sockaddr_in addr; diff --git a/trunk/src/app/srs_app_utility.hpp b/trunk/src/app/srs_app_utility.hpp index 48ccb62bb..6903dd789 100644 --- a/trunk/src/app/srs_app_utility.hpp +++ b/trunk/src/app/srs_app_utility.hpp @@ -44,7 +44,8 @@ class SrsBuffer; class SrsJsonObject; // client open socket and connect to server. -extern int srs_socket_connect(std::string server, int port, int64_t timeout, st_netfd_t* pstfd); +// @param tm The timeout in ms. +extern int srs_socket_connect(std::string server, int port, int64_t tm, st_netfd_t* pstfd); /** * convert level in string to log level in int. diff --git a/trunk/src/kernel/srs_kernel_consts.hpp b/trunk/src/kernel/srs_kernel_consts.hpp index b2ceb5b5c..03db74ad9 100644 --- a/trunk/src/kernel/srs_kernel_consts.hpp +++ b/trunk/src/kernel/srs_kernel_consts.hpp @@ -68,15 +68,18 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // the following is the timeout for rtmp protocol, // to avoid death connection. +// Never timeout in ms. +#define SRS_CONSTS_NO_TMMS ((int64_t) -1LL) + // the common io timeout, for both recv and send. // TODO: FIXME: use ms for timeout. -#define SRS_CONSTS_RTMP_TIMEOUT_US (int64_t)(30*1000*1000LL) +#define SRS_CONSTS_RTMP_TMMS (30*1000) // the timeout to wait for client control message, // if timeout, we generally ignore and send the data to client, // generally, it's the pulse time for data seding. // @remark, recomment to 500ms. -#define SRS_CONSTS_RTMP_PULSE_TIMEOUT_US (int64_t)(500*1000LL) +#define SRS_CONSTS_RTMP_PULSE_TMMS (500) /** * max rtmp header size: @@ -225,7 +228,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define SRS_CONSTS_HTTP_QUERY_SEP '?' // the default recv timeout. -#define SRS_HTTP_RECV_TIMEOUT_US 60 * 1000 * 1000 +#define SRS_HTTP_RECV_TMMS (60 * 1000) // 6.1.1 Status Code and Reason Phrase #define SRS_CONSTS_HTTP_Continue 100 @@ -410,8 +413,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define SRS_CONSTS_KAFKA_DEFAULT_PORT 9092 // the common io timeout, for both recv and send. -// TODO: FIXME: use ms for timeout. -#define SRS_CONSTS_KAFKA_TIMEOUT_US (int64_t)(30*1000*1000LL) +#define SRS_CONSTS_KAFKA_TMMS (30*1000) #endif diff --git a/trunk/src/kernel/srs_kernel_utility.cpp b/trunk/src/kernel/srs_kernel_utility.cpp index b981de475..9e8abb17b 100644 --- a/trunk/src/kernel/srs_kernel_utility.cpp +++ b/trunk/src/kernel/srs_kernel_utility.cpp @@ -135,8 +135,7 @@ int64_t srs_update_system_time_ms() // 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; + _srs_system_time_startup_time = _srs_system_time_us_cache = now_us; return _srs_system_time_us_cache / 1000; } @@ -144,15 +143,13 @@ int64_t srs_update_system_time_ms() 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); + srs_warn("clock jump, history=%"PRId64"us, now=%"PRId64"us, diff=%"PRId64"us", _srs_system_time_us_cache, now_us, diff); // @see: https://github.com/ossrs/srs/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); + srs_info("clock updated, startup=%"PRId64"us, now=%"PRId64"us", _srs_system_time_startup_time, _srs_system_time_us_cache); return _srs_system_time_us_cache / 1000; } diff --git a/trunk/src/libs/srs_lib_simple_socket.cpp b/trunk/src/libs/srs_lib_simple_socket.cpp index e3b6c4909..72ccbfdb6 100644 --- a/trunk/src/libs/srs_lib_simple_socket.cpp +++ b/trunk/src/libs/srs_lib_simple_socket.cpp @@ -66,24 +66,22 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include - -#ifndef ST_UTIME_NO_TIMEOUT - #define ST_UTIME_NO_TIMEOUT -1 -#endif +#include // when io not hijacked, use simple socket, the block sync stream. #ifndef SRS_HIJACK_IO struct SrsBlockSyncSocket { SOCKET fd; - int64_t recv_timeout; - int64_t send_timeout; - int64_t recv_bytes; - int64_t send_bytes; + int64_t rbytes; + int64_t sbytes; + // The send/recv timeout in ms. + int64_t rtm; + int64_t stm; SrsBlockSyncSocket() { - send_timeout = recv_timeout = ST_UTIME_NO_TIMEOUT; - recv_bytes = send_bytes = 0; + stm = rtm = SRS_CONSTS_NO_TMMS; + rbytes = sbytes = 0; SOCKET_RESET(fd); SOCKET_SETUP(); @@ -156,66 +154,75 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. return ERROR_SOCKET_READ; } - skt->recv_bytes += nb_read; + skt->rbytes += nb_read; return ret; } - int srs_hijack_io_set_recv_timeout(srs_hijack_io_t ctx, int64_t timeout_us) + int srs_hijack_io_set_recv_timeout(srs_hijack_io_t ctx, int64_t tm) { SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx; - int sec = (int)(timeout_us / 1000000LL); - int microsec = (int)(timeout_us % 1000000LL); + // The default for this option is zero, + // which indicates that a receive operation shall not time out. + int32_t sec = 0; + int32_t usec = 0; - sec = srs_max(0, sec); - microsec = srs_max(0, microsec); + if (tm != SRS_CONSTS_NO_TMMS) { + sec = (int32_t)(tm / 1000); + usec = (int32_t)((tm % 1000)*1000); + } - struct timeval tv = { sec , microsec }; + struct timeval tv = { sec , usec }; if (setsockopt(skt->fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) { return SOCKET_ERRNO(); } - skt->recv_timeout = timeout_us; + + skt->rtm = tm; return ERROR_SUCCESS; } int64_t srs_hijack_io_get_recv_timeout(srs_hijack_io_t ctx) { SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx; - return skt->recv_timeout; + return skt->rtm; } int64_t srs_hijack_io_get_recv_bytes(srs_hijack_io_t ctx) { SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx; - return skt->recv_bytes; + return skt->rbytes; } - int srs_hijack_io_set_send_timeout(srs_hijack_io_t ctx, int64_t timeout_us) + int srs_hijack_io_set_send_timeout(srs_hijack_io_t ctx, int64_t tm) { SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx; - int sec = (int)(timeout_us / 1000000LL); - int microsec = (int)(timeout_us % 1000000LL); - - sec = srs_max(0, sec); - microsec = srs_max(0, microsec); - - struct timeval tv = { sec , microsec }; + // The default for this option is zero, + // which indicates that a receive operation shall not time out. + int32_t sec = 0; + int32_t usec = 0; + + if (tm != SRS_CONSTS_NO_TMMS) { + sec = (int32_t)(tm / 1000); + usec = (int32_t)((tm % 1000)*1000); + } + + struct timeval tv = { sec , usec }; if (setsockopt(skt->fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) == -1) { return SOCKET_ERRNO(); } - skt->send_timeout = timeout_us; + skt->stm = tm; return ERROR_SUCCESS; } int64_t srs_hijack_io_get_send_timeout(srs_hijack_io_t ctx) { SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx; - return skt->send_timeout; + return skt->stm; } int64_t srs_hijack_io_get_send_bytes(srs_hijack_io_t ctx) { SrsBlockSyncSocket* skt = (SrsBlockSyncSocket*)ctx; - return skt->send_bytes; + return skt->sbytes; } int srs_hijack_io_writev(srs_hijack_io_t ctx, const iovec *iov, int iov_size, ssize_t* nwrite) { @@ -241,13 +248,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. return ERROR_SOCKET_WRITE; } - skt->send_bytes += nb_write; + skt->sbytes += nb_write; return ret; } - bool srs_hijack_io_is_never_timeout(srs_hijack_io_t ctx, int64_t timeout_us) + bool srs_hijack_io_is_never_timeout(srs_hijack_io_t ctx, int64_t tm) { - return timeout_us == (int64_t)ST_UTIME_NO_TIMEOUT; + return tm == SRS_CONSTS_NO_TMMS; } int srs_hijack_io_read_fully(srs_hijack_io_t ctx, void* buf, size_t size, ssize_t* nread) { @@ -273,7 +280,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. if (nread) { *nread = nb_read; } - skt->recv_bytes += nb_read; + skt->rbytes += nb_read; return ret; } @@ -298,7 +305,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. return ERROR_SOCKET_WRITE; } - skt->send_bytes += nb_write; + skt->sbytes += nb_write; return ret; } @@ -342,10 +349,10 @@ int SimpleSocketStream::read(void* buf, size_t size, ssize_t* nread) } // ISrsProtocolReader -void SimpleSocketStream::set_recv_timeout(int64_t timeout_us) +void SimpleSocketStream::set_recv_timeout(int64_t tm) { srs_assert(io); - srs_hijack_io_set_recv_timeout(io, timeout_us); + srs_hijack_io_set_recv_timeout(io, tm); } int64_t SimpleSocketStream::get_recv_timeout() @@ -361,10 +368,10 @@ int64_t SimpleSocketStream::get_recv_bytes() } // ISrsProtocolWriter -void SimpleSocketStream::set_send_timeout(int64_t timeout_us) +void SimpleSocketStream::set_send_timeout(int64_t tm) { srs_assert(io); - srs_hijack_io_set_send_timeout(io, timeout_us); + srs_hijack_io_set_send_timeout(io, tm); } int64_t SimpleSocketStream::get_send_timeout() @@ -386,10 +393,10 @@ int SimpleSocketStream::writev(const iovec *iov, int iov_size, ssize_t* nwrite) } // ISrsProtocolReaderWriter -bool SimpleSocketStream::is_never_timeout(int64_t timeout_us) +bool SimpleSocketStream::is_never_timeout(int64_t tm) { srs_assert(io); - return srs_hijack_io_is_never_timeout(io, timeout_us); + return srs_hijack_io_is_never_timeout(io, tm); } int SimpleSocketStream::read_fully(void* buf, size_t size, ssize_t* nread) diff --git a/trunk/src/libs/srs_lib_simple_socket.hpp b/trunk/src/libs/srs_lib_simple_socket.hpp index d3d6d1353..a9ff88bb3 100644 --- a/trunk/src/libs/srs_lib_simple_socket.hpp +++ b/trunk/src/libs/srs_lib_simple_socket.hpp @@ -58,18 +58,18 @@ public: virtual int read(void* buf, size_t size, ssize_t* nread); // ISrsProtocolReader public: - virtual void set_recv_timeout(int64_t timeout_us); + virtual void set_recv_timeout(int64_t tm); virtual int64_t get_recv_timeout(); virtual int64_t get_recv_bytes(); // ISrsProtocolWriter public: - virtual void set_send_timeout(int64_t timeout_us); + virtual void set_send_timeout(int64_t tm); virtual int64_t get_send_timeout(); virtual int64_t get_send_bytes(); virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite); // ISrsProtocolReaderWriter public: - virtual bool is_never_timeout(int64_t timeout_us); + virtual bool is_never_timeout(int64_t tm); virtual int read_fully(void* buf, size_t size, ssize_t* nread); virtual int write(void* buf, size_t size, ssize_t* nwrite); }; diff --git a/trunk/src/libs/srs_librtmp.cpp b/trunk/src/libs/srs_librtmp.cpp index fa2115630..1b3a93ab4 100644 --- a/trunk/src/libs/srs_librtmp.cpp +++ b/trunk/src/libs/srs_librtmp.cpp @@ -54,8 +54,8 @@ using namespace std; ISrsLog* _srs_log = new ISrsLog(); ISrsThreadContext* _srs_context = new ISrsThreadContext(); -// use this default timeout in us, if user not set. -#define SRS_SOCKET_DEFAULT_TIMEOUT 30 * 1000 * 1000LL +// The default socket timeout in ms. +#define SRS_SOCKET_DEFAULT_TMMS (30 * 1000) /** * export runtime context. @@ -108,7 +108,7 @@ struct Context // the aac sequence header. std::string aac_specific_config; - // user set timeout, in us. + // user set timeout, in ms. int64_t stimeout; int64_t rtimeout; @@ -120,7 +120,7 @@ struct Context h264_sps_pps_sent = false; h264_sps_changed = false; h264_pps_changed = false; - rtimeout = stimeout = -1; + rtimeout = stimeout = SRS_CONSTS_NO_TMMS; } virtual ~Context() { srs_freep(req); @@ -580,8 +580,8 @@ int srs_rtmp_set_timeout(srs_rtmp_t rtmp, int recv_timeout_ms, int send_timeout_ Context* context = (Context*)rtmp; - context->stimeout = send_timeout_ms * 1000; - context->rtimeout = recv_timeout_ms * 1000; + context->stimeout = send_timeout_ms; + context->rtimeout = recv_timeout_ms; context->skt->set_recv_timeout(context->rtimeout); context->skt->set_send_timeout(context->stimeout); @@ -646,12 +646,12 @@ int srs_rtmp_connect_server(srs_rtmp_t rtmp) Context* context = (Context*)rtmp; // set timeout if user not set. - if (context->stimeout == -1) { - context->stimeout = SRS_SOCKET_DEFAULT_TIMEOUT; + if (context->stimeout == SRS_CONSTS_NO_TMMS) { + context->stimeout = SRS_SOCKET_DEFAULT_TMMS; context->skt->set_send_timeout(context->stimeout); } - if (context->rtimeout == -1) { - context->rtimeout = SRS_SOCKET_DEFAULT_TIMEOUT; + if (context->rtimeout == SRS_CONSTS_NO_TMMS) { + context->rtimeout = SRS_SOCKET_DEFAULT_TMMS; context->skt->set_recv_timeout(context->rtimeout); } diff --git a/trunk/src/libs/srs_librtmp.hpp b/trunk/src/libs/srs_librtmp.hpp index 6f3d9fe01..0058d3ebc 100644 --- a/trunk/src/libs/srs_librtmp.hpp +++ b/trunk/src/libs/srs_librtmp.hpp @@ -1020,10 +1020,10 @@ typedef void* srs_hijack_io_t; */ extern int srs_hijack_io_read(srs_hijack_io_t ctx, void* buf, size_t size, ssize_t* nread); /** - * set the socket recv timeout. + * set the socket recv timeout in ms. * @return 0, success; otherswise, failed. */ - extern int srs_hijack_io_set_recv_timeout(srs_hijack_io_t ctx, int64_t timeout_us); + extern int srs_hijack_io_set_recv_timeout(srs_hijack_io_t ctx, int64_t tm); /** * get the socket recv timeout. * @return 0, success; otherswise, failed. @@ -1035,10 +1035,10 @@ typedef void* srs_hijack_io_t; */ extern int64_t srs_hijack_io_get_recv_bytes(srs_hijack_io_t ctx); /** - * set the socket send timeout. + * set the socket send timeout in ms. * @return 0, success; otherswise, failed. */ - extern int srs_hijack_io_set_send_timeout(srs_hijack_io_t ctx, int64_t timeout_us); + extern int srs_hijack_io_set_send_timeout(srs_hijack_io_t ctx, int64_t tm); /** * get the socket send timeout. * @return 0, success; otherswise, failed. @@ -1055,10 +1055,11 @@ typedef void* srs_hijack_io_t; */ extern int srs_hijack_io_writev(srs_hijack_io_t ctx, const iovec *iov, int iov_size, ssize_t* nwrite); /** - * whether the timeout is never timeout. + * whether the timeout is never timeout in ms. * @return 0, success; otherswise, failed. */ - extern bool srs_hijack_io_is_never_timeout(srs_hijack_io_t ctx, int64_t timeout_us); + // TODO: FIXME: Upgrade srs-bench and change the us to ms for timeout. + extern bool srs_hijack_io_is_never_timeout(srs_hijack_io_t ctx, int64_t tm); /** * read fully, fill the buf exactly size bytes. * @return 0, success; otherswise, failed. diff --git a/trunk/src/main/srs_main_ingest_hls.cpp b/trunk/src/main/srs_main_ingest_hls.cpp index 78d7ef8e1..f8853b0d2 100644 --- a/trunk/src/main/srs_main_ingest_hls.cpp +++ b/trunk/src/main/srs_main_ingest_hls.cpp @@ -1226,9 +1226,9 @@ int SrsIngestSrsOutput::connect() srs_trace("connect output=%s", url.c_str()); // connect host. - int64_t cto = SRS_CONSTS_RTMP_TIMEOUT_US; - int64_t sto = SRS_CONSTS_RTMP_PULSE_TIMEOUT_US; - sdk = new SrsSimpleRtmpClient(url, cto/1000, sto/1000); + int64_t cto = SRS_CONSTS_RTMP_TMMS; + int64_t sto = SRS_CONSTS_RTMP_PULSE_TMMS; + sdk = new SrsSimpleRtmpClient(url, cto, sto); if ((ret = sdk->connect()) != ERROR_SUCCESS) { close(); diff --git a/trunk/src/protocol/srs_http_stack.cpp b/trunk/src/protocol/srs_http_stack.cpp index 91bfd82cf..fa6f28e3f 100644 --- a/trunk/src/protocol/srs_http_stack.cpp +++ b/trunk/src/protocol/srs_http_stack.cpp @@ -43,46 +43,46 @@ string srs_generate_http_status_text(int status) { static std::map _status_map; if (_status_map.empty()) { - _status_map[SRS_CONSTS_HTTP_Continue ] = SRS_CONSTS_HTTP_Continue_str ; - _status_map[SRS_CONSTS_HTTP_SwitchingProtocols ] = SRS_CONSTS_HTTP_SwitchingProtocols_str ; - _status_map[SRS_CONSTS_HTTP_OK ] = SRS_CONSTS_HTTP_OK_str ; - _status_map[SRS_CONSTS_HTTP_Created ] = SRS_CONSTS_HTTP_Created_str ; - _status_map[SRS_CONSTS_HTTP_Accepted ] = SRS_CONSTS_HTTP_Accepted_str ; - _status_map[SRS_CONSTS_HTTP_NonAuthoritativeInformation ] = SRS_CONSTS_HTTP_NonAuthoritativeInformation_str ; - _status_map[SRS_CONSTS_HTTP_NoContent ] = SRS_CONSTS_HTTP_NoContent_str ; - _status_map[SRS_CONSTS_HTTP_ResetContent ] = SRS_CONSTS_HTTP_ResetContent_str ; - _status_map[SRS_CONSTS_HTTP_PartialContent ] = SRS_CONSTS_HTTP_PartialContent_str ; - _status_map[SRS_CONSTS_HTTP_MultipleChoices ] = SRS_CONSTS_HTTP_MultipleChoices_str ; - _status_map[SRS_CONSTS_HTTP_MovedPermanently ] = SRS_CONSTS_HTTP_MovedPermanently_str ; - _status_map[SRS_CONSTS_HTTP_Found ] = SRS_CONSTS_HTTP_Found_str ; - _status_map[SRS_CONSTS_HTTP_SeeOther ] = SRS_CONSTS_HTTP_SeeOther_str ; - _status_map[SRS_CONSTS_HTTP_NotModified ] = SRS_CONSTS_HTTP_NotModified_str ; - _status_map[SRS_CONSTS_HTTP_UseProxy ] = SRS_CONSTS_HTTP_UseProxy_str ; - _status_map[SRS_CONSTS_HTTP_TemporaryRedirect ] = SRS_CONSTS_HTTP_TemporaryRedirect_str ; - _status_map[SRS_CONSTS_HTTP_BadRequest ] = SRS_CONSTS_HTTP_BadRequest_str ; - _status_map[SRS_CONSTS_HTTP_Unauthorized ] = SRS_CONSTS_HTTP_Unauthorized_str ; - _status_map[SRS_CONSTS_HTTP_PaymentRequired ] = SRS_CONSTS_HTTP_PaymentRequired_str ; - _status_map[SRS_CONSTS_HTTP_Forbidden ] = SRS_CONSTS_HTTP_Forbidden_str ; - _status_map[SRS_CONSTS_HTTP_NotFound ] = SRS_CONSTS_HTTP_NotFound_str ; - _status_map[SRS_CONSTS_HTTP_MethodNotAllowed ] = SRS_CONSTS_HTTP_MethodNotAllowed_str ; - _status_map[SRS_CONSTS_HTTP_NotAcceptable ] = SRS_CONSTS_HTTP_NotAcceptable_str ; - _status_map[SRS_CONSTS_HTTP_ProxyAuthenticationRequired ] = SRS_CONSTS_HTTP_ProxyAuthenticationRequired_str ; - _status_map[SRS_CONSTS_HTTP_RequestTimeout ] = SRS_CONSTS_HTTP_RequestTimeout_str ; - _status_map[SRS_CONSTS_HTTP_Conflict ] = SRS_CONSTS_HTTP_Conflict_str ; - _status_map[SRS_CONSTS_HTTP_Gone ] = SRS_CONSTS_HTTP_Gone_str ; - _status_map[SRS_CONSTS_HTTP_LengthRequired ] = SRS_CONSTS_HTTP_LengthRequired_str ; - _status_map[SRS_CONSTS_HTTP_PreconditionFailed ] = SRS_CONSTS_HTTP_PreconditionFailed_str ; - _status_map[SRS_CONSTS_HTTP_RequestEntityTooLarge ] = SRS_CONSTS_HTTP_RequestEntityTooLarge_str ; - _status_map[SRS_CONSTS_HTTP_RequestURITooLarge ] = SRS_CONSTS_HTTP_RequestURITooLarge_str ; - _status_map[SRS_CONSTS_HTTP_UnsupportedMediaType ] = SRS_CONSTS_HTTP_UnsupportedMediaType_str ; - _status_map[SRS_CONSTS_HTTP_RequestedRangeNotSatisfiable ] = SRS_CONSTS_HTTP_RequestedRangeNotSatisfiable_str ; - _status_map[SRS_CONSTS_HTTP_ExpectationFailed ] = SRS_CONSTS_HTTP_ExpectationFailed_str ; - _status_map[SRS_CONSTS_HTTP_InternalServerError ] = SRS_CONSTS_HTTP_InternalServerError_str ; - _status_map[SRS_CONSTS_HTTP_NotImplemented ] = SRS_CONSTS_HTTP_NotImplemented_str ; - _status_map[SRS_CONSTS_HTTP_BadGateway ] = SRS_CONSTS_HTTP_BadGateway_str ; - _status_map[SRS_CONSTS_HTTP_ServiceUnavailable ] = SRS_CONSTS_HTTP_ServiceUnavailable_str ; - _status_map[SRS_CONSTS_HTTP_GatewayTimeout ] = SRS_CONSTS_HTTP_GatewayTimeout_str ; - _status_map[SRS_CONSTS_HTTP_HTTPVersionNotSupported ] = SRS_CONSTS_HTTP_HTTPVersionNotSupported_str ; + _status_map[SRS_CONSTS_HTTP_Continue] = SRS_CONSTS_HTTP_Continue_str; + _status_map[SRS_CONSTS_HTTP_SwitchingProtocols] = SRS_CONSTS_HTTP_SwitchingProtocols_str; + _status_map[SRS_CONSTS_HTTP_OK] = SRS_CONSTS_HTTP_OK_str; + _status_map[SRS_CONSTS_HTTP_Created] = SRS_CONSTS_HTTP_Created_str; + _status_map[SRS_CONSTS_HTTP_Accepted] = SRS_CONSTS_HTTP_Accepted_str; + _status_map[SRS_CONSTS_HTTP_NonAuthoritativeInformation] = SRS_CONSTS_HTTP_NonAuthoritativeInformation_str; + _status_map[SRS_CONSTS_HTTP_NoContent] = SRS_CONSTS_HTTP_NoContent_str; + _status_map[SRS_CONSTS_HTTP_ResetContent] = SRS_CONSTS_HTTP_ResetContent_str; + _status_map[SRS_CONSTS_HTTP_PartialContent] = SRS_CONSTS_HTTP_PartialContent_str; + _status_map[SRS_CONSTS_HTTP_MultipleChoices] = SRS_CONSTS_HTTP_MultipleChoices_str; + _status_map[SRS_CONSTS_HTTP_MovedPermanently] = SRS_CONSTS_HTTP_MovedPermanently_str; + _status_map[SRS_CONSTS_HTTP_Found] = SRS_CONSTS_HTTP_Found_str; + _status_map[SRS_CONSTS_HTTP_SeeOther] = SRS_CONSTS_HTTP_SeeOther_str; + _status_map[SRS_CONSTS_HTTP_NotModified] = SRS_CONSTS_HTTP_NotModified_str; + _status_map[SRS_CONSTS_HTTP_UseProxy] = SRS_CONSTS_HTTP_UseProxy_str; + _status_map[SRS_CONSTS_HTTP_TemporaryRedirect] = SRS_CONSTS_HTTP_TemporaryRedirect_str; + _status_map[SRS_CONSTS_HTTP_BadRequest] = SRS_CONSTS_HTTP_BadRequest_str; + _status_map[SRS_CONSTS_HTTP_Unauthorized] = SRS_CONSTS_HTTP_Unauthorized_str; + _status_map[SRS_CONSTS_HTTP_PaymentRequired] = SRS_CONSTS_HTTP_PaymentRequired_str; + _status_map[SRS_CONSTS_HTTP_Forbidden] = SRS_CONSTS_HTTP_Forbidden_str; + _status_map[SRS_CONSTS_HTTP_NotFound] = SRS_CONSTS_HTTP_NotFound_str; + _status_map[SRS_CONSTS_HTTP_MethodNotAllowed] = SRS_CONSTS_HTTP_MethodNotAllowed_str; + _status_map[SRS_CONSTS_HTTP_NotAcceptable] = SRS_CONSTS_HTTP_NotAcceptable_str; + _status_map[SRS_CONSTS_HTTP_ProxyAuthenticationRequired] = SRS_CONSTS_HTTP_ProxyAuthenticationRequired_str; + _status_map[SRS_CONSTS_HTTP_RequestTimeout] = SRS_CONSTS_HTTP_RequestTimeout_str; + _status_map[SRS_CONSTS_HTTP_Conflict] = SRS_CONSTS_HTTP_Conflict_str; + _status_map[SRS_CONSTS_HTTP_Gone] = SRS_CONSTS_HTTP_Gone_str; + _status_map[SRS_CONSTS_HTTP_LengthRequired] = SRS_CONSTS_HTTP_LengthRequired_str; + _status_map[SRS_CONSTS_HTTP_PreconditionFailed] = SRS_CONSTS_HTTP_PreconditionFailed_str; + _status_map[SRS_CONSTS_HTTP_RequestEntityTooLarge] = SRS_CONSTS_HTTP_RequestEntityTooLarge_str; + _status_map[SRS_CONSTS_HTTP_RequestURITooLarge] = SRS_CONSTS_HTTP_RequestURITooLarge_str; + _status_map[SRS_CONSTS_HTTP_UnsupportedMediaType] = SRS_CONSTS_HTTP_UnsupportedMediaType_str; + _status_map[SRS_CONSTS_HTTP_RequestedRangeNotSatisfiable] = SRS_CONSTS_HTTP_RequestedRangeNotSatisfiable_str; + _status_map[SRS_CONSTS_HTTP_ExpectationFailed] = SRS_CONSTS_HTTP_ExpectationFailed_str; + _status_map[SRS_CONSTS_HTTP_InternalServerError] = SRS_CONSTS_HTTP_InternalServerError_str; + _status_map[SRS_CONSTS_HTTP_NotImplemented] = SRS_CONSTS_HTTP_NotImplemented_str; + _status_map[SRS_CONSTS_HTTP_BadGateway] = SRS_CONSTS_HTTP_BadGateway_str; + _status_map[SRS_CONSTS_HTTP_ServiceUnavailable] = SRS_CONSTS_HTTP_ServiceUnavailable_str; + _status_map[SRS_CONSTS_HTTP_GatewayTimeout] = SRS_CONSTS_HTTP_GatewayTimeout_str; + _status_map[SRS_CONSTS_HTTP_HTTPVersionNotSupported] = SRS_CONSTS_HTTP_HTTPVersionNotSupported_str; } std::string status_text; @@ -2855,7 +2855,7 @@ http_parse_host(const char * buf, struct http_parser_url *u, int found_at) { case s_http_userinfo: if (s != s_http_userinfo) { - u->field_data[UF_USERINFO].off = p - buf ; + u->field_data[UF_USERINFO].off = p - buf; u->field_data[UF_USERINFO].len = 0; u->field_set |= (1 << UF_USERINFO); } diff --git a/trunk/src/protocol/srs_protocol_io.hpp b/trunk/src/protocol/srs_protocol_io.hpp index c34adaedc..cdb72e982 100644 --- a/trunk/src/protocol/srs_protocol_io.hpp +++ b/trunk/src/protocol/srs_protocol_io.hpp @@ -126,12 +126,12 @@ public: // for protocol public: /** - * set the recv timeout in us, recv will error when timeout. - * @remark, if not set, use ST_UTIME_NO_TIMEOUT, never timeout. - */ - virtual void set_recv_timeout(int64_t timeout_us) = 0; + * Set the timeout tm in ms for recv bytes from peer. + * @remark Use SRS_CONSTS_NO_TIMEOUT to never timeout. + */ + virtual void set_recv_timeout(int64_t tm) = 0; /** - * get the recv timeout in us. + * Get the timeout in ms for recv bytes from peer. */ virtual int64_t get_recv_timeout() = 0; // for handshake. @@ -154,13 +154,13 @@ public: // for protocol public: /** - * set the send timeout in us, send will error when timeout. - * @remark, if not set, use ST_UTIME_NO_TIMEOUT, never timeout. - */ - virtual void set_send_timeout(int64_t timeout_us) = 0; + * Set the timeout tm in ms for send bytes to peer. + * @remark Use SRS_CONSTS_NO_TIMEOUT to never timeout. + */ + virtual void set_send_timeout(int64_t tm) = 0; /** - * get the send timeout in us. - */ + * Get the timeout in ms for send bytes to peer. + */ virtual int64_t get_send_timeout() = 0; }; @@ -175,9 +175,9 @@ public: // for protocol public: /** - * whether the specified timeout_us is never timeout. - */ - virtual bool is_never_timeout(int64_t timeout_us) = 0; + * Whether the specified tm in ms is never timeout. + */ + virtual bool is_never_timeout(int64_t tm) = 0; }; #endif diff --git a/trunk/src/protocol/srs_rtmp_stack.cpp b/trunk/src/protocol/srs_rtmp_stack.cpp index 14a0ae252..c17fa1d1d 100644 --- a/trunk/src/protocol/srs_rtmp_stack.cpp +++ b/trunk/src/protocol/srs_rtmp_stack.cpp @@ -325,9 +325,9 @@ void SrsProtocol::set_recv_buffer(int buffer_size) } #endif -void SrsProtocol::set_recv_timeout(int64_t timeout_us) +void SrsProtocol::set_recv_timeout(int64_t tm) { - return skt->set_recv_timeout(timeout_us); + return skt->set_recv_timeout(tm); } int64_t SrsProtocol::get_recv_timeout() @@ -335,9 +335,9 @@ int64_t SrsProtocol::get_recv_timeout() return skt->get_recv_timeout(); } -void SrsProtocol::set_send_timeout(int64_t timeout_us) +void SrsProtocol::set_send_timeout(int64_t tm) { - return skt->set_send_timeout(timeout_us); + return skt->set_send_timeout(tm); } int64_t SrsProtocol::get_send_timeout() @@ -1982,14 +1982,14 @@ SrsRtmpClient::~SrsRtmpClient() srs_freep(hs_bytes); } -void SrsRtmpClient::set_recv_timeout(int64_t timeout_us) +void SrsRtmpClient::set_recv_timeout(int64_t tm) { - protocol->set_recv_timeout(timeout_us); + protocol->set_recv_timeout(tm); } -void SrsRtmpClient::set_send_timeout(int64_t timeout_us) +void SrsRtmpClient::set_send_timeout(int64_t tm) { - protocol->set_send_timeout(timeout_us); + protocol->set_send_timeout(tm); } int64_t SrsRtmpClient::get_recv_bytes() @@ -2410,9 +2410,9 @@ void SrsRtmpServer::set_recv_buffer(int buffer_size) } #endif -void SrsRtmpServer::set_recv_timeout(int64_t timeout_us) +void SrsRtmpServer::set_recv_timeout(int64_t tm) { - protocol->set_recv_timeout(timeout_us); + protocol->set_recv_timeout(tm); } int64_t SrsRtmpServer::get_recv_timeout() @@ -2420,9 +2420,9 @@ int64_t SrsRtmpServer::get_recv_timeout() return protocol->get_recv_timeout(); } -void SrsRtmpServer::set_send_timeout(int64_t timeout_us) +void SrsRtmpServer::set_send_timeout(int64_t tm) { - protocol->set_send_timeout(timeout_us); + protocol->set_send_timeout(tm); } int64_t SrsRtmpServer::get_send_timeout() @@ -2621,7 +2621,7 @@ int SrsRtmpServer::response_connect_app(SrsRequest *req, const char* server_ip) return ret; } -#define SRS_RTMP_REDIRECT_TIMEOUT 3000 +#define SRS_RTMP_REDIRECT_TMMS 3000 int SrsRtmpServer::redirect(SrsRequest* r, string host, int port, bool& accepted) { int ret = ERROR_SUCCESS; @@ -2649,7 +2649,7 @@ int SrsRtmpServer::redirect(SrsRequest* r, string host, int port, bool& accepted // client must response a call message. // or we never know whether the client is ok to redirect. - protocol->set_recv_timeout(SRS_RTMP_REDIRECT_TIMEOUT * 1000); + protocol->set_recv_timeout(SRS_RTMP_REDIRECT_TMMS); if (true) { SrsCommonMessage* msg = NULL; SrsCallPacket* pkt = NULL; diff --git a/trunk/src/protocol/srs_rtmp_stack.hpp b/trunk/src/protocol/srs_rtmp_stack.hpp index 8f65f8a55..c29423cdd 100644 --- a/trunk/src/protocol/srs_rtmp_stack.hpp +++ b/trunk/src/protocol/srs_rtmp_stack.hpp @@ -313,16 +313,16 @@ public: #endif public: /** - * set/get the recv timeout in us. + * set/get the recv timeout in ms. * if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. */ - virtual void set_recv_timeout(int64_t timeout_us); + virtual void set_recv_timeout(int64_t tm); virtual int64_t get_recv_timeout(); /** - * set/get the send timeout in us. + * set/get the send timeout in ms. * if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. */ - virtual void set_send_timeout(int64_t timeout_us); + virtual void set_send_timeout(int64_t tm); virtual int64_t get_send_timeout(); /** * get recv/send bytes. @@ -681,64 +681,16 @@ protected: public: SrsRtmpClient(ISrsProtocolReaderWriter* skt); virtual ~SrsRtmpClient(); - // protocol methods proxy +// protocol methods proxy public: - /** - * set the recv timeout in us. - * if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. - */ - virtual void set_recv_timeout(int64_t timeout_us); - /** - * set the send timeout in us. - * if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. - */ - virtual void set_send_timeout(int64_t timeout_us); - /** - * get recv/send bytes. - */ + virtual void set_recv_timeout(int64_t tm); + virtual void set_send_timeout(int64_t tm); virtual int64_t get_recv_bytes(); virtual int64_t get_send_bytes(); - /** - * recv a RTMP message, which is bytes oriented. - * user can use decode_message to get the decoded RTMP packet. - * @param pmsg, set the received message, - * always NULL if error, - * NULL for unknown packet but return success. - * never NULL if decode success. - * @remark, drop message when msg is empty or payload length is empty. - */ virtual int recv_message(SrsCommonMessage** pmsg); - /** - * decode bytes oriented RTMP message to RTMP packet, - * @param ppacket, output decoded packet, - * always NULL if error, never NULL if success. - * @return error when unknown packet, error when decode failed. - */ virtual int decode_message(SrsCommonMessage* msg, SrsPacket** ppacket); - /** - * send the RTMP message and always free it. - * user must never free or use the msg after this method, - * for it will always free the msg. - * @param msg, the msg to send out, never be NULL. - * @param stream_id, the stream id of packet to send over, 0 for control message. - */ virtual int send_and_free_message(SrsSharedPtrMessage* msg, int stream_id); - /** - * send the RTMP message and always free it. - * user must never free or use the msg after this method, - * for it will always free the msg. - * @param msgs, the msgs to send out, never be NULL. - * @param nb_msgs, the size of msgs to send out. - * @param stream_id, the stream id of packet to send over, 0 for control message. - */ virtual int send_and_free_messages(SrsSharedPtrMessage** msgs, int nb_msgs, int stream_id); - /** - * send the RTMP packet and always free it. - * user must never free or use the packet after this method, - * for it will always free the packet. - * @param packet, the packet to send out, never be NULL. - * @param stream_id, the stream id of packet to send over, 0 for control message. - */ virtual int send_and_free_packet(SrsPacket* packet, int stream_id); public: /** @@ -865,16 +817,16 @@ public: virtual void set_recv_buffer(int buffer_size); #endif /** - * set/get the recv timeout in us. + * set/get the recv timeout in ms. * if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. */ - virtual void set_recv_timeout(int64_t timeout_us); + virtual void set_recv_timeout(int64_t tm); virtual int64_t get_recv_timeout(); /** - * set/get the send timeout in us. + * set/get the send timeout in ms. * if timeout, recv/send message return ERROR_SOCKET_TIMEOUT. */ - virtual void set_send_timeout(int64_t timeout_us); + virtual void set_send_timeout(int64_t tm); virtual int64_t get_send_timeout(); /** * get recv/send bytes. diff --git a/trunk/src/protocol/srs_rtsp_stack.cpp b/trunk/src/protocol/srs_rtsp_stack.cpp index 701a67e76..a65717c35 100644 --- a/trunk/src/protocol/srs_rtsp_stack.cpp +++ b/trunk/src/protocol/srs_rtsp_stack.cpp @@ -48,50 +48,50 @@ string srs_generate_rtsp_status_text(int status) { static std::map _status_map; if (_status_map.empty()) { - _status_map[SRS_CONSTS_RTSP_Continue ] = SRS_CONSTS_RTSP_Continue_str ; - _status_map[SRS_CONSTS_RTSP_OK ] = SRS_CONSTS_RTSP_OK_str ; - _status_map[SRS_CONSTS_RTSP_Created ] = SRS_CONSTS_RTSP_Created_str ; - _status_map[SRS_CONSTS_RTSP_LowOnStorageSpace ] = SRS_CONSTS_RTSP_LowOnStorageSpace_str ; - _status_map[SRS_CONSTS_RTSP_MultipleChoices ] = SRS_CONSTS_RTSP_MultipleChoices_str ; - _status_map[SRS_CONSTS_RTSP_MovedPermanently ] = SRS_CONSTS_RTSP_MovedPermanently_str ; - _status_map[SRS_CONSTS_RTSP_MovedTemporarily ] = SRS_CONSTS_RTSP_MovedTemporarily_str ; - _status_map[SRS_CONSTS_RTSP_SeeOther ] = SRS_CONSTS_RTSP_SeeOther_str ; - _status_map[SRS_CONSTS_RTSP_NotModified ] = SRS_CONSTS_RTSP_NotModified_str ; - _status_map[SRS_CONSTS_RTSP_UseProxy ] = SRS_CONSTS_RTSP_UseProxy_str ; - _status_map[SRS_CONSTS_RTSP_BadRequest ] = SRS_CONSTS_RTSP_BadRequest_str ; - _status_map[SRS_CONSTS_RTSP_Unauthorized ] = SRS_CONSTS_RTSP_Unauthorized_str ; - _status_map[SRS_CONSTS_RTSP_PaymentRequired ] = SRS_CONSTS_RTSP_PaymentRequired_str ; - _status_map[SRS_CONSTS_RTSP_Forbidden ] = SRS_CONSTS_RTSP_Forbidden_str ; - _status_map[SRS_CONSTS_RTSP_NotFound ] = SRS_CONSTS_RTSP_NotFound_str ; - _status_map[SRS_CONSTS_RTSP_MethodNotAllowed ] = SRS_CONSTS_RTSP_MethodNotAllowed_str ; - _status_map[SRS_CONSTS_RTSP_NotAcceptable ] = SRS_CONSTS_RTSP_NotAcceptable_str ; - _status_map[SRS_CONSTS_RTSP_ProxyAuthenticationRequired ] = SRS_CONSTS_RTSP_ProxyAuthenticationRequired_str ; - _status_map[SRS_CONSTS_RTSP_RequestTimeout ] = SRS_CONSTS_RTSP_RequestTimeout_str ; - _status_map[SRS_CONSTS_RTSP_Gone ] = SRS_CONSTS_RTSP_Gone_str ; - _status_map[SRS_CONSTS_RTSP_LengthRequired ] = SRS_CONSTS_RTSP_LengthRequired_str ; - _status_map[SRS_CONSTS_RTSP_PreconditionFailed ] = SRS_CONSTS_RTSP_PreconditionFailed_str ; - _status_map[SRS_CONSTS_RTSP_RequestEntityTooLarge ] = SRS_CONSTS_RTSP_RequestEntityTooLarge_str ; - _status_map[SRS_CONSTS_RTSP_RequestURITooLarge ] = SRS_CONSTS_RTSP_RequestURITooLarge_str ; - _status_map[SRS_CONSTS_RTSP_UnsupportedMediaType ] = SRS_CONSTS_RTSP_UnsupportedMediaType_str ; - _status_map[SRS_CONSTS_RTSP_ParameterNotUnderstood ] = SRS_CONSTS_RTSP_ParameterNotUnderstood_str ; - _status_map[SRS_CONSTS_RTSP_ConferenceNotFound ] = SRS_CONSTS_RTSP_ConferenceNotFound_str ; - _status_map[SRS_CONSTS_RTSP_NotEnoughBandwidth ] = SRS_CONSTS_RTSP_NotEnoughBandwidth_str ; - _status_map[SRS_CONSTS_RTSP_SessionNotFound ] = SRS_CONSTS_RTSP_SessionNotFound_str ; - _status_map[SRS_CONSTS_RTSP_MethodNotValidInThisState ] = SRS_CONSTS_RTSP_MethodNotValidInThisState_str ; - _status_map[SRS_CONSTS_RTSP_HeaderFieldNotValidForResource ] = SRS_CONSTS_RTSP_HeaderFieldNotValidForResource_str ; - _status_map[SRS_CONSTS_RTSP_InvalidRange ] = SRS_CONSTS_RTSP_InvalidRange_str ; - _status_map[SRS_CONSTS_RTSP_ParameterIsReadOnly ] = SRS_CONSTS_RTSP_ParameterIsReadOnly_str ; - _status_map[SRS_CONSTS_RTSP_AggregateOperationNotAllowed ] = SRS_CONSTS_RTSP_AggregateOperationNotAllowed_str ; - _status_map[SRS_CONSTS_RTSP_OnlyAggregateOperationAllowed ] = SRS_CONSTS_RTSP_OnlyAggregateOperationAllowed_str ; - _status_map[SRS_CONSTS_RTSP_UnsupportedTransport ] = SRS_CONSTS_RTSP_UnsupportedTransport_str ; - _status_map[SRS_CONSTS_RTSP_DestinationUnreachable ] = SRS_CONSTS_RTSP_DestinationUnreachable_str ; - _status_map[SRS_CONSTS_RTSP_InternalServerError ] = SRS_CONSTS_RTSP_InternalServerError_str ; - _status_map[SRS_CONSTS_RTSP_NotImplemented ] = SRS_CONSTS_RTSP_NotImplemented_str ; - _status_map[SRS_CONSTS_RTSP_BadGateway ] = SRS_CONSTS_RTSP_BadGateway_str ; - _status_map[SRS_CONSTS_RTSP_ServiceUnavailable ] = SRS_CONSTS_RTSP_ServiceUnavailable_str ; - _status_map[SRS_CONSTS_RTSP_GatewayTimeout ] = SRS_CONSTS_RTSP_GatewayTimeout_str ; - _status_map[SRS_CONSTS_RTSP_RTSPVersionNotSupported ] = SRS_CONSTS_RTSP_RTSPVersionNotSupported_str ; - _status_map[SRS_CONSTS_RTSP_OptionNotSupported ] = SRS_CONSTS_RTSP_OptionNotSupported_str ; + _status_map[SRS_CONSTS_RTSP_Continue] = SRS_CONSTS_RTSP_Continue_str; + _status_map[SRS_CONSTS_RTSP_OK] = SRS_CONSTS_RTSP_OK_str; + _status_map[SRS_CONSTS_RTSP_Created] = SRS_CONSTS_RTSP_Created_str; + _status_map[SRS_CONSTS_RTSP_LowOnStorageSpace] = SRS_CONSTS_RTSP_LowOnStorageSpace_str; + _status_map[SRS_CONSTS_RTSP_MultipleChoices] = SRS_CONSTS_RTSP_MultipleChoices_str; + _status_map[SRS_CONSTS_RTSP_MovedPermanently] = SRS_CONSTS_RTSP_MovedPermanently_str; + _status_map[SRS_CONSTS_RTSP_MovedTemporarily] = SRS_CONSTS_RTSP_MovedTemporarily_str; + _status_map[SRS_CONSTS_RTSP_SeeOther] = SRS_CONSTS_RTSP_SeeOther_str; + _status_map[SRS_CONSTS_RTSP_NotModified] = SRS_CONSTS_RTSP_NotModified_str; + _status_map[SRS_CONSTS_RTSP_UseProxy] = SRS_CONSTS_RTSP_UseProxy_str; + _status_map[SRS_CONSTS_RTSP_BadRequest] = SRS_CONSTS_RTSP_BadRequest_str; + _status_map[SRS_CONSTS_RTSP_Unauthorized] = SRS_CONSTS_RTSP_Unauthorized_str; + _status_map[SRS_CONSTS_RTSP_PaymentRequired] = SRS_CONSTS_RTSP_PaymentRequired_str; + _status_map[SRS_CONSTS_RTSP_Forbidden] = SRS_CONSTS_RTSP_Forbidden_str; + _status_map[SRS_CONSTS_RTSP_NotFound] = SRS_CONSTS_RTSP_NotFound_str; + _status_map[SRS_CONSTS_RTSP_MethodNotAllowed] = SRS_CONSTS_RTSP_MethodNotAllowed_str; + _status_map[SRS_CONSTS_RTSP_NotAcceptable] = SRS_CONSTS_RTSP_NotAcceptable_str; + _status_map[SRS_CONSTS_RTSP_ProxyAuthenticationRequired] = SRS_CONSTS_RTSP_ProxyAuthenticationRequired_str; + _status_map[SRS_CONSTS_RTSP_RequestTimeout] = SRS_CONSTS_RTSP_RequestTimeout_str; + _status_map[SRS_CONSTS_RTSP_Gone] = SRS_CONSTS_RTSP_Gone_str; + _status_map[SRS_CONSTS_RTSP_LengthRequired] = SRS_CONSTS_RTSP_LengthRequired_str; + _status_map[SRS_CONSTS_RTSP_PreconditionFailed] = SRS_CONSTS_RTSP_PreconditionFailed_str; + _status_map[SRS_CONSTS_RTSP_RequestEntityTooLarge] = SRS_CONSTS_RTSP_RequestEntityTooLarge_str; + _status_map[SRS_CONSTS_RTSP_RequestURITooLarge] = SRS_CONSTS_RTSP_RequestURITooLarge_str; + _status_map[SRS_CONSTS_RTSP_UnsupportedMediaType] = SRS_CONSTS_RTSP_UnsupportedMediaType_str; + _status_map[SRS_CONSTS_RTSP_ParameterNotUnderstood] = SRS_CONSTS_RTSP_ParameterNotUnderstood_str; + _status_map[SRS_CONSTS_RTSP_ConferenceNotFound] = SRS_CONSTS_RTSP_ConferenceNotFound_str; + _status_map[SRS_CONSTS_RTSP_NotEnoughBandwidth] = SRS_CONSTS_RTSP_NotEnoughBandwidth_str; + _status_map[SRS_CONSTS_RTSP_SessionNotFound] = SRS_CONSTS_RTSP_SessionNotFound_str; + _status_map[SRS_CONSTS_RTSP_MethodNotValidInThisState] = SRS_CONSTS_RTSP_MethodNotValidInThisState_str; + _status_map[SRS_CONSTS_RTSP_HeaderFieldNotValidForResource] = SRS_CONSTS_RTSP_HeaderFieldNotValidForResource_str; + _status_map[SRS_CONSTS_RTSP_InvalidRange] = SRS_CONSTS_RTSP_InvalidRange_str; + _status_map[SRS_CONSTS_RTSP_ParameterIsReadOnly] = SRS_CONSTS_RTSP_ParameterIsReadOnly_str; + _status_map[SRS_CONSTS_RTSP_AggregateOperationNotAllowed] = SRS_CONSTS_RTSP_AggregateOperationNotAllowed_str; + _status_map[SRS_CONSTS_RTSP_OnlyAggregateOperationAllowed] = SRS_CONSTS_RTSP_OnlyAggregateOperationAllowed_str; + _status_map[SRS_CONSTS_RTSP_UnsupportedTransport] = SRS_CONSTS_RTSP_UnsupportedTransport_str; + _status_map[SRS_CONSTS_RTSP_DestinationUnreachable] = SRS_CONSTS_RTSP_DestinationUnreachable_str; + _status_map[SRS_CONSTS_RTSP_InternalServerError] = SRS_CONSTS_RTSP_InternalServerError_str; + _status_map[SRS_CONSTS_RTSP_NotImplemented] = SRS_CONSTS_RTSP_NotImplemented_str; + _status_map[SRS_CONSTS_RTSP_BadGateway] = SRS_CONSTS_RTSP_BadGateway_str; + _status_map[SRS_CONSTS_RTSP_ServiceUnavailable] = SRS_CONSTS_RTSP_ServiceUnavailable_str; + _status_map[SRS_CONSTS_RTSP_GatewayTimeout] = SRS_CONSTS_RTSP_GatewayTimeout_str; + _status_map[SRS_CONSTS_RTSP_RTSPVersionNotSupported] = SRS_CONSTS_RTSP_RTSPVersionNotSupported_str; + _status_map[SRS_CONSTS_RTSP_OptionNotSupported] = SRS_CONSTS_RTSP_OptionNotSupported_str; } std::string status_text; diff --git a/trunk/src/utest/srs_utest_protocol.cpp b/trunk/src/utest/srs_utest_protocol.cpp index 7b9a07b6c..5fd2c5b11 100644 --- a/trunk/src/utest/srs_utest_protocol.cpp +++ b/trunk/src/utest/srs_utest_protocol.cpp @@ -42,7 +42,7 @@ MockEmptyIO::~MockEmptyIO() { } -bool MockEmptyIO::is_never_timeout(int64_t /*timeout_us*/) +bool MockEmptyIO::is_never_timeout(int64_t /*tm*/) { return true; } @@ -57,7 +57,7 @@ int MockEmptyIO::write(void* /*buf*/, size_t /*size*/, ssize_t* /*nwrite*/) return ERROR_SUCCESS; } -void MockEmptyIO::set_recv_timeout(int64_t /*timeout_us*/) +void MockEmptyIO::set_recv_timeout(int64_t /*tm*/) { } @@ -71,7 +71,7 @@ int64_t MockEmptyIO::get_recv_bytes() return -1; } -void MockEmptyIO::set_send_timeout(int64_t /*timeout_us*/) +void MockEmptyIO::set_send_timeout(int64_t /*tm*/) { } @@ -97,17 +97,17 @@ int MockEmptyIO::read(void* /*buf*/, size_t /*size*/, ssize_t* /*nread*/) MockBufferIO::MockBufferIO() { - recv_timeout = send_timeout = ST_UTIME_NO_TIMEOUT; - recv_bytes = send_bytes = 0; + rtm = stm = SRS_CONSTS_NO_TMMS; + rbytes = sbytes = 0; } MockBufferIO::~MockBufferIO() { } -bool MockBufferIO::is_never_timeout(int64_t timeout_us) +bool MockBufferIO::is_never_timeout(int64_t tm) { - return (int64_t)ST_UTIME_NO_TIMEOUT == timeout_us; + return tm == SRS_CONSTS_NO_TMMS; } int MockBufferIO::read_fully(void* buf, size_t size, ssize_t* nread) @@ -117,7 +117,7 @@ int MockBufferIO::read_fully(void* buf, size_t size, ssize_t* nread) } memcpy(buf, in_buffer.bytes(), size); - recv_bytes += size; + rbytes += size; if (nread) { *nread = size; } @@ -127,7 +127,7 @@ int MockBufferIO::read_fully(void* buf, size_t size, ssize_t* nread) int MockBufferIO::write(void* buf, size_t size, ssize_t* nwrite) { - send_bytes += size; + sbytes += size; if (nwrite) { *nwrite = size; } @@ -135,34 +135,34 @@ int MockBufferIO::write(void* buf, size_t size, ssize_t* nwrite) return ERROR_SUCCESS; } -void MockBufferIO::set_recv_timeout(int64_t timeout_us) +void MockBufferIO::set_recv_timeout(int64_t tm) { - recv_timeout = timeout_us; + rtm = tm; } int64_t MockBufferIO::get_recv_timeout() { - return recv_timeout; + return rtm; } int64_t MockBufferIO::get_recv_bytes() { - return recv_bytes; + return rbytes; } -void MockBufferIO::set_send_timeout(int64_t timeout_us) +void MockBufferIO::set_send_timeout(int64_t tm) { - send_timeout = timeout_us; + stm = tm; } int64_t MockBufferIO::get_send_timeout() { - return send_timeout; + return stm; } int64_t MockBufferIO::get_send_bytes() { - return send_bytes; + return sbytes; } int MockBufferIO::writev(const iovec *iov, int iov_size, ssize_t* nwrite) @@ -180,6 +180,8 @@ int MockBufferIO::writev(const iovec *iov, int iov_size, ssize_t* nwrite) total += writen; } + sbytes += total; + if (nwrite) { *nwrite = total; } @@ -195,7 +197,7 @@ int MockBufferIO::read(void* buf, size_t size, ssize_t* nread) size_t available = srs_min(in_buffer.length(), (int)size); memcpy(buf, in_buffer.bytes(), available); - recv_bytes += available; + rbytes += available; if (nread) { *nread = available; } @@ -530,8 +532,8 @@ VOID TEST(ProtocolStackTest, ProtocolTimeout) MockBufferIO bio; SrsProtocol proto(&bio); - EXPECT_TRUE((int64_t)ST_UTIME_NO_TIMEOUT == proto.get_recv_timeout()); - EXPECT_TRUE((int64_t)ST_UTIME_NO_TIMEOUT == proto.get_send_timeout()); + EXPECT_TRUE(SRS_CONSTS_NO_TMMS == proto.get_recv_timeout()); + EXPECT_TRUE(SRS_CONSTS_NO_TMMS == proto.get_send_timeout()); proto.set_recv_timeout(10); EXPECT_TRUE(10 == proto.get_recv_timeout()); diff --git a/trunk/src/utest/srs_utest_protocol.hpp b/trunk/src/utest/srs_utest_protocol.hpp index 0f7282ed2..3beb890a5 100644 --- a/trunk/src/utest/srs_utest_protocol.hpp +++ b/trunk/src/utest/srs_utest_protocol.hpp @@ -49,19 +49,19 @@ public: virtual ~MockEmptyIO(); // for protocol public: - virtual bool is_never_timeout(int64_t timeout_us); + virtual bool is_never_timeout(int64_t tm); // for handshake. public: virtual int read_fully(void* buf, size_t size, ssize_t* nread); virtual int write(void* buf, size_t size, ssize_t* nwrite); // for protocol public: - virtual void set_recv_timeout(int64_t timeout_us); + virtual void set_recv_timeout(int64_t tm); virtual int64_t get_recv_timeout(); virtual int64_t get_recv_bytes(); // for protocol public: - virtual void set_send_timeout(int64_t timeout_us); + virtual void set_send_timeout(int64_t tm); virtual int64_t get_send_timeout(); virtual int64_t get_send_bytes(); virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite); @@ -73,10 +73,12 @@ public: class MockBufferIO : public ISrsProtocolReaderWriter { public: - int64_t recv_timeout; - int64_t send_timeout; - int64_t recv_bytes; - int64_t send_bytes; + // The send/recv timeout in ms. + int64_t rtm; + int64_t stm; + // The send/recv data in bytes. + int64_t rbytes; + int64_t sbytes; // data source for socket read. SrsSimpleStream in_buffer; // data buffer for socket send. @@ -86,19 +88,19 @@ public: virtual ~MockBufferIO(); // for protocol public: - virtual bool is_never_timeout(int64_t timeout_us); + virtual bool is_never_timeout(int64_t tm); // for handshake. public: virtual int read_fully(void* buf, size_t size, ssize_t* nread); virtual int write(void* buf, size_t size, ssize_t* nwrite); // for protocol public: - virtual void set_recv_timeout(int64_t timeout_us); + virtual void set_recv_timeout(int64_t tm); virtual int64_t get_recv_timeout(); virtual int64_t get_recv_bytes(); // for protocol public: - virtual void set_send_timeout(int64_t timeout_us); + virtual void set_send_timeout(int64_t tm); virtual int64_t get_send_timeout(); virtual int64_t get_send_bytes(); virtual int writev(const iovec *iov, int iov_size, ssize_t* nwrite);