pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 | |
pbos@webrtc.org | 12dc1a3 | 2013-08-05 16:22:53 | [diff] [blame] | 11 | #include <string.h> |
mflodman | 101f250 | 2016-06-09 15:21:19 | [diff] [blame] | 12 | #include <algorithm> |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 13 | #include <map> |
kwiberg | b25345e | 2016-03-12 14:10:44 | [diff] [blame] | 14 | #include <memory> |
ossu | f515ab8 | 2016-12-07 12:52:58 | [diff] [blame] | 15 | #include <set> |
brandtr | 25445d3 | 2016-10-24 06:37:14 | [diff] [blame] | 16 | #include <utility> |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 17 | #include <vector> |
| 18 | |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 19 | #include "absl/memory/memory.h" |
Danil Chapovalov | b9b146c | 2018-06-15 10:28:07 | [diff] [blame] | 20 | #include "absl/types/optional.h" |
Sebastian Jansson | 74682c1 | 2019-03-01 10:50:20 | [diff] [blame] | 21 | #include "api/task_queue/global_task_queue_factory.h" |
Sebastian Jansson | c6c4426 | 2018-05-09 08:33:39 | [diff] [blame] | 22 | #include "api/transport/network_control.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 23 | #include "audio/audio_receive_stream.h" |
| 24 | #include "audio/audio_send_stream.h" |
| 25 | #include "audio/audio_state.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 26 | #include "call/bitrate_allocator.h" |
| 27 | #include "call/call.h" |
| 28 | #include "call/flexfec_receive_stream_impl.h" |
Sebastian Jansson | b34556e | 2018-03-21 13:38:32 | [diff] [blame] | 29 | #include "call/receive_time_calculator.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 30 | #include "call/rtp_stream_receiver_controller.h" |
| 31 | #include "call/rtp_transport_controller_send.h" |
Elad Alon | 4a87e1c | 2017-10-03 14:11:34 | [diff] [blame] | 32 | #include "logging/rtc_event_log/events/rtc_event_audio_receive_stream_config.h" |
Elad Alon | 4a87e1c | 2017-10-03 14:11:34 | [diff] [blame] | 33 | #include "logging/rtc_event_log/events/rtc_event_rtcp_packet_incoming.h" |
| 34 | #include "logging/rtc_event_log/events/rtc_event_rtp_packet_incoming.h" |
| 35 | #include "logging/rtc_event_log/events/rtc_event_video_receive_stream_config.h" |
| 36 | #include "logging/rtc_event_log/events/rtc_event_video_send_stream_config.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 37 | #include "logging/rtc_event_log/rtc_event_log.h" |
Elad Alon | 99a81b6 | 2017-09-21 08:25:29 | [diff] [blame] | 38 | #include "logging/rtc_event_log/rtc_stream_config.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 39 | #include "modules/bitrate_controller/include/bitrate_controller.h" |
| 40 | #include "modules/congestion_controller/include/receive_side_congestion_controller.h" |
| 41 | #include "modules/rtp_rtcp/include/flexfec_receiver.h" |
| 42 | #include "modules/rtp_rtcp/include/rtp_header_extension_map.h" |
| 43 | #include "modules/rtp_rtcp/include/rtp_header_parser.h" |
| 44 | #include "modules/rtp_rtcp/source/byte_io.h" |
| 45 | #include "modules/rtp_rtcp/source/rtp_packet_received.h" |
| 46 | #include "modules/utility/include/process_thread.h" |
Ying Wang | 3b790f3 | 2018-01-19 16:58:57 | [diff] [blame] | 47 | #include "modules/video_coding/fec_controller_default.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 48 | #include "rtc_base/checks.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 49 | #include "rtc_base/constructor_magic.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 50 | #include "rtc_base/location.h" |
| 51 | #include "rtc_base/logging.h" |
Sebastian Jansson | 19704ec | 2018-03-12 14:59:12 | [diff] [blame] | 52 | #include "rtc_base/numerics/safe_minmax.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 53 | #include "rtc_base/sequenced_task_checker.h" |
Jonas Olsson | 0a713b6 | 2018-04-04 13:49:32 | [diff] [blame] | 54 | #include "rtc_base/strings/string_builder.h" |
Sebastian Jansson | c6c4426 | 2018-05-09 08:33:39 | [diff] [blame] | 55 | #include "rtc_base/synchronization/rw_lock_wrapper.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 56 | #include "rtc_base/thread_annotations.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 57 | #include "rtc_base/time_utils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 58 | #include "rtc_base/trace_event.h" |
| 59 | #include "system_wrappers/include/clock.h" |
| 60 | #include "system_wrappers/include/cpu_info.h" |
Jonas Oreland | 6d83592 | 2019-03-18 09:59:40 | [diff] [blame] | 61 | #include "system_wrappers/include/field_trial.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 62 | #include "system_wrappers/include/metrics.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 63 | #include "video/call_stats.h" |
| 64 | #include "video/send_delay_stats.h" |
| 65 | #include "video/stats_counter.h" |
| 66 | #include "video/video_receive_stream.h" |
| 67 | #include "video/video_send_stream.h" |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 68 | |
| 69 | namespace webrtc { |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 | [diff] [blame] | 70 | |
nisse | 4709e89 | 2017-02-07 09:18:43 | [diff] [blame] | 71 | namespace { |
Johannes Kron | f59666b | 2019-04-08 10:57:06 | [diff] [blame^] | 72 | bool SendPeriodicFeedback(const std::vector<RtpExtension>& extensions) { |
Johannes Kron | 7ff164e | 2019-02-07 11:50:18 | [diff] [blame] | 73 | for (const auto& extension : extensions) { |
| 74 | if (extension.uri == RtpExtension::kTransportSequenceNumberV2Uri) |
Johannes Kron | f59666b | 2019-04-08 10:57:06 | [diff] [blame^] | 75 | return false; |
Johannes Kron | 7ff164e | 2019-02-07 11:50:18 | [diff] [blame] | 76 | } |
Johannes Kron | f59666b | 2019-04-08 10:57:06 | [diff] [blame^] | 77 | return true; |
Johannes Kron | 7ff164e | 2019-02-07 11:50:18 | [diff] [blame] | 78 | } |
| 79 | |
nisse | 4709e89 | 2017-02-07 09:18:43 | [diff] [blame] | 80 | // TODO(nisse): This really begs for a shared context struct. |
| 81 | bool UseSendSideBwe(const std::vector<RtpExtension>& extensions, |
| 82 | bool transport_cc) { |
| 83 | if (!transport_cc) |
| 84 | return false; |
| 85 | for (const auto& extension : extensions) { |
Johannes Kron | 7ff164e | 2019-02-07 11:50:18 | [diff] [blame] | 86 | if (extension.uri == RtpExtension::kTransportSequenceNumberUri || |
| 87 | extension.uri == RtpExtension::kTransportSequenceNumberV2Uri) |
nisse | 4709e89 | 2017-02-07 09:18:43 | [diff] [blame] | 88 | return true; |
| 89 | } |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | bool UseSendSideBwe(const VideoReceiveStream::Config& config) { |
| 94 | return UseSendSideBwe(config.rtp.extensions, config.rtp.transport_cc); |
| 95 | } |
| 96 | |
| 97 | bool UseSendSideBwe(const AudioReceiveStream::Config& config) { |
| 98 | return UseSendSideBwe(config.rtp.extensions, config.rtp.transport_cc); |
| 99 | } |
| 100 | |
| 101 | bool UseSendSideBwe(const FlexfecReceiveStream::Config& config) { |
| 102 | return UseSendSideBwe(config.rtp_header_extensions, config.transport_cc); |
| 103 | } |
| 104 | |
nisse | 26e3abb | 2017-08-25 11:44:25 | [diff] [blame] | 105 | const int* FindKeyByValue(const std::map<int, int>& m, int v) { |
| 106 | for (const auto& kv : m) { |
| 107 | if (kv.second == v) |
| 108 | return &kv.first; |
| 109 | } |
| 110 | return nullptr; |
| 111 | } |
| 112 | |
eladalon | 8ec568a | 2017-09-08 13:15:52 | [diff] [blame] | 113 | std::unique_ptr<rtclog::StreamConfig> CreateRtcLogStreamConfig( |
perkj | 09e71da | 2017-05-22 10:26:49 | [diff] [blame] | 114 | const VideoReceiveStream::Config& config) { |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 115 | auto rtclog_config = absl::make_unique<rtclog::StreamConfig>(); |
eladalon | 8ec568a | 2017-09-08 13:15:52 | [diff] [blame] | 116 | rtclog_config->remote_ssrc = config.rtp.remote_ssrc; |
| 117 | rtclog_config->local_ssrc = config.rtp.local_ssrc; |
| 118 | rtclog_config->rtx_ssrc = config.rtp.rtx_ssrc; |
| 119 | rtclog_config->rtcp_mode = config.rtp.rtcp_mode; |
| 120 | rtclog_config->remb = config.rtp.remb; |
| 121 | rtclog_config->rtp_extensions = config.rtp.extensions; |
perkj | 09e71da | 2017-05-22 10:26:49 | [diff] [blame] | 122 | |
| 123 | for (const auto& d : config.decoders) { |
nisse | 26e3abb | 2017-08-25 11:44:25 | [diff] [blame] | 124 | const int* search = |
| 125 | FindKeyByValue(config.rtp.rtx_associated_payload_types, d.payload_type); |
Niels Möller | cb7e1d2 | 2018-09-11 13:56:04 | [diff] [blame] | 126 | rtclog_config->codecs.emplace_back(d.video_format.name, d.payload_type, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 127 | search ? *search : 0); |
perkj | 09e71da | 2017-05-22 10:26:49 | [diff] [blame] | 128 | } |
| 129 | return rtclog_config; |
| 130 | } |
| 131 | |
eladalon | 8ec568a | 2017-09-08 13:15:52 | [diff] [blame] | 132 | std::unique_ptr<rtclog::StreamConfig> CreateRtcLogStreamConfig( |
perkj | c0876aa | 2017-05-22 11:08:28 | [diff] [blame] | 133 | const VideoSendStream::Config& config, |
| 134 | size_t ssrc_index) { |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 135 | auto rtclog_config = absl::make_unique<rtclog::StreamConfig>(); |
eladalon | 8ec568a | 2017-09-08 13:15:52 | [diff] [blame] | 136 | rtclog_config->local_ssrc = config.rtp.ssrcs[ssrc_index]; |
perkj | c0876aa | 2017-05-22 11:08:28 | [diff] [blame] | 137 | if (ssrc_index < config.rtp.rtx.ssrcs.size()) { |
eladalon | 8ec568a | 2017-09-08 13:15:52 | [diff] [blame] | 138 | rtclog_config->rtx_ssrc = config.rtp.rtx.ssrcs[ssrc_index]; |
perkj | c0876aa | 2017-05-22 11:08:28 | [diff] [blame] | 139 | } |
eladalon | 8ec568a | 2017-09-08 13:15:52 | [diff] [blame] | 140 | rtclog_config->rtcp_mode = config.rtp.rtcp_mode; |
| 141 | rtclog_config->rtp_extensions = config.rtp.extensions; |
perkj | c0876aa | 2017-05-22 11:08:28 | [diff] [blame] | 142 | |
Niels Möller | 259a497 | 2018-04-05 13:36:51 | [diff] [blame] | 143 | rtclog_config->codecs.emplace_back(config.rtp.payload_name, |
| 144 | config.rtp.payload_type, |
eladalon | 8ec568a | 2017-09-08 13:15:52 | [diff] [blame] | 145 | config.rtp.rtx.payload_type); |
perkj | c0876aa | 2017-05-22 11:08:28 | [diff] [blame] | 146 | return rtclog_config; |
| 147 | } |
| 148 | |
eladalon | 8ec568a | 2017-09-08 13:15:52 | [diff] [blame] | 149 | std::unique_ptr<rtclog::StreamConfig> CreateRtcLogStreamConfig( |
perkj | ac8f52d | 2017-05-22 16:36:28 | [diff] [blame] | 150 | const AudioReceiveStream::Config& config) { |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 151 | auto rtclog_config = absl::make_unique<rtclog::StreamConfig>(); |
eladalon | 8ec568a | 2017-09-08 13:15:52 | [diff] [blame] | 152 | rtclog_config->remote_ssrc = config.rtp.remote_ssrc; |
| 153 | rtclog_config->local_ssrc = config.rtp.local_ssrc; |
| 154 | rtclog_config->rtp_extensions = config.rtp.extensions; |
perkj | ac8f52d | 2017-05-22 16:36:28 | [diff] [blame] | 155 | return rtclog_config; |
| 156 | } |
| 157 | |
nisse | 4709e89 | 2017-02-07 09:18:43 | [diff] [blame] | 158 | } // namespace |
| 159 | |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 160 | namespace internal { |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 | [diff] [blame] | 161 | |
Sebastian Jansson | e625605 | 2018-05-04 12:08:15 | [diff] [blame] | 162 | class Call final : public webrtc::Call, |
| 163 | public PacketReceiver, |
| 164 | public RecoveredPacketReceiver, |
| 165 | public TargetTransferRateObserver, |
| 166 | public BitrateAllocator::LimitObserver { |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 167 | public: |
Sebastian Jansson | 4e5f5ed | 2019-03-01 17:13:27 | [diff] [blame] | 168 | Call(Clock* clock, |
| 169 | const Call::Config& config, |
Sebastian Jansson | 896b47c | 2019-03-01 17:48:16 | [diff] [blame] | 170 | std::unique_ptr<RtpTransportControllerSendInterface> transport_send, |
| 171 | std::unique_ptr<ProcessThread> module_process_thread, |
| 172 | TaskQueueFactory* task_queue_factory); |
Mirko Bonadei | 8fdcac3 | 2018-08-28 14:30:18 | [diff] [blame] | 173 | ~Call() override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 174 | |
brandtr | 25445d3 | 2016-10-24 06:37:14 | [diff] [blame] | 175 | // Implements webrtc::Call. |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 176 | PacketReceiver* Receiver() override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 177 | |
Fredrik Solenberg | 04f4931 | 2015-06-08 11:04:56 | [diff] [blame] | 178 | webrtc::AudioSendStream* CreateAudioSendStream( |
| 179 | const webrtc::AudioSendStream::Config& config) override; |
| 180 | void DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) override; |
| 181 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 182 | webrtc::AudioReceiveStream* CreateAudioReceiveStream( |
| 183 | const webrtc::AudioReceiveStream::Config& config) override; |
| 184 | void DestroyAudioReceiveStream( |
| 185 | webrtc::AudioReceiveStream* receive_stream) override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 186 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 187 | webrtc::VideoSendStream* CreateVideoSendStream( |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 188 | webrtc::VideoSendStream::Config config, |
| 189 | VideoEncoderConfig encoder_config) override; |
Ying Wang | 3b790f3 | 2018-01-19 16:58:57 | [diff] [blame] | 190 | webrtc::VideoSendStream* CreateVideoSendStream( |
| 191 | webrtc::VideoSendStream::Config config, |
| 192 | VideoEncoderConfig encoder_config, |
| 193 | std::unique_ptr<FecController> fec_controller) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 194 | void DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 195 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 196 | webrtc::VideoReceiveStream* CreateVideoReceiveStream( |
Tommi | 733b547 | 2016-06-10 15:58:01 | [diff] [blame] | 197 | webrtc::VideoReceiveStream::Config configuration) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 198 | void DestroyVideoReceiveStream( |
| 199 | webrtc::VideoReceiveStream* receive_stream) override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 200 | |
brandtr | 7250b39 | 2016-12-19 09:13:46 | [diff] [blame] | 201 | FlexfecReceiveStream* CreateFlexfecReceiveStream( |
| 202 | const FlexfecReceiveStream::Config& config) override; |
brandtr | 25445d3 | 2016-10-24 06:37:14 | [diff] [blame] | 203 | void DestroyFlexfecReceiveStream( |
brandtr | 7250b39 | 2016-12-19 09:13:46 | [diff] [blame] | 204 | FlexfecReceiveStream* receive_stream) override; |
brandtr | 25445d3 | 2016-10-24 06:37:14 | [diff] [blame] | 205 | |
Sebastian Jansson | 8f83b42 | 2018-02-21 12:07:13 | [diff] [blame] | 206 | RtpTransportControllerSendInterface* GetTransportControllerSend() override; |
| 207 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 | [diff] [blame] | 208 | Stats GetStats() const override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 209 | |
brandtr | 25445d3 | 2016-10-24 06:37:14 | [diff] [blame] | 210 | // Implements PacketReceiver. |
stefan | 68786d2 | 2015-09-08 12:36:15 | [diff] [blame] | 211 | DeliveryStatus DeliverPacket(MediaType media_type, |
Danil Chapovalov | 292a73e | 2017-12-07 16:00:40 | [diff] [blame] | 212 | rtc::CopyOnWriteBuffer packet, |
Niels Möller | 7008287 | 2018-08-07 09:03:12 | [diff] [blame] | 213 | int64_t packet_time_us) override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 214 | |
brandtr | 4e52386 | 2016-10-19 06:50:45 | [diff] [blame] | 215 | // Implements RecoveredPacketReceiver. |
nisse | d2ef314 | 2017-05-11 15:00:58 | [diff] [blame] | 216 | void OnRecoveredPacket(const uint8_t* packet, size_t length) override; |
brandtr | 4e52386 | 2016-10-19 06:50:45 | [diff] [blame] | 217 | |
Alex Narest | 78609d5 | 2017-10-20 08:37:47 | [diff] [blame] | 218 | void SetBitrateAllocationStrategy( |
| 219 | std::unique_ptr<rtc::BitrateAllocationStrategy> |
| 220 | bitrate_allocation_strategy) override; |
| 221 | |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 222 | void SignalChannelNetworkState(MediaType media, NetworkState state) override; |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 223 | |
Stefan Holmer | 64be7fa | 2018-10-04 13:21:55 | [diff] [blame] | 224 | void OnAudioTransportOverheadChanged( |
| 225 | int transport_overhead_per_packet) override; |
michaelt | 79e0588 | 2016-11-08 10:50:09 | [diff] [blame] | 226 | |
stefan | c1aeaf0 | 2015-10-15 14:26:07 | [diff] [blame] | 227 | void OnSentPacket(const rtc::SentPacket& sent_packet) override; |
| 228 | |
Sebastian Jansson | 19704ec | 2018-03-12 14:59:12 | [diff] [blame] | 229 | // Implements TargetTransferRateObserver, |
| 230 | void OnTargetTransferRate(TargetTransferRate msg) override; |
Sebastian Jansson | 2701bc9 | 2018-12-11 14:02:47 | [diff] [blame] | 231 | void OnStartRateUpdate(DataRate start_rate) override; |
mflodman | 0e7e259 | 2015-11-13 05:02:42 | [diff] [blame] | 232 | |
perkj | 71ee44c | 2016-06-15 07:47:53 | [diff] [blame] | 233 | // Implements BitrateAllocator::LimitObserver. |
| 234 | void OnAllocationLimitsChanged(uint32_t min_send_bitrate_bps, |
philipel | f69e768 | 2018-02-28 12:06:28 | [diff] [blame] | 235 | uint32_t max_padding_bitrate_bps, |
Sebastian Jansson | 79f0d4d | 2019-01-23 08:41:43 | [diff] [blame] | 236 | uint32_t total_bitrate_bps) override; |
perkj | 71ee44c | 2016-06-15 07:47:53 | [diff] [blame] | 237 | |
Piotr (Peter) Slatala | cc8e8bb | 2018-11-15 16:26:19 | [diff] [blame] | 238 | // This method is invoked when the media transport is created and when the |
| 239 | // media transport is being destructed. |
| 240 | // We only allow one media transport per connection. |
| 241 | // |
| 242 | // It should be called with non-null argument at most once, and if it was |
| 243 | // called with non-null argument, it has to be called with a null argument |
| 244 | // at least once after that. |
| 245 | void MediaTransportChange(MediaTransportInterface* media_transport) override; |
| 246 | |
Piotr (Peter) Slatala | 7fbfaa4 | 2019-03-18 17:31:54 | [diff] [blame] | 247 | void SetClientBitratePreferences(const BitrateSettings& preferences) override; |
| 248 | |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 249 | private: |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 250 | DeliveryStatus DeliverRtcp(MediaType media_type, |
| 251 | const uint8_t* packet, |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 252 | size_t length); |
stefan | 68786d2 | 2015-09-08 12:36:15 | [diff] [blame] | 253 | DeliveryStatus DeliverRtp(MediaType media_type, |
Danil Chapovalov | 292a73e | 2017-12-07 16:00:40 | [diff] [blame] | 254 | rtc::CopyOnWriteBuffer packet, |
Niels Möller | 7008287 | 2018-08-07 09:03:12 | [diff] [blame] | 255 | int64_t packet_time_us); |
pbos | 8fc7fa7 | 2015-07-15 15:02:58 | [diff] [blame] | 256 | void ConfigureSync(const std::string& sync_group) |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 257 | RTC_EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); |
pbos | 8fc7fa7 | 2015-07-15 15:02:58 | [diff] [blame] | 258 | |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 259 | void NotifyBweOfReceivedPacket(const RtpPacketReceived& packet, |
| 260 | MediaType media_type) |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 261 | RTC_SHARED_LOCKS_REQUIRED(receive_crit_); |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 262 | |
asapersson | fc5e81c | 2017-04-20 06:28:53 | [diff] [blame] | 263 | void UpdateSendHistograms(int64_t first_sent_packet_ms) |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 264 | RTC_EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_); |
stefan | 18adf0a | 2015-11-17 14:24:56 | [diff] [blame] | 265 | void UpdateReceiveHistograms(); |
asapersson | 4374a09 | 2016-07-27 07:39:09 | [diff] [blame] | 266 | void UpdateHistograms(); |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 267 | void UpdateAggregateNetworkState(); |
stefan | 91d9260 | 2015-11-11 18:13:02 | [diff] [blame] | 268 | |
Piotr (Peter) Slatala | cc8e8bb | 2018-11-15 16:26:19 | [diff] [blame] | 269 | // If |media_transport| is not null, it registers the rate observer for the |
| 270 | // media transport. |
| 271 | void RegisterRateObserver() RTC_LOCKS_EXCLUDED(target_observer_crit_); |
| 272 | |
Niels Möller | 4687915 | 2019-01-07 14:54:47 | [diff] [blame] | 273 | // Intended for DCHECKs, to avoid locking in production builds. |
| 274 | MediaTransportInterface* media_transport() |
| 275 | RTC_LOCKS_EXCLUDED(target_observer_crit_); |
| 276 | |
Peter Boström | d3c9447 | 2015-12-09 10:20:58 | [diff] [blame] | 277 | Clock* const clock_; |
Sebastian Jansson | 896b47c | 2019-03-01 17:48:16 | [diff] [blame] | 278 | TaskQueueFactory* const task_queue_factory_; |
stefan | 91d9260 | 2015-11-11 18:13:02 | [diff] [blame] | 279 | |
Piotr (Peter) Slatala | 7fbfaa4 | 2019-03-18 17:31:54 | [diff] [blame] | 280 | // Caching the last SetBitrate for media transport. |
| 281 | absl::optional<MediaTransportTargetRateConstraints> last_set_bitrate_ |
| 282 | RTC_GUARDED_BY(&target_observer_crit_); |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame] | 283 | const int num_cpu_cores_; |
kwiberg | b25345e | 2016-03-12 14:10:44 | [diff] [blame] | 284 | const std::unique_ptr<ProcessThread> module_process_thread_; |
kwiberg | b25345e | 2016-03-12 14:10:44 | [diff] [blame] | 285 | const std::unique_ptr<CallStats> call_stats_; |
| 286 | const std::unique_ptr<BitrateAllocator> bitrate_allocator_; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 287 | Call::Config config_; |
eladalon | f3f5c0e | 2017-08-18 09:47:08 | [diff] [blame] | 288 | rtc::SequencedTaskChecker configuration_sequence_checker_; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 289 | |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 290 | NetworkState audio_network_state_; |
| 291 | NetworkState video_network_state_; |
Sebastian Jansson | a06e919 | 2018-03-07 17:49:55 | [diff] [blame] | 292 | rtc::CriticalSection aggregate_network_up_crit_; |
| 293 | bool aggregate_network_up_ RTC_GUARDED_BY(aggregate_network_up_crit_); |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 294 | |
kwiberg | b25345e | 2016-03-12 14:10:44 | [diff] [blame] | 295 | std::unique_ptr<RWLockWrapper> receive_crit_; |
brandtr | 25445d3 | 2016-10-24 06:37:14 | [diff] [blame] | 296 | // Audio, Video, and FlexFEC receive streams are owned by the client that |
| 297 | // creates them. |
nisse | e4bcd6d | 2017-05-16 11:47:04 | [diff] [blame] | 298 | std::set<AudioReceiveStream*> audio_receive_streams_ |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 299 | RTC_GUARDED_BY(receive_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 300 | std::set<VideoReceiveStream*> video_receive_streams_ |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 301 | RTC_GUARDED_BY(receive_crit_); |
nisse | e4bcd6d | 2017-05-16 11:47:04 | [diff] [blame] | 302 | |
pbos | 8fc7fa7 | 2015-07-15 15:02:58 | [diff] [blame] | 303 | std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 304 | RTC_GUARDED_BY(receive_crit_); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 305 | |
nisse | 0f15f92 | 2017-06-21 08:05:22 | [diff] [blame] | 306 | // TODO(nisse): Should eventually be injected at creation, |
| 307 | // with a single object in the bundled case. |
eladalon | 2a2b297 | 2017-07-03 16:25:27 | [diff] [blame] | 308 | RtpStreamReceiverController audio_receiver_controller_; |
| 309 | RtpStreamReceiverController video_receiver_controller_; |
nisse | e4bcd6d | 2017-05-16 11:47:04 | [diff] [blame] | 310 | |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 311 | // This extra map is used for receive processing which is |
| 312 | // independent of media type. |
| 313 | |
| 314 | // TODO(nisse): In the RTP transport refactoring, we should have a |
| 315 | // single mapping from ssrc to a more abstract receive stream, with |
| 316 | // accessor methods for all configuration we need at this level. |
| 317 | struct ReceiveRtpConfig { |
Erik Språng | 0970851 | 2018-03-14 14:16:50 | [diff] [blame] | 318 | explicit ReceiveRtpConfig(const webrtc::AudioReceiveStream::Config& config) |
| 319 | : extensions(config.rtp.extensions), |
| 320 | use_send_side_bwe(UseSendSideBwe(config)) {} |
| 321 | explicit ReceiveRtpConfig(const webrtc::VideoReceiveStream::Config& config) |
| 322 | : extensions(config.rtp.extensions), |
| 323 | use_send_side_bwe(UseSendSideBwe(config)) {} |
| 324 | explicit ReceiveRtpConfig(const FlexfecReceiveStream::Config& config) |
| 325 | : extensions(config.rtp_header_extensions), |
| 326 | use_send_side_bwe(UseSendSideBwe(config)) {} |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 327 | |
| 328 | // Registered RTP header extensions for each stream. Note that RTP header |
| 329 | // extensions are negotiated per track ("m= line") in the SDP, but we have |
| 330 | // no notion of tracks at the Call level. We therefore store the RTP header |
| 331 | // extensions per SSRC instead, which leads to some storage overhead. |
Erik Språng | 0970851 | 2018-03-14 14:16:50 | [diff] [blame] | 332 | const RtpHeaderExtensionMap extensions; |
nisse | 4709e89 | 2017-02-07 09:18:43 | [diff] [blame] | 333 | // Set if both RTP extension the RTCP feedback message needed for |
| 334 | // send side BWE are negotiated. |
Erik Språng | 0970851 | 2018-03-14 14:16:50 | [diff] [blame] | 335 | const bool use_send_side_bwe; |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 336 | }; |
| 337 | std::map<uint32_t, ReceiveRtpConfig> receive_rtp_config_ |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 338 | RTC_GUARDED_BY(receive_crit_); |
brandtr | b29e652 | 2016-12-21 14:37:18 | [diff] [blame] | 339 | |
kwiberg | b25345e | 2016-03-12 14:10:44 | [diff] [blame] | 340 | std::unique_ptr<RWLockWrapper> send_crit_; |
solenberg | c7a8b08 | 2015-10-16 21:35:07 | [diff] [blame] | 341 | // Audio and Video send streams are owned by the client that creates them. |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 342 | std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ |
| 343 | RTC_GUARDED_BY(send_crit_); |
| 344 | std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ |
| 345 | RTC_GUARDED_BY(send_crit_); |
| 346 | std::set<VideoSendStream*> video_send_streams_ RTC_GUARDED_BY(send_crit_); |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 347 | |
ossu | c3d4b48 | 2017-05-23 13:07:11 | [diff] [blame] | 348 | using RtpStateMap = std::map<uint32_t, RtpState>; |
| 349 | RtpStateMap suspended_audio_send_ssrcs_ |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 350 | RTC_GUARDED_BY(configuration_sequence_checker_); |
ossu | c3d4b48 | 2017-05-23 13:07:11 | [diff] [blame] | 351 | RtpStateMap suspended_video_send_ssrcs_ |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 352 | RTC_GUARDED_BY(configuration_sequence_checker_); |
ossu | c3d4b48 | 2017-05-23 13:07:11 | [diff] [blame] | 353 | |
Åsa Persson | 4bece9a | 2017-10-06 08:04:04 | [diff] [blame] | 354 | using RtpPayloadStateMap = std::map<uint32_t, RtpPayloadState>; |
| 355 | RtpPayloadStateMap suspended_video_payload_states_ |
| 356 | RTC_GUARDED_BY(configuration_sequence_checker_); |
| 357 | |
skvlad | 11a9cbf | 2016-10-07 18:53:05 | [diff] [blame] | 358 | webrtc::RtcEventLog* event_log_; |
ivoc | b04965c | 2015-09-09 07:09:43 | [diff] [blame] | 359 | |
stefan | 18adf0a | 2015-11-17 14:24:56 | [diff] [blame] | 360 | // The following members are only accessed (exclusively) from one thread and |
| 361 | // from the destructor, and therefore doesn't need any explicit |
| 362 | // synchronization. |
asapersson | 250fd97 | 2016-09-08 07:07:21 | [diff] [blame] | 363 | RateCounter received_bytes_per_second_counter_; |
| 364 | RateCounter received_audio_bytes_per_second_counter_; |
| 365 | RateCounter received_video_bytes_per_second_counter_; |
| 366 | RateCounter received_rtcp_bytes_per_second_counter_; |
Danil Chapovalov | b9b146c | 2018-06-15 10:28:07 | [diff] [blame] | 367 | absl::optional<int64_t> first_received_rtp_audio_ms_; |
| 368 | absl::optional<int64_t> last_received_rtp_audio_ms_; |
| 369 | absl::optional<int64_t> first_received_rtp_video_ms_; |
| 370 | absl::optional<int64_t> last_received_rtp_video_ms_; |
stefan | 91d9260 | 2015-11-11 18:13:02 | [diff] [blame] | 371 | |
Sebastian Jansson | 19704ec | 2018-03-12 14:59:12 | [diff] [blame] | 372 | rtc::CriticalSection last_bandwidth_bps_crit_; |
| 373 | uint32_t last_bandwidth_bps_ RTC_GUARDED_BY(&last_bandwidth_bps_crit_); |
stefan | 18adf0a | 2015-11-17 14:24:56 | [diff] [blame] | 374 | // TODO(holmer): Remove this lock once BitrateController no longer calls |
| 375 | // OnNetworkChanged from multiple threads. |
| 376 | rtc::CriticalSection bitrate_crit_; |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 377 | uint32_t min_allocated_send_bitrate_bps_ RTC_GUARDED_BY(&bitrate_crit_); |
| 378 | uint32_t configured_max_padding_bitrate_bps_ RTC_GUARDED_BY(&bitrate_crit_); |
| 379 | AvgCounter estimated_send_bitrate_kbps_counter_ |
| 380 | RTC_GUARDED_BY(&bitrate_crit_); |
| 381 | AvgCounter pacer_bitrate_kbps_counter_ RTC_GUARDED_BY(&bitrate_crit_); |
stefan | 18adf0a | 2015-11-17 14:24:56 | [diff] [blame] | 382 | |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 383 | ReceiveSideCongestionController receive_side_cc_; |
Sebastian Jansson | b34556e | 2018-03-21 13:38:32 | [diff] [blame] | 384 | |
| 385 | const std::unique_ptr<ReceiveTimeCalculator> receive_time_calculator_; |
| 386 | |
asapersson | 35151f3 | 2016-05-03 06:44:01 | [diff] [blame] | 387 | const std::unique_ptr<SendDelayStats> video_send_delay_stats_; |
asapersson | 4374a09 | 2016-07-27 07:39:09 | [diff] [blame] | 388 | const int64_t start_ms_; |
mflodman | 0e7e259 | 2015-11-13 05:02:42 | [diff] [blame] | 389 | |
Sebastian Jansson | e625605 | 2018-05-04 12:08:15 | [diff] [blame] | 390 | // Caches transport_send_.get(), to avoid racing with destructor. |
| 391 | // Note that this is declared before transport_send_ to ensure that it is not |
| 392 | // invalidated until no more tasks can be running on the transport_send_ task |
| 393 | // queue. |
| 394 | RtpTransportControllerSendInterface* transport_send_ptr_; |
| 395 | // Declared last since it will issue callbacks from a task queue. Declaring it |
| 396 | // last ensures that it is destroyed first and any running tasks are finished. |
| 397 | std::unique_ptr<RtpTransportControllerSendInterface> transport_send_; |
Piotr (Peter) Slatala | cc8e8bb | 2018-11-15 16:26:19 | [diff] [blame] | 398 | |
| 399 | // This is a precaution, since |MediaTransportChange| is not guaranteed to be |
| 400 | // invoked on a particular thread. |
| 401 | rtc::CriticalSection target_observer_crit_; |
| 402 | bool is_target_rate_observer_registered_ |
| 403 | RTC_GUARDED_BY(&target_observer_crit_) = false; |
| 404 | MediaTransportInterface* media_transport_ |
| 405 | RTC_GUARDED_BY(&target_observer_crit_) = nullptr; |
| 406 | |
henrikg | 3c089d7 | 2015-09-16 12:37:44 | [diff] [blame] | 407 | RTC_DISALLOW_COPY_AND_ASSIGN(Call); |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 | [diff] [blame] | 408 | }; |
pbos@webrtc.org | c49d5b7 | 2013-12-05 12:11:47 | [diff] [blame] | 409 | } // namespace internal |
pbos@webrtc.org | fd39e13 | 2013-08-14 13:52:52 | [diff] [blame] | 410 | |
asapersson | 2e5cfcd | 2016-08-11 15:41:18 | [diff] [blame] | 411 | std::string Call::Stats::ToString(int64_t time_ms) const { |
Jonas Olsson | 0a713b6 | 2018-04-04 13:49:32 | [diff] [blame] | 412 | char buf[1024]; |
| 413 | rtc::SimpleStringBuilder ss(buf); |
asapersson | 2e5cfcd | 2016-08-11 15:41:18 | [diff] [blame] | 414 | ss << "Call stats: " << time_ms << ", {"; |
| 415 | ss << "send_bw_bps: " << send_bandwidth_bps << ", "; |
| 416 | ss << "recv_bw_bps: " << recv_bandwidth_bps << ", "; |
| 417 | ss << "max_pad_bps: " << max_padding_bitrate_bps << ", "; |
| 418 | ss << "pacer_delay_ms: " << pacer_delay_ms << ", "; |
| 419 | ss << "rtt_ms: " << rtt_ms; |
| 420 | ss << '}'; |
| 421 | return ss.str(); |
| 422 | } |
| 423 | |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 | [diff] [blame] | 424 | Call* Call::Create(const Call::Config& config) { |
Danil Chapovalov | 359fe33 | 2019-04-01 08:46:36 | [diff] [blame] | 425 | return Create(config, Clock::GetRealTimeClock(), |
| 426 | ProcessThread::Create("PacerThread"), |
| 427 | ProcessThread::Create("ModuleProcessThread")); |
Sebastian Jansson | 896b47c | 2019-03-01 17:48:16 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | Call* Call::Create(const Call::Config& config, |
Sebastian Jansson | 4e5f5ed | 2019-03-01 17:13:27 | [diff] [blame] | 431 | Clock* clock, |
Sebastian Jansson | 896b47c | 2019-03-01 17:48:16 | [diff] [blame] | 432 | std::unique_ptr<ProcessThread> call_thread, |
Danil Chapovalov | 359fe33 | 2019-04-01 08:46:36 | [diff] [blame] | 433 | std::unique_ptr<ProcessThread> pacer_thread) { |
| 434 | // TODO(bugs.webrtc.org/10284): DCHECK task_queue_factory dependency is |
| 435 | // always provided in the config. |
| 436 | TaskQueueFactory* task_queue_factory = config.task_queue_factory |
| 437 | ? config.task_queue_factory |
| 438 | : &GlobalTaskQueueFactory(); |
Sebastian Jansson | 97f61ea | 2018-02-21 12:01:55 | [diff] [blame] | 439 | return new internal::Call( |
Sebastian Jansson | 4e5f5ed | 2019-03-01 17:13:27 | [diff] [blame] | 440 | clock, config, |
Sebastian Jansson | ed50e6c | 2019-03-01 13:45:21 | [diff] [blame] | 441 | absl::make_unique<RtpTransportControllerSend>( |
Sebastian Jansson | 4e5f5ed | 2019-03-01 17:13:27 | [diff] [blame] | 442 | clock, config.event_log, config.network_controller_factory, |
| 443 | config.bitrate_config, std::move(pacer_thread), task_queue_factory), |
Sebastian Jansson | 896b47c | 2019-03-01 17:48:16 | [diff] [blame] | 444 | std::move(call_thread), task_queue_factory); |
zstein | 7cb69d5 | 2017-05-08 18:52:38 | [diff] [blame] | 445 | } |
| 446 | |
Ying Wang | 0dd1b0a | 2018-02-20 11:50:27 | [diff] [blame] | 447 | // This method here to avoid subclasses has to implement this method. |
| 448 | // Call perf test will use Internal::Call::CreateVideoSendStream() to inject |
| 449 | // FecController. |
Ying Wang | 3b790f3 | 2018-01-19 16:58:57 | [diff] [blame] | 450 | VideoSendStream* Call::CreateVideoSendStream( |
| 451 | VideoSendStream::Config config, |
| 452 | VideoEncoderConfig encoder_config, |
| 453 | std::unique_ptr<FecController> fec_controller) { |
| 454 | return nullptr; |
| 455 | } |
| 456 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 457 | namespace internal { |
| 458 | |
Sebastian Jansson | 4e5f5ed | 2019-03-01 17:13:27 | [diff] [blame] | 459 | Call::Call(Clock* clock, |
| 460 | const Call::Config& config, |
Sebastian Jansson | 896b47c | 2019-03-01 17:48:16 | [diff] [blame] | 461 | std::unique_ptr<RtpTransportControllerSendInterface> transport_send, |
| 462 | std::unique_ptr<ProcessThread> module_process_thread, |
| 463 | TaskQueueFactory* task_queue_factory) |
Sebastian Jansson | 4e5f5ed | 2019-03-01 17:13:27 | [diff] [blame] | 464 | : clock_(clock), |
Sebastian Jansson | 896b47c | 2019-03-01 17:48:16 | [diff] [blame] | 465 | task_queue_factory_(task_queue_factory), |
stefan | 91d9260 | 2015-11-11 18:13:02 | [diff] [blame] | 466 | num_cpu_cores_(CpuInfo::DetectNumberOfCores()), |
Sebastian Jansson | 896b47c | 2019-03-01 17:48:16 | [diff] [blame] | 467 | module_process_thread_(std::move(module_process_thread)), |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 468 | call_stats_(new CallStats(clock_, module_process_thread_.get())), |
Sebastian Jansson | da6806c | 2019-03-04 16:05:12 | [diff] [blame] | 469 | bitrate_allocator_(new BitrateAllocator(clock_, this)), |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame] | 470 | config_(config), |
Sergey Ulanov | e2b1501 | 2016-11-23 00:08:30 | [diff] [blame] | 471 | audio_network_state_(kNetworkDown), |
| 472 | video_network_state_(kNetworkDown), |
Sebastian Jansson | a06e919 | 2018-03-07 17:49:55 | [diff] [blame] | 473 | aggregate_network_up_(false), |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 474 | receive_crit_(RWLockWrapper::CreateRWLock()), |
stefan | 91d9260 | 2015-11-11 18:13:02 | [diff] [blame] | 475 | send_crit_(RWLockWrapper::CreateRWLock()), |
skvlad | 11a9cbf | 2016-10-07 18:53:05 | [diff] [blame] | 476 | event_log_(config.event_log), |
asapersson | 250fd97 | 2016-09-08 07:07:21 | [diff] [blame] | 477 | received_bytes_per_second_counter_(clock_, nullptr, true), |
| 478 | received_audio_bytes_per_second_counter_(clock_, nullptr, true), |
| 479 | received_video_bytes_per_second_counter_(clock_, nullptr, true), |
| 480 | received_rtcp_bytes_per_second_counter_(clock_, nullptr, true), |
Sebastian Jansson | 19704ec | 2018-03-12 14:59:12 | [diff] [blame] | 481 | last_bandwidth_bps_(0), |
perkj | 71ee44c | 2016-06-15 07:47:53 | [diff] [blame] | 482 | min_allocated_send_bitrate_bps_(0), |
sprang | 9c0b551 | 2016-07-06 07:54:28 | [diff] [blame] | 483 | configured_max_padding_bitrate_bps_(0), |
asapersson | ce2e136 | 2016-09-09 07:13:35 | [diff] [blame] | 484 | estimated_send_bitrate_kbps_counter_(clock_, nullptr, true), |
| 485 | pacer_bitrate_kbps_counter_(clock_, nullptr, true), |
nisse | 0584331 | 2017-04-19 06:38:35 | [diff] [blame] | 486 | receive_side_cc_(clock_, transport_send->packet_router()), |
Sebastian Jansson | b34556e | 2018-03-21 13:38:32 | [diff] [blame] | 487 | receive_time_calculator_(ReceiveTimeCalculator::CreateFromFieldTrial()), |
asapersson | 4374a09 | 2016-07-27 07:39:09 | [diff] [blame] | 488 | video_send_delay_stats_(new SendDelayStats(clock_)), |
Benjamin Wright | a556448 | 2019-04-03 17:44:18 | [diff] [blame] | 489 | start_ms_(clock_->TimeInMilliseconds()) { |
skvlad | 11a9cbf | 2016-10-07 18:53:05 | [diff] [blame] | 490 | RTC_DCHECK(config.event_log != nullptr); |
nisse | 6167b26 | 2017-04-06 13:34:25 | [diff] [blame] | 491 | transport_send_ = std::move(transport_send); |
Sebastian Jansson | e625605 | 2018-05-04 12:08:15 | [diff] [blame] | 492 | transport_send_ptr_ = transport_send_.get(); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 493 | } |
| 494 | |
pbos@webrtc.org | 841c8a4 | 2013-09-09 15:04:25 | [diff] [blame] | 495 | Call::~Call() { |
eladalon | f3f5c0e | 2017-08-18 09:47:08 | [diff] [blame] | 496 | RTC_DCHECK_CALLED_SEQUENTIALLY(&configuration_sequence_checker_); |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 497 | |
solenberg | c7a8b08 | 2015-10-16 21:35:07 | [diff] [blame] | 498 | RTC_CHECK(audio_send_ssrcs_.empty()); |
| 499 | RTC_CHECK(video_send_ssrcs_.empty()); |
| 500 | RTC_CHECK(video_send_streams_.empty()); |
nisse | e4bcd6d | 2017-05-16 11:47:04 | [diff] [blame] | 501 | RTC_CHECK(audio_receive_streams_.empty()); |
solenberg | c7a8b08 | 2015-10-16 21:35:07 | [diff] [blame] | 502 | RTC_CHECK(video_receive_streams_.empty()); |
pbos@webrtc.org | 9e4e524 | 2015-02-12 10:48:23 | [diff] [blame] | 503 | |
Piotr (Peter) Slatala | b275788 | 2018-12-18 19:17:09 | [diff] [blame] | 504 | if (!media_transport_) { |
| 505 | module_process_thread_->DeRegisterModule( |
| 506 | receive_side_cc_.GetRemoteBitrateEstimator(true)); |
| 507 | module_process_thread_->DeRegisterModule(&receive_side_cc_); |
| 508 | module_process_thread_->DeRegisterModule(call_stats_.get()); |
| 509 | module_process_thread_->Stop(); |
| 510 | call_stats_->DeregisterStatsObserver(&receive_side_cc_); |
Piotr (Peter) Slatala | b275788 | 2018-12-18 19:17:09 | [diff] [blame] | 511 | } |
sprang | 6d6122b | 2016-07-13 13:37:09 | [diff] [blame] | 512 | |
Sebastian Jansson | e4be6da | 2018-02-15 15:51:41 | [diff] [blame] | 513 | int64_t first_sent_packet_ms = transport_send_->GetFirstPacketTimeMs(); |
sprang | 6d6122b | 2016-07-13 13:37:09 | [diff] [blame] | 514 | // Only update histograms after process threads have been shut down, so that |
| 515 | // they won't try to concurrently update stats. |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 516 | { |
| 517 | rtc::CritScope lock(&bitrate_crit_); |
asapersson | fc5e81c | 2017-04-20 06:28:53 | [diff] [blame] | 518 | UpdateSendHistograms(first_sent_packet_ms); |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 519 | } |
sprang | 6d6122b | 2016-07-13 13:37:09 | [diff] [blame] | 520 | UpdateReceiveHistograms(); |
asapersson | 4374a09 | 2016-07-27 07:39:09 | [diff] [blame] | 521 | UpdateHistograms(); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 522 | } |
| 523 | |
Piotr (Peter) Slatala | cc8e8bb | 2018-11-15 16:26:19 | [diff] [blame] | 524 | void Call::RegisterRateObserver() { |
| 525 | rtc::CritScope lock(&target_observer_crit_); |
| 526 | |
| 527 | if (is_target_rate_observer_registered_) { |
| 528 | return; |
| 529 | } |
| 530 | |
| 531 | is_target_rate_observer_registered_ = true; |
| 532 | |
| 533 | if (media_transport_) { |
Piotr (Peter) Slatala | b275788 | 2018-12-18 19:17:09 | [diff] [blame] | 534 | // TODO(bugs.webrtc.org/9719): We should report call_stats_ from |
| 535 | // media transport (at least Rtt). We should extend media transport |
| 536 | // interface to include "receive_side bwe" if needed. |
Piotr (Peter) Slatala | cc8e8bb | 2018-11-15 16:26:19 | [diff] [blame] | 537 | media_transport_->AddTargetTransferRateObserver(this); |
| 538 | } else { |
| 539 | transport_send_ptr_->RegisterTargetTransferRateObserver(this); |
Piotr (Peter) Slatala | b275788 | 2018-12-18 19:17:09 | [diff] [blame] | 540 | |
| 541 | call_stats_->RegisterStatsObserver(&receive_side_cc_); |
Piotr (Peter) Slatala | b275788 | 2018-12-18 19:17:09 | [diff] [blame] | 542 | |
| 543 | module_process_thread_->RegisterModule( |
| 544 | receive_side_cc_.GetRemoteBitrateEstimator(true), RTC_FROM_HERE); |
| 545 | module_process_thread_->RegisterModule(call_stats_.get(), RTC_FROM_HERE); |
| 546 | module_process_thread_->RegisterModule(&receive_side_cc_, RTC_FROM_HERE); |
| 547 | module_process_thread_->Start(); |
Piotr (Peter) Slatala | cc8e8bb | 2018-11-15 16:26:19 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | |
Niels Möller | 4687915 | 2019-01-07 14:54:47 | [diff] [blame] | 551 | MediaTransportInterface* Call::media_transport() { |
| 552 | rtc::CritScope lock(&target_observer_crit_); |
| 553 | return media_transport_; |
| 554 | } |
| 555 | |
Piotr (Peter) Slatala | cc8e8bb | 2018-11-15 16:26:19 | [diff] [blame] | 556 | void Call::MediaTransportChange(MediaTransportInterface* media_transport) { |
| 557 | rtc::CritScope lock(&target_observer_crit_); |
| 558 | |
| 559 | if (is_target_rate_observer_registered_) { |
| 560 | // Only used to unregister rate observer from media transport. Registration |
| 561 | // happens when the stream is created. |
| 562 | if (!media_transport && media_transport_) { |
| 563 | media_transport_->RemoveTargetTransferRateObserver(this); |
| 564 | media_transport_ = nullptr; |
| 565 | is_target_rate_observer_registered_ = false; |
| 566 | } |
| 567 | } else if (media_transport) { |
| 568 | RTC_DCHECK(media_transport_ == nullptr || |
| 569 | media_transport_ == media_transport) |
| 570 | << "media_transport_=" << (media_transport_ != nullptr) |
| 571 | << ", (media_transport_==media_transport)=" |
| 572 | << (media_transport_ == media_transport); |
| 573 | media_transport_ = media_transport; |
Piotr (Peter) Slatala | 946b968 | 2019-03-18 17:25:02 | [diff] [blame] | 574 | MediaTransportTargetRateConstraints constraints; |
| 575 | if (config_.bitrate_config.start_bitrate_bps > 0) { |
| 576 | constraints.starting_bitrate = |
| 577 | DataRate::bps(config_.bitrate_config.start_bitrate_bps); |
| 578 | } |
| 579 | if (config_.bitrate_config.max_bitrate_bps > 0) { |
| 580 | constraints.max_bitrate = |
| 581 | DataRate::bps(config_.bitrate_config.max_bitrate_bps); |
| 582 | } |
| 583 | if (config_.bitrate_config.min_bitrate_bps > 0) { |
| 584 | constraints.min_bitrate = |
| 585 | DataRate::bps(config_.bitrate_config.min_bitrate_bps); |
| 586 | } |
Piotr (Peter) Slatala | 7fbfaa4 | 2019-03-18 17:31:54 | [diff] [blame] | 587 | |
| 588 | // User called ::SetBitrate on peer connection before |
| 589 | // media transport was created. |
| 590 | if (last_set_bitrate_) { |
| 591 | media_transport_->SetTargetBitrateLimits(*last_set_bitrate_); |
| 592 | } else { |
| 593 | media_transport_->SetTargetBitrateLimits(constraints); |
| 594 | } |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | void Call::SetClientBitratePreferences(const BitrateSettings& preferences) { |
| 599 | GetTransportControllerSend()->SetClientBitratePreferences(preferences); |
| 600 | // Can the client code invoke 'SetBitrate' before media transport is created? |
| 601 | // It's probably possible :/ |
| 602 | MediaTransportTargetRateConstraints constraints; |
| 603 | if (preferences.start_bitrate_bps.has_value()) { |
| 604 | constraints.starting_bitrate = |
| 605 | webrtc::DataRate::bps(*preferences.start_bitrate_bps); |
| 606 | } |
| 607 | if (preferences.max_bitrate_bps.has_value()) { |
| 608 | constraints.max_bitrate = |
| 609 | webrtc::DataRate::bps(*preferences.max_bitrate_bps); |
| 610 | } |
| 611 | if (preferences.min_bitrate_bps.has_value()) { |
| 612 | constraints.min_bitrate = |
| 613 | webrtc::DataRate::bps(*preferences.min_bitrate_bps); |
| 614 | } |
| 615 | rtc::CritScope lock(&target_observer_crit_); |
| 616 | last_set_bitrate_ = constraints; |
| 617 | if (media_transport_) { |
Piotr (Peter) Slatala | 946b968 | 2019-03-18 17:25:02 | [diff] [blame] | 618 | media_transport_->SetTargetBitrateLimits(constraints); |
Piotr (Peter) Slatala | cc8e8bb | 2018-11-15 16:26:19 | [diff] [blame] | 619 | } |
| 620 | } |
| 621 | |
asapersson | 4374a09 | 2016-07-27 07:39:09 | [diff] [blame] | 622 | void Call::UpdateHistograms() { |
asapersson | 1d02d3e | 2016-09-10 05:40:25 | [diff] [blame] | 623 | RTC_HISTOGRAM_COUNTS_100000( |
asapersson | 4374a09 | 2016-07-27 07:39:09 | [diff] [blame] | 624 | "WebRTC.Call.LifetimeInSeconds", |
| 625 | (clock_->TimeInMilliseconds() - start_ms_) / 1000); |
| 626 | } |
| 627 | |
asapersson | fc5e81c | 2017-04-20 06:28:53 | [diff] [blame] | 628 | void Call::UpdateSendHistograms(int64_t first_sent_packet_ms) { |
| 629 | if (first_sent_packet_ms == -1) |
stefan | 18adf0a | 2015-11-17 14:24:56 | [diff] [blame] | 630 | return; |
| 631 | int64_t elapsed_sec = |
asapersson | fc5e81c | 2017-04-20 06:28:53 | [diff] [blame] | 632 | (clock_->TimeInMilliseconds() - first_sent_packet_ms) / 1000; |
stefan | 18adf0a | 2015-11-17 14:24:56 | [diff] [blame] | 633 | if (elapsed_sec < metrics::kMinRunTimeInSeconds) |
| 634 | return; |
asapersson | ce2e136 | 2016-09-09 07:13:35 | [diff] [blame] | 635 | const int kMinRequiredPeriodicSamples = 5; |
| 636 | AggregatedStats send_bitrate_stats = |
| 637 | estimated_send_bitrate_kbps_counter_.ProcessAndGetStats(); |
| 638 | if (send_bitrate_stats.num_samples > kMinRequiredPeriodicSamples) { |
asapersson | 1d02d3e | 2016-09-10 05:40:25 | [diff] [blame] | 639 | RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.EstimatedSendBitrateInKbps", |
| 640 | send_bitrate_stats.average); |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 641 | RTC_LOG(LS_INFO) << "WebRTC.Call.EstimatedSendBitrateInKbps, " |
| 642 | << send_bitrate_stats.ToString(); |
stefan | 18adf0a | 2015-11-17 14:24:56 | [diff] [blame] | 643 | } |
asapersson | ce2e136 | 2016-09-09 07:13:35 | [diff] [blame] | 644 | AggregatedStats pacer_bitrate_stats = |
| 645 | pacer_bitrate_kbps_counter_.ProcessAndGetStats(); |
| 646 | if (pacer_bitrate_stats.num_samples > kMinRequiredPeriodicSamples) { |
asapersson | 1d02d3e | 2016-09-10 05:40:25 | [diff] [blame] | 647 | RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.PacerBitrateInKbps", |
| 648 | pacer_bitrate_stats.average); |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 649 | RTC_LOG(LS_INFO) << "WebRTC.Call.PacerBitrateInKbps, " |
| 650 | << pacer_bitrate_stats.ToString(); |
stefan | 18adf0a | 2015-11-17 14:24:56 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
| 654 | void Call::UpdateReceiveHistograms() { |
saza | 0d7f04d | 2017-07-04 11:05:06 | [diff] [blame] | 655 | if (first_received_rtp_audio_ms_) { |
| 656 | RTC_HISTOGRAM_COUNTS_100000( |
| 657 | "WebRTC.Call.TimeReceivingAudioRtpPacketsInSeconds", |
| 658 | (*last_received_rtp_audio_ms_ - *first_received_rtp_audio_ms_) / 1000); |
| 659 | } |
| 660 | if (first_received_rtp_video_ms_) { |
| 661 | RTC_HISTOGRAM_COUNTS_100000( |
| 662 | "WebRTC.Call.TimeReceivingVideoRtpPacketsInSeconds", |
| 663 | (*last_received_rtp_video_ms_ - *first_received_rtp_video_ms_) / 1000); |
| 664 | } |
asapersson | 250fd97 | 2016-09-08 07:07:21 | [diff] [blame] | 665 | const int kMinRequiredPeriodicSamples = 5; |
| 666 | AggregatedStats video_bytes_per_sec = |
| 667 | received_video_bytes_per_second_counter_.GetStats(); |
| 668 | if (video_bytes_per_sec.num_samples > kMinRequiredPeriodicSamples) { |
asapersson | 1d02d3e | 2016-09-10 05:40:25 | [diff] [blame] | 669 | RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.VideoBitrateReceivedInKbps", |
| 670 | video_bytes_per_sec.average * 8 / 1000); |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 671 | RTC_LOG(LS_INFO) << "WebRTC.Call.VideoBitrateReceivedInBps, " |
| 672 | << video_bytes_per_sec.ToStringWithMultiplier(8); |
stefan | 91d9260 | 2015-11-11 18:13:02 | [diff] [blame] | 673 | } |
asapersson | 250fd97 | 2016-09-08 07:07:21 | [diff] [blame] | 674 | AggregatedStats audio_bytes_per_sec = |
| 675 | received_audio_bytes_per_second_counter_.GetStats(); |
| 676 | if (audio_bytes_per_sec.num_samples > kMinRequiredPeriodicSamples) { |
asapersson | 1d02d3e | 2016-09-10 05:40:25 | [diff] [blame] | 677 | RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.AudioBitrateReceivedInKbps", |
| 678 | audio_bytes_per_sec.average * 8 / 1000); |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 679 | RTC_LOG(LS_INFO) << "WebRTC.Call.AudioBitrateReceivedInBps, " |
| 680 | << audio_bytes_per_sec.ToStringWithMultiplier(8); |
stefan | 91d9260 | 2015-11-11 18:13:02 | [diff] [blame] | 681 | } |
asapersson | 250fd97 | 2016-09-08 07:07:21 | [diff] [blame] | 682 | AggregatedStats rtcp_bytes_per_sec = |
| 683 | received_rtcp_bytes_per_second_counter_.GetStats(); |
| 684 | if (rtcp_bytes_per_sec.num_samples > kMinRequiredPeriodicSamples) { |
asapersson | 1d02d3e | 2016-09-10 05:40:25 | [diff] [blame] | 685 | RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.RtcpBitrateReceivedInBps", |
| 686 | rtcp_bytes_per_sec.average * 8); |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 687 | RTC_LOG(LS_INFO) << "WebRTC.Call.RtcpBitrateReceivedInBps, " |
| 688 | << rtcp_bytes_per_sec.ToStringWithMultiplier(8); |
stefan | 91d9260 | 2015-11-11 18:13:02 | [diff] [blame] | 689 | } |
asapersson | 250fd97 | 2016-09-08 07:07:21 | [diff] [blame] | 690 | AggregatedStats recv_bytes_per_sec = |
| 691 | received_bytes_per_second_counter_.GetStats(); |
| 692 | if (recv_bytes_per_sec.num_samples > kMinRequiredPeriodicSamples) { |
asapersson | 1d02d3e | 2016-09-10 05:40:25 | [diff] [blame] | 693 | RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.BitrateReceivedInKbps", |
| 694 | recv_bytes_per_sec.average * 8 / 1000); |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 695 | RTC_LOG(LS_INFO) << "WebRTC.Call.BitrateReceivedInBps, " |
| 696 | << recv_bytes_per_sec.ToStringWithMultiplier(8); |
asapersson | 250fd97 | 2016-09-08 07:07:21 | [diff] [blame] | 697 | } |
stefan | 91d9260 | 2015-11-11 18:13:02 | [diff] [blame] | 698 | } |
| 699 | |
solenberg | 5a28939 | 2015-10-19 10:39:20 | [diff] [blame] | 700 | PacketReceiver* Call::Receiver() { |
eladalon | d1dd2f7 | 2017-08-25 09:55:57 | [diff] [blame] | 701 | RTC_DCHECK_CALLED_SEQUENTIALLY(&configuration_sequence_checker_); |
solenberg | 5a28939 | 2015-10-19 10:39:20 | [diff] [blame] | 702 | return this; |
| 703 | } |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 704 | |
Fredrik Solenberg | 04f4931 | 2015-06-08 11:04:56 | [diff] [blame] | 705 | webrtc::AudioSendStream* Call::CreateAudioSendStream( |
| 706 | const webrtc::AudioSendStream::Config& config) { |
solenberg | c7a8b08 | 2015-10-16 21:35:07 | [diff] [blame] | 707 | TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream"); |
eladalon | f3f5c0e | 2017-08-18 09:47:08 | [diff] [blame] | 708 | RTC_DCHECK_CALLED_SEQUENTIALLY(&configuration_sequence_checker_); |
Piotr (Peter) Slatala | cc8e8bb | 2018-11-15 16:26:19 | [diff] [blame] | 709 | |
Niels Möller | 4687915 | 2019-01-07 14:54:47 | [diff] [blame] | 710 | RTC_DCHECK(media_transport() == config.media_transport); |
Piotr (Peter) Slatala | cc8e8bb | 2018-11-15 16:26:19 | [diff] [blame] | 711 | |
| 712 | RegisterRateObserver(); |
| 713 | |
Oskar Sundbom | 56ef305 | 2018-10-30 15:11:02 | [diff] [blame] | 714 | // Stream config is logged in AudioSendStream::ConfigureStream, as it may |
| 715 | // change during the stream's lifetime. |
Danil Chapovalov | b9b146c | 2018-06-15 10:28:07 | [diff] [blame] | 716 | absl::optional<RtpState> suspended_rtp_state; |
ossu | c3d4b48 | 2017-05-23 13:07:11 | [diff] [blame] | 717 | { |
| 718 | const auto& iter = suspended_audio_send_ssrcs_.find(config.rtp.ssrc); |
| 719 | if (iter != suspended_audio_send_ssrcs_.end()) { |
| 720 | suspended_rtp_state.emplace(iter->second); |
| 721 | } |
| 722 | } |
| 723 | |
Sebastian Jansson | 44dd9f2 | 2019-03-08 13:50:30 | [diff] [blame] | 724 | AudioSendStream* send_stream = |
| 725 | new AudioSendStream(clock_, config, config_.audio_state, |
| 726 | task_queue_factory_, module_process_thread_.get(), |
| 727 | transport_send_ptr_, bitrate_allocator_.get(), |
| 728 | event_log_, call_stats_.get(), suspended_rtp_state); |
solenberg | c7a8b08 | 2015-10-16 21:35:07 | [diff] [blame] | 729 | { |
solenberg | c7a8b08 | 2015-10-16 21:35:07 | [diff] [blame] | 730 | WriteLockScoped write_lock(*send_crit_); |
| 731 | RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == |
| 732 | audio_send_ssrcs_.end()); |
| 733 | audio_send_ssrcs_[config.rtp.ssrc] = send_stream; |
solenberg | c7a8b08 | 2015-10-16 21:35:07 | [diff] [blame] | 734 | } |
solenberg | 7602aab | 2016-11-14 19:30:07 | [diff] [blame] | 735 | { |
| 736 | ReadLockScoped read_lock(*receive_crit_); |
nisse | e4bcd6d | 2017-05-16 11:47:04 | [diff] [blame] | 737 | for (AudioReceiveStream* stream : audio_receive_streams_) { |
| 738 | if (stream->config().rtp.local_ssrc == config.rtp.ssrc) { |
| 739 | stream->AssociateSendStream(send_stream); |
solenberg | 7602aab | 2016-11-14 19:30:07 | [diff] [blame] | 740 | } |
| 741 | } |
| 742 | } |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 743 | send_stream->SignalNetworkState(audio_network_state_); |
| 744 | UpdateAggregateNetworkState(); |
solenberg | c7a8b08 | 2015-10-16 21:35:07 | [diff] [blame] | 745 | return send_stream; |
Fredrik Solenberg | 04f4931 | 2015-06-08 11:04:56 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { |
solenberg | c7a8b08 | 2015-10-16 21:35:07 | [diff] [blame] | 749 | TRACE_EVENT0("webrtc", "Call::DestroyAudioSendStream"); |
eladalon | f3f5c0e | 2017-08-18 09:47:08 | [diff] [blame] | 750 | RTC_DCHECK_CALLED_SEQUENTIALLY(&configuration_sequence_checker_); |
solenberg | c7a8b08 | 2015-10-16 21:35:07 | [diff] [blame] | 751 | RTC_DCHECK(send_stream != nullptr); |
| 752 | |
| 753 | send_stream->Stop(); |
| 754 | |
eladalon | abbc430 | 2017-07-26 09:09:44 | [diff] [blame] | 755 | const uint32_t ssrc = send_stream->GetConfig().rtp.ssrc; |
solenberg | c7a8b08 | 2015-10-16 21:35:07 | [diff] [blame] | 756 | webrtc::internal::AudioSendStream* audio_send_stream = |
| 757 | static_cast<webrtc::internal::AudioSendStream*>(send_stream); |
ossu | c3d4b48 | 2017-05-23 13:07:11 | [diff] [blame] | 758 | suspended_audio_send_ssrcs_[ssrc] = audio_send_stream->GetRtpState(); |
solenberg | c7a8b08 | 2015-10-16 21:35:07 | [diff] [blame] | 759 | { |
| 760 | WriteLockScoped write_lock(*send_crit_); |
solenberg | 7602aab | 2016-11-14 19:30:07 | [diff] [blame] | 761 | size_t num_deleted = audio_send_ssrcs_.erase(ssrc); |
| 762 | RTC_DCHECK_EQ(1, num_deleted); |
| 763 | } |
| 764 | { |
| 765 | ReadLockScoped read_lock(*receive_crit_); |
nisse | e4bcd6d | 2017-05-16 11:47:04 | [diff] [blame] | 766 | for (AudioReceiveStream* stream : audio_receive_streams_) { |
| 767 | if (stream->config().rtp.local_ssrc == ssrc) { |
| 768 | stream->AssociateSendStream(nullptr); |
solenberg | 7602aab | 2016-11-14 19:30:07 | [diff] [blame] | 769 | } |
| 770 | } |
solenberg | c7a8b08 | 2015-10-16 21:35:07 | [diff] [blame] | 771 | } |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 772 | UpdateAggregateNetworkState(); |
eladalon | abbc430 | 2017-07-26 09:09:44 | [diff] [blame] | 773 | delete send_stream; |
Fredrik Solenberg | 04f4931 | 2015-06-08 11:04:56 | [diff] [blame] | 774 | } |
| 775 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 776 | webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( |
| 777 | const webrtc::AudioReceiveStream::Config& config) { |
| 778 | TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); |
eladalon | f3f5c0e | 2017-08-18 09:47:08 | [diff] [blame] | 779 | RTC_DCHECK_CALLED_SEQUENTIALLY(&configuration_sequence_checker_); |
Piotr (Peter) Slatala | b275788 | 2018-12-18 19:17:09 | [diff] [blame] | 780 | RegisterRateObserver(); |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 781 | event_log_->Log(absl::make_unique<RtcEventAudioReceiveStreamConfig>( |
Elad Alon | 4a87e1c | 2017-10-03 14:11:34 | [diff] [blame] | 782 | CreateRtcLogStreamConfig(config))); |
nisse | 0f15f92 | 2017-06-21 08:05:22 | [diff] [blame] | 783 | AudioReceiveStream* receive_stream = new AudioReceiveStream( |
Sebastian Jansson | 977b335 | 2019-03-04 16:43:34 | [diff] [blame] | 784 | clock_, &audio_receiver_controller_, transport_send_ptr_->packet_router(), |
Fredrik Solenberg | 8f5787a | 2018-01-11 12:52:30 | [diff] [blame] | 785 | module_process_thread_.get(), config, config_.audio_state, event_log_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 786 | { |
| 787 | WriteLockScoped write_lock(*receive_crit_); |
Erik Språng | 0970851 | 2018-03-14 14:16:50 | [diff] [blame] | 788 | receive_rtp_config_.emplace(config.rtp.remote_ssrc, |
| 789 | ReceiveRtpConfig(config)); |
nisse | e4bcd6d | 2017-05-16 11:47:04 | [diff] [blame] | 790 | audio_receive_streams_.insert(receive_stream); |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 791 | |
pbos | 8fc7fa7 | 2015-07-15 15:02:58 | [diff] [blame] | 792 | ConfigureSync(config.sync_group); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 793 | } |
solenberg | 7602aab | 2016-11-14 19:30:07 | [diff] [blame] | 794 | { |
| 795 | ReadLockScoped read_lock(*send_crit_); |
| 796 | auto it = audio_send_ssrcs_.find(config.rtp.local_ssrc); |
| 797 | if (it != audio_send_ssrcs_.end()) { |
| 798 | receive_stream->AssociateSendStream(it->second); |
| 799 | } |
| 800 | } |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 801 | receive_stream->SignalNetworkState(audio_network_state_); |
| 802 | UpdateAggregateNetworkState(); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 803 | return receive_stream; |
| 804 | } |
| 805 | |
| 806 | void Call::DestroyAudioReceiveStream( |
| 807 | webrtc::AudioReceiveStream* receive_stream) { |
| 808 | TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream"); |
eladalon | f3f5c0e | 2017-08-18 09:47:08 | [diff] [blame] | 809 | RTC_DCHECK_CALLED_SEQUENTIALLY(&configuration_sequence_checker_); |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 810 | RTC_DCHECK(receive_stream != nullptr); |
solenberg | c7a8b08 | 2015-10-16 21:35:07 | [diff] [blame] | 811 | webrtc::internal::AudioReceiveStream* audio_receive_stream = |
| 812 | static_cast<webrtc::internal::AudioReceiveStream*>(receive_stream); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 813 | { |
| 814 | WriteLockScoped write_lock(*receive_crit_); |
nisse | 4709e89 | 2017-02-07 09:18:43 | [diff] [blame] | 815 | const AudioReceiveStream::Config& config = audio_receive_stream->config(); |
| 816 | uint32_t ssrc = config.rtp.remote_ssrc; |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 817 | receive_side_cc_.GetRemoteBitrateEstimator(UseSendSideBwe(config)) |
nisse | 4709e89 | 2017-02-07 09:18:43 | [diff] [blame] | 818 | ->RemoveStream(ssrc); |
nisse | e4bcd6d | 2017-05-16 11:47:04 | [diff] [blame] | 819 | audio_receive_streams_.erase(audio_receive_stream); |
pbos | 8fc7fa7 | 2015-07-15 15:02:58 | [diff] [blame] | 820 | const std::string& sync_group = audio_receive_stream->config().sync_group; |
| 821 | const auto it = sync_stream_mapping_.find(sync_group); |
| 822 | if (it != sync_stream_mapping_.end() && |
| 823 | it->second == audio_receive_stream) { |
| 824 | sync_stream_mapping_.erase(it); |
| 825 | ConfigureSync(sync_group); |
| 826 | } |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 827 | receive_rtp_config_.erase(ssrc); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 828 | } |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 829 | UpdateAggregateNetworkState(); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 830 | delete audio_receive_stream; |
| 831 | } |
| 832 | |
Ying Wang | 0dd1b0a | 2018-02-20 11:50:27 | [diff] [blame] | 833 | // This method can be used for Call tests with external fec controller factory. |
Ying Wang | 3b790f3 | 2018-01-19 16:58:57 | [diff] [blame] | 834 | webrtc::VideoSendStream* Call::CreateVideoSendStream( |
| 835 | webrtc::VideoSendStream::Config config, |
| 836 | VideoEncoderConfig encoder_config, |
| 837 | std::unique_ptr<FecController> fec_controller) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 | [diff] [blame] | 838 | TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); |
eladalon | f3f5c0e | 2017-08-18 09:47:08 | [diff] [blame] | 839 | RTC_DCHECK_CALLED_SEQUENTIALLY(&configuration_sequence_checker_); |
pbos@webrtc.org | 1819fd7 | 2013-06-10 13:48:26 | [diff] [blame] | 840 | |
Niels Möller | 4687915 | 2019-01-07 14:54:47 | [diff] [blame] | 841 | RTC_DCHECK(media_transport() == config.media_transport); |
| 842 | |
Piotr (Peter) Slatala | cc8e8bb | 2018-11-15 16:26:19 | [diff] [blame] | 843 | RegisterRateObserver(); |
| 844 | |
asapersson | 35151f3 | 2016-05-03 06:44:01 | [diff] [blame] | 845 | video_send_delay_stats_->AddSsrcs(config); |
perkj | c0876aa | 2017-05-22 11:08:28 | [diff] [blame] | 846 | for (size_t ssrc_index = 0; ssrc_index < config.rtp.ssrcs.size(); |
| 847 | ++ssrc_index) { |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 848 | event_log_->Log(absl::make_unique<RtcEventVideoSendStreamConfig>( |
Elad Alon | 4a87e1c | 2017-10-03 14:11:34 | [diff] [blame] | 849 | CreateRtcLogStreamConfig(config, ssrc_index))); |
perkj | c0876aa | 2017-05-22 11:08:28 | [diff] [blame] | 850 | } |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 851 | |
mflodman@webrtc.org | eb16b81 | 2014-06-16 08:57:39 | [diff] [blame] | 852 | // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if |
| 853 | // the call has already started. |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 854 | // Copy ssrcs from |config| since |config| is moved. |
| 855 | std::vector<uint32_t> ssrcs = config.rtp.ssrcs; |
Ying Wang | 0dd1b0a | 2018-02-20 11:50:27 | [diff] [blame] | 856 | |
mflodman | 0c478b3 | 2015-10-21 13:52:16 | [diff] [blame] | 857 | VideoSendStream* send_stream = new VideoSendStream( |
Sebastian Jansson | 0b69826 | 2019-03-07 08:17:19 | [diff] [blame] | 858 | clock_, num_cpu_cores_, module_process_thread_.get(), task_queue_factory_, |
Sebastian Jansson | 74682c1 | 2019-03-01 10:50:20 | [diff] [blame] | 859 | call_stats_.get(), transport_send_ptr_, bitrate_allocator_.get(), |
nisse | 0584331 | 2017-04-19 06:38:35 | [diff] [blame] | 860 | video_send_delay_stats_.get(), event_log_, std::move(config), |
Åsa Persson | 4bece9a | 2017-10-06 08:04:04 | [diff] [blame] | 861 | std::move(encoder_config), suspended_video_send_ssrcs_, |
Stefan Holmer | dbdb3a0 | 2018-07-17 14:03:46 | [diff] [blame] | 862 | suspended_video_payload_states_, std::move(fec_controller)); |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 863 | |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 864 | { |
| 865 | WriteLockScoped write_lock(*send_crit_); |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 866 | for (uint32_t ssrc : ssrcs) { |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 867 | RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); |
| 868 | video_send_ssrcs_[ssrc] = send_stream; |
| 869 | } |
| 870 | video_send_streams_.insert(send_stream); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 871 | } |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 872 | UpdateAggregateNetworkState(); |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 873 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 874 | return send_stream; |
| 875 | } |
| 876 | |
Ying Wang | 0dd1b0a | 2018-02-20 11:50:27 | [diff] [blame] | 877 | webrtc::VideoSendStream* Call::CreateVideoSendStream( |
| 878 | webrtc::VideoSendStream::Config config, |
| 879 | VideoEncoderConfig encoder_config) { |
Ying Wang | 012b7e7 | 2018-03-05 14:44:23 | [diff] [blame] | 880 | if (config_.fec_controller_factory) { |
| 881 | RTC_LOG(LS_INFO) << "External FEC Controller will be used."; |
| 882 | } |
Ying Wang | 0dd1b0a | 2018-02-20 11:50:27 | [diff] [blame] | 883 | std::unique_ptr<FecController> fec_controller = |
| 884 | config_.fec_controller_factory |
| 885 | ? config_.fec_controller_factory->CreateFecController() |
Sebastian Jansson | 11c012a | 2019-03-29 13:17:26 | [diff] [blame] | 886 | : absl::make_unique<FecControllerDefault>(clock_); |
Ying Wang | 0dd1b0a | 2018-02-20 11:50:27 | [diff] [blame] | 887 | return CreateVideoSendStream(std::move(config), std::move(encoder_config), |
| 888 | std::move(fec_controller)); |
| 889 | } |
| 890 | |
pbos@webrtc.org | 2c46f8d | 2013-11-21 13:49:43 | [diff] [blame] | 891 | void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 | [diff] [blame] | 892 | TRACE_EVENT0("webrtc", "Call::DestroyVideoSendStream"); |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 893 | RTC_DCHECK(send_stream != nullptr); |
eladalon | f3f5c0e | 2017-08-18 09:47:08 | [diff] [blame] | 894 | RTC_DCHECK_CALLED_SEQUENTIALLY(&configuration_sequence_checker_); |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 895 | |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 | [diff] [blame] | 896 | send_stream->Stop(); |
| 897 | |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 | [diff] [blame] | 898 | VideoSendStream* send_stream_impl = nullptr; |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 899 | { |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 900 | WriteLockScoped write_lock(*send_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 901 | auto it = video_send_ssrcs_.begin(); |
| 902 | while (it != video_send_ssrcs_.end()) { |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 903 | if (it->second == static_cast<VideoSendStream*>(send_stream)) { |
| 904 | send_stream_impl = it->second; |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 905 | video_send_ssrcs_.erase(it++); |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 | [diff] [blame] | 906 | } else { |
| 907 | ++it; |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 908 | } |
| 909 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 910 | video_send_streams_.erase(send_stream_impl); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 911 | } |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 912 | RTC_CHECK(send_stream_impl != nullptr); |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 913 | |
Åsa Persson | 4bece9a | 2017-10-06 08:04:04 | [diff] [blame] | 914 | VideoSendStream::RtpStateMap rtp_states; |
| 915 | VideoSendStream::RtpPayloadStateMap rtp_payload_states; |
| 916 | send_stream_impl->StopPermanentlyAndGetRtpStates(&rtp_states, |
| 917 | &rtp_payload_states); |
| 918 | for (const auto& kv : rtp_states) { |
| 919 | suspended_video_send_ssrcs_[kv.first] = kv.second; |
| 920 | } |
| 921 | for (const auto& kv : rtp_payload_states) { |
| 922 | suspended_video_payload_states_[kv.first] = kv.second; |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 | [diff] [blame] | 923 | } |
| 924 | |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 925 | UpdateAggregateNetworkState(); |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 926 | delete send_stream_impl; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 927 | } |
| 928 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 929 | webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( |
Tommi | 733b547 | 2016-06-10 15:58:01 | [diff] [blame] | 930 | webrtc::VideoReceiveStream::Config configuration) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 | [diff] [blame] | 931 | TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); |
eladalon | f3f5c0e | 2017-08-18 09:47:08 | [diff] [blame] | 932 | RTC_DCHECK_CALLED_SEQUENTIALLY(&configuration_sequence_checker_); |
brandtr | fb45c6c | 2017-01-27 14:47:55 | [diff] [blame] | 933 | |
Johannes Kron | f59666b | 2019-04-08 10:57:06 | [diff] [blame^] | 934 | receive_side_cc_.SetSendPeriodicFeedback( |
| 935 | SendPeriodicFeedback(configuration.rtp.extensions)); |
Johannes Kron | 7ff164e | 2019-02-07 11:50:18 | [diff] [blame] | 936 | |
Piotr (Peter) Slatala | b275788 | 2018-12-18 19:17:09 | [diff] [blame] | 937 | RegisterRateObserver(); |
| 938 | |
nisse | 0f15f92 | 2017-06-21 08:05:22 | [diff] [blame] | 939 | VideoReceiveStream* receive_stream = new VideoReceiveStream( |
Sebastian Jansson | 896b47c | 2019-03-01 17:48:16 | [diff] [blame] | 940 | task_queue_factory_, &video_receiver_controller_, num_cpu_cores_, |
Sebastian Jansson | e625605 | 2018-05-04 12:08:15 | [diff] [blame] | 941 | transport_send_ptr_->packet_router(), std::move(configuration), |
Sebastian Jansson | 8026d60 | 2019-03-04 18:39:01 | [diff] [blame] | 942 | module_process_thread_.get(), call_stats_.get(), clock_); |
Tommi | 733b547 | 2016-06-10 15:58:01 | [diff] [blame] | 943 | |
| 944 | const webrtc::VideoReceiveStream::Config& config = receive_stream->config(); |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 945 | { |
| 946 | WriteLockScoped write_lock(*receive_crit_); |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 947 | if (config.rtp.rtx_ssrc) { |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 948 | // We record identical config for the rtx stream as for the main |
nisse | b8f9a32 | 2017-03-27 12:36:15 | [diff] [blame] | 949 | // stream. Since the transport_send_cc negotiation is per payload |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 950 | // type, we may get an incorrect value for the rtx stream, but |
| 951 | // that is unlikely to matter in practice. |
Erik Språng | 0970851 | 2018-03-14 14:16:50 | [diff] [blame] | 952 | receive_rtp_config_.emplace(config.rtp.rtx_ssrc, |
| 953 | ReceiveRtpConfig(config)); |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 954 | } |
Erik Språng | 0970851 | 2018-03-14 14:16:50 | [diff] [blame] | 955 | receive_rtp_config_.emplace(config.rtp.remote_ssrc, |
| 956 | ReceiveRtpConfig(config)); |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 957 | video_receive_streams_.insert(receive_stream); |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 958 | ConfigureSync(config.sync_group); |
| 959 | } |
| 960 | receive_stream->SignalNetworkState(video_network_state_); |
| 961 | UpdateAggregateNetworkState(); |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 962 | event_log_->Log(absl::make_unique<RtcEventVideoReceiveStreamConfig>( |
Elad Alon | 4a87e1c | 2017-10-03 14:11:34 | [diff] [blame] | 963 | CreateRtcLogStreamConfig(config))); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 964 | return receive_stream; |
| 965 | } |
| 966 | |
pbos@webrtc.org | 2c46f8d | 2013-11-21 13:49:43 | [diff] [blame] | 967 | void Call::DestroyVideoReceiveStream( |
| 968 | webrtc::VideoReceiveStream* receive_stream) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 | [diff] [blame] | 969 | TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); |
eladalon | f3f5c0e | 2017-08-18 09:47:08 | [diff] [blame] | 970 | RTC_DCHECK_CALLED_SEQUENTIALLY(&configuration_sequence_checker_); |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 971 | RTC_DCHECK(receive_stream != nullptr); |
nisse | e4bcd6d | 2017-05-16 11:47:04 | [diff] [blame] | 972 | VideoReceiveStream* receive_stream_impl = |
| 973 | static_cast<VideoReceiveStream*>(receive_stream); |
| 974 | const VideoReceiveStream::Config& config = receive_stream_impl->config(); |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 975 | { |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 976 | WriteLockScoped write_lock(*receive_crit_); |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 | [diff] [blame] | 977 | // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a |
| 978 | // separate SSRC there can be either one or two. |
nisse | e4bcd6d | 2017-05-16 11:47:04 | [diff] [blame] | 979 | receive_rtp_config_.erase(config.rtp.remote_ssrc); |
| 980 | if (config.rtp.rtx_ssrc) { |
| 981 | receive_rtp_config_.erase(config.rtp.rtx_ssrc); |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 982 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 983 | video_receive_streams_.erase(receive_stream_impl); |
nisse | e4bcd6d | 2017-05-16 11:47:04 | [diff] [blame] | 984 | ConfigureSync(config.sync_group); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 985 | } |
nisse | 4709e89 | 2017-02-07 09:18:43 | [diff] [blame] | 986 | |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 987 | receive_side_cc_.GetRemoteBitrateEstimator(UseSendSideBwe(config)) |
nisse | 4709e89 | 2017-02-07 09:18:43 | [diff] [blame] | 988 | ->RemoveStream(config.rtp.remote_ssrc); |
| 989 | |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 990 | UpdateAggregateNetworkState(); |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 | [diff] [blame] | 991 | delete receive_stream_impl; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 992 | } |
| 993 | |
brandtr | 7250b39 | 2016-12-19 09:13:46 | [diff] [blame] | 994 | FlexfecReceiveStream* Call::CreateFlexfecReceiveStream( |
| 995 | const FlexfecReceiveStream::Config& config) { |
brandtr | 25445d3 | 2016-10-24 06:37:14 | [diff] [blame] | 996 | TRACE_EVENT0("webrtc", "Call::CreateFlexfecReceiveStream"); |
eladalon | f3f5c0e | 2017-08-18 09:47:08 | [diff] [blame] | 997 | RTC_DCHECK_CALLED_SEQUENTIALLY(&configuration_sequence_checker_); |
brandtr | b29e652 | 2016-12-21 14:37:18 | [diff] [blame] | 998 | |
| 999 | RecoveredPacketReceiver* recovered_packet_receiver = this; |
brandtr | 25445d3 | 2016-10-24 06:37:14 | [diff] [blame] | 1000 | |
nisse | 0f15f92 | 2017-06-21 08:05:22 | [diff] [blame] | 1001 | FlexfecReceiveStreamImpl* receive_stream; |
brandtr | 25445d3 | 2016-10-24 06:37:14 | [diff] [blame] | 1002 | { |
| 1003 | WriteLockScoped write_lock(*receive_crit_); |
nisse | 0f15f92 | 2017-06-21 08:05:22 | [diff] [blame] | 1004 | // Unlike the video and audio receive streams, |
| 1005 | // FlexfecReceiveStream implements RtpPacketSinkInterface itself, |
| 1006 | // and hence its constructor passes its |this| pointer to |
eladalon | 2a2b297 | 2017-07-03 16:25:27 | [diff] [blame] | 1007 | // video_receiver_controller_->CreateStream(). Calling the |
nisse | 0f15f92 | 2017-06-21 08:05:22 | [diff] [blame] | 1008 | // constructor while holding |receive_crit_| ensures that we don't |
| 1009 | // call OnRtpPacket until the constructor is finished and the |
| 1010 | // object is in a valid state. |
| 1011 | // TODO(nisse): Fix constructor so that it can be moved outside of |
| 1012 | // this locked scope. |
| 1013 | receive_stream = new FlexfecReceiveStreamImpl( |
Sebastian Jansson | 8026d60 | 2019-03-04 18:39:01 | [diff] [blame] | 1014 | clock_, &video_receiver_controller_, config, recovered_packet_receiver, |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 1015 | call_stats_.get(), module_process_thread_.get()); |
brandtr | b29e652 | 2016-12-21 14:37:18 | [diff] [blame] | 1016 | |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 1017 | RTC_DCHECK(receive_rtp_config_.find(config.remote_ssrc) == |
| 1018 | receive_rtp_config_.end()); |
Erik Språng | 0970851 | 2018-03-14 14:16:50 | [diff] [blame] | 1019 | receive_rtp_config_.emplace(config.remote_ssrc, ReceiveRtpConfig(config)); |
brandtr | 25445d3 | 2016-10-24 06:37:14 | [diff] [blame] | 1020 | } |
brandtr | b29e652 | 2016-12-21 14:37:18 | [diff] [blame] | 1021 | |
brandtr | 25445d3 | 2016-10-24 06:37:14 | [diff] [blame] | 1022 | // TODO(brandtr): Store config in RtcEventLog here. |
brandtr | b29e652 | 2016-12-21 14:37:18 | [diff] [blame] | 1023 | |
brandtr | 25445d3 | 2016-10-24 06:37:14 | [diff] [blame] | 1024 | return receive_stream; |
| 1025 | } |
| 1026 | |
brandtr | 7250b39 | 2016-12-19 09:13:46 | [diff] [blame] | 1027 | void Call::DestroyFlexfecReceiveStream(FlexfecReceiveStream* receive_stream) { |
brandtr | 25445d3 | 2016-10-24 06:37:14 | [diff] [blame] | 1028 | TRACE_EVENT0("webrtc", "Call::DestroyFlexfecReceiveStream"); |
eladalon | f3f5c0e | 2017-08-18 09:47:08 | [diff] [blame] | 1029 | RTC_DCHECK_CALLED_SEQUENTIALLY(&configuration_sequence_checker_); |
brandtr | b29e652 | 2016-12-21 14:37:18 | [diff] [blame] | 1030 | |
brandtr | 25445d3 | 2016-10-24 06:37:14 | [diff] [blame] | 1031 | RTC_DCHECK(receive_stream != nullptr); |
brandtr | 25445d3 | 2016-10-24 06:37:14 | [diff] [blame] | 1032 | { |
| 1033 | WriteLockScoped write_lock(*receive_crit_); |
brandtr | b29e652 | 2016-12-21 14:37:18 | [diff] [blame] | 1034 | |
eladalon | 42f44f9 | 2017-07-25 13:40:06 | [diff] [blame] | 1035 | const FlexfecReceiveStream::Config& config = receive_stream->GetConfig(); |
nisse | 4709e89 | 2017-02-07 09:18:43 | [diff] [blame] | 1036 | uint32_t ssrc = config.remote_ssrc; |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 1037 | receive_rtp_config_.erase(ssrc); |
brandtr | b29e652 | 2016-12-21 14:37:18 | [diff] [blame] | 1038 | |
brandtr | 7250b39 | 2016-12-19 09:13:46 | [diff] [blame] | 1039 | // Remove all SSRCs pointing to the FlexfecReceiveStreamImpl to be |
| 1040 | // destroyed. |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 1041 | receive_side_cc_.GetRemoteBitrateEstimator(UseSendSideBwe(config)) |
nisse | 4709e89 | 2017-02-07 09:18:43 | [diff] [blame] | 1042 | ->RemoveStream(ssrc); |
brandtr | 25445d3 | 2016-10-24 06:37:14 | [diff] [blame] | 1043 | } |
brandtr | b29e652 | 2016-12-21 14:37:18 | [diff] [blame] | 1044 | |
eladalon | 42f44f9 | 2017-07-25 13:40:06 | [diff] [blame] | 1045 | delete receive_stream; |
brandtr | 25445d3 | 2016-10-24 06:37:14 | [diff] [blame] | 1046 | } |
| 1047 | |
Sebastian Jansson | 8f83b42 | 2018-02-21 12:07:13 | [diff] [blame] | 1048 | RtpTransportControllerSendInterface* Call::GetTransportControllerSend() { |
Sebastian Jansson | e625605 | 2018-05-04 12:08:15 | [diff] [blame] | 1049 | return transport_send_ptr_; |
Sebastian Jansson | 8f83b42 | 2018-02-21 12:07:13 | [diff] [blame] | 1050 | } |
| 1051 | |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 | [diff] [blame] | 1052 | Call::Stats Call::GetStats() const { |
solenberg | 5a28939 | 2015-10-19 10:39:20 | [diff] [blame] | 1053 | // TODO(solenberg): Some test cases in EndToEndTest use this from a different |
| 1054 | // thread. Re-enable once that is fixed. |
eladalon | f3f5c0e | 2017-08-18 09:47:08 | [diff] [blame] | 1055 | // RTC_DCHECK_CALLED_SEQUENTIALLY(&configuration_sequence_checker_); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 | [diff] [blame] | 1056 | Stats stats; |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame] | 1057 | // Fetch available send/receive bitrates. |
Peter Boström | 45553ae | 2015-05-08 11:54:38 | [diff] [blame] | 1058 | std::vector<unsigned int> ssrcs; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 | [diff] [blame] | 1059 | uint32_t recv_bandwidth = 0; |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 1060 | receive_side_cc_.GetRemoteBitrateEstimator(false)->LatestEstimate( |
mflodman | a20de20 | 2015-10-19 05:08:19 | [diff] [blame] | 1061 | &ssrcs, &recv_bandwidth); |
Sebastian Jansson | 19704ec | 2018-03-12 14:59:12 | [diff] [blame] | 1062 | |
| 1063 | { |
| 1064 | rtc::CritScope cs(&last_bandwidth_bps_crit_); |
| 1065 | stats.send_bandwidth_bps = last_bandwidth_bps_; |
| 1066 | } |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 | [diff] [blame] | 1067 | stats.recv_bandwidth_bps = recv_bandwidth; |
Sebastian Jansson | a06e919 | 2018-03-07 17:49:55 | [diff] [blame] | 1068 | // TODO(srte): It is unclear if we only want to report queues if network is |
| 1069 | // available. |
| 1070 | { |
| 1071 | rtc::CritScope cs(&aggregate_network_up_crit_); |
Sebastian Jansson | e625605 | 2018-05-04 12:08:15 | [diff] [blame] | 1072 | stats.pacer_delay_ms = aggregate_network_up_ |
| 1073 | ? transport_send_ptr_->GetPacerQueuingDelayMs() |
| 1074 | : 0; |
Sebastian Jansson | a06e919 | 2018-03-07 17:49:55 | [diff] [blame] | 1075 | } |
| 1076 | |
Tommi | 38c5d93 | 2018-03-27 21:11:09 | [diff] [blame] | 1077 | stats.rtt_ms = call_stats_->LastProcessedRtt(); |
sprang | 9c0b551 | 2016-07-06 07:54:28 | [diff] [blame] | 1078 | { |
| 1079 | rtc::CritScope cs(&bitrate_crit_); |
| 1080 | stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_; |
| 1081 | } |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 | [diff] [blame] | 1082 | return stats; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 1083 | } |
| 1084 | |
Alex Narest | 78609d5 | 2017-10-20 08:37:47 | [diff] [blame] | 1085 | void Call::SetBitrateAllocationStrategy( |
| 1086 | std::unique_ptr<rtc::BitrateAllocationStrategy> |
| 1087 | bitrate_allocation_strategy) { |
Sebastian Jansson | e625605 | 2018-05-04 12:08:15 | [diff] [blame] | 1088 | // TODO(srte): This function should be moved to RtpTransportControllerSend |
| 1089 | // when BitrateAllocator is moved there. |
| 1090 | struct Functor { |
| 1091 | void operator()() { |
| 1092 | bitrate_allocator_->SetBitrateAllocationStrategy( |
| 1093 | std::move(bitrate_allocation_strategy_)); |
| 1094 | } |
| 1095 | BitrateAllocator* bitrate_allocator_; |
| 1096 | std::unique_ptr<rtc::BitrateAllocationStrategy> |
| 1097 | bitrate_allocation_strategy_; |
| 1098 | }; |
| 1099 | transport_send_ptr_->GetWorkerQueue()->PostTask(Functor{ |
| 1100 | bitrate_allocator_.get(), std::move(bitrate_allocation_strategy)}); |
Alex Narest | 78609d5 | 2017-10-20 08:37:47 | [diff] [blame] | 1101 | } |
| 1102 | |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 1103 | void Call::SignalChannelNetworkState(MediaType media, NetworkState state) { |
eladalon | f3f5c0e | 2017-08-18 09:47:08 | [diff] [blame] | 1104 | RTC_DCHECK_CALLED_SEQUENTIALLY(&configuration_sequence_checker_); |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 1105 | switch (media) { |
| 1106 | case MediaType::AUDIO: |
| 1107 | audio_network_state_ = state; |
| 1108 | break; |
| 1109 | case MediaType::VIDEO: |
| 1110 | video_network_state_ = state; |
| 1111 | break; |
| 1112 | case MediaType::ANY: |
| 1113 | case MediaType::DATA: |
| 1114 | RTC_NOTREACHED(); |
| 1115 | break; |
| 1116 | } |
| 1117 | |
| 1118 | UpdateAggregateNetworkState(); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 1119 | { |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 1120 | ReadLockScoped read_lock(*send_crit_); |
solenberg | c7a8b08 | 2015-10-16 21:35:07 | [diff] [blame] | 1121 | for (auto& kv : audio_send_ssrcs_) { |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 1122 | kv.second->SignalNetworkState(audio_network_state_); |
solenberg | c7a8b08 | 2015-10-16 21:35:07 | [diff] [blame] | 1123 | } |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 1124 | } |
| 1125 | { |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 1126 | ReadLockScoped read_lock(*receive_crit_); |
nisse | e4bcd6d | 2017-05-16 11:47:04 | [diff] [blame] | 1127 | for (AudioReceiveStream* audio_receive_stream : audio_receive_streams_) { |
| 1128 | audio_receive_stream->SignalNetworkState(audio_network_state_); |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 1129 | } |
nisse | e4bcd6d | 2017-05-16 11:47:04 | [diff] [blame] | 1130 | for (VideoReceiveStream* video_receive_stream : video_receive_streams_) { |
| 1131 | video_receive_stream->SignalNetworkState(video_network_state_); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 1132 | } |
| 1133 | } |
| 1134 | } |
| 1135 | |
Stefan Holmer | 64be7fa | 2018-10-04 13:21:55 | [diff] [blame] | 1136 | void Call::OnAudioTransportOverheadChanged(int transport_overhead_per_packet) { |
| 1137 | ReadLockScoped read_lock(*send_crit_); |
| 1138 | for (auto& kv : audio_send_ssrcs_) { |
| 1139 | kv.second->SetTransportOverhead(transport_overhead_per_packet); |
michaelt | 79e0588 | 2016-11-08 10:50:09 | [diff] [blame] | 1140 | } |
| 1141 | } |
| 1142 | |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 1143 | void Call::UpdateAggregateNetworkState() { |
eladalon | f3f5c0e | 2017-08-18 09:47:08 | [diff] [blame] | 1144 | RTC_DCHECK_CALLED_SEQUENTIALLY(&configuration_sequence_checker_); |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 1145 | |
| 1146 | bool have_audio = false; |
| 1147 | bool have_video = false; |
| 1148 | { |
| 1149 | ReadLockScoped read_lock(*send_crit_); |
Benjamin Wright | 41f9f2c | 2019-03-14 01:03:29 | [diff] [blame] | 1150 | if (!audio_send_ssrcs_.empty()) |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 1151 | have_audio = true; |
Benjamin Wright | 41f9f2c | 2019-03-14 01:03:29 | [diff] [blame] | 1152 | if (!video_send_ssrcs_.empty()) |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 1153 | have_video = true; |
| 1154 | } |
| 1155 | { |
| 1156 | ReadLockScoped read_lock(*receive_crit_); |
Benjamin Wright | 41f9f2c | 2019-03-14 01:03:29 | [diff] [blame] | 1157 | if (!audio_receive_streams_.empty()) |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 1158 | have_audio = true; |
Benjamin Wright | 41f9f2c | 2019-03-14 01:03:29 | [diff] [blame] | 1159 | if (!video_receive_streams_.empty()) |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 1160 | have_video = true; |
| 1161 | } |
| 1162 | |
Sebastian Jansson | a06e919 | 2018-03-07 17:49:55 | [diff] [blame] | 1163 | bool aggregate_network_up = |
| 1164 | ((have_video && video_network_state_ == kNetworkUp) || |
| 1165 | (have_audio && audio_network_state_ == kNetworkUp)); |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 1166 | |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 1167 | RTC_LOG(LS_INFO) << "UpdateAggregateNetworkState: aggregate_state=" |
Sebastian Jansson | a06e919 | 2018-03-07 17:49:55 | [diff] [blame] | 1168 | << (aggregate_network_up ? "up" : "down"); |
| 1169 | { |
| 1170 | rtc::CritScope cs(&aggregate_network_up_crit_); |
| 1171 | aggregate_network_up_ = aggregate_network_up; |
| 1172 | } |
Sebastian Jansson | e625605 | 2018-05-04 12:08:15 | [diff] [blame] | 1173 | transport_send_ptr_->OnNetworkAvailability(aggregate_network_up); |
skvlad | 7a43d25 | 2016-03-22 22:32:27 | [diff] [blame] | 1174 | } |
| 1175 | |
stefan | c1aeaf0 | 2015-10-15 14:26:07 | [diff] [blame] | 1176 | void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { |
asapersson | 35151f3 | 2016-05-03 06:44:01 | [diff] [blame] | 1177 | video_send_delay_stats_->OnSentPacket(sent_packet.packet_id, |
| 1178 | clock_->TimeInMilliseconds()); |
Sebastian Jansson | e625605 | 2018-05-04 12:08:15 | [diff] [blame] | 1179 | transport_send_ptr_->OnSentPacket(sent_packet); |
stefan | c1aeaf0 | 2015-10-15 14:26:07 | [diff] [blame] | 1180 | } |
| 1181 | |
Sebastian Jansson | 2701bc9 | 2018-12-11 14:02:47 | [diff] [blame] | 1182 | void Call::OnStartRateUpdate(DataRate start_rate) { |
| 1183 | if (!transport_send_ptr_->GetWorkerQueue()->IsCurrent()) { |
| 1184 | transport_send_ptr_->GetWorkerQueue()->PostTask( |
| 1185 | [this, start_rate] { this->OnStartRateUpdate(start_rate); }); |
| 1186 | return; |
| 1187 | } |
| 1188 | bitrate_allocator_->UpdateStartRate(start_rate.bps<uint32_t>()); |
| 1189 | } |
| 1190 | |
Sebastian Jansson | 19704ec | 2018-03-12 14:59:12 | [diff] [blame] | 1191 | void Call::OnTargetTransferRate(TargetTransferRate msg) { |
Piotr (Peter) Slatala | cc8e8bb | 2018-11-15 16:26:19 | [diff] [blame] | 1192 | // TODO(bugs.webrtc.org/9719) |
| 1193 | // Call::OnTargetTransferRate requires that on target transfer rate is invoked |
| 1194 | // from the worker queue (because bitrate_allocator_ requires it). Media |
| 1195 | // transport does not guarantee the callback on the worker queue. |
| 1196 | // When the threading model for MediaTransportInterface is update, reconsider |
| 1197 | // changing this implementation. |
| 1198 | if (!transport_send_ptr_->GetWorkerQueue()->IsCurrent()) { |
| 1199 | transport_send_ptr_->GetWorkerQueue()->PostTask( |
| 1200 | [this, msg] { this->OnTargetTransferRate(msg); }); |
| 1201 | return; |
| 1202 | } |
| 1203 | |
Sebastian Jansson | 19704ec | 2018-03-12 14:59:12 | [diff] [blame] | 1204 | uint32_t target_bitrate_bps = msg.target_rate.bps(); |
| 1205 | int loss_ratio_255 = msg.network_estimate.loss_rate_ratio * 255; |
| 1206 | uint8_t fraction_loss = |
| 1207 | rtc::dchecked_cast<uint8_t>(rtc::SafeClamp(loss_ratio_255, 0, 255)); |
| 1208 | int64_t rtt_ms = msg.network_estimate.round_trip_time.ms(); |
| 1209 | int64_t probing_interval_ms = msg.network_estimate.bwe_period.ms(); |
| 1210 | uint32_t bandwidth_bps = msg.network_estimate.bandwidth.bps(); |
| 1211 | { |
| 1212 | rtc::CritScope cs(&last_bandwidth_bps_crit_); |
| 1213 | last_bandwidth_bps_ = bandwidth_bps; |
| 1214 | } |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 1215 | // For controlling the rate of feedback messages. |
| 1216 | receive_side_cc_.OnBitrateChanged(target_bitrate_bps); |
Sebastian Jansson | 89c94b9 | 2018-11-20 16:16:36 | [diff] [blame] | 1217 | bitrate_allocator_->OnNetworkChanged(target_bitrate_bps, bandwidth_bps, |
| 1218 | fraction_loss, rtt_ms, |
| 1219 | probing_interval_ms); |
mflodman | 0e7e259 | 2015-11-13 05:02:42 | [diff] [blame] | 1220 | |
asapersson | ce2e136 | 2016-09-09 07:13:35 | [diff] [blame] | 1221 | // Ignore updates if bitrate is zero (the aggregate network state is down). |
| 1222 | if (target_bitrate_bps == 0) { |
stefan | 18adf0a | 2015-11-17 14:24:56 | [diff] [blame] | 1223 | rtc::CritScope lock(&bitrate_crit_); |
asapersson | ce2e136 | 2016-09-09 07:13:35 | [diff] [blame] | 1224 | estimated_send_bitrate_kbps_counter_.ProcessAndPause(); |
| 1225 | pacer_bitrate_kbps_counter_.ProcessAndPause(); |
| 1226 | return; |
stefan | 18adf0a | 2015-11-17 14:24:56 | [diff] [blame] | 1227 | } |
asapersson | ce2e136 | 2016-09-09 07:13:35 | [diff] [blame] | 1228 | |
| 1229 | bool sending_video; |
| 1230 | { |
| 1231 | ReadLockScoped read_lock(*send_crit_); |
| 1232 | sending_video = !video_send_streams_.empty(); |
| 1233 | } |
| 1234 | |
| 1235 | rtc::CritScope lock(&bitrate_crit_); |
| 1236 | if (!sending_video) { |
| 1237 | // Do not update the stats if we are not sending video. |
| 1238 | estimated_send_bitrate_kbps_counter_.ProcessAndPause(); |
| 1239 | pacer_bitrate_kbps_counter_.ProcessAndPause(); |
| 1240 | return; |
| 1241 | } |
| 1242 | estimated_send_bitrate_kbps_counter_.Add(target_bitrate_bps / 1000); |
| 1243 | // Pacer bitrate may be higher than bitrate estimate if enforcing min bitrate. |
| 1244 | uint32_t pacer_bitrate_bps = |
| 1245 | std::max(target_bitrate_bps, min_allocated_send_bitrate_bps_); |
| 1246 | pacer_bitrate_kbps_counter_.Add(pacer_bitrate_bps / 1000); |
perkj | 71ee44c | 2016-06-15 07:47:53 | [diff] [blame] | 1247 | } |
mflodman | 101f250 | 2016-06-09 15:21:19 | [diff] [blame] | 1248 | |
perkj | 71ee44c | 2016-06-15 07:47:53 | [diff] [blame] | 1249 | void Call::OnAllocationLimitsChanged(uint32_t min_send_bitrate_bps, |
philipel | f69e768 | 2018-02-28 12:06:28 | [diff] [blame] | 1250 | uint32_t max_padding_bitrate_bps, |
Sebastian Jansson | 79f0d4d | 2019-01-23 08:41:43 | [diff] [blame] | 1251 | uint32_t total_bitrate_bps) { |
Sebastian Jansson | e625605 | 2018-05-04 12:08:15 | [diff] [blame] | 1252 | transport_send_ptr_->SetAllocatedSendBitrateLimits( |
Oleh Prypin | 04d4950 | 2018-03-19 13:29:42 | [diff] [blame] | 1253 | min_send_bitrate_bps, max_padding_bitrate_bps, total_bitrate_bps); |
Sebastian Jansson | 35fa280 | 2018-10-01 07:16:12 | [diff] [blame] | 1254 | |
Piotr (Peter) Slatala | 48c5493 | 2019-01-28 14:50:38 | [diff] [blame] | 1255 | { |
| 1256 | rtc::CritScope lock(&target_observer_crit_); |
| 1257 | if (media_transport_) { |
| 1258 | MediaTransportAllocatedBitrateLimits limits; |
| 1259 | limits.min_pacing_rate = DataRate::bps(min_send_bitrate_bps); |
| 1260 | limits.max_padding_bitrate = DataRate::bps(max_padding_bitrate_bps); |
| 1261 | limits.max_total_allocated_bitrate = DataRate::bps(total_bitrate_bps); |
| 1262 | media_transport_->SetAllocatedBitrateLimits(limits); |
| 1263 | } |
| 1264 | } |
| 1265 | |
perkj | 71ee44c | 2016-06-15 07:47:53 | [diff] [blame] | 1266 | rtc::CritScope lock(&bitrate_crit_); |
| 1267 | min_allocated_send_bitrate_bps_ = min_send_bitrate_bps; |
sprang | 9c0b551 | 2016-07-06 07:54:28 | [diff] [blame] | 1268 | configured_max_padding_bitrate_bps_ = max_padding_bitrate_bps; |
mflodman | 0e7e259 | 2015-11-13 05:02:42 | [diff] [blame] | 1269 | } |
| 1270 | |
pbos | 8fc7fa7 | 2015-07-15 15:02:58 | [diff] [blame] | 1271 | void Call::ConfigureSync(const std::string& sync_group) { |
| 1272 | // Set sync only if there was no previous one. |
solenberg | 3ebbcb5 | 2017-01-31 11:58:40 | [diff] [blame] | 1273 | if (sync_group.empty()) |
pbos | 8fc7fa7 | 2015-07-15 15:02:58 | [diff] [blame] | 1274 | return; |
| 1275 | |
| 1276 | AudioReceiveStream* sync_audio_stream = nullptr; |
| 1277 | // Find existing audio stream. |
| 1278 | const auto it = sync_stream_mapping_.find(sync_group); |
| 1279 | if (it != sync_stream_mapping_.end()) { |
| 1280 | sync_audio_stream = it->second; |
| 1281 | } else { |
| 1282 | // No configured audio stream, see if we can find one. |
nisse | e4bcd6d | 2017-05-16 11:47:04 | [diff] [blame] | 1283 | for (AudioReceiveStream* stream : audio_receive_streams_) { |
| 1284 | if (stream->config().sync_group == sync_group) { |
pbos | 8fc7fa7 | 2015-07-15 15:02:58 | [diff] [blame] | 1285 | if (sync_audio_stream != nullptr) { |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 1286 | RTC_LOG(LS_WARNING) |
| 1287 | << "Attempting to sync more than one audio stream " |
| 1288 | "within the same sync group. This is not " |
| 1289 | "supported in the current implementation."; |
pbos | 8fc7fa7 | 2015-07-15 15:02:58 | [diff] [blame] | 1290 | break; |
| 1291 | } |
nisse | e4bcd6d | 2017-05-16 11:47:04 | [diff] [blame] | 1292 | sync_audio_stream = stream; |
pbos | 8fc7fa7 | 2015-07-15 15:02:58 | [diff] [blame] | 1293 | } |
| 1294 | } |
| 1295 | } |
| 1296 | if (sync_audio_stream) |
| 1297 | sync_stream_mapping_[sync_group] = sync_audio_stream; |
| 1298 | size_t num_synced_streams = 0; |
| 1299 | for (VideoReceiveStream* video_stream : video_receive_streams_) { |
| 1300 | if (video_stream->config().sync_group != sync_group) |
| 1301 | continue; |
| 1302 | ++num_synced_streams; |
| 1303 | if (num_synced_streams > 1) { |
| 1304 | // TODO(pbos): Support synchronizing more than one A/V pair. |
| 1305 | // https://code.google.com/p/webrtc/issues/detail?id=4762 |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 1306 | RTC_LOG(LS_WARNING) |
| 1307 | << "Attempting to sync more than one audio/video pair " |
| 1308 | "within the same sync group. This is not supported in " |
| 1309 | "the current implementation."; |
pbos | 8fc7fa7 | 2015-07-15 15:02:58 | [diff] [blame] | 1310 | } |
| 1311 | // Only sync the first A/V pair within this sync group. |
solenberg | 3ebbcb5 | 2017-01-31 11:58:40 | [diff] [blame] | 1312 | if (num_synced_streams == 1) { |
| 1313 | // sync_audio_stream may be null and that's ok. |
| 1314 | video_stream->SetSync(sync_audio_stream); |
pbos | 8fc7fa7 | 2015-07-15 15:02:58 | [diff] [blame] | 1315 | } else { |
solenberg | 3ebbcb5 | 2017-01-31 11:58:40 | [diff] [blame] | 1316 | video_stream->SetSync(nullptr); |
pbos | 8fc7fa7 | 2015-07-15 15:02:58 | [diff] [blame] | 1317 | } |
| 1318 | } |
| 1319 | } |
| 1320 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 1321 | PacketReceiver::DeliveryStatus Call::DeliverRtcp(MediaType media_type, |
| 1322 | const uint8_t* packet, |
| 1323 | size_t length) { |
Peter Boström | 6f28cf0 | 2015-12-07 22:17:15 | [diff] [blame] | 1324 | TRACE_EVENT0("webrtc", "Call::DeliverRtcp"); |
mflodman | 3d7db26 | 2016-04-29 07:57:13 | [diff] [blame] | 1325 | // TODO(pbos): Make sure it's a valid packet. |
pbos@webrtc.org | caba2d2 | 2014-05-14 13:57:12 | [diff] [blame] | 1326 | // Return DELIVERY_UNKNOWN_SSRC if it can be determined that |
| 1327 | // there's no receiver of the packet. |
asapersson | 250fd97 | 2016-09-08 07:07:21 | [diff] [blame] | 1328 | if (received_bytes_per_second_counter_.HasSample()) { |
| 1329 | // First RTP packet has been received. |
| 1330 | received_bytes_per_second_counter_.Add(static_cast<int>(length)); |
| 1331 | received_rtcp_bytes_per_second_counter_.Add(static_cast<int>(length)); |
| 1332 | } |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 1333 | bool rtcp_delivered = false; |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 1334 | if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 1335 | ReadLockScoped read_lock(*receive_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 1336 | for (VideoReceiveStream* stream : video_receive_streams_) { |
mflodman | 3d7db26 | 2016-04-29 07:57:13 | [diff] [blame] | 1337 | if (stream->DeliverRtcp(packet, length)) |
pbos@webrtc.org | 4052370 | 2013-08-05 12:49:22 | [diff] [blame] | 1338 | rtcp_delivered = true; |
mflodman | 3d7db26 | 2016-04-29 07:57:13 | [diff] [blame] | 1339 | } |
| 1340 | } |
| 1341 | if (media_type == MediaType::ANY || media_type == MediaType::AUDIO) { |
| 1342 | ReadLockScoped read_lock(*receive_crit_); |
nisse | e4bcd6d | 2017-05-16 11:47:04 | [diff] [blame] | 1343 | for (AudioReceiveStream* stream : audio_receive_streams_) { |
Niels Möller | 8fb1a6a | 2019-03-05 13:29:42 | [diff] [blame] | 1344 | stream->DeliverRtcp(packet, length); |
| 1345 | rtcp_delivered = true; |
pbos@webrtc.org | bbb07e6 | 2013-08-05 12:01:36 | [diff] [blame] | 1346 | } |
| 1347 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 1348 | if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 | [diff] [blame] | 1349 | ReadLockScoped read_lock(*send_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 1350 | for (VideoSendStream* stream : video_send_streams_) { |
Niels Möller | 8fb1a6a | 2019-03-05 13:29:42 | [diff] [blame] | 1351 | stream->DeliverRtcp(packet, length); |
| 1352 | rtcp_delivered = true; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 1353 | } |
| 1354 | } |
mflodman | 3d7db26 | 2016-04-29 07:57:13 | [diff] [blame] | 1355 | if (media_type == MediaType::ANY || media_type == MediaType::AUDIO) { |
| 1356 | ReadLockScoped read_lock(*send_crit_); |
| 1357 | for (auto& kv : audio_send_ssrcs_) { |
Niels Möller | 8fb1a6a | 2019-03-05 13:29:42 | [diff] [blame] | 1358 | kv.second->DeliverRtcp(packet, length); |
| 1359 | rtcp_delivered = true; |
mflodman | 3d7db26 | 2016-04-29 07:57:13 | [diff] [blame] | 1360 | } |
| 1361 | } |
| 1362 | |
Elad Alon | 4a87e1c | 2017-10-03 14:11:34 | [diff] [blame] | 1363 | if (rtcp_delivered) { |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 1364 | event_log_->Log(absl::make_unique<RtcEventRtcpPacketIncoming>( |
Elad Alon | 4a87e1c | 2017-10-03 14:11:34 | [diff] [blame] | 1365 | rtc::MakeArrayView(packet, length))); |
| 1366 | } |
mflodman | 3d7db26 | 2016-04-29 07:57:13 | [diff] [blame] | 1367 | |
pbos@webrtc.org | caba2d2 | 2014-05-14 13:57:12 | [diff] [blame] | 1368 | return rtcp_delivered ? DELIVERY_OK : DELIVERY_PACKET_ERROR; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 1369 | } |
| 1370 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 1371 | PacketReceiver::DeliveryStatus Call::DeliverRtp(MediaType media_type, |
Danil Chapovalov | 292a73e | 2017-12-07 16:00:40 | [diff] [blame] | 1372 | rtc::CopyOnWriteBuffer packet, |
Niels Möller | 7008287 | 2018-08-07 09:03:12 | [diff] [blame] | 1373 | int64_t packet_time_us) { |
Peter Boström | 6f28cf0 | 2015-12-07 22:17:15 | [diff] [blame] | 1374 | TRACE_EVENT0("webrtc", "Call::DeliverRtp"); |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 1375 | |
Danil Chapovalov | b709cf8 | 2017-10-04 12:01:45 | [diff] [blame] | 1376 | RtpPacketReceived parsed_packet; |
Danil Chapovalov | 292a73e | 2017-12-07 16:00:40 | [diff] [blame] | 1377 | if (!parsed_packet.Parse(std::move(packet))) |
Danil Chapovalov | b709cf8 | 2017-10-04 12:01:45 | [diff] [blame] | 1378 | return DELIVERY_PACKET_ERROR; |
| 1379 | |
Niels Möller | 7008287 | 2018-08-07 09:03:12 | [diff] [blame] | 1380 | if (packet_time_us != -1) { |
Sebastian Jansson | b34556e | 2018-03-21 13:38:32 | [diff] [blame] | 1381 | if (receive_time_calculator_) { |
Christoffer Rodbro | 992a868 | 2018-10-30 14:14:36 | [diff] [blame] | 1382 | // Repair packet_time_us for clock resets by comparing a new read of |
| 1383 | // the same clock (TimeUTCMicros) to a monotonic clock reading. |
Niels Möller | 7008287 | 2018-08-07 09:03:12 | [diff] [blame] | 1384 | packet_time_us = receive_time_calculator_->ReconcileReceiveTimes( |
Christoffer Rodbro | 992a868 | 2018-10-30 14:14:36 | [diff] [blame] | 1385 | packet_time_us, rtc::TimeUTCMicros(), clock_->TimeInMicroseconds()); |
Sebastian Jansson | b34556e | 2018-03-21 13:38:32 | [diff] [blame] | 1386 | } |
Niels Möller | 7008287 | 2018-08-07 09:03:12 | [diff] [blame] | 1387 | parsed_packet.set_arrival_time_ms((packet_time_us + 500) / 1000); |
Danil Chapovalov | b709cf8 | 2017-10-04 12:01:45 | [diff] [blame] | 1388 | } else { |
| 1389 | parsed_packet.set_arrival_time_ms(clock_->TimeInMilliseconds()); |
| 1390 | } |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 1391 | |
sprang | c1abde7 | 2017-07-11 10:56:21 | [diff] [blame] | 1392 | // We might get RTP keep-alive packets in accordance with RFC6263 section 4.6. |
| 1393 | // These are empty (zero length payload) RTP packets with an unsignaled |
| 1394 | // payload type. |
Danil Chapovalov | b709cf8 | 2017-10-04 12:01:45 | [diff] [blame] | 1395 | const bool is_keep_alive_packet = parsed_packet.payload_size() == 0; |
sprang | c1abde7 | 2017-07-11 10:56:21 | [diff] [blame] | 1396 | |
| 1397 | RTC_DCHECK(media_type == MediaType::AUDIO || media_type == MediaType::VIDEO || |
| 1398 | is_keep_alive_packet); |
| 1399 | |
sprang | c1abde7 | 2017-07-11 10:56:21 | [diff] [blame] | 1400 | ReadLockScoped read_lock(*receive_crit_); |
Danil Chapovalov | b709cf8 | 2017-10-04 12:01:45 | [diff] [blame] | 1401 | auto it = receive_rtp_config_.find(parsed_packet.Ssrc()); |
nisse | 0f15f92 | 2017-06-21 08:05:22 | [diff] [blame] | 1402 | if (it == receive_rtp_config_.end()) { |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 1403 | RTC_LOG(LS_ERROR) << "receive_rtp_config_ lookup failed for ssrc " |
| 1404 | << parsed_packet.Ssrc(); |
nisse | 0f15f92 | 2017-06-21 08:05:22 | [diff] [blame] | 1405 | // Destruction of the receive stream, including deregistering from the |
| 1406 | // RtpDemuxer, is not protected by the |receive_crit_| lock. But |
| 1407 | // deregistering in the |receive_rtp_config_| map is protected by that lock. |
| 1408 | // So by not passing the packet on to demuxing in this case, we prevent |
| 1409 | // incoming packets to be passed on via the demuxer to a receive stream |
| 1410 | // which is being torned down. |
| 1411 | return DELIVERY_UNKNOWN_SSRC; |
| 1412 | } |
Jonas Oreland | 6d83592 | 2019-03-18 09:59:40 | [diff] [blame] | 1413 | |
Danil Chapovalov | b709cf8 | 2017-10-04 12:01:45 | [diff] [blame] | 1414 | parsed_packet.IdentifyExtensions(it->second.extensions); |
nisse | 0f15f92 | 2017-06-21 08:05:22 | [diff] [blame] | 1415 | |
Danil Chapovalov | b709cf8 | 2017-10-04 12:01:45 | [diff] [blame] | 1416 | NotifyBweOfReceivedPacket(parsed_packet, media_type); |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 1417 | |
Danil Chapovalov | cbf5b73 | 2017-12-08 13:05:20 | [diff] [blame] | 1418 | // RateCounters expect input parameter as int, save it as int, |
| 1419 | // instead of converting each time it is passed to RateCounter::Add below. |
| 1420 | int length = static_cast<int>(parsed_packet.size()); |
nisse | e5ad5ca | 2017-03-30 06:57:43 | [diff] [blame] | 1421 | if (media_type == MediaType::AUDIO) { |
Danil Chapovalov | b709cf8 | 2017-10-04 12:01:45 | [diff] [blame] | 1422 | if (audio_receiver_controller_.OnRtpPacket(parsed_packet)) { |
Danil Chapovalov | 292a73e | 2017-12-07 16:00:40 | [diff] [blame] | 1423 | received_bytes_per_second_counter_.Add(length); |
| 1424 | received_audio_bytes_per_second_counter_.Add(length); |
Elad Alon | 4a87e1c | 2017-10-03 14:11:34 | [diff] [blame] | 1425 | event_log_->Log( |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 1426 | absl::make_unique<RtcEventRtpPacketIncoming>(parsed_packet)); |
Danil Chapovalov | b709cf8 | 2017-10-04 12:01:45 | [diff] [blame] | 1427 | const int64_t arrival_time_ms = parsed_packet.arrival_time_ms(); |
saza | 0d7f04d | 2017-07-04 11:05:06 | [diff] [blame] | 1428 | if (!first_received_rtp_audio_ms_) { |
| 1429 | first_received_rtp_audio_ms_.emplace(arrival_time_ms); |
| 1430 | } |
| 1431 | last_received_rtp_audio_ms_.emplace(arrival_time_ms); |
nisse | 657bab2 | 2017-02-21 14:28:10 | [diff] [blame] | 1432 | return DELIVERY_OK; |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 1433 | } |
nisse | e4bcd6d | 2017-05-16 11:47:04 | [diff] [blame] | 1434 | } else if (media_type == MediaType::VIDEO) { |
Niels Möller | 2ff1f2a | 2018-08-09 14:16:34 | [diff] [blame] | 1435 | parsed_packet.set_payload_type_frequency(kVideoPayloadTypeFrequency); |
Danil Chapovalov | b709cf8 | 2017-10-04 12:01:45 | [diff] [blame] | 1436 | if (video_receiver_controller_.OnRtpPacket(parsed_packet)) { |
Danil Chapovalov | 292a73e | 2017-12-07 16:00:40 | [diff] [blame] | 1437 | received_bytes_per_second_counter_.Add(length); |
| 1438 | received_video_bytes_per_second_counter_.Add(length); |
Elad Alon | 4a87e1c | 2017-10-03 14:11:34 | [diff] [blame] | 1439 | event_log_->Log( |
Karl Wiberg | 918f50c | 2018-07-05 09:40:33 | [diff] [blame] | 1440 | absl::make_unique<RtcEventRtpPacketIncoming>(parsed_packet)); |
Danil Chapovalov | b709cf8 | 2017-10-04 12:01:45 | [diff] [blame] | 1441 | const int64_t arrival_time_ms = parsed_packet.arrival_time_ms(); |
saza | 0d7f04d | 2017-07-04 11:05:06 | [diff] [blame] | 1442 | if (!first_received_rtp_video_ms_) { |
| 1443 | first_received_rtp_video_ms_.emplace(arrival_time_ms); |
| 1444 | } |
| 1445 | last_received_rtp_video_ms_.emplace(arrival_time_ms); |
nisse | 5c29a7a | 2017-02-16 14:52:32 | [diff] [blame] | 1446 | return DELIVERY_OK; |
Fredrik Solenberg | 23fba1f | 2015-04-29 13:24:01 | [diff] [blame] | 1447 | } |
| 1448 | } |
| 1449 | return DELIVERY_UNKNOWN_SSRC; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 1450 | } |
| 1451 | |
stefan | 68786d2 | 2015-09-08 12:36:15 | [diff] [blame] | 1452 | PacketReceiver::DeliveryStatus Call::DeliverPacket( |
| 1453 | MediaType media_type, |
Danil Chapovalov | 292a73e | 2017-12-07 16:00:40 | [diff] [blame] | 1454 | rtc::CopyOnWriteBuffer packet, |
Niels Möller | 7008287 | 2018-08-07 09:03:12 | [diff] [blame] | 1455 | int64_t packet_time_us) { |
eladalon | d1dd2f7 | 2017-08-25 09:55:57 | [diff] [blame] | 1456 | RTC_DCHECK_CALLED_SEQUENTIALLY(&configuration_sequence_checker_); |
Danil Chapovalov | 292a73e | 2017-12-07 16:00:40 | [diff] [blame] | 1457 | if (RtpHeaderParser::IsRtcp(packet.cdata(), packet.size())) |
| 1458 | return DeliverRtcp(media_type, packet.cdata(), packet.size()); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 1459 | |
Niels Möller | 7008287 | 2018-08-07 09:03:12 | [diff] [blame] | 1460 | return DeliverRtp(media_type, std::move(packet), packet_time_us); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 1461 | } |
| 1462 | |
nisse | d2ef314 | 2017-05-11 15:00:58 | [diff] [blame] | 1463 | void Call::OnRecoveredPacket(const uint8_t* packet, size_t length) { |
Danil Chapovalov | b709cf8 | 2017-10-04 12:01:45 | [diff] [blame] | 1464 | RtpPacketReceived parsed_packet; |
| 1465 | if (!parsed_packet.Parse(packet, length)) |
nisse | d2ef314 | 2017-05-11 15:00:58 | [diff] [blame] | 1466 | return; |
| 1467 | |
Danil Chapovalov | b709cf8 | 2017-10-04 12:01:45 | [diff] [blame] | 1468 | parsed_packet.set_recovered(true); |
nisse | d2ef314 | 2017-05-11 15:00:58 | [diff] [blame] | 1469 | |
brandtr | caea68f | 2017-08-23 07:55:17 | [diff] [blame] | 1470 | ReadLockScoped read_lock(*receive_crit_); |
Danil Chapovalov | b709cf8 | 2017-10-04 12:01:45 | [diff] [blame] | 1471 | auto it = receive_rtp_config_.find(parsed_packet.Ssrc()); |
brandtr | caea68f | 2017-08-23 07:55:17 | [diff] [blame] | 1472 | if (it == receive_rtp_config_.end()) { |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 1473 | RTC_LOG(LS_ERROR) << "receive_rtp_config_ lookup failed for ssrc " |
| 1474 | << parsed_packet.Ssrc(); |
brandtr | caea68f | 2017-08-23 07:55:17 | [diff] [blame] | 1475 | // Destruction of the receive stream, including deregistering from the |
| 1476 | // RtpDemuxer, is not protected by the |receive_crit_| lock. But |
| 1477 | // deregistering in the |receive_rtp_config_| map is protected by that lock. |
| 1478 | // So by not passing the packet on to demuxing in this case, we prevent |
| 1479 | // incoming packets to be passed on via the demuxer to a receive stream |
Erik Språng | 0970851 | 2018-03-14 14:16:50 | [diff] [blame] | 1480 | // which is being torn down. |
brandtr | caea68f | 2017-08-23 07:55:17 | [diff] [blame] | 1481 | return; |
| 1482 | } |
Danil Chapovalov | b709cf8 | 2017-10-04 12:01:45 | [diff] [blame] | 1483 | parsed_packet.IdentifyExtensions(it->second.extensions); |
brandtr | caea68f | 2017-08-23 07:55:17 | [diff] [blame] | 1484 | |
| 1485 | // TODO(brandtr): Update here when we support protecting audio packets too. |
Niels Möller | 2ff1f2a | 2018-08-09 14:16:34 | [diff] [blame] | 1486 | parsed_packet.set_payload_type_frequency(kVideoPayloadTypeFrequency); |
Danil Chapovalov | b709cf8 | 2017-10-04 12:01:45 | [diff] [blame] | 1487 | video_receiver_controller_.OnRtpPacket(parsed_packet); |
brandtr | 4e52386 | 2016-10-19 06:50:45 | [diff] [blame] | 1488 | } |
| 1489 | |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 1490 | void Call::NotifyBweOfReceivedPacket(const RtpPacketReceived& packet, |
| 1491 | MediaType media_type) { |
| 1492 | auto it = receive_rtp_config_.find(packet.Ssrc()); |
nisse | 4709e89 | 2017-02-07 09:18:43 | [diff] [blame] | 1493 | bool use_send_side_bwe = |
| 1494 | (it != receive_rtp_config_.end()) && it->second.use_send_side_bwe; |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 1495 | |
brandtr | b29e652 | 2016-12-21 14:37:18 | [diff] [blame] | 1496 | RTPHeader header; |
| 1497 | packet.GetHeader(&header); |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 1498 | |
nisse | 4709e89 | 2017-02-07 09:18:43 | [diff] [blame] | 1499 | if (!use_send_side_bwe && header.extension.hasTransportSequenceNumber) { |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 1500 | // Inconsistent configuration of send side BWE. Do nothing. |
| 1501 | // TODO(nisse): Without this check, we may produce RTCP feedback |
| 1502 | // packets even when not negotiated. But it would be cleaner to |
| 1503 | // move the check down to RTCPSender::SendFeedbackPacket, which |
| 1504 | // would also help the PacketRouter to select an appropriate rtp |
| 1505 | // module in the case that some, but not all, have RTCP feedback |
| 1506 | // enabled. |
| 1507 | return; |
| 1508 | } |
| 1509 | // For audio, we only support send side BWE. |
nisse | e5ad5ca | 2017-03-30 06:57:43 | [diff] [blame] | 1510 | if (media_type == MediaType::VIDEO || |
nisse | 4709e89 | 2017-02-07 09:18:43 | [diff] [blame] | 1511 | (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) { |
nisse | 559af38 | 2017-03-21 13:41:12 | [diff] [blame] | 1512 | receive_side_cc_.OnReceivedPacket( |
nisse | d44ce05 | 2017-02-06 10:23:00 | [diff] [blame] | 1513 | packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(), |
| 1514 | header); |
| 1515 | } |
brandtr | b29e652 | 2016-12-21 14:37:18 | [diff] [blame] | 1516 | } |
| 1517 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 1518 | } // namespace internal |
nisse | b8f9a32 | 2017-03-27 12:36:15 | [diff] [blame] | 1519 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 | [diff] [blame] | 1520 | } // namespace webrtc |