AI: Add utest to cover api module.
This commit is contained in:
parent
3948f0d4fe
commit
1509fde2da
|
|
@ -315,6 +315,16 @@ public:
|
|||
virtual std::vector<std::string> get_https_api_listens() = 0;
|
||||
virtual std::string get_https_api_ssl_key() = 0;
|
||||
virtual std::string get_https_api_ssl_cert() = 0;
|
||||
// Whether enable the HTTP RAW API.
|
||||
virtual bool get_raw_api() = 0;
|
||||
// Whether allow rpc reload.
|
||||
virtual bool get_raw_api_allow_reload() = 0;
|
||||
// Whether allow rpc query.
|
||||
virtual bool get_raw_api_allow_query() = 0;
|
||||
// Whether allow rpc update.
|
||||
virtual bool get_raw_api_allow_update() = 0;
|
||||
// Dumps the http_api sections to json for raw api info.
|
||||
virtual srs_error_t raw_to_json(SrsJsonObject *obj) = 0;
|
||||
|
||||
public:
|
||||
// HTTP Server config
|
||||
|
|
@ -354,6 +364,8 @@ public:
|
|||
// Exporter config
|
||||
virtual bool get_exporter_enabled() = 0;
|
||||
virtual std::string get_exporter_listen() = 0;
|
||||
virtual std::string get_exporter_label() = 0;
|
||||
virtual std::string get_exporter_tag() = 0;
|
||||
|
||||
public:
|
||||
// Stats config
|
||||
|
|
|
|||
|
|
@ -170,22 +170,22 @@ srs_error_t srs_api_response_code(ISrsHttpResponseWriter *w, ISrsHttpMessage *r,
|
|||
|
||||
SrsGoApiRoot::SrsGoApiRoot()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiRoot::~SrsGoApiRoot()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiRoot::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
{
|
||||
SrsStatistic *stat = _srs_stat;
|
||||
|
||||
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||
|
||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
|
||||
obj->set("server", SrsJsonAny::str(stat_->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat_->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat_->service_pid().c_str()));
|
||||
|
||||
SrsJsonObject *urls = SrsJsonAny::object();
|
||||
obj->set("urls", urls);
|
||||
|
|
@ -209,22 +209,22 @@ srs_error_t SrsGoApiRoot::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage
|
|||
|
||||
SrsGoApiApi::SrsGoApiApi()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiApi::~SrsGoApiApi()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiApi::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
{
|
||||
SrsStatistic *stat = _srs_stat;
|
||||
|
||||
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||
|
||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
|
||||
obj->set("server", SrsJsonAny::str(stat_->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat_->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat_->service_pid().c_str()));
|
||||
|
||||
SrsJsonObject *urls = SrsJsonAny::object();
|
||||
obj->set("urls", urls);
|
||||
|
|
@ -236,22 +236,22 @@ srs_error_t SrsGoApiApi::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *
|
|||
|
||||
SrsGoApiV1::SrsGoApiV1()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiV1::~SrsGoApiV1()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiV1::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
{
|
||||
SrsStatistic *stat = _srs_stat;
|
||||
|
||||
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||
|
||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
|
||||
obj->set("server", SrsJsonAny::str(stat_->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat_->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat_->service_pid().c_str()));
|
||||
|
||||
SrsJsonObject *urls = SrsJsonAny::object();
|
||||
obj->set("urls", urls);
|
||||
|
|
@ -292,22 +292,22 @@ srs_error_t SrsGoApiV1::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r
|
|||
|
||||
SrsGoApiVersion::SrsGoApiVersion()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiVersion::~SrsGoApiVersion()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiVersion::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
{
|
||||
SrsStatistic *stat = _srs_stat;
|
||||
|
||||
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||
|
||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
|
||||
obj->set("server", SrsJsonAny::str(stat_->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat_->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat_->service_pid().c_str()));
|
||||
|
||||
SrsJsonObject *data = SrsJsonAny::object();
|
||||
obj->set("data", data);
|
||||
|
|
@ -322,22 +322,22 @@ srs_error_t SrsGoApiVersion::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessa
|
|||
|
||||
SrsGoApiSummaries::SrsGoApiSummaries()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiSummaries::~SrsGoApiSummaries()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiSummaries::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
{
|
||||
SrsStatistic *stat = _srs_stat;
|
||||
|
||||
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||
|
||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
|
||||
obj->set("server", SrsJsonAny::str(stat_->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat_->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat_->service_pid().c_str()));
|
||||
|
||||
srs_api_dump_summaries(obj.get());
|
||||
|
||||
|
|
@ -346,22 +346,22 @@ srs_error_t SrsGoApiSummaries::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMes
|
|||
|
||||
SrsGoApiRusages::SrsGoApiRusages()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiRusages::~SrsGoApiRusages()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiRusages::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
{
|
||||
SrsStatistic *stat = _srs_stat;
|
||||
|
||||
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||
|
||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
|
||||
obj->set("server", SrsJsonAny::str(stat_->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat_->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat_->service_pid().c_str()));
|
||||
|
||||
SrsJsonObject *data = SrsJsonAny::object();
|
||||
obj->set("data", data);
|
||||
|
|
@ -392,22 +392,22 @@ srs_error_t SrsGoApiRusages::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessa
|
|||
|
||||
SrsGoApiSelfProcStats::SrsGoApiSelfProcStats()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiSelfProcStats::~SrsGoApiSelfProcStats()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiSelfProcStats::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
{
|
||||
SrsStatistic *stat = _srs_stat;
|
||||
|
||||
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||
|
||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
|
||||
obj->set("server", SrsJsonAny::str(stat_->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat_->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat_->service_pid().c_str()));
|
||||
|
||||
SrsJsonObject *data = SrsJsonAny::object();
|
||||
obj->set("data", data);
|
||||
|
|
@ -470,22 +470,22 @@ srs_error_t SrsGoApiSelfProcStats::serve_http(ISrsHttpResponseWriter *w, ISrsHtt
|
|||
|
||||
SrsGoApiSystemProcStats::SrsGoApiSystemProcStats()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiSystemProcStats::~SrsGoApiSystemProcStats()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiSystemProcStats::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
{
|
||||
SrsStatistic *stat = _srs_stat;
|
||||
|
||||
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||
|
||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
|
||||
obj->set("server", SrsJsonAny::str(stat_->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat_->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat_->service_pid().c_str()));
|
||||
|
||||
SrsJsonObject *data = SrsJsonAny::object();
|
||||
obj->set("data", data);
|
||||
|
|
@ -510,22 +510,22 @@ srs_error_t SrsGoApiSystemProcStats::serve_http(ISrsHttpResponseWriter *w, ISrsH
|
|||
|
||||
SrsGoApiMemInfos::SrsGoApiMemInfos()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiMemInfos::~SrsGoApiMemInfos()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiMemInfos::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
{
|
||||
SrsStatistic *stat = _srs_stat;
|
||||
|
||||
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||
|
||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
|
||||
obj->set("server", SrsJsonAny::str(stat_->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat_->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat_->service_pid().c_str()));
|
||||
|
||||
SrsJsonObject *data = SrsJsonAny::object();
|
||||
obj->set("data", data);
|
||||
|
|
@ -551,22 +551,22 @@ srs_error_t SrsGoApiMemInfos::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMess
|
|||
|
||||
SrsGoApiAuthors::SrsGoApiAuthors()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiAuthors::~SrsGoApiAuthors()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiAuthors::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
{
|
||||
SrsStatistic *stat = _srs_stat;
|
||||
|
||||
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||
|
||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
|
||||
obj->set("server", SrsJsonAny::str(stat_->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat_->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat_->service_pid().c_str()));
|
||||
|
||||
SrsJsonObject *data = SrsJsonAny::object();
|
||||
obj->set("data", data);
|
||||
|
|
@ -579,22 +579,22 @@ srs_error_t SrsGoApiAuthors::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessa
|
|||
|
||||
SrsGoApiFeatures::SrsGoApiFeatures()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiFeatures::~SrsGoApiFeatures()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiFeatures::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
{
|
||||
SrsStatistic *stat = _srs_stat;
|
||||
|
||||
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||
|
||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
|
||||
obj->set("server", SrsJsonAny::str(stat_->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat_->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat_->service_pid().c_str()));
|
||||
|
||||
SrsJsonObject *data = SrsJsonAny::object();
|
||||
obj->set("data", data);
|
||||
|
|
@ -648,22 +648,22 @@ srs_error_t SrsGoApiFeatures::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMess
|
|||
|
||||
SrsGoApiRequests::SrsGoApiRequests()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiRequests::~SrsGoApiRequests()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiRequests::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
{
|
||||
SrsStatistic *stat = _srs_stat;
|
||||
|
||||
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||
|
||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
|
||||
obj->set("server", SrsJsonAny::str(stat_->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat_->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat_->service_pid().c_str()));
|
||||
|
||||
SrsJsonObject *data = SrsJsonAny::object();
|
||||
obj->set("data", data);
|
||||
|
|
@ -693,40 +693,40 @@ srs_error_t SrsGoApiRequests::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMess
|
|||
|
||||
SrsGoApiVhosts::SrsGoApiVhosts()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiVhosts::~SrsGoApiVhosts()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
SrsStatistic *stat = _srs_stat;
|
||||
|
||||
// path: {pattern}{vhost_id}
|
||||
// e.g. /api/v1/vhosts/100 pattern= /api/v1/vhosts/, vhost_id=100
|
||||
string vid = r->parse_rest_id(entry_->pattern);
|
||||
SrsStatisticVhost *vhost = NULL;
|
||||
|
||||
if (!vid.empty() && (vhost = stat->find_vhost_by_id(vid)) == NULL) {
|
||||
if (!vid.empty() && (vhost = stat_->find_vhost_by_id(vid)) == NULL) {
|
||||
return srs_api_response_code(w, r, ERROR_RTMP_VHOST_NOT_FOUND);
|
||||
}
|
||||
|
||||
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||
|
||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
|
||||
obj->set("server", SrsJsonAny::str(stat_->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat_->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat_->service_pid().c_str()));
|
||||
|
||||
if (r->is_http_get()) {
|
||||
if (!vhost) {
|
||||
SrsJsonArray *data = SrsJsonAny::array();
|
||||
obj->set("vhosts", data);
|
||||
|
||||
if ((err = stat->dumps_vhosts(data)) != srs_success) {
|
||||
if ((err = stat_->dumps_vhosts(data)) != srs_success) {
|
||||
int code = srs_error_code(err);
|
||||
srs_freep(err);
|
||||
return srs_api_response_code(w, r, code);
|
||||
|
|
@ -751,33 +751,33 @@ srs_error_t SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessag
|
|||
|
||||
SrsGoApiStreams::SrsGoApiStreams()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiStreams::~SrsGoApiStreams()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
SrsStatistic *stat = _srs_stat;
|
||||
|
||||
// path: {pattern}{stream_id}
|
||||
// e.g. /api/v1/streams/100 pattern= /api/v1/streams/, stream_id=100
|
||||
string sid = r->parse_rest_id(entry_->pattern);
|
||||
|
||||
SrsStatisticStream *stream = NULL;
|
||||
if (!sid.empty() && (stream = stat->find_stream(sid)) == NULL) {
|
||||
if (!sid.empty() && (stream = stat_->find_stream(sid)) == NULL) {
|
||||
return srs_api_response_code(w, r, ERROR_RTMP_STREAM_NOT_FOUND);
|
||||
}
|
||||
|
||||
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||
|
||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
|
||||
obj->set("server", SrsJsonAny::str(stat_->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat_->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat_->service_pid().c_str()));
|
||||
|
||||
if (r->is_http_get()) {
|
||||
if (!stream) {
|
||||
|
|
@ -788,7 +788,7 @@ srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessa
|
|||
std::string rcount = r->query_get("count");
|
||||
int start = srs_max(0, atoi(rstart.c_str()));
|
||||
int count = srs_max(10, atoi(rcount.c_str()));
|
||||
if ((err = stat->dumps_streams(data, start, count)) != srs_success) {
|
||||
if ((err = stat_->dumps_streams(data, start, count)) != srs_success) {
|
||||
int code = srs_error_code(err);
|
||||
srs_freep(err);
|
||||
return srs_api_response_code(w, r, code);
|
||||
|
|
@ -813,33 +813,33 @@ srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessa
|
|||
|
||||
SrsGoApiClients::SrsGoApiClients()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiClients::~SrsGoApiClients()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
SrsStatistic *stat = _srs_stat;
|
||||
|
||||
// path: {pattern}{client_id}
|
||||
// e.g. /api/v1/clients/100 pattern= /api/v1/clients/, client_id=100
|
||||
string client_id = r->parse_rest_id(entry_->pattern);
|
||||
|
||||
SrsStatisticClient *client = NULL;
|
||||
if (!client_id.empty() && (client = stat->find_client(client_id)) == NULL) {
|
||||
if (!client_id.empty() && (client = stat_->find_client(client_id)) == NULL) {
|
||||
return srs_api_response_code(w, r, ERROR_RTMP_CLIENT_NOT_FOUND);
|
||||
}
|
||||
|
||||
SrsUniquePtr<SrsJsonObject> obj(SrsJsonAny::object());
|
||||
|
||||
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
|
||||
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat->service_pid().c_str()));
|
||||
obj->set("server", SrsJsonAny::str(stat_->server_id().c_str()));
|
||||
obj->set("service", SrsJsonAny::str(stat_->service_id().c_str()));
|
||||
obj->set("pid", SrsJsonAny::str(stat_->service_pid().c_str()));
|
||||
|
||||
if (r->is_http_get()) {
|
||||
if (!client) {
|
||||
|
|
@ -850,7 +850,7 @@ srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessa
|
|||
std::string rcount = r->query_get("count");
|
||||
int start = srs_max(0, atoi(rstart.c_str()));
|
||||
int count = srs_max(10, atoi(rcount.c_str()));
|
||||
if ((err = stat->dumps_clients(data, start, count)) != srs_success) {
|
||||
if ((err = stat_->dumps_clients(data, start, count)) != srs_success) {
|
||||
int code = srs_error_code(err);
|
||||
srs_freep(err);
|
||||
return srs_api_response_code(w, r, code);
|
||||
|
|
@ -884,21 +884,30 @@ srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessa
|
|||
return srs_api_response(w, r, obj->dumps());
|
||||
}
|
||||
|
||||
SrsGoApiRaw::SrsGoApiRaw(SrsServer *svr)
|
||||
SrsGoApiRaw::SrsGoApiRaw(ISrsSignalHandler *handler)
|
||||
{
|
||||
server_ = svr;
|
||||
handler_ = handler;
|
||||
|
||||
raw_api_ = _srs_config->get_raw_api();
|
||||
allow_reload_ = _srs_config->get_raw_api_allow_reload();
|
||||
allow_query_ = _srs_config->get_raw_api_allow_query();
|
||||
allow_update_ = _srs_config->get_raw_api_allow_update();
|
||||
stat_ = _srs_stat;
|
||||
config_ = _srs_config;
|
||||
}
|
||||
|
||||
_srs_config->subscribe(this);
|
||||
void SrsGoApiRaw::assemble()
|
||||
{
|
||||
raw_api_ = config_->get_raw_api();
|
||||
allow_reload_ = config_->get_raw_api_allow_reload();
|
||||
allow_query_ = config_->get_raw_api_allow_query();
|
||||
allow_update_ = config_->get_raw_api_allow_update();
|
||||
|
||||
config_->subscribe(this);
|
||||
}
|
||||
|
||||
SrsGoApiRaw::~SrsGoApiRaw()
|
||||
{
|
||||
_srs_config->unsubscribe(this);
|
||||
config_->unsubscribe(this);
|
||||
|
||||
stat_ = NULL;
|
||||
config_ = NULL;
|
||||
}
|
||||
|
||||
extern srs_error_t _srs_reload_err;
|
||||
|
|
@ -918,7 +927,7 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *
|
|||
// for rpc=raw, to query the raw api config for http api.
|
||||
if (rpc == "raw") {
|
||||
// query global scope.
|
||||
if ((err = _srs_config->raw_to_json(obj.get())) != srs_success) {
|
||||
if ((err = config_->raw_to_json(obj.get())) != srs_success) {
|
||||
int code = srs_error_code(err);
|
||||
srs_freep(err);
|
||||
return srs_api_response_code(w, r, code);
|
||||
|
|
@ -945,7 +954,7 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *
|
|||
return srs_api_response_code(w, r, ERROR_SYSTEM_CONFIG_RAW_DISABLED);
|
||||
}
|
||||
|
||||
server_->on_signal(SRS_SIGNAL_RELOAD);
|
||||
handler_->on_signal(SRS_SIGNAL_RELOAD);
|
||||
return srs_api_response_code(w, r, ERROR_SUCCESS);
|
||||
} else if (rpc == "reload-fetch") {
|
||||
SrsJsonObject *data = SrsJsonAny::object();
|
||||
|
|
@ -964,10 +973,12 @@ srs_error_t SrsGoApiRaw::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *
|
|||
|
||||
SrsGoApiClusters::SrsGoApiClusters()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiClusters::~SrsGoApiClusters()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiClusters::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
|
|
@ -997,10 +1008,12 @@ srs_error_t SrsGoApiClusters::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMess
|
|||
|
||||
SrsGoApiError::SrsGoApiError()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiError::~SrsGoApiError()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiError::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
|
|
@ -1013,10 +1026,12 @@ srs_error_t SrsGoApiError::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage
|
|||
|
||||
SrsGoApiTcmalloc::SrsGoApiTcmalloc()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiTcmalloc::~SrsGoApiTcmalloc()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiTcmalloc::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
|
|
@ -1097,11 +1112,15 @@ srs_error_t SrsGoApiTcmalloc::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMess
|
|||
SrsGoApiValgrind::SrsGoApiValgrind()
|
||||
{
|
||||
trd_ = NULL;
|
||||
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiValgrind::~SrsGoApiValgrind()
|
||||
{
|
||||
srs_freep(trd_);
|
||||
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiValgrind::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
|
|
@ -1199,10 +1218,12 @@ srs_error_t SrsGoApiValgrind::cycle()
|
|||
#ifdef SRS_SIGNAL_API
|
||||
SrsGoApiSignal::SrsGoApiSignal()
|
||||
{
|
||||
stat_ = _srs_stat;
|
||||
}
|
||||
|
||||
SrsGoApiSignal::~SrsGoApiSignal()
|
||||
{
|
||||
stat_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiSignal::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
|
|
@ -1244,13 +1265,21 @@ srs_error_t SrsGoApiSignal::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessag
|
|||
|
||||
SrsGoApiMetrics::SrsGoApiMetrics()
|
||||
{
|
||||
enabled_ = _srs_config->get_exporter_enabled();
|
||||
label_ = _srs_config->get_exporter_label();
|
||||
tag_ = _srs_config->get_exporter_tag();
|
||||
stat_ = _srs_stat;
|
||||
config_ = _srs_config;
|
||||
}
|
||||
|
||||
void SrsGoApiMetrics::assemble()
|
||||
{
|
||||
enabled_ = config_->get_exporter_enabled();
|
||||
label_ = config_->get_exporter_label();
|
||||
tag_ = config_->get_exporter_tag();
|
||||
}
|
||||
|
||||
SrsGoApiMetrics::~SrsGoApiMetrics()
|
||||
{
|
||||
stat_ = NULL;
|
||||
config_ = NULL;
|
||||
}
|
||||
|
||||
srs_error_t SrsGoApiMetrics::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessage *r)
|
||||
|
|
@ -1273,7 +1302,6 @@ srs_error_t SrsGoApiMetrics::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessa
|
|||
* error counter
|
||||
*/
|
||||
|
||||
SrsStatistic *stat = _srs_stat;
|
||||
std::stringstream ss;
|
||||
|
||||
#if defined(__linux__) || defined(SRS_OSX)
|
||||
|
|
@ -1295,9 +1323,9 @@ srs_error_t SrsGoApiMetrics::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessa
|
|||
ss << "# HELP srs_build_info A metric with a constant '1' value labeled by build_date, version from which SRS was built.\n"
|
||||
<< "# TYPE srs_build_info gauge\n"
|
||||
<< "srs_build_info{"
|
||||
<< "server=\"" << stat->server_id() << "\","
|
||||
<< "service=\"" << stat->service_id() << "\","
|
||||
<< "pid=\"" << stat->service_pid() << "\","
|
||||
<< "server=\"" << stat_->server_id() << "\","
|
||||
<< "service=\"" << stat_->service_id() << "\","
|
||||
<< "pid=\"" << stat_->service_pid() << "\","
|
||||
<< "build_date=\"" << SRS_BUILD_DATE << "\","
|
||||
<< "major=\"" << VERSION_MAJOR << "\","
|
||||
<< "version=\"" << RTMP_SIG_SRS_VERSION << "\","
|
||||
|
|
@ -1328,7 +1356,7 @@ srs_error_t SrsGoApiMetrics::serve_http(ISrsHttpResponseWriter *w, ISrsHttpMessa
|
|||
|
||||
// Dump metrics by statistic.
|
||||
int64_t send_bytes, recv_bytes, nstreams, nclients, total_nclients, nerrs;
|
||||
stat->dumps_metrics(send_bytes, recv_bytes, nstreams, nclients, total_nclients, nerrs);
|
||||
stat_->dumps_metrics(send_bytes, recv_bytes, nstreams, nclients, total_nclients, nerrs);
|
||||
|
||||
// The total of bytes sent.
|
||||
ss << "# HELP srs_send_bytes_total SRS total sent bytes.\n"
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ class SrsSdp;
|
|||
class ISrsRequest;
|
||||
class ISrsHttpResponseWriter;
|
||||
class SrsHttpConn;
|
||||
class ISrsSignalHandler;
|
||||
class ISrsStatistic;
|
||||
class ISrsAppConfig;
|
||||
|
||||
#include <string>
|
||||
|
||||
|
|
@ -35,6 +38,9 @@ extern srs_error_t srs_api_response_code(ISrsHttpResponseWriter *w, ISrsHttpMess
|
|||
// For http root.
|
||||
class SrsGoApiRoot : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiRoot();
|
||||
virtual ~SrsGoApiRoot();
|
||||
|
|
@ -45,6 +51,9 @@ public:
|
|||
|
||||
class SrsGoApiApi : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiApi();
|
||||
virtual ~SrsGoApiApi();
|
||||
|
|
@ -55,6 +64,9 @@ public:
|
|||
|
||||
class SrsGoApiV1 : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiV1();
|
||||
virtual ~SrsGoApiV1();
|
||||
|
|
@ -65,6 +77,9 @@ public:
|
|||
|
||||
class SrsGoApiVersion : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiVersion();
|
||||
virtual ~SrsGoApiVersion();
|
||||
|
|
@ -75,6 +90,9 @@ public:
|
|||
|
||||
class SrsGoApiSummaries : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiSummaries();
|
||||
virtual ~SrsGoApiSummaries();
|
||||
|
|
@ -85,6 +103,9 @@ public:
|
|||
|
||||
class SrsGoApiRusages : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiRusages();
|
||||
virtual ~SrsGoApiRusages();
|
||||
|
|
@ -95,6 +116,9 @@ public:
|
|||
|
||||
class SrsGoApiSelfProcStats : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiSelfProcStats();
|
||||
virtual ~SrsGoApiSelfProcStats();
|
||||
|
|
@ -105,6 +129,9 @@ public:
|
|||
|
||||
class SrsGoApiSystemProcStats : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiSystemProcStats();
|
||||
virtual ~SrsGoApiSystemProcStats();
|
||||
|
|
@ -115,6 +142,9 @@ public:
|
|||
|
||||
class SrsGoApiMemInfos : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiMemInfos();
|
||||
virtual ~SrsGoApiMemInfos();
|
||||
|
|
@ -125,6 +155,9 @@ public:
|
|||
|
||||
class SrsGoApiAuthors : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiAuthors();
|
||||
virtual ~SrsGoApiAuthors();
|
||||
|
|
@ -135,6 +168,9 @@ public:
|
|||
|
||||
class SrsGoApiFeatures : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiFeatures();
|
||||
virtual ~SrsGoApiFeatures();
|
||||
|
|
@ -145,6 +181,9 @@ public:
|
|||
|
||||
class SrsGoApiRequests : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiRequests();
|
||||
virtual ~SrsGoApiRequests();
|
||||
|
|
@ -155,6 +194,9 @@ public:
|
|||
|
||||
class SrsGoApiVhosts : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiVhosts();
|
||||
virtual ~SrsGoApiVhosts();
|
||||
|
|
@ -165,6 +207,9 @@ public:
|
|||
|
||||
class SrsGoApiStreams : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiStreams();
|
||||
virtual ~SrsGoApiStreams();
|
||||
|
|
@ -175,6 +220,9 @@ public:
|
|||
|
||||
class SrsGoApiClients : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiClients();
|
||||
virtual ~SrsGoApiClients();
|
||||
|
|
@ -186,7 +234,11 @@ public:
|
|||
class SrsGoApiRaw : public ISrsHttpHandler, public ISrsReloadHandler
|
||||
{
|
||||
private:
|
||||
SrsServer *server_;
|
||||
ISrsStatistic *stat_;
|
||||
ISrsAppConfig *config_;
|
||||
|
||||
private:
|
||||
ISrsSignalHandler *handler_;
|
||||
|
||||
private:
|
||||
bool raw_api_;
|
||||
|
|
@ -195,7 +247,8 @@ private:
|
|||
bool allow_update_;
|
||||
|
||||
public:
|
||||
SrsGoApiRaw(SrsServer *svr);
|
||||
SrsGoApiRaw(ISrsSignalHandler *handler);
|
||||
void assemble();
|
||||
virtual ~SrsGoApiRaw();
|
||||
|
||||
public:
|
||||
|
|
@ -204,6 +257,9 @@ public:
|
|||
|
||||
class SrsGoApiClusters : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiClusters();
|
||||
virtual ~SrsGoApiClusters();
|
||||
|
|
@ -214,6 +270,9 @@ public:
|
|||
|
||||
class SrsGoApiError : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiError();
|
||||
virtual ~SrsGoApiError();
|
||||
|
|
@ -225,6 +284,9 @@ public:
|
|||
#ifdef SRS_GPERF
|
||||
class SrsGoApiTcmalloc : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiTcmalloc();
|
||||
virtual ~SrsGoApiTcmalloc();
|
||||
|
|
@ -237,6 +299,9 @@ public:
|
|||
#ifdef SRS_VALGRIND
|
||||
class SrsGoApiValgrind : public ISrsHttpHandler, public ISrsCoroutineHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
private:
|
||||
ISrsCoroutine *trd_;
|
||||
std::string task_;
|
||||
|
|
@ -256,6 +321,9 @@ public:
|
|||
#ifdef SRS_SIGNAL_API
|
||||
class SrsGoApiSignal : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
|
||||
public:
|
||||
SrsGoApiSignal();
|
||||
virtual ~SrsGoApiSignal();
|
||||
|
|
@ -267,6 +335,10 @@ public:
|
|||
|
||||
class SrsGoApiMetrics : public ISrsHttpHandler
|
||||
{
|
||||
private:
|
||||
ISrsStatistic *stat_;
|
||||
ISrsAppConfig *config_;
|
||||
|
||||
private:
|
||||
bool enabled_;
|
||||
std::string label_;
|
||||
|
|
@ -274,6 +346,7 @@ private:
|
|||
|
||||
public:
|
||||
SrsGoApiMetrics();
|
||||
void assemble();
|
||||
virtual ~SrsGoApiMetrics();
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -142,6 +142,14 @@ srs_error_t srs_global_initialize()
|
|||
return err;
|
||||
}
|
||||
|
||||
ISrsSignalHandler::ISrsSignalHandler()
|
||||
{
|
||||
}
|
||||
|
||||
ISrsSignalHandler::~ISrsSignalHandler()
|
||||
{
|
||||
}
|
||||
|
||||
SrsServer::SrsServer()
|
||||
{
|
||||
signal_reload_ = false;
|
||||
|
|
@ -758,9 +766,13 @@ srs_error_t SrsServer::http_handle()
|
|||
if ((err = http_api_mux_->handle("/api/v1/clients/", new SrsGoApiClients())) != srs_success) {
|
||||
return srs_error_wrap(err, "handle clients");
|
||||
}
|
||||
if ((err = http_api_mux_->handle("/api/v1/raw", new SrsGoApiRaw(this))) != srs_success) {
|
||||
|
||||
SrsGoApiRaw *raw_api = new SrsGoApiRaw(this);
|
||||
raw_api->assemble();
|
||||
if ((err = http_api_mux_->handle("/api/v1/raw", raw_api)) != srs_success) {
|
||||
return srs_error_wrap(err, "handle raw");
|
||||
}
|
||||
|
||||
if ((err = http_api_mux_->handle("/api/v1/clusters", new SrsGoApiClusters())) != srs_success) {
|
||||
return srs_error_wrap(err, "handle clusters");
|
||||
}
|
||||
|
|
@ -805,7 +817,9 @@ srs_error_t SrsServer::http_handle()
|
|||
#endif
|
||||
|
||||
// metrics by prometheus
|
||||
if ((err = http_api_mux_->handle("/metrics", new SrsGoApiMetrics())) != srs_success) {
|
||||
SrsGoApiMetrics *metrics = new SrsGoApiMetrics();
|
||||
metrics->assemble();
|
||||
if ((err = http_api_mux_->handle("/metrics", metrics)) != srs_success) {
|
||||
return srs_error_wrap(err, "handle tests errors");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,6 +73,17 @@ class SrsAppFactory;
|
|||
// Initialize global shared variables cross all threads.
|
||||
extern srs_error_t srs_global_initialize();
|
||||
|
||||
// The signal handler interface.
|
||||
class ISrsSignalHandler
|
||||
{
|
||||
public:
|
||||
ISrsSignalHandler();
|
||||
virtual ~ISrsSignalHandler();
|
||||
|
||||
public:
|
||||
virtual void on_signal(int signo) = 0;
|
||||
};
|
||||
|
||||
// SrsServer is the main server class of SRS (Simple Realtime Server) that provides comprehensive
|
||||
// streaming media server functionality. It serves as the central orchestrator for all streaming
|
||||
// protocols and services in a single-threaded, coroutine-based architecture.
|
||||
|
|
@ -81,7 +92,8 @@ class SrsServer : public ISrsReloadHandler, // Reload framework for permormance
|
|||
public ISrsTcpHandler,
|
||||
public ISrsHourGlassHandler,
|
||||
public ISrsSrtClientHandler,
|
||||
public ISrsUdpMuxHandler
|
||||
public ISrsUdpMuxHandler,
|
||||
public ISrsSignalHandler
|
||||
{
|
||||
private:
|
||||
ISrsAppConfig *config_;
|
||||
|
|
|
|||
|
|
@ -148,6 +148,29 @@ public:
|
|||
virtual void kbps_add_delta(std::string id, ISrsKbpsDelta *delta) = 0;
|
||||
virtual void kbps_sample() = 0;
|
||||
virtual srs_error_t on_video_frames(ISrsRequest *req, int nb_frames) = 0;
|
||||
|
||||
public:
|
||||
// Get the server id, used to identify the server.
|
||||
// For example, when restart, the server id must changed.
|
||||
virtual std::string server_id() = 0;
|
||||
// Get the service id, used to identify the restart of service.
|
||||
virtual std::string service_id() = 0;
|
||||
// Get the service pid, used to identify the service process.
|
||||
virtual std::string service_pid() = 0;
|
||||
// Find vhost by id.
|
||||
virtual SrsStatisticVhost *find_vhost_by_id(std::string vid) = 0;
|
||||
// Find stream by id.
|
||||
virtual SrsStatisticStream *find_stream(std::string sid) = 0;
|
||||
// Find client by id.
|
||||
virtual SrsStatisticClient *find_client(std::string client_id) = 0;
|
||||
// Dumps the vhosts to json array.
|
||||
virtual srs_error_t dumps_vhosts(SrsJsonArray *arr) = 0;
|
||||
// Dumps the streams to json array.
|
||||
virtual srs_error_t dumps_streams(SrsJsonArray *arr, int start, int count) = 0;
|
||||
// Dumps the clients to json array.
|
||||
virtual srs_error_t dumps_clients(SrsJsonArray *arr, int start, int count) = 0;
|
||||
// Dumps exporter metrics.
|
||||
virtual srs_error_t dumps_metrics(int64_t &send_bytes, int64_t &recv_bytes, int64_t &nstreams, int64_t &nclients, int64_t &total_nclients, int64_t &nerrs) = 0;
|
||||
};
|
||||
|
||||
// The global statistic instance.
|
||||
|
|
|
|||
|
|
@ -490,22 +490,22 @@ bool SrsFormat::is_avc_sequence_header()
|
|||
return vcodec_ && (h264 || h265 || av1) && video_ && video_->avc_packet_type_ == SrsVideoAvcFrameTraitSequenceHeader;
|
||||
}
|
||||
|
||||
SrsParsedAudioPacket* SrsFormat::audio()
|
||||
SrsParsedAudioPacket *SrsFormat::audio()
|
||||
{
|
||||
return audio_;
|
||||
}
|
||||
|
||||
SrsAudioCodecConfig* SrsFormat::acodec()
|
||||
SrsAudioCodecConfig *SrsFormat::acodec()
|
||||
{
|
||||
return acodec_;
|
||||
}
|
||||
|
||||
SrsParsedVideoPacket* SrsFormat::video()
|
||||
SrsParsedVideoPacket *SrsFormat::video()
|
||||
{
|
||||
return video_;
|
||||
}
|
||||
|
||||
SrsVideoCodecConfig* SrsFormat::vcodec()
|
||||
SrsVideoCodecConfig *SrsFormat::vcodec()
|
||||
{
|
||||
return vcodec_;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -193,10 +193,10 @@ public:
|
|||
|
||||
public:
|
||||
// Getters for codec and packet information
|
||||
virtual SrsParsedAudioPacket* audio() = 0;
|
||||
virtual SrsAudioCodecConfig* acodec() = 0;
|
||||
virtual SrsParsedVideoPacket* video() = 0;
|
||||
virtual SrsVideoCodecConfig* vcodec() = 0;
|
||||
virtual SrsParsedAudioPacket *audio() = 0;
|
||||
virtual SrsAudioCodecConfig *acodec() = 0;
|
||||
virtual SrsParsedVideoPacket *video() = 0;
|
||||
virtual SrsVideoCodecConfig *vcodec() = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -247,10 +247,10 @@ public:
|
|||
|
||||
public:
|
||||
// Getters for codec and packet information
|
||||
virtual SrsParsedAudioPacket* audio();
|
||||
virtual SrsAudioCodecConfig* acodec();
|
||||
virtual SrsParsedVideoPacket* video();
|
||||
virtual SrsVideoCodecConfig* vcodec();
|
||||
virtual SrsParsedAudioPacket *audio();
|
||||
virtual SrsAudioCodecConfig *acodec();
|
||||
virtual SrsParsedVideoPacket *video();
|
||||
virtual SrsVideoCodecConfig *vcodec();
|
||||
|
||||
private:
|
||||
// Demux the video packet in H.264 codec.
|
||||
|
|
|
|||
|
|
@ -3003,22 +3003,22 @@ srs_error_t SrsTsMessageCache::cache_video(SrsParsedVideoPacket *frame, int64_t
|
|||
return err;
|
||||
}
|
||||
|
||||
SrsTsMessage* SrsTsMessageCache::audio()
|
||||
SrsTsMessage *SrsTsMessageCache::audio()
|
||||
{
|
||||
return audio_;
|
||||
}
|
||||
|
||||
void SrsTsMessageCache::set_audio(SrsTsMessage* msg)
|
||||
void SrsTsMessageCache::set_audio(SrsTsMessage *msg)
|
||||
{
|
||||
audio_ = msg;
|
||||
}
|
||||
|
||||
SrsTsMessage* SrsTsMessageCache::video()
|
||||
SrsTsMessage *SrsTsMessageCache::video()
|
||||
{
|
||||
return video_;
|
||||
}
|
||||
|
||||
void SrsTsMessageCache::set_video(SrsTsMessage* msg)
|
||||
void SrsTsMessageCache::set_video(SrsTsMessage *msg)
|
||||
{
|
||||
video_ = msg;
|
||||
}
|
||||
|
|
@ -3469,7 +3469,7 @@ srs_error_t SrsTsTransmuxer::flush_audio()
|
|||
}
|
||||
|
||||
// write success, clear and free the ts message.
|
||||
SrsTsMessage* audio_msg = tsmc_->audio();
|
||||
SrsTsMessage *audio_msg = tsmc_->audio();
|
||||
srs_freep(audio_msg);
|
||||
tsmc_->set_audio(NULL);
|
||||
|
||||
|
|
@ -3485,7 +3485,7 @@ srs_error_t SrsTsTransmuxer::flush_video()
|
|||
}
|
||||
|
||||
// write success, clear and free the ts message.
|
||||
SrsTsMessage* video_msg = tsmc_->video();
|
||||
SrsTsMessage *video_msg = tsmc_->video();
|
||||
srs_freep(video_msg);
|
||||
tsmc_->set_video(NULL);
|
||||
|
||||
|
|
|
|||
|
|
@ -1437,10 +1437,10 @@ public:
|
|||
|
||||
public:
|
||||
// Getters and setters for cached messages
|
||||
virtual SrsTsMessage* audio() = 0;
|
||||
virtual void set_audio(SrsTsMessage* msg) = 0;
|
||||
virtual SrsTsMessage* video() = 0;
|
||||
virtual void set_video(SrsTsMessage* msg) = 0;
|
||||
virtual SrsTsMessage *audio() = 0;
|
||||
virtual void set_audio(SrsTsMessage *msg) = 0;
|
||||
virtual SrsTsMessage *video() = 0;
|
||||
virtual void set_video(SrsTsMessage *msg) = 0;
|
||||
};
|
||||
|
||||
// TS messages cache, to group frames to TS message,
|
||||
|
|
@ -1464,10 +1464,10 @@ public:
|
|||
|
||||
public:
|
||||
// Getters and setters for cached messages
|
||||
virtual SrsTsMessage* audio();
|
||||
virtual void set_audio(SrsTsMessage* msg);
|
||||
virtual SrsTsMessage* video();
|
||||
virtual void set_video(SrsTsMessage* msg);
|
||||
virtual SrsTsMessage *audio();
|
||||
virtual void set_audio(SrsTsMessage *msg);
|
||||
virtual SrsTsMessage *video();
|
||||
virtual void set_video(SrsTsMessage *msg);
|
||||
|
||||
private:
|
||||
virtual srs_error_t do_cache_mp3(SrsParsedAudioPacket *frame);
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class SrsTcpClient;
|
|||
class SrsSslClient : public ISrsReader, public ISrsStreamWriter
|
||||
{
|
||||
private:
|
||||
SrsTcpClient *transport_;
|
||||
ISrsProtocolReadWriter *transport_;
|
||||
|
||||
private:
|
||||
SSL_CTX *ssl_ctx_;
|
||||
|
|
|
|||
|
|
@ -774,6 +774,62 @@ srs_error_t MockStatisticForResampleKbps::on_video_frames(ISrsRequest *req, int
|
|||
return srs_success;
|
||||
}
|
||||
|
||||
std::string MockStatisticForResampleKbps::server_id()
|
||||
{
|
||||
return "mock_server_id";
|
||||
}
|
||||
|
||||
std::string MockStatisticForResampleKbps::service_id()
|
||||
{
|
||||
return "mock_service_id";
|
||||
}
|
||||
|
||||
std::string MockStatisticForResampleKbps::service_pid()
|
||||
{
|
||||
return "mock_pid";
|
||||
}
|
||||
|
||||
SrsStatisticVhost *MockStatisticForResampleKbps::find_vhost_by_id(std::string vid)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SrsStatisticStream *MockStatisticForResampleKbps::find_stream(std::string sid)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SrsStatisticClient *MockStatisticForResampleKbps::find_client(std::string client_id)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
srs_error_t MockStatisticForResampleKbps::dumps_vhosts(SrsJsonArray *arr)
|
||||
{
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
srs_error_t MockStatisticForResampleKbps::dumps_streams(SrsJsonArray *arr, int start, int count)
|
||||
{
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
srs_error_t MockStatisticForResampleKbps::dumps_clients(SrsJsonArray *arr, int start, int count)
|
||||
{
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
srs_error_t MockStatisticForResampleKbps::dumps_metrics(int64_t &send_bytes, int64_t &recv_bytes, int64_t &nstreams, int64_t &nclients, int64_t &total_nclients, int64_t &nerrs)
|
||||
{
|
||||
send_bytes = 0;
|
||||
recv_bytes = 0;
|
||||
nstreams = 0;
|
||||
nclients = 0;
|
||||
total_nclients = 0;
|
||||
nerrs = 0;
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
void MockStatisticForResampleKbps::reset()
|
||||
{
|
||||
kbps_add_delta_count_ = 0;
|
||||
|
|
|
|||
|
|
@ -258,6 +258,16 @@ public:
|
|||
virtual void kbps_add_delta(std::string id, ISrsKbpsDelta *delta);
|
||||
virtual void kbps_sample();
|
||||
virtual srs_error_t on_video_frames(ISrsRequest *req, int nb_frames);
|
||||
virtual std::string server_id();
|
||||
virtual std::string service_id();
|
||||
virtual std::string service_pid();
|
||||
virtual SrsStatisticVhost *find_vhost_by_id(std::string vid);
|
||||
virtual SrsStatisticStream *find_stream(std::string sid);
|
||||
virtual SrsStatisticClient *find_client(std::string client_id);
|
||||
virtual srs_error_t dumps_vhosts(SrsJsonArray *arr);
|
||||
virtual srs_error_t dumps_streams(SrsJsonArray *arr, int start, int count);
|
||||
virtual srs_error_t dumps_clients(SrsJsonArray *arr, int start, int count);
|
||||
virtual srs_error_t dumps_metrics(int64_t &send_bytes, int64_t &recv_bytes, int64_t &nstreams, int64_t &nclients, int64_t &total_nclients, int64_t &nerrs);
|
||||
void reset();
|
||||
};
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -16,6 +16,7 @@
|
|||
#include <srs_app_http_hooks.hpp>
|
||||
#include <srs_app_http_stream.hpp>
|
||||
#include <srs_app_rtmp_source.hpp>
|
||||
#include <srs_app_server.hpp>
|
||||
#include <srs_protocol_http_conn.hpp>
|
||||
#include <srs_protocol_rtmp_stack.hpp>
|
||||
#include <srs_utest_app6.hpp>
|
||||
|
|
@ -249,6 +250,16 @@ public:
|
|||
virtual void kbps_add_delta(std::string id, ISrsKbpsDelta *delta);
|
||||
virtual void kbps_sample();
|
||||
virtual srs_error_t on_video_frames(ISrsRequest *req, int nb_frames);
|
||||
virtual std::string server_id();
|
||||
virtual std::string service_id();
|
||||
virtual std::string service_pid();
|
||||
virtual SrsStatisticVhost *find_vhost_by_id(std::string vid);
|
||||
virtual SrsStatisticStream *find_stream(std::string sid);
|
||||
virtual SrsStatisticClient *find_client(std::string client_id);
|
||||
virtual srs_error_t dumps_vhosts(SrsJsonArray *arr);
|
||||
virtual srs_error_t dumps_streams(SrsJsonArray *arr, int start, int count);
|
||||
virtual srs_error_t dumps_clients(SrsJsonArray *arr, int start, int count);
|
||||
virtual srs_error_t dumps_metrics(int64_t &send_bytes, int64_t &recv_bytes, int64_t &nstreams, int64_t &nclients, int64_t &total_nclients, int64_t &nerrs);
|
||||
};
|
||||
|
||||
// Mock ISrsSecurity for testing SrsLiveStream::serve_http_impl
|
||||
|
|
@ -349,4 +360,62 @@ public:
|
|||
virtual std::string host();
|
||||
};
|
||||
|
||||
// Mock SrsHttpMessage for testing HTTP API response functions
|
||||
class MockHttpMessageForApiResponse : public SrsHttpMessage
|
||||
{
|
||||
public:
|
||||
MockHttpConn *mock_conn_;
|
||||
bool is_jsonp_;
|
||||
std::string callback_;
|
||||
std::string path_;
|
||||
std::map<std::string, std::string> query_params_;
|
||||
|
||||
public:
|
||||
MockHttpMessageForApiResponse();
|
||||
virtual ~MockHttpMessageForApiResponse();
|
||||
|
||||
public:
|
||||
virtual bool is_jsonp();
|
||||
virtual std::string query_get(std::string key);
|
||||
virtual std::string path();
|
||||
};
|
||||
|
||||
// Mock ISrsSignalHandler for testing SrsGoApiRaw
|
||||
class MockSignalHandler : public ISrsSignalHandler
|
||||
{
|
||||
public:
|
||||
int signal_received_;
|
||||
int signal_count_;
|
||||
|
||||
public:
|
||||
MockSignalHandler();
|
||||
virtual ~MockSignalHandler();
|
||||
|
||||
public:
|
||||
virtual void on_signal(int signo);
|
||||
void reset();
|
||||
};
|
||||
|
||||
// Mock ISrsAppConfig for testing SrsGoApiRaw
|
||||
class MockAppConfigForRawApi : public MockAppConfig
|
||||
{
|
||||
public:
|
||||
bool raw_api_;
|
||||
bool allow_reload_;
|
||||
bool allow_query_;
|
||||
bool allow_update_;
|
||||
srs_error_t raw_to_json_error_;
|
||||
|
||||
public:
|
||||
MockAppConfigForRawApi();
|
||||
virtual ~MockAppConfigForRawApi();
|
||||
|
||||
public:
|
||||
virtual bool get_raw_api();
|
||||
virtual bool get_raw_api_allow_reload();
|
||||
virtual bool get_raw_api_allow_query();
|
||||
virtual bool get_raw_api_allow_update();
|
||||
virtual srs_error_t raw_to_json(SrsJsonObject *obj);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -2705,6 +2705,62 @@ srs_error_t MockRtcStatistic::on_video_frames(ISrsRequest *req, int nb_frames)
|
|||
return srs_success;
|
||||
}
|
||||
|
||||
std::string MockRtcStatistic::server_id()
|
||||
{
|
||||
return "mock_server_id";
|
||||
}
|
||||
|
||||
std::string MockRtcStatistic::service_id()
|
||||
{
|
||||
return "mock_service_id";
|
||||
}
|
||||
|
||||
std::string MockRtcStatistic::service_pid()
|
||||
{
|
||||
return "mock_pid";
|
||||
}
|
||||
|
||||
SrsStatisticVhost *MockRtcStatistic::find_vhost_by_id(std::string vid)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SrsStatisticStream *MockRtcStatistic::find_stream(std::string sid)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SrsStatisticClient *MockRtcStatistic::find_client(std::string client_id)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
srs_error_t MockRtcStatistic::dumps_vhosts(SrsJsonArray *arr)
|
||||
{
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
srs_error_t MockRtcStatistic::dumps_streams(SrsJsonArray *arr, int start, int count)
|
||||
{
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
srs_error_t MockRtcStatistic::dumps_clients(SrsJsonArray *arr, int start, int count)
|
||||
{
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
srs_error_t MockRtcStatistic::dumps_metrics(int64_t &send_bytes, int64_t &recv_bytes, int64_t &nstreams, int64_t &nclients, int64_t &total_nclients, int64_t &nerrs)
|
||||
{
|
||||
send_bytes = 0;
|
||||
recv_bytes = 0;
|
||||
nstreams = 0;
|
||||
nclients = 0;
|
||||
total_nclients = 0;
|
||||
nerrs = 0;
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
// Unit tests for SrsRtcAsyncCallOnStop::call()
|
||||
VOID TEST(RtcAsyncCallOnStopTest, CallWithHttpHooksDisabled)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -248,6 +248,7 @@ public:
|
|||
virtual srs_error_t reload(SrsReloadState *pstate) { return srs_success; }
|
||||
virtual srs_error_t persistence() { return srs_success; }
|
||||
virtual std::string config() { return ""; }
|
||||
virtual SrsConfDirective *get_root() { return NULL; }
|
||||
virtual int get_max_connections() { return 1000; }
|
||||
virtual std::string get_pid_file() { return ""; }
|
||||
virtual bool empty_ip_ok() { return false; }
|
||||
|
|
@ -266,6 +267,11 @@ public:
|
|||
virtual std::vector<std::string> get_https_api_listens() { return std::vector<std::string>(); }
|
||||
virtual std::string get_https_api_ssl_key() { return ""; }
|
||||
virtual std::string get_https_api_ssl_cert() { return ""; }
|
||||
virtual bool get_raw_api() { return false; }
|
||||
virtual bool get_raw_api_allow_reload() { return false; }
|
||||
virtual bool get_raw_api_allow_query() { return false; }
|
||||
virtual bool get_raw_api_allow_update() { return false; }
|
||||
virtual srs_error_t raw_to_json(SrsJsonObject *obj) { return srs_success; }
|
||||
virtual bool get_http_stream_enabled() { return false; }
|
||||
virtual std::vector<std::string> get_http_stream_listens() { return std::vector<std::string>(); }
|
||||
virtual bool get_https_stream_enabled() { return false; }
|
||||
|
|
@ -287,6 +293,8 @@ public:
|
|||
virtual std::string get_stream_caster_engine(SrsConfDirective *conf) { return ""; }
|
||||
virtual bool get_exporter_enabled() { return false; }
|
||||
virtual std::string get_exporter_listen() { return ""; }
|
||||
virtual std::string get_exporter_label() { return ""; }
|
||||
virtual std::string get_exporter_tag() { return ""; }
|
||||
virtual bool get_stats_enabled() { return false; }
|
||||
virtual int get_stats_network() { return 0; }
|
||||
virtual bool get_heartbeat_enabled() { return false; }
|
||||
|
|
@ -383,7 +391,6 @@ public:
|
|||
virtual bool get_atc_auto(std::string vhost);
|
||||
virtual bool get_reduce_sequence_header(std::string vhost);
|
||||
virtual bool get_parse_sps(std::string vhost);
|
||||
virtual SrsConfDirective *get_root() { return NULL; }
|
||||
virtual bool get_vhost_enabled(SrsConfDirective *conf) { return true; }
|
||||
virtual bool get_vhost_http_remux_enabled(std::string vhost) { return false; }
|
||||
virtual bool get_vhost_http_remux_enabled(SrsConfDirective *vhost) { return false; }
|
||||
|
|
@ -469,6 +476,16 @@ public:
|
|||
virtual void kbps_add_delta(std::string id, ISrsKbpsDelta *delta);
|
||||
virtual void kbps_sample();
|
||||
virtual srs_error_t on_video_frames(ISrsRequest *req, int nb_frames);
|
||||
virtual std::string server_id();
|
||||
virtual std::string service_id();
|
||||
virtual std::string service_pid();
|
||||
virtual SrsStatisticVhost *find_vhost_by_id(std::string vid);
|
||||
virtual SrsStatisticStream *find_stream(std::string sid);
|
||||
virtual SrsStatisticClient *find_client(std::string client_id);
|
||||
virtual srs_error_t dumps_vhosts(SrsJsonArray *arr);
|
||||
virtual srs_error_t dumps_streams(SrsJsonArray *arr, int start, int count);
|
||||
virtual srs_error_t dumps_clients(SrsJsonArray *arr, int start, int count);
|
||||
virtual srs_error_t dumps_metrics(int64_t &send_bytes, int64_t &recv_bytes, int64_t &nstreams, int64_t &nclients, int64_t &total_nclients, int64_t &nerrs);
|
||||
void set_on_client_error(srs_error_t err);
|
||||
void reset();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1922,6 +1922,62 @@ srs_error_t MockStatisticForOriginHub::on_video_frames(ISrsRequest *req, int nb_
|
|||
return srs_success;
|
||||
}
|
||||
|
||||
std::string MockStatisticForOriginHub::server_id()
|
||||
{
|
||||
return "mock_server_id";
|
||||
}
|
||||
|
||||
std::string MockStatisticForOriginHub::service_id()
|
||||
{
|
||||
return "mock_service_id";
|
||||
}
|
||||
|
||||
std::string MockStatisticForOriginHub::service_pid()
|
||||
{
|
||||
return "mock_pid";
|
||||
}
|
||||
|
||||
SrsStatisticVhost *MockStatisticForOriginHub::find_vhost_by_id(std::string vid)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SrsStatisticStream *MockStatisticForOriginHub::find_stream(std::string sid)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SrsStatisticClient *MockStatisticForOriginHub::find_client(std::string client_id)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
srs_error_t MockStatisticForOriginHub::dumps_vhosts(SrsJsonArray *arr)
|
||||
{
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
srs_error_t MockStatisticForOriginHub::dumps_streams(SrsJsonArray *arr, int start, int count)
|
||||
{
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
srs_error_t MockStatisticForOriginHub::dumps_clients(SrsJsonArray *arr, int start, int count)
|
||||
{
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
srs_error_t MockStatisticForOriginHub::dumps_metrics(int64_t &send_bytes, int64_t &recv_bytes, int64_t &nstreams, int64_t &nclients, int64_t &total_nclients, int64_t &nerrs)
|
||||
{
|
||||
send_bytes = 0;
|
||||
recv_bytes = 0;
|
||||
nstreams = 0;
|
||||
nclients = 0;
|
||||
total_nclients = 0;
|
||||
nerrs = 0;
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
// Mock ISrsNgExec implementation
|
||||
MockNgExecForOriginHub::MockNgExecForOriginHub()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -202,6 +202,16 @@ public:
|
|||
virtual void kbps_add_delta(std::string id, ISrsKbpsDelta *delta);
|
||||
virtual void kbps_sample();
|
||||
virtual srs_error_t on_video_frames(ISrsRequest *req, int nb_frames);
|
||||
virtual std::string server_id();
|
||||
virtual std::string service_id();
|
||||
virtual std::string service_pid();
|
||||
virtual SrsStatisticVhost *find_vhost_by_id(std::string vid);
|
||||
virtual SrsStatisticStream *find_stream(std::string sid);
|
||||
virtual SrsStatisticClient *find_client(std::string client_id);
|
||||
virtual srs_error_t dumps_vhosts(SrsJsonArray *arr);
|
||||
virtual srs_error_t dumps_streams(SrsJsonArray *arr, int start, int count);
|
||||
virtual srs_error_t dumps_clients(SrsJsonArray *arr, int start, int count);
|
||||
virtual srs_error_t dumps_metrics(int64_t &send_bytes, int64_t &recv_bytes, int64_t &nstreams, int64_t &nclients, int64_t &total_nclients, int64_t &nerrs);
|
||||
};
|
||||
|
||||
// Mock ISrsNgExec for testing SrsOriginHub::on_publish
|
||||
|
|
|
|||
|
|
@ -114,6 +114,56 @@ srs_error_t MockResponseWriter::filter(SrsHttpHeader *h)
|
|||
return srs_success;
|
||||
}
|
||||
|
||||
MockResponseWriterForJsonp::MockResponseWriterForJsonp()
|
||||
{
|
||||
w = new SrsHttpResponseWriter(&io);
|
||||
w->set_header_filter(this);
|
||||
}
|
||||
|
||||
MockResponseWriterForJsonp::~MockResponseWriterForJsonp()
|
||||
{
|
||||
srs_freep(w);
|
||||
}
|
||||
|
||||
srs_error_t MockResponseWriterForJsonp::final_request()
|
||||
{
|
||||
return w->final_request();
|
||||
}
|
||||
|
||||
SrsHttpHeader *MockResponseWriterForJsonp::header()
|
||||
{
|
||||
return w->header();
|
||||
}
|
||||
|
||||
srs_error_t MockResponseWriterForJsonp::write(char *data, int size)
|
||||
{
|
||||
return w->write(data, size);
|
||||
}
|
||||
|
||||
srs_error_t MockResponseWriterForJsonp::writev(const iovec *iov, int iovcnt, ssize_t *pnwrite)
|
||||
{
|
||||
return w->writev(iov, iovcnt, pnwrite);
|
||||
}
|
||||
|
||||
void MockResponseWriterForJsonp::write_header(int code)
|
||||
{
|
||||
w->write_header(code);
|
||||
}
|
||||
|
||||
srs_error_t MockResponseWriterForJsonp::filter(SrsHttpHeader *h)
|
||||
{
|
||||
// Do NOT filter Content-Type for JSONP testing - we need to verify it
|
||||
h->del("Server");
|
||||
h->del("Connection");
|
||||
h->del("Location");
|
||||
h->del("Content-Range");
|
||||
h->del("Access-Control-Allow-Origin");
|
||||
h->del("Access-Control-Allow-Methods");
|
||||
h->del("Access-Control-Expose-Headers");
|
||||
h->del("Access-Control-Allow-Headers");
|
||||
return srs_success;
|
||||
}
|
||||
|
||||
string mock_http_response(int status, string content)
|
||||
{
|
||||
stringstream ss;
|
||||
|
|
|
|||
|
|
@ -40,6 +40,28 @@ public:
|
|||
virtual srs_error_t filter(SrsHttpHeader *h);
|
||||
};
|
||||
|
||||
// Mock response writer for JSONP testing - does not filter Content-Type header
|
||||
class MockResponseWriterForJsonp : public ISrsHttpResponseWriter, public ISrsHttpHeaderFilter
|
||||
{
|
||||
public:
|
||||
SrsHttpResponseWriter *w;
|
||||
MockBufferIO io;
|
||||
|
||||
public:
|
||||
MockResponseWriterForJsonp();
|
||||
virtual ~MockResponseWriterForJsonp();
|
||||
|
||||
public:
|
||||
virtual srs_error_t final_request();
|
||||
virtual SrsHttpHeader *header();
|
||||
virtual srs_error_t write(char *data, int size);
|
||||
virtual srs_error_t writev(const iovec *iov, int iovcnt, ssize_t *pnwrite);
|
||||
virtual void write_header(int code);
|
||||
|
||||
public:
|
||||
virtual srs_error_t filter(SrsHttpHeader *h);
|
||||
};
|
||||
|
||||
class MockMSegmentsReader : public ISrsReader
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user