2
0

rtcpnackresponder.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * Copyright (c) 2020 Filip Klembara (in2core)
  3. *
  4. * This Source Code Form is subject to the terms of the Mozilla Public
  5. * License, v. 2.0. If a copy of the MPL was not distributed with this
  6. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  7. */
  8. #ifndef RTC_RTCP_NACK_RESPONDER_H
  9. #define RTC_RTCP_NACK_RESPONDER_H
  10. #if RTC_ENABLE_MEDIA
  11. #include "mediahandler.hpp"
  12. #include <queue>
  13. #include <unordered_map>
  14. namespace rtc {
  15. class RTC_CPP_EXPORT RtcpNackResponder final : public MediaHandler {
  16. public:
  17. static const size_t DefaultMaxSize = 512;
  18. RtcpNackResponder(size_t maxSize = DefaultMaxSize);
  19. void incoming(message_vector &messages, const message_callback &send) override;
  20. void outgoing(message_vector &messages, const message_callback &send) override;
  21. private:
  22. // Packet storage
  23. class RTC_CPP_EXPORT Storage {
  24. /// Packet storage element
  25. struct RTC_CPP_EXPORT Element {
  26. Element(message_ptr packet, uint16_t sequenceNumber, shared_ptr<Element> next = nullptr);
  27. const message_ptr packet;
  28. const uint16_t sequenceNumber;
  29. /// Pointer to newer element
  30. shared_ptr<Element> next = nullptr;
  31. };
  32. private:
  33. /// Oldest packet in storage
  34. shared_ptr<Element> oldest = nullptr;
  35. /// Newest packet in storage
  36. shared_ptr<Element> newest = nullptr;
  37. /// Inner storage
  38. std::unordered_map<uint16_t, shared_ptr<Element>> storage{};
  39. std::mutex mutex;
  40. /// Maximum storage size
  41. const size_t maxSize;
  42. /// Returns current size
  43. size_t size();
  44. public:
  45. Storage(size_t _maxSize);
  46. /// Returns packet with given sequence number
  47. message_ptr get(uint16_t sequenceNumber);
  48. /// Stores packet
  49. /// @param packet Packet
  50. void store(message_ptr packet);
  51. };
  52. const shared_ptr<Storage> mStorage;
  53. };
  54. } // namespace rtc
  55. #endif /* RTC_ENABLE_MEDIA */
  56. #endif /* RTC_RTCP_NACK_RESPONDER_H */