优化代码

This commit is contained in:
ziyue 2022-10-08 10:47:09 +08:00
parent c790254f46
commit 2b64245c14
2 changed files with 6 additions and 5 deletions

View File

@ -292,9 +292,8 @@ API_EXPORT void API_CALL mk_webrtc_get_answer_sdp(void *user_data, on_mk_webrtc_
std::string offer_str = offer; std::string offer_str = offer;
WebRtcPluginManager::Instance().getAnswerSdp(*session, type, WebRtcArgsUrl(url), WebRtcPluginManager::Instance().getAnswerSdp(*session, type, WebRtcArgsUrl(url),
[offer_str, session, user_data, cb](const WebRtcInterface &exchanger) mutable { [offer_str, session, user_data, cb](const WebRtcInterface &exchanger) mutable {
std::string sdp_answer;
try { try {
sdp_answer = const_cast<WebRtcInterface &>(exchanger).getAnswerSdp(offer_str); auto sdp_answer = const_cast<WebRtcInterface &>(exchanger).getAnswerSdp(offer_str);
cb(user_data, sdp_answer.data(), nullptr); cb(user_data, sdp_answer.data(), nullptr);
} catch (std::exception &ex) { } catch (std::exception &ex) {
cb(user_data, nullptr, ex.what()); cb(user_data, nullptr, ex.what());

View File

@ -61,8 +61,9 @@ void RtpSender::startSend(const MediaSourceEvent::SendRtpArgs &args, const funct
} }
// tcp服务器默认开启5秒 // tcp服务器默认开启5秒
auto delay_task = _poller->doDelayTask(_args.tcp_passive_close_delay_ms, [tcp_listener, cb,is_wait]() mutable { auto delay_task = _poller->doDelayTask(_args.tcp_passive_close_delay_ms, [tcp_listener, cb,is_wait]() mutable {
if(is_wait) if (is_wait) {
cb(0, SockException(Err_timeout, "wait tcp connection timeout")); cb(0, SockException(Err_timeout, "wait tcp connection timeout"));
}
tcp_listener = nullptr; tcp_listener = nullptr;
return 0; return 0;
}); });
@ -75,8 +76,9 @@ void RtpSender::startSend(const MediaSourceEvent::SendRtpArgs &args, const funct
delay_task->cancel(); delay_task->cancel();
strong_self->_socket_rtp = sock; strong_self->_socket_rtp = sock;
strong_self->onConnect(); strong_self->onConnect();
if(is_wait) if (is_wait) {
cb(sock->get_local_port(), SockException()); cb(sock->get_local_port(), SockException());
}
InfoL << "accept connection from:" << sock->get_peer_ip() << ":" << sock->get_peer_port(); InfoL << "accept connection from:" << sock->get_peer_ip() << ":" << sock->get_peer_port();
}); });
InfoL << "start tcp passive server on:" << tcp_listener->get_local_port(); InfoL << "start tcp passive server on:" << tcp_listener->get_local_port();