nisse | b8f9a32 | 2017-03-27 05:36:15 -0700 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef CALL_RTP_TRANSPORT_CONTROLLER_SEND_H_ |
| 12 | #define CALL_RTP_TRANSPORT_CONTROLLER_SEND_H_ |
nisse | b8f9a32 | 2017-03-27 05:36:15 -0700 | [diff] [blame] | 13 | |
Sebastian Jansson | 91bb667 | 2018-02-21 13:02:51 +0100 | [diff] [blame] | 14 | #include <map> |
Sebastian Jansson | c33c0fc | 2018-02-22 11:10:18 +0100 | [diff] [blame] | 15 | #include <memory> |
Sebastian Jansson | 97f61ea | 2018-02-21 13:01:55 +0100 | [diff] [blame] | 16 | #include <string> |
| 17 | |
| 18 | #include "call/rtp_bitrate_configurator.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "call/rtp_transport_controller_send_interface.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 20 | #include "common_types.h" // NOLINT(build/include) |
Sebastian Jansson | 10211e9 | 2018-02-28 16:48:26 +0100 | [diff] [blame] | 21 | #include "modules/congestion_controller/include/send_side_congestion_controller_interface.h" |
Niels Möller | fd6c091 | 2017-10-31 10:19:10 +0100 | [diff] [blame] | 22 | #include "modules/pacing/packet_router.h" |
Sebastian Jansson | c33c0fc | 2018-02-22 11:10:18 +0100 | [diff] [blame] | 23 | #include "modules/utility/include/process_thread.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "rtc_base/constructormagic.h" |
Sebastian Jansson | 91bb667 | 2018-02-21 13:02:51 +0100 | [diff] [blame] | 25 | #include "rtc_base/networkroute.h" |
Sebastian Jansson | e625605 | 2018-05-04 14:08:15 +0200 | [diff] [blame^] | 26 | #include "rtc_base/task_queue.h" |
nisse | cae45d0 | 2017-04-24 05:53:20 -0700 | [diff] [blame] | 27 | |
nisse | b8f9a32 | 2017-03-27 05:36:15 -0700 | [diff] [blame] | 28 | namespace webrtc { |
nisse | cae45d0 | 2017-04-24 05:53:20 -0700 | [diff] [blame] | 29 | class Clock; |
| 30 | class RtcEventLog; |
nisse | b8f9a32 | 2017-03-27 05:36:15 -0700 | [diff] [blame] | 31 | |
nisse | cae45d0 | 2017-04-24 05:53:20 -0700 | [diff] [blame] | 32 | // TODO(nisse): When we get the underlying transports here, we should |
| 33 | // have one object implementing RtpTransportControllerSendInterface |
| 34 | // per transport, sharing the same congestion controller. |
Sebastian Jansson | 317a522 | 2018-03-16 15:36:37 +0100 | [diff] [blame] | 35 | class RtpTransportControllerSend final |
| 36 | : public RtpTransportControllerSendInterface, |
| 37 | public NetworkChangedObserver { |
nisse | b8f9a32 | 2017-03-27 05:36:15 -0700 | [diff] [blame] | 38 | public: |
Sebastian Jansson | 97f61ea | 2018-02-21 13:01:55 +0100 | [diff] [blame] | 39 | RtpTransportControllerSend(Clock* clock, |
| 40 | RtcEventLog* event_log, |
| 41 | const BitrateConstraints& bitrate_config); |
| 42 | ~RtpTransportControllerSend() override; |
Sebastian Jansson | 19704ec | 2018-03-12 15:59:12 +0100 | [diff] [blame] | 43 | |
| 44 | // Implements NetworkChangedObserver interface. |
| 45 | void OnNetworkChanged(uint32_t bitrate_bps, |
| 46 | uint8_t fraction_loss, |
| 47 | int64_t rtt_ms, |
| 48 | int64_t probing_interval_ms) override; |
| 49 | |
nisse | cae45d0 | 2017-04-24 05:53:20 -0700 | [diff] [blame] | 50 | // Implements RtpTransportControllerSendInterface |
Sebastian Jansson | e625605 | 2018-05-04 14:08:15 +0200 | [diff] [blame^] | 51 | rtc::TaskQueue* GetWorkerQueue() override; |
nisse | 76e62b0 | 2017-05-31 02:24:52 -0700 | [diff] [blame] | 52 | PacketRouter* packet_router() override; |
Sebastian Jansson | 4c1ffb8 | 2018-02-15 16:51:58 +0100 | [diff] [blame] | 53 | |
nisse | 76e62b0 | 2017-05-31 02:24:52 -0700 | [diff] [blame] | 54 | TransportFeedbackObserver* transport_feedback_observer() override; |
| 55 | RtpPacketSender* packet_sender() override; |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 56 | const RtpKeepAliveConfig& keepalive_config() const override; |
| 57 | |
Stefan Holmer | 5c8942a | 2017-08-22 16:16:44 +0200 | [diff] [blame] | 58 | void SetAllocatedSendBitrateLimits(int min_send_bitrate_bps, |
philipel | 832b1c8 | 2018-02-28 17:04:18 +0100 | [diff] [blame] | 59 | int max_padding_bitrate_bps, |
philipel | db4fa4b | 2018-03-06 18:29:22 +0100 | [diff] [blame] | 60 | int max_total_bitrate_bps) override; |
Stefan Holmer | 5c8942a | 2017-08-22 16:16:44 +0200 | [diff] [blame] | 61 | |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 62 | void SetKeepAliveConfig(const RtpKeepAliveConfig& config); |
Sebastian Jansson | 4c1ffb8 | 2018-02-15 16:51:58 +0100 | [diff] [blame] | 63 | void SetPacingFactor(float pacing_factor) override; |
| 64 | void SetQueueTimeLimit(int limit_ms) override; |
Sebastian Jansson | e4be6da | 2018-02-15 16:51:41 +0100 | [diff] [blame] | 65 | CallStatsObserver* GetCallStatsObserver() override; |
| 66 | void RegisterPacketFeedbackObserver( |
| 67 | PacketFeedbackObserver* observer) override; |
| 68 | void DeRegisterPacketFeedbackObserver( |
| 69 | PacketFeedbackObserver* observer) override; |
Sebastian Jansson | 19704ec | 2018-03-12 15:59:12 +0100 | [diff] [blame] | 70 | void RegisterTargetTransferRateObserver( |
| 71 | TargetTransferRateObserver* observer) override; |
Sebastian Jansson | 97f61ea | 2018-02-21 13:01:55 +0100 | [diff] [blame] | 72 | void OnNetworkRouteChanged(const std::string& transport_name, |
| 73 | const rtc::NetworkRoute& network_route) override; |
Sebastian Jansson | e4be6da | 2018-02-15 16:51:41 +0100 | [diff] [blame] | 74 | void OnNetworkAvailability(bool network_available) override; |
Sebastian Jansson | e4be6da | 2018-02-15 16:51:41 +0100 | [diff] [blame] | 75 | RtcpBandwidthObserver* GetBandwidthObserver() override; |
Sebastian Jansson | e4be6da | 2018-02-15 16:51:41 +0100 | [diff] [blame] | 76 | int64_t GetPacerQueuingDelayMs() const override; |
| 77 | int64_t GetFirstPacketTimeMs() const override; |
Sebastian Jansson | 12130bb | 2018-03-21 12:48:43 +0100 | [diff] [blame] | 78 | void SetPerPacketFeedbackAvailable(bool available) override; |
Sebastian Jansson | e4be6da | 2018-02-15 16:51:41 +0100 | [diff] [blame] | 79 | void EnablePeriodicAlrProbing(bool enable) override; |
| 80 | void OnSentPacket(const rtc::SentPacket& sent_packet) override; |
nisse | cae45d0 | 2017-04-24 05:53:20 -0700 | [diff] [blame] | 81 | |
Sebastian Jansson | 97f61ea | 2018-02-21 13:01:55 +0100 | [diff] [blame] | 82 | void SetSdpBitrateParameters(const BitrateConstraints& constraints) override; |
| 83 | void SetClientBitratePreferences( |
| 84 | const BitrateConstraintsMask& preferences) override; |
| 85 | |
nisse | cae45d0 | 2017-04-24 05:53:20 -0700 | [diff] [blame] | 86 | private: |
Sebastian Jansson | 19704ec | 2018-03-12 15:59:12 +0100 | [diff] [blame] | 87 | const Clock* const clock_; |
nisse | cae45d0 | 2017-04-24 05:53:20 -0700 | [diff] [blame] | 88 | PacketRouter packet_router_; |
Stefan Holmer | 5c8942a | 2017-08-22 16:16:44 +0200 | [diff] [blame] | 89 | PacedSender pacer_; |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 90 | RtpKeepAliveConfig keepalive_; |
Sebastian Jansson | 97f61ea | 2018-02-21 13:01:55 +0100 | [diff] [blame] | 91 | RtpBitrateConfigurator bitrate_configurator_; |
Sebastian Jansson | 91bb667 | 2018-02-21 13:02:51 +0100 | [diff] [blame] | 92 | std::map<std::string, rtc::NetworkRoute> network_routes_; |
Sebastian Jansson | c33c0fc | 2018-02-22 11:10:18 +0100 | [diff] [blame] | 93 | const std::unique_ptr<ProcessThread> process_thread_; |
Sebastian Jansson | 19704ec | 2018-03-12 15:59:12 +0100 | [diff] [blame] | 94 | rtc::CriticalSection observer_crit_; |
| 95 | TargetTransferRateObserver* observer_ RTC_GUARDED_BY(observer_crit_); |
Sebastian Jansson | 947120f | 2018-03-26 14:56:37 +0200 | [diff] [blame] | 96 | // Caches send_side_cc_.get(), to avoid racing with destructor. |
| 97 | // Note that this is declared before send_side_cc_ to ensure that it is not |
| 98 | // invalidated until no more tasks can be running on the send_side_cc_ task |
| 99 | // queue. |
| 100 | // TODO(srte): Remove this when only the task queue based send side congestion |
| 101 | // controller is used and it is no longer accessed synchronously in the |
| 102 | // OnNetworkChanged callback. |
| 103 | SendSideCongestionControllerInterface* send_side_cc_ptr_; |
Sebastian Jansson | 317a522 | 2018-03-16 15:36:37 +0100 | [diff] [blame] | 104 | // Declared last since it will issue callbacks from a task queue. Declaring it |
| 105 | // last ensures that it is destroyed first. |
| 106 | const std::unique_ptr<SendSideCongestionControllerInterface> send_side_cc_; |
Sebastian Jansson | e625605 | 2018-05-04 14:08:15 +0200 | [diff] [blame^] | 107 | // TODO(perkj): |task_queue_| is supposed to replace |process_thread_|. |
| 108 | // |task_queue_| is defined last to ensure all pending tasks are cancelled |
| 109 | // and deleted before any other members. |
| 110 | rtc::TaskQueue task_queue_; |
nisse | cae45d0 | 2017-04-24 05:53:20 -0700 | [diff] [blame] | 111 | RTC_DISALLOW_COPY_AND_ASSIGN(RtpTransportControllerSend); |
nisse | b8f9a32 | 2017-03-27 05:36:15 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | } // namespace webrtc |
| 115 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 116 | #endif // CALL_RTP_TRANSPORT_CONTROLLER_SEND_H_ |