mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Log: Use object as context id for complex context
This commit is contained in:
parent
bff7ef085d
commit
6624b8acca
34 changed files with 276 additions and 238 deletions
|
@ -201,7 +201,7 @@ srs_error_t SrsConnection::cycle()
|
|||
return srs_success;
|
||||
}
|
||||
|
||||
string SrsConnection::srs_id()
|
||||
SrsContextId SrsConnection::srs_id()
|
||||
{
|
||||
return trd->cid();
|
||||
}
|
||||
|
|
|
@ -93,7 +93,8 @@ public:
|
|||
virtual srs_error_t cycle();
|
||||
public:
|
||||
// Get the srs id which identify the client.
|
||||
virtual std::string srs_id();
|
||||
// TODO: FIXME: Rename to cid.
|
||||
virtual SrsContextId srs_id();
|
||||
// Get the remote ip of peer.
|
||||
virtual std::string remote_ip();
|
||||
// Set connection to expired.
|
||||
|
|
|
@ -533,7 +533,7 @@ srs_error_t SrsDvrMp4Segmenter::close_encoder()
|
|||
return err;
|
||||
}
|
||||
|
||||
SrsDvrAsyncCallOnDvr::SrsDvrAsyncCallOnDvr(std::string c, SrsRequest* r, string p)
|
||||
SrsDvrAsyncCallOnDvr::SrsDvrAsyncCallOnDvr(SrsContextId c, SrsRequest* r, string p)
|
||||
{
|
||||
cid = c;
|
||||
req = r->copy();
|
||||
|
@ -673,7 +673,7 @@ srs_error_t SrsDvrPlan::on_reap_segment()
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
std::string cid = _srs_context->get_id();
|
||||
SrsContextId cid = _srs_context->get_id();
|
||||
|
||||
SrsFragment* fragment = segment->current();
|
||||
string fullpath = fragment->fullpath();
|
||||
|
|
|
@ -159,11 +159,11 @@ protected:
|
|||
class SrsDvrAsyncCallOnDvr : public ISrsAsyncCallTask
|
||||
{
|
||||
private:
|
||||
std::string cid;
|
||||
SrsContextId cid;
|
||||
std::string path;
|
||||
SrsRequest* req;
|
||||
public:
|
||||
SrsDvrAsyncCallOnDvr(std::string c, SrsRequest* r, std::string p);
|
||||
SrsDvrAsyncCallOnDvr(SrsContextId c, SrsRequest* r, std::string p);
|
||||
virtual ~SrsDvrAsyncCallOnDvr();
|
||||
public:
|
||||
virtual srs_error_t call();
|
||||
|
|
|
@ -82,7 +82,7 @@ void SrsHlsSegment::config_cipher(unsigned char* key,unsigned char* iv)
|
|||
fw->config_cipher(key, iv);
|
||||
}
|
||||
|
||||
SrsDvrAsyncCallOnHls::SrsDvrAsyncCallOnHls(string c, SrsRequest* r, string p, string t, string m, string mu, int s, srs_utime_t d)
|
||||
SrsDvrAsyncCallOnHls::SrsDvrAsyncCallOnHls(SrsContextId c, SrsRequest* r, string p, string t, string m, string mu, int s, srs_utime_t d)
|
||||
{
|
||||
req = r->copy();
|
||||
cid = c;
|
||||
|
@ -137,7 +137,7 @@ string SrsDvrAsyncCallOnHls::to_string()
|
|||
return "on_hls: " + path;
|
||||
}
|
||||
|
||||
SrsDvrAsyncCallOnHlsNotify::SrsDvrAsyncCallOnHlsNotify(string c, SrsRequest* r, string u)
|
||||
SrsDvrAsyncCallOnHlsNotify::SrsDvrAsyncCallOnHlsNotify(SrsContextId c, SrsRequest* r, string u)
|
||||
{
|
||||
cid = c;
|
||||
req = r->copy();
|
||||
|
|
|
@ -80,7 +80,7 @@ public:
|
|||
class SrsDvrAsyncCallOnHls : public ISrsAsyncCallTask
|
||||
{
|
||||
private:
|
||||
std::string cid;
|
||||
SrsContextId cid;
|
||||
std::string path;
|
||||
std::string ts_url;
|
||||
std::string m3u8;
|
||||
|
@ -90,7 +90,7 @@ private:
|
|||
srs_utime_t duration;
|
||||
public:
|
||||
// TODO: FIXME: Use TBN 1000.
|
||||
SrsDvrAsyncCallOnHls(std::string c, SrsRequest* r, std::string p, std::string t, std::string m, std::string mu, int s, srs_utime_t d);
|
||||
SrsDvrAsyncCallOnHls(SrsContextId c, SrsRequest* r, std::string p, std::string t, std::string m, std::string mu, int s, srs_utime_t d);
|
||||
virtual ~SrsDvrAsyncCallOnHls();
|
||||
public:
|
||||
virtual srs_error_t call();
|
||||
|
@ -101,11 +101,11 @@ public:
|
|||
class SrsDvrAsyncCallOnHlsNotify : public ISrsAsyncCallTask
|
||||
{
|
||||
private:
|
||||
std::string cid;
|
||||
SrsContextId cid;
|
||||
std::string ts_url;
|
||||
SrsRequest* req;
|
||||
public:
|
||||
SrsDvrAsyncCallOnHlsNotify(std::string c, SrsRequest* r, std::string u);
|
||||
SrsDvrAsyncCallOnHlsNotify(SrsContextId c, SrsRequest* r, std::string u);
|
||||
virtual ~SrsDvrAsyncCallOnHlsNotify();
|
||||
public:
|
||||
virtual srs_error_t call();
|
||||
|
|
|
@ -811,10 +811,10 @@ srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
|
|||
|
||||
// path: {pattern}{client_id}
|
||||
// e.g. /api/v1/clients/100 pattern= /api/v1/clients/, client_id=100
|
||||
std::string cid = r->parse_rest_id(entry->pattern);
|
||||
std::string client_id = r->parse_rest_id(entry->pattern);
|
||||
|
||||
SrsStatisticClient* client = NULL;
|
||||
if (cid != "" && (client = stat->find_client(cid)) == NULL) {
|
||||
if (client_id != "" && (client = stat->find_client(client_id)) == NULL) {
|
||||
return srs_api_response_code(w, r, ERROR_RTMP_CLIENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
|
@ -854,7 +854,7 @@ srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
|
|||
}
|
||||
|
||||
client->conn->expire();
|
||||
srs_warn("kickoff client id=%s ok", cid.c_str());
|
||||
srs_warn("kickoff client id=%s ok", client_id.c_str());
|
||||
} else {
|
||||
return srs_go_http_error(w, SRS_CONSTS_HTTP_MethodNotAllowed);
|
||||
}
|
||||
|
|
|
@ -60,15 +60,13 @@ srs_error_t SrsHttpHooks::on_connect(string url, SrsRequest* req)
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
// TODO: FIXME: check client_id must be int?
|
||||
std::string client_id = _srs_context->get_id();
|
||||
SrsContextId cid = _srs_context->get_id();
|
||||
|
||||
SrsJsonObject* obj = SrsJsonAny::object();
|
||||
SrsAutoFree(SrsJsonObject, obj);
|
||||
|
||||
obj->set("action", SrsJsonAny::str("on_connect"));
|
||||
// obj->set("client_id", SrsJsonAny::integer(client_id));
|
||||
obj->set("client_id", SrsJsonAny::str(client_id.c_str()));
|
||||
obj->set("client_id", SrsJsonAny::str(cid.c_str()));
|
||||
obj->set("ip", SrsJsonAny::str(req->ip.c_str()));
|
||||
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str()));
|
||||
obj->set("app", SrsJsonAny::str(req->app.c_str()));
|
||||
|
@ -82,11 +80,11 @@ srs_error_t SrsHttpHooks::on_connect(string url, SrsRequest* req)
|
|||
SrsHttpClient http;
|
||||
if ((err = do_post(&http, url, data, status_code, res)) != srs_success) {
|
||||
return srs_error_wrap(err, "http: on_connect failed, client_id=%s, url=%s, request=%s, response=%s, code=%d",
|
||||
client_id.c_str(), url.c_str(), data.c_str(), res.c_str(), status_code);
|
||||
cid.c_str(), url.c_str(), data.c_str(), res.c_str(), status_code);
|
||||
}
|
||||
|
||||
srs_trace("http: on_connect ok, client_id=%s, url=%s, request=%s, response=%s",
|
||||
client_id.c_str(), url.c_str(), data.c_str(), res.c_str());
|
||||
cid.c_str(), url.c_str(), data.c_str(), res.c_str());
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -95,13 +93,13 @@ void SrsHttpHooks::on_close(string url, SrsRequest* req, int64_t send_bytes, int
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
std::string client_id = _srs_context->get_id();
|
||||
SrsContextId cid = _srs_context->get_id();
|
||||
|
||||
SrsJsonObject* obj = SrsJsonAny::object();
|
||||
SrsAutoFree(SrsJsonObject, obj);
|
||||
|
||||
obj->set("action", SrsJsonAny::str("on_close"));
|
||||
obj->set("client_id", SrsJsonAny::str(client_id.c_str()));
|
||||
obj->set("client_id", SrsJsonAny::str(cid.c_str()));
|
||||
obj->set("ip", SrsJsonAny::str(req->ip.c_str()));
|
||||
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str()));
|
||||
obj->set("app", SrsJsonAny::str(req->app.c_str()));
|
||||
|
@ -117,12 +115,12 @@ void SrsHttpHooks::on_close(string url, SrsRequest* req, int64_t send_bytes, int
|
|||
int ret = srs_error_code(err);
|
||||
srs_freep(err);
|
||||
srs_warn("http: ignore on_close failed, client_id=%s, url=%s, request=%s, response=%s, code=%d, ret=%d",
|
||||
client_id.c_str(), url.c_str(), data.c_str(), res.c_str(), status_code, ret);
|
||||
cid.c_str(), url.c_str(), data.c_str(), res.c_str(), status_code, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
srs_trace("http: on_close ok, client_id=%s, url=%s, request=%s, response=%s",
|
||||
client_id.c_str(), url.c_str(), data.c_str(), res.c_str());
|
||||
cid.c_str(), url.c_str(), data.c_str(), res.c_str());
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -131,13 +129,13 @@ srs_error_t SrsHttpHooks::on_publish(string url, SrsRequest* req)
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
std::string client_id = _srs_context->get_id();
|
||||
SrsContextId cid = _srs_context->get_id();
|
||||
|
||||
SrsJsonObject* obj = SrsJsonAny::object();
|
||||
SrsAutoFree(SrsJsonObject, obj);
|
||||
|
||||
obj->set("action", SrsJsonAny::str("on_publish"));
|
||||
obj->set("client_id", SrsJsonAny::str(client_id.c_str()));
|
||||
obj->set("client_id", SrsJsonAny::str(cid.c_str()));
|
||||
obj->set("ip", SrsJsonAny::str(req->ip.c_str()));
|
||||
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str()));
|
||||
obj->set("app", SrsJsonAny::str(req->app.c_str()));
|
||||
|
@ -152,11 +150,11 @@ srs_error_t SrsHttpHooks::on_publish(string url, SrsRequest* req)
|
|||
SrsHttpClient http;
|
||||
if ((err = do_post(&http, url, data, status_code, res)) != srs_success) {
|
||||
return srs_error_wrap(err, "http: on_publish failed, client_id=%s, url=%s, request=%s, response=%s, code=%d",
|
||||
client_id.c_str(), url.c_str(), data.c_str(), res.c_str(), status_code);
|
||||
cid.c_str(), url.c_str(), data.c_str(), res.c_str(), status_code);
|
||||
}
|
||||
|
||||
srs_trace("http: on_publish ok, client_id=%s, url=%s, request=%s, response=%s",
|
||||
client_id.c_str(), url.c_str(), data.c_str(), res.c_str());
|
||||
cid.c_str(), url.c_str(), data.c_str(), res.c_str());
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -165,13 +163,13 @@ void SrsHttpHooks::on_unpublish(string url, SrsRequest* req)
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
std::string client_id = _srs_context->get_id();
|
||||
SrsContextId cid = _srs_context->get_id();
|
||||
|
||||
SrsJsonObject* obj = SrsJsonAny::object();
|
||||
SrsAutoFree(SrsJsonObject, obj);
|
||||
|
||||
obj->set("action", SrsJsonAny::str("on_unpublish"));
|
||||
obj->set("client_id", SrsJsonAny::str(client_id.c_str()));
|
||||
obj->set("client_id", SrsJsonAny::str(cid.c_str()));
|
||||
obj->set("ip", SrsJsonAny::str(req->ip.c_str()));
|
||||
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str()));
|
||||
obj->set("app", SrsJsonAny::str(req->app.c_str()));
|
||||
|
@ -187,12 +185,12 @@ void SrsHttpHooks::on_unpublish(string url, SrsRequest* req)
|
|||
int ret = srs_error_code(err);
|
||||
srs_freep(err);
|
||||
srs_warn("http: ignore on_unpublish failed, client_id=%s, url=%s, request=%s, response=%s, status=%d, ret=%d",
|
||||
client_id.c_str(), url.c_str(), data.c_str(), res.c_str(), status_code, ret);
|
||||
cid.c_str(), url.c_str(), data.c_str(), res.c_str(), status_code, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
srs_trace("http: on_unpublish ok, client_id=%s, url=%s, request=%s, response=%s",
|
||||
client_id.c_str(), url.c_str(), data.c_str(), res.c_str());
|
||||
cid.c_str(), url.c_str(), data.c_str(), res.c_str());
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -201,13 +199,13 @@ srs_error_t SrsHttpHooks::on_play(string url, SrsRequest* req)
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
std::string client_id = _srs_context->get_id();
|
||||
SrsContextId cid = _srs_context->get_id();
|
||||
|
||||
SrsJsonObject* obj = SrsJsonAny::object();
|
||||
SrsAutoFree(SrsJsonObject, obj);
|
||||
|
||||
obj->set("action", SrsJsonAny::str("on_play"));
|
||||
obj->set("client_id", SrsJsonAny::str(client_id.c_str()));
|
||||
obj->set("client_id", SrsJsonAny::str(cid.c_str()));
|
||||
obj->set("ip", SrsJsonAny::str(req->ip.c_str()));
|
||||
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str()));
|
||||
obj->set("app", SrsJsonAny::str(req->app.c_str()));
|
||||
|
@ -222,11 +220,11 @@ srs_error_t SrsHttpHooks::on_play(string url, SrsRequest* req)
|
|||
SrsHttpClient http;
|
||||
if ((err = do_post(&http, url, data, status_code, res)) != srs_success) {
|
||||
return srs_error_wrap(err, "http: on_play failed, client_id=%s, url=%s, request=%s, response=%s, status=%d",
|
||||
client_id.c_str(), url.c_str(), data.c_str(), res.c_str(), status_code);
|
||||
cid.c_str(), url.c_str(), data.c_str(), res.c_str(), status_code);
|
||||
}
|
||||
|
||||
srs_trace("http: on_play ok, client_id=%s, url=%s, request=%s, response=%s",
|
||||
client_id.c_str(), url.c_str(), data.c_str(), res.c_str());
|
||||
cid.c_str(), url.c_str(), data.c_str(), res.c_str());
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -235,13 +233,13 @@ void SrsHttpHooks::on_stop(string url, SrsRequest* req)
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
std::string client_id = _srs_context->get_id();
|
||||
SrsContextId cid = _srs_context->get_id();
|
||||
|
||||
SrsJsonObject* obj = SrsJsonAny::object();
|
||||
SrsAutoFree(SrsJsonObject, obj);
|
||||
|
||||
obj->set("action", SrsJsonAny::str("on_stop"));
|
||||
obj->set("client_id", SrsJsonAny::str(client_id.c_str()));
|
||||
obj->set("client_id", SrsJsonAny::str(cid.c_str()));
|
||||
obj->set("ip", SrsJsonAny::str(req->ip.c_str()));
|
||||
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str()));
|
||||
obj->set("app", SrsJsonAny::str(req->app.c_str()));
|
||||
|
@ -257,28 +255,28 @@ void SrsHttpHooks::on_stop(string url, SrsRequest* req)
|
|||
int ret = srs_error_code(err);
|
||||
srs_freep(err);
|
||||
srs_warn("http: ignore on_stop failed, client_id=%s, url=%s, request=%s, response=%s, code=%d, ret=%d",
|
||||
client_id.c_str(), url.c_str(), data.c_str(), res.c_str(), status_code, ret);
|
||||
cid.c_str(), url.c_str(), data.c_str(), res.c_str(), status_code, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
srs_trace("http: on_stop ok, client_id=%s, url=%s, request=%s, response=%s",
|
||||
client_id.c_str(), url.c_str(), data.c_str(), res.c_str());
|
||||
cid.c_str(), url.c_str(), data.c_str(), res.c_str());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
srs_error_t SrsHttpHooks::on_dvr(std::string cid, string url, SrsRequest* req, string file)
|
||||
srs_error_t SrsHttpHooks::on_dvr(SrsContextId c, string url, SrsRequest* req, string file)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
std::string client_id = cid;
|
||||
SrsContextId cid = c;
|
||||
std::string cwd = _srs_config->cwd();
|
||||
|
||||
SrsJsonObject* obj = SrsJsonAny::object();
|
||||
SrsAutoFree(SrsJsonObject, obj);
|
||||
|
||||
obj->set("action", SrsJsonAny::str("on_dvr"));
|
||||
obj->set("client_id", SrsJsonAny::str(client_id.c_str()));
|
||||
obj->set("client_id", SrsJsonAny::str(cid.c_str()));
|
||||
obj->set("ip", SrsJsonAny::str(req->ip.c_str()));
|
||||
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str()));
|
||||
obj->set("app", SrsJsonAny::str(req->app.c_str()));
|
||||
|
@ -294,20 +292,20 @@ srs_error_t SrsHttpHooks::on_dvr(std::string cid, string url, SrsRequest* req, s
|
|||
SrsHttpClient http;
|
||||
if ((err = do_post(&http, url, data, status_code, res)) != srs_success) {
|
||||
return srs_error_wrap(err, "http post on_dvr uri failed, client_id=%s, url=%s, request=%s, response=%s, code=%d",
|
||||
client_id.c_str(), url.c_str(), data.c_str(), res.c_str(), status_code);
|
||||
cid.c_str(), url.c_str(), data.c_str(), res.c_str(), status_code);
|
||||
}
|
||||
|
||||
srs_trace("http hook on_dvr success. client_id=%s, url=%s, request=%s, response=%s",
|
||||
client_id.c_str(), url.c_str(), data.c_str(), res.c_str());
|
||||
cid.c_str(), url.c_str(), data.c_str(), res.c_str());
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsHttpHooks::on_hls(std::string cid, string url, SrsRequest* req, string file, string ts_url, string m3u8, string m3u8_url, int sn, srs_utime_t duration)
|
||||
srs_error_t SrsHttpHooks::on_hls(SrsContextId c, string url, SrsRequest* req, string file, string ts_url, string m3u8, string m3u8_url, int sn, srs_utime_t duration)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
std::string client_id = cid;
|
||||
SrsContextId cid = c;
|
||||
std::string cwd = _srs_config->cwd();
|
||||
|
||||
// the ts_url is under the same dir of m3u8_url.
|
||||
|
@ -320,7 +318,7 @@ srs_error_t SrsHttpHooks::on_hls(std::string cid, string url, SrsRequest* req, s
|
|||
SrsAutoFree(SrsJsonObject, obj);
|
||||
|
||||
obj->set("action", SrsJsonAny::str("on_hls"));
|
||||
obj->set("client_id", SrsJsonAny::str(client_id.c_str()));
|
||||
obj->set("client_id", SrsJsonAny::str(cid.c_str()));
|
||||
obj->set("ip", SrsJsonAny::str(req->ip.c_str()));
|
||||
obj->set("vhost", SrsJsonAny::str(req->vhost.c_str()));
|
||||
obj->set("app", SrsJsonAny::str(req->app.c_str()));
|
||||
|
@ -344,16 +342,16 @@ srs_error_t SrsHttpHooks::on_hls(std::string cid, string url, SrsRequest* req, s
|
|||
}
|
||||
|
||||
srs_trace("http: on_hls ok, client_id=%s, url=%s, request=%s, response=%s",
|
||||
client_id.c_str(), url.c_str(), data.c_str(), res.c_str());
|
||||
cid.c_str(), url.c_str(), data.c_str(), res.c_str());
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsHttpHooks::on_hls_notify(std::string cid, std::string url, SrsRequest* req, std::string ts_url, int nb_notify)
|
||||
srs_error_t SrsHttpHooks::on_hls_notify(SrsContextId c, std::string url, SrsRequest* req, std::string ts_url, int nb_notify)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
std::string client_id = cid;
|
||||
SrsContextId cid = c;
|
||||
std::string cwd = _srs_config->cwd();
|
||||
|
||||
if (srs_string_is_http(ts_url)) {
|
||||
|
@ -409,7 +407,7 @@ srs_error_t SrsHttpHooks::on_hls_notify(std::string cid, std::string url, SrsReq
|
|||
|
||||
int spenttime = (int)(srsu2ms(srs_update_system_time()) - starttime);
|
||||
srs_trace("http hook on_hls_notify success. client_id=%s, url=%s, code=%d, spent=%dms, read=%dB, err=%s",
|
||||
client_id.c_str(), url.c_str(), msg->status_code(), spenttime, nb_read, srs_error_desc(err).c_str());
|
||||
cid.c_str(), url.c_str(), msg->status_code(), spenttime, nb_read, srs_error_desc(err).c_str());
|
||||
|
||||
// ignore any error for on_hls_notify.
|
||||
srs_error_reset(err);
|
||||
|
|
|
@ -74,7 +74,7 @@ public:
|
|||
// ignore if empty.
|
||||
// @param file the file path, can be relative or absolute path.
|
||||
// @param cid the source connection cid, for the on_dvr is async call.
|
||||
static srs_error_t on_dvr(std::string cid, std::string url, SrsRequest* req, std::string file);
|
||||
static srs_error_t on_dvr(SrsContextId cid, std::string url, SrsRequest* req, std::string file);
|
||||
// When hls reap segment, callback.
|
||||
// @param url the api server url, to process the event.
|
||||
// ignore if empty.
|
||||
|
@ -85,7 +85,7 @@ public:
|
|||
// @param sn the seq_no, the sequence number of ts in hls/m3u8.
|
||||
// @param duration the segment duration in srs_utime_t.
|
||||
// @param cid the source connection cid, for the on_dvr is async call.
|
||||
static srs_error_t on_hls(std::string cid, std::string url, SrsRequest* req, std::string file, std::string ts_url,
|
||||
static srs_error_t on_hls(SrsContextId cid, std::string url, SrsRequest* req, std::string file, std::string ts_url,
|
||||
std::string m3u8, std::string m3u8_url, int sn, srs_utime_t duration);
|
||||
// When hls reap segment, callback.
|
||||
// @param url the api server url, to process the event.
|
||||
|
@ -93,7 +93,7 @@ public:
|
|||
// @param ts_url the ts uri, used to replace the variable [ts_url] in url.
|
||||
// @param nb_notify the max bytes to read from notify server.
|
||||
// @param cid the source connection cid, for the on_dvr is async call.
|
||||
static srs_error_t on_hls_notify(std::string cid, std::string url, SrsRequest* req, std::string ts_url, int nb_notify);
|
||||
static srs_error_t on_hls_notify(SrsContextId cid, std::string url, SrsRequest* req, std::string ts_url, int nb_notify);
|
||||
// Discover co-workers for origin cluster.
|
||||
static srs_error_t discover_co_workers(std::string url, std::string& host, int& port);
|
||||
private:
|
||||
|
|
|
@ -94,7 +94,7 @@ void SrsFileLog::reopen()
|
|||
open_log_file();
|
||||
}
|
||||
|
||||
void SrsFileLog::verbose(const char* tag, const char* context_id, const char* fmt, ...)
|
||||
void SrsFileLog::verbose(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelVerbose) {
|
||||
return;
|
||||
|
@ -114,7 +114,7 @@ void SrsFileLog::verbose(const char* tag, const char* context_id, const char* fm
|
|||
write_log(fd, log_data, size, SrsLogLevelVerbose);
|
||||
}
|
||||
|
||||
void SrsFileLog::info(const char* tag, const char* context_id, const char* fmt, ...)
|
||||
void SrsFileLog::info(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelInfo) {
|
||||
return;
|
||||
|
@ -134,7 +134,7 @@ void SrsFileLog::info(const char* tag, const char* context_id, const char* fmt,
|
|||
write_log(fd, log_data, size, SrsLogLevelInfo);
|
||||
}
|
||||
|
||||
void SrsFileLog::trace(const char* tag, const char* context_id, const char* fmt, ...)
|
||||
void SrsFileLog::trace(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelTrace) {
|
||||
return;
|
||||
|
@ -154,7 +154,7 @@ void SrsFileLog::trace(const char* tag, const char* context_id, const char* fmt,
|
|||
write_log(fd, log_data, size, SrsLogLevelTrace);
|
||||
}
|
||||
|
||||
void SrsFileLog::warn(const char* tag, const char* context_id, const char* fmt, ...)
|
||||
void SrsFileLog::warn(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelWarn) {
|
||||
return;
|
||||
|
@ -174,7 +174,7 @@ void SrsFileLog::warn(const char* tag, const char* context_id, const char* fmt,
|
|||
write_log(fd, log_data, size, SrsLogLevelWarn);
|
||||
}
|
||||
|
||||
void SrsFileLog::error(const char* tag, const char* context_id, const char* fmt, ...)
|
||||
void SrsFileLog::error(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelError) {
|
||||
return;
|
||||
|
|
|
@ -55,11 +55,11 @@ public:
|
|||
public:
|
||||
virtual srs_error_t initialize();
|
||||
virtual void reopen();
|
||||
virtual void verbose(const char* tag, const char* context_id, const char* fmt, ...);
|
||||
virtual void info(const char* tag, const char* context_id, const char* fmt, ...);
|
||||
virtual void trace(const char* tag, const char* context_id, const char* fmt, ...);
|
||||
virtual void warn(const char* tag, const char* context_id, const char* fmt, ...);
|
||||
virtual void error(const char* tag, const char* context_id, const char* fmt, ...);
|
||||
virtual void verbose(const char* tag, SrsContextId context_id, const char* fmt, ...);
|
||||
virtual void info(const char* tag, SrsContextId context_id, const char* fmt, ...);
|
||||
virtual void trace(const char* tag, SrsContextId context_id, const char* fmt, ...);
|
||||
virtual void warn(const char* tag, SrsContextId context_id, const char* fmt, ...);
|
||||
virtual void error(const char* tag, SrsContextId context_id, const char* fmt, ...);
|
||||
// Interface ISrsReloadHandler.
|
||||
public:
|
||||
virtual srs_error_t on_reload_utc_time();
|
||||
|
|
|
@ -180,7 +180,7 @@ srs_error_t SrsProcess::start()
|
|||
srs_info("fork process: %s", cli.c_str());
|
||||
|
||||
// for log
|
||||
std::string cid = _srs_context->get_id();
|
||||
SrsContextId cid = _srs_context->get_id();
|
||||
int ppid = getpid();
|
||||
|
||||
// TODO: fork or vfork?
|
||||
|
|
|
@ -57,7 +57,7 @@ ISrsMessagePumper::~ISrsMessagePumper()
|
|||
{
|
||||
}
|
||||
|
||||
SrsRecvThread::SrsRecvThread(ISrsMessagePumper* p, SrsRtmpServer* r, srs_utime_t tm, std::string parent_cid)
|
||||
SrsRecvThread::SrsRecvThread(ISrsMessagePumper* p, SrsRtmpServer* r, srs_utime_t tm, SrsContextId parent_cid)
|
||||
{
|
||||
rtmp = r;
|
||||
pumper = p;
|
||||
|
@ -71,7 +71,7 @@ SrsRecvThread::~SrsRecvThread()
|
|||
srs_freep(trd);
|
||||
}
|
||||
|
||||
std::string SrsRecvThread::cid()
|
||||
SrsContextId SrsRecvThread::cid()
|
||||
{
|
||||
return trd->cid();
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ srs_error_t SrsRecvThread::do_cycle()
|
|||
return err;
|
||||
}
|
||||
|
||||
SrsQueueRecvThread::SrsQueueRecvThread(SrsConsumer* consumer, SrsRtmpServer* rtmp_sdk, srs_utime_t tm, std::string parent_cid)
|
||||
SrsQueueRecvThread::SrsQueueRecvThread(SrsConsumer* consumer, SrsRtmpServer* rtmp_sdk, srs_utime_t tm, SrsContextId parent_cid)
|
||||
: trd(this, rtmp_sdk, tm, parent_cid)
|
||||
{
|
||||
_consumer = consumer;
|
||||
|
@ -278,7 +278,7 @@ void SrsQueueRecvThread::on_stop()
|
|||
}
|
||||
|
||||
SrsPublishRecvThread::SrsPublishRecvThread(SrsRtmpServer* rtmp_sdk, SrsRequest* _req,
|
||||
int mr_sock_fd, srs_utime_t tm, SrsRtmpConn* conn, SrsSource* source, std::string parent_cid)
|
||||
int mr_sock_fd, srs_utime_t tm, SrsRtmpConn* conn, SrsSource* source, SrsContextId parent_cid)
|
||||
: trd(this, rtmp_sdk, tm, parent_cid)
|
||||
{
|
||||
rtmp = rtmp_sdk;
|
||||
|
@ -290,8 +290,7 @@ SrsPublishRecvThread::SrsPublishRecvThread(SrsRtmpServer* rtmp_sdk, SrsRequest*
|
|||
_nb_msgs = 0;
|
||||
video_frames = 0;
|
||||
error = srs_cond_new();
|
||||
ncid = cid = "";
|
||||
|
||||
|
||||
req = _req;
|
||||
mr_fd = mr_sock_fd;
|
||||
|
||||
|
@ -346,7 +345,7 @@ void SrsPublishRecvThread::set_cid(std::string v)
|
|||
ncid = v;
|
||||
}
|
||||
|
||||
std::string SrsPublishRecvThread::get_cid()
|
||||
SrsContextId SrsPublishRecvThread::get_cid()
|
||||
{
|
||||
return ncid;
|
||||
}
|
||||
|
@ -374,7 +373,7 @@ srs_error_t SrsPublishRecvThread::consume(SrsCommonMessage* msg)
|
|||
srs_error_t err = srs_success;
|
||||
|
||||
// when cid changed, change it.
|
||||
if (ncid != cid) {
|
||||
if (!ncid.equals(cid)) {
|
||||
_srs_context->set_id(ncid);
|
||||
cid = ncid;
|
||||
}
|
||||
|
|
|
@ -81,16 +81,16 @@ protected:
|
|||
SrsCoroutine* trd;
|
||||
ISrsMessagePumper* pumper;
|
||||
SrsRtmpServer* rtmp;
|
||||
std::string _parent_cid;
|
||||
SrsContextId _parent_cid;
|
||||
// The recv timeout in srs_utime_t.
|
||||
srs_utime_t timeout;
|
||||
public:
|
||||
// Constructor.
|
||||
// @param tm The receive timeout in srs_utime_t.
|
||||
SrsRecvThread(ISrsMessagePumper* p, SrsRtmpServer* r, srs_utime_t tm, std::string parent_cid);
|
||||
SrsRecvThread(ISrsMessagePumper* p, SrsRtmpServer* r, srs_utime_t tm, SrsContextId parent_cid);
|
||||
virtual ~SrsRecvThread();
|
||||
public:
|
||||
virtual std::string cid();
|
||||
virtual SrsContextId cid();
|
||||
public:
|
||||
virtual srs_error_t start();
|
||||
virtual void stop();
|
||||
|
@ -117,7 +117,7 @@ private:
|
|||
SrsConsumer* _consumer;
|
||||
public:
|
||||
// TODO: FIXME: Refine timeout in time unit.
|
||||
SrsQueueRecvThread(SrsConsumer* consumer, SrsRtmpServer* rtmp_sdk, srs_utime_t tm, std::string parent_cid);
|
||||
SrsQueueRecvThread(SrsConsumer* consumer, SrsRtmpServer* rtmp_sdk, srs_utime_t tm, SrsContextId parent_cid);
|
||||
virtual ~SrsQueueRecvThread();
|
||||
public:
|
||||
virtual srs_error_t start();
|
||||
|
@ -168,11 +168,11 @@ private:
|
|||
// @see https://github.com/ossrs/srs/issues/244
|
||||
srs_cond_t error;
|
||||
// The merged context id.
|
||||
std::string cid;
|
||||
std::string ncid;
|
||||
SrsContextId cid;
|
||||
SrsContextId ncid;
|
||||
public:
|
||||
SrsPublishRecvThread(SrsRtmpServer* rtmp_sdk, SrsRequest* _req,
|
||||
int mr_sock_fd, srs_utime_t tm, SrsRtmpConn* conn, SrsSource* source, std::string parent_cid);
|
||||
int mr_sock_fd, srs_utime_t tm, SrsRtmpConn* conn, SrsSource* source, SrsContextId parent_cid);
|
||||
virtual ~SrsPublishRecvThread();
|
||||
public:
|
||||
// Wait for error for some timeout.
|
||||
|
@ -181,7 +181,7 @@ public:
|
|||
virtual uint64_t nb_video_frames();
|
||||
virtual srs_error_t error_code();
|
||||
virtual void set_cid(std::string v);
|
||||
virtual std::string get_cid();
|
||||
virtual SrsContextId get_cid();
|
||||
public:
|
||||
virtual srs_error_t start();
|
||||
virtual void stop();
|
||||
|
|
|
@ -271,7 +271,7 @@ SrsRtcOutgoingInfo::~SrsRtcOutgoingInfo()
|
|||
{
|
||||
}
|
||||
|
||||
SrsRtcPlayer::SrsRtcPlayer(SrsRtcSession* s, string parent_cid)
|
||||
SrsRtcPlayer::SrsRtcPlayer(SrsRtcSession* s, SrsContextId parent_cid)
|
||||
{
|
||||
_parent_cid = parent_cid;
|
||||
trd = new SrsDummyCoroutine();
|
||||
|
@ -345,7 +345,7 @@ srs_error_t SrsRtcPlayer::on_reload_vhost_realtime(string vhost)
|
|||
return on_reload_vhost_play(vhost);
|
||||
}
|
||||
|
||||
std::string SrsRtcPlayer::cid()
|
||||
SrsContextId SrsRtcPlayer::cid()
|
||||
{
|
||||
return trd->cid();
|
||||
}
|
||||
|
@ -1725,8 +1725,8 @@ block +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|||
|
||||
void SrsRtcPublisher::request_keyframe()
|
||||
{
|
||||
std::string scid = _srs_context->get_id();
|
||||
std::string pcid = session_->context_id();
|
||||
SrsContextId scid = _srs_context->get_id();
|
||||
SrsContextId pcid = session_->context_id();
|
||||
srs_trace("RTC play=[%d][%s] request keyframe from publish=[%d][%s]", ::getpid(), scid.c_str(), ::getpid(), pcid.c_str());
|
||||
|
||||
request_keyframe_ = true;
|
||||
|
@ -1767,7 +1767,6 @@ void SrsRtcPublisher::simulate_drop_packet(SrsRtpHeader* h, int nn_bytes)
|
|||
SrsRtcSession::SrsRtcSession(SrsRtcServer* s)
|
||||
{
|
||||
req = NULL;
|
||||
cid = "";
|
||||
is_publisher_ = false;
|
||||
encrypt = true;
|
||||
|
||||
|
@ -1860,12 +1859,12 @@ void SrsRtcSession::switch_to_context()
|
|||
_srs_context->set_id(cid);
|
||||
}
|
||||
|
||||
std::string SrsRtcSession::context_id()
|
||||
SrsContextId SrsRtcSession::context_id()
|
||||
{
|
||||
return cid;
|
||||
}
|
||||
|
||||
srs_error_t SrsRtcSession::initialize(SrsRtcSource* source, SrsRequest* r, bool is_publisher, string username, std::string context_id)
|
||||
srs_error_t SrsRtcSession::initialize(SrsRtcSource* source, SrsRequest* r, bool is_publisher, string username, SrsContextId context_id)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
|
|
|
@ -185,7 +185,7 @@ public:
|
|||
class SrsRtcPlayer : virtual public ISrsCoroutineHandler, virtual public ISrsReloadHandler
|
||||
{
|
||||
protected:
|
||||
std::string _parent_cid;
|
||||
SrsContextId _parent_cid;
|
||||
SrsCoroutine* trd;
|
||||
SrsRtcSession* session_;
|
||||
private:
|
||||
|
@ -208,7 +208,7 @@ private:
|
|||
// Whether enabled nack.
|
||||
bool nack_enabled_;
|
||||
public:
|
||||
SrsRtcPlayer(SrsRtcSession* s, std::string parent_cid);
|
||||
SrsRtcPlayer(SrsRtcSession* s, SrsContextId parent_cid);
|
||||
virtual ~SrsRtcPlayer();
|
||||
public:
|
||||
srs_error_t initialize(uint32_t vssrc, uint32_t assrc, uint16_t v_pt, uint16_t a_pt);
|
||||
|
@ -217,7 +217,7 @@ public:
|
|||
virtual srs_error_t on_reload_vhost_play(std::string vhost);
|
||||
virtual srs_error_t on_reload_vhost_realtime(std::string vhost);
|
||||
public:
|
||||
virtual std::string cid();
|
||||
virtual SrsContextId cid();
|
||||
public:
|
||||
virtual srs_error_t start();
|
||||
virtual void stop();
|
||||
|
@ -337,7 +337,7 @@ private:
|
|||
srs_utime_t last_stun_time;
|
||||
private:
|
||||
// For each RTC session, we use a specified cid for debugging logs.
|
||||
std::string cid;
|
||||
SrsContextId cid;
|
||||
// For each RTC session, whether requires encrypt.
|
||||
// Read config value, rtc_server.encrypt, default to on.
|
||||
// Sepcifies by HTTP API, query encrypt, optional.
|
||||
|
@ -372,10 +372,10 @@ public:
|
|||
std::string username();
|
||||
void set_encrypt(bool v);
|
||||
void switch_to_context();
|
||||
std::string context_id();
|
||||
SrsContextId context_id();
|
||||
public:
|
||||
// Before initialize, user must set the local SDP, which is used to inititlize DTLS.
|
||||
srs_error_t initialize(SrsRtcSource* source, SrsRequest* r, bool is_publisher, std::string username, std::string context_id);
|
||||
srs_error_t initialize(SrsRtcSource* source, SrsRequest* r, bool is_publisher, std::string username, SrsContextId context_id);
|
||||
// The peer address may change, we can identify that by STUN messages.
|
||||
srs_error_t on_stun(SrsUdpMuxSocket* skt, SrsStunPacket* r);
|
||||
srs_error_t on_dtls(char* data, int nb_data);
|
||||
|
|
|
@ -344,7 +344,7 @@ srs_error_t SrsRtcServer::create_session(
|
|||
session->set_local_sdp(local_sdp);
|
||||
session->set_state(WAITING_STUN);
|
||||
|
||||
std::string cid = _srs_context->get_id();
|
||||
SrsContextId cid = _srs_context->get_id();
|
||||
// Before session initialize, we must setup the local SDP.
|
||||
if ((err = session->initialize(source, req, publish, username, cid)) != srs_success) {
|
||||
srs_freep(session);
|
||||
|
@ -401,7 +401,7 @@ srs_error_t SrsRtcServer::setup_session2(SrsRtcSession* session, SrsRequest* req
|
|||
// TODO: FIXME: Collision detect.
|
||||
string username = session->get_local_sdp()->get_ice_ufrag() + ":" + remote_sdp.get_ice_ufrag();
|
||||
|
||||
std::string cid = _srs_context->get_id();
|
||||
SrsContextId cid = _srs_context->get_id();
|
||||
if ((err = session->initialize(source, req, false, username, cid)) != srs_success) {
|
||||
return srs_error_wrap(err, "init");
|
||||
}
|
||||
|
|
|
@ -245,7 +245,6 @@ ISrsRtcPublisher::~ISrsRtcPublisher()
|
|||
|
||||
SrsRtcSource::SrsRtcSource()
|
||||
{
|
||||
_source_id = _pre_source_id = "";
|
||||
_can_publish = true;
|
||||
rtc_publisher_ = NULL;
|
||||
|
||||
|
@ -288,17 +287,17 @@ void SrsRtcSource::update_auth(SrsRequest* r)
|
|||
req->update_auth(r);
|
||||
}
|
||||
|
||||
srs_error_t SrsRtcSource::on_source_id_changed(std::string id)
|
||||
srs_error_t SrsRtcSource::on_source_id_changed(SrsContextId id)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (_source_id == id) {
|
||||
if (_source_id.equals(id)) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (_pre_source_id == "") {
|
||||
if (_pre_source_id.empty()) {
|
||||
_pre_source_id = id;
|
||||
} else if (_pre_source_id != _source_id) {
|
||||
} else if (!_pre_source_id.equals(_source_id)) {
|
||||
_pre_source_id = _source_id;
|
||||
}
|
||||
|
||||
|
@ -314,12 +313,12 @@ srs_error_t SrsRtcSource::on_source_id_changed(std::string id)
|
|||
return err;
|
||||
}
|
||||
|
||||
std::string SrsRtcSource::source_id()
|
||||
SrsContextId SrsRtcSource::source_id()
|
||||
{
|
||||
return _source_id;
|
||||
}
|
||||
|
||||
std::string SrsRtcSource::pre_source_id()
|
||||
SrsContextId SrsRtcSource::pre_source_id()
|
||||
{
|
||||
return _pre_source_id;
|
||||
}
|
||||
|
@ -395,7 +394,7 @@ void SrsRtcSource::on_unpublish()
|
|||
srs_trace("cleanup when unpublish");
|
||||
|
||||
_can_publish = true;
|
||||
_source_id = -1;
|
||||
_source_id = SrsContextId();
|
||||
|
||||
// TODO: FIXME: Handle by statistic.
|
||||
}
|
||||
|
|
|
@ -109,9 +109,9 @@ private:
|
|||
// For edge, it's the edge ingest id.
|
||||
// when source id changed, for example, the edge reconnect,
|
||||
// invoke the on_source_id_changed() to let all clients know.
|
||||
std::string _source_id;
|
||||
SrsContextId _source_id;
|
||||
// previous source id.
|
||||
std::string _pre_source_id;
|
||||
SrsContextId _pre_source_id;
|
||||
SrsRequest* req;
|
||||
ISrsRtcPublisher* rtc_publisher_;
|
||||
// Transmux RTMP to RTC.
|
||||
|
@ -129,10 +129,10 @@ public:
|
|||
// Update the authentication information in request.
|
||||
virtual void update_auth(SrsRequest* r);
|
||||
// The source id changed.
|
||||
virtual srs_error_t on_source_id_changed(std::string id);
|
||||
virtual srs_error_t on_source_id_changed(SrsContextId id);
|
||||
// Get current source id.
|
||||
virtual std::string source_id();
|
||||
virtual std::string pre_source_id();
|
||||
virtual SrsContextId source_id();
|
||||
virtual SrsContextId pre_source_id();
|
||||
// Get the bridger.
|
||||
ISrsSourceBridger* bridger();
|
||||
public:
|
||||
|
|
|
@ -1792,7 +1792,7 @@ void SrsSourceManager::dispose()
|
|||
|
||||
srs_error_t SrsSourceManager::cycle()
|
||||
{
|
||||
std::string cid = _srs_context->get_id();
|
||||
SrsContextId cid = _srs_context->get_id();
|
||||
srs_error_t err = do_cycle();
|
||||
_srs_context->set_id(cid);
|
||||
|
||||
|
@ -1866,7 +1866,6 @@ SrsSource::SrsSource()
|
|||
mix_queue = new SrsMixQueue();
|
||||
|
||||
_can_publish = true;
|
||||
_pre_source_id = _source_id = "";
|
||||
die_at = 0;
|
||||
|
||||
handler = NULL;
|
||||
|
@ -2065,17 +2064,17 @@ srs_error_t SrsSource::on_reload_vhost_play(string vhost)
|
|||
return err;
|
||||
}
|
||||
|
||||
srs_error_t SrsSource::on_source_id_changed(string id)
|
||||
srs_error_t SrsSource::on_source_id_changed(SrsContextId id)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
if (_source_id == id) {
|
||||
if (_source_id.equals(id)) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (_pre_source_id == "") {
|
||||
if (_pre_source_id.empty()) {
|
||||
_pre_source_id = id;
|
||||
} else if (_pre_source_id != _source_id) {
|
||||
} else if (!_pre_source_id.equals(_source_id)) {
|
||||
_pre_source_id = _source_id;
|
||||
}
|
||||
|
||||
|
@ -2091,12 +2090,12 @@ srs_error_t SrsSource::on_source_id_changed(string id)
|
|||
return err;
|
||||
}
|
||||
|
||||
string SrsSource::source_id()
|
||||
SrsContextId SrsSource::source_id()
|
||||
{
|
||||
return _source_id;
|
||||
}
|
||||
|
||||
string SrsSource::pre_source_id()
|
||||
SrsContextId SrsSource::pre_source_id()
|
||||
{
|
||||
return _pre_source_id;
|
||||
}
|
||||
|
@ -2560,7 +2559,7 @@ void SrsSource::on_unpublish()
|
|||
srs_trace("cleanup when unpublish");
|
||||
|
||||
_can_publish = true;
|
||||
_source_id = -1;
|
||||
_source_id = SrsContextId();
|
||||
|
||||
// notify the handler.
|
||||
srs_assert(handler);
|
||||
|
|
|
@ -508,9 +508,9 @@ private:
|
|||
// For edge, it's the edge ingest id.
|
||||
// when source id changed, for example, the edge reconnect,
|
||||
// invoke the on_source_id_changed() to let all clients know.
|
||||
std::string _source_id;
|
||||
SrsContextId _source_id;
|
||||
// previous source id.
|
||||
std::string _pre_source_id;
|
||||
SrsContextId _pre_source_id;
|
||||
// deep copy of client request.
|
||||
SrsRequest* req;
|
||||
// To delivery stream to clients.
|
||||
|
@ -567,10 +567,10 @@ public:
|
|||
virtual srs_error_t on_reload_vhost_play(std::string vhost);
|
||||
public:
|
||||
// The source id changed.
|
||||
virtual srs_error_t on_source_id_changed(std::string id);
|
||||
virtual srs_error_t on_source_id_changed(SrsContextId id);
|
||||
// Get current source id.
|
||||
virtual std::string source_id();
|
||||
virtual std::string pre_source_id();
|
||||
virtual SrsContextId source_id();
|
||||
virtual SrsContextId pre_source_id();
|
||||
// Whether source is inactive, which means there is no publishing stream source.
|
||||
// @remark For edge, it's inactive util stream has been pulled from origin.
|
||||
virtual bool inactive();
|
||||
|
|
|
@ -74,18 +74,27 @@ srs_error_t SrsDummyCoroutine::pull()
|
|||
return srs_error_new(ERROR_THREAD_DUMMY, "dummy pull");
|
||||
}
|
||||
|
||||
string SrsDummyCoroutine::cid()
|
||||
SrsContextId SrsDummyCoroutine::cid()
|
||||
{
|
||||
return "";
|
||||
return SrsContextId();
|
||||
}
|
||||
|
||||
_ST_THREAD_CREATE_PFN _pfn_st_thread_create = (_ST_THREAD_CREATE_PFN)st_thread_create;
|
||||
|
||||
SrsSTCoroutine::SrsSTCoroutine(string n, ISrsCoroutineHandler* h, std::string cid)
|
||||
SrsSTCoroutine::SrsSTCoroutine(string n, ISrsCoroutineHandler* h)
|
||||
{
|
||||
name = n;
|
||||
handler = h;
|
||||
context = cid;
|
||||
trd = NULL;
|
||||
trd_err = srs_success;
|
||||
started = interrupted = disposed = cycle_done = false;
|
||||
}
|
||||
|
||||
SrsSTCoroutine::SrsSTCoroutine(string n, ISrsCoroutineHandler* h, SrsContextId cid)
|
||||
{
|
||||
name = n;
|
||||
handler = h;
|
||||
cid_ = cid;
|
||||
trd = NULL;
|
||||
trd_err = srs_success;
|
||||
started = interrupted = disposed = cycle_done = false;
|
||||
|
@ -180,18 +189,18 @@ srs_error_t SrsSTCoroutine::pull()
|
|||
return srs_error_copy(trd_err);
|
||||
}
|
||||
|
||||
string SrsSTCoroutine::cid()
|
||||
SrsContextId SrsSTCoroutine::cid()
|
||||
{
|
||||
return context;
|
||||
return cid_;
|
||||
}
|
||||
|
||||
srs_error_t SrsSTCoroutine::cycle()
|
||||
{
|
||||
if (_srs_context) {
|
||||
if (!context.empty()) {
|
||||
_srs_context->set_id(context);
|
||||
if (!cid_.empty()) {
|
||||
_srs_context->set_id(cid_);
|
||||
} else {
|
||||
context = _srs_context->generate_id();
|
||||
cid_ = _srs_context->generate_id();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include <srs_kernel_log.hpp>
|
||||
#include <srs_service_st.hpp>
|
||||
#include <srs_protocol_io.hpp>
|
||||
|
||||
|
@ -80,7 +81,7 @@ public:
|
|||
// @return a copy of error, which should be freed by user.
|
||||
// NULL if not terminated and user should pull again.
|
||||
virtual srs_error_t pull() = 0;
|
||||
virtual std::string cid() = 0;
|
||||
virtual SrsContextId cid() = 0;
|
||||
};
|
||||
|
||||
// An empty coroutine, user can default to this object before create any real coroutine.
|
||||
|
@ -95,7 +96,7 @@ public:
|
|||
virtual void stop();
|
||||
virtual void interrupt();
|
||||
virtual srs_error_t pull();
|
||||
virtual std::string cid();
|
||||
virtual SrsContextId cid();
|
||||
};
|
||||
|
||||
// For utest to mock the thread create.
|
||||
|
@ -121,7 +122,7 @@ private:
|
|||
ISrsCoroutineHandler* handler;
|
||||
private:
|
||||
srs_thread_t trd;
|
||||
std::string context;
|
||||
SrsContextId cid_;
|
||||
srs_error_t trd_err;
|
||||
private:
|
||||
bool started;
|
||||
|
@ -132,7 +133,8 @@ private:
|
|||
public:
|
||||
// Create a thread with name n and handler h.
|
||||
// @remark User can specify a cid for thread to use, or we will allocate a new one.
|
||||
SrsSTCoroutine(std::string n, ISrsCoroutineHandler* h, std::string cid = "");
|
||||
SrsSTCoroutine(std::string n, ISrsCoroutineHandler* h);
|
||||
SrsSTCoroutine(std::string n, ISrsCoroutineHandler* h, SrsContextId cid);
|
||||
virtual ~SrsSTCoroutine();
|
||||
public:
|
||||
// Start the thread.
|
||||
|
@ -154,7 +156,7 @@ public:
|
|||
// @remark Return ERROR_THREAD_INTERRUPED when thread is interrupted.
|
||||
virtual srs_error_t pull();
|
||||
// Get the context id of thread.
|
||||
virtual std::string cid();
|
||||
virtual SrsContextId cid();
|
||||
private:
|
||||
virtual srs_error_t cycle();
|
||||
static void* pfn(void* arg);
|
||||
|
|
|
@ -101,8 +101,7 @@ SrsStatisticStream::SrsStatisticStream()
|
|||
id = srs_generate_id();
|
||||
vhost = NULL;
|
||||
active = false;
|
||||
connection_cid = -1;
|
||||
|
||||
|
||||
has_video = false;
|
||||
vcodec = SrsVideoCodecIdReserved;
|
||||
avc_profile = SrsAvcProfileReserved;
|
||||
|
@ -184,7 +183,7 @@ srs_error_t SrsStatisticStream::dumps(SrsJsonObject* obj)
|
|||
return err;
|
||||
}
|
||||
|
||||
void SrsStatisticStream::publish(string cid)
|
||||
void SrsStatisticStream::publish(SrsContextId cid)
|
||||
{
|
||||
connection_cid = cid;
|
||||
active = true;
|
||||
|
@ -337,10 +336,10 @@ SrsStatisticStream* SrsStatistic::find_stream(string sid)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SrsStatisticClient* SrsStatistic::find_client(string cid)
|
||||
SrsStatisticClient* SrsStatistic::find_client(string client_id)
|
||||
{
|
||||
std::map<std::string, SrsStatisticClient*>::iterator it;
|
||||
if ((it = clients.find(cid)) != clients.end()) {
|
||||
if ((it = clients.find(client_id)) != clients.end()) {
|
||||
return it->second;
|
||||
}
|
||||
return NULL;
|
||||
|
@ -392,7 +391,7 @@ srs_error_t SrsStatistic::on_video_frames(SrsRequest* req, int nb_frames)
|
|||
return err;
|
||||
}
|
||||
|
||||
void SrsStatistic::on_stream_publish(SrsRequest* req, string cid)
|
||||
void SrsStatistic::on_stream_publish(SrsRequest* req, SrsContextId cid)
|
||||
{
|
||||
SrsStatisticVhost* vhost = create_vhost(req);
|
||||
SrsStatisticStream* stream = create_stream(vhost, req);
|
||||
|
@ -423,10 +422,13 @@ void SrsStatistic::on_stream_close(SrsRequest* req)
|
|||
}
|
||||
}
|
||||
|
||||
srs_error_t SrsStatistic::on_client(std::string id, SrsRequest* req, SrsConnection* conn, SrsRtmpConnType type)
|
||||
srs_error_t SrsStatistic::on_client(SrsContextId cid, SrsRequest* req, SrsConnection* conn, SrsRtmpConnType type)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
|
||||
// TODO: FIXME: We should use UUID for client ID.
|
||||
std::string id = cid.c_str();
|
||||
|
||||
SrsStatisticVhost* vhost = create_vhost(req);
|
||||
SrsStatisticStream* stream = create_stream(vhost, req);
|
||||
|
||||
|
@ -451,8 +453,11 @@ srs_error_t SrsStatistic::on_client(std::string id, SrsRequest* req, SrsConnecti
|
|||
return err;
|
||||
}
|
||||
|
||||
void SrsStatistic::on_disconnect(std::string id)
|
||||
void SrsStatistic::on_disconnect(SrsContextId cid)
|
||||
{
|
||||
// TODO: FIXME: We should use UUID for client ID.
|
||||
std::string id = cid.c_str();
|
||||
|
||||
std::map<std::string, SrsStatisticClient*>::iterator it;
|
||||
if ((it = clients.find(id)) == clients.end()) {
|
||||
return;
|
||||
|
@ -471,7 +476,8 @@ void SrsStatistic::on_disconnect(std::string id)
|
|||
|
||||
void SrsStatistic::kbps_add_delta(SrsConnection* conn)
|
||||
{
|
||||
std::string id = conn->srs_id();
|
||||
// TODO: FIXME: Should not use context id as connection id.
|
||||
std::string id = conn->srs_id().c_str();
|
||||
if (clients.find(id) == clients.end()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ public:
|
|||
std::string stream;
|
||||
std::string url;
|
||||
bool active;
|
||||
std::string connection_cid;
|
||||
SrsContextId connection_cid;
|
||||
int nb_clients;
|
||||
uint64_t nb_frames;
|
||||
public:
|
||||
|
@ -101,7 +101,7 @@ public:
|
|||
virtual srs_error_t dumps(SrsJsonObject* obj);
|
||||
public:
|
||||
// Publish the stream.
|
||||
virtual void publish(std::string cid);
|
||||
virtual void publish(SrsContextId cid);
|
||||
// Close the stream.
|
||||
virtual void close();
|
||||
};
|
||||
|
@ -181,7 +181,7 @@ public:
|
|||
public:
|
||||
virtual SrsStatisticVhost* find_vhost(std::string vid);
|
||||
virtual SrsStatisticStream* find_stream(std::string sid);
|
||||
virtual SrsStatisticClient* find_client(std::string cid);
|
||||
virtual SrsStatisticClient* find_client(std::string client_id);
|
||||
public:
|
||||
// When got video info for stream.
|
||||
virtual srs_error_t on_video_info(SrsRequest* req, SrsVideoCodecId vcodec, SrsAvcProfile avc_profile,
|
||||
|
@ -195,7 +195,7 @@ public:
|
|||
// When publish stream.
|
||||
// @param req the request object of publish connection.
|
||||
// @param cid the cid of publish connection.
|
||||
virtual void on_stream_publish(SrsRequest* req, std::string cid);
|
||||
virtual void on_stream_publish(SrsRequest* req, SrsContextId cid);
|
||||
// When close stream.
|
||||
virtual void on_stream_close(SrsRequest* req);
|
||||
public:
|
||||
|
@ -204,12 +204,14 @@ public:
|
|||
// @param req, the client request object.
|
||||
// @param conn, the physical absract connection object.
|
||||
// @param type, the type of connection.
|
||||
virtual srs_error_t on_client(std::string id, SrsRequest* req, SrsConnection* conn, SrsRtmpConnType type);
|
||||
// TODO: FIXME: We should not use context id as client id.
|
||||
virtual srs_error_t on_client(SrsContextId id, SrsRequest* req, SrsConnection* conn, SrsRtmpConnType type);
|
||||
// Client disconnect
|
||||
// @remark the on_disconnect always call, while the on_client is call when
|
||||
// only got the request object, so the client specified by id maybe not
|
||||
// exists in stat.
|
||||
virtual void on_disconnect(std::string id);
|
||||
// TODO: FIXME: We should not use context id as client id.
|
||||
virtual void on_disconnect(SrsContextId id);
|
||||
// Sample the kbps, add delta bytes of conn.
|
||||
// Use kbps_sample() to get all result of kbps stat.
|
||||
// TODO: FIXME: the add delta must use ISrsKbpsDelta interface instead.
|
||||
|
|
|
@ -113,4 +113,29 @@
|
|||
class SrsCplxError;
|
||||
typedef SrsCplxError* srs_error_t;
|
||||
|
||||
// The context ID, it default to a string object, we can also use other objects.
|
||||
#include <string>
|
||||
struct _SrsContextId
|
||||
{
|
||||
std::string v_;
|
||||
_SrsContextId() {
|
||||
}
|
||||
_SrsContextId(std::string v) {
|
||||
v_ = v;
|
||||
}
|
||||
_SrsContextId(const _SrsContextId& cp) {
|
||||
v_ = cp.v_;
|
||||
}
|
||||
const char* c_str() {
|
||||
return v_.c_str();
|
||||
}
|
||||
bool empty() {
|
||||
return v_.empty();
|
||||
}
|
||||
bool equals(const _SrsContextId& to) {
|
||||
return v_ == to.v_;
|
||||
}
|
||||
};
|
||||
typedef _SrsContextId SrsContextId;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -57,7 +57,7 @@ SrsCplxError::SrsCplxError()
|
|||
{
|
||||
code = ERROR_SUCCESS;
|
||||
wrapped = NULL;
|
||||
cid = rerrno = line = 0;
|
||||
rerrno = line = 0;
|
||||
}
|
||||
|
||||
SrsCplxError::~SrsCplxError()
|
||||
|
@ -79,7 +79,7 @@ std::string SrsCplxError::description() {
|
|||
|
||||
next = this;
|
||||
while (next) {
|
||||
ss << "thread [" << getpid() << "][" << next->cid << "]: "
|
||||
ss << "thread [" << getpid() << "][" << next->cid.c_str() << "]: "
|
||||
<< next->func << "() [" << next->file << ":" << next->line << "]"
|
||||
<< "[errno=" << next->rerrno << "]";
|
||||
|
||||
|
|
|
@ -414,7 +414,7 @@ private:
|
|||
std::string file;
|
||||
int line;
|
||||
|
||||
std::string cid;
|
||||
SrsContextId cid;
|
||||
int rerrno;
|
||||
|
||||
std::string desc;
|
||||
|
|
|
@ -65,24 +65,24 @@ public:
|
|||
virtual void reopen() = 0;
|
||||
public:
|
||||
// The log for verbose, very verbose information.
|
||||
virtual void verbose(const char* tag, const char* context_id, const char* fmt, ...) = 0;
|
||||
virtual void verbose(const char* tag, SrsContextId context_id, const char* fmt, ...) = 0;
|
||||
// The log for debug, detail information.
|
||||
virtual void info(const char* tag, const char* context_id, const char* fmt, ...) = 0;
|
||||
virtual void info(const char* tag, SrsContextId context_id, const char* fmt, ...) = 0;
|
||||
// The log for trace, important information.
|
||||
virtual void trace(const char* tag, const char* context_id, const char* fmt, ...) = 0;
|
||||
virtual void trace(const char* tag, SrsContextId context_id, const char* fmt, ...) = 0;
|
||||
// The log for warn, warn is something should take attention, but not a error.
|
||||
virtual void warn(const char* tag, const char* context_id, const char* fmt, ...) = 0;
|
||||
virtual void warn(const char* tag, SrsContextId context_id, const char* fmt, ...) = 0;
|
||||
// The log for error, something error occur, do something about the error, ie. close the connection,
|
||||
// but we will donot abort the program.
|
||||
virtual void error(const char* tag, const char* context_id, const char* fmt, ...) = 0;
|
||||
virtual void error(const char* tag, SrsContextId context_id, const char* fmt, ...) = 0;
|
||||
};
|
||||
|
||||
// The logic context for a RTMP connection, or RTC Session.
|
||||
// The logic context, for example, a RTMP connection, or RTC Session, etc.
|
||||
// We can grep the context id to identify the logic unit, for debugging.
|
||||
// For example:
|
||||
// _srs_context->generate_id(); // Generate a new context.
|
||||
// _srs_context->get_id(); // Get current context.
|
||||
// int old_id = _srs_context->set_id("1000"); // Change the context.
|
||||
// _srs_context->generate_id(); // Generate a new context id.
|
||||
// _srs_context->get_id(); // Get current context id.
|
||||
// int old_id = _srs_context->set_id("1000"); // Change the context id.
|
||||
class ISrsContext
|
||||
{
|
||||
public:
|
||||
|
@ -90,12 +90,12 @@ public:
|
|||
virtual ~ISrsContext();
|
||||
public:
|
||||
// Generate the id for current context.
|
||||
virtual std::string generate_id() = 0;
|
||||
virtual SrsContextId generate_id() = 0;
|
||||
// Get the generated id of current context.
|
||||
virtual std::string get_id() = 0;
|
||||
virtual SrsContextId get_id() = 0;
|
||||
// Set the id of current context.
|
||||
// @return the previous id value; 0 if no context.
|
||||
virtual std::string set_id(std::string v) = 0;
|
||||
virtual SrsContextId set_id(SrsContextId v) = 0;
|
||||
};
|
||||
|
||||
// @global User must provides a log object
|
||||
|
@ -108,25 +108,25 @@ extern ISrsContext* _srs_context;
|
|||
// Use __FUNCTION__ to print c method
|
||||
// Use __PRETTY_FUNCTION__ to print c++ class:method
|
||||
#if 1
|
||||
#define srs_verbose(msg, ...) _srs_log->verbose(NULL, _srs_context->get_id().c_str(), msg, ##__VA_ARGS__)
|
||||
#define srs_info(msg, ...) _srs_log->info(NULL, _srs_context->get_id().c_str(), msg, ##__VA_ARGS__)
|
||||
#define srs_trace(msg, ...) _srs_log->trace(NULL, _srs_context->get_id().c_str(), msg, ##__VA_ARGS__)
|
||||
#define srs_warn(msg, ...) _srs_log->warn(NULL, _srs_context->get_id().c_str(), msg, ##__VA_ARGS__)
|
||||
#define srs_error(msg, ...) _srs_log->error(NULL, _srs_context->get_id().c_str(), msg, ##__VA_ARGS__)
|
||||
#define srs_verbose(msg, ...) _srs_log->verbose(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_info(msg, ...) _srs_log->info(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_trace(msg, ...) _srs_log->trace(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_warn(msg, ...) _srs_log->warn(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_error(msg, ...) _srs_log->error(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#endif
|
||||
#if 0
|
||||
#define srs_verbose(msg, ...) _srs_log->verbose(__FUNCTION__, _srs_context->get_id().c_str(), msg, ##__VA_ARGS__)
|
||||
#define srs_info(msg, ...) _srs_log->info(__FUNCTION__, _srs_context->get_id().c_str(), msg, ##__VA_ARGS__)
|
||||
#define srs_trace(msg, ...) _srs_log->trace(__FUNCTION__, _srs_context->get_id().c_str(), msg, ##__VA_ARGS__)
|
||||
#define srs_warn(msg, ...) _srs_log->warn(__FUNCTION__, _srs_context->get_id().c_str(), msg, ##__VA_ARGS__)
|
||||
#define srs_error(msg, ...) _srs_log->error(__FUNCTION__, _srs_context->get_id().c_str(), msg, ##__VA_ARGS__)
|
||||
#define srs_verbose(msg, ...) _srs_log->verbose(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_info(msg, ...) _srs_log->info(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_trace(msg, ...) _srs_log->trace(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_warn(msg, ...) _srs_log->warn(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_error(msg, ...) _srs_log->error(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#endif
|
||||
#if 0
|
||||
#define srs_verbose(msg, ...) _srs_log->verbose(__PRETTY_FUNCTION__, _srs_context->get_id().c_str(), msg, ##__VA_ARGS__)
|
||||
#define srs_info(msg, ...) _srs_log->info(__PRETTY_FUNCTION__, _srs_context->get_id().c_str(), msg, ##__VA_ARGS__)
|
||||
#define srs_trace(msg, ...) _srs_log->trace(__PRETTY_FUNCTION__, _srs_context->get_id().c_str(), msg, ##__VA_ARGS__)
|
||||
#define srs_warn(msg, ...) _srs_log->warn(__PRETTY_FUNCTION__, _srs_context->get_id().c_str(), msg, ##__VA_ARGS__)
|
||||
#define srs_error(msg, ...) _srs_log->error(__PRETTY_FUNCTION__, _srs_context->get_id().c_str(), msg, ##__VA_ARGS__)
|
||||
#define srs_verbose(msg, ...) _srs_log->verbose(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_info(msg, ...) _srs_log->info(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_trace(msg, ...) _srs_log->trace(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_warn(msg, ...) _srs_log->warn(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#define srs_error(msg, ...) _srs_log->error(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
// TODO: FIXME: Add more verbose and info logs.
|
||||
|
|
|
@ -42,7 +42,7 @@ SrsThreadContext::~SrsThreadContext()
|
|||
{
|
||||
}
|
||||
|
||||
string SrsThreadContext::generate_id()
|
||||
SrsContextId SrsThreadContext::generate_id()
|
||||
{
|
||||
static int id = 0;
|
||||
|
||||
|
@ -51,22 +51,21 @@ string SrsThreadContext::generate_id()
|
|||
}
|
||||
int gid = id++;
|
||||
|
||||
stringstream ss;
|
||||
ss << gid;
|
||||
cache[srs_thread_self()] = ss.str();
|
||||
return ss.str();
|
||||
SrsContextId cid = SrsContextId(srs_int2str(gid));
|
||||
cache[srs_thread_self()] = cid;
|
||||
return cid;
|
||||
}
|
||||
|
||||
string SrsThreadContext::get_id()
|
||||
SrsContextId SrsThreadContext::get_id()
|
||||
{
|
||||
return cache[srs_thread_self()];
|
||||
}
|
||||
|
||||
string SrsThreadContext::set_id(string v)
|
||||
SrsContextId SrsThreadContext::set_id(SrsContextId v)
|
||||
{
|
||||
srs_thread_t self = srs_thread_self();
|
||||
|
||||
string ov;
|
||||
SrsContextId ov;
|
||||
if (cache.find(self) != cache.end()) {
|
||||
ov = cache[self];
|
||||
}
|
||||
|
@ -79,7 +78,7 @@ string SrsThreadContext::set_id(string v)
|
|||
void SrsThreadContext::clear_cid()
|
||||
{
|
||||
srs_thread_t self = srs_thread_self();
|
||||
std::map<srs_thread_t, string>::iterator it = cache.find(self);
|
||||
std::map<srs_thread_t, SrsContextId>::iterator it = cache.find(self);
|
||||
if (it != cache.end()) {
|
||||
cache.erase(it);
|
||||
}
|
||||
|
@ -108,7 +107,7 @@ void SrsConsoleLog::reopen()
|
|||
{
|
||||
}
|
||||
|
||||
void SrsConsoleLog::verbose(const char* tag, const char* context_id, const char* fmt, ...)
|
||||
void SrsConsoleLog::verbose(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelVerbose) {
|
||||
return;
|
||||
|
@ -128,7 +127,7 @@ void SrsConsoleLog::verbose(const char* tag, const char* context_id, const char*
|
|||
fprintf(stdout, "%s\n", buffer);
|
||||
}
|
||||
|
||||
void SrsConsoleLog::info(const char* tag, const char* context_id, const char* fmt, ...)
|
||||
void SrsConsoleLog::info(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelInfo) {
|
||||
return;
|
||||
|
@ -148,7 +147,7 @@ void SrsConsoleLog::info(const char* tag, const char* context_id, const char* fm
|
|||
fprintf(stdout, "%s\n", buffer);
|
||||
}
|
||||
|
||||
void SrsConsoleLog::trace(const char* tag, const char* context_id, const char* fmt, ...)
|
||||
void SrsConsoleLog::trace(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelTrace) {
|
||||
return;
|
||||
|
@ -168,7 +167,7 @@ void SrsConsoleLog::trace(const char* tag, const char* context_id, const char* f
|
|||
fprintf(stdout, "%s\n", buffer);
|
||||
}
|
||||
|
||||
void SrsConsoleLog::warn(const char* tag, const char* context_id, const char* fmt, ...)
|
||||
void SrsConsoleLog::warn(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelWarn) {
|
||||
return;
|
||||
|
@ -188,7 +187,7 @@ void SrsConsoleLog::warn(const char* tag, const char* context_id, const char* fm
|
|||
fprintf(stderr, "%s\n", buffer);
|
||||
}
|
||||
|
||||
void SrsConsoleLog::error(const char* tag, const char* context_id, const char* fmt, ...)
|
||||
void SrsConsoleLog::error(const char* tag, SrsContextId context_id, const char* fmt, ...)
|
||||
{
|
||||
if (level > SrsLogLevelError) {
|
||||
return;
|
||||
|
@ -214,7 +213,7 @@ void SrsConsoleLog::error(const char* tag, const char* context_id, const char* f
|
|||
}
|
||||
// LCOV_EXCL_STOP
|
||||
|
||||
bool srs_log_header(char* buffer, int size, bool utc, bool dangerous, const char* tag, const char* cid, const char* level, int* psize)
|
||||
bool srs_log_header(char* buffer, int size, bool utc, bool dangerous, const char* tag, SrsContextId cid, const char* level, int* psize)
|
||||
{
|
||||
// clock time
|
||||
timeval tv;
|
||||
|
@ -240,24 +239,24 @@ bool srs_log_header(char* buffer, int size, bool utc, bool dangerous, const char
|
|||
written = snprintf(buffer, size,
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%s][%d][%s][%d] ",
|
||||
1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000),
|
||||
level, tag, getpid(), cid, errno);
|
||||
level, tag, getpid(), cid.c_str(), errno);
|
||||
} else {
|
||||
written = snprintf(buffer, size,
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%s][%d] ",
|
||||
1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000),
|
||||
level, getpid(), cid, errno);
|
||||
level, getpid(), cid.c_str(), errno);
|
||||
}
|
||||
} else {
|
||||
if (tag) {
|
||||
written = snprintf(buffer, size,
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%s][%d][%s] ",
|
||||
1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000),
|
||||
level, tag, getpid(), cid);
|
||||
level, tag, getpid(), cid.c_str());
|
||||
} else {
|
||||
written = snprintf(buffer, size,
|
||||
"[%d-%02d-%02d %02d:%02d:%02d.%03d][%s][%d][%s] ",
|
||||
1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(tv.tv_usec / 1000),
|
||||
level, getpid(), cid);
|
||||
level, getpid(), cid.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,14 +37,14 @@
|
|||
class SrsThreadContext : public ISrsContext
|
||||
{
|
||||
private:
|
||||
std::map<srs_thread_t, std::string> cache;
|
||||
std::map<srs_thread_t, SrsContextId> cache;
|
||||
public:
|
||||
SrsThreadContext();
|
||||
virtual ~SrsThreadContext();
|
||||
public:
|
||||
virtual std::string generate_id();
|
||||
virtual std::string get_id();
|
||||
virtual std::string set_id(std::string v);
|
||||
virtual SrsContextId generate_id();
|
||||
virtual SrsContextId get_id();
|
||||
virtual SrsContextId set_id(SrsContextId v);
|
||||
public:
|
||||
virtual void clear_cid();
|
||||
};
|
||||
|
@ -64,11 +64,11 @@ public:
|
|||
public:
|
||||
virtual srs_error_t initialize();
|
||||
virtual void reopen();
|
||||
virtual void verbose(const char* tag, const char* context_id, const char* fmt, ...);
|
||||
virtual void info(const char* tag, const char* context_id, const char* fmt, ...);
|
||||
virtual void trace(const char* tag, const char* context_id, const char* fmt, ...);
|
||||
virtual void warn(const char* tag, const char* context_id, const char* fmt, ...);
|
||||
virtual void error(const char* tag, const char* context_id, const char* fmt, ...);
|
||||
virtual void verbose(const char* tag, SrsContextId context_id, const char* fmt, ...);
|
||||
virtual void info(const char* tag, SrsContextId context_id, const char* fmt, ...);
|
||||
virtual void trace(const char* tag, SrsContextId context_id, const char* fmt, ...);
|
||||
virtual void warn(const char* tag, SrsContextId context_id, const char* fmt, ...);
|
||||
virtual void error(const char* tag, SrsContextId context_id, const char* fmt, ...);
|
||||
};
|
||||
|
||||
// Generate the log header.
|
||||
|
@ -76,6 +76,6 @@ public:
|
|||
// @param utc Whether use UTC time format in the log header.
|
||||
// @param psize Output the actual header size.
|
||||
// @remark It's a internal API.
|
||||
bool srs_log_header(char* buffer, int size, bool utc, bool dangerous, const char* tag, const char* cid, const char* level, int* psize);
|
||||
bool srs_log_header(char* buffer, int size, bool utc, bool dangerous, const char* tag, SrsContextId cid, const char* level, int* psize);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -71,7 +71,7 @@ srs_error_t srs_st_init()
|
|||
}
|
||||
|
||||
// Before ST init, we might have already inited the background cid.
|
||||
string cid = _srs_context->get_id();
|
||||
SrsContextId cid = _srs_context->get_id();
|
||||
if (cid.empty()) {
|
||||
cid = _srs_context->generate_id();
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ VOID TEST(AppCoroutineTest, Dummy)
|
|||
SrsDummyCoroutine dc;
|
||||
|
||||
if (true) {
|
||||
EXPECT_EQ("", dc.cid());
|
||||
EXPECT_TRUE(dc.cid().empty());
|
||||
|
||||
srs_error_t err = dc.pull();
|
||||
EXPECT_TRUE(err != srs_success);
|
||||
|
@ -52,7 +52,7 @@ VOID TEST(AppCoroutineTest, Dummy)
|
|||
if (true) {
|
||||
dc.stop();
|
||||
|
||||
EXPECT_EQ("", dc.cid());
|
||||
EXPECT_TRUE(dc.cid().empty());
|
||||
|
||||
srs_error_t err = dc.pull();
|
||||
EXPECT_TRUE(err != srs_success);
|
||||
|
@ -68,7 +68,7 @@ VOID TEST(AppCoroutineTest, Dummy)
|
|||
if (true) {
|
||||
dc.interrupt();
|
||||
|
||||
EXPECT_EQ("", dc.cid());
|
||||
EXPECT_TRUE(dc.cid().empty());
|
||||
|
||||
srs_error_t err = dc.pull();
|
||||
EXPECT_TRUE(err != srs_success);
|
||||
|
@ -88,7 +88,7 @@ public:
|
|||
srs_error_t err;
|
||||
srs_cond_t running;
|
||||
srs_cond_t exited;
|
||||
std::string cid;
|
||||
SrsContextId cid;
|
||||
// Quit without error.
|
||||
bool quit;
|
||||
public:
|
||||
|
@ -128,12 +128,12 @@ VOID TEST(AppCoroutineTest, StartStop)
|
|||
MockCoroutineHandler ch;
|
||||
SrsSTCoroutine sc("test", &ch);
|
||||
ch.trd = ≻
|
||||
EXPECT_EQ("", sc.cid());
|
||||
EXPECT_TRUE(sc.cid().empty());
|
||||
|
||||
// Thread stop after created.
|
||||
sc.stop();
|
||||
|
||||
EXPECT_EQ("", sc.cid());
|
||||
EXPECT_TRUE(sc.cid().empty());
|
||||
|
||||
srs_error_t err = sc.pull();
|
||||
EXPECT_TRUE(srs_success != err);
|
||||
|
@ -151,7 +151,7 @@ VOID TEST(AppCoroutineTest, StartStop)
|
|||
MockCoroutineHandler ch;
|
||||
SrsSTCoroutine sc("test", &ch);
|
||||
ch.trd = ≻
|
||||
EXPECT_EQ("", sc.cid());
|
||||
EXPECT_TRUE(sc.cid().empty());
|
||||
|
||||
EXPECT_TRUE(srs_success == sc.start());
|
||||
EXPECT_TRUE(srs_success == sc.pull());
|
||||
|
@ -178,7 +178,7 @@ VOID TEST(AppCoroutineTest, StartStop)
|
|||
MockCoroutineHandler ch;
|
||||
SrsSTCoroutine sc("test", &ch);
|
||||
ch.trd = ≻
|
||||
EXPECT_EQ("", sc.cid());
|
||||
EXPECT_TRUE(sc.cid().empty());
|
||||
|
||||
EXPECT_TRUE(srs_success == sc.start());
|
||||
EXPECT_TRUE(srs_success == sc.pull());
|
||||
|
@ -220,16 +220,16 @@ VOID TEST(AppCoroutineTest, Cycle)
|
|||
|
||||
if (true) {
|
||||
MockCoroutineHandler ch;
|
||||
SrsSTCoroutine sc("test", &ch, "250");
|
||||
SrsSTCoroutine sc("test", &ch, SrsContextId("250"));
|
||||
ch.trd = ≻
|
||||
EXPECT_TRUE("250" == sc.cid());
|
||||
EXPECT_TRUE(sc.cid().equals(SrsContextId("250")));
|
||||
|
||||
EXPECT_TRUE(srs_success == sc.start());
|
||||
EXPECT_TRUE(srs_success == sc.pull());
|
||||
|
||||
// After running, the cid in cycle should equal to the thread.
|
||||
srs_cond_timedwait(ch.running, 100 * SRS_UTIME_MILLISECONDS);
|
||||
EXPECT_TRUE("250" == ch.cid);
|
||||
EXPECT_TRUE(ch.cid.equals(SrsContextId("250")));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
|
|
|
@ -898,7 +898,7 @@ class MockOnCycleThread : public ISrsCoroutineHandler
|
|||
public:
|
||||
SrsSTCoroutine trd;
|
||||
srs_cond_t cond;
|
||||
MockOnCycleThread() : trd("mock", this, "0") {
|
||||
MockOnCycleThread() : trd("mock", this) {
|
||||
cond = srs_cond_new();
|
||||
};
|
||||
virtual ~MockOnCycleThread() {
|
||||
|
@ -938,7 +938,7 @@ class MockOnCycleThread2 : public ISrsCoroutineHandler
|
|||
public:
|
||||
SrsSTCoroutine trd;
|
||||
srs_mutex_t lock;
|
||||
MockOnCycleThread2() : trd("mock", this, "0") {
|
||||
MockOnCycleThread2() : trd("mock", this) {
|
||||
lock = srs_mutex_new();
|
||||
};
|
||||
virtual ~MockOnCycleThread2() {
|
||||
|
@ -979,7 +979,7 @@ class MockOnCycleThread3 : public ISrsCoroutineHandler
|
|||
public:
|
||||
SrsSTCoroutine trd;
|
||||
srs_netfd_t fd;
|
||||
MockOnCycleThread3() : trd("mock", this, "0") {
|
||||
MockOnCycleThread3() : trd("mock", this) {
|
||||
fd = NULL;
|
||||
};
|
||||
virtual ~MockOnCycleThread3() {
|
||||
|
@ -1230,7 +1230,7 @@ class MockOnCycleThread4 : public ISrsCoroutineHandler
|
|||
public:
|
||||
SrsSTCoroutine trd;
|
||||
srs_netfd_t fd;
|
||||
MockOnCycleThread4() : trd("mock", this, "0") {
|
||||
MockOnCycleThread4() : trd("mock", this) {
|
||||
fd = NULL;
|
||||
};
|
||||
virtual ~MockOnCycleThread4() {
|
||||
|
@ -1382,19 +1382,19 @@ VOID TEST(TCPServerTest, ContextUtility)
|
|||
if (true) {
|
||||
SrsThreadContext ctx;
|
||||
|
||||
EXPECT_TRUE("" == ctx.set_id("100"));
|
||||
EXPECT_TRUE("100" == ctx.set_id("1000"));
|
||||
EXPECT_TRUE("1000" == ctx.get_id());
|
||||
EXPECT_TRUE(ctx.set_id(SrsContextId("100")).empty());
|
||||
EXPECT_TRUE(ctx.set_id(SrsContextId("1000")).equals(SrsContextId("100")));
|
||||
EXPECT_TRUE(ctx.get_id().equals(SrsContextId("1000")));
|
||||
|
||||
ctx.clear_cid();
|
||||
EXPECT_TRUE("" == ctx.set_id("100"));
|
||||
EXPECT_TRUE(ctx.set_id(SrsContextId("100")).empty());
|
||||
}
|
||||
|
||||
int base_size = 0;
|
||||
if (true) {
|
||||
errno = 0;
|
||||
int size = 0; char buf[1024]; HELPER_ARRAY_INIT(buf, 1024, 0);
|
||||
ASSERT_TRUE(srs_log_header(buf, 1024, true, true, "SRS", "100", "Trace", &size));
|
||||
ASSERT_TRUE(srs_log_header(buf, 1024, true, true, "SRS", SrsContextId("100"), "Trace", &size));
|
||||
base_size = size;
|
||||
EXPECT_TRUE(base_size > 0);
|
||||
}
|
||||
|
@ -1402,21 +1402,21 @@ VOID TEST(TCPServerTest, ContextUtility)
|
|||
if (true) {
|
||||
errno = 0;
|
||||
int size = 0; char buf[1024]; HELPER_ARRAY_INIT(buf, 1024, 0);
|
||||
ASSERT_TRUE(srs_log_header(buf, 1024, false, true, "SRS", "100", "Trace", &size));
|
||||
ASSERT_TRUE(srs_log_header(buf, 1024, false, true, "SRS", SrsContextId("100"), "Trace", &size));
|
||||
EXPECT_EQ(base_size, size);
|
||||
}
|
||||
|
||||
if (true) {
|
||||
errno = 0;
|
||||
int size = 0; char buf[1024]; HELPER_ARRAY_INIT(buf, 1024, 0);
|
||||
ASSERT_TRUE(srs_log_header(buf, 1024, false, true, NULL, "100", "Trace", &size));
|
||||
ASSERT_TRUE(srs_log_header(buf, 1024, false, true, NULL, SrsContextId("100"), "Trace", &size));
|
||||
EXPECT_EQ(base_size - 5, size);
|
||||
}
|
||||
|
||||
if (true) {
|
||||
errno = 0;
|
||||
int size = 0; char buf[1024]; HELPER_ARRAY_INIT(buf, 1024, 0);
|
||||
ASSERT_TRUE(srs_log_header(buf, 1024, false, false, NULL, "100", "Trace", &size));
|
||||
ASSERT_TRUE(srs_log_header(buf, 1024, false, false, NULL, SrsContextId("100"), "Trace", &size));
|
||||
EXPECT_EQ(base_size - 8, size);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue