优化ffmpeg url解析规则,提高rtmp客户端兼容性 (#2936)

根据ffmpeg测试,类似rtmp://ip/a/b/c/d/e/f这样的url,app应该为a/b,stream_id应该为c/d/e/f,
tcl_url应该为rtmp://ip/a/b, teams的rtmps服务需要按这种方式才能推成功

---------

Co-authored-by: yangkun <yangkun@osee-dig.com>
This commit is contained in:
夏楚 2023-10-27 21:39:36 +08:00 committed by GitHub
parent 1a4b8406bb
commit c876e53924
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 15 deletions

View File

@ -52,17 +52,18 @@ void RtmpPlayer::teardown() {
void RtmpPlayer::play(const string &url) { void RtmpPlayer::play(const string &url) {
teardown(); teardown();
string host_url = findSubString(url.data(), "://", "/"); auto schema = findSubString(url.data(), nullptr, "://");
{ auto host_url = findSubString(url.data(), "://", "/");
auto pos = url.find_last_of('/'); _app = findSubString(url.data(), (host_url + "/").data(), "/");
if (pos != string::npos) { _stream_id = findSubString(url.data(), (host_url + "/" + _app + "/").data(), NULL);
_stream_id = url.substr(pos + 1); 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 = schema + "://" + host_url + "/" + _app;
_tc_url = string("rtmp://") + host_url + "/" + _app; if (_app.empty() || _stream_id.empty()) {
if (!_app.size() || !_stream_id.size()) {
onPlayResult_l(SockException(Err_other, "rtmp url非法"), false); onPlayResult_l(SockException(Err_other, "rtmp url非法"), false);
return; return;
} }

View File

@ -63,14 +63,20 @@ void RtmpPusher::onPublishResult_l(const SockException &ex, bool handshake_done)
} }
} }
void RtmpPusher::publish(const string &url) { void RtmpPusher::publish(const string &url) {
teardown(); teardown();
string host_url = findSubString(url.data(), "://", "/"); auto schema = findSubString(url.data(), nullptr, "://");
auto host_url = findSubString(url.data(), "://", "/");
_app = findSubString(url.data(), (host_url + "/").data(), "/"); _app = findSubString(url.data(), (host_url + "/").data(), "/");
_stream_id = findSubString(url.data(), (host_url + "/" + _app + "/").data(), NULL); _stream_id = findSubString(url.data(), (host_url + "/" + _app + "/").data(), NULL);
_tc_url = string("rtmp://") + host_url + "/" + _app; auto app_second = findSubString(_stream_id.data(), nullptr, "/");
if (!app_second.empty() && app_second.find('?') == std::string::npos) {
if (!_app.size() || !_stream_id.size()) { // _stream_id存在多级不包含'?', 说明分割符'/'不是url参数的一部分
_app += "/" + app_second;
_stream_id.erase(0, app_second.size() + 1);
}
_tc_url = schema + "://" + host_url + "/" + _app;
if (_app.empty() || _stream_id.empty()) {
onPublishResult_l(SockException(Err_other, "rtmp url非法"), false); onPublishResult_l(SockException(Err_other, "rtmp url非法"), false);
return; return;
} }