优化rtmp播放器url解析逻辑
This commit is contained in:
parent
be46a37d3a
commit
1b95ed1c97
|
|
@ -52,17 +52,18 @@ void RtmpPlayer::teardown() {
|
|||
|
||||
void RtmpPlayer::play(const string &url) {
|
||||
teardown();
|
||||
string host_url = findSubString(url.data(), "://", "/");
|
||||
{
|
||||
auto pos = url.find_last_of('/');
|
||||
if (pos != string::npos) {
|
||||
_stream_id = url.substr(pos + 1);
|
||||
}
|
||||
auto schema = findSubString(url.data(), nullptr, "://");
|
||||
auto host_url = findSubString(url.data(), "://", "/");
|
||||
_app = findSubString(url.data(), (host_url + "/").data(), "/");
|
||||
_stream_id = findSubString(url.data(), (host_url + "/" + _app + "/").data(), NULL);
|
||||
auto app_second = findSubString(_stream_id.data(), nullptr, "/");
|
||||
if (!app_second.empty() && app_second.find('?') == std::string::npos) {
|
||||
// _stream_id存在多级;不包含'?', 说明分割符'/'不是url参数的一部分
|
||||
_app += "/" + app_second;
|
||||
_stream_id.erase(0, app_second.size() + 1);
|
||||
}
|
||||
_app = findSubString(url.data(), (host_url + "/").data(), ("/" + _stream_id).data());
|
||||
_tc_url = string("rtmp://") + host_url + "/" + _app;
|
||||
|
||||
if (!_app.size() || !_stream_id.size()) {
|
||||
_tc_url = schema + "://" + host_url + "/" + _app;
|
||||
if (_app.empty() || _stream_id.empty()) {
|
||||
onPlayResult_l(SockException(Err_other, "rtmp url非法"), false);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ void RtmpPusher::publish(const string &url) {
|
|||
if (!app_second.empty() && app_second.find('?') == std::string::npos) {
|
||||
// _stream_id存在多级;不包含'?', 说明分割符'/'不是url参数的一部分
|
||||
_app += "/" + app_second;
|
||||
_stream_id.erase(0, app_second.size());
|
||||
_stream_id.erase(0, app_second.size() + 1);
|
||||
}
|
||||
_tc_url = schema + "://" + host_url + "/" + _app;
|
||||
if (_app.empty() || _stream_id.empty()) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue