Skip to content

Commit

Permalink
[core] Fixed group rcv buffering of ignored packet (#1804)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko authored Feb 11, 2021
1 parent 66cb7c7 commit bdb3191
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions srtcore/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2372,21 +2372,22 @@ int CUDTGroup::recv(char* buf, int len, SRT_MSGCTRL& w_mc)
// by "more correct data" if found more appropriate later. But we have to
// copy these data anyway anywhere, even if they need to fall on the floor later.
int stat;
char extrabuf[SRT_LIVE_MAX_PLSIZE];
char* msgbuf = NULL;
if (output_size)
{
// We have already the data, so this must fall on the floor
char lostbuf[SRT_LIVE_MAX_PLSIZE];
stat = ps->core().receiveMessage((lostbuf), SRT_LIVE_MAX_PLSIZE, (mctrl), CUDTUnited::ERH_RETURN);
// We already have the target data in `buf`. Now reading extra data potentially redundant (to be ignored)
// or AHEAD (to be buffered internally by the group)
msgbuf = extrabuf;
stat = ps->core().receiveMessage((extrabuf), SRT_LIVE_MAX_PLSIZE, (mctrl), CUDTUnited::ERH_RETURN);
HLOGC(grlog.Debug,
log << "group/recv: @" << id << " IGNORED data with %" << mctrl.pktseq << " #" << mctrl.msgno
<< ": " << (stat <= 0 ? "(NOTHING)" : BufferStamp(lostbuf, stat)));
if (stat > 0)
{
m_stats.recvDiscard.Update(stat);
}
log << "group/recv: @" << id << " EXTRACTED EXTRA data with %" << mctrl.pktseq
<< " #" << mctrl.msgno << ": " << (stat <= 0 ? "(NOTHING)" : BufferStamp(extrabuf, stat))
<< (CSeqNo::seqcmp(mctrl.pktseq, m_RcvBaseSeqNo) > 1 ? " - TO STORE" : " - TO IGNORE"));
}
else
{
msgbuf = buf;
stat = ps->core().receiveMessage((buf), len, (mctrl), CUDTUnited::ERH_RETURN);
HLOGC(grlog.Debug,
log << "group/recv: @" << id << " EXTRACTED data with %" << mctrl.pktseq << " #"
Expand Down Expand Up @@ -2451,7 +2452,7 @@ int CUDTGroup::recv(char* buf, int len, SRT_MSGCTRL& w_mc)
log << "group/recv: @" << id << " %" << mctrl.pktseq << " #" << mctrl.msgno
<< " BEHIND base=%" << m_RcvBaseSeqNo << " - discarding");
// The sequence is recorded, the packet has to be discarded.
// That's all.
m_stats.recvDiscard.Update(stat);
continue;
}

Expand All @@ -2464,7 +2465,7 @@ int CUDTGroup::recv(char* buf, int len, SRT_MSGCTRL& w_mc)
HLOGC(grlog.Debug,
log << "@" << id << " %" << mctrl.pktseq << " #" << mctrl.msgno << " AHEAD base=%"
<< m_RcvBaseSeqNo);
p->packet.assign(buf, buf + stat);
p->packet.assign(msgbuf, msgbuf + stat);
p->mctrl = mctrl;
break; // Don't read from that socket anymore.
}
Expand Down Expand Up @@ -2713,8 +2714,8 @@ CUDTGroup::ReadPos* CUDTGroup::checkPacketAhead()
{
// The very next packet. Return it.
HLOGC(grlog.Debug,
log << "group/recv: Base %" << m_RcvBaseSeqNo << " ahead delivery POSSIBLE %" << a.mctrl.pktseq << "#"
<< a.mctrl.msgno << " from @" << i->first << ")");
log << "group/recv: Base %" << m_RcvBaseSeqNo << " ahead delivery POSSIBLE %" << a.mctrl.pktseq
<< " #" << a.mctrl.msgno << " from @" << i->first << ")");
out = &a;
}
else if (seqdiff < 1 && !a.packet.empty())
Expand Down

0 comments on commit bdb3191

Please sign in to comment.