From 7fde20bb4c87714830e480b8b8db3090c764992d Mon Sep 17 00:00:00 2001 From: yangkun Date: Fri, 27 Oct 2023 10:16:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AEffmpeg=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=EF=BC=8C=E7=B1=BB=E4=BC=BCrtmps://ip/a/b/c=E8=BF=99=E6=A0=B7?= =?UTF-8?q?=E7=9A=84url,app=E5=BA=94=E8=AF=A5=E4=B8=BAa/b,stream=5Fid?= =?UTF-8?q?=E5=BA=94=E8=AF=A5=E4=B8=BAc,=20tcl=5Furl=E5=BA=94=E8=AF=A5?= =?UTF-8?q?=E4=B8=BArtmps://ip/a/b,teams=E7=9A=84rtmps=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E6=8C=89=E8=BF=99=E7=A7=8D=E6=96=B9=E5=BC=8F=E6=89=8D=E8=83=BD?= =?UTF-8?q?=E6=8E=A8=E6=88=90=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/Parser.cpp | 24 ++++++++++++++++++++++++ src/Common/Parser.h | 1 + src/Rtmp/RtmpPusher.cpp | 23 ++++++++++++++++++----- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/Common/Parser.cpp b/src/Common/Parser.cpp index 9c073f2c..012a3306 100644 --- a/src/Common/Parser.cpp +++ b/src/Common/Parser.cpp @@ -20,6 +20,30 @@ using namespace toolkit; namespace mediakit { +string findrSubString(const char *buf, const char *start, const char end, size_t buf_size) { + if (buf_size <= 0) { + buf_size = strlen(buf); + } + auto msg_start = buf; + auto msg_end = buf + buf_size; + size_t len = 0; + if (start != NULL) { + len = strlen(start); + msg_start = strstr(buf, start); + } + if (msg_start == NULL) { + return ""; + } + msg_start += len; + if (end != NULL) { + msg_end = strrchr(msg_start, end); + if (msg_end == NULL) { + return ""; + } + } + return string(msg_start, msg_end); +} + string findSubString(const char *buf, const char *start, const char *end, size_t buf_size) { if (buf_size <= 0) { buf_size = strlen(buf); diff --git a/src/Common/Parser.h b/src/Common/Parser.h index 3741f4bc..5c10cae7 100644 --- a/src/Common/Parser.h +++ b/src/Common/Parser.h @@ -18,6 +18,7 @@ namespace mediakit { // 从字符串中提取子字符串 +std::string findrSubString(const char *buf, const char *start, const char end, size_t buf_size = 0); std::string findSubString(const char *buf, const char *start, const char *end, size_t buf_size = 0); // 把url解析为主机地址和端口号,兼容ipv4/ipv6/dns void splitUrl(const std::string &url, std::string &host, uint16_t &port); diff --git a/src/Rtmp/RtmpPusher.cpp b/src/Rtmp/RtmpPusher.cpp index f401cf34..27e00ae7 100644 --- a/src/Rtmp/RtmpPusher.cpp +++ b/src/Rtmp/RtmpPusher.cpp @@ -65,12 +65,25 @@ void RtmpPusher::onPublishResult_l(const SockException &ex, bool handshake_done) void RtmpPusher::publish(const string &url) { teardown(); - string 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; + string _head ; + // rtmps rt_url head should be rtmps + const char *rtmp_head = "rtmp://"; + const char *rtmps_head = "rtmps://"; + if(0 == strncasecmp(url.c_str(), rtmp_head, strlen(rtmp_head))) + { + _head = rtmp_head; + } + if(0 == strncasecmp(url.c_str(), rtmps_head, strlen(rtmps_head))) + { + _head = rtmps_head; + } - if (!_app.size() || !_stream_id.size()) { + string host_url = findSubString(url.data(), "://", "/"); + _app = findrSubString(url.data(), (host_url + "/").data(), '/'); + _stream_id = findSubString(url.data(), (host_url + "/" + _app + "/").data(), NULL); + _tc_url = _head + host_url + "/" + _app; + + if (!_app.size() || !_stream_id.size() || !_head.size()) { onPublishResult_l(SockException(Err_other, "rtmp url非法"), false); return; }