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:
		
							parent
							
								
									d7437834d4
								
							
						
					
					
						commit
						06e7a20b5f
					
				
					 3 changed files with 96 additions and 61 deletions
				
			
		| 
						 | 
				
			
			@ -3,6 +3,93 @@
 | 
			
		|||
#include "stringex.hpp"
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
bool is_streamid_valid(const std::string& streamid) {
 | 
			
		||||
    int mode = ERR_SRT_MODE;
 | 
			
		||||
    std::string url_subpash;
 | 
			
		||||
 | 
			
		||||
    bool ret = get_streamid_info(streamid, mode, url_subpash);
 | 
			
		||||
    if (!ret) {
 | 
			
		||||
        return ret;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if ((mode != PULL_SRT_MODE) && (mode != PUSH_SRT_MODE)) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (url_subpash.empty()) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    std::vector<std::string> info_vec;
 | 
			
		||||
    string_split(url_subpash, "/", info_vec);
 | 
			
		||||
    if (info_vec.size() < 2) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool get_key_value(const std::string& info, std::string& key, std::string& value) {
 | 
			
		||||
    size_t pos = info.find("=");
 | 
			
		||||
 | 
			
		||||
    if (pos == info.npos) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    key = info.substr(0, pos);
 | 
			
		||||
    value = info.substr(pos+1);
 | 
			
		||||
 | 
			
		||||
    if (key.empty() || value.empty()) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//eg. streamid=#!::h:live/livestream,m:publish
 | 
			
		||||
bool get_streamid_info(const std::string& streamid, int& mode, std::string& url_subpash) {
 | 
			
		||||
    std::vector<std::string> info_vec;
 | 
			
		||||
    std::string real_streamid;
 | 
			
		||||
 | 
			
		||||
    size_t pos = streamid.find("#!::h");
 | 
			
		||||
    if (pos != 0) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    real_streamid = streamid.substr(4);
 | 
			
		||||
 | 
			
		||||
    string_split(real_streamid, ",", info_vec);
 | 
			
		||||
    if (info_vec.size() < 2) {
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (int index = 0; index < info_vec.size(); index++) {
 | 
			
		||||
        std::string key;
 | 
			
		||||
        std::string value;
 | 
			
		||||
 | 
			
		||||
        bool ret = get_key_value(info_vec[index], key, value);
 | 
			
		||||
        if (!ret) {
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        if (key == "h") {
 | 
			
		||||
            url_subpash = value;//eg. h=live/stream
 | 
			
		||||
        } else if (key == "m") {
 | 
			
		||||
            std::string mode_str = string_lower(value);//m=publish or m=request
 | 
			
		||||
            if (mode_str == "publish") {
 | 
			
		||||
                mode = PUSH_SRT_MODE;
 | 
			
		||||
            } else if (mode_str == "request") {
 | 
			
		||||
                mode = PULL_SRT_MODE;
 | 
			
		||||
            } else {
 | 
			
		||||
                mode = ERR_SRT_MODE;
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
        } else {//not suport
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
srt_conn::srt_conn(SRTSOCKET conn_fd, const std::string& streamid):_conn_fd(conn_fd),
 | 
			
		||||
    _streamid(streamid) {
 | 
			
		||||
    get_streamid_info(streamid, _mode, _url_subpath);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -421,7 +421,12 @@ void srt_handle::handle_srt_socket(SRT_SOCKSTATUS status, SRTSOCKET conn_fd)
 | 
			
		|||
        }
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    get_streamid_info(conn_ptr->get_streamid(), mode, subpath);
 | 
			
		||||
    bool ret = get_streamid_info(conn_ptr->get_streamid(), mode, subpath);
 | 
			
		||||
    if (!ret) {
 | 
			
		||||
        conn_ptr->close();
 | 
			
		||||
        conn_ptr = nullptr;
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    if (mode == PUSH_SRT_MODE) {
 | 
			
		||||
        switch (status)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue