rtcpsrreporter.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_SENDER_REPORTABLE_H
  19. #define RTC_RTCP_SENDER_REPORTABLE_H
  20. #if RTC_ENABLE_MEDIA
  21. #include "mediahandlerelement.hpp"
  22. #include "message.hpp"
  23. #include "rtppacketizationconfig.hpp"
  24. namespace rtc {
  25. class RTC_CPP_EXPORT RtcpSrReporter final : public MediaHandlerElement {
  26. bool needsToReport = false;
  27. uint32_t packetCount = 0;
  28. uint32_t payloadOctets = 0;
  29. double timeOffset = 0;
  30. uint32_t mPreviousReportedTimestamp = 0;
  31. void addToReport(RtpHeader *rtp, uint32_t rtpSize);
  32. message_ptr getSenderReport(uint32_t timestamp);
  33. public:
  34. static uint64_t secondsToNTP(double seconds);
  35. /// Timestamp of previous sender report
  36. const uint32_t &previousReportedTimestamp = mPreviousReportedTimestamp;
  37. /// RTP configuration
  38. const shared_ptr<RtpPacketizationConfig> rtpConfig;
  39. RtcpSrReporter(shared_ptr<RtpPacketizationConfig> rtpConfig);
  40. ChainedOutgoingProduct processOutgoingBinaryMessage(ChainedMessagesProduct messages,
  41. message_ptr control) override;
  42. /// Set `needsToReport` flag. Sender report will be sent before next RTP packet with same
  43. /// timestamp.
  44. void setNeedsToReport();
  45. /// Set offset to compute NTS for RTCP SR packets. Offset represents relation between real start
  46. /// time and timestamp of the stream in RTP packets
  47. /// @note `time_offset = rtpConfig->startTime - rtpConfig->timestampToSeconds(rtpConfig->timestamp)`
  48. void startRecording();
  49. };
  50. } // namespace rtc
  51. #endif /* RTC_ENABLE_MEDIA */
  52. #endif /* RTC_RTCP_SENDER_REPORTABLE_H */