TwccContext.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2021 The ZLMediaKit project authors. All Rights Reserved.
  3. *
  4. * This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
  5. *
  6. * Use of this source code is governed by MIT-like license that can be found in the
  7. * LICENSE file in the root of the source tree. All contributing project authors
  8. * may be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef ZLMEDIAKIT_TWCCCONTEXT_H
  11. #define ZLMEDIAKIT_TWCCCONTEXT_H
  12. #include <stdint.h>
  13. #include <map>
  14. #include <functional>
  15. #include <string>
  16. namespace mediakit {
  17. class TwccContext {
  18. public:
  19. using onSendTwccCB = std::function<void(uint32_t ssrc, std::string fci)>;
  20. // 每个twcc rtcp包最多表明的rtp ext seq增量 [AUTO-TRANSLATED:530d1e35]
  21. // Maximum RTP ext seq increment indicated by each twcc rtcp packet
  22. static constexpr size_t kMaxSeqSize = 20;
  23. // 每个twcc rtcp包发送的最大时间间隔,单位毫秒 [AUTO-TRANSLATED:e45656da]
  24. // Maximum time interval for sending each twcc rtcp packet, in milliseconds
  25. static constexpr size_t kMaxTimeDelta = 256;
  26. void onRtp(uint32_t ssrc, uint16_t twcc_ext_seq, uint64_t stamp_ms);
  27. void setOnSendTwccCB(onSendTwccCB cb);
  28. private:
  29. void onSendTwcc(uint32_t ssrc);
  30. bool needSendTwcc() const;
  31. int checkSeqStatus(uint16_t twcc_ext_seq) const;
  32. void clearStatus();
  33. private:
  34. uint64_t _min_stamp = 0;
  35. uint64_t _max_stamp;
  36. std::map<uint32_t /*twcc_ext_seq*/, uint64_t/*recv time in ms*/> _rtp_recv_status;
  37. uint8_t _twcc_pkt_count = 0;
  38. onSendTwccCB _cb;
  39. };
  40. }// namespace mediakit
  41. #endif //ZLMEDIAKIT_TWCCCONTEXT_H