完善rtcp nack相关代码

This commit is contained in:
xia-chu 2021-04-20 17:15:01 +08:00
parent 31b6dde715
commit cce9de74d3
3 changed files with 51 additions and 0 deletions

View File

@ -142,4 +142,30 @@ string FCI_REMB::dumpString() const {
return printer; return printer;
} }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void FCI_NACK::net2Host() {
pid = ntohs(pid);
blp = ntohs(blp);
}
vector<bool> FCI_NACK::getBitArray() const {
vector<bool> 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 }//namespace mediakit

View File

@ -221,11 +221,31 @@ public:
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
class FCI_NACK { class FCI_NACK {
public: public:
static constexpr size_t kBitSize = 16;
// The PID field is used to specify a lost packet. The PID field // The PID field is used to specify a lost packet. The PID field
// refers to the RTP sequence number of the lost packet. // refers to the RTP sequence number of the lost packet.
uint16_t pid; uint16_t pid;
// bitmask of following lost packets (BLP): 16 bits // bitmask of following lost packets (BLP): 16 bits
uint16_t blp; uint16_t blp;
void net2Host();
vector<bool> getBitArray() const;
string dumpString() const;
template<typename Type>
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; } PACKED;
//RTPFB fmt = 3 //RTPFB fmt = 3

View File

@ -37,5 +37,10 @@ int main() {
ptr->net2Host(str.size()); ptr->net2Host(str.size());
InfoL << ptr->dumpString(); InfoL << ptr->dumpString();
} }
{
FCI_NACK nack(1234, vector<int>({1, 0, 0, 0, 1, 0, 1, 0, 1, 0}));
nack.net2Host();
InfoL << nack.dumpString();
}
return 0; return 0;
} }