mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 04:31:37 +08:00
优化代码
This commit is contained in:
parent
c59a7a04c3
commit
b1dc285649
@ -90,7 +90,7 @@ void NackContext::received(uint16_t seq, bool is_rtx) {
|
|||||||
//回环
|
//回环
|
||||||
_seq.clear();
|
_seq.clear();
|
||||||
_last_max_seq = min_seq;
|
_last_max_seq = min_seq;
|
||||||
_nack_send_ntp.clear();
|
_nack_send_status.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,12 +151,12 @@ void NackContext::eraseFrontSeq() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void NackContext::onRtx(uint16_t seq) {
|
void NackContext::onRtx(uint16_t seq) {
|
||||||
auto it = _nack_send_ntp.find(seq);
|
auto it = _nack_send_status.find(seq);
|
||||||
if (it == _nack_send_ntp.end()) {
|
if (it == _nack_send_status.end()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto rtt = getCurrentMillisecond() - it->second.update_stamp;
|
auto rtt = getCurrentMillisecond() - it->second.update_stamp;
|
||||||
_nack_send_ntp.erase(it);
|
_nack_send_status.erase(it);
|
||||||
|
|
||||||
if (rtt >= 0) {
|
if (rtt >= 0) {
|
||||||
//rtt不肯小于0
|
//rtt不肯小于0
|
||||||
@ -170,7 +170,7 @@ void NackContext::recordNack(const FCI_NACK &nack) {
|
|||||||
auto i = nack.getPid();
|
auto i = nack.getPid();
|
||||||
for (auto flag : nack.getBitArray()) {
|
for (auto flag : nack.getBitArray()) {
|
||||||
if (flag) {
|
if (flag) {
|
||||||
auto &ref = _nack_send_ntp[i];
|
auto &ref = _nack_send_status[i];
|
||||||
ref.first_stamp = now;
|
ref.first_stamp = now;
|
||||||
ref.update_stamp = now;
|
ref.update_stamp = now;
|
||||||
ref.nack_count = 1;
|
ref.nack_count = 1;
|
||||||
@ -178,18 +178,18 @@ void NackContext::recordNack(const FCI_NACK &nack) {
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
//记录太多了,移除一部分早期的记录
|
//记录太多了,移除一部分早期的记录
|
||||||
while (_nack_send_ntp.size() > kNackMaxSize) {
|
while (_nack_send_status.size() > kNackMaxSize) {
|
||||||
_nack_send_ntp.erase(_nack_send_ntp.begin());
|
_nack_send_status.erase(_nack_send_status.begin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t NackContext::reSendNack() {
|
uint64_t NackContext::reSendNack() {
|
||||||
set<uint16_t> nack_rtp;
|
set<uint16_t> nack_rtp;
|
||||||
auto now = getCurrentMillisecond();
|
auto now = getCurrentMillisecond();
|
||||||
for (auto it = _nack_send_ntp.begin(); it != _nack_send_ntp.end();) {
|
for (auto it = _nack_send_status.begin(); it != _nack_send_status.end();) {
|
||||||
if (now - it->second.first_stamp > kNackMaxMS) {
|
if (now - it->second.first_stamp > kNackMaxMS) {
|
||||||
//该rtp丢失太久了,不再要求重传
|
//该rtp丢失太久了,不再要求重传
|
||||||
it = _nack_send_ntp.erase(it);
|
it = _nack_send_status.erase(it);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (now - it->second.update_stamp < 2 * _rtt) {
|
if (now - it->second.update_stamp < 2 * _rtt) {
|
||||||
@ -203,13 +203,13 @@ uint64_t NackContext::reSendNack() {
|
|||||||
it->second.update_stamp = now;
|
it->second.update_stamp = now;
|
||||||
if (++(it->second.nack_count) == kNackMaxCount) {
|
if (++(it->second.nack_count) == kNackMaxCount) {
|
||||||
//nack次数太多,移除之
|
//nack次数太多,移除之
|
||||||
it = _nack_send_ntp.erase(it);
|
it = _nack_send_status.erase(it);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_nack_send_ntp.empty()) {
|
if (_nack_send_status.empty()) {
|
||||||
//不需要再发送nack
|
//不需要再发送nack
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -219,7 +219,7 @@ uint64_t NackContext::reSendNack() {
|
|||||||
for (auto it = nack_rtp.begin(); it != nack_rtp.end();) {
|
for (auto it = nack_rtp.begin(); it != nack_rtp.end();) {
|
||||||
if (pid == -1) {
|
if (pid == -1) {
|
||||||
pid = *it;
|
pid = *it;
|
||||||
vec.resize(16, false);
|
vec.resize(FCI_NACK::kBitSize, false);
|
||||||
++it;
|
++it;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ private:
|
|||||||
uint64_t update_stamp;
|
uint64_t update_stamp;
|
||||||
int nack_count = 0;
|
int nack_count = 0;
|
||||||
};
|
};
|
||||||
map<uint16_t/*seq*/, NackStatus > _nack_send_ntp;
|
map<uint16_t/*seq*/, NackStatus > _nack_send_status;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //ZLMEDIAKIT_NACK_H
|
#endif //ZLMEDIAKIT_NACK_H
|
||||||
|
Loading…
Reference in New Issue
Block a user