webrtc支持通过http参数指定是否优先tcp模式 (#2105)

* webrtc push/play支持通过http参数指定tcp

* force_tcp改成perferred_tcp

Co-authored-by: xiongziliang <771730766@qq.com>
This commit is contained in:
Dw9
2022-11-27 12:43:16 +08:00
committed by GitHub
parent 50fa671564
commit fef9d31631
7 changed files with 32 additions and 20 deletions

View File

@@ -402,8 +402,8 @@ void WebRtcTransportImp::OnDtlsTransportApplicationDataReceived(const RTC::DtlsT
#endif
}
WebRtcTransportImp::WebRtcTransportImp(const EventPoller::Ptr &poller)
: WebRtcTransport(poller) {
WebRtcTransportImp::WebRtcTransportImp(const EventPoller::Ptr &poller,bool perferred_tcp)
: WebRtcTransport(poller), _perferred_tcp(perferred_tcp) {
InfoL << getIdentifier();
}
@@ -629,13 +629,13 @@ void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const {
if (extern_ips.empty()) {
std::string local_ip = SockUtil::get_local_ip();
if (local_udp_port) { configure.addCandidate(*makeIceCandidate(local_ip, local_udp_port, 120, "udp")); }
if (local_tcp_port) { configure.addCandidate(*makeIceCandidate(local_ip, local_tcp_port, 110, "tcp")); }
if (local_tcp_port) { configure.addCandidate(*makeIceCandidate(local_ip, local_tcp_port, _perferred_tcp ? 125 : 115, "tcp")); }
} else {
const uint32_t delta = 10;
uint32_t priority = 100 + delta * extern_ips.size();
for (auto ip : extern_ips) {
if (local_udp_port) { configure.addCandidate(*makeIceCandidate(ip, local_udp_port, priority + 5, "udp")); }
if (local_tcp_port) { configure.addCandidate(*makeIceCandidate(ip, local_tcp_port, priority, "tcp")); }
if (local_udp_port) { configure.addCandidate(*makeIceCandidate(ip, local_udp_port, priority, "udp")); }
if (local_tcp_port) { configure.addCandidate(*makeIceCandidate(ip, local_tcp_port, priority - (_perferred_tcp ? -5 : 5), "tcp")); }
priority -= delta;
}
}
@@ -1153,7 +1153,9 @@ void echo_plugin(Session &sender, const WebRtcArgs &args, const WebRtcPluginMana
void push_plugin(Session &sender, const WebRtcArgs &args, const WebRtcPluginManager::onCreateRtc &cb) {
MediaInfo info(args["url"]);
Broadcast::PublishAuthInvoker invoker = [cb, info](const string &err, const ProtocolOption &option) mutable {
bool perferred_tcp = args["perferred_tcp"];
Broadcast::PublishAuthInvoker invoker = [cb, info, perferred_tcp](const string &err, const ProtocolOption &option) mutable {
if (!err.empty()) {
cb(WebRtcException(SockException(Err_other, err)));
return;
@@ -1192,7 +1194,7 @@ void push_plugin(Session &sender, const WebRtcArgs &args, const WebRtcPluginMana
push_src_ownership = push_src->getOwnership();
push_src->setProtocolOption(option);
}
auto rtc = WebRtcPusher::create(EventPollerPool::Instance().getPoller(), push_src, push_src_ownership, info, option);
auto rtc = WebRtcPusher::create(EventPollerPool::Instance().getPoller(), push_src, push_src_ownership, info, option, perferred_tcp);
push_src->setListener(rtc);
cb(*rtc);
};
@@ -1207,8 +1209,10 @@ void push_plugin(Session &sender, const WebRtcArgs &args, const WebRtcPluginMana
void play_plugin(Session &sender, const WebRtcArgs &args, const WebRtcPluginManager::onCreateRtc &cb) {
MediaInfo info(args["url"]);
bool perferred_tcp = args["perferred_tcp"];
auto session_ptr = sender.shared_from_this();
Broadcast::AuthInvoker invoker = [cb, info, session_ptr](const string &err) mutable {
Broadcast::AuthInvoker invoker = [cb, info, session_ptr, perferred_tcp](const string &err) mutable {
if (!err.empty()) {
cb(WebRtcException(SockException(Err_other, err)));
return;
@@ -1224,7 +1228,7 @@ void play_plugin(Session &sender, const WebRtcArgs &args, const WebRtcPluginMana
}
// 还原成rtc目的是为了hook时识别哪种播放协议
info._schema = RTC_SCHEMA;
auto rtc = WebRtcPlayer::create(EventPollerPool::Instance().getPoller(), src, info);
auto rtc = WebRtcPlayer::create(EventPollerPool::Instance().getPoller(), src, info, perferred_tcp);
cb(*rtc);
});
};