rtcpnackresponder.hpp 2.6 KB

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