Skip to content

Commit

Permalink
RTC: Fix nack encode seqnum (#2766)
Browse files Browse the repository at this point in the history
* fix nack encode seqnum

* add nack encode utest

* change Variable naming

Co-authored-by: liyalong1 <[email protected]>
  • Loading branch information
xiaofeilong and liyalong1 authored Dec 6, 2021
1 parent 5ccd63d commit 4decc1f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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 rtcp_nack_encode(ssrc);
for(uint16_t i = 16; i < 50; ++i) {
rtcp_nack_encode.add_lost_sn(i);
}
srs_error_t err_before = rtcp_nack_encode.encode(&stream_before);
EXPECT_TRUE(err_before == 0);
char buf_after[kRtcpPacketSize];
memcpy(buf_after, buf_before, kRtcpPacketSize);
SrsBuffer stream_after(buf_after, sizeof(buf_after));
SrsRtcpNack rtcp_nack_decode(ssrc);
srs_error_t err_after = rtcp_nack_decode.decode(&stream_after);
EXPECT_TRUE(err_after == 0);
vector<uint16_t> before = rtcp_nack_encode.get_lost_sns();
vector<uint16_t> after = rtcp_nack_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

0 comments on commit 4decc1f

Please sign in to comment.