Merge SRS3, change id of stat to string

pull/2144/head
winlin 4 years ago
commit 1c41f5d796

@ -209,6 +209,8 @@ For previous versions, please read:
## V3 changes
* v3.0, 2021-01-07, Change id from int to string for the statistics. 3.0.157
* <strong>v3.0, 2021-01-02, [3.0 release3(3.0.156)][r3.0r3] released. 122736 lines.</strong>
* v3.0, 2020-12-26, For RTMP edge/forward, pass vhost in tcUrl, not in stream. 3.0.156
* v3.0, 2020-12-17, Fix [#1694][bug #1694], Support DVR 2GB+ MP4 file. 3.0.155
* v3.0, 2020-12-17, Fix [#1548][bug #1548], Add edts in MP4 for Windows10. 3.0.154
@ -841,6 +843,7 @@ For previous versions, please read:
## Releases
* 2021-01-02, [Release v3.0-r3][r3.0r3], 3.0 release3, 3.0.156, 122736 lines.
* 2020-10-31, [Release v3.0-r2][r3.0r2], 3.0 release2, 3.0.153, 122663 lines.
* 2020-10-10, [Release v3.0-r1][r3.0r1], 3.0 release1, 3.0.144, 122674 lines.
* 2020-06-27, [Release v3.0-r0][r3.0r0], 3.0 release0, 3.0.141, 122674 lines.
@ -1803,6 +1806,7 @@ Winlin
[exo #828]: https://github.com/google/ExoPlayer/pull/828
[r3.0r3]: https://github.com/ossrs/srs/releases/tag/v3.0-r3
[r3.0r2]: https://github.com/ossrs/srs/releases/tag/v3.0-r2
[r3.0r1]: https://github.com/ossrs/srs/releases/tag/v3.0-r1
[r3.0r0]: https://github.com/ossrs/srs/releases/tag/v3.0-r0

@ -2243,8 +2243,11 @@ srs_error_t SrsConfig::global_to_json(SrsJsonObject* obj)
SrsJsonObject* sobj = SrsJsonAny::object();
sobjs->set(dir->arg0(), sobj);
SrsStatisticVhost* svhost = stat->find_vhost(dir->arg0());
sobj->set("id", SrsJsonAny::str(svhost? svhost->id.c_str() : ""));
SrsStatisticVhost* svhost = stat->find_vhost_by_name(dir->arg0());
if (!svhost) {
continue;
}
sobj->set("id", SrsJsonAny::str(svhost->id.c_str()));
sobj->set("name", dir->dumps_arg0_to_str());
sobj->set("enabled", SrsJsonAny::boolean(get_vhost_enabled(dir->arg0())));
@ -2368,8 +2371,11 @@ srs_error_t SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsJsonObject* obj
// always present in vhost.
SrsStatistic* stat = SrsStatistic::instance();
SrsStatisticVhost* svhost = stat->find_vhost(vhost->arg0());
obj->set("id", SrsJsonAny::str(svhost? svhost->id.c_str() : ""));
SrsStatisticVhost* svhost = stat->find_vhost_by_name(vhost->arg0());
if (!svhost) {
return err;
}
obj->set("id", SrsJsonAny::str(svhost->id.c_str()));
obj->set("name", vhost->dumps_arg0_to_str());
obj->set("enabled", SrsJsonAny::boolean(get_vhost_enabled(vhost)));

@ -194,7 +194,7 @@ srs_error_t SrsGoApiRoot::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
SrsAutoFree(SrsJsonObject, obj);
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
obj->set("server", SrsJsonAny::integer(stat->server_id()));
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
SrsJsonObject* urls = SrsJsonAny::object();
obj->set("urls", urls);
@ -232,7 +232,7 @@ srs_error_t SrsGoApiApi::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
SrsAutoFree(SrsJsonObject, obj);
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
obj->set("server", SrsJsonAny::integer(stat->server_id()));
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
SrsJsonObject* urls = SrsJsonAny::object();
obj->set("urls", urls);
@ -258,7 +258,7 @@ srs_error_t SrsGoApiV1::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r
SrsAutoFree(SrsJsonObject, obj);
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
obj->set("server", SrsJsonAny::integer(stat->server_id()));
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
SrsJsonObject* urls = SrsJsonAny::object();
obj->set("urls", urls);
@ -307,7 +307,7 @@ srs_error_t SrsGoApiVersion::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
SrsAutoFree(SrsJsonObject, obj);
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
obj->set("server", SrsJsonAny::integer(stat->server_id()));
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
SrsJsonObject* data = SrsJsonAny::object();
obj->set("data", data);
@ -336,7 +336,7 @@ srs_error_t SrsGoApiSummaries::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMes
SrsAutoFree(SrsJsonObject, obj);
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
obj->set("server", SrsJsonAny::integer(stat->server_id()));
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
srs_api_dump_summaries(obj);
@ -359,7 +359,7 @@ srs_error_t SrsGoApiRusages::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
SrsAutoFree(SrsJsonObject, obj);
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
obj->set("server", SrsJsonAny::integer(stat->server_id()));
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
SrsJsonObject* data = SrsJsonAny::object();
obj->set("data", data);
@ -404,7 +404,7 @@ srs_error_t SrsGoApiSelfProcStats::serve_http(ISrsHttpResponseWriter* w, ISrsHtt
SrsAutoFree(SrsJsonObject, obj);
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
obj->set("server", SrsJsonAny::integer(stat->server_id()));
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
SrsJsonObject* data = SrsJsonAny::object();
obj->set("data", data);
@ -481,7 +481,7 @@ srs_error_t SrsGoApiSystemProcStats::serve_http(ISrsHttpResponseWriter* w, ISrsH
SrsAutoFree(SrsJsonObject, obj);
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
obj->set("server", SrsJsonAny::integer(stat->server_id()));
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
SrsJsonObject* data = SrsJsonAny::object();
obj->set("data", data);
@ -520,7 +520,7 @@ srs_error_t SrsGoApiMemInfos::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
SrsAutoFree(SrsJsonObject, obj);
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
obj->set("server", SrsJsonAny::integer(stat->server_id()));
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
SrsJsonObject* data = SrsJsonAny::object();
obj->set("data", data);
@ -560,7 +560,7 @@ srs_error_t SrsGoApiAuthors::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
SrsAutoFree(SrsJsonObject, obj);
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
obj->set("server", SrsJsonAny::integer(stat->server_id()));
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
SrsJsonObject* data = SrsJsonAny::object();
obj->set("data", data);
@ -587,7 +587,7 @@ srs_error_t SrsGoApiFeatures::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
SrsAutoFree(SrsJsonObject, obj);
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
obj->set("server", SrsJsonAny::integer(stat->server_id()));
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
SrsJsonObject* data = SrsJsonAny::object();
obj->set("data", data);
@ -655,7 +655,7 @@ srs_error_t SrsGoApiRequests::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
SrsAutoFree(SrsJsonObject, obj);
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
obj->set("server", SrsJsonAny::integer(stat->server_id()));
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
SrsJsonObject* data = SrsJsonAny::object();
obj->set("data", data);
@ -699,10 +699,10 @@ srs_error_t SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessag
// path: {pattern}{vhost_id}
// e.g. /api/v1/vhosts/100 pattern= /api/v1/vhosts/, vhost_id=100
std::string vid = r->parse_rest_id(entry->pattern);
string vid = r->parse_rest_id(entry->pattern);
SrsStatisticVhost* vhost = NULL;
if (vid != "" && (vhost = stat->find_vhost(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);
}
@ -710,7 +710,7 @@ srs_error_t SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessag
SrsAutoFree(SrsJsonObject, obj);
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
obj->set("server", SrsJsonAny::integer(stat->server_id()));
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
if (r->is_http_get()) {
if (!vhost) {
@ -755,10 +755,10 @@ srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
// path: {pattern}{stream_id}
// e.g. /api/v1/streams/100 pattern= /api/v1/streams/, stream_id=100
std::string sid = r->parse_rest_id(entry->pattern);
string sid = r->parse_rest_id(entry->pattern);
SrsStatisticStream* stream = NULL;
if (sid != "" && (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);
}
@ -766,7 +766,7 @@ srs_error_t SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
SrsAutoFree(SrsJsonObject, obj);
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
obj->set("server", SrsJsonAny::integer(stat->server_id()));
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
if (r->is_http_get()) {
if (!stream) {
@ -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 client_id = r->parse_rest_id(entry->pattern);
string client_id = r->parse_rest_id(entry->pattern);
SrsStatisticClient* client = NULL;
if (client_id != "" && (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);
}
@ -822,7 +822,7 @@ srs_error_t SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessa
SrsAutoFree(SrsJsonObject, obj);
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
obj->set("server", SrsJsonAny::integer(stat->server_id()));
obj->set("server", SrsJsonAny::str(stat->server_id().c_str()));
if (r->is_http_get()) {
if (!client) {

@ -606,7 +606,7 @@ srs_error_t SrsLiveStream::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess
// update the statistic when source disconveried.
SrsStatistic* stat = SrsStatistic::instance();
if ((err = stat->on_client(_srs_context->get_id(), req, hc, SrsRtmpConnPlay)) != srs_success) {
if ((err = stat->on_client(srs_int2str(_srs_context->get_id()), req, hc, SrsRtmpConnPlay)) != srs_success) {
return srs_error_wrap(err, "stat on client");
}

@ -533,7 +533,7 @@ srs_error_t SrsRtmpConn::stream_service_cycle()
// update the statistic when source disconveried.
SrsStatistic* stat = SrsStatistic::instance();
if ((err = stat->on_client(_srs_context->get_id(), req, this, info->type)) != srs_success) {
if ((err = stat->on_client(srs_int2str(_srs_context->get_id()), req, this, info->type)) != srs_success) {
return srs_error_wrap(err, "rtmp: stat client");
}

@ -2527,7 +2527,7 @@ srs_error_t SrsSource::on_publish()
}
SrsStatistic* stat = SrsStatistic::instance();
stat->on_stream_publish(req, _source_id);
stat->on_stream_publish(req, srs_int2str(_source_id));
return err;
}

@ -35,14 +35,14 @@ using namespace std;
#include <srs_kernel_utility.hpp>
#include <srs_protocol_amf0.hpp>
int64_t srs_gvid = 0;
int64_t srs_generate_id()
string srs_generate_id()
{
static int64_t srs_gvid = 0;
if (srs_gvid == 0) {
srs_gvid = getpid() * 3;
}
return srs_gvid++;
return "vid-" + srs_int2str(srs_gvid++);
}
SrsStatisticVhost::SrsStatisticVhost()
@ -202,7 +202,6 @@ void SrsStatisticStream::close()
SrsStatisticClient::SrsStatisticClient()
{
id = "";
stream = NULL;
conn = NULL;
req = NULL;
@ -318,15 +317,28 @@ SrsStatistic* SrsStatistic::instance()
return _instance;
}
SrsStatisticVhost* SrsStatistic::find_vhost(string vid)
SrsStatisticVhost* SrsStatistic::find_vhost_by_id(std::string vid)
{
std::map<std::string, SrsStatisticVhost*>::iterator it;
std::map<string, SrsStatisticVhost*>::iterator it;
if ((it = vhosts.find(vid)) != vhosts.end()) {
return it->second;
}
return NULL;
}
SrsStatisticVhost* SrsStatistic::find_vhost_by_name(string name)
{
if (rvhosts.empty()) {
return NULL;
}
std::map<string, SrsStatisticVhost*>::iterator it;
if ((it = rvhosts.find(name)) != rvhosts.end()) {
return it->second;
}
return NULL;
}
SrsStatisticStream* SrsStatistic::find_stream(string sid)
{
std::map<std::string, SrsStatisticStream*>::iterator it;
@ -516,7 +528,7 @@ SrsKbps* SrsStatistic::kbps_sample()
return kbps;
}
int64_t SrsStatistic::server_id()
std::string SrsStatistic::server_id()
{
return _server_id;
}

@ -149,7 +149,7 @@ class SrsStatistic : public ISrsProtocolPerf
private:
static SrsStatistic *_instance;
// The id to identify the sever.
int64_t _server_id;
std::string _server_id;
private:
// The key: vhost id, value: vhost object.
std::map<std::string, SrsStatisticVhost*> vhosts;
@ -180,7 +180,8 @@ private:
public:
static SrsStatistic* instance();
public:
virtual SrsStatisticVhost* find_vhost(std::string vid);
virtual SrsStatisticVhost* find_vhost_by_id(std::string vid);
virtual SrsStatisticVhost* find_vhost_by_name(std::string name);
virtual SrsStatisticStream* find_stream(std::string sid);
virtual SrsStatisticClient* find_client(std::string client_id);
public:
@ -222,7 +223,7 @@ public:
public:
// Get the server id, used to identify the server.
// For example, when restart, the server id must changed.
virtual int64_t server_id();
virtual std::string server_id();
// Dumps the vhosts to amf0 array.
virtual srs_error_t dumps_vhosts(SrsJsonArray* arr);
// Dumps the streams to amf0 array.

@ -24,6 +24,6 @@
#ifndef SRS_CORE_VERSION3_HPP
#define SRS_CORE_VERSION3_HPP
#define SRS_VERSION3_REVISION 156
#define SRS_VERSION3_REVISION 157
#endif

@ -478,11 +478,11 @@ public:
virtual std::string path() = 0;
virtual std::string query() = 0;
virtual std::string ext() = 0;
// Get the RESTful id,
// Get the RESTful id, in string,
// for example, pattern is /api/v1/streams, path is /api/v1/streams/100,
// then the rest id is 100.
// @param pattern the handler pattern which will serve the request.
// @return the REST id; -1 if not matched.
// @return the REST id; "" if not matched.
virtual std::string parse_rest_id(std::string pattern) = 0;
public:
// Read body to string.

@ -573,7 +573,13 @@ VOID TEST(HTTPServerTest, MessageConnection)
if (true) {
SrsHttpMessage m;
HELPER_EXPECT_SUCCESS(m.set_url("http://127.0.0.1/v1/streams/100", false));
EXPECT_EQ("100", m.parse_rest_id("/v1/streams/")); EXPECT_FALSE(m.is_jsonp());
EXPECT_STREQ("100", m.parse_rest_id("/v1/streams/").c_str()); EXPECT_FALSE(m.is_jsonp());
}
if (true) {
SrsHttpMessage m;
HELPER_EXPECT_SUCCESS(m.set_url("http://127.0.0.1/v1/streams/abc", false));
EXPECT_STREQ("abc", m.parse_rest_id("/v1/streams/").c_str()); EXPECT_FALSE(m.is_jsonp());
}
}

Loading…
Cancel
Save