diff --git a/README.md b/README.md
index be4d4d2a7..38388798a 100755
--- a/README.md
+++ b/README.md
@@ -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
+* v3.0, 2021-01-02, [3.0 release3(3.0.156)][r3.0r3] released. 122736 lines.
* 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
diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp
index a07b81d2b..bbd0ab46c 100644
--- a/trunk/src/app/srs_app_config.cpp
+++ b/trunk/src/app/srs_app_config.cpp
@@ -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,9 +2371,12 @@ 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)));
diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp
index b9f5b73a6..449146aac 100644
--- a/trunk/src/app/srs_app_http_api.cpp
+++ b/trunk/src/app/srs_app_http_api.cpp
@@ -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) {
diff --git a/trunk/src/app/srs_app_rtc_api.cpp b/trunk/src/app/srs_app_rtc_api.cpp
index fd14b41d0..e1fa754ac 100644
--- a/trunk/src/app/srs_app_rtc_api.cpp
+++ b/trunk/src/app/srs_app_rtc_api.cpp
@@ -205,7 +205,7 @@ srs_error_t SrsGoApiRtcPlay::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMe
local_sdp_str = srs_string_replace(local_sdp_str.c_str(), "\r\n", "\\r\\n");
res->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
- res->set("server", SrsJsonAny::integer(SrsStatistic::instance()->server_id()));
+ res->set("server", SrsJsonAny::str(SrsStatistic::instance()->server_id().c_str()));
// TODO: add candidates in response json?
@@ -557,7 +557,7 @@ srs_error_t SrsGoApiRtcPublish::do_serve_http(ISrsHttpResponseWriter* w, ISrsHtt
local_sdp_str = srs_string_replace(local_sdp_str.c_str(), "\r\n", "\\r\\n");
res->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
- res->set("server", SrsJsonAny::integer(SrsStatistic::instance()->server_id()));
+ res->set("server", SrsJsonAny::str(SrsStatistic::instance()->server_id().c_str()));
// TODO: add candidates in response json?
diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp
index 5c4aca1d3..f2c2c314f 100644
--- a/trunk/src/app/srs_app_server.cpp
+++ b/trunk/src/app/srs_app_server.cpp
@@ -1698,7 +1698,7 @@ void SrsServer::remove(ISrsResource* c)
SrsStatistic* stat = SrsStatistic::instance();
stat->kbps_add_delta(c->get_id(), conn);
stat->on_disconnect(c->get_id());
-
+
// use manager to free it async.
conn_manager->remove(c);
}
diff --git a/trunk/src/app/srs_app_statistic.cpp b/trunk/src/app/srs_app_statistic.cpp
index fcf031447..69d4a5cb5 100644
--- a/trunk/src/app/srs_app_statistic.cpp
+++ b/trunk/src/app/srs_app_statistic.cpp
@@ -35,19 +35,22 @@ using namespace std;
#include
#include
-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;
+ srs_gvid = getpid();
}
- return srs_gvid++;
+
+ string prefix = "vid";
+ string rand_id = srs_int2str(srs_get_system_time() % 1000);
+ return prefix + "-" + srs_int2str(srs_gvid++) + "-" + rand_id;
}
SrsStatisticVhost::SrsStatisticVhost()
{
- id = srs_int2str(srs_generate_id());
+ id = srs_generate_id();
clk = new SrsWallClock();
kbps = new SrsKbps(clk);
@@ -98,7 +101,7 @@ srs_error_t SrsStatisticVhost::dumps(SrsJsonObject* obj)
SrsStatisticStream::SrsStatisticStream()
{
- id = srs_int2str(srs_generate_id());
+ id = srs_generate_id();
vhost = NULL;
active = false;
@@ -202,7 +205,6 @@ void SrsStatisticStream::close()
SrsStatisticClient::SrsStatisticClient()
{
- id = "";
stream = NULL;
conn = NULL;
req = NULL;
@@ -318,15 +320,28 @@ SrsStatistic* SrsStatistic::instance()
return _instance;
}
-SrsStatisticVhost* SrsStatistic::find_vhost(string vid)
+SrsStatisticVhost* SrsStatistic::find_vhost_by_id(std::string vid)
{
- std::map::iterator it;
+ std::map::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::iterator it;
+ if ((it = rvhosts.find(name)) != rvhosts.end()) {
+ return it->second;
+ }
+ return NULL;
+}
+
SrsStatisticStream* SrsStatistic::find_stream(string sid)
{
std::map::iterator it;
@@ -416,7 +431,7 @@ void SrsStatistic::on_stream_close(SrsRequest* req)
// TODO: FIXME: Should fix https://github.com/ossrs/srs/issues/803
if (true) {
std::map::iterator it;
- if ((it=rstreams.find(stream->url)) != rstreams.end()) {
+ if ((it = rstreams.find(stream->url)) != rstreams.end()) {
rstreams.erase(it);
}
}
@@ -516,7 +531,7 @@ SrsKbps* SrsStatistic::kbps_sample()
return kbps;
}
-int64_t SrsStatistic::server_id()
+std::string SrsStatistic::server_id()
{
return _server_id;
}
diff --git a/trunk/src/app/srs_app_statistic.hpp b/trunk/src/app/srs_app_statistic.hpp
index edd6ac821..c62eec78d 100644
--- a/trunk/src/app/srs_app_statistic.hpp
+++ b/trunk/src/app/srs_app_statistic.hpp
@@ -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 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.
diff --git a/trunk/src/core/srs_core_version3.hpp b/trunk/src/core/srs_core_version3.hpp
index 281b3955d..a3d519d3f 100644
--- a/trunk/src/core/srs_core_version3.hpp
+++ b/trunk/src/core/srs_core_version3.hpp
@@ -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
diff --git a/trunk/src/protocol/srs_http_stack.hpp b/trunk/src/protocol/srs_http_stack.hpp
index efb084a17..7e4c0da0e 100644
--- a/trunk/src/protocol/srs_http_stack.hpp
+++ b/trunk/src/protocol/srs_http_stack.hpp
@@ -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.
diff --git a/trunk/src/utest/srs_utest_service.cpp b/trunk/src/utest/srs_utest_service.cpp
index 76570b0a8..4562d27bf 100644
--- a/trunk/src/utest/srs_utest_service.cpp
+++ b/trunk/src/utest/srs_utest_service.cpp
@@ -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());
}
}