rtcpsrreporter.hpp 2.1 KB

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