正在显示
5 个修改的文件
包含
68 行增加
和
9 行删除
| @@ -2270,6 +2270,29 @@ int SrsConfig::raw_set_pid(string pid, bool& applied) | @@ -2270,6 +2270,29 @@ int SrsConfig::raw_set_pid(string pid, bool& applied) | ||
| 2270 | return ret; | 2270 | return ret; |
| 2271 | } | 2271 | } |
| 2272 | 2272 | ||
| 2273 | +int SrsConfig::raw_set_chunk_size(string chunk_size, bool& applied) | ||
| 2274 | +{ | ||
| 2275 | + int ret = ERROR_SUCCESS; | ||
| 2276 | + | ||
| 2277 | + applied = false; | ||
| 2278 | + | ||
| 2279 | + | ||
| 2280 | + SrsConfDirective* conf = root->get_or_create("chunk_size"); | ||
| 2281 | + | ||
| 2282 | + if (conf->arg0() == chunk_size) { | ||
| 2283 | + return ret; | ||
| 2284 | + } | ||
| 2285 | + | ||
| 2286 | + conf->args.clear(); | ||
| 2287 | + conf->args.push_back(chunk_size); | ||
| 2288 | + | ||
| 2289 | + // directly supported reload for chunk_size change. | ||
| 2290 | + | ||
| 2291 | + applied = true; | ||
| 2292 | + | ||
| 2293 | + return ret; | ||
| 2294 | +} | ||
| 2295 | + | ||
| 2273 | int SrsConfig::do_reload_listen() | 2296 | int SrsConfig::do_reload_listen() |
| 2274 | { | 2297 | { |
| 2275 | int ret = ERROR_SUCCESS; | 2298 | int ret = ERROR_SUCCESS; |
| @@ -341,6 +341,10 @@ public: | @@ -341,6 +341,10 @@ public: | ||
| 341 | * raw set the global pid. | 341 | * raw set the global pid. |
| 342 | */ | 342 | */ |
| 343 | virtual int raw_set_pid(std::string pid, bool& applied); | 343 | virtual int raw_set_pid(std::string pid, bool& applied); |
| 344 | + /** | ||
| 345 | + * raw set the global chunk size. | ||
| 346 | + */ | ||
| 347 | + virtual int raw_set_chunk_size(std::string chunk_size, bool& applied); | ||
| 344 | private: | 348 | private: |
| 345 | virtual int do_reload_listen(); | 349 | virtual int do_reload_listen(); |
| 346 | virtual int do_reload_pid(); | 350 | virtual int do_reload_pid(); |
| @@ -986,8 +986,9 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | @@ -986,8 +986,9 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | ||
| 986 | // @param value the updated value for scope. | 986 | // @param value the updated value for scope. |
| 987 | // possible updates: | 987 | // possible updates: |
| 988 | // @param scope @param value value-description | 988 | // @param scope @param value value-description |
| 989 | - // global.listen 1935,1936 the port list. | ||
| 990 | - // global.pid ./objs/srs.pid the pid file of srs. | 989 | + // listen 1935,1936 the port list. |
| 990 | + // pid ./objs/srs.pid the pid file of srs. | ||
| 991 | + // chunk_size 60000 the global RTMP chunk_size. | ||
| 991 | if (rpc == "update") { | 992 | if (rpc == "update") { |
| 992 | if (!allow_update) { | 993 | if (!allow_update) { |
| 993 | ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED; | 994 | ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED; |
| @@ -997,14 +998,14 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | @@ -997,14 +998,14 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | ||
| 997 | 998 | ||
| 998 | std::string scope = r->query_get("scope"); | 999 | std::string scope = r->query_get("scope"); |
| 999 | std::string value = r->query_get("value"); | 1000 | std::string value = r->query_get("value"); |
| 1000 | - if (scope.empty() || (scope != "global.listen" && scope != "global.pid")) { | 1001 | + if (scope.empty() || (scope != "listen" && scope != "pid" && scope != "chunk_size")) { |
| 1001 | ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; | 1002 | ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED; |
| 1002 | srs_error("raw api query invalid scope=%s. ret=%d", scope.c_str(), ret); | 1003 | srs_error("raw api query invalid scope=%s. ret=%d", scope.c_str(), ret); |
| 1003 | return srs_api_response_code(w, r, ret); | 1004 | return srs_api_response_code(w, r, ret); |
| 1004 | } | 1005 | } |
| 1005 | 1006 | ||
| 1006 | bool applied = false; | 1007 | bool applied = false; |
| 1007 | - if (scope == "global.listen") { | 1008 | + if (scope == "listen") { |
| 1008 | vector<string> eps = srs_string_split(value, ","); | 1009 | vector<string> eps = srs_string_split(value, ","); |
| 1009 | 1010 | ||
| 1010 | bool invalid = eps.empty(); | 1011 | bool invalid = eps.empty(); |
| @@ -1018,15 +1019,15 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | @@ -1018,15 +1019,15 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | ||
| 1018 | } | 1019 | } |
| 1019 | if (invalid) { | 1020 | if (invalid) { |
| 1020 | ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; | 1021 | ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; |
| 1021 | - srs_error("raw api update check global.listen=%s failed. ret=%d", value.c_str(), ret); | 1022 | + srs_error("raw api update check listen=%s failed. ret=%d", value.c_str(), ret); |
| 1022 | return srs_api_response_code(w, r, ret); | 1023 | return srs_api_response_code(w, r, ret); |
| 1023 | } | 1024 | } |
| 1024 | 1025 | ||
| 1025 | if ((ret = _srs_config->raw_set_listen(eps, applied)) != ERROR_SUCCESS) { | 1026 | if ((ret = _srs_config->raw_set_listen(eps, applied)) != ERROR_SUCCESS) { |
| 1026 | - srs_error("raw api update global.listen=%s failed. ret=%d", value.c_str(), ret); | 1027 | + srs_error("raw api update listen=%s failed. ret=%d", value.c_str(), ret); |
| 1027 | return srs_api_response_code(w, r, ret); | 1028 | return srs_api_response_code(w, r, ret); |
| 1028 | } | 1029 | } |
| 1029 | - } else if (scope == "global.pid") { | 1030 | + } else if (scope == "pid") { |
| 1030 | bool invalid = value.empty(); | 1031 | bool invalid = value.empty(); |
| 1031 | if (!invalid) { | 1032 | if (!invalid) { |
| 1032 | invalid = !srs_string_starts_with(value, "./") | 1033 | invalid = !srs_string_starts_with(value, "./") |
| @@ -1038,12 +1039,24 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | @@ -1038,12 +1039,24 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) | ||
| 1038 | } | 1039 | } |
| 1039 | if (invalid) { | 1040 | if (invalid) { |
| 1040 | ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; | 1041 | ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; |
| 1041 | - srs_error("raw api update check global.pid=%s failed. ret=%d", value.c_str(), ret); | 1042 | + srs_error("raw api update check pid=%s failed. ret=%d", value.c_str(), ret); |
| 1042 | return srs_api_response_code(w, r, ret); | 1043 | return srs_api_response_code(w, r, ret); |
| 1043 | } | 1044 | } |
| 1044 | 1045 | ||
| 1045 | if ((ret = _srs_config->raw_set_pid(value, applied)) != ERROR_SUCCESS) { | 1046 | if ((ret = _srs_config->raw_set_pid(value, applied)) != ERROR_SUCCESS) { |
| 1046 | - srs_error("raw api update global.pid=%s failed. ret=%d", value.c_str(), ret); | 1047 | + srs_error("raw api update pid=%s failed. ret=%d", value.c_str(), ret); |
| 1048 | + return srs_api_response_code(w, r, ret); | ||
| 1049 | + } | ||
| 1050 | + } else if (scope == "chunk_size") { | ||
| 1051 | + int csv = ::atoi(value.c_str()); | ||
| 1052 | + if (csv < 128 || csv > 65535 || !srs_is_digit_number(value)) { | ||
| 1053 | + ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS; | ||
| 1054 | + srs_error("raw api update check chunk_size=%s/%d failed. ret=%d", value.c_str(), csv, ret); | ||
| 1055 | + return srs_api_response_code(w, r, ret); | ||
| 1056 | + } | ||
| 1057 | + | ||
| 1058 | + if ((ret = _srs_config->raw_set_chunk_size(value, applied)) != ERROR_SUCCESS) { | ||
| 1059 | + srs_error("raw api update chunk_size=%s/%d failed. ret=%d", value.c_str(), csv, ret); | ||
| 1047 | return srs_api_response_code(w, r, ret); | 1060 | return srs_api_response_code(w, r, ret); |
| 1048 | } | 1061 | } |
| 1049 | } | 1062 | } |
| @@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 35 | #endif | 35 | #endif |
| 36 | #include <stdlib.h> | 36 | #include <stdlib.h> |
| 37 | #include <sys/time.h> | 37 | #include <sys/time.h> |
| 38 | +#include <math.h> | ||
| 38 | #include <map> | 39 | #include <map> |
| 39 | using namespace std; | 40 | using namespace std; |
| 40 | 41 | ||
| @@ -1355,6 +1356,17 @@ string srs_get_peer_ip(int fd) | @@ -1355,6 +1356,17 @@ string srs_get_peer_ip(int fd) | ||
| 1355 | return ip; | 1356 | return ip; |
| 1356 | } | 1357 | } |
| 1357 | 1358 | ||
| 1359 | +bool srs_is_digit_number(const string& str) | ||
| 1360 | +{ | ||
| 1361 | + if (str.empty()) { | ||
| 1362 | + return false; | ||
| 1363 | + } | ||
| 1364 | + | ||
| 1365 | + int v = ::atoi(str.c_str()); | ||
| 1366 | + int powv = (int)pow(10, str.length() - 1); | ||
| 1367 | + return v / powv >= 1 && v / powv <= 9; | ||
| 1368 | +} | ||
| 1369 | + | ||
| 1358 | void srs_api_dump_summaries(SrsAmf0Object* obj) | 1370 | void srs_api_dump_summaries(SrsAmf0Object* obj) |
| 1359 | { | 1371 | { |
| 1360 | SrsRusage* r = srs_get_system_rusage(); | 1372 | SrsRusage* r = srs_get_system_rusage(); |
| @@ -669,6 +669,13 @@ extern int srs_get_local_port(int fd); | @@ -669,6 +669,13 @@ extern int srs_get_local_port(int fd); | ||
| 669 | // where peer ip is the client public ip which connected to server. | 669 | // where peer ip is the client public ip which connected to server. |
| 670 | extern std::string srs_get_peer_ip(int fd); | 670 | extern std::string srs_get_peer_ip(int fd); |
| 671 | 671 | ||
| 672 | +// whether string is digit number | ||
| 673 | +// is_digit("1234567890") === true | ||
| 674 | +// is_digit("0123456789") === false | ||
| 675 | +// is_digit("1234567890a") === false | ||
| 676 | +// is_digit("a1234567890") === false | ||
| 677 | +extern bool srs_is_digit_number(const std::string& str); | ||
| 678 | + | ||
| 672 | // dump summaries for /api/v1/summaries. | 679 | // dump summaries for /api/v1/summaries. |
| 673 | extern void srs_api_dump_summaries(SrsAmf0Object* obj); | 680 | extern void srs_api_dump_summaries(SrsAmf0Object* obj); |
| 674 | 681 |
-
请 注册 或 登录 后发表评论