Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RTC: Fix nack encode seqnum #2766

Merged
merged 4 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion trunk/src/kernel/srs_kernel_rtc_rtcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,10 @@ srs_error_t SrsRtcpNack::encode(SrsBuffer *buffer)
} else if( (sn - pid) > 16) {
// add new chunk
chunks.push_back(chunk);
chunk.in_use = false;
chunk.pid = sn;
chunk.blp = 0;
chunk.in_use = true;
pid = sn;
} else {
chunk.blp |= 1 << (sn-pid-1);
}
Expand Down
26 changes: 26 additions & 0 deletions trunk/src/utest/srs_utest_rtc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,32 @@ VOID TEST(KernelRTCTest, NACKFetchRTPPacket)
}
}

VOID TEST(KernelRTCTest, NACKEncode)
{
uint32_t ssrc = 123;
char buf_before[kRtcpPacketSize];
SrsBuffer stream_before(buf_before, sizeof(buf_before));

SrsRtcpNack rtcpNack_encode(ssrc);
for(uint16_t i = 16; i < 50; ++i) {
rtcpNack_encode.add_lost_sn(i);
Copy link
Collaborator

@xiaozhihong xiaozhihong Dec 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rtcpNack_encode, rtcpNack_decode, It is better to name them consistently with the style of srs, so change them to rtcp_nack_encode, rtcp_nack_decode would be better.

TRANS_BY_GPT3

}
srs_error_t err1 = rtcpNack_encode.encode(&stream_before);
EXPECT_TRUE(err1 == 0);
char buf_after[kRtcpPacketSize];
memcpy(buf_after, buf_before, kRtcpPacketSize);
SrsBuffer stream_after(buf_after, sizeof(buf_after));
SrsRtcpNack rtcpNack_decode(ssrc);
srs_error_t err2 = rtcpNack_decode.decode(&stream_after);
EXPECT_TRUE(err2 == 0);
vector<uint16_t> before = rtcpNack_encode.get_lost_sns();
vector<uint16_t> after = rtcpNack_decode.get_lost_sns();
EXPECT_TRUE(before.size() == after.size());
for(int i = 0; i < before.size() && i < after.size(); ++i) {
EXPECT_TRUE(before.at(i) == after.at(i));
}
}

extern bool srs_is_stun(const uint8_t* data, size_t size);
extern bool srs_is_dtls(const uint8_t* data, size_t len);
extern bool srs_is_rtp_or_rtcp(const uint8_t* data, size_t len);
Expand Down