From c876e539243ada420dfd29862d620e21ccffcfeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=8F=E6=A5=9A?= <771730766@qq.com> Date: Fri, 27 Oct 2023 21:39:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96ffmpeg=20url=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E8=A7=84=E5=88=99=EF=BC=8C=E6=8F=90=E9=AB=98rtmp?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E5=85=BC=E5=AE=B9=E6=80=A7=20(#2936?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根据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 --- src/Rtmp/RtmpPlayer.cpp | 21 +++++++++++---------- src/Rtmp/RtmpPusher.cpp | 16 +++++++++++----- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/Rtmp/RtmpPlayer.cpp b/src/Rtmp/RtmpPlayer.cpp index 42914cda..13c0131b 100644 --- a/src/Rtmp/RtmpPlayer.cpp +++ b/src/Rtmp/RtmpPlayer.cpp @@ -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; } diff --git a/src/Rtmp/RtmpPusher.cpp b/src/Rtmp/RtmpPusher.cpp index f401cf34..c48f3820 100644 --- a/src/Rtmp/RtmpPusher.cpp +++ b/src/Rtmp/RtmpPusher.cpp @@ -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(); - 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(), "/"); _stream_id = findSubString(url.data(), (host_url + "/" + _app + "/").data(), NULL); - _tc_url = string("rtmp://") + host_url + "/" + _app; - - if (!_app.size() || !_stream_id.size()) { + 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); + } + _tc_url = schema + "://" + host_url + "/" + _app; + if (_app.empty() || _stream_id.empty()) { onPublishResult_l(SockException(Err_other, "rtmp url非法"), false); return; }