rtcp.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * Copyright (c) 2020 Staz Modrzynski
  3. * Copyright (c) 2020 Paul-Louis Ageneau
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #ifndef RTC_RTCP_H
  20. #define RTC_RTCP_H
  21. #include <utility>
  22. #include "include.hpp"
  23. #include "log.hpp"
  24. #include "message.hpp"
  25. #include "rtp.hpp"
  26. namespace rtc {
  27. class RtcpHandler {
  28. protected:
  29. /**
  30. * Use this callback when trying to send custom data (such as RTCP) to the client.
  31. */
  32. synchronized_callback<rtc::message_ptr> outgoingCallback;
  33. public:
  34. /**
  35. * Called when there is traffic coming from the peer
  36. * @param ptr
  37. * @return
  38. */
  39. virtual rtc::message_ptr incoming(rtc::message_ptr ptr) = 0;
  40. /**
  41. * Called when there is traffic that needs to be sent to the peer
  42. * @param ptr
  43. * @return
  44. */
  45. virtual rtc::message_ptr outgoing(rtc::message_ptr ptr) = 0;
  46. /**
  47. * This callback is used to send traffic back to the peer.
  48. * This callback skips calling the track's methods.
  49. * @param cb
  50. */
  51. void onOutgoing(const std::function<void(rtc::message_ptr)> &cb);
  52. virtual bool requestKeyframe() { return false; }
  53. };
  54. class Track;
  55. // An RtcpSession can be plugged into a Track to handle the whole RTCP session
  56. class RtcpReceivingSession : public RtcpHandler {
  57. public:
  58. rtc::message_ptr incoming(rtc::message_ptr ptr) override;
  59. rtc::message_ptr outgoing(rtc::message_ptr ptr) override;
  60. bool send(rtc::message_ptr ptr);
  61. void requestBitrate(unsigned int newBitrate);
  62. bool requestKeyframe() override;
  63. protected:
  64. void pushREMB(unsigned int bitrate);
  65. void pushRR(unsigned int lastSR_delay);
  66. void pushPLI();
  67. unsigned int mRequestedBitrate = 0;
  68. SSRC mSsrc = 0;
  69. uint32_t mGreatestSeqNo = 0;
  70. uint64_t mSyncRTPTS, mSyncNTPTS;
  71. };
  72. } // namespace rtc
  73. #endif // RTC_RTCP_H