正在显示
9 个修改的文件
包含
30 行增加
和
26 行删除
| @@ -37,7 +37,7 @@ SrsConnection::SrsConnection(SrsServer* srs_server, st_netfd_t client_stfd) | @@ -37,7 +37,7 @@ SrsConnection::SrsConnection(SrsServer* srs_server, st_netfd_t client_stfd) | ||
| 37 | // so we never use joinable. | 37 | // so we never use joinable. |
| 38 | // TODO: FIXME: maybe other thread need to stop it. | 38 | // TODO: FIXME: maybe other thread need to stop it. |
| 39 | // @see: https://github.com/winlinvip/simple-rtmp-server/issues/78 | 39 | // @see: https://github.com/winlinvip/simple-rtmp-server/issues/78 |
| 40 | - pthread = new SrsThread(this, 0, false); | 40 | + pthread = new SrsThread("conn", this, 0, false); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | SrsConnection::~SrsConnection() | 43 | SrsConnection::~SrsConnection() |
| @@ -69,7 +69,7 @@ SrsEdgeIngester::SrsEdgeIngester() | @@ -69,7 +69,7 @@ SrsEdgeIngester::SrsEdgeIngester() | ||
| 69 | origin_index = 0; | 69 | origin_index = 0; |
| 70 | stream_id = 0; | 70 | stream_id = 0; |
| 71 | stfd = NULL; | 71 | stfd = NULL; |
| 72 | - pthread = new SrsThread(this, SRS_EDGE_INGESTER_SLEEP_US, true); | 72 | + pthread = new SrsThread("edge-igs", this, SRS_EDGE_INGESTER_SLEEP_US, true); |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | SrsEdgeIngester::~SrsEdgeIngester() | 75 | SrsEdgeIngester::~SrsEdgeIngester() |
| @@ -386,7 +386,7 @@ SrsEdgeForwarder::SrsEdgeForwarder() | @@ -386,7 +386,7 @@ SrsEdgeForwarder::SrsEdgeForwarder() | ||
| 386 | origin_index = 0; | 386 | origin_index = 0; |
| 387 | stream_id = 0; | 387 | stream_id = 0; |
| 388 | stfd = NULL; | 388 | stfd = NULL; |
| 389 | - pthread = new SrsThread(this, SRS_EDGE_FORWARDER_SLEEP_US, true); | 389 | + pthread = new SrsThread("edge-fwr", this, SRS_EDGE_FORWARDER_SLEEP_US, true); |
| 390 | queue = new SrsMessageQueue(); | 390 | queue = new SrsMessageQueue(); |
| 391 | send_error_code = ERROR_SUCCESS; | 391 | send_error_code = ERROR_SUCCESS; |
| 392 | } | 392 | } |
| @@ -44,7 +44,7 @@ static std::vector<std::string> _transcoded_url; | @@ -44,7 +44,7 @@ static std::vector<std::string> _transcoded_url; | ||
| 44 | 44 | ||
| 45 | SrsEncoder::SrsEncoder() | 45 | SrsEncoder::SrsEncoder() |
| 46 | { | 46 | { |
| 47 | - pthread = new SrsThread(this, SRS_RTMP_ENCODER_SLEEP_US, true); | 47 | + pthread = new SrsThread("encoder", this, SRS_RTMP_ENCODER_SLEEP_US, true); |
| 48 | pithy_print = new SrsPithyPrint(SRS_CONSTS_STAGE_ENCODER); | 48 | pithy_print = new SrsPithyPrint(SRS_CONSTS_STAGE_ENCODER); |
| 49 | } | 49 | } |
| 50 | 50 |
| @@ -58,7 +58,7 @@ SrsForwarder::SrsForwarder(SrsSource* _source) | @@ -58,7 +58,7 @@ SrsForwarder::SrsForwarder(SrsSource* _source) | ||
| 58 | kbps = new SrsKbps(); | 58 | kbps = new SrsKbps(); |
| 59 | stream_id = 0; | 59 | stream_id = 0; |
| 60 | 60 | ||
| 61 | - pthread = new SrsThread(this, SRS_FORWARDER_SLEEP_US, true); | 61 | + pthread = new SrsThread("forward", this, SRS_FORWARDER_SLEEP_US, true); |
| 62 | queue = new SrsMessageQueue(); | 62 | queue = new SrsMessageQueue(); |
| 63 | jitter = new SrsRtmpJitter(); | 63 | jitter = new SrsRtmpJitter(); |
| 64 | 64 |
| @@ -36,7 +36,7 @@ using namespace std; | @@ -36,7 +36,7 @@ using namespace std; | ||
| 36 | 36 | ||
| 37 | // when error, ingester sleep for a while and retry. | 37 | // when error, ingester sleep for a while and retry. |
| 38 | // ingest never sleep a long time, for we must start the stream ASAP. | 38 | // ingest never sleep a long time, for we must start the stream ASAP. |
| 39 | -#define SRS_AUTO_INGESTER_SLEEP_US (int64_t)(6*100*1000LL) | 39 | +#define SRS_AUTO_INGESTER_SLEEP_US (int64_t)(3*1000*1000LL) |
| 40 | 40 | ||
| 41 | SrsIngesterFFMPEG::SrsIngesterFFMPEG(SrsFFMPEG* _ffmpeg, string _vhost, string _id) | 41 | SrsIngesterFFMPEG::SrsIngesterFFMPEG(SrsFFMPEG* _ffmpeg, string _vhost, string _id) |
| 42 | { | 42 | { |
| @@ -54,7 +54,7 @@ SrsIngester::SrsIngester() | @@ -54,7 +54,7 @@ SrsIngester::SrsIngester() | ||
| 54 | { | 54 | { |
| 55 | _srs_config->subscribe(this); | 55 | _srs_config->subscribe(this); |
| 56 | 56 | ||
| 57 | - pthread = new SrsThread(this, SRS_AUTO_INGESTER_SLEEP_US, true); | 57 | + pthread = new SrsThread("ingest", this, SRS_AUTO_INGESTER_SLEEP_US, true); |
| 58 | pithy_print = new SrsPithyPrint(SRS_CONSTS_STAGE_INGESTER); | 58 | pithy_print = new SrsPithyPrint(SRS_CONSTS_STAGE_INGESTER); |
| 59 | } | 59 | } |
| 60 | 60 |
| @@ -40,7 +40,7 @@ SrsRecvThread::SrsRecvThread(ISrsMessageHandler* msg_handler, SrsRtmpServer* rtm | @@ -40,7 +40,7 @@ SrsRecvThread::SrsRecvThread(ISrsMessageHandler* msg_handler, SrsRtmpServer* rtm | ||
| 40 | timeout = timeout_ms; | 40 | timeout = timeout_ms; |
| 41 | handler = msg_handler; | 41 | handler = msg_handler; |
| 42 | rtmp = rtmp_sdk; | 42 | rtmp = rtmp_sdk; |
| 43 | - trd = new SrsThread(this, 0, true); | 43 | + trd = new SrsThread("recv", this, 0, true); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | SrsRecvThread::~SrsRecvThread() | 46 | SrsRecvThread::~SrsRecvThread() |
| @@ -53,9 +53,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -53,9 +53,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 53 | 53 | ||
| 54 | // system interval in ms, | 54 | // system interval in ms, |
| 55 | // all resolution times should be times togother, | 55 | // all resolution times should be times togother, |
| 56 | -// for example, system-time is 3(300ms), | ||
| 57 | -// then rusage can be 3*x, for instance, 3*10=30(3s), | ||
| 58 | -// the meminfo canbe 30*x, for instance, 30*2=60(6s) | 56 | +// for example, system-interval is x=1s(1000ms), |
| 57 | +// then rusage can be 3*x, for instance, 3*1=3s, | ||
| 58 | +// the meminfo canbe 6*x, for instance, 6*1=6s, | ||
| 59 | // for performance refine, @see: https://github.com/winlinvip/simple-rtmp-server/issues/194 | 59 | // for performance refine, @see: https://github.com/winlinvip/simple-rtmp-server/issues/194 |
| 60 | // @remark, recomment to 1000ms. | 60 | // @remark, recomment to 1000ms. |
| 61 | #define SRS_SYS_CYCLE_INTERVAL 1000 | 61 | #define SRS_SYS_CYCLE_INTERVAL 1000 |
| @@ -63,7 +63,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -63,7 +63,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 63 | // update time interval: | 63 | // update time interval: |
| 64 | // SRS_SYS_CYCLE_INTERVAL * SRS_SYS_TIME_RESOLUTION_MS_TIMES | 64 | // SRS_SYS_CYCLE_INTERVAL * SRS_SYS_TIME_RESOLUTION_MS_TIMES |
| 65 | // @see SYS_TIME_RESOLUTION_US | 65 | // @see SYS_TIME_RESOLUTION_US |
| 66 | -#define SRS_SYS_TIME_RESOLUTION_MS_TIMES 3 | 66 | +#define SRS_SYS_TIME_RESOLUTION_MS_TIMES 1 |
| 67 | 67 | ||
| 68 | // update rusage interval: | 68 | // update rusage interval: |
| 69 | // SRS_SYS_CYCLE_INTERVAL * SRS_SYS_RUSAGE_RESOLUTION_TIMES | 69 | // SRS_SYS_CYCLE_INTERVAL * SRS_SYS_RUSAGE_RESOLUTION_TIMES |
| @@ -102,7 +102,7 @@ SrsListener::SrsListener(SrsServer* server, SrsListenerType type) | @@ -102,7 +102,7 @@ SrsListener::SrsListener(SrsServer* server, SrsListenerType type) | ||
| 102 | _server = server; | 102 | _server = server; |
| 103 | _type = type; | 103 | _type = type; |
| 104 | 104 | ||
| 105 | - pthread = new SrsThread(this, 0, true); | 105 | + pthread = new SrsThread("listen", this, 0, true); |
| 106 | } | 106 | } |
| 107 | 107 | ||
| 108 | SrsListener::~SrsListener() | 108 | SrsListener::~SrsListener() |
| @@ -215,7 +215,7 @@ SrsSignalManager::SrsSignalManager(SrsServer* server) | @@ -215,7 +215,7 @@ SrsSignalManager::SrsSignalManager(SrsServer* server) | ||
| 215 | 215 | ||
| 216 | _server = server; | 216 | _server = server; |
| 217 | sig_pipe[0] = sig_pipe[1] = -1; | 217 | sig_pipe[0] = sig_pipe[1] = -1; |
| 218 | - pthread = new SrsThread(this, 0, true); | 218 | + pthread = new SrsThread("signal", this, 0, true); |
| 219 | signal_read_stfd = NULL; | 219 | signal_read_stfd = NULL; |
| 220 | } | 220 | } |
| 221 | 221 | ||
| @@ -714,7 +714,7 @@ int SrsServer::do_cycle() | @@ -714,7 +714,7 @@ int SrsServer::do_cycle() | ||
| 714 | srs_trace("reload config success."); | 714 | srs_trace("reload config success."); |
| 715 | } | 715 | } |
| 716 | 716 | ||
| 717 | - // update the cache time or rusage. | 717 | + // update the cache time |
| 718 | if ((i % SRS_SYS_TIME_RESOLUTION_MS_TIMES) == 0) { | 718 | if ((i % SRS_SYS_TIME_RESOLUTION_MS_TIMES) == 0) { |
| 719 | srs_info("update current time cache."); | 719 | srs_info("update current time cache."); |
| 720 | srs_update_system_time_ms(); | 720 | srs_update_system_time_ms(); |
| @@ -54,8 +54,9 @@ void ISrsThreadHandler::on_thread_stop() | @@ -54,8 +54,9 @@ void ISrsThreadHandler::on_thread_stop() | ||
| 54 | { | 54 | { |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | -SrsThread::SrsThread(ISrsThreadHandler* thread_handler, int64_t interval_us, bool joinable) | 57 | +SrsThread::SrsThread(const char* name, ISrsThreadHandler* thread_handler, int64_t interval_us, bool joinable) |
| 58 | { | 58 | { |
| 59 | + _name = name; | ||
| 59 | handler = thread_handler; | 60 | handler = thread_handler; |
| 60 | cycle_interval_us = interval_us; | 61 | cycle_interval_us = interval_us; |
| 61 | 62 | ||
| @@ -86,7 +87,7 @@ int SrsThread::start() | @@ -86,7 +87,7 @@ int SrsThread::start() | ||
| 86 | int ret = ERROR_SUCCESS; | 87 | int ret = ERROR_SUCCESS; |
| 87 | 88 | ||
| 88 | if(tid) { | 89 | if(tid) { |
| 89 | - srs_info("thread already running."); | 90 | + srs_info("thread %s already running.", _name); |
| 90 | return ret; | 91 | return ret; |
| 91 | } | 92 | } |
| 92 | 93 | ||
| @@ -141,7 +142,7 @@ void SrsThread::thread_cycle() | @@ -141,7 +142,7 @@ void SrsThread::thread_cycle() | ||
| 141 | int ret = ERROR_SUCCESS; | 142 | int ret = ERROR_SUCCESS; |
| 142 | 143 | ||
| 143 | _srs_context->generate_id(); | 144 | _srs_context->generate_id(); |
| 144 | - srs_info("thread cycle start"); | 145 | + srs_info("thread %s cycle start", _name); |
| 145 | 146 | ||
| 146 | _cid = _srs_context->get_id(); | 147 | _cid = _srs_context->get_id(); |
| 147 | 148 | ||
| @@ -155,24 +156,24 @@ void SrsThread::thread_cycle() | @@ -155,24 +156,24 @@ void SrsThread::thread_cycle() | ||
| 155 | 156 | ||
| 156 | while (loop) { | 157 | while (loop) { |
| 157 | if ((ret = handler->on_before_cycle()) != ERROR_SUCCESS) { | 158 | if ((ret = handler->on_before_cycle()) != ERROR_SUCCESS) { |
| 158 | - srs_warn("thread on before cycle failed, ignored and retry, ret=%d", ret); | 159 | + srs_warn("thread %s on before cycle failed, ignored and retry, ret=%d", _name, ret); |
| 159 | goto failed; | 160 | goto failed; |
| 160 | } | 161 | } |
| 161 | - srs_info("thread on before cycle success"); | 162 | + srs_info("thread %s on before cycle success"); |
| 162 | 163 | ||
| 163 | if ((ret = handler->cycle()) != ERROR_SUCCESS) { | 164 | if ((ret = handler->cycle()) != ERROR_SUCCESS) { |
| 164 | if (!srs_is_client_gracefully_close(ret)) { | 165 | if (!srs_is_client_gracefully_close(ret)) { |
| 165 | - srs_warn("thread cycle failed, ignored and retry, ret=%d", ret); | 166 | + srs_warn("thread cycle failed, ignored and retry, ret=%d", _name, ret); |
| 166 | } | 167 | } |
| 167 | goto failed; | 168 | goto failed; |
| 168 | } | 169 | } |
| 169 | - srs_info("thread cycle success"); | 170 | + srs_info("thread %s cycle success", _name); |
| 170 | 171 | ||
| 171 | if ((ret = handler->on_end_cycle()) != ERROR_SUCCESS) { | 172 | if ((ret = handler->on_end_cycle()) != ERROR_SUCCESS) { |
| 172 | - srs_warn("thread on end cycle failed, ignored and retry, ret=%d", ret); | 173 | + srs_warn("thread %s on end cycle failed, ignored and retry, ret=%d", _name, ret); |
| 173 | goto failed; | 174 | goto failed; |
| 174 | } | 175 | } |
| 175 | - srs_info("thread on end cycle success"); | 176 | + srs_info("thread %s on end cycle success", _name); |
| 176 | 177 | ||
| 177 | failed: | 178 | failed: |
| 178 | if (!loop) { | 179 | if (!loop) { |
| @@ -187,7 +188,7 @@ failed: | @@ -187,7 +188,7 @@ failed: | ||
| 187 | } | 188 | } |
| 188 | 189 | ||
| 189 | handler->on_thread_stop(); | 190 | handler->on_thread_stop(); |
| 190 | - srs_info("thread cycle finished"); | 191 | + srs_info("thread %s cycle finished", _name); |
| 191 | } | 192 | } |
| 192 | 193 | ||
| 193 | void* SrsThread::thread_fun(void* arg) | 194 | void* SrsThread::thread_fun(void* arg) |
| @@ -88,23 +88,26 @@ private: | @@ -88,23 +88,26 @@ private: | ||
| 88 | bool loop; | 88 | bool loop; |
| 89 | bool can_run; | 89 | bool can_run; |
| 90 | bool _joinable; | 90 | bool _joinable; |
| 91 | + const char* _name; | ||
| 91 | private: | 92 | private: |
| 92 | ISrsThreadHandler* handler; | 93 | ISrsThreadHandler* handler; |
| 93 | int64_t cycle_interval_us; | 94 | int64_t cycle_interval_us; |
| 94 | public: | 95 | public: |
| 95 | /** | 96 | /** |
| 96 | * initialize the thread. | 97 | * initialize the thread. |
| 98 | + * @param name, human readable name for st debug. | ||
| 97 | * @param thread_handler, the cycle handler for the thread. | 99 | * @param thread_handler, the cycle handler for the thread. |
| 98 | * @param interval_us, the sleep interval when cycle finished. | 100 | * @param interval_us, the sleep interval when cycle finished. |
| 99 | * @param joinable, if joinable, other thread must stop the thread. | 101 | * @param joinable, if joinable, other thread must stop the thread. |
| 100 | * @remark if joinable, thread never quit itself, or memory leak. | 102 | * @remark if joinable, thread never quit itself, or memory leak. |
| 101 | * @see: https://github.com/winlinvip/simple-rtmp-server/issues/78 | 103 | * @see: https://github.com/winlinvip/simple-rtmp-server/issues/78 |
| 104 | + * @remark about st debug, see st-1.9/README, _st_iterate_threads_flag | ||
| 102 | */ | 105 | */ |
| 103 | /** | 106 | /** |
| 104 | * TODO: FIXME: maybe all thread must be reap by others threads, | 107 | * TODO: FIXME: maybe all thread must be reap by others threads, |
| 105 | * @see: https://github.com/winlinvip/simple-rtmp-server/issues/77 | 108 | * @see: https://github.com/winlinvip/simple-rtmp-server/issues/77 |
| 106 | */ | 109 | */ |
| 107 | - SrsThread(ISrsThreadHandler* thread_handler, int64_t interval_us, bool joinable); | 110 | + SrsThread(const char* name, ISrsThreadHandler* thread_handler, int64_t interval_us, bool joinable); |
| 108 | virtual ~SrsThread(); | 111 | virtual ~SrsThread(); |
| 109 | public: | 112 | public: |
| 110 | /** | 113 | /** |
-
请 注册 或 登录 后发表评论