mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 04:31:37 +08:00
完善ipv6网络适配
This commit is contained in:
parent
3062ea0e7c
commit
d66845425c
@ -1 +1 @@
|
|||||||
Subproject commit 442f682b1aebc67ee60a1c43718b8bf66e3c1667
|
Subproject commit d1bd0e5459f5138b59d8e012ef148b0f562d1f29
|
@ -80,7 +80,7 @@ bool RtpProcess::inputRtp(bool is_udp, const Socket::Ptr &sock, const char *data
|
|||||||
if (!_sock) {
|
if (!_sock) {
|
||||||
//第一次运行本函数
|
//第一次运行本函数
|
||||||
_sock = sock;
|
_sock = sock;
|
||||||
_addr = *addr;
|
_addr = *((struct sockaddr_storage *)addr);
|
||||||
emitOnPublish();
|
emitOnPublish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,11 +198,11 @@ void RtpProcess::setOnDetach(const function<void()> &cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string RtpProcess::get_peer_ip() {
|
string RtpProcess::get_peer_ip() {
|
||||||
return SockUtil::inet_ntoa(((struct sockaddr_in &) _addr).sin_addr);
|
return SockUtil::inet_ntoa((struct sockaddr *)&_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t RtpProcess::get_peer_port() {
|
uint16_t RtpProcess::get_peer_port() {
|
||||||
return ntohs(((struct sockaddr_in &) _addr).sin_port);
|
return SockUtil::inet_port((struct sockaddr *)&_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
string RtpProcess::get_local_ip() {
|
string RtpProcess::get_local_ip() {
|
||||||
|
@ -84,7 +84,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
uint32_t _dts = 0;
|
uint32_t _dts = 0;
|
||||||
uint64_t _total_bytes = 0;
|
uint64_t _total_bytes = 0;
|
||||||
struct sockaddr _addr{0};
|
struct sockaddr_storage _addr{0};
|
||||||
toolkit::Socket::Ptr _sock;
|
toolkit::Socket::Ptr _sock;
|
||||||
MediaInfo _media_info;
|
MediaInfo _media_info;
|
||||||
toolkit::Ticker _last_frame_time;
|
toolkit::Ticker _last_frame_time;
|
||||||
|
@ -53,7 +53,7 @@ public:
|
|||||||
}
|
}
|
||||||
if (!strong_self->_rtcp_addr) {
|
if (!strong_self->_rtcp_addr) {
|
||||||
//只设置一次rtcp对端端口
|
//只设置一次rtcp对端端口
|
||||||
strong_self->_rtcp_addr = std::make_shared<struct sockaddr>();
|
strong_self->_rtcp_addr = std::make_shared<struct sockaddr_storage>();
|
||||||
memcpy(strong_self->_rtcp_addr.get(), addr, addr_len);
|
memcpy(strong_self->_rtcp_addr.get(), addr, addr_len);
|
||||||
}
|
}
|
||||||
auto rtcps = RtcpHeader::loadFromBytes(buf->data(), buf->size());
|
auto rtcps = RtcpHeader::loadFromBytes(buf->data(), buf->size());
|
||||||
@ -71,10 +71,13 @@ private:
|
|||||||
}
|
}
|
||||||
_ticker.resetTime();
|
_ticker.resetTime();
|
||||||
|
|
||||||
auto rtcp_addr = _rtcp_addr.get();
|
auto rtcp_addr = (struct sockaddr *)_rtcp_addr.get();
|
||||||
if (!rtcp_addr) {
|
if (!rtcp_addr) {
|
||||||
//默认的,rtcp端口为rtp端口+1
|
//默认的,rtcp端口为rtp端口+1
|
||||||
((sockaddr_in *) addr)->sin_port = htons(ntohs(((sockaddr_in *) addr)->sin_port) + 1);
|
switch(addr->sa_family){
|
||||||
|
case AF_INET: ((sockaddr_in *) addr)->sin_port = htons(ntohs(((sockaddr_in *) addr)->sin_port) + 1); break;
|
||||||
|
case AF_INET6: ((sockaddr_in6 *) addr)->sin6_port = htons(ntohs(((sockaddr_in6 *) addr)->sin6_port) + 1); break;
|
||||||
|
}
|
||||||
//未收到rtcp打洞包时,采用默认的rtcp端口
|
//未收到rtcp打洞包时,采用默认的rtcp端口
|
||||||
rtcp_addr = addr;
|
rtcp_addr = addr;
|
||||||
}
|
}
|
||||||
@ -85,7 +88,7 @@ private:
|
|||||||
Ticker _ticker;
|
Ticker _ticker;
|
||||||
Socket::Ptr _rtcp_sock;
|
Socket::Ptr _rtcp_sock;
|
||||||
uint32_t _sample_rate;
|
uint32_t _sample_rate;
|
||||||
std::shared_ptr<struct sockaddr> _rtcp_addr;
|
std::shared_ptr<struct sockaddr_storage> _rtcp_addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
void RtpServer::start(uint16_t local_port, const string &stream_id, bool enable_tcp, const char *local_ip, bool re_use_port, uint32_t ssrc) {
|
void RtpServer::start(uint16_t local_port, const string &stream_id, bool enable_tcp, const char *local_ip, bool re_use_port, uint32_t ssrc) {
|
||||||
|
@ -40,7 +40,7 @@ void RtpSession::attachServer(const Server &server) {
|
|||||||
RtpSession::RtpSession(const Socket::Ptr &sock) : Session(sock) {
|
RtpSession::RtpSession(const Socket::Ptr &sock) : Session(sock) {
|
||||||
DebugP(this);
|
DebugP(this);
|
||||||
socklen_t addr_len = sizeof(_addr);
|
socklen_t addr_len = sizeof(_addr);
|
||||||
getpeername(sock->rawFD(), &_addr, &addr_len);
|
getpeername(sock->rawFD(), (struct sockaddr *)&_addr, &addr_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
RtpSession::~RtpSession() {
|
RtpSession::~RtpSession() {
|
||||||
@ -110,7 +110,7 @@ void RtpSession::onRtpPacket(const char *data, size_t len) {
|
|||||||
WarnP(this) << "ssrc不匹配,rtp已丢弃:" << rtp_ssrc << " != " << _ssrc;
|
WarnP(this) << "ssrc不匹配,rtp已丢弃:" << rtp_ssrc << " != " << _ssrc;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_process->inputRtp(false, getSock(), data, len, &_addr);
|
_process->inputRtp(false, getSock(), data, len, (struct sockaddr *)&_addr);
|
||||||
} catch (RtpTrack::BadRtpException &ex) {
|
} catch (RtpTrack::BadRtpException &ex) {
|
||||||
if (!_is_udp) {
|
if (!_is_udp) {
|
||||||
WarnL << ex.what() << ",开始搜索ssrc以便恢复上下文";
|
WarnL << ex.what() << ",开始搜索ssrc以便恢复上下文";
|
||||||
|
@ -50,7 +50,7 @@ private:
|
|||||||
uint32_t _ssrc = 0;
|
uint32_t _ssrc = 0;
|
||||||
toolkit::Ticker _ticker;
|
toolkit::Ticker _ticker;
|
||||||
std::string _stream_id;
|
std::string _stream_id;
|
||||||
struct sockaddr _addr;
|
struct sockaddr_storage _addr;
|
||||||
RtpProcess::Ptr _process;
|
RtpProcess::Ptr _process;
|
||||||
std::shared_ptr<toolkit::ObjectStatistic<toolkit::TcpSession> > _statistic_tcp;
|
std::shared_ptr<toolkit::ObjectStatistic<toolkit::TcpSession> > _statistic_tcp;
|
||||||
std::shared_ptr<toolkit::ObjectStatistic<toolkit::UdpSession> > _statistic_udp;
|
std::shared_ptr<toolkit::ObjectStatistic<toolkit::UdpSession> > _statistic_udp;
|
||||||
|
@ -292,7 +292,8 @@ void RtspPlayer::handleResSETUP(const Parser &parser, unsigned int track_idx) {
|
|||||||
//udp组播
|
//udp组播
|
||||||
auto multiAddr = transport_map["destination"];
|
auto multiAddr = transport_map["destination"];
|
||||||
pRtpSockRef = createSocket();
|
pRtpSockRef = createSocket();
|
||||||
if (!pRtpSockRef->bindUdpSock(rtp_port, "::")) {
|
//目前组播仅支持ipv4
|
||||||
|
if (!pRtpSockRef->bindUdpSock(rtp_port, "0.0.0.0")) {
|
||||||
pRtpSockRef.reset();
|
pRtpSockRef.reset();
|
||||||
throw std::runtime_error("open udp sock err");
|
throw std::runtime_error("open udp sock err");
|
||||||
}
|
}
|
||||||
@ -303,45 +304,38 @@ void RtspPlayer::handleResSETUP(const Parser &parser, unsigned int track_idx) {
|
|||||||
|
|
||||||
//设置rtcp发送端口
|
//设置rtcp发送端口
|
||||||
pRtcpSockRef = createSocket();
|
pRtcpSockRef = createSocket();
|
||||||
if (!pRtcpSockRef->bindUdpSock(0, "::")) {
|
//目前组播仅支持ipv4
|
||||||
|
if (!pRtcpSockRef->bindUdpSock(0, "0.0.0.0")) {
|
||||||
//分配端口失败
|
//分配端口失败
|
||||||
throw runtime_error("open udp socket failed");
|
throw runtime_error("open udp socket failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
//设置发送地址和发送端口
|
//设置发送地址和发送端口
|
||||||
struct sockaddr_in rtpto;
|
auto dst = SockUtil::make_sockaddr(get_peer_ip().data(), rtcp_port);
|
||||||
rtpto.sin_port = ntohs(rtcp_port);
|
pRtcpSockRef->bindPeerAddr((struct sockaddr *)&(dst));
|
||||||
rtpto.sin_family = AF_INET;
|
|
||||||
rtpto.sin_addr.s_addr = inet_addr(get_peer_ip().data());
|
|
||||||
pRtcpSockRef->bindPeerAddr((struct sockaddr *)&(rtpto));
|
|
||||||
} else {
|
} else {
|
||||||
createUdpSockIfNecessary(track_idx);
|
createUdpSockIfNecessary(track_idx);
|
||||||
//udp单播
|
//udp单播
|
||||||
struct sockaddr_in rtpto;
|
auto dst = SockUtil::make_sockaddr(get_peer_ip().data(), rtp_port);
|
||||||
rtpto.sin_port = ntohs(rtp_port);
|
pRtpSockRef->bindPeerAddr((struct sockaddr *)&(dst));
|
||||||
rtpto.sin_family = AF_INET;
|
|
||||||
rtpto.sin_addr.s_addr = inet_addr(get_peer_ip().data());
|
|
||||||
pRtpSockRef->bindPeerAddr((struct sockaddr *)&(rtpto));
|
|
||||||
//发送rtp打洞包
|
//发送rtp打洞包
|
||||||
pRtpSockRef->send("\xce\xfa\xed\xfe", 4);
|
pRtpSockRef->send("\xce\xfa\xed\xfe", 4);
|
||||||
|
|
||||||
|
dst = SockUtil::make_sockaddr(get_peer_ip().data(), rtcp_port);
|
||||||
//设置rtcp发送目标,为后续发送rtcp做准备
|
//设置rtcp发送目标,为后续发送rtcp做准备
|
||||||
rtpto.sin_port = ntohs(rtcp_port);
|
pRtcpSockRef->bindPeerAddr((struct sockaddr *)&(dst));
|
||||||
rtpto.sin_family = AF_INET;
|
|
||||||
rtpto.sin_addr.s_addr = inet_addr(get_peer_ip().data());
|
|
||||||
pRtcpSockRef->bindPeerAddr((struct sockaddr *)&(rtpto));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto srcIP = inet_addr(get_peer_ip().data());
|
auto peer_ip = get_peer_ip();
|
||||||
weak_ptr<RtspPlayer> weakSelf = dynamic_pointer_cast<RtspPlayer>(shared_from_this());
|
weak_ptr<RtspPlayer> weakSelf = dynamic_pointer_cast<RtspPlayer>(shared_from_this());
|
||||||
//设置rtp over udp接收回调处理函数
|
//设置rtp over udp接收回调处理函数
|
||||||
pRtpSockRef->setOnRead([srcIP, track_idx, weakSelf](const Buffer::Ptr &buf, struct sockaddr *addr , int addr_len) {
|
pRtpSockRef->setOnRead([peer_ip, track_idx, weakSelf](const Buffer::Ptr &buf, struct sockaddr *addr , int addr_len) {
|
||||||
auto strongSelf = weakSelf.lock();
|
auto strongSelf = weakSelf.lock();
|
||||||
if (!strongSelf) {
|
if (!strongSelf) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (((struct sockaddr_in *) addr)->sin_addr.s_addr != srcIP) {
|
if (SockUtil::inet_ntoa(addr) != peer_ip) {
|
||||||
WarnL << "收到其他地址的rtp数据:" << SockUtil::inet_ntoa(((struct sockaddr_in *) addr)->sin_addr);
|
WarnL << "收到其他地址的rtp数据:" << SockUtil::inet_ntoa(addr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
strongSelf->handleOneRtp(track_idx, strongSelf->_sdp_track[track_idx]->_type,
|
strongSelf->handleOneRtp(track_idx, strongSelf->_sdp_track[track_idx]->_type,
|
||||||
@ -350,13 +344,13 @@ void RtspPlayer::handleResSETUP(const Parser &parser, unsigned int track_idx) {
|
|||||||
|
|
||||||
if(pRtcpSockRef) {
|
if(pRtcpSockRef) {
|
||||||
//设置rtcp over udp接收回调处理函数
|
//设置rtcp over udp接收回调处理函数
|
||||||
pRtcpSockRef->setOnRead([srcIP, track_idx, weakSelf](const Buffer::Ptr &buf, struct sockaddr *addr , int addr_len) {
|
pRtcpSockRef->setOnRead([peer_ip, track_idx, weakSelf](const Buffer::Ptr &buf, struct sockaddr *addr , int addr_len) {
|
||||||
auto strongSelf = weakSelf.lock();
|
auto strongSelf = weakSelf.lock();
|
||||||
if (!strongSelf) {
|
if (!strongSelf) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (((struct sockaddr_in *) addr)->sin_addr.s_addr != srcIP) {
|
if (SockUtil::inet_ntoa(addr) != peer_ip) {
|
||||||
WarnL << "收到其他地址的rtcp数据:" << SockUtil::inet_ntoa(((struct sockaddr_in *) addr)->sin_addr);
|
WarnL << "收到其他地址的rtcp数据:" << SockUtil::inet_ntoa(addr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
strongSelf->onRtcpPacket(track_idx, strongSelf->_sdp_track[track_idx], (uint8_t *) buf->data(), buf->size());
|
strongSelf->onRtcpPacket(track_idx, strongSelf->_sdp_track[track_idx], (uint8_t *) buf->data(), buf->size());
|
||||||
|
@ -307,30 +307,25 @@ void RtspPusher::handleResSetup(const Parser &parser, unsigned int track_idx) {
|
|||||||
auto &rtp_sock = _rtp_sock[track_idx];
|
auto &rtp_sock = _rtp_sock[track_idx];
|
||||||
auto &rtcp_sock = _rtcp_sock[track_idx];
|
auto &rtcp_sock = _rtcp_sock[track_idx];
|
||||||
|
|
||||||
struct sockaddr_in rtpto;
|
auto rtpto = SockUtil::make_sockaddr(get_peer_ip().data(), rtp_port);
|
||||||
//设置rtp发送目标,为后续发送rtp做准备
|
//设置rtp发送目标,为后续发送rtp做准备
|
||||||
rtpto.sin_port = ntohs(rtp_port);
|
|
||||||
rtpto.sin_family = AF_INET;
|
|
||||||
rtpto.sin_addr.s_addr = inet_addr(get_peer_ip().data());
|
|
||||||
rtp_sock->bindPeerAddr((struct sockaddr *) &(rtpto));
|
rtp_sock->bindPeerAddr((struct sockaddr *) &(rtpto));
|
||||||
|
|
||||||
//设置rtcp发送目标,为后续发送rtcp做准备
|
//设置rtcp发送目标,为后续发送rtcp做准备
|
||||||
rtpto.sin_port = ntohs(rtcp_port);
|
auto rtcpto = SockUtil::make_sockaddr(get_peer_ip().data(), rtcp_port);
|
||||||
rtpto.sin_family = AF_INET;
|
rtcp_sock->bindPeerAddr((struct sockaddr *)&(rtcpto));
|
||||||
rtpto.sin_addr.s_addr = inet_addr(get_peer_ip().data());
|
|
||||||
rtcp_sock->bindPeerAddr((struct sockaddr *)&(rtpto));
|
|
||||||
|
|
||||||
auto srcIP = inet_addr(get_peer_ip().data());
|
auto peer_ip = get_peer_ip();
|
||||||
weak_ptr<RtspPusher> weakSelf = dynamic_pointer_cast<RtspPusher>(shared_from_this());
|
weak_ptr<RtspPusher> weakSelf = dynamic_pointer_cast<RtspPusher>(shared_from_this());
|
||||||
if(rtcp_sock) {
|
if(rtcp_sock) {
|
||||||
//设置rtcp over udp接收回调处理函数
|
//设置rtcp over udp接收回调处理函数
|
||||||
rtcp_sock->setOnRead([srcIP, track_idx, weakSelf](const Buffer::Ptr &buf, struct sockaddr *addr , int addr_len) {
|
rtcp_sock->setOnRead([peer_ip, track_idx, weakSelf](const Buffer::Ptr &buf, struct sockaddr *addr , int addr_len) {
|
||||||
auto strongSelf = weakSelf.lock();
|
auto strongSelf = weakSelf.lock();
|
||||||
if (!strongSelf) {
|
if (!strongSelf) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (((struct sockaddr_in *) addr)->sin_addr.s_addr != srcIP) {
|
if (SockUtil::inet_ntoa(addr) != peer_ip) {
|
||||||
WarnL << "收到其他地址的rtcp数据:" << SockUtil::inet_ntoa(((struct sockaddr_in *) addr)->sin_addr);
|
WarnL << "收到其他地址的rtcp数据:" << SockUtil::inet_ntoa(addr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
strongSelf->onRtcpPacket(track_idx, strongSelf->_track_vec[track_idx], (uint8_t *) buf->data(), buf->size());
|
strongSelf->onRtcpPacket(track_idx, strongSelf->_track_vec[track_idx], (uint8_t *) buf->data(), buf->size());
|
||||||
|
@ -705,19 +705,12 @@ void RtspSession::handleReq_Setup(const Parser &parser) {
|
|||||||
uint16_t ui16RtpPort = atoi(FindField(strClientPort.data(), NULL, "-").data());
|
uint16_t ui16RtpPort = atoi(FindField(strClientPort.data(), NULL, "-").data());
|
||||||
uint16_t ui16RtcpPort = atoi(FindField(strClientPort.data(), "-", NULL).data());
|
uint16_t ui16RtcpPort = atoi(FindField(strClientPort.data(), "-", NULL).data());
|
||||||
|
|
||||||
struct sockaddr_in peerAddr;
|
auto peerAddr = SockUtil::make_sockaddr(get_peer_ip().data(), ui16RtpPort);
|
||||||
//设置rtp发送目标地址
|
//设置rtp发送目标地址
|
||||||
peerAddr.sin_family = AF_INET;
|
|
||||||
peerAddr.sin_port = htons(ui16RtpPort);
|
|
||||||
peerAddr.sin_addr.s_addr = inet_addr(get_peer_ip().data());
|
|
||||||
bzero(&(peerAddr.sin_zero), sizeof peerAddr.sin_zero);
|
|
||||||
pr.first->bindPeerAddr((struct sockaddr *) (&peerAddr));
|
pr.first->bindPeerAddr((struct sockaddr *) (&peerAddr));
|
||||||
|
|
||||||
//设置rtcp发送目标地址
|
//设置rtcp发送目标地址
|
||||||
peerAddr.sin_family = AF_INET;
|
peerAddr = SockUtil::make_sockaddr(get_peer_ip().data(), ui16RtcpPort);
|
||||||
peerAddr.sin_port = htons(ui16RtcpPort);
|
|
||||||
peerAddr.sin_addr.s_addr = inet_addr(get_peer_ip().data());
|
|
||||||
bzero(&(peerAddr.sin_zero), sizeof peerAddr.sin_zero);
|
|
||||||
pr.second->bindPeerAddr((struct sockaddr *) (&peerAddr));
|
pr.second->bindPeerAddr((struct sockaddr *) (&peerAddr));
|
||||||
|
|
||||||
//尝试获取客户端nat映射地址
|
//尝试获取客户端nat映射地址
|
||||||
@ -953,7 +946,7 @@ void RtspSession::onRtpSorted(RtpPacket::Ptr rtp, int track_idx) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RtspSession::onRcvPeerUdpData(int interleaved, const Buffer::Ptr &buf, const struct sockaddr &addr) {
|
void RtspSession::onRcvPeerUdpData(int interleaved, const Buffer::Ptr &buf, const struct sockaddr_storage &addr) {
|
||||||
//这是rtcp心跳包,说明播放器还存活
|
//这是rtcp心跳包,说明播放器还存活
|
||||||
_alive_ticker.resetTime();
|
_alive_ticker.resetTime();
|
||||||
|
|
||||||
@ -965,13 +958,13 @@ void RtspSession::onRcvPeerUdpData(int interleaved, const Buffer::Ptr &buf, cons
|
|||||||
} else if (!_udp_connected_flags.count(interleaved)) {
|
} else if (!_udp_connected_flags.count(interleaved)) {
|
||||||
//这是rtsp播放器的rtp打洞包
|
//这是rtsp播放器的rtp打洞包
|
||||||
_udp_connected_flags.emplace(interleaved);
|
_udp_connected_flags.emplace(interleaved);
|
||||||
_rtp_socks[interleaved / 2]->bindPeerAddr(&addr);
|
_rtp_socks[interleaved / 2]->bindPeerAddr((struct sockaddr *)&addr);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//rtcp包
|
//rtcp包
|
||||||
if (!_udp_connected_flags.count(interleaved)) {
|
if (!_udp_connected_flags.count(interleaved)) {
|
||||||
_udp_connected_flags.emplace(interleaved);
|
_udp_connected_flags.emplace(interleaved);
|
||||||
_rtcp_socks[(interleaved - 1) / 2]->bindPeerAddr(&addr);
|
_rtcp_socks[(interleaved - 1) / 2]->bindPeerAddr((struct sockaddr *)&addr);
|
||||||
}
|
}
|
||||||
onRtcpPacket((interleaved - 1) / 2, _sdp_track[(interleaved - 1) / 2], buf->data(), buf->size());
|
onRtcpPacket((interleaved - 1) / 2, _sdp_track[(interleaved - 1) / 2], buf->data(), buf->size());
|
||||||
}
|
}
|
||||||
@ -979,20 +972,20 @@ void RtspSession::onRcvPeerUdpData(int interleaved, const Buffer::Ptr &buf, cons
|
|||||||
|
|
||||||
void RtspSession::startListenPeerUdpData(int track_idx) {
|
void RtspSession::startListenPeerUdpData(int track_idx) {
|
||||||
weak_ptr<RtspSession> weakSelf = dynamic_pointer_cast<RtspSession>(shared_from_this());
|
weak_ptr<RtspSession> weakSelf = dynamic_pointer_cast<RtspSession>(shared_from_this());
|
||||||
auto srcIP = inet_addr(get_peer_ip().data());
|
auto peer_ip = get_peer_ip();
|
||||||
auto onUdpData = [weakSelf,srcIP](const Buffer::Ptr &buf, struct sockaddr *peer_addr, int interleaved){
|
auto onUdpData = [weakSelf,peer_ip](const Buffer::Ptr &buf, struct sockaddr *peer_addr, int interleaved){
|
||||||
auto strongSelf = weakSelf.lock();
|
auto strongSelf = weakSelf.lock();
|
||||||
if (!strongSelf) {
|
if (!strongSelf) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((struct sockaddr_in *) peer_addr)->sin_addr.s_addr != srcIP) {
|
if (SockUtil::inet_ntoa(peer_addr) != peer_ip) {
|
||||||
WarnP(strongSelf.get()) << ((interleaved % 2 == 0) ? "收到其他地址的rtp数据:" : "收到其他地址的rtcp数据:")
|
WarnP(strongSelf.get()) << ((interleaved % 2 == 0) ? "收到其他地址的rtp数据:" : "收到其他地址的rtcp数据:")
|
||||||
<< SockUtil::inet_ntoa(((struct sockaddr_in *) peer_addr)->sin_addr);
|
<< SockUtil::inet_ntoa(peer_addr);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sockaddr addr = *peer_addr;
|
struct sockaddr_storage addr = *((struct sockaddr_storage *)peer_addr);
|
||||||
strongSelf->async([weakSelf, buf, addr, interleaved]() {
|
strongSelf->async([weakSelf, buf, addr, interleaved]() {
|
||||||
auto strongSelf = weakSelf.lock();
|
auto strongSelf = weakSelf.lock();
|
||||||
if (!strongSelf) {
|
if (!strongSelf) {
|
||||||
|
@ -133,7 +133,7 @@ private:
|
|||||||
int getTrackIndexByControlUrl(const std::string &control_url);
|
int getTrackIndexByControlUrl(const std::string &control_url);
|
||||||
int getTrackIndexByInterleaved(int interleaved);
|
int getTrackIndexByInterleaved(int interleaved);
|
||||||
//一般用于接收udp打洞包,也用于rtsp推流
|
//一般用于接收udp打洞包,也用于rtsp推流
|
||||||
void onRcvPeerUdpData(int interleaved, const toolkit::Buffer::Ptr &buf, const struct sockaddr &addr);
|
void onRcvPeerUdpData(int interleaved, const toolkit::Buffer::Ptr &buf, const struct sockaddr_storage &addr);
|
||||||
//配合onRcvPeerUdpData使用
|
//配合onRcvPeerUdpData使用
|
||||||
void startListenPeerUdpData(int track_idx);
|
void startListenPeerUdpData(int track_idx);
|
||||||
////rtsp专有认证相关////
|
////rtsp专有认证相关////
|
||||||
|
@ -75,8 +75,7 @@ void UDPServer::onErr(const string &key, const SockException &err) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void UDPServer::onRecv(int interleaved, const Buffer::Ptr &buf, struct sockaddr* peer_addr) {
|
void UDPServer::onRecv(int interleaved, const Buffer::Ptr &buf, struct sockaddr* peer_addr) {
|
||||||
struct sockaddr_in *in = (struct sockaddr_in *) peer_addr;
|
string peer_ip = SockUtil::inet_ntoa(peer_addr);
|
||||||
string peer_ip = SockUtil::inet_ntoa(in->sin_addr);
|
|
||||||
lock_guard<mutex> lck(_mtx_on_recv);
|
lock_guard<mutex> lck(_mtx_on_recv);
|
||||||
auto it0 = _on_recv_map.find(peer_ip);
|
auto it0 = _on_recv_map.find(peer_ip);
|
||||||
if (it0 == _on_recv_map.end()) {
|
if (it0 == _on_recv_map.end()) {
|
||||||
|
@ -37,7 +37,7 @@ static bool loadFile(const char *path){
|
|||||||
uint32_t timeStamp_last = 0;
|
uint32_t timeStamp_last = 0;
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
char rtp[0xFFFF];
|
char rtp[0xFFFF];
|
||||||
struct sockaddr addr = {0};
|
struct sockaddr_storage addr = {0};
|
||||||
auto sock = Socket::createSocket();
|
auto sock = Socket::createSocket();
|
||||||
size_t total_size = 0;
|
size_t total_size = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -58,7 +58,7 @@ static bool loadFile(const char *path){
|
|||||||
total_size += len;
|
total_size += len;
|
||||||
uint32_t timeStamp;
|
uint32_t timeStamp;
|
||||||
|
|
||||||
RtpSelector::Instance().inputRtp(sock, rtp, len, &addr, &timeStamp);
|
RtpSelector::Instance().inputRtp(sock, rtp, len, (struct sockaddr *)&addr, &timeStamp);
|
||||||
auto diff = timeStamp - timeStamp_last;
|
auto diff = timeStamp - timeStamp_last;
|
||||||
if (diff > 0 && diff < 500) {
|
if (diff > 0 && diff < 500) {
|
||||||
usleep(diff * 1000);
|
usleep(diff * 1000);
|
||||||
|
@ -46,7 +46,7 @@ EventPoller::Ptr WebRtcSession::queryPoller(const Buffer::Ptr &buffer) {
|
|||||||
|
|
||||||
WebRtcSession::WebRtcSession(const Socket::Ptr &sock) : UdpSession(sock) {
|
WebRtcSession::WebRtcSession(const Socket::Ptr &sock) : UdpSession(sock) {
|
||||||
socklen_t addr_len = sizeof(_peer_addr);
|
socklen_t addr_len = sizeof(_peer_addr);
|
||||||
getpeername(sock->rawFD(), &_peer_addr, &addr_len);
|
getpeername(sock->rawFD(), (struct sockaddr *)&_peer_addr, &addr_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
WebRtcSession::~WebRtcSession() {
|
WebRtcSession::~WebRtcSession() {
|
||||||
@ -67,7 +67,7 @@ void WebRtcSession::onRecv(const Buffer::Ptr &buffer) {
|
|||||||
}
|
}
|
||||||
_ticker.resetTime();
|
_ticker.resetTime();
|
||||||
CHECK(_transport);
|
CHECK(_transport);
|
||||||
_transport->inputSockData(buffer->data(), buffer->size(), &_peer_addr);
|
_transport->inputSockData(buffer->data(), buffer->size(), (struct sockaddr *)&_peer_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebRtcSession::onError(const SockException &err) {
|
void WebRtcSession::onError(const SockException &err) {
|
||||||
|
@ -32,7 +32,7 @@ private:
|
|||||||
std::string _identifier;
|
std::string _identifier;
|
||||||
bool _find_transport = true;
|
bool _find_transport = true;
|
||||||
Ticker _ticker;
|
Ticker _ticker;
|
||||||
struct sockaddr _peer_addr;
|
struct sockaddr_storage _peer_addr;
|
||||||
std::shared_ptr<WebRtcTransportImp> _transport;
|
std::shared_ptr<WebRtcTransportImp> _transport;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ static bool is_rtcp(char *buf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static string getPeerAddress(RTC::TransportTuple *tuple){
|
static string getPeerAddress(RTC::TransportTuple *tuple){
|
||||||
return SockUtil::inet_ntoa(((struct sockaddr_in *)tuple)->sin_addr) + ":" + to_string(ntohs(((struct sockaddr_in *)tuple)->sin_port));
|
return SockUtil::inet_ntoa(tuple);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebRtcTransport::inputSockData(char *buf, int len, RTC::TransportTuple *tuple) {
|
void WebRtcTransport::inputSockData(char *buf, int len, RTC::TransportTuple *tuple) {
|
||||||
|
Loading…
Reference in New Issue
Block a user