精简代码
This commit is contained in:
parent
0a09cdaeea
commit
be46a37d3a
|
|
@ -20,30 +20,6 @@ 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,7 +18,6 @@
|
||||||
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);
|
||||||
|
|
|
||||||
|
|
@ -62,32 +62,21 @@ void RtmpPusher::onPublishResult_l(const SockException &ex, bool handshake_done)
|
||||||
shutdown(SockException(Err_shutdown,"teardown"));
|
shutdown(SockException(Err_shutdown,"teardown"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef _MSC_VER
|
|
||||||
//not #if defined(_WIN32) || defined(_WIN64) because we have strncasecmp in mingw
|
|
||||||
#define strncasecmp _strnicmp
|
|
||||||
#define strcasecmp _stricmp
|
|
||||||
#endif
|
|
||||||
void RtmpPusher::publish(const string &url) {
|
void RtmpPusher::publish(const string &url) {
|
||||||
teardown();
|
teardown();
|
||||||
string head ;
|
auto schema = findSubString(url.data(), nullptr, "://");
|
||||||
// rtmps rt_url head should be rtmps
|
auto host_url = findSubString(url.data(), "://", "/");
|
||||||
const char *rtmp_head = "rtmp://";
|
_app = findSubString(url.data(), (host_url + "/").data(), "/");
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
string host_url = findSubString(url.data(), "://", "/");
|
|
||||||
_app = findrSubString(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 = head + 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() || !head.size()) {
|
// _stream_id存在多级;不包含'?', 说明分割符'/'不是url参数的一部分
|
||||||
|
_app += "/" + app_second;
|
||||||
|
_stream_id.erase(0, app_second.size());
|
||||||
|
}
|
||||||
|
_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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue