From 3e81e6e0f1d96305b0c4d2baebc1be007912f0a4 Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 22 Nov 2014 18:08:45 +0800 Subject: [PATCH] refine code for bug #217, use recv thread to set the timeout. --- trunk/src/app/srs_app_recv_thread.cpp | 24 ++++++++++++++++++++++++ trunk/src/app/srs_app_recv_thread.hpp | 3 +++ trunk/src/app/srs_app_rtmp_conn.cpp | 18 ++---------------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/trunk/src/app/srs_app_recv_thread.cpp b/trunk/src/app/srs_app_recv_thread.cpp index 190adfb3f..21e6cd316 100644 --- a/trunk/src/app/srs_app_recv_thread.cpp +++ b/trunk/src/app/srs_app_recv_thread.cpp @@ -96,3 +96,27 @@ int SrsRecvThread::cycle() return ret; } +void SrsRecvThread::on_thread_start() +{ + // the multiple messages writev improve performance large, + // but the timeout recv will cause 33% sys call performance, + // to use isolate thread to recv, can improve about 33% performance. + // @see https://github.com/winlinvip/simple-rtmp-server/issues/194 + // @see: https://github.com/winlinvip/simple-rtmp-server/issues/217 + rtmp->set_recv_timeout(ST_UTIME_NO_TIMEOUT); + + // disable the protocol auto response, + // for the isolate recv thread should never send any messages. + rtmp->set_auto_response(false); +} + +void SrsRecvThread::on_thread_stop() +{ + // enable the protocol auto response, + // for the isolate recv thread terminated. + rtmp->set_auto_response(true); + + // reset the timeout to pulse mode. + rtmp->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US); +} + diff --git a/trunk/src/app/srs_app_recv_thread.hpp b/trunk/src/app/srs_app_recv_thread.hpp index 9ba671dd6..dd8886e15 100644 --- a/trunk/src/app/srs_app_recv_thread.hpp +++ b/trunk/src/app/srs_app_recv_thread.hpp @@ -59,6 +59,9 @@ public: virtual int start(); virtual void stop(); virtual int cycle(); +public: + virtual void on_thread_start(); + virtual void on_thread_stop(); }; #endif diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index 3597e2d74..0d3d6a393 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -498,21 +498,11 @@ int SrsRtmpConn::playing(SrsSource* source) { int ret = ERROR_SUCCESS; - // the multiple messages writev improve performance large, - // but the timeout recv will cause 33% sys call performance, - // to use isolate thread to recv, can improve about 33% performance. - // @see https://github.com/winlinvip/simple-rtmp-server/issues/194 + // use isolate thread to recv, // @see: https://github.com/winlinvip/simple-rtmp-server/issues/217 - //rtmp->set_recv_timeout(SRS_CONSTS_RTMP_PULSE_TIMEOUT_US); - rtmp->set_recv_timeout(ST_UTIME_NO_TIMEOUT); - - // disable the protocol auto response, - // for the isolate recv thread should never send any messages. - rtmp->set_auto_response(false); + SrsRecvThread trd(rtmp); - // use isolate thread to recv, // start isolate recv thread. - SrsRecvThread trd(rtmp); if ((ret = trd.start()) != ERROR_SUCCESS) { srs_error("start isolate recv thread failed. ret=%d", ret); return ret; @@ -524,10 +514,6 @@ int SrsRtmpConn::playing(SrsSource* source) // stop isolate recv thread trd.stop(); - // enable the protocol auto response, - // for the isolate recv thread terminated. - rtmp->set_auto_response(true); - return ret; }