rtcpnackresponder.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * Copyright (c) 2020 Filip Klembara (in2core)
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef RTC_RTCP_NACK_RESPONDER_H
  19. #define RTC_RTCP_NACK_RESPONDER_H
  20. #if RTC_ENABLE_MEDIA
  21. #include "mediahandlerelement.hpp"
  22. #include <queue>
  23. #include <unordered_map>
  24. namespace rtc {
  25. class RTC_CPP_EXPORT RtcpNackResponder final : public MediaHandlerElement {
  26. /// Packet storage
  27. class RTC_CPP_EXPORT Storage {
  28. /// Packet storage element
  29. struct RTC_CPP_EXPORT Element {
  30. Element(binary_ptr packet, uint16_t sequenceNumber, shared_ptr<Element> next = nullptr);
  31. const binary_ptr packet;
  32. const uint16_t sequenceNumber;
  33. /// Pointer to newer element
  34. shared_ptr<Element> next = nullptr;
  35. };
  36. private:
  37. /// Oldest packet in storage
  38. shared_ptr<Element> oldest = nullptr;
  39. /// Newest packet in storage
  40. shared_ptr<Element> newest = nullptr;
  41. /// Inner storage
  42. std::unordered_map<uint16_t, shared_ptr<Element>> storage{};
  43. /// Maximum storage size
  44. const unsigned maximumSize;
  45. /// Returnst current size
  46. unsigned size();
  47. public:
  48. static const unsigned defaultMaximumSize = 512;
  49. Storage(unsigned _maximumSize);
  50. /// Returns packet with given sequence number
  51. optional<binary_ptr> get(uint16_t sequenceNumber);
  52. /// Stores packet
  53. /// @param packet Packet
  54. void store(binary_ptr packet);
  55. };
  56. const shared_ptr<Storage> storage;
  57. std::mutex reportMutex;
  58. public:
  59. RtcpNackResponder(unsigned maxStoredPacketCount = Storage::defaultMaximumSize);
  60. /// Checks for RTCP NACK and handles it,
  61. /// @param message RTCP message
  62. /// @returns unchanged RTCP message and requested RTP packets
  63. ChainedIncomingControlProduct processIncomingControlMessage(message_ptr message) override;
  64. /// Stores RTP packets in internal storage
  65. /// @param messages RTP packets
  66. /// @param control RTCP
  67. /// @returns Unchanged RTP and RTCP
  68. ChainedOutgoingProduct processOutgoingBinaryMessage(ChainedMessagesProduct messages,
  69. message_ptr control) override;
  70. };
  71. } // namespace rtc
  72. #endif /* RTC_ENABLE_MEDIA */
  73. #endif /* RTC_RTCP_NACK_RESPONDER_H */