rtcpsrreporter.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 "message.hpp"
  22. #include "rtppacketizationconfig.hpp"
  23. #include "mediahandlerelement.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 _previousReportedTimestamp = 0;
  31. void addToReport(RTP *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 = _previousReportedTimestamp;
  37. /// RTP configuration
  38. const shared_ptr<RtpPacketizationConfig> rtpConfig;
  39. RtcpSrReporter(shared_ptr<RtpPacketizationConfig> rtpConfig);
  40. ChainedOutgoingProduct processOutgoingBinaryMessage(ChainedMessagesProduct messages, message_ptr control) override;
  41. /// Set `needsToReport` flag. Sender report will be sent before next RTP packet with same
  42. /// timestamp.
  43. void setNeedsToReport();
  44. /// Set offset to compute NTS for RTCP SR packets. Offset represents relation between real start
  45. /// time and timestamp of the stream in RTP packets
  46. /// @note `time_offset = rtpConfig->startTime_s -
  47. /// rtpConfig->timestampToSeconds(rtpConfig->timestamp)`
  48. void startRecording();
  49. };
  50. } // namespace rtc
  51. #endif /* RTC_ENABLE_MEDIA */
  52. #endif /* RTC_RTCP_SENDER_REPORTABLE_H */