diff --git a/src/Rtcp/RtcpFCI.cpp b/src/Rtcp/RtcpFCI.cpp index d03d1a60..44d22055 100644 --- a/src/Rtcp/RtcpFCI.cpp +++ b/src/Rtcp/RtcpFCI.cpp @@ -142,4 +142,30 @@ string FCI_REMB::dumpString() const { return printer; } +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void FCI_NACK::net2Host() { + pid = ntohs(pid); + blp = ntohs(blp); +} + +vector FCI_NACK::getBitArray() const { + vector ret; + ret.resize(kBitSize); + for (size_t i = 0; i < kBitSize; ++i) { + ret[i] = blp & (1 << (kBitSize - i - 1)); + } + return ret; +} + +string FCI_NACK::dumpString() const { + _StrPrinter printer; + printer << "pid:" << pid << ",blp:"; + for (auto &flag : getBitArray()) { + printer << flag << " "; + } + return std::move(printer); +} + + }//namespace mediakit \ No newline at end of file diff --git a/src/Rtcp/RtcpFCI.h b/src/Rtcp/RtcpFCI.h index f36056d9..ed216149 100644 --- a/src/Rtcp/RtcpFCI.h +++ b/src/Rtcp/RtcpFCI.h @@ -221,11 +221,31 @@ public: // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ class FCI_NACK { public: + static constexpr size_t kBitSize = 16; + // The PID field is used to specify a lost packet. The PID field // refers to the RTP sequence number of the lost packet. uint16_t pid; // bitmask of following lost packets (BLP): 16 bits uint16_t blp; + + void net2Host(); + vector getBitArray() const; + string dumpString() const; + + template + FCI_NACK(uint16_t pid_h, const Type &type){ + uint16_t blp_h = 0; + int i = kBitSize; + for (auto &item : type) { + --i; + if (item) { + blp_h |= (1 << i); + } + } + blp = htons(blp_h); + pid = htons(pid_h); + } } PACKED; //RTPFB fmt = 3 diff --git a/tests/test_rtcp_fci.cpp b/tests/test_rtcp_fci.cpp index c974d4b0..d8fd1eca 100644 --- a/tests/test_rtcp_fci.cpp +++ b/tests/test_rtcp_fci.cpp @@ -37,5 +37,10 @@ int main() { ptr->net2Host(str.size()); InfoL << ptr->dumpString(); } + { + FCI_NACK nack(1234, vector({1, 0, 0, 0, 1, 0, 1, 0, 1, 0})); + nack.net2Host(); + InfoL << nack.dumpString(); + } return 0; }