winlin

change server timeout longer, recv timeout from 5s to 30s

@@ -42,11 +42,6 @@ using namespace std; @@ -42,11 +42,6 @@ using namespace std;
42 #include <srs_core_http.hpp> 42 #include <srs_core_http.hpp>
43 #include <srs_core_bandwidth.hpp> 43 #include <srs_core_bandwidth.hpp>
44 44
45 -#define SRS_PULSE_TIMEOUT_MS 100  
46 -#define SRS_SEND_TIMEOUT_US 5000000L  
47 -#define SRS_RECV_TIMEOUT_US SRS_SEND_TIMEOUT_US  
48 -#define SRS_STREAM_BUSY_SLEEP_MS 2000  
49 -  
50 SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd) 45 SrsClient::SrsClient(SrsServer* srs_server, st_netfd_t client_stfd)
51 : SrsConnection(srs_server, client_stfd) 46 : SrsConnection(srs_server, client_stfd)
52 { 47 {
@@ -198,7 +193,7 @@ int SrsClient::service_cycle() @@ -198,7 +193,7 @@ int SrsClient::service_cycle()
198 srs_warn("stream %s is already publishing. ret=%d", 193 srs_warn("stream %s is already publishing. ret=%d",
199 req->get_stream_url().c_str(), ret); 194 req->get_stream_url().c_str(), ret);
200 // to delay request 195 // to delay request
201 - st_usleep(SRS_STREAM_BUSY_SLEEP_MS * 1000); 196 + st_usleep(SRS_STREAM_BUSY_SLEEP_US);
202 return ret; 197 return ret;
203 } 198 }
204 199
@@ -324,12 +319,12 @@ int SrsClient::playing(SrsSource* source) @@ -324,12 +319,12 @@ int SrsClient::playing(SrsSource* source)
324 SrsAutoFree(SrsConsumer, consumer, false); 319 SrsAutoFree(SrsConsumer, consumer, false);
325 srs_verbose("consumer created success."); 320 srs_verbose("consumer created success.");
326 321
327 - rtmp->set_recv_timeout(SRS_PULSE_TIMEOUT_MS * 1000); 322 + rtmp->set_recv_timeout(SRS_PULSE_TIMEOUT_US);
328 323
329 SrsPithyPrint pithy_print(SRS_STAGE_PLAY_USER); 324 SrsPithyPrint pithy_print(SRS_STAGE_PLAY_USER);
330 325
331 while (true) { 326 while (true) {
332 - pithy_print.elapse(SRS_PULSE_TIMEOUT_MS); 327 + pithy_print.elapse(SRS_PULSE_TIMEOUT_US / 1000);
333 328
334 // switch to other st-threads. 329 // switch to other st-threads.
335 st_usleep(0); 330 st_usleep(0);
@@ -37,11 +37,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -37,11 +37,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 #include <srs_core_config.hpp> 37 #include <srs_core_config.hpp>
38 #include <srs_core_rtmp.hpp> 38 #include <srs_core_rtmp.hpp>
39 #include <srs_core_pithy_print.hpp> 39 #include <srs_core_pithy_print.hpp>
  40 +#include <srs_core_protocol.hpp>
40 41
41 #ifdef SRS_FFMPEG 42 #ifdef SRS_FFMPEG
42 43
43 -#define SRS_ENCODER_SLEEP_MS 2000  
44 -  
45 #define SRS_ENCODER_COPY "copy" 44 #define SRS_ENCODER_COPY "copy"
46 #define SRS_ENCODER_VCODEC "libx264" 45 #define SRS_ENCODER_VCODEC "libx264"
47 #define SRS_ENCODER_ACODEC "libaacplus" 46 #define SRS_ENCODER_ACODEC "libaacplus"
@@ -483,7 +482,7 @@ void SrsFFMPEG::stop() @@ -483,7 +482,7 @@ void SrsFFMPEG::stop()
483 482
484 SrsEncoder::SrsEncoder() 483 SrsEncoder::SrsEncoder()
485 { 484 {
486 - pthread = new SrsThread(this, SRS_ENCODER_SLEEP_MS); 485 + pthread = new SrsThread(this, SRS_ENCODER_SLEEP_US);
487 pithy_print = new SrsPithyPrint(SRS_STAGE_ENCODER); 486 pithy_print = new SrsPithyPrint(SRS_STAGE_ENCODER);
488 } 487 }
489 488
@@ -549,7 +548,7 @@ int SrsEncoder::cycle() @@ -549,7 +548,7 @@ int SrsEncoder::cycle()
549 548
550 // pithy print 549 // pithy print
551 encoder(); 550 encoder();
552 - pithy_print->elapse(SRS_ENCODER_SLEEP_MS); 551 + pithy_print->elapse(SRS_ENCODER_SLEEP_US / 1000);
553 552
554 return ret; 553 return ret;
555 } 554 }
@@ -38,11 +38,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -38,11 +38,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 #include <srs_core_source.hpp> 38 #include <srs_core_source.hpp>
39 #include <srs_core_autofree.hpp> 39 #include <srs_core_autofree.hpp>
40 40
41 -#define SRS_PULSE_TIMEOUT_MS 100  
42 -#define SRS_FORWARDER_SLEEP_MS 2000  
43 -#define SRS_SEND_TIMEOUT_US 3000000L  
44 -#define SRS_RECV_TIMEOUT_US SRS_SEND_TIMEOUT_US  
45 -  
46 SrsForwarder::SrsForwarder(SrsSource* _source) 41 SrsForwarder::SrsForwarder(SrsSource* _source)
47 { 42 {
48 source = _source; 43 source = _source;
@@ -51,7 +46,7 @@ SrsForwarder::SrsForwarder(SrsSource* _source) @@ -51,7 +46,7 @@ SrsForwarder::SrsForwarder(SrsSource* _source)
51 stfd = NULL; 46 stfd = NULL;
52 stream_id = 0; 47 stream_id = 0;
53 48
54 - pthread = new SrsThread(this, SRS_FORWARDER_SLEEP_MS); 49 + pthread = new SrsThread(this, SRS_FORWARDER_SLEEP_US);
55 queue = new SrsMessageQueue(); 50 queue = new SrsMessageQueue();
56 jitter = new SrsRtmpJitter(); 51 jitter = new SrsRtmpJitter();
57 } 52 }
@@ -286,7 +281,7 @@ int SrsForwarder::forward() @@ -286,7 +281,7 @@ int SrsForwarder::forward()
286 { 281 {
287 int ret = ERROR_SUCCESS; 282 int ret = ERROR_SUCCESS;
288 283
289 - client->set_recv_timeout(SRS_PULSE_TIMEOUT_MS * 1000); 284 + client->set_recv_timeout(SRS_PULSE_TIMEOUT_US);
290 285
291 SrsPithyPrint pithy_print(SRS_STAGE_FORWARDER); 286 SrsPithyPrint pithy_print(SRS_STAGE_FORWARDER);
292 287
@@ -322,7 +317,7 @@ int SrsForwarder::forward() @@ -322,7 +317,7 @@ int SrsForwarder::forward()
322 SrsAutoFree(SrsSharedPtrMessage*, msgs, true); 317 SrsAutoFree(SrsSharedPtrMessage*, msgs, true);
323 318
324 // pithy print 319 // pithy print
325 - pithy_print.elapse(SRS_PULSE_TIMEOUT_MS); 320 + pithy_print.elapse(SRS_PULSE_TIMEOUT_US / 1000);
326 if (pithy_print.can_print()) { 321 if (pithy_print.can_print()) {
327 srs_trace("-> time=%"PRId64", msgs=%d, obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d", 322 srs_trace("-> time=%"PRId64", msgs=%d, obytes=%"PRId64", ibytes=%"PRId64", okbps=%d, ikbps=%d",
328 pithy_print.get_age(), count, client->get_send_bytes(), client->get_recv_bytes(), client->get_send_kbps(), client->get_recv_kbps()); 323 pithy_print.get_age(), count, client->get_send_bytes(), client->get_recv_bytes(), client->get_send_kbps(), client->get_recv_kbps());
@@ -282,8 +282,6 @@ messages. @@ -282,8 +282,6 @@ messages.
282 /**************************************************************************** 282 /****************************************************************************
283 ***************************************************************************** 283 *****************************************************************************
284 ****************************************************************************/ 284 ****************************************************************************/
285 -// when got a messae header, increase recv timeout to got an entire message.  
286 -#define SRS_MIN_RECV_TIMEOUT_US 3000  
287 285
288 SrsProtocol::AckWindowSize::AckWindowSize() 286 SrsProtocol::AckWindowSize::AckWindowSize()
289 { 287 {
@@ -36,6 +36,37 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -36,6 +36,37 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 #include <srs_core_log.hpp> 36 #include <srs_core_log.hpp>
37 #include <srs_core_error.hpp> 37 #include <srs_core_error.hpp>
38 38
  39 +// the following is the timeout for rtmp protocol,
  40 +// to avoid death connection.
  41 +
  42 +// when got a messae header, there must be some data,
  43 +// increase recv timeout to got an entire message.
  44 +#define SRS_MIN_RECV_TIMEOUT_US 60*1000*1000L
  45 +
  46 +// the timeout to wait for client control message,
  47 +// if timeout, we generally ignore and send the data to client,
  48 +// generally, it's the pulse time for data seding.
  49 +#define SRS_PULSE_TIMEOUT_US 200*1000L
  50 +
  51 +// the timeout to wait client data,
  52 +// if timeout, close the connection.
  53 +#define SRS_SEND_TIMEOUT_US 30*1000*1000L
  54 +
  55 +// the timeout to send data to client,
  56 +// if timeout, close the connection.
  57 +#define SRS_RECV_TIMEOUT_US 30*1000*1000L
  58 +
  59 +// when stream is busy, for example, streaming is already
  60 +// publishing, when a new client to request to publish,
  61 +// sleep a while and close the connection.
  62 +#define SRS_STREAM_BUSY_SLEEP_US 3*1000*1000L
  63 +
  64 +// when error, forwarder sleep for a while and retry.
  65 +#define SRS_FORWARDER_SLEEP_US 3*1000*1000L
  66 +
  67 +// when error, encoder sleep for a while and retry.
  68 +#define SRS_ENCODER_SLEEP_US 3*1000*1000L
  69 +
39 class SrsSocket; 70 class SrsSocket;
40 class SrsBuffer; 71 class SrsBuffer;
41 class SrsPacket; 72 class SrsPacket;
@@ -54,10 +54,10 @@ void ISrsThreadHandler::on_leave_loop() @@ -54,10 +54,10 @@ void ISrsThreadHandler::on_leave_loop()
54 { 54 {
55 } 55 }
56 56
57 -SrsThread::SrsThread(ISrsThreadHandler* thread_handler, int64_t interval_ms) 57 +SrsThread::SrsThread(ISrsThreadHandler* thread_handler, int64_t interval_us)
58 { 58 {
59 handler = thread_handler; 59 handler = thread_handler;
60 - cycle_interval_milliseconds = interval_ms; 60 + cycle_interval_us = interval_us;
61 61
62 tid = NULL; 62 tid = NULL;
63 loop = false; 63 loop = false;
@@ -143,7 +143,7 @@ failed: @@ -143,7 +143,7 @@ failed:
143 break; 143 break;
144 } 144 }
145 145
146 - st_usleep(cycle_interval_milliseconds * 1000); 146 + st_usleep(cycle_interval_us);
147 } 147 }
148 148
149 handler->on_leave_loop(); 149 handler->on_leave_loop();
@@ -85,14 +85,14 @@ private: @@ -85,14 +85,14 @@ private:
85 bool loop; 85 bool loop;
86 private: 86 private:
87 ISrsThreadHandler* handler; 87 ISrsThreadHandler* handler;
88 - int64_t cycle_interval_milliseconds; 88 + int64_t cycle_interval_us;
89 public: 89 public:
90 /** 90 /**
91 * initialize the thread. 91 * initialize the thread.
92 * @param thread_handler, the cycle handler for the thread. 92 * @param thread_handler, the cycle handler for the thread.
93 - * @param interval_ms, the sleep interval when cycle finished. 93 + * @param interval_us, the sleep interval when cycle finished.
94 */ 94 */
95 - SrsThread(ISrsThreadHandler* thread_handler, int64_t interval_ms); 95 + SrsThread(ISrsThreadHandler* thread_handler, int64_t interval_us);
96 virtual ~SrsThread(); 96 virtual ~SrsThread();
97 public: 97 public:
98 /** 98 /**