diff --git a/trunk/src/core/srs_core_client.cpp b/trunk/src/core/srs_core_client.cpp index 7fb4ef5c6..3d5dc6c4d 100644 --- a/trunk/src/core/srs_core_client.cpp +++ b/trunk/src/core/srs_core_client.cpp @@ -42,11 +42,6 @@ using namespace std; #include #include -#define SRS_PULSE_TIMEOUT_MS 100 -#define SRS_SEND_TIMEOUT_US 5000000L -#define SRS_RECV_TIMEOUT_US SRS_SEND_TIMEOUT_US -#define SRS_STREAM_BUSY_SLEEP_MS 2000 - SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd) : SrsConnection(srs_server, client_stfd) { @@ -198,7 +193,7 @@ int SrsClient::service_cycle() srs_warn("stream %s is already publishing. ret=%d", req->get_stream_url().c_str(), ret); // to delay request - st_usleep(SRS_STREAM_BUSY_SLEEP_MS * 1000); + st_usleep(SRS_STREAM_BUSY_SLEEP_US); return ret; } @@ -324,12 +319,12 @@ int SrsClient::playing(SrsSource* source) SrsAutoFree(SrsConsumer, consumer, false); srs_verbose("consumer created success."); - rtmp->set_recv_timeout(SRS_PULSE_TIMEOUT_MS * 1000); + rtmp->set_recv_timeout(SRS_PULSE_TIMEOUT_US); SrsPithyPrint pithy_print(SRS_STAGE_PLAY_USER); while (true) { - pithy_print.elapse(SRS_PULSE_TIMEOUT_MS); + pithy_print.elapse(SRS_PULSE_TIMEOUT_US / 1000); // switch to other st-threads. st_usleep(0); diff --git a/trunk/src/core/srs_core_encoder.cpp b/trunk/src/core/srs_core_encoder.cpp index c56509796..95cf523ac 100644 --- a/trunk/src/core/srs_core_encoder.cpp +++ b/trunk/src/core/srs_core_encoder.cpp @@ -37,11 +37,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include +#include #ifdef SRS_FFMPEG -#define SRS_ENCODER_SLEEP_MS 2000 - #define SRS_ENCODER_COPY "copy" #define SRS_ENCODER_VCODEC "libx264" #define SRS_ENCODER_ACODEC "libaacplus" @@ -483,7 +482,7 @@ void SrsFFMPEG::stop() SrsEncoder::SrsEncoder() { - pthread = new SrsThread(this, SRS_ENCODER_SLEEP_MS); + pthread = new SrsThread(this, SRS_ENCODER_SLEEP_US); pithy_print = new SrsPithyPrint(SRS_STAGE_ENCODER); } @@ -549,7 +548,7 @@ int SrsEncoder::cycle() // pithy print encoder(); - pithy_print->elapse(SRS_ENCODER_SLEEP_MS); + pithy_print->elapse(SRS_ENCODER_SLEEP_US / 1000); return ret; } diff --git a/trunk/src/core/srs_core_forward.cpp b/trunk/src/core/srs_core_forward.cpp index 60a3541a7..98c545399 100644 --- a/trunk/src/core/srs_core_forward.cpp +++ b/trunk/src/core/srs_core_forward.cpp @@ -38,11 +38,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include -#define SRS_PULSE_TIMEOUT_MS 100 -#define SRS_FORWARDER_SLEEP_MS 2000 -#define SRS_SEND_TIMEOUT_US 3000000L -#define SRS_RECV_TIMEOUT_US SRS_SEND_TIMEOUT_US - SrsForwarder::SrsForwarder(SrsSource* _source) { source = _source; @@ -51,7 +46,7 @@ SrsForwarder::SrsForwarder(SrsSource* _source) stfd = NULL; stream_id = 0; - pthread = new SrsThread(this, SRS_FORWARDER_SLEEP_MS); + pthread = new SrsThread(this, SRS_FORWARDER_SLEEP_US); queue = new SrsMessageQueue(); jitter = new SrsRtmpJitter(); } @@ -286,7 +281,7 @@ int SrsForwarder::forward() { int ret = ERROR_SUCCESS; - client->set_recv_timeout(SRS_PULSE_TIMEOUT_MS * 1000); + client->set_recv_timeout(SRS_PULSE_TIMEOUT_US); SrsPithyPrint pithy_print(SRS_STAGE_FORWARDER); @@ -322,7 +317,7 @@ int SrsForwarder::forward() SrsAutoFree(SrsSharedPtrMessage*, msgs, true); // pithy print - pithy_print.elapse(SRS_PULSE_TIMEOUT_MS); + pithy_print.elapse(SRS_PULSE_TIMEOUT_US / 1000); if (pithy_print.can_print()) { srs_trace("-> time=%"PRId64", msgs=%d, obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d", pithy_print.get_age(), count, client->get_send_bytes(), client->get_recv_bytes(), client->get_send_kbps(), client->get_recv_kbps()); diff --git a/trunk/src/core/srs_core_protocol.cpp b/trunk/src/core/srs_core_protocol.cpp index 3d3d6138b..4de050c75 100644 --- a/trunk/src/core/srs_core_protocol.cpp +++ b/trunk/src/core/srs_core_protocol.cpp @@ -282,8 +282,6 @@ messages. /**************************************************************************** ***************************************************************************** ****************************************************************************/ -// when got a messae header, increase recv timeout to got an entire message. -#define SRS_MIN_RECV_TIMEOUT_US 3000 SrsProtocol::AckWindowSize::AckWindowSize() { diff --git a/trunk/src/core/srs_core_protocol.hpp b/trunk/src/core/srs_core_protocol.hpp index 089251709..ca6602c67 100644 --- a/trunk/src/core/srs_core_protocol.hpp +++ b/trunk/src/core/srs_core_protocol.hpp @@ -36,6 +36,37 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include +// the following is the timeout for rtmp protocol, +// to avoid death connection. + +// when got a messae header, there must be some data, +// increase recv timeout to got an entire message. +#define SRS_MIN_RECV_TIMEOUT_US 60*1000*1000L + +// 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. +#define SRS_PULSE_TIMEOUT_US 200*1000L + +// the timeout to wait client data, +// if timeout, close the connection. +#define SRS_SEND_TIMEOUT_US 30*1000*1000L + +// the timeout to send data to client, +// if timeout, close the connection. +#define SRS_RECV_TIMEOUT_US 30*1000*1000L + +// 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 3*1000*1000L + +// when error, forwarder sleep for a while and retry. +#define SRS_FORWARDER_SLEEP_US 3*1000*1000L + +// when error, encoder sleep for a while and retry. +#define SRS_ENCODER_SLEEP_US 3*1000*1000L + class SrsSocket; class SrsBuffer; class SrsPacket; diff --git a/trunk/src/core/srs_core_thread.cpp b/trunk/src/core/srs_core_thread.cpp index 61e4fb5b8..b6742f29c 100644 --- a/trunk/src/core/srs_core_thread.cpp +++ b/trunk/src/core/srs_core_thread.cpp @@ -54,10 +54,10 @@ void ISrsThreadHandler::on_leave_loop() { } -SrsThread::SrsThread(ISrsThreadHandler* thread_handler, int64_t interval_ms) +SrsThread::SrsThread(ISrsThreadHandler* thread_handler, int64_t interval_us) { handler = thread_handler; - cycle_interval_milliseconds = interval_ms; + cycle_interval_us = interval_us; tid = NULL; loop = false; @@ -143,7 +143,7 @@ failed: break; } - st_usleep(cycle_interval_milliseconds * 1000); + st_usleep(cycle_interval_us); } handler->on_leave_loop(); diff --git a/trunk/src/core/srs_core_thread.hpp b/trunk/src/core/srs_core_thread.hpp index 940ba050c..3210dcb56 100644 --- a/trunk/src/core/srs_core_thread.hpp +++ b/trunk/src/core/srs_core_thread.hpp @@ -85,14 +85,14 @@ private: bool loop; private: ISrsThreadHandler* handler; - int64_t cycle_interval_milliseconds; + int64_t cycle_interval_us; public: /** * initialize the thread. * @param thread_handler, the cycle handler for the thread. - * @param interval_ms, the sleep interval when cycle finished. + * @param interval_us, the sleep interval when cycle finished. */ - SrsThread(ISrsThreadHandler* thread_handler, int64_t interval_ms); + SrsThread(ISrsThreadHandler* thread_handler, int64_t interval_us); virtual ~SrsThread(); public: /**