1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

update streamid decode

This commit is contained in:
runner365 2020-01-23 17:19:06 +08:00
parent d7437834d4
commit 06e7a20b5f
3 changed files with 96 additions and 61 deletions

View file

@ -15,66 +15,9 @@
#define PULL_SRT_MODE 0x01
#define PUSH_SRT_MODE 0x02
inline bool is_streamid_valid(const std::string& streamid) {
bool ret = false;
if (streamid.empty()) {
return ret;
}
//check whether subpath is valid, eg. live/test or srs.srt.com.cn/live/test
std::vector<std::string> ret_vec;
string_split(streamid, "/", ret_vec);
if (ret_vec.size() < 2) {
return ret;
}
//check whether mode is valid, eg. live/test?m=push or live/test?m=pull
size_t pos = streamid.find("?");
if (pos == streamid.npos) {
return ret;
}
std::string mode = streamid.substr(pos+1);
string_split(mode, "=", ret_vec);
if (ret_vec.size() != 2) {
return ret;
}
//it must be m=push or m=pull
std::string mode_oper = string_lower(ret_vec[1]);
if ((ret_vec[0] != "m") || ((mode_oper != "push") && (mode_oper != "pull"))) {
return ret;
}
ret = true;
return ret;
}
inline void get_streamid_info(const std::string& streamid, int& mode, std::string& url_subpash) {
std::string real_streamip;
size_t pos = streamid.find("?");
if (pos == std::string::npos) {
mode = ERR_SRT_MODE;
url_subpash = streamid;
} else {
std::string mode_str = streamid.substr(pos+1);
url_subpash = streamid.substr(0, pos);
size_t mode_pos = mode_str.find("m=");
if (mode_pos == std::string::npos) {
mode = PULL_SRT_MODE;
} else {
mode_str = mode_str.substr(mode_pos+2);
mode_str = string_lower(mode_str);
if (mode_str == "push") {
mode = PUSH_SRT_MODE;
} else if(mode_str == "pull"){
mode = PULL_SRT_MODE;
} else {
mode = ERR_SRT_MODE;
}
}
}
}
bool is_streamid_valid(const std::string& streamid);
bool get_key_value(const std::string& info, std::string& key, std::string& value);
bool get_streamid_info(const std::string& streamid, int& mode, std::string& url_subpash);
class srt_conn {
public: