Skip to content

Commit

Permalink
for #319, raw api support update the global RTMP chunk_size.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Sep 1, 2015
1 parent 2cfb716 commit c8466c3
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 9 deletions.
23 changes: 23 additions & 0 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2270,6 +2270,29 @@ int SrsConfig::raw_set_pid(string pid, bool& applied)
return ret;
}

int SrsConfig::raw_set_chunk_size(string chunk_size, bool& applied)
{
int ret = ERROR_SUCCESS;

applied = false;


SrsConfDirective* conf = root->get_or_create("chunk_size");

if (conf->arg0() == chunk_size) {
return ret;
}

conf->args.clear();
conf->args.push_back(chunk_size);

// directly supported reload for chunk_size change.

applied = true;

return ret;
}

int SrsConfig::do_reload_listen()
{
int ret = ERROR_SUCCESS;
Expand Down
4 changes: 4 additions & 0 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ class SrsConfig
* raw set the global pid.
*/
virtual int raw_set_pid(std::string pid, bool& applied);
/**
* raw set the global chunk size.
*/
virtual int raw_set_chunk_size(std::string chunk_size, bool& applied);
private:
virtual int do_reload_listen();
virtual int do_reload_pid();
Expand Down
31 changes: 22 additions & 9 deletions trunk/src/app/srs_app_http_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,8 +986,9 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
// @param value the updated value for scope.
// possible updates:
// @param scope @param value value-description
// global.listen 1935,1936 the port list.
// global.pid ./objs/srs.pid the pid file of srs.
// listen 1935,1936 the port list.
// pid ./objs/srs.pid the pid file of srs.
// chunk_size 60000 the global RTMP chunk_size.
if (rpc == "update") {
if (!allow_update) {
ret = ERROR_SYSTEM_CONFIG_RAW_DISABLED;
Expand All @@ -997,14 +998,14 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)

std::string scope = r->query_get("scope");
std::string value = r->query_get("value");
if (scope.empty() || (scope != "global.listen" && scope != "global.pid")) {
if (scope.empty() || (scope != "listen" && scope != "pid" && scope != "chunk_size")) {
ret = ERROR_SYSTEM_CONFIG_RAW_NOT_ALLOWED;
srs_error("raw api query invalid scope=%s. ret=%d", scope.c_str(), ret);
return srs_api_response_code(w, r, ret);
}

bool applied = false;
if (scope == "global.listen") {
if (scope == "listen") {
vector<string> eps = srs_string_split(value, ",");

bool invalid = eps.empty();
Expand All @@ -1018,15 +1019,15 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
}
if (invalid) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS;
srs_error("raw api update check global.listen=%s failed. ret=%d", value.c_str(), ret);
srs_error("raw api update check listen=%s failed. ret=%d", value.c_str(), ret);
return srs_api_response_code(w, r, ret);
}

if ((ret = _srs_config->raw_set_listen(eps, applied)) != ERROR_SUCCESS) {
srs_error("raw api update global.listen=%s failed. ret=%d", value.c_str(), ret);
srs_error("raw api update listen=%s failed. ret=%d", value.c_str(), ret);
return srs_api_response_code(w, r, ret);
}
} else if (scope == "global.pid") {
} else if (scope == "pid") {
bool invalid = value.empty();
if (!invalid) {
invalid = !srs_string_starts_with(value, "./")
Expand All @@ -1038,12 +1039,24 @@ int SrsGoApiRaw::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
}
if (invalid) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS;
srs_error("raw api update check global.pid=%s failed. ret=%d", value.c_str(), ret);
srs_error("raw api update check pid=%s failed. ret=%d", value.c_str(), ret);
return srs_api_response_code(w, r, ret);
}

if ((ret = _srs_config->raw_set_pid(value, applied)) != ERROR_SUCCESS) {
srs_error("raw api update global.pid=%s failed. ret=%d", value.c_str(), ret);
srs_error("raw api update pid=%s failed. ret=%d", value.c_str(), ret);
return srs_api_response_code(w, r, ret);
}
} else if (scope == "chunk_size") {
int csv = ::atoi(value.c_str());
if (csv < 128 || csv > 65535 || !srs_is_digit_number(value)) {
ret = ERROR_SYSTEM_CONFIG_RAW_PARAMS;
srs_error("raw api update check chunk_size=%s/%d failed. ret=%d", value.c_str(), csv, ret);
return srs_api_response_code(w, r, ret);
}

if ((ret = _srs_config->raw_set_chunk_size(value, applied)) != ERROR_SUCCESS) {
srs_error("raw api update chunk_size=%s/%d failed. ret=%d", value.c_str(), csv, ret);
return srs_api_response_code(w, r, ret);
}
}
Expand Down
12 changes: 12 additions & 0 deletions trunk/src/app/srs_app_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#endif
#include <stdlib.h>
#include <sys/time.h>
#include <math.h>
#include <map>
using namespace std;

Expand Down Expand Up @@ -1355,6 +1356,17 @@ string srs_get_peer_ip(int fd)
return ip;
}

bool srs_is_digit_number(const string& str)
{
if (str.empty()) {
return false;
}

int v = ::atoi(str.c_str());
int powv = (int)pow(10, str.length() - 1);
return v / powv >= 1 && v / powv <= 9;
}

void srs_api_dump_summaries(SrsAmf0Object* obj)
{
SrsRusage* r = srs_get_system_rusage();
Expand Down
7 changes: 7 additions & 0 deletions trunk/src/app/srs_app_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,13 @@ extern int srs_get_local_port(int fd);
// where peer ip is the client public ip which connected to server.
extern std::string srs_get_peer_ip(int fd);

// whether string is digit number
// is_digit("1234567890") === true
// is_digit("0123456789") === false
// is_digit("1234567890a") === false
// is_digit("a1234567890") === false
extern bool srs_is_digit_number(const std::string& str);

// dump summaries for /api/v1/summaries.
extern void srs_api_dump_summaries(SrsAmf0Object* obj);

Expand Down

0 comments on commit c8466c3

Please sign in to comment.