mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
for bug #237, add name for thread. 2.0.47
This commit is contained in:
parent
c083238760
commit
c457364321
9 changed files with 30 additions and 26 deletions
|
@ -37,7 +37,7 @@ SrsConnection::SrsConnection(SrsServer* srs_server, st_netfd_t client_stfd)
|
||||||
// so we never use joinable.
|
// so we never use joinable.
|
||||||
// TODO: FIXME: maybe other thread need to stop it.
|
// TODO: FIXME: maybe other thread need to stop it.
|
||||||
// @see: https://github.com/winlinvip/simple-rtmp-server/issues/78
|
// @see: https://github.com/winlinvip/simple-rtmp-server/issues/78
|
||||||
pthread = new SrsThread(this, 0, false);
|
pthread = new SrsThread("conn", this, 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsConnection::~SrsConnection()
|
SrsConnection::~SrsConnection()
|
||||||
|
|
|
@ -69,7 +69,7 @@ SrsEdgeIngester::SrsEdgeIngester()
|
||||||
origin_index = 0;
|
origin_index = 0;
|
||||||
stream_id = 0;
|
stream_id = 0;
|
||||||
stfd = NULL;
|
stfd = NULL;
|
||||||
pthread = new SrsThread(this, SRS_EDGE_INGESTER_SLEEP_US, true);
|
pthread = new SrsThread("edge-igs", this, SRS_EDGE_INGESTER_SLEEP_US, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsEdgeIngester::~SrsEdgeIngester()
|
SrsEdgeIngester::~SrsEdgeIngester()
|
||||||
|
@ -386,7 +386,7 @@ SrsEdgeForwarder::SrsEdgeForwarder()
|
||||||
origin_index = 0;
|
origin_index = 0;
|
||||||
stream_id = 0;
|
stream_id = 0;
|
||||||
stfd = NULL;
|
stfd = NULL;
|
||||||
pthread = new SrsThread(this, SRS_EDGE_FORWARDER_SLEEP_US, true);
|
pthread = new SrsThread("edge-fwr", this, SRS_EDGE_FORWARDER_SLEEP_US, true);
|
||||||
queue = new SrsMessageQueue();
|
queue = new SrsMessageQueue();
|
||||||
send_error_code = ERROR_SUCCESS;
|
send_error_code = ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ static std::vector<std::string> _transcoded_url;
|
||||||
|
|
||||||
SrsEncoder::SrsEncoder()
|
SrsEncoder::SrsEncoder()
|
||||||
{
|
{
|
||||||
pthread = new SrsThread(this, SRS_RTMP_ENCODER_SLEEP_US, true);
|
pthread = new SrsThread("encoder", this, SRS_RTMP_ENCODER_SLEEP_US, true);
|
||||||
pithy_print = new SrsPithyPrint(SRS_CONSTS_STAGE_ENCODER);
|
pithy_print = new SrsPithyPrint(SRS_CONSTS_STAGE_ENCODER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ SrsForwarder::SrsForwarder(SrsSource* _source)
|
||||||
kbps = new SrsKbps();
|
kbps = new SrsKbps();
|
||||||
stream_id = 0;
|
stream_id = 0;
|
||||||
|
|
||||||
pthread = new SrsThread(this, SRS_FORWARDER_SLEEP_US, true);
|
pthread = new SrsThread("forward", this, SRS_FORWARDER_SLEEP_US, true);
|
||||||
queue = new SrsMessageQueue();
|
queue = new SrsMessageQueue();
|
||||||
jitter = new SrsRtmpJitter();
|
jitter = new SrsRtmpJitter();
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ using namespace std;
|
||||||
|
|
||||||
// when error, ingester sleep for a while and retry.
|
// when error, ingester sleep for a while and retry.
|
||||||
// ingest never sleep a long time, for we must start the stream ASAP.
|
// ingest never sleep a long time, for we must start the stream ASAP.
|
||||||
#define SRS_AUTO_INGESTER_SLEEP_US (int64_t)(6*100*1000LL)
|
#define SRS_AUTO_INGESTER_SLEEP_US (int64_t)(3*1000*1000LL)
|
||||||
|
|
||||||
SrsIngesterFFMPEG::SrsIngesterFFMPEG(SrsFFMPEG* _ffmpeg, string _vhost, string _id)
|
SrsIngesterFFMPEG::SrsIngesterFFMPEG(SrsFFMPEG* _ffmpeg, string _vhost, string _id)
|
||||||
{
|
{
|
||||||
|
@ -54,7 +54,7 @@ SrsIngester::SrsIngester()
|
||||||
{
|
{
|
||||||
_srs_config->subscribe(this);
|
_srs_config->subscribe(this);
|
||||||
|
|
||||||
pthread = new SrsThread(this, SRS_AUTO_INGESTER_SLEEP_US, true);
|
pthread = new SrsThread("ingest", this, SRS_AUTO_INGESTER_SLEEP_US, true);
|
||||||
pithy_print = new SrsPithyPrint(SRS_CONSTS_STAGE_INGESTER);
|
pithy_print = new SrsPithyPrint(SRS_CONSTS_STAGE_INGESTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ SrsRecvThread::SrsRecvThread(ISrsMessageHandler* msg_handler, SrsRtmpServer* rtm
|
||||||
timeout = timeout_ms;
|
timeout = timeout_ms;
|
||||||
handler = msg_handler;
|
handler = msg_handler;
|
||||||
rtmp = rtmp_sdk;
|
rtmp = rtmp_sdk;
|
||||||
trd = new SrsThread(this, 0, true);
|
trd = new SrsThread("recv", this, 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRecvThread::~SrsRecvThread()
|
SrsRecvThread::~SrsRecvThread()
|
||||||
|
|
|
@ -53,9 +53,9 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// system interval in ms,
|
// system interval in ms,
|
||||||
// all resolution times should be times togother,
|
// all resolution times should be times togother,
|
||||||
// for example, system-time is 3(300ms),
|
// for example, system-interval is x=1s(1000ms),
|
||||||
// then rusage can be 3*x, for instance, 3*10=30(3s),
|
// then rusage can be 3*x, for instance, 3*1=3s,
|
||||||
// the meminfo canbe 30*x, for instance, 30*2=60(6s)
|
// the meminfo canbe 6*x, for instance, 6*1=6s,
|
||||||
// for performance refine, @see: https://github.com/winlinvip/simple-rtmp-server/issues/194
|
// for performance refine, @see: https://github.com/winlinvip/simple-rtmp-server/issues/194
|
||||||
// @remark, recomment to 1000ms.
|
// @remark, recomment to 1000ms.
|
||||||
#define SRS_SYS_CYCLE_INTERVAL 1000
|
#define SRS_SYS_CYCLE_INTERVAL 1000
|
||||||
|
@ -63,7 +63,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// update time interval:
|
// update time interval:
|
||||||
// SRS_SYS_CYCLE_INTERVAL * SRS_SYS_TIME_RESOLUTION_MS_TIMES
|
// SRS_SYS_CYCLE_INTERVAL * SRS_SYS_TIME_RESOLUTION_MS_TIMES
|
||||||
// @see SYS_TIME_RESOLUTION_US
|
// @see SYS_TIME_RESOLUTION_US
|
||||||
#define SRS_SYS_TIME_RESOLUTION_MS_TIMES 3
|
#define SRS_SYS_TIME_RESOLUTION_MS_TIMES 1
|
||||||
|
|
||||||
// update rusage interval:
|
// update rusage interval:
|
||||||
// SRS_SYS_CYCLE_INTERVAL * SRS_SYS_RUSAGE_RESOLUTION_TIMES
|
// SRS_SYS_CYCLE_INTERVAL * SRS_SYS_RUSAGE_RESOLUTION_TIMES
|
||||||
|
@ -102,7 +102,7 @@ SrsListener::SrsListener(SrsServer* server, SrsListenerType type)
|
||||||
_server = server;
|
_server = server;
|
||||||
_type = type;
|
_type = type;
|
||||||
|
|
||||||
pthread = new SrsThread(this, 0, true);
|
pthread = new SrsThread("listen", this, 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsListener::~SrsListener()
|
SrsListener::~SrsListener()
|
||||||
|
@ -215,7 +215,7 @@ SrsSignalManager::SrsSignalManager(SrsServer* server)
|
||||||
|
|
||||||
_server = server;
|
_server = server;
|
||||||
sig_pipe[0] = sig_pipe[1] = -1;
|
sig_pipe[0] = sig_pipe[1] = -1;
|
||||||
pthread = new SrsThread(this, 0, true);
|
pthread = new SrsThread("signal", this, 0, true);
|
||||||
signal_read_stfd = NULL;
|
signal_read_stfd = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -714,7 +714,7 @@ int SrsServer::do_cycle()
|
||||||
srs_trace("reload config success.");
|
srs_trace("reload config success.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the cache time or rusage.
|
// update the cache time
|
||||||
if ((i % SRS_SYS_TIME_RESOLUTION_MS_TIMES) == 0) {
|
if ((i % SRS_SYS_TIME_RESOLUTION_MS_TIMES) == 0) {
|
||||||
srs_info("update current time cache.");
|
srs_info("update current time cache.");
|
||||||
srs_update_system_time_ms();
|
srs_update_system_time_ms();
|
||||||
|
|
|
@ -54,8 +54,9 @@ void ISrsThreadHandler::on_thread_stop()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsThread::SrsThread(ISrsThreadHandler* thread_handler, int64_t interval_us, bool joinable)
|
SrsThread::SrsThread(const char* name, ISrsThreadHandler* thread_handler, int64_t interval_us, bool joinable)
|
||||||
{
|
{
|
||||||
|
_name = name;
|
||||||
handler = thread_handler;
|
handler = thread_handler;
|
||||||
cycle_interval_us = interval_us;
|
cycle_interval_us = interval_us;
|
||||||
|
|
||||||
|
@ -86,7 +87,7 @@ int SrsThread::start()
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
if(tid) {
|
if(tid) {
|
||||||
srs_info("thread already running.");
|
srs_info("thread %s already running.", _name);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +142,7 @@ void SrsThread::thread_cycle()
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
_srs_context->generate_id();
|
_srs_context->generate_id();
|
||||||
srs_info("thread cycle start");
|
srs_info("thread %s cycle start", _name);
|
||||||
|
|
||||||
_cid = _srs_context->get_id();
|
_cid = _srs_context->get_id();
|
||||||
|
|
||||||
|
@ -155,24 +156,24 @@ void SrsThread::thread_cycle()
|
||||||
|
|
||||||
while (loop) {
|
while (loop) {
|
||||||
if ((ret = handler->on_before_cycle()) != ERROR_SUCCESS) {
|
if ((ret = handler->on_before_cycle()) != ERROR_SUCCESS) {
|
||||||
srs_warn("thread on before cycle failed, ignored and retry, ret=%d", ret);
|
srs_warn("thread %s on before cycle failed, ignored and retry, ret=%d", _name, ret);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
srs_info("thread on before cycle success");
|
srs_info("thread %s on before cycle success");
|
||||||
|
|
||||||
if ((ret = handler->cycle()) != ERROR_SUCCESS) {
|
if ((ret = handler->cycle()) != ERROR_SUCCESS) {
|
||||||
if (!srs_is_client_gracefully_close(ret)) {
|
if (!srs_is_client_gracefully_close(ret)) {
|
||||||
srs_warn("thread cycle failed, ignored and retry, ret=%d", ret);
|
srs_warn("thread cycle failed, ignored and retry, ret=%d", _name, ret);
|
||||||
}
|
}
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
srs_info("thread cycle success");
|
srs_info("thread %s cycle success", _name);
|
||||||
|
|
||||||
if ((ret = handler->on_end_cycle()) != ERROR_SUCCESS) {
|
if ((ret = handler->on_end_cycle()) != ERROR_SUCCESS) {
|
||||||
srs_warn("thread on end cycle failed, ignored and retry, ret=%d", ret);
|
srs_warn("thread %s on end cycle failed, ignored and retry, ret=%d", _name, ret);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
srs_info("thread on end cycle success");
|
srs_info("thread %s on end cycle success", _name);
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
if (!loop) {
|
if (!loop) {
|
||||||
|
@ -187,7 +188,7 @@ failed:
|
||||||
}
|
}
|
||||||
|
|
||||||
handler->on_thread_stop();
|
handler->on_thread_stop();
|
||||||
srs_info("thread cycle finished");
|
srs_info("thread %s cycle finished", _name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* SrsThread::thread_fun(void* arg)
|
void* SrsThread::thread_fun(void* arg)
|
||||||
|
|
|
@ -88,23 +88,26 @@ private:
|
||||||
bool loop;
|
bool loop;
|
||||||
bool can_run;
|
bool can_run;
|
||||||
bool _joinable;
|
bool _joinable;
|
||||||
|
const char* _name;
|
||||||
private:
|
private:
|
||||||
ISrsThreadHandler* handler;
|
ISrsThreadHandler* handler;
|
||||||
int64_t cycle_interval_us;
|
int64_t cycle_interval_us;
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* initialize the thread.
|
* initialize the thread.
|
||||||
|
* @param name, human readable name for st debug.
|
||||||
* @param thread_handler, the cycle handler for the thread.
|
* @param thread_handler, the cycle handler for the thread.
|
||||||
* @param interval_us, the sleep interval when cycle finished.
|
* @param interval_us, the sleep interval when cycle finished.
|
||||||
* @param joinable, if joinable, other thread must stop the thread.
|
* @param joinable, if joinable, other thread must stop the thread.
|
||||||
* @remark if joinable, thread never quit itself, or memory leak.
|
* @remark if joinable, thread never quit itself, or memory leak.
|
||||||
* @see: https://github.com/winlinvip/simple-rtmp-server/issues/78
|
* @see: https://github.com/winlinvip/simple-rtmp-server/issues/78
|
||||||
|
* @remark about st debug, see st-1.9/README, _st_iterate_threads_flag
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* TODO: FIXME: maybe all thread must be reap by others threads,
|
* TODO: FIXME: maybe all thread must be reap by others threads,
|
||||||
* @see: https://github.com/winlinvip/simple-rtmp-server/issues/77
|
* @see: https://github.com/winlinvip/simple-rtmp-server/issues/77
|
||||||
*/
|
*/
|
||||||
SrsThread(ISrsThreadHandler* thread_handler, int64_t interval_us, bool joinable);
|
SrsThread(const char* name, ISrsThreadHandler* thread_handler, int64_t interval_us, bool joinable);
|
||||||
virtual ~SrsThread();
|
virtual ~SrsThread();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue