根据ffmpeg测试,类似rtmps://ip/a/b/c这样的url,app应该为a/b,stream_id应该为c, tcl_url应该为rtmps://ip/a/b,teams的rtmps需要按这种方式才能推成功
This commit is contained in:
parent
1a4b8406bb
commit
7fde20bb4c
|
|
@ -20,6 +20,30 @@ using namespace toolkit;
|
||||||
|
|
||||||
namespace mediakit {
|
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) {
|
string findSubString(const char *buf, const char *start, const char *end, size_t buf_size) {
|
||||||
if (buf_size <= 0) {
|
if (buf_size <= 0) {
|
||||||
buf_size = strlen(buf);
|
buf_size = strlen(buf);
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
namespace mediakit {
|
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);
|
std::string findSubString(const char *buf, const char *start, const char *end, size_t buf_size = 0);
|
||||||
// 把url解析为主机地址和端口号,兼容ipv4/ipv6/dns
|
// 把url解析为主机地址和端口号,兼容ipv4/ipv6/dns
|
||||||
void splitUrl(const std::string &url, std::string &host, uint16_t &port);
|
void splitUrl(const std::string &url, std::string &host, uint16_t &port);
|
||||||
|
|
|
||||||
|
|
@ -65,12 +65,25 @@ 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(), "://", "/");
|
string _head ;
|
||||||
_app = findSubString(url.data(), (host_url + "/").data(), "/");
|
// rtmps rt_url head should be rtmps
|
||||||
_stream_id = findSubString(url.data(), (host_url + "/" + _app + "/").data(), NULL);
|
const char *rtmp_head = "rtmp://";
|
||||||
_tc_url = string("rtmp://") + host_url + "/" + _app;
|
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);
|
onPublishResult_l(SockException(Err_other, "rtmp url非法"), false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue