rtp_transport_controller_send.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 CALL_RTP_TRANSPORT_CONTROLLER_SEND_H_
  11. #define CALL_RTP_TRANSPORT_CONTROLLER_SEND_H_
  12. #include <atomic>
  13. #include <map>
  14. #include <memory>
  15. #include <string>
  16. #include <vector>
  17. #include "api/network_state_predictor.h"
  18. #include "api/transport/network_control.h"
  19. #include "api/units/data_rate.h"
  20. #include "call/rtp_bitrate_configurator.h"
  21. #include "call/rtp_transport_controller_send_interface.h"
  22. #include "call/rtp_video_sender.h"
  23. #include "modules/congestion_controller/rtp/control_handler.h"
  24. #include "modules/congestion_controller/rtp/transport_feedback_adapter.h"
  25. #include "modules/congestion_controller/rtp/transport_feedback_demuxer.h"
  26. #include "modules/pacing/paced_sender.h"
  27. #include "modules/pacing/packet_router.h"
  28. #include "modules/pacing/rtp_packet_pacer.h"
  29. #include "modules/pacing/task_queue_paced_sender.h"
  30. #include "modules/utility/include/process_thread.h"
  31. #include "rtc_base/constructor_magic.h"
  32. #include "rtc_base/network_route.h"
  33. #include "rtc_base/race_checker.h"
  34. #include "rtc_base/task_queue.h"
  35. #include "rtc_base/task_utils/repeating_task.h"
  36. namespace webrtc {
  37. class Clock;
  38. class FrameEncryptorInterface;
  39. class RtcEventLog;
  40. // TODO(nisse): When we get the underlying transports here, we should
  41. // have one object implementing RtpTransportControllerSendInterface
  42. // per transport, sharing the same congestion controller.
  43. class RtpTransportControllerSend final
  44. : public RtpTransportControllerSendInterface,
  45. public RtcpBandwidthObserver,
  46. public TransportFeedbackObserver,
  47. public NetworkStateEstimateObserver {
  48. public:
  49. RtpTransportControllerSend(
  50. Clock* clock,
  51. RtcEventLog* event_log,
  52. NetworkStatePredictorFactoryInterface* predictor_factory,
  53. NetworkControllerFactoryInterface* controller_factory,
  54. const BitrateConstraints& bitrate_config,
  55. std::unique_ptr<ProcessThread> process_thread,
  56. TaskQueueFactory* task_queue_factory,
  57. const WebRtcKeyValueConfig* trials);
  58. ~RtpTransportControllerSend() override;
  59. RtpVideoSenderInterface* CreateRtpVideoSender(
  60. std::map<uint32_t, RtpState> suspended_ssrcs,
  61. const std::map<uint32_t, RtpPayloadState>&
  62. states, // move states into RtpTransportControllerSend
  63. const RtpConfig& rtp_config,
  64. int rtcp_report_interval_ms,
  65. Transport* send_transport,
  66. const RtpSenderObservers& observers,
  67. RtcEventLog* event_log,
  68. std::unique_ptr<FecController> fec_controller,
  69. const RtpSenderFrameEncryptionConfig& frame_encryption_config,
  70. rtc::scoped_refptr<FrameTransformerInterface> frame_transformer) override;
  71. void DestroyRtpVideoSender(
  72. RtpVideoSenderInterface* rtp_video_sender) override;
  73. // Implements RtpTransportControllerSendInterface
  74. rtc::TaskQueue* GetWorkerQueue() override;
  75. PacketRouter* packet_router() override;
  76. NetworkStateEstimateObserver* network_state_estimate_observer() override;
  77. TransportFeedbackObserver* transport_feedback_observer() override;
  78. RtpPacketSender* packet_sender() override;
  79. void SetAllocatedSendBitrateLimits(BitrateAllocationLimits limits) override;
  80. void SetPacingFactor(float pacing_factor) override;
  81. void SetQueueTimeLimit(int limit_ms) override;
  82. StreamFeedbackProvider* GetStreamFeedbackProvider() override;
  83. void RegisterTargetTransferRateObserver(
  84. TargetTransferRateObserver* observer) override;
  85. void OnNetworkRouteChanged(const std::string& transport_name,
  86. const rtc::NetworkRoute& network_route) override;
  87. void OnNetworkAvailability(bool network_available) override;
  88. RtcpBandwidthObserver* GetBandwidthObserver() override;
  89. int64_t GetPacerQueuingDelayMs() const override;
  90. absl::optional<Timestamp> GetFirstPacketTime() const override;
  91. void EnablePeriodicAlrProbing(bool enable) override;
  92. void OnSentPacket(const rtc::SentPacket& sent_packet) override;
  93. void OnReceivedPacket(const ReceivedPacket& packet_msg) override;
  94. void SetSdpBitrateParameters(const BitrateConstraints& constraints) override;
  95. void SetClientBitratePreferences(const BitrateSettings& preferences) override;
  96. void OnTransportOverheadChanged(
  97. size_t transport_overhead_bytes_per_packet) override;
  98. void AccountForAudioPacketsInPacedSender(bool account_for_audio) override;
  99. void IncludeOverheadInPacedSender() override;
  100. void EnsureStarted() override;
  101. // Implements RtcpBandwidthObserver interface
  102. void OnReceivedEstimatedBitrate(uint32_t bitrate) override;
  103. void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks,
  104. int64_t rtt,
  105. int64_t now_ms) override;
  106. // Implements TransportFeedbackObserver interface
  107. void OnAddPacket(const RtpPacketSendInfo& packet_info) override;
  108. void OnTransportFeedback(const rtcp::TransportFeedback& feedback) override;
  109. // Implements NetworkStateEstimateObserver interface
  110. void OnRemoteNetworkEstimate(NetworkStateEstimate estimate) override;
  111. private:
  112. void MaybeCreateControllers() RTC_RUN_ON(task_queue_);
  113. void UpdateInitialConstraints(TargetRateConstraints new_contraints)
  114. RTC_RUN_ON(task_queue_);
  115. void StartProcessPeriodicTasks() RTC_RUN_ON(task_queue_);
  116. void UpdateControllerWithTimeInterval() RTC_RUN_ON(task_queue_);
  117. absl::optional<BitrateConstraints> ApplyOrLiftRelayCap(bool is_relayed);
  118. bool IsRelevantRouteChange(const rtc::NetworkRoute& old_route,
  119. const rtc::NetworkRoute& new_route) const;
  120. void UpdateBitrateConstraints(const BitrateConstraints& updated);
  121. void UpdateStreamsConfig() RTC_RUN_ON(task_queue_);
  122. void OnReceivedRtcpReceiverReportBlocks(const ReportBlockList& report_blocks,
  123. int64_t now_ms)
  124. RTC_RUN_ON(task_queue_);
  125. void PostUpdates(NetworkControlUpdate update) RTC_RUN_ON(task_queue_);
  126. void UpdateControlState() RTC_RUN_ON(task_queue_);
  127. RtpPacketPacer* pacer();
  128. const RtpPacketPacer* pacer() const;
  129. Clock* const clock_;
  130. RtcEventLog* const event_log_;
  131. PacketRouter packet_router_;
  132. std::vector<std::unique_ptr<RtpVideoSenderInterface>> video_rtp_senders_;
  133. RtpBitrateConfigurator bitrate_configurator_;
  134. std::map<std::string, rtc::NetworkRoute> network_routes_;
  135. bool process_thread_started_;
  136. const std::unique_ptr<ProcessThread> process_thread_;
  137. const bool use_task_queue_pacer_;
  138. std::unique_ptr<PacedSender> process_thread_pacer_;
  139. std::unique_ptr<TaskQueuePacedSender> task_queue_pacer_;
  140. TargetTransferRateObserver* observer_ RTC_GUARDED_BY(task_queue_);
  141. TransportFeedbackDemuxer feedback_demuxer_;
  142. TransportFeedbackAdapter transport_feedback_adapter_
  143. RTC_GUARDED_BY(task_queue_);
  144. NetworkControllerFactoryInterface* const controller_factory_override_
  145. RTC_PT_GUARDED_BY(task_queue_);
  146. const std::unique_ptr<NetworkControllerFactoryInterface>
  147. controller_factory_fallback_ RTC_PT_GUARDED_BY(task_queue_);
  148. std::unique_ptr<CongestionControlHandler> control_handler_
  149. RTC_GUARDED_BY(task_queue_) RTC_PT_GUARDED_BY(task_queue_);
  150. std::unique_ptr<NetworkControllerInterface> controller_
  151. RTC_GUARDED_BY(task_queue_) RTC_PT_GUARDED_BY(task_queue_);
  152. TimeDelta process_interval_ RTC_GUARDED_BY(task_queue_);
  153. std::map<uint32_t, RTCPReportBlock> last_report_blocks_
  154. RTC_GUARDED_BY(task_queue_);
  155. Timestamp last_report_block_time_ RTC_GUARDED_BY(task_queue_);
  156. NetworkControllerConfig initial_config_ RTC_GUARDED_BY(task_queue_);
  157. StreamsConfig streams_config_ RTC_GUARDED_BY(task_queue_);
  158. const bool reset_feedback_on_route_change_;
  159. const bool send_side_bwe_with_overhead_;
  160. const bool add_pacing_to_cwin_;
  161. FieldTrialParameter<DataRate> relay_bandwidth_cap_;
  162. size_t transport_overhead_bytes_per_packet_ RTC_GUARDED_BY(task_queue_);
  163. bool network_available_ RTC_GUARDED_BY(task_queue_);
  164. RepeatingTaskHandle pacer_queue_update_task_ RTC_GUARDED_BY(task_queue_);
  165. RepeatingTaskHandle controller_task_ RTC_GUARDED_BY(task_queue_);
  166. // Protected by internal locks.
  167. RateLimiter retransmission_rate_limiter_;
  168. // TODO(perkj): |task_queue_| is supposed to replace |process_thread_|.
  169. // |task_queue_| is defined last to ensure all pending tasks are cancelled
  170. // and deleted before any other members.
  171. rtc::TaskQueue task_queue_;
  172. RTC_DISALLOW_COPY_AND_ASSIGN(RtpTransportControllerSend);
  173. };
  174. } // namespace webrtc
  175. #endif // CALL_RTP_TRANSPORT_CONTROLLER_SEND_H_