rtcp_transceiver_impl.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_IMPL_H_
  11. #define MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_IMPL_H_
  12. #include <map>
  13. #include <memory>
  14. #include <string>
  15. #include <vector>
  16. #include "absl/types/optional.h"
  17. #include "api/array_view.h"
  18. #include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
  19. #include "modules/rtp_rtcp/source/rtcp_packet/dlrr.h"
  20. #include "modules/rtp_rtcp/source/rtcp_packet/remb.h"
  21. #include "modules/rtp_rtcp/source/rtcp_packet/report_block.h"
  22. #include "modules/rtp_rtcp/source/rtcp_packet/target_bitrate.h"
  23. #include "modules/rtp_rtcp/source/rtcp_transceiver_config.h"
  24. #include "rtc_base/task_utils/repeating_task.h"
  25. #include "system_wrappers/include/ntp_time.h"
  26. namespace webrtc {
  27. //
  28. // Manage incoming and outgoing rtcp messages for multiple BUNDLED streams.
  29. //
  30. // This class is not thread-safe.
  31. class RtcpTransceiverImpl {
  32. public:
  33. explicit RtcpTransceiverImpl(const RtcpTransceiverConfig& config);
  34. RtcpTransceiverImpl(const RtcpTransceiverImpl&) = delete;
  35. RtcpTransceiverImpl& operator=(const RtcpTransceiverImpl&) = delete;
  36. ~RtcpTransceiverImpl();
  37. void StopPeriodicTask() { periodic_task_handle_.Stop(); }
  38. void AddMediaReceiverRtcpObserver(uint32_t remote_ssrc,
  39. MediaReceiverRtcpObserver* observer);
  40. void RemoveMediaReceiverRtcpObserver(uint32_t remote_ssrc,
  41. MediaReceiverRtcpObserver* observer);
  42. void SetReadyToSend(bool ready);
  43. void ReceivePacket(rtc::ArrayView<const uint8_t> packet, int64_t now_us);
  44. void SendCompoundPacket();
  45. void SetRemb(int64_t bitrate_bps, std::vector<uint32_t> ssrcs);
  46. void UnsetRemb();
  47. // Temporary helpers to send pre-built TransportFeedback rtcp packet.
  48. uint32_t sender_ssrc() const { return config_.feedback_ssrc; }
  49. void SendRawPacket(rtc::ArrayView<const uint8_t> packet);
  50. void SendNack(uint32_t ssrc, std::vector<uint16_t> sequence_numbers);
  51. void SendPictureLossIndication(uint32_t ssrc);
  52. // If new_request is true then requested sequence no. will increase for each
  53. // requested ssrc.
  54. void SendFullIntraRequest(rtc::ArrayView<const uint32_t> ssrcs,
  55. bool new_request);
  56. // SendCombinedRtcpPacket ignores rtcp mode and does not send a compound
  57. // message. https://tools.ietf.org/html/rfc4585#section-3.1
  58. void SendCombinedRtcpPacket(
  59. std::vector<std::unique_ptr<rtcp::RtcpPacket>> rtcp_packets);
  60. private:
  61. class PacketSender;
  62. struct RemoteSenderState;
  63. void HandleReceivedPacket(const rtcp::CommonHeader& rtcp_packet_header,
  64. int64_t now_us);
  65. // Individual rtcp packet handlers.
  66. void HandleBye(const rtcp::CommonHeader& rtcp_packet_header);
  67. void HandleSenderReport(const rtcp::CommonHeader& rtcp_packet_header,
  68. int64_t now_us);
  69. void HandleExtendedReports(const rtcp::CommonHeader& rtcp_packet_header,
  70. int64_t now_us);
  71. // Extended Reports blocks handlers.
  72. void HandleDlrr(const rtcp::Dlrr& dlrr, int64_t now_us);
  73. void HandleTargetBitrate(const rtcp::TargetBitrate& target_bitrate,
  74. uint32_t remote_ssrc);
  75. void ReschedulePeriodicCompoundPackets();
  76. void SchedulePeriodicCompoundPackets(int64_t delay_ms);
  77. // Creates compound RTCP packet, as defined in
  78. // https://tools.ietf.org/html/rfc5506#section-2
  79. void CreateCompoundPacket(PacketSender* sender);
  80. // Sends RTCP packets.
  81. void SendPeriodicCompoundPacket();
  82. void SendImmediateFeedback(const rtcp::RtcpPacket& rtcp_packet);
  83. // Generate Report Blocks to be send in Sender or Receiver Report.
  84. std::vector<rtcp::ReportBlock> CreateReportBlocks(int64_t now_us);
  85. const RtcpTransceiverConfig config_;
  86. bool ready_to_send_;
  87. absl::optional<rtcp::Remb> remb_;
  88. // TODO(danilchap): Remove entries from remote_senders_ that are no longer
  89. // needed.
  90. std::map<uint32_t, RemoteSenderState> remote_senders_;
  91. RepeatingTaskHandle periodic_task_handle_;
  92. };
  93. } // namespace webrtc
  94. #endif // MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_IMPL_H_