rtp发送去除重连机制

This commit is contained in:
xiongziliang 2022-08-27 10:59:15 +08:00
parent 6a4297845f
commit 0cab9c8d16
2 changed files with 4 additions and 33 deletions

View File

@ -281,38 +281,10 @@ void RtpSender::onFlushRtpList(shared_ptr<List<Buffer::Ptr> > rtp_list) {
});
}
void RtpSender::onErr(const SockException &ex, bool is_connect) {
void RtpSender::onErr(const SockException &ex) {
_is_connect = false;
if (_args.passive || !_args.is_udp) {
WarnL << "send rtp tcp connection lost: " << ex.what();
//tcp模式如果对方断开连接应该停止发送rtp
onClose(ex);
return;
}
//监听socket断开事件方便重连
if (is_connect) {
WarnL << "重连" << _args.dst_url << ":" << _args.dst_port << "失败, 原因为:" << ex.what();
} else {
WarnL << "停止发送 rtp:" << _args.dst_url << ":" << _args.dst_port << ", 原因为:" << ex.what();
}
weak_ptr<RtpSender> weak_self = shared_from_this();
_connect_timer = std::make_shared<Timer>(10.0f, [weak_self]() {
auto strong_self = weak_self.lock();
if (!strong_self) {
return false;
}
strong_self->startSend(strong_self->_args, [weak_self](uint16_t local_port, const SockException &ex){
auto strong_self = weak_self.lock();
if (strong_self && ex) {
//连接失败且本对象未销毁,那么重试连接
strong_self->onErr(ex, true);
}
});
return false;
}, _poller);
WarnL << "send rtp tcp connection lost: " << ex.what();
onClose(ex);
}
void RtpSender::setOnClose(std::function<void(const toolkit::SockException &ex)> on_close){

View File

@ -62,7 +62,7 @@ private:
//udp/tcp连接成功回调
void onConnect();
//异常断开socket事件
void onErr(const toolkit::SockException &ex, bool is_connect = false);
void onErr(const toolkit::SockException &ex);
void createRtcpSocket();
void onRecvRtcp(RtcpHeader *rtcp);
void onSendRtpUdp(const toolkit::Buffer::Ptr &buf, bool check);
@ -74,7 +74,6 @@ private:
toolkit::Socket::Ptr _socket_rtp;
toolkit::Socket::Ptr _socket_rtcp;
toolkit::EventPoller::Ptr _poller;
toolkit::Timer::Ptr _connect_timer;
MediaSinkInterface::Ptr _interface;
std::shared_ptr<RtcpContext> _rtcp_context;
toolkit::Ticker _rtcp_send_ticker;