rtp.hpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. /**
  2. * Copyright (c) 2020 Staz Modrzynski
  3. * Copyright (c) 2020 Paul-Louis Ageneau
  4. * Copyright (c) 2020 Filip Klembara (in2core)
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef RTC_RTP_HPP
  21. #define RTC_RTP_HPP
  22. #include "log.hpp"
  23. #include <cmath>
  24. #ifdef _WIN32
  25. #include <winsock2.h>
  26. #else
  27. #include <arpa/inet.h>
  28. #endif
  29. #ifndef htonll
  30. #define htonll(x) \
  31. ((uint64_t)htonl(((uint64_t)(x)&0xFFFFFFFF) << 32) | (uint64_t)htonl((uint64_t)(x) >> 32))
  32. #endif
  33. #ifndef ntohll
  34. #define ntohll(x) htonll(x)
  35. #endif
  36. namespace rtc {
  37. typedef uint32_t SSRC;
  38. #pragma pack(push, 1)
  39. struct RTP {
  40. private:
  41. uint8_t _first;
  42. uint8_t _payloadType;
  43. uint16_t _seqNumber;
  44. uint32_t _timestamp;
  45. SSRC _ssrc;
  46. public:
  47. SSRC csrc[16];
  48. inline uint8_t version() const { return _first >> 6; }
  49. inline bool padding() const { return (_first >> 5) & 0x01; }
  50. inline bool extension() const { return (_first >> 4) & 0x01; }
  51. inline uint8_t csrcCount() const { return _first & 0x0F; }
  52. inline uint8_t marker() const { return _payloadType & 0b10000000; }
  53. inline uint8_t payloadType() const { return _payloadType & 0b01111111; }
  54. inline uint16_t seqNumber() const { return ntohs(_seqNumber); }
  55. inline uint32_t timestamp() const { return ntohl(_timestamp); }
  56. inline uint32_t ssrc() const { return ntohl(_ssrc); }
  57. inline size_t getSize() const {
  58. return reinterpret_cast<const char *>(&csrc) - reinterpret_cast<const char *>(this) +
  59. sizeof(SSRC) * csrcCount();
  60. }
  61. [[nodiscard]] char *getBody() {
  62. return reinterpret_cast<char *>(&csrc) + sizeof(SSRC) * csrcCount();
  63. }
  64. [[nodiscard]] const char *getBody() const {
  65. return reinterpret_cast<const char *>(&csrc) + sizeof(SSRC) * csrcCount();
  66. }
  67. inline void preparePacket() {
  68. _first |= (1 << 7);
  69. }
  70. inline void setSeqNumber(uint16_t newSeqNo) { _seqNumber = htons(newSeqNo); }
  71. inline void setPayloadType(uint8_t newPayloadType) {
  72. _payloadType = (_payloadType & 0b10000000u) | (0b01111111u & newPayloadType);
  73. }
  74. inline void setSsrc(uint32_t in_ssrc) { _ssrc = htonl(in_ssrc); }
  75. inline void setMarker(bool marker) { _payloadType = (_payloadType & 0x7F) | (marker << 7); };
  76. void setTimestamp(uint32_t i) { _timestamp = htonl(i); }
  77. void log() {
  78. PLOG_VERBOSE << "RTP V: " << (int)version() << " P: " << (padding() ? "P" : " ")
  79. << " X: " << (extension() ? "X" : " ") << " CC: " << (int)csrcCount()
  80. << " M: " << (marker() ? "M" : " ") << " PT: " << (int)payloadType()
  81. << " SEQNO: " << seqNumber() << " TS: " << timestamp();
  82. }
  83. };
  84. struct RTCP_ReportBlock {
  85. SSRC ssrc;
  86. private:
  87. uint32_t _fractionLostAndPacketsLost; // fraction lost is 8-bit, packets lost is 24-bit
  88. uint16_t _seqNoCycles;
  89. uint16_t _highestSeqNo;
  90. uint32_t _jitter;
  91. uint32_t _lastReport;
  92. uint32_t _delaySinceLastReport;
  93. public:
  94. inline void preparePacket(SSRC in_ssrc, [[maybe_unused]] unsigned int packetsLost,
  95. [[maybe_unused]] unsigned int totalPackets, uint16_t highestSeqNo,
  96. uint16_t seqNoCycles, uint32_t jitter, uint64_t lastSR_NTP,
  97. uint64_t lastSR_DELAY) {
  98. setSeqNo(highestSeqNo, seqNoCycles);
  99. setJitter(jitter);
  100. setSSRC(in_ssrc);
  101. // Middle 32 bits of NTP Timestamp
  102. // this->lastReport = lastSR_NTP >> 16u;
  103. setNTPOfSR(uint64_t(lastSR_NTP));
  104. setDelaySinceSR(uint32_t(lastSR_DELAY));
  105. // The delay, expressed in units of 1/65536 seconds
  106. // this->delaySinceLastReport = lastSR_DELAY;
  107. }
  108. inline void setSSRC(SSRC in_ssrc) { this->ssrc = htonl(in_ssrc); }
  109. [[nodiscard]] inline SSRC getSSRC() const { return ntohl(ssrc); }
  110. inline void setPacketsLost([[maybe_unused]] unsigned int packetsLost,
  111. [[maybe_unused]] unsigned int totalPackets) {
  112. // TODO Implement loss percentages.
  113. _fractionLostAndPacketsLost = 0;
  114. }
  115. [[nodiscard]] inline unsigned int getLossPercentage() const {
  116. // TODO Implement loss percentages.
  117. return 0;
  118. }
  119. [[nodiscard]] inline unsigned int getPacketLostCount() const {
  120. // TODO Implement total packets lost.
  121. return 0;
  122. }
  123. inline uint16_t seqNoCycles() const { return ntohs(_seqNoCycles); }
  124. inline uint16_t highestSeqNo() const { return ntohs(_highestSeqNo); }
  125. inline uint32_t jitter() const { return ntohl(_jitter); }
  126. inline void setSeqNo(uint16_t highestSeqNo, uint16_t seqNoCycles) {
  127. _highestSeqNo = htons(highestSeqNo);
  128. _seqNoCycles = htons(seqNoCycles);
  129. }
  130. inline void setJitter(uint32_t jitter) { _jitter = htonl(jitter); }
  131. inline void setNTPOfSR(uint64_t ntp) { _lastReport = htonll(ntp >> 16u); }
  132. [[nodiscard]] inline uint32_t getNTPOfSR() const { return ntohl(_lastReport) << 16u; }
  133. inline void setDelaySinceSR(uint32_t sr) {
  134. // The delay, expressed in units of 1/65536 seconds
  135. _delaySinceLastReport = htonl(sr);
  136. }
  137. [[nodiscard]] inline uint32_t getDelaySinceSR() const { return ntohl(_delaySinceLastReport); }
  138. inline void log() const {
  139. PLOG_VERBOSE << "RTCP report block: "
  140. << "ssrc="
  141. << ntohl(ssrc)
  142. // TODO: Implement these reports
  143. // << ", fractionLost=" << fractionLost
  144. // << ", packetsLost=" << packetsLost
  145. << ", highestSeqNo=" << highestSeqNo() << ", seqNoCycles=" << seqNoCycles()
  146. << ", jitter=" << jitter() << ", lastSR=" << getNTPOfSR()
  147. << ", lastSRDelay=" << getDelaySinceSR();
  148. }
  149. };
  150. struct RTCP_HEADER {
  151. private:
  152. uint8_t _first;
  153. uint8_t _payloadType;
  154. uint16_t _length;
  155. public:
  156. inline uint8_t version() const { return _first >> 6; }
  157. inline bool padding() const { return (_first >> 5) & 0x01; }
  158. inline uint8_t reportCount() const { return _first & 0x0F; }
  159. inline uint8_t payloadType() const { return _payloadType; }
  160. inline uint16_t length() const { return ntohs(_length); }
  161. inline size_t lengthInBytes() const { return (1 + length()) * 4; }
  162. inline void setPayloadType(uint8_t type) { _payloadType = type; }
  163. inline void setReportCount(uint8_t count) {
  164. _first = (_first & 0b11100000u) | (count & 0b00011111u);
  165. }
  166. inline void setLength(uint16_t length) { _length = htons(length); }
  167. inline void prepareHeader(uint8_t payloadType, uint8_t reportCount, uint16_t length) {
  168. _first = 0b10000000; // version 2, no padding
  169. setReportCount(reportCount);
  170. setPayloadType(payloadType);
  171. setLength(length);
  172. }
  173. inline void log() const {
  174. PLOG_VERBOSE << "RTCP header: "
  175. << "version=" << unsigned(version()) << ", padding=" << padding()
  176. << ", reportCount=" << unsigned(reportCount())
  177. << ", payloadType=" << unsigned(payloadType()) << ", length=" << length();
  178. }
  179. };
  180. struct RTCP_FB_HEADER {
  181. RTCP_HEADER header;
  182. SSRC packetSender;
  183. SSRC mediaSource;
  184. [[nodiscard]] SSRC getPacketSenderSSRC() const { return ntohl(packetSender); }
  185. [[nodiscard]] SSRC getMediaSourceSSRC() const { return ntohl(mediaSource); }
  186. void setPacketSenderSSRC(SSRC ssrc) { this->packetSender = htonl(ssrc); }
  187. void setMediaSourceSSRC(SSRC ssrc) { this->mediaSource = htonl(ssrc); }
  188. void log() {
  189. header.log();
  190. PLOG_VERBOSE << "FB: "
  191. << " packet sender: " << getPacketSenderSSRC()
  192. << " media source: " << getMediaSourceSSRC();
  193. }
  194. };
  195. struct RTCP_SR {
  196. RTCP_HEADER header;
  197. SSRC _senderSSRC;
  198. private:
  199. uint64_t _ntpTimestamp;
  200. uint32_t _rtpTimestamp;
  201. uint32_t _packetCount;
  202. uint32_t _octetCount;
  203. RTCP_ReportBlock _reportBlocks;
  204. public:
  205. inline void preparePacket(SSRC senderSSRC, uint8_t reportCount) {
  206. unsigned int length =
  207. ((sizeof(header) + 24 + reportCount * sizeof(RTCP_ReportBlock)) / 4) - 1;
  208. header.prepareHeader(200, reportCount, uint16_t(length));
  209. this->_senderSSRC = htonl(senderSSRC);
  210. }
  211. [[nodiscard]] inline RTCP_ReportBlock *getReportBlock(int num) { return &_reportBlocks + num; }
  212. [[nodiscard]] inline const RTCP_ReportBlock *getReportBlock(int num) const {
  213. return &_reportBlocks + num;
  214. }
  215. [[nodiscard]] static unsigned int size(unsigned int reportCount) {
  216. return sizeof(RTCP_HEADER) + 24 + reportCount * sizeof(RTCP_ReportBlock);
  217. }
  218. [[nodiscard]] inline size_t getSize() const {
  219. // "length" in packet is one less than the number of 32 bit words in the packet.
  220. return sizeof(uint32_t) * (1 + size_t(header.length()));
  221. }
  222. inline uint64_t ntpTimestamp() const { return ntohll(_ntpTimestamp); }
  223. inline uint32_t rtpTimestamp() const { return ntohl(_rtpTimestamp); }
  224. inline uint32_t packetCount() const { return ntohl(_packetCount); }
  225. inline uint32_t octetCount() const { return ntohl(_octetCount); }
  226. inline uint32_t senderSSRC() const { return ntohl(_senderSSRC); }
  227. inline void setNtpTimestamp(uint64_t ts) { _ntpTimestamp = htonll(ts); }
  228. inline void setRtpTimestamp(uint32_t ts) { _rtpTimestamp = htonl(ts); }
  229. inline void setOctetCount(uint32_t ts) { _octetCount = htonl(ts); }
  230. inline void setPacketCount(uint32_t ts) { _packetCount = htonl(ts); }
  231. inline void log() const {
  232. header.log();
  233. PLOG_VERBOSE << "RTCP SR: "
  234. << " SSRC=" << senderSSRC() << ", NTP_TS=" << ntpTimestamp()
  235. << ", RTP_TS=" << rtpTimestamp() << ", packetCount=" << packetCount()
  236. << ", octetCount=" << octetCount();
  237. for (unsigned i = 0; i < unsigned(header.reportCount()); i++) {
  238. getReportBlock(i)->log();
  239. }
  240. }
  241. };
  242. struct RTCP_SDES_CHUNK {
  243. private:
  244. SSRC _ssrc;
  245. public:
  246. uint8_t type;
  247. private:
  248. uint8_t _length;
  249. char _text;
  250. public:
  251. inline SSRC ssrc() const { return ntohl(_ssrc); }
  252. inline void setSSRC(SSRC ssrc) { _ssrc = htonl(ssrc); }
  253. inline std::string text() const {
  254. return std::string(&_text, _length);
  255. }
  256. inline void setText(std::string text) {
  257. _length = text.length();
  258. memcpy(&_text, text.data(), _length);
  259. }
  260. inline uint8_t length() {
  261. return _length;
  262. }
  263. [[nodiscard]] static unsigned int size(uint8_t textLength) {
  264. auto words = uint8_t(std::ceil(double(textLength + 2) / 4)) + 1;
  265. return words * 4;
  266. }
  267. };
  268. struct RTCP_SDES {
  269. RTCP_HEADER header;
  270. private:
  271. RTCP_SDES_CHUNK _chunks;
  272. public:
  273. inline void preparePacket(uint8_t chunkCount) {
  274. unsigned int chunkSize = 0;
  275. for(uint8_t i = 0; i < chunkCount; i++) {
  276. auto chunk = getChunk(i);
  277. chunkSize += RTCP_SDES_CHUNK::size(chunk->length());
  278. }
  279. uint16_t length = (sizeof(header) + chunkSize) / 4 - 1;
  280. header.prepareHeader(202, chunkCount, length);
  281. }
  282. inline RTCP_SDES_CHUNK *getChunk(int num) {
  283. auto base = &_chunks;
  284. while (num-- > 0) {
  285. auto chunkSize = RTCP_SDES_CHUNK::size(base->length());
  286. base = reinterpret_cast<RTCP_SDES_CHUNK *>(reinterpret_cast<uint8_t *>(base) + chunkSize);
  287. }
  288. return reinterpret_cast<RTCP_SDES_CHUNK *>(base);
  289. }
  290. [[nodiscard]] static unsigned int size(std::vector<uint8_t> lengths) {
  291. unsigned int chunks_size = 0;
  292. for (auto length: lengths) {
  293. chunks_size += RTCP_SDES_CHUNK::size(length);
  294. }
  295. return 4 + chunks_size;
  296. }
  297. };
  298. struct RTCP_RR {
  299. RTCP_HEADER header;
  300. SSRC _senderSSRC;
  301. private:
  302. RTCP_ReportBlock _reportBlocks;
  303. public:
  304. [[nodiscard]] inline RTCP_ReportBlock *getReportBlock(int num) { return &_reportBlocks + num; }
  305. [[nodiscard]] inline const RTCP_ReportBlock *getReportBlock(int num) const {
  306. return &_reportBlocks + num;
  307. }
  308. inline SSRC senderSSRC() const { return ntohl(_senderSSRC); }
  309. inline void setSenderSSRC(SSRC ssrc) { this->_senderSSRC = htonl(ssrc); }
  310. [[nodiscard]] inline size_t getSize() const {
  311. // "length" in packet is one less than the number of 32 bit words in the packet.
  312. return sizeof(uint32_t) * (1 + size_t(header.length()));
  313. }
  314. inline void preparePacket(SSRC senderSSRC, uint8_t reportCount) {
  315. // "length" in packet is one less than the number of 32 bit words in the packet.
  316. size_t length = (sizeWithReportBlocks(reportCount) / 4) - 1;
  317. header.prepareHeader(201, reportCount, uint16_t(length));
  318. this->_senderSSRC = htonl(senderSSRC);
  319. }
  320. inline static size_t sizeWithReportBlocks(uint8_t reportCount) {
  321. return sizeof(header) + 4 + size_t(reportCount) * sizeof(RTCP_ReportBlock);
  322. }
  323. inline bool isSenderReport() { return header.payloadType() == 200; }
  324. inline bool isReceiverReport() { return header.payloadType() == 201; }
  325. inline void log() const {
  326. header.log();
  327. PLOG_VERBOSE << "RTCP RR: "
  328. << " SSRC=" << ntohl(_senderSSRC);
  329. for (unsigned i = 0; i < unsigned(header.reportCount()); i++) {
  330. getReportBlock(i)->log();
  331. }
  332. }
  333. };
  334. struct RTCP_REMB {
  335. RTCP_FB_HEADER header;
  336. /*! \brief Unique identifier ('R' 'E' 'M' 'B') */
  337. char id[4];
  338. /*! \brief Num SSRC, Br Exp, Br Mantissa (bit mask) */
  339. uint32_t bitrate;
  340. SSRC ssrc[1];
  341. [[nodiscard]] unsigned int getSize() const {
  342. // "length" in packet is one less than the number of 32 bit words in the packet.
  343. return sizeof(uint32_t) * (1 + header.header.length());
  344. }
  345. void preparePacket(SSRC senderSSRC, unsigned int numSSRC, unsigned int in_bitrate) {
  346. // Report Count becomes the format here.
  347. header.header.prepareHeader(206, 15, 0);
  348. // Always zero.
  349. header.setMediaSourceSSRC(0);
  350. header.setPacketSenderSSRC(senderSSRC);
  351. id[0] = 'R';
  352. id[1] = 'E';
  353. id[2] = 'M';
  354. id[3] = 'B';
  355. setBitrate(numSSRC, in_bitrate);
  356. }
  357. void setBitrate(unsigned int numSSRC, unsigned int in_bitrate) {
  358. unsigned int exp = 0;
  359. while (in_bitrate > pow(2, 18) - 1) {
  360. exp++;
  361. in_bitrate /= 2;
  362. }
  363. // "length" in packet is one less than the number of 32 bit words in the packet.
  364. header.header.setLength(
  365. uint16_t((offsetof(RTCP_REMB, ssrc) / sizeof(uint32_t)) - 1 + numSSRC));
  366. this->bitrate = htonl((numSSRC << (32u - 8u)) | (exp << (32u - 8u - 6u)) | in_bitrate);
  367. }
  368. void setSsrc(int iterator, SSRC newSssrc) { ssrc[iterator] = htonl(newSssrc); }
  369. size_t static inline sizeWithSSRCs(int count) {
  370. return sizeof(RTCP_REMB) + (count - 1) * sizeof(SSRC);
  371. }
  372. };
  373. struct RTCP_PLI {
  374. RTCP_FB_HEADER header;
  375. void preparePacket(SSRC messageSSRC) {
  376. header.header.prepareHeader(206, 1, 2);
  377. header.setPacketSenderSSRC(messageSSRC);
  378. header.setMediaSourceSSRC(messageSSRC);
  379. }
  380. void print() { header.log(); }
  381. [[nodiscard]] static unsigned int size() { return sizeof(RTCP_FB_HEADER); }
  382. };
  383. struct RTCP_FIR_PART {
  384. uint32_t ssrc;
  385. uint8_t seqNo;
  386. uint8_t dummy1;
  387. uint16_t dummy2;
  388. };
  389. struct RTCP_FIR {
  390. RTCP_FB_HEADER header;
  391. RTCP_FIR_PART parts[1];
  392. void preparePacket(SSRC messageSSRC, uint8_t seqNo) {
  393. header.header.prepareHeader(206, 4, 2 + 2 * 1);
  394. header.setPacketSenderSSRC(messageSSRC);
  395. header.setMediaSourceSSRC(messageSSRC);
  396. parts[0].ssrc = htonl(messageSSRC);
  397. parts[0].seqNo = seqNo;
  398. }
  399. void print() { header.log(); }
  400. [[nodiscard]] static unsigned int size() {
  401. return sizeof(RTCP_FB_HEADER) + sizeof(RTCP_FIR_PART);
  402. }
  403. };
  404. struct RTCP_NACK_PART {
  405. uint16_t pid;
  406. uint16_t blp;
  407. };
  408. class RTCP_NACK {
  409. public:
  410. RTCP_FB_HEADER header;
  411. RTCP_NACK_PART parts[1];
  412. public:
  413. void preparePacket(SSRC ssrc, unsigned int discreteSeqNoCount) {
  414. header.header.prepareHeader(205, 1, 2 + uint16_t(discreteSeqNoCount));
  415. header.setMediaSourceSSRC(ssrc);
  416. header.setPacketSenderSSRC(ssrc);
  417. }
  418. /**
  419. * Add a packet to the list of missing packets.
  420. * @param fciCount The number of FCI fields that are present in this packet.
  421. * Let the number start at zero and let this function grow the number.
  422. * @param fciPID The seq no of the active FCI. It will be initialized automatically, and will
  423. * change automatically.
  424. * @param missingPacket The seq no of the missing packet. This will be added to the queue.
  425. * @return true if the packet has grown, false otherwise.
  426. */
  427. bool addMissingPacket(unsigned int *fciCount, uint16_t *fciPID, uint16_t missingPacket) {
  428. if (*fciCount == 0 || missingPacket < *fciPID || missingPacket > (*fciPID + 16)) {
  429. parts[*fciCount].pid = htons(missingPacket);
  430. parts[*fciCount].blp = 0;
  431. *fciPID = missingPacket;
  432. (*fciCount)++;
  433. return true;
  434. } else {
  435. // TODO SPEEED!
  436. auto blp = ntohs(parts[(*fciCount) - 1].blp);
  437. auto newBit = 1u << (unsigned int)(missingPacket - (1 + *fciPID));
  438. parts[(*fciCount) - 1].blp = htons(blp | newBit);
  439. return false;
  440. }
  441. }
  442. [[nodiscard]] static unsigned int getSize(unsigned int discreteSeqNoCount) {
  443. return offsetof(RTCP_NACK, parts) + sizeof(RTCP_NACK_PART) * discreteSeqNoCount;
  444. }
  445. [[nodiscard]] unsigned int getSeqNoCount() { return header.header.length() - 2; }
  446. };
  447. class RTP_RTX {
  448. private:
  449. RTP header;
  450. public:
  451. size_t copyTo(RTP *dest, size_t totalSize, uint8_t originalPayloadType) {
  452. memmove((char *)dest, (char *)this, header.getSize());
  453. dest->setSeqNumber(getOriginalSeqNo());
  454. dest->setPayloadType(originalPayloadType);
  455. memmove(dest->getBody(), getBody(), getBodySize(totalSize));
  456. return totalSize;
  457. }
  458. [[nodiscard]] uint16_t getOriginalSeqNo() const {
  459. return ntohs(*(uint16_t *)(header.getBody()));
  460. }
  461. [[nodiscard]] char *getBody() { return header.getBody() + sizeof(uint16_t); }
  462. [[nodiscard]] const char *getBody() const { return header.getBody() + sizeof(uint16_t); }
  463. [[nodiscard]] size_t getBodySize(size_t totalSize) {
  464. return totalSize - (getBody() - reinterpret_cast<char *>(this));
  465. }
  466. [[nodiscard]] RTP &getHeader() { return header; }
  467. size_t normalizePacket(size_t totalSize, SSRC originalSSRC, uint8_t originalPayloadType) {
  468. header.setSeqNumber(getOriginalSeqNo());
  469. header.setSsrc(originalSSRC);
  470. header.setPayloadType(originalPayloadType);
  471. // TODO, the -12 is the size of the header (which is variable!)
  472. memmove(header.getBody(), header.getBody() + sizeof(uint16_t),
  473. totalSize - 12 - sizeof(uint16_t));
  474. return totalSize - sizeof(uint16_t);
  475. }
  476. };
  477. #pragma pack(pop)
  478. }; // namespace rtc
  479. #endif