blob: e2d896249c6191ad8293b3d02f17b970344bfbc5 [file] [log] [blame]
pbos@webrtc.org29d58392013-05-16 12:08:031/*
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
Jonas Olssona4d87372019-07-05 17:08:3311#include "call/call.h"
12
pbos@webrtc.org12dc1a32013-08-05 16:22:5313#include <string.h>
Jonas Olssona4d87372019-07-05 17:08:3314
mflodman101f2502016-06-09 15:21:1915#include <algorithm>
pbos@webrtc.org29d58392013-05-16 12:08:0316#include <map>
kwibergb25345e2016-03-12 14:10:4417#include <memory>
ossuf515ab82016-12-07 12:52:5818#include <set>
brandtr25445d32016-10-24 06:37:1419#include <utility>
pbos@webrtc.org29d58392013-05-16 12:08:0320#include <vector>
21
Danil Chapovalovb9b146c2018-06-15 10:28:0722#include "absl/types/optional.h"
Danil Chapovalov83bbe912019-08-07 10:24:5323#include "api/rtc_event_log/rtc_event_log.h"
Sebastian Janssonc6c44262018-05-09 08:33:3924#include "api/transport/network_control.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3125#include "audio/audio_receive_stream.h"
26#include "audio/audio_send_stream.h"
27#include "audio/audio_state.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3128#include "call/bitrate_allocator.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3129#include "call/flexfec_receive_stream_impl.h"
Sebastian Janssonb34556e2018-03-21 13:38:3230#include "call/receive_time_calculator.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3131#include "call/rtp_stream_receiver_controller.h"
32#include "call/rtp_transport_controller_send.h"
Elad Alon4a87e1c2017-10-03 14:11:3433#include "logging/rtc_event_log/events/rtc_event_audio_receive_stream_config.h"
Elad Alon4a87e1c2017-10-03 14:11:3434#include "logging/rtc_event_log/events/rtc_event_rtcp_packet_incoming.h"
35#include "logging/rtc_event_log/events/rtc_event_rtp_packet_incoming.h"
36#include "logging/rtc_event_log/events/rtc_event_video_receive_stream_config.h"
37#include "logging/rtc_event_log/events/rtc_event_video_send_stream_config.h"
Elad Alon99a81b62017-09-21 08:25:2938#include "logging/rtc_event_log/rtc_stream_config.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3139#include "modules/congestion_controller/include/receive_side_congestion_controller.h"
40#include "modules/rtp_rtcp/include/flexfec_receiver.h"
41#include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3142#include "modules/rtp_rtcp/source/byte_io.h"
43#include "modules/rtp_rtcp/source/rtp_packet_received.h"
Tommi25eb47c2019-08-29 14:39:0544#include "modules/rtp_rtcp/source/rtp_utility.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3145#include "modules/utility/include/process_thread.h"
Ying Wang3b790f32018-01-19 16:58:5746#include "modules/video_coding/fec_controller_default.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3147#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 17:11:0048#include "rtc_base/constructor_magic.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3149#include "rtc_base/location.h"
50#include "rtc_base/logging.h"
Jonas Olsson0a713b62018-04-04 13:49:3251#include "rtc_base/strings/string_builder.h"
Sebastian Janssonc6c44262018-05-09 08:33:3952#include "rtc_base/synchronization/rw_lock_wrapper.h"
Sebastian Janssonb55015e2019-04-09 11:44:0453#include "rtc_base/synchronization/sequence_checker.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3154#include "rtc_base/thread_annotations.h"
Steve Anton10542f22019-01-11 17:11:0055#include "rtc_base/time_utils.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3156#include "rtc_base/trace_event.h"
57#include "system_wrappers/include/clock.h"
58#include "system_wrappers/include/cpu_info.h"
Jonas Oreland6d835922019-03-18 09:59:4059#include "system_wrappers/include/field_trial.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3160#include "system_wrappers/include/metrics.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3161#include "video/call_stats.h"
62#include "video/send_delay_stats.h"
63#include "video/stats_counter.h"
64#include "video/video_receive_stream.h"
65#include "video/video_send_stream.h"
pbos@webrtc.org29d58392013-05-16 12:08:0366
67namespace webrtc {
pbos@webrtc.orgab990ae2014-09-17 09:02:2568
nisse4709e892017-02-07 09:18:4369namespace {
Johannes Kronf59666b2019-04-08 10:57:0670bool SendPeriodicFeedback(const std::vector<RtpExtension>& extensions) {
Johannes Kron7ff164e2019-02-07 11:50:1871 for (const auto& extension : extensions) {
72 if (extension.uri == RtpExtension::kTransportSequenceNumberV2Uri)
Johannes Kronf59666b2019-04-08 10:57:0673 return false;
Johannes Kron7ff164e2019-02-07 11:50:1874 }
Johannes Kronf59666b2019-04-08 10:57:0675 return true;
Johannes Kron7ff164e2019-02-07 11:50:1876}
77
nisse4709e892017-02-07 09:18:4378// TODO(nisse): This really begs for a shared context struct.
79bool UseSendSideBwe(const std::vector<RtpExtension>& extensions,
80 bool transport_cc) {
81 if (!transport_cc)
82 return false;
83 for (const auto& extension : extensions) {
Johannes Kron7ff164e2019-02-07 11:50:1884 if (extension.uri == RtpExtension::kTransportSequenceNumberUri ||
85 extension.uri == RtpExtension::kTransportSequenceNumberV2Uri)
nisse4709e892017-02-07 09:18:4386 return true;
87 }
88 return false;
89}
90
91bool UseSendSideBwe(const VideoReceiveStream::Config& config) {
92 return UseSendSideBwe(config.rtp.extensions, config.rtp.transport_cc);
93}
94
95bool UseSendSideBwe(const AudioReceiveStream::Config& config) {
96 return UseSendSideBwe(config.rtp.extensions, config.rtp.transport_cc);
97}
98
99bool UseSendSideBwe(const FlexfecReceiveStream::Config& config) {
100 return UseSendSideBwe(config.rtp_header_extensions, config.transport_cc);
101}
102
nisse26e3abb2017-08-25 11:44:25103const int* FindKeyByValue(const std::map<int, int>& m, int v) {
104 for (const auto& kv : m) {
105 if (kv.second == v)
106 return &kv.first;
107 }
108 return nullptr;
109}
110
eladalon8ec568a2017-09-08 13:15:52111std::unique_ptr<rtclog::StreamConfig> CreateRtcLogStreamConfig(
perkj09e71da2017-05-22 10:26:49112 const VideoReceiveStream::Config& config) {
Mirko Bonadei317a1f02019-09-17 15:06:18113 auto rtclog_config = std::make_unique<rtclog::StreamConfig>();
eladalon8ec568a2017-09-08 13:15:52114 rtclog_config->remote_ssrc = config.rtp.remote_ssrc;
115 rtclog_config->local_ssrc = config.rtp.local_ssrc;
116 rtclog_config->rtx_ssrc = config.rtp.rtx_ssrc;
117 rtclog_config->rtcp_mode = config.rtp.rtcp_mode;
eladalon8ec568a2017-09-08 13:15:52118 rtclog_config->rtp_extensions = config.rtp.extensions;
perkj09e71da2017-05-22 10:26:49119
120 for (const auto& d : config.decoders) {
nisse26e3abb2017-08-25 11:44:25121 const int* search =
122 FindKeyByValue(config.rtp.rtx_associated_payload_types, d.payload_type);
Niels Möllercb7e1d22018-09-11 13:56:04123 rtclog_config->codecs.emplace_back(d.video_format.name, d.payload_type,
Yves Gerey665174f2018-06-19 13:03:05124 search ? *search : 0);
perkj09e71da2017-05-22 10:26:49125 }
126 return rtclog_config;
127}
128
eladalon8ec568a2017-09-08 13:15:52129std::unique_ptr<rtclog::StreamConfig> CreateRtcLogStreamConfig(
perkjc0876aa2017-05-22 11:08:28130 const VideoSendStream::Config& config,
131 size_t ssrc_index) {
Mirko Bonadei317a1f02019-09-17 15:06:18132 auto rtclog_config = std::make_unique<rtclog::StreamConfig>();
eladalon8ec568a2017-09-08 13:15:52133 rtclog_config->local_ssrc = config.rtp.ssrcs[ssrc_index];
perkjc0876aa2017-05-22 11:08:28134 if (ssrc_index < config.rtp.rtx.ssrcs.size()) {
eladalon8ec568a2017-09-08 13:15:52135 rtclog_config->rtx_ssrc = config.rtp.rtx.ssrcs[ssrc_index];
perkjc0876aa2017-05-22 11:08:28136 }
eladalon8ec568a2017-09-08 13:15:52137 rtclog_config->rtcp_mode = config.rtp.rtcp_mode;
138 rtclog_config->rtp_extensions = config.rtp.extensions;
perkjc0876aa2017-05-22 11:08:28139
Niels Möller259a4972018-04-05 13:36:51140 rtclog_config->codecs.emplace_back(config.rtp.payload_name,
141 config.rtp.payload_type,
eladalon8ec568a2017-09-08 13:15:52142 config.rtp.rtx.payload_type);
perkjc0876aa2017-05-22 11:08:28143 return rtclog_config;
144}
145
eladalon8ec568a2017-09-08 13:15:52146std::unique_ptr<rtclog::StreamConfig> CreateRtcLogStreamConfig(
perkjac8f52d2017-05-22 16:36:28147 const AudioReceiveStream::Config& config) {
Mirko Bonadei317a1f02019-09-17 15:06:18148 auto rtclog_config = std::make_unique<rtclog::StreamConfig>();
eladalon8ec568a2017-09-08 13:15:52149 rtclog_config->remote_ssrc = config.rtp.remote_ssrc;
150 rtclog_config->local_ssrc = config.rtp.local_ssrc;
151 rtclog_config->rtp_extensions = config.rtp.extensions;
perkjac8f52d2017-05-22 16:36:28152 return rtclog_config;
153}
154
Tommi25eb47c2019-08-29 14:39:05155bool IsRtcp(const uint8_t* packet, size_t length) {
156 RtpUtility::RtpHeaderParser rtp_parser(packet, length);
157 return rtp_parser.RTCP();
158}
159
nisse4709e892017-02-07 09:18:43160} // namespace
161
pbos@webrtc.org16e03b72013-10-28 16:32:01162namespace internal {
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07163
Sebastian Janssone6256052018-05-04 12:08:15164class Call final : public webrtc::Call,
165 public PacketReceiver,
166 public RecoveredPacketReceiver,
167 public TargetTransferRateObserver,
168 public BitrateAllocator::LimitObserver {
pbos@webrtc.org16e03b72013-10-28 16:32:01169 public:
Sebastian Jansson4e5f5ed2019-03-01 17:13:27170 Call(Clock* clock,
171 const Call::Config& config,
Sebastian Jansson896b47c2019-03-01 17:48:16172 std::unique_ptr<RtpTransportControllerSendInterface> transport_send,
173 std::unique_ptr<ProcessThread> module_process_thread,
174 TaskQueueFactory* task_queue_factory);
Mirko Bonadei8fdcac32018-08-28 14:30:18175 ~Call() override;
pbos@webrtc.org16e03b72013-10-28 16:32:01176
brandtr25445d32016-10-24 06:37:14177 // Implements webrtc::Call.
kjellander@webrtc.org14665ff2015-03-04 12:58:35178 PacketReceiver* Receiver() override;
pbos@webrtc.org16e03b72013-10-28 16:32:01179
Fredrik Solenberg04f49312015-06-08 11:04:56180 webrtc::AudioSendStream* CreateAudioSendStream(
181 const webrtc::AudioSendStream::Config& config) override;
182 void DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) override;
183
Fredrik Solenberg23fba1f2015-04-29 13:24:01184 webrtc::AudioReceiveStream* CreateAudioReceiveStream(
185 const webrtc::AudioReceiveStream::Config& config) override;
186 void DestroyAudioReceiveStream(
187 webrtc::AudioReceiveStream* receive_stream) override;
pbos@webrtc.org16e03b72013-10-28 16:32:01188
Fredrik Solenberg23fba1f2015-04-29 13:24:01189 webrtc::VideoSendStream* CreateVideoSendStream(
perkj26091b12016-09-01 08:17:40190 webrtc::VideoSendStream::Config config,
191 VideoEncoderConfig encoder_config) override;
Ying Wang3b790f32018-01-19 16:58:57192 webrtc::VideoSendStream* CreateVideoSendStream(
193 webrtc::VideoSendStream::Config config,
194 VideoEncoderConfig encoder_config,
195 std::unique_ptr<FecController> fec_controller) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35196 void DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) override;
pbos@webrtc.org16e03b72013-10-28 16:32:01197
Fredrik Solenberg23fba1f2015-04-29 13:24:01198 webrtc::VideoReceiveStream* CreateVideoReceiveStream(
Tommi733b5472016-06-10 15:58:01199 webrtc::VideoReceiveStream::Config configuration) override;
kjellander@webrtc.org14665ff2015-03-04 12:58:35200 void DestroyVideoReceiveStream(
201 webrtc::VideoReceiveStream* receive_stream) override;
pbos@webrtc.org16e03b72013-10-28 16:32:01202
brandtr7250b392016-12-19 09:13:46203 FlexfecReceiveStream* CreateFlexfecReceiveStream(
204 const FlexfecReceiveStream::Config& config) override;
brandtr25445d32016-10-24 06:37:14205 void DestroyFlexfecReceiveStream(
brandtr7250b392016-12-19 09:13:46206 FlexfecReceiveStream* receive_stream) override;
brandtr25445d32016-10-24 06:37:14207
Sebastian Jansson8f83b422018-02-21 12:07:13208 RtpTransportControllerSendInterface* GetTransportControllerSend() override;
209
kjellander@webrtc.org14665ff2015-03-04 12:58:35210 Stats GetStats() const override;
pbos@webrtc.org16e03b72013-10-28 16:32:01211
brandtr25445d32016-10-24 06:37:14212 // Implements PacketReceiver.
stefan68786d22015-09-08 12:36:15213 DeliveryStatus DeliverPacket(MediaType media_type,
Danil Chapovalov292a73e2017-12-07 16:00:40214 rtc::CopyOnWriteBuffer packet,
Niels Möller70082872018-08-07 09:03:12215 int64_t packet_time_us) override;
pbos@webrtc.org16e03b72013-10-28 16:32:01216
brandtr4e523862016-10-19 06:50:45217 // Implements RecoveredPacketReceiver.
nissed2ef3142017-05-11 15:00:58218 void OnRecoveredPacket(const uint8_t* packet, size_t length) override;
brandtr4e523862016-10-19 06:50:45219
skvlad7a43d252016-03-22 22:32:27220 void SignalChannelNetworkState(MediaType media, NetworkState state) override;
pbos@webrtc.org26c0c412014-09-03 16:17:12221
Stefan Holmer64be7fa2018-10-04 13:21:55222 void OnAudioTransportOverheadChanged(
223 int transport_overhead_per_packet) override;
michaelt79e05882016-11-08 10:50:09224
stefanc1aeaf02015-10-15 14:26:07225 void OnSentPacket(const rtc::SentPacket& sent_packet) override;
226
Sebastian Jansson19704ec2018-03-12 14:59:12227 // Implements TargetTransferRateObserver,
228 void OnTargetTransferRate(TargetTransferRate msg) override;
Sebastian Jansson2701bc92018-12-11 14:02:47229 void OnStartRateUpdate(DataRate start_rate) override;
mflodman0e7e2592015-11-13 05:02:42230
perkj71ee44c2016-06-15 07:47:53231 // Implements BitrateAllocator::LimitObserver.
Sebastian Jansson93b1ea22019-09-18 16:31:52232 void OnAllocationLimitsChanged(BitrateAllocationLimits limits) override;
perkj71ee44c2016-06-15 07:47:53233
Piotr (Peter) Slatala7fbfaa42019-03-18 17:31:54234 void SetClientBitratePreferences(const BitrateSettings& preferences) override;
235
pbos@webrtc.org16e03b72013-10-28 16:32:01236 private:
Yves Gerey665174f2018-06-19 13:03:05237 DeliveryStatus DeliverRtcp(MediaType media_type,
238 const uint8_t* packet,
Fredrik Solenberg23fba1f2015-04-29 13:24:01239 size_t length);
stefan68786d22015-09-08 12:36:15240 DeliveryStatus DeliverRtp(MediaType media_type,
Danil Chapovalov292a73e2017-12-07 16:00:40241 rtc::CopyOnWriteBuffer packet,
Niels Möller70082872018-08-07 09:03:12242 int64_t packet_time_us);
pbos8fc7fa72015-07-15 15:02:58243 void ConfigureSync(const std::string& sync_group)
danilchapa37de392017-09-09 11:17:22244 RTC_EXCLUSIVE_LOCKS_REQUIRED(receive_crit_);
pbos8fc7fa72015-07-15 15:02:58245
nissed44ce052017-02-06 10:23:00246 void NotifyBweOfReceivedPacket(const RtpPacketReceived& packet,
247 MediaType media_type)
danilchapa37de392017-09-09 11:17:22248 RTC_SHARED_LOCKS_REQUIRED(receive_crit_);
nissed44ce052017-02-06 10:23:00249
Erik Språng425d6aa2019-07-29 14:38:27250 void UpdateSendHistograms(Timestamp first_sent_packet)
danilchapa37de392017-09-09 11:17:22251 RTC_EXCLUSIVE_LOCKS_REQUIRED(&bitrate_crit_);
stefan18adf0a2015-11-17 14:24:56252 void UpdateReceiveHistograms();
asapersson4374a092016-07-27 07:39:09253 void UpdateHistograms();
skvlad7a43d252016-03-22 22:32:27254 void UpdateAggregateNetworkState();
stefan91d92602015-11-11 18:13:02255
Tommi78a71382019-08-08 10:27:53256 void RegisterRateObserver();
Niels Möller46879152019-01-07 14:54:47257
Tommi48b48e52019-08-09 09:42:32258 rtc::TaskQueue* network_queue() const {
259 return transport_send_ptr_->GetWorkerQueue();
260 }
261
Peter Boströmd3c94472015-12-09 10:20:58262 Clock* const clock_;
Sebastian Jansson896b47c2019-03-01 17:48:16263 TaskQueueFactory* const task_queue_factory_;
stefan91d92602015-11-11 18:13:02264
Peter Boström45553ae2015-05-08 11:54:38265 const int num_cpu_cores_;
kwibergb25345e2016-03-12 14:10:44266 const std::unique_ptr<ProcessThread> module_process_thread_;
kwibergb25345e2016-03-12 14:10:44267 const std::unique_ptr<CallStats> call_stats_;
268 const std::unique_ptr<BitrateAllocator> bitrate_allocator_;
pbos@webrtc.org16e03b72013-10-28 16:32:01269 Call::Config config_;
Sebastian Janssonb55015e2019-04-09 11:44:04270 SequenceChecker configuration_sequence_checker_;
Tommi78a71382019-08-08 10:27:53271 SequenceChecker worker_sequence_checker_;
pbos@webrtc.org16e03b72013-10-28 16:32:01272
skvlad7a43d252016-03-22 22:32:27273 NetworkState audio_network_state_;
274 NetworkState video_network_state_;
Tommi48b48e52019-08-09 09:42:32275 bool aggregate_network_up_ RTC_GUARDED_BY(configuration_sequence_checker_);
pbos@webrtc.org16e03b72013-10-28 16:32:01276
kwibergb25345e2016-03-12 14:10:44277 std::unique_ptr<RWLockWrapper> receive_crit_;
brandtr25445d32016-10-24 06:37:14278 // Audio, Video, and FlexFEC receive streams are owned by the client that
279 // creates them.
nissee4bcd6d2017-05-16 11:47:04280 std::set<AudioReceiveStream*> audio_receive_streams_
danilchapa37de392017-09-09 11:17:22281 RTC_GUARDED_BY(receive_crit_);
Fredrik Solenberg23fba1f2015-04-29 13:24:01282 std::set<VideoReceiveStream*> video_receive_streams_
danilchapa37de392017-09-09 11:17:22283 RTC_GUARDED_BY(receive_crit_);
nissee4bcd6d2017-05-16 11:47:04284
pbos8fc7fa72015-07-15 15:02:58285 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_
danilchapa37de392017-09-09 11:17:22286 RTC_GUARDED_BY(receive_crit_);
pbos@webrtc.org26c0c412014-09-03 16:17:12287
nisse0f15f922017-06-21 08:05:22288 // TODO(nisse): Should eventually be injected at creation,
289 // with a single object in the bundled case.
eladalon2a2b2972017-07-03 16:25:27290 RtpStreamReceiverController audio_receiver_controller_;
291 RtpStreamReceiverController video_receiver_controller_;
nissee4bcd6d2017-05-16 11:47:04292
nissed44ce052017-02-06 10:23:00293 // This extra map is used for receive processing which is
294 // independent of media type.
295
296 // TODO(nisse): In the RTP transport refactoring, we should have a
297 // single mapping from ssrc to a more abstract receive stream, with
298 // accessor methods for all configuration we need at this level.
299 struct ReceiveRtpConfig {
Erik Språng09708512018-03-14 14:16:50300 explicit ReceiveRtpConfig(const webrtc::AudioReceiveStream::Config& config)
301 : extensions(config.rtp.extensions),
302 use_send_side_bwe(UseSendSideBwe(config)) {}
303 explicit ReceiveRtpConfig(const webrtc::VideoReceiveStream::Config& config)
304 : extensions(config.rtp.extensions),
305 use_send_side_bwe(UseSendSideBwe(config)) {}
306 explicit ReceiveRtpConfig(const FlexfecReceiveStream::Config& config)
307 : extensions(config.rtp_header_extensions),
308 use_send_side_bwe(UseSendSideBwe(config)) {}
nissed44ce052017-02-06 10:23:00309
310 // Registered RTP header extensions for each stream. Note that RTP header
311 // extensions are negotiated per track ("m= line") in the SDP, but we have
312 // no notion of tracks at the Call level. We therefore store the RTP header
313 // extensions per SSRC instead, which leads to some storage overhead.
Erik Språng09708512018-03-14 14:16:50314 const RtpHeaderExtensionMap extensions;
nisse4709e892017-02-07 09:18:43315 // Set if both RTP extension the RTCP feedback message needed for
316 // send side BWE are negotiated.
Erik Språng09708512018-03-14 14:16:50317 const bool use_send_side_bwe;
nissed44ce052017-02-06 10:23:00318 };
319 std::map<uint32_t, ReceiveRtpConfig> receive_rtp_config_
danilchapa37de392017-09-09 11:17:22320 RTC_GUARDED_BY(receive_crit_);
brandtrb29e6522016-12-21 14:37:18321
kwibergb25345e2016-03-12 14:10:44322 std::unique_ptr<RWLockWrapper> send_crit_;
solenbergc7a8b082015-10-16 21:35:07323 // Audio and Video send streams are owned by the client that creates them.
danilchapa37de392017-09-09 11:17:22324 std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_
325 RTC_GUARDED_BY(send_crit_);
326 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_
327 RTC_GUARDED_BY(send_crit_);
328 std::set<VideoSendStream*> video_send_streams_ RTC_GUARDED_BY(send_crit_);
pbos@webrtc.org16e03b72013-10-28 16:32:01329
ossuc3d4b482017-05-23 13:07:11330 using RtpStateMap = std::map<uint32_t, RtpState>;
331 RtpStateMap suspended_audio_send_ssrcs_
danilchapa37de392017-09-09 11:17:22332 RTC_GUARDED_BY(configuration_sequence_checker_);
ossuc3d4b482017-05-23 13:07:11333 RtpStateMap suspended_video_send_ssrcs_
danilchapa37de392017-09-09 11:17:22334 RTC_GUARDED_BY(configuration_sequence_checker_);
ossuc3d4b482017-05-23 13:07:11335
Åsa Persson4bece9a2017-10-06 08:04:04336 using RtpPayloadStateMap = std::map<uint32_t, RtpPayloadState>;
337 RtpPayloadStateMap suspended_video_payload_states_
338 RTC_GUARDED_BY(configuration_sequence_checker_);
339
skvlad11a9cbf2016-10-07 18:53:05340 webrtc::RtcEventLog* event_log_;
ivocb04965c2015-09-09 07:09:43341
stefan18adf0a2015-11-17 14:24:56342 // The following members are only accessed (exclusively) from one thread and
343 // from the destructor, and therefore doesn't need any explicit
344 // synchronization.
asapersson250fd972016-09-08 07:07:21345 RateCounter received_bytes_per_second_counter_;
346 RateCounter received_audio_bytes_per_second_counter_;
347 RateCounter received_video_bytes_per_second_counter_;
348 RateCounter received_rtcp_bytes_per_second_counter_;
Danil Chapovalovb9b146c2018-06-15 10:28:07349 absl::optional<int64_t> first_received_rtp_audio_ms_;
350 absl::optional<int64_t> last_received_rtp_audio_ms_;
351 absl::optional<int64_t> first_received_rtp_video_ms_;
352 absl::optional<int64_t> last_received_rtp_video_ms_;
stefan91d92602015-11-11 18:13:02353
Sebastian Jansson19704ec2018-03-12 14:59:12354 rtc::CriticalSection last_bandwidth_bps_crit_;
355 uint32_t last_bandwidth_bps_ RTC_GUARDED_BY(&last_bandwidth_bps_crit_);
stefan18adf0a2015-11-17 14:24:56356 // TODO(holmer): Remove this lock once BitrateController no longer calls
357 // OnNetworkChanged from multiple threads.
358 rtc::CriticalSection bitrate_crit_;
Tommi78a71382019-08-08 10:27:53359 uint32_t min_allocated_send_bitrate_bps_
360 RTC_GUARDED_BY(&worker_sequence_checker_);
danilchapa37de392017-09-09 11:17:22361 uint32_t configured_max_padding_bitrate_bps_ RTC_GUARDED_BY(&bitrate_crit_);
362 AvgCounter estimated_send_bitrate_kbps_counter_
363 RTC_GUARDED_BY(&bitrate_crit_);
364 AvgCounter pacer_bitrate_kbps_counter_ RTC_GUARDED_BY(&bitrate_crit_);
stefan18adf0a2015-11-17 14:24:56365
nisse559af382017-03-21 13:41:12366 ReceiveSideCongestionController receive_side_cc_;
Sebastian Janssonb34556e2018-03-21 13:38:32367
368 const std::unique_ptr<ReceiveTimeCalculator> receive_time_calculator_;
369
asapersson35151f32016-05-03 06:44:01370 const std::unique_ptr<SendDelayStats> video_send_delay_stats_;
asapersson4374a092016-07-27 07:39:09371 const int64_t start_ms_;
mflodman0e7e2592015-11-13 05:02:42372
Sebastian Janssone6256052018-05-04 12:08:15373 // Caches transport_send_.get(), to avoid racing with destructor.
374 // Note that this is declared before transport_send_ to ensure that it is not
375 // invalidated until no more tasks can be running on the transport_send_ task
376 // queue.
Tommi78a71382019-08-08 10:27:53377 RtpTransportControllerSendInterface* const transport_send_ptr_;
Sebastian Janssone6256052018-05-04 12:08:15378 // Declared last since it will issue callbacks from a task queue. Declaring it
379 // last ensures that it is destroyed first and any running tasks are finished.
380 std::unique_ptr<RtpTransportControllerSendInterface> transport_send_;
Piotr (Peter) Slatalacc8e8bb2018-11-15 16:26:19381
Piotr (Peter) Slatalacc8e8bb2018-11-15 16:26:19382 bool is_target_rate_observer_registered_
Tommi78a71382019-08-08 10:27:53383 RTC_GUARDED_BY(&configuration_sequence_checker_) = false;
Piotr (Peter) Slatalacc8e8bb2018-11-15 16:26:19384
henrikg3c089d72015-09-16 12:37:44385 RTC_DISALLOW_COPY_AND_ASSIGN(Call);
pbos@webrtc.org16e03b72013-10-28 16:32:01386};
pbos@webrtc.orgc49d5b72013-12-05 12:11:47387} // namespace internal
pbos@webrtc.orgfd39e132013-08-14 13:52:52388
asapersson2e5cfcd2016-08-11 15:41:18389std::string Call::Stats::ToString(int64_t time_ms) const {
Jonas Olsson0a713b62018-04-04 13:49:32390 char buf[1024];
391 rtc::SimpleStringBuilder ss(buf);
asapersson2e5cfcd2016-08-11 15:41:18392 ss << "Call stats: " << time_ms << ", {";
393 ss << "send_bw_bps: " << send_bandwidth_bps << ", ";
394 ss << "recv_bw_bps: " << recv_bandwidth_bps << ", ";
395 ss << "max_pad_bps: " << max_padding_bitrate_bps << ", ";
396 ss << "pacer_delay_ms: " << pacer_delay_ms << ", ";
397 ss << "rtt_ms: " << rtt_ms;
398 ss << '}';
399 return ss.str();
400}
401
stefan@webrtc.org7e9315b2013-12-04 10:24:26402Call* Call::Create(const Call::Config& config) {
Danil Chapovalov359fe332019-04-01 08:46:36403 return Create(config, Clock::GetRealTimeClock(),
Erik Språng6950b302019-08-16 10:54:08404 ProcessThread::Create("ModuleProcessThread"),
405 ProcessThread::Create("PacerThread"));
Sebastian Jansson896b47c2019-03-01 17:48:16406}
407
408Call* Call::Create(const Call::Config& config,
Sebastian Jansson4e5f5ed2019-03-01 17:13:27409 Clock* clock,
Sebastian Jansson896b47c2019-03-01 17:48:16410 std::unique_ptr<ProcessThread> call_thread,
Danil Chapovalov359fe332019-04-01 08:46:36411 std::unique_ptr<ProcessThread> pacer_thread) {
Danil Chapovalov53d45ba2019-07-03 12:56:33412 RTC_DCHECK(config.task_queue_factory);
Sebastian Jansson97f61ea2018-02-21 12:01:55413 return new internal::Call(
Sebastian Jansson4e5f5ed2019-03-01 17:13:27414 clock, config,
Mirko Bonadei317a1f02019-09-17 15:06:18415 std::make_unique<RtpTransportControllerSend>(
Ying Wang0810a7c2019-04-10 11:48:24416 clock, config.event_log, config.network_state_predictor_factory,
417 config.network_controller_factory, config.bitrate_config,
Erik Språng662678d2019-11-15 16:18:52418 std::move(pacer_thread), config.task_queue_factory, config.trials),
Danil Chapovalov53d45ba2019-07-03 12:56:33419 std::move(call_thread), config.task_queue_factory);
zstein7cb69d52017-05-08 18:52:38420}
421
Ying Wang0dd1b0a2018-02-20 11:50:27422// This method here to avoid subclasses has to implement this method.
423// Call perf test will use Internal::Call::CreateVideoSendStream() to inject
424// FecController.
Ying Wang3b790f32018-01-19 16:58:57425VideoSendStream* Call::CreateVideoSendStream(
426 VideoSendStream::Config config,
427 VideoEncoderConfig encoder_config,
428 std::unique_ptr<FecController> fec_controller) {
429 return nullptr;
430}
431
pbos@webrtc.org29d58392013-05-16 12:08:03432namespace internal {
433
Sebastian Jansson4e5f5ed2019-03-01 17:13:27434Call::Call(Clock* clock,
435 const Call::Config& config,
Sebastian Jansson896b47c2019-03-01 17:48:16436 std::unique_ptr<RtpTransportControllerSendInterface> transport_send,
437 std::unique_ptr<ProcessThread> module_process_thread,
438 TaskQueueFactory* task_queue_factory)
Sebastian Jansson4e5f5ed2019-03-01 17:13:27439 : clock_(clock),
Sebastian Jansson896b47c2019-03-01 17:48:16440 task_queue_factory_(task_queue_factory),
stefan91d92602015-11-11 18:13:02441 num_cpu_cores_(CpuInfo::DetectNumberOfCores()),
Sebastian Jansson896b47c2019-03-01 17:48:16442 module_process_thread_(std::move(module_process_thread)),
Tommi38c5d932018-03-27 21:11:09443 call_stats_(new CallStats(clock_, module_process_thread_.get())),
Sebastian Jansson40de3cc2019-09-19 12:54:43444 bitrate_allocator_(new BitrateAllocator(this)),
Peter Boström45553ae2015-05-08 11:54:38445 config_(config),
Sergey Ulanove2b15012016-11-23 00:08:30446 audio_network_state_(kNetworkDown),
447 video_network_state_(kNetworkDown),
Sebastian Janssona06e9192018-03-07 17:49:55448 aggregate_network_up_(false),
pbos@webrtc.org26c0c412014-09-03 16:17:12449 receive_crit_(RWLockWrapper::CreateRWLock()),
stefan91d92602015-11-11 18:13:02450 send_crit_(RWLockWrapper::CreateRWLock()),
skvlad11a9cbf2016-10-07 18:53:05451 event_log_(config.event_log),
asapersson250fd972016-09-08 07:07:21452 received_bytes_per_second_counter_(clock_, nullptr, true),
453 received_audio_bytes_per_second_counter_(clock_, nullptr, true),
454 received_video_bytes_per_second_counter_(clock_, nullptr, true),
455 received_rtcp_bytes_per_second_counter_(clock_, nullptr, true),
Sebastian Jansson19704ec2018-03-12 14:59:12456 last_bandwidth_bps_(0),
perkj71ee44c2016-06-15 07:47:53457 min_allocated_send_bitrate_bps_(0),
sprang9c0b5512016-07-06 07:54:28458 configured_max_padding_bitrate_bps_(0),
asaperssonce2e1362016-09-09 07:13:35459 estimated_send_bitrate_kbps_counter_(clock_, nullptr, true),
460 pacer_bitrate_kbps_counter_(clock_, nullptr, true),
nisse05843312017-04-19 06:38:35461 receive_side_cc_(clock_, transport_send->packet_router()),
Sebastian Janssonb34556e2018-03-21 13:38:32462 receive_time_calculator_(ReceiveTimeCalculator::CreateFromFieldTrial()),
asapersson4374a092016-07-27 07:39:09463 video_send_delay_stats_(new SendDelayStats(clock_)),
Tommi78a71382019-08-08 10:27:53464 start_ms_(clock_->TimeInMilliseconds()),
465 transport_send_ptr_(transport_send.get()),
466 transport_send_(std::move(transport_send)) {
skvlad11a9cbf2016-10-07 18:53:05467 RTC_DCHECK(config.event_log != nullptr);
Erik Språng17f82cf2019-12-04 10:10:43468 RTC_DCHECK(config.trials != nullptr);
Tommi78a71382019-08-08 10:27:53469 worker_sequence_checker_.Detach();
Tommi48b48e52019-08-09 09:42:32470
471 call_stats_->RegisterStatsObserver(&receive_side_cc_);
472
473 module_process_thread_->RegisterModule(
474 receive_side_cc_.GetRemoteBitrateEstimator(true), RTC_FROM_HERE);
475 module_process_thread_->RegisterModule(call_stats_.get(), RTC_FROM_HERE);
476 module_process_thread_->RegisterModule(&receive_side_cc_, RTC_FROM_HERE);
pbos@webrtc.org29d58392013-05-16 12:08:03477}
478
pbos@webrtc.org841c8a42013-09-09 15:04:25479Call::~Call() {
Sebastian Janssonb55015e2019-04-09 11:44:04480 RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
perkj26091b12016-09-01 08:17:40481
solenbergc7a8b082015-10-16 21:35:07482 RTC_CHECK(audio_send_ssrcs_.empty());
483 RTC_CHECK(video_send_ssrcs_.empty());
484 RTC_CHECK(video_send_streams_.empty());
nissee4bcd6d2017-05-16 11:47:04485 RTC_CHECK(audio_receive_streams_.empty());
solenbergc7a8b082015-10-16 21:35:07486 RTC_CHECK(video_receive_streams_.empty());
pbos@webrtc.org9e4e5242015-02-12 10:48:23487
Tommi48b48e52019-08-09 09:42:32488 module_process_thread_->Stop();
Tommi78a71382019-08-08 10:27:53489 module_process_thread_->DeRegisterModule(
490 receive_side_cc_.GetRemoteBitrateEstimator(true));
491 module_process_thread_->DeRegisterModule(&receive_side_cc_);
492 module_process_thread_->DeRegisterModule(call_stats_.get());
Tommi78a71382019-08-08 10:27:53493 call_stats_->DeregisterStatsObserver(&receive_side_cc_);
sprang6d6122b2016-07-13 13:37:09494
Erik Språng425d6aa2019-07-29 14:38:27495 absl::optional<Timestamp> first_sent_packet_ms =
496 transport_send_->GetFirstPacketTime();
Tommi48b48e52019-08-09 09:42:32497
sprang6d6122b2016-07-13 13:37:09498 // Only update histograms after process threads have been shut down, so that
499 // they won't try to concurrently update stats.
Erik Språngaa59eca2019-07-24 12:52:55500 if (first_sent_packet_ms) {
perkj26091b12016-09-01 08:17:40501 rtc::CritScope lock(&bitrate_crit_);
Erik Språngaa59eca2019-07-24 12:52:55502 UpdateSendHistograms(*first_sent_packet_ms);
perkj26091b12016-09-01 08:17:40503 }
Tommi48b48e52019-08-09 09:42:32504
sprang6d6122b2016-07-13 13:37:09505 UpdateReceiveHistograms();
asapersson4374a092016-07-27 07:39:09506 UpdateHistograms();
pbos@webrtc.org29d58392013-05-16 12:08:03507}
508
Piotr (Peter) Slatalacc8e8bb2018-11-15 16:26:19509void Call::RegisterRateObserver() {
Tommi78a71382019-08-08 10:27:53510 RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
Piotr (Peter) Slatalacc8e8bb2018-11-15 16:26:19511
Tommi78a71382019-08-08 10:27:53512 if (is_target_rate_observer_registered_)
Piotr (Peter) Slatalacc8e8bb2018-11-15 16:26:19513 return;
Piotr (Peter) Slatalacc8e8bb2018-11-15 16:26:19514
515 is_target_rate_observer_registered_ = true;
516
Tommi48b48e52019-08-09 09:42:32517 // This call seems to kick off a number of things, so probably better left
518 // off being kicked off on request rather than in the ctor.
Tommi78a71382019-08-08 10:27:53519 transport_send_ptr_->RegisterTargetTransferRateObserver(this);
Piotr (Peter) Slatalab2757882018-12-18 19:17:09520
Tommi78a71382019-08-08 10:27:53521 module_process_thread_->Start();
Piotr (Peter) Slatala7fbfaa42019-03-18 17:31:54522}
523
524void Call::SetClientBitratePreferences(const BitrateSettings& preferences) {
Tommi78a71382019-08-08 10:27:53525 RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
Piotr (Peter) Slatala7fbfaa42019-03-18 17:31:54526 GetTransportControllerSend()->SetClientBitratePreferences(preferences);
Piotr (Peter) Slatalacc8e8bb2018-11-15 16:26:19527}
528
asapersson4374a092016-07-27 07:39:09529void Call::UpdateHistograms() {
asapersson1d02d3e2016-09-10 05:40:25530 RTC_HISTOGRAM_COUNTS_100000(
asapersson4374a092016-07-27 07:39:09531 "WebRTC.Call.LifetimeInSeconds",
532 (clock_->TimeInMilliseconds() - start_ms_) / 1000);
533}
534
Tommi48b48e52019-08-09 09:42:32535// Called from the dtor.
Erik Språng425d6aa2019-07-29 14:38:27536void Call::UpdateSendHistograms(Timestamp first_sent_packet) {
stefan18adf0a2015-11-17 14:24:56537 int64_t elapsed_sec =
Erik Språng425d6aa2019-07-29 14:38:27538 (clock_->TimeInMilliseconds() - first_sent_packet.ms()) / 1000;
stefan18adf0a2015-11-17 14:24:56539 if (elapsed_sec < metrics::kMinRunTimeInSeconds)
540 return;
asaperssonce2e1362016-09-09 07:13:35541 const int kMinRequiredPeriodicSamples = 5;
542 AggregatedStats send_bitrate_stats =
543 estimated_send_bitrate_kbps_counter_.ProcessAndGetStats();
544 if (send_bitrate_stats.num_samples > kMinRequiredPeriodicSamples) {
asapersson1d02d3e2016-09-10 05:40:25545 RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.EstimatedSendBitrateInKbps",
546 send_bitrate_stats.average);
Mirko Bonadei675513b2017-11-09 10:09:25547 RTC_LOG(LS_INFO) << "WebRTC.Call.EstimatedSendBitrateInKbps, "
548 << send_bitrate_stats.ToString();
stefan18adf0a2015-11-17 14:24:56549 }
asaperssonce2e1362016-09-09 07:13:35550 AggregatedStats pacer_bitrate_stats =
551 pacer_bitrate_kbps_counter_.ProcessAndGetStats();
552 if (pacer_bitrate_stats.num_samples > kMinRequiredPeriodicSamples) {
asapersson1d02d3e2016-09-10 05:40:25553 RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.PacerBitrateInKbps",
554 pacer_bitrate_stats.average);
Mirko Bonadei675513b2017-11-09 10:09:25555 RTC_LOG(LS_INFO) << "WebRTC.Call.PacerBitrateInKbps, "
556 << pacer_bitrate_stats.ToString();
stefan18adf0a2015-11-17 14:24:56557 }
558}
559
560void Call::UpdateReceiveHistograms() {
saza0d7f04d2017-07-04 11:05:06561 if (first_received_rtp_audio_ms_) {
562 RTC_HISTOGRAM_COUNTS_100000(
563 "WebRTC.Call.TimeReceivingAudioRtpPacketsInSeconds",
564 (*last_received_rtp_audio_ms_ - *first_received_rtp_audio_ms_) / 1000);
565 }
566 if (first_received_rtp_video_ms_) {
567 RTC_HISTOGRAM_COUNTS_100000(
568 "WebRTC.Call.TimeReceivingVideoRtpPacketsInSeconds",
569 (*last_received_rtp_video_ms_ - *first_received_rtp_video_ms_) / 1000);
570 }
asapersson250fd972016-09-08 07:07:21571 const int kMinRequiredPeriodicSamples = 5;
572 AggregatedStats video_bytes_per_sec =
573 received_video_bytes_per_second_counter_.GetStats();
574 if (video_bytes_per_sec.num_samples > kMinRequiredPeriodicSamples) {
asapersson1d02d3e2016-09-10 05:40:25575 RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.VideoBitrateReceivedInKbps",
576 video_bytes_per_sec.average * 8 / 1000);
Mirko Bonadei675513b2017-11-09 10:09:25577 RTC_LOG(LS_INFO) << "WebRTC.Call.VideoBitrateReceivedInBps, "
578 << video_bytes_per_sec.ToStringWithMultiplier(8);
stefan91d92602015-11-11 18:13:02579 }
asapersson250fd972016-09-08 07:07:21580 AggregatedStats audio_bytes_per_sec =
581 received_audio_bytes_per_second_counter_.GetStats();
582 if (audio_bytes_per_sec.num_samples > kMinRequiredPeriodicSamples) {
asapersson1d02d3e2016-09-10 05:40:25583 RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.AudioBitrateReceivedInKbps",
584 audio_bytes_per_sec.average * 8 / 1000);
Mirko Bonadei675513b2017-11-09 10:09:25585 RTC_LOG(LS_INFO) << "WebRTC.Call.AudioBitrateReceivedInBps, "
586 << audio_bytes_per_sec.ToStringWithMultiplier(8);
stefan91d92602015-11-11 18:13:02587 }
asapersson250fd972016-09-08 07:07:21588 AggregatedStats rtcp_bytes_per_sec =
589 received_rtcp_bytes_per_second_counter_.GetStats();
590 if (rtcp_bytes_per_sec.num_samples > kMinRequiredPeriodicSamples) {
asapersson1d02d3e2016-09-10 05:40:25591 RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.RtcpBitrateReceivedInBps",
592 rtcp_bytes_per_sec.average * 8);
Mirko Bonadei675513b2017-11-09 10:09:25593 RTC_LOG(LS_INFO) << "WebRTC.Call.RtcpBitrateReceivedInBps, "
594 << rtcp_bytes_per_sec.ToStringWithMultiplier(8);
stefan91d92602015-11-11 18:13:02595 }
asapersson250fd972016-09-08 07:07:21596 AggregatedStats recv_bytes_per_sec =
597 received_bytes_per_second_counter_.GetStats();
598 if (recv_bytes_per_sec.num_samples > kMinRequiredPeriodicSamples) {
asapersson1d02d3e2016-09-10 05:40:25599 RTC_HISTOGRAM_COUNTS_100000("WebRTC.Call.BitrateReceivedInKbps",
600 recv_bytes_per_sec.average * 8 / 1000);
Mirko Bonadei675513b2017-11-09 10:09:25601 RTC_LOG(LS_INFO) << "WebRTC.Call.BitrateReceivedInBps, "
602 << recv_bytes_per_sec.ToStringWithMultiplier(8);
asapersson250fd972016-09-08 07:07:21603 }
stefan91d92602015-11-11 18:13:02604}
605
solenberg5a289392015-10-19 10:39:20606PacketReceiver* Call::Receiver() {
Sebastian Janssonb55015e2019-04-09 11:44:04607 RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
solenberg5a289392015-10-19 10:39:20608 return this;
609}
pbos@webrtc.org29d58392013-05-16 12:08:03610
Fredrik Solenberg04f49312015-06-08 11:04:56611webrtc::AudioSendStream* Call::CreateAudioSendStream(
612 const webrtc::AudioSendStream::Config& config) {
solenbergc7a8b082015-10-16 21:35:07613 TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream");
Sebastian Janssonb55015e2019-04-09 11:44:04614 RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
Piotr (Peter) Slatalacc8e8bb2018-11-15 16:26:19615
Piotr (Peter) Slatalacc8e8bb2018-11-15 16:26:19616 RegisterRateObserver();
617
Oskar Sundbom56ef3052018-10-30 15:11:02618 // Stream config is logged in AudioSendStream::ConfigureStream, as it may
619 // change during the stream's lifetime.
Danil Chapovalovb9b146c2018-06-15 10:28:07620 absl::optional<RtpState> suspended_rtp_state;
ossuc3d4b482017-05-23 13:07:11621 {
622 const auto& iter = suspended_audio_send_ssrcs_.find(config.rtp.ssrc);
623 if (iter != suspended_audio_send_ssrcs_.end()) {
624 suspended_rtp_state.emplace(iter->second);
625 }
626 }
627
Sebastian Jansson44dd9f22019-03-08 13:50:30628 AudioSendStream* send_stream =
629 new AudioSendStream(clock_, config, config_.audio_state,
630 task_queue_factory_, module_process_thread_.get(),
631 transport_send_ptr_, bitrate_allocator_.get(),
632 event_log_, call_stats_.get(), suspended_rtp_state);
solenbergc7a8b082015-10-16 21:35:07633 {
solenbergc7a8b082015-10-16 21:35:07634 WriteLockScoped write_lock(*send_crit_);
635 RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) ==
636 audio_send_ssrcs_.end());
637 audio_send_ssrcs_[config.rtp.ssrc] = send_stream;
solenbergc7a8b082015-10-16 21:35:07638 }
solenberg7602aab2016-11-14 19:30:07639 {
640 ReadLockScoped read_lock(*receive_crit_);
nissee4bcd6d2017-05-16 11:47:04641 for (AudioReceiveStream* stream : audio_receive_streams_) {
642 if (stream->config().rtp.local_ssrc == config.rtp.ssrc) {
643 stream->AssociateSendStream(send_stream);
solenberg7602aab2016-11-14 19:30:07644 }
645 }
646 }
skvlad7a43d252016-03-22 22:32:27647 UpdateAggregateNetworkState();
solenbergc7a8b082015-10-16 21:35:07648 return send_stream;
Fredrik Solenberg04f49312015-06-08 11:04:56649}
650
651void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) {
solenbergc7a8b082015-10-16 21:35:07652 TRACE_EVENT0("webrtc", "Call::DestroyAudioSendStream");
Sebastian Janssonb55015e2019-04-09 11:44:04653 RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
solenbergc7a8b082015-10-16 21:35:07654 RTC_DCHECK(send_stream != nullptr);
655
656 send_stream->Stop();
657
eladalonabbc4302017-07-26 09:09:44658 const uint32_t ssrc = send_stream->GetConfig().rtp.ssrc;
solenbergc7a8b082015-10-16 21:35:07659 webrtc::internal::AudioSendStream* audio_send_stream =
660 static_cast<webrtc::internal::AudioSendStream*>(send_stream);
ossuc3d4b482017-05-23 13:07:11661 suspended_audio_send_ssrcs_[ssrc] = audio_send_stream->GetRtpState();
solenbergc7a8b082015-10-16 21:35:07662 {
663 WriteLockScoped write_lock(*send_crit_);
solenberg7602aab2016-11-14 19:30:07664 size_t num_deleted = audio_send_ssrcs_.erase(ssrc);
665 RTC_DCHECK_EQ(1, num_deleted);
666 }
667 {
668 ReadLockScoped read_lock(*receive_crit_);
nissee4bcd6d2017-05-16 11:47:04669 for (AudioReceiveStream* stream : audio_receive_streams_) {
670 if (stream->config().rtp.local_ssrc == ssrc) {
671 stream->AssociateSendStream(nullptr);
solenberg7602aab2016-11-14 19:30:07672 }
673 }
solenbergc7a8b082015-10-16 21:35:07674 }
skvlad7a43d252016-03-22 22:32:27675 UpdateAggregateNetworkState();
eladalonabbc4302017-07-26 09:09:44676 delete send_stream;
Fredrik Solenberg04f49312015-06-08 11:04:56677}
678
Fredrik Solenberg23fba1f2015-04-29 13:24:01679webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream(
680 const webrtc::AudioReceiveStream::Config& config) {
681 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream");
Sebastian Janssonb55015e2019-04-09 11:44:04682 RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
Piotr (Peter) Slatalab2757882018-12-18 19:17:09683 RegisterRateObserver();
Mirko Bonadei317a1f02019-09-17 15:06:18684 event_log_->Log(std::make_unique<RtcEventAudioReceiveStreamConfig>(
Elad Alon4a87e1c2017-10-03 14:11:34685 CreateRtcLogStreamConfig(config)));
nisse0f15f922017-06-21 08:05:22686 AudioReceiveStream* receive_stream = new AudioReceiveStream(
Sebastian Jansson977b3352019-03-04 16:43:34687 clock_, &audio_receiver_controller_, transport_send_ptr_->packet_router(),
Ivo Creusenc3d1f9b2019-11-01 10:47:51688 module_process_thread_.get(), config_.neteq_factory, config,
689 config_.audio_state, event_log_);
Fredrik Solenberg23fba1f2015-04-29 13:24:01690 {
691 WriteLockScoped write_lock(*receive_crit_);
Erik Språng09708512018-03-14 14:16:50692 receive_rtp_config_.emplace(config.rtp.remote_ssrc,
693 ReceiveRtpConfig(config));
nissee4bcd6d2017-05-16 11:47:04694 audio_receive_streams_.insert(receive_stream);
nissed44ce052017-02-06 10:23:00695
pbos8fc7fa72015-07-15 15:02:58696 ConfigureSync(config.sync_group);
Fredrik Solenberg23fba1f2015-04-29 13:24:01697 }
solenberg7602aab2016-11-14 19:30:07698 {
699 ReadLockScoped read_lock(*send_crit_);
700 auto it = audio_send_ssrcs_.find(config.rtp.local_ssrc);
701 if (it != audio_send_ssrcs_.end()) {
702 receive_stream->AssociateSendStream(it->second);
703 }
704 }
skvlad7a43d252016-03-22 22:32:27705 UpdateAggregateNetworkState();
Fredrik Solenberg23fba1f2015-04-29 13:24:01706 return receive_stream;
707}
708
709void Call::DestroyAudioReceiveStream(
710 webrtc::AudioReceiveStream* receive_stream) {
711 TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream");
Sebastian Janssonb55015e2019-04-09 11:44:04712 RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
henrikg91d6ede2015-09-17 07:24:34713 RTC_DCHECK(receive_stream != nullptr);
solenbergc7a8b082015-10-16 21:35:07714 webrtc::internal::AudioReceiveStream* audio_receive_stream =
715 static_cast<webrtc::internal::AudioReceiveStream*>(receive_stream);
Fredrik Solenberg23fba1f2015-04-29 13:24:01716 {
717 WriteLockScoped write_lock(*receive_crit_);
nisse4709e892017-02-07 09:18:43718 const AudioReceiveStream::Config& config = audio_receive_stream->config();
719 uint32_t ssrc = config.rtp.remote_ssrc;
nisse559af382017-03-21 13:41:12720 receive_side_cc_.GetRemoteBitrateEstimator(UseSendSideBwe(config))
nisse4709e892017-02-07 09:18:43721 ->RemoveStream(ssrc);
nissee4bcd6d2017-05-16 11:47:04722 audio_receive_streams_.erase(audio_receive_stream);
pbos8fc7fa72015-07-15 15:02:58723 const std::string& sync_group = audio_receive_stream->config().sync_group;
724 const auto it = sync_stream_mapping_.find(sync_group);
725 if (it != sync_stream_mapping_.end() &&
726 it->second == audio_receive_stream) {
727 sync_stream_mapping_.erase(it);
728 ConfigureSync(sync_group);
729 }
nissed44ce052017-02-06 10:23:00730 receive_rtp_config_.erase(ssrc);
Fredrik Solenberg23fba1f2015-04-29 13:24:01731 }
skvlad7a43d252016-03-22 22:32:27732 UpdateAggregateNetworkState();
Fredrik Solenberg23fba1f2015-04-29 13:24:01733 delete audio_receive_stream;
734}
735
Ying Wang0dd1b0a2018-02-20 11:50:27736// This method can be used for Call tests with external fec controller factory.
Ying Wang3b790f32018-01-19 16:58:57737webrtc::VideoSendStream* Call::CreateVideoSendStream(
738 webrtc::VideoSendStream::Config config,
739 VideoEncoderConfig encoder_config,
740 std::unique_ptr<FecController> fec_controller) {
pbos@webrtc.org50fe3592015-01-29 12:33:07741 TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream");
Sebastian Janssonb55015e2019-04-09 11:44:04742 RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
pbos@webrtc.org1819fd72013-06-10 13:48:26743
Piotr (Peter) Slatalacc8e8bb2018-11-15 16:26:19744 RegisterRateObserver();
745
asapersson35151f32016-05-03 06:44:01746 video_send_delay_stats_->AddSsrcs(config);
perkjc0876aa2017-05-22 11:08:28747 for (size_t ssrc_index = 0; ssrc_index < config.rtp.ssrcs.size();
748 ++ssrc_index) {
Mirko Bonadei317a1f02019-09-17 15:06:18749 event_log_->Log(std::make_unique<RtcEventVideoSendStreamConfig>(
Elad Alon4a87e1c2017-10-03 14:11:34750 CreateRtcLogStreamConfig(config, ssrc_index)));
perkjc0876aa2017-05-22 11:08:28751 }
perkj26091b12016-09-01 08:17:40752
mflodman@webrtc.orgeb16b812014-06-16 08:57:39753 // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if
754 // the call has already started.
perkj26091b12016-09-01 08:17:40755 // Copy ssrcs from |config| since |config| is moved.
756 std::vector<uint32_t> ssrcs = config.rtp.ssrcs;
Ying Wang0dd1b0a2018-02-20 11:50:27757
mflodman0c478b32015-10-21 13:52:16758 VideoSendStream* send_stream = new VideoSendStream(
Sebastian Jansson0b698262019-03-07 08:17:19759 clock_, num_cpu_cores_, module_process_thread_.get(), task_queue_factory_,
Sebastian Jansson74682c12019-03-01 10:50:20760 call_stats_.get(), transport_send_ptr_, bitrate_allocator_.get(),
nisse05843312017-04-19 06:38:35761 video_send_delay_stats_.get(), event_log_, std::move(config),
Åsa Persson4bece9a2017-10-06 08:04:04762 std::move(encoder_config), suspended_video_send_ssrcs_,
Stefan Holmerdbdb3a02018-07-17 14:03:46763 suspended_video_payload_states_, std::move(fec_controller));
perkj26091b12016-09-01 08:17:40764
skvlad7a43d252016-03-22 22:32:27765 {
766 WriteLockScoped write_lock(*send_crit_);
perkj26091b12016-09-01 08:17:40767 for (uint32_t ssrc : ssrcs) {
skvlad7a43d252016-03-22 22:32:27768 RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end());
769 video_send_ssrcs_[ssrc] = send_stream;
770 }
771 video_send_streams_.insert(send_stream);
pbos@webrtc.org29d58392013-05-16 12:08:03772 }
skvlad7a43d252016-03-22 22:32:27773 UpdateAggregateNetworkState();
perkj26091b12016-09-01 08:17:40774
pbos@webrtc.org29d58392013-05-16 12:08:03775 return send_stream;
776}
777
Ying Wang0dd1b0a2018-02-20 11:50:27778webrtc::VideoSendStream* Call::CreateVideoSendStream(
779 webrtc::VideoSendStream::Config config,
780 VideoEncoderConfig encoder_config) {
Ying Wang012b7e72018-03-05 14:44:23781 if (config_.fec_controller_factory) {
782 RTC_LOG(LS_INFO) << "External FEC Controller will be used.";
783 }
Ying Wang0dd1b0a2018-02-20 11:50:27784 std::unique_ptr<FecController> fec_controller =
785 config_.fec_controller_factory
786 ? config_.fec_controller_factory->CreateFecController()
Mirko Bonadei317a1f02019-09-17 15:06:18787 : std::make_unique<FecControllerDefault>(clock_);
Ying Wang0dd1b0a2018-02-20 11:50:27788 return CreateVideoSendStream(std::move(config), std::move(encoder_config),
789 std::move(fec_controller));
790}
791
pbos@webrtc.org2c46f8d2013-11-21 13:49:43792void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) {
pbos@webrtc.org50fe3592015-01-29 12:33:07793 TRACE_EVENT0("webrtc", "Call::DestroyVideoSendStream");
henrikg91d6ede2015-09-17 07:24:34794 RTC_DCHECK(send_stream != nullptr);
Sebastian Janssonb55015e2019-04-09 11:44:04795 RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
pbos@webrtc.org95e51f52013-09-05 12:38:54796
pbos@webrtc.org2bb1bda2014-07-07 13:06:48797 send_stream->Stop();
798
pbos@webrtc.org2b4ce3a2015-03-23 13:12:24799 VideoSendStream* send_stream_impl = nullptr;
pbos@webrtc.org95e51f52013-09-05 12:38:54800 {
pbos@webrtc.org26c0c412014-09-03 16:17:12801 WriteLockScoped write_lock(*send_crit_);
Fredrik Solenberg23fba1f2015-04-29 13:24:01802 auto it = video_send_ssrcs_.begin();
803 while (it != video_send_ssrcs_.end()) {
pbos@webrtc.org95e51f52013-09-05 12:38:54804 if (it->second == static_cast<VideoSendStream*>(send_stream)) {
805 send_stream_impl = it->second;
Fredrik Solenberg23fba1f2015-04-29 13:24:01806 video_send_ssrcs_.erase(it++);
pbos@webrtc.org2bb1bda2014-07-07 13:06:48807 } else {
808 ++it;
pbos@webrtc.org95e51f52013-09-05 12:38:54809 }
810 }
Fredrik Solenberg23fba1f2015-04-29 13:24:01811 video_send_streams_.erase(send_stream_impl);
pbos@webrtc.org29d58392013-05-16 12:08:03812 }
henrikg91d6ede2015-09-17 07:24:34813 RTC_CHECK(send_stream_impl != nullptr);
pbos@webrtc.org95e51f52013-09-05 12:38:54814
Åsa Persson4bece9a2017-10-06 08:04:04815 VideoSendStream::RtpStateMap rtp_states;
816 VideoSendStream::RtpPayloadStateMap rtp_payload_states;
817 send_stream_impl->StopPermanentlyAndGetRtpStates(&rtp_states,
818 &rtp_payload_states);
819 for (const auto& kv : rtp_states) {
820 suspended_video_send_ssrcs_[kv.first] = kv.second;
821 }
822 for (const auto& kv : rtp_payload_states) {
823 suspended_video_payload_states_[kv.first] = kv.second;
pbos@webrtc.org2bb1bda2014-07-07 13:06:48824 }
825
skvlad7a43d252016-03-22 22:32:27826 UpdateAggregateNetworkState();
pbos@webrtc.org95e51f52013-09-05 12:38:54827 delete send_stream_impl;
pbos@webrtc.org29d58392013-05-16 12:08:03828}
829
Fredrik Solenberg23fba1f2015-04-29 13:24:01830webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream(
Tommi733b5472016-06-10 15:58:01831 webrtc::VideoReceiveStream::Config configuration) {
pbos@webrtc.org50fe3592015-01-29 12:33:07832 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream");
Sebastian Janssonb55015e2019-04-09 11:44:04833 RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
brandtrfb45c6c2017-01-27 14:47:55834
Johannes Kronf59666b2019-04-08 10:57:06835 receive_side_cc_.SetSendPeriodicFeedback(
836 SendPeriodicFeedback(configuration.rtp.extensions));
Johannes Kron7ff164e2019-02-07 11:50:18837
Piotr (Peter) Slatalab2757882018-12-18 19:17:09838 RegisterRateObserver();
839
nisse0f15f922017-06-21 08:05:22840 VideoReceiveStream* receive_stream = new VideoReceiveStream(
Sebastian Jansson896b47c2019-03-01 17:48:16841 task_queue_factory_, &video_receiver_controller_, num_cpu_cores_,
Sebastian Janssone6256052018-05-04 12:08:15842 transport_send_ptr_->packet_router(), std::move(configuration),
Sebastian Jansson8026d602019-03-04 18:39:01843 module_process_thread_.get(), call_stats_.get(), clock_);
Tommi733b5472016-06-10 15:58:01844
845 const webrtc::VideoReceiveStream::Config& config = receive_stream->config();
skvlad7a43d252016-03-22 22:32:27846 {
847 WriteLockScoped write_lock(*receive_crit_);
nissed44ce052017-02-06 10:23:00848 if (config.rtp.rtx_ssrc) {
nissed44ce052017-02-06 10:23:00849 // We record identical config for the rtx stream as for the main
nisseb8f9a322017-03-27 12:36:15850 // stream. Since the transport_send_cc negotiation is per payload
nissed44ce052017-02-06 10:23:00851 // type, we may get an incorrect value for the rtx stream, but
852 // that is unlikely to matter in practice.
Erik Språng09708512018-03-14 14:16:50853 receive_rtp_config_.emplace(config.rtp.rtx_ssrc,
854 ReceiveRtpConfig(config));
nissed44ce052017-02-06 10:23:00855 }
Erik Språng09708512018-03-14 14:16:50856 receive_rtp_config_.emplace(config.rtp.remote_ssrc,
857 ReceiveRtpConfig(config));
skvlad7a43d252016-03-22 22:32:27858 video_receive_streams_.insert(receive_stream);
skvlad7a43d252016-03-22 22:32:27859 ConfigureSync(config.sync_group);
860 }
861 receive_stream->SignalNetworkState(video_network_state_);
862 UpdateAggregateNetworkState();
Mirko Bonadei317a1f02019-09-17 15:06:18863 event_log_->Log(std::make_unique<RtcEventVideoReceiveStreamConfig>(
Elad Alon4a87e1c2017-10-03 14:11:34864 CreateRtcLogStreamConfig(config)));
pbos@webrtc.org29d58392013-05-16 12:08:03865 return receive_stream;
866}
867
pbos@webrtc.org2c46f8d2013-11-21 13:49:43868void Call::DestroyVideoReceiveStream(
869 webrtc::VideoReceiveStream* receive_stream) {
pbos@webrtc.org50fe3592015-01-29 12:33:07870 TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream");
Sebastian Janssonb55015e2019-04-09 11:44:04871 RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
henrikg91d6ede2015-09-17 07:24:34872 RTC_DCHECK(receive_stream != nullptr);
nissee4bcd6d2017-05-16 11:47:04873 VideoReceiveStream* receive_stream_impl =
874 static_cast<VideoReceiveStream*>(receive_stream);
875 const VideoReceiveStream::Config& config = receive_stream_impl->config();
pbos@webrtc.org95e51f52013-09-05 12:38:54876 {
pbos@webrtc.org26c0c412014-09-03 16:17:12877 WriteLockScoped write_lock(*receive_crit_);
pbos@webrtc.orgc279a5d2014-01-24 09:30:53878 // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a
879 // separate SSRC there can be either one or two.
nissee4bcd6d2017-05-16 11:47:04880 receive_rtp_config_.erase(config.rtp.remote_ssrc);
881 if (config.rtp.rtx_ssrc) {
882 receive_rtp_config_.erase(config.rtp.rtx_ssrc);
pbos@webrtc.org95e51f52013-09-05 12:38:54883 }
Fredrik Solenberg23fba1f2015-04-29 13:24:01884 video_receive_streams_.erase(receive_stream_impl);
nissee4bcd6d2017-05-16 11:47:04885 ConfigureSync(config.sync_group);
pbos@webrtc.org29d58392013-05-16 12:08:03886 }
nisse4709e892017-02-07 09:18:43887
nisse559af382017-03-21 13:41:12888 receive_side_cc_.GetRemoteBitrateEstimator(UseSendSideBwe(config))
nisse4709e892017-02-07 09:18:43889 ->RemoveStream(config.rtp.remote_ssrc);
890
skvlad7a43d252016-03-22 22:32:27891 UpdateAggregateNetworkState();
pbos@webrtc.org95e51f52013-09-05 12:38:54892 delete receive_stream_impl;
pbos@webrtc.org29d58392013-05-16 12:08:03893}
894
brandtr7250b392016-12-19 09:13:46895FlexfecReceiveStream* Call::CreateFlexfecReceiveStream(
896 const FlexfecReceiveStream::Config& config) {
brandtr25445d32016-10-24 06:37:14897 TRACE_EVENT0("webrtc", "Call::CreateFlexfecReceiveStream");
Sebastian Janssonb55015e2019-04-09 11:44:04898 RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
brandtrb29e6522016-12-21 14:37:18899
900 RecoveredPacketReceiver* recovered_packet_receiver = this;
brandtr25445d32016-10-24 06:37:14901
nisse0f15f922017-06-21 08:05:22902 FlexfecReceiveStreamImpl* receive_stream;
brandtr25445d32016-10-24 06:37:14903 {
904 WriteLockScoped write_lock(*receive_crit_);
nisse0f15f922017-06-21 08:05:22905 // Unlike the video and audio receive streams,
906 // FlexfecReceiveStream implements RtpPacketSinkInterface itself,
907 // and hence its constructor passes its |this| pointer to
eladalon2a2b2972017-07-03 16:25:27908 // video_receiver_controller_->CreateStream(). Calling the
nisse0f15f922017-06-21 08:05:22909 // constructor while holding |receive_crit_| ensures that we don't
910 // call OnRtpPacket until the constructor is finished and the
911 // object is in a valid state.
912 // TODO(nisse): Fix constructor so that it can be moved outside of
913 // this locked scope.
914 receive_stream = new FlexfecReceiveStreamImpl(
Sebastian Jansson8026d602019-03-04 18:39:01915 clock_, &video_receiver_controller_, config, recovered_packet_receiver,
Tommi38c5d932018-03-27 21:11:09916 call_stats_.get(), module_process_thread_.get());
brandtrb29e6522016-12-21 14:37:18917
nissed44ce052017-02-06 10:23:00918 RTC_DCHECK(receive_rtp_config_.find(config.remote_ssrc) ==
919 receive_rtp_config_.end());
Erik Språng09708512018-03-14 14:16:50920 receive_rtp_config_.emplace(config.remote_ssrc, ReceiveRtpConfig(config));
brandtr25445d32016-10-24 06:37:14921 }
brandtrb29e6522016-12-21 14:37:18922
brandtr25445d32016-10-24 06:37:14923 // TODO(brandtr): Store config in RtcEventLog here.
brandtrb29e6522016-12-21 14:37:18924
brandtr25445d32016-10-24 06:37:14925 return receive_stream;
926}
927
brandtr7250b392016-12-19 09:13:46928void Call::DestroyFlexfecReceiveStream(FlexfecReceiveStream* receive_stream) {
brandtr25445d32016-10-24 06:37:14929 TRACE_EVENT0("webrtc", "Call::DestroyFlexfecReceiveStream");
Sebastian Janssonb55015e2019-04-09 11:44:04930 RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
brandtrb29e6522016-12-21 14:37:18931
brandtr25445d32016-10-24 06:37:14932 RTC_DCHECK(receive_stream != nullptr);
brandtr25445d32016-10-24 06:37:14933 {
934 WriteLockScoped write_lock(*receive_crit_);
brandtrb29e6522016-12-21 14:37:18935
eladalon42f44f92017-07-25 13:40:06936 const FlexfecReceiveStream::Config& config = receive_stream->GetConfig();
nisse4709e892017-02-07 09:18:43937 uint32_t ssrc = config.remote_ssrc;
nissed44ce052017-02-06 10:23:00938 receive_rtp_config_.erase(ssrc);
brandtrb29e6522016-12-21 14:37:18939
brandtr7250b392016-12-19 09:13:46940 // Remove all SSRCs pointing to the FlexfecReceiveStreamImpl to be
941 // destroyed.
nisse559af382017-03-21 13:41:12942 receive_side_cc_.GetRemoteBitrateEstimator(UseSendSideBwe(config))
nisse4709e892017-02-07 09:18:43943 ->RemoveStream(ssrc);
brandtr25445d32016-10-24 06:37:14944 }
brandtrb29e6522016-12-21 14:37:18945
eladalon42f44f92017-07-25 13:40:06946 delete receive_stream;
brandtr25445d32016-10-24 06:37:14947}
948
Sebastian Jansson8f83b422018-02-21 12:07:13949RtpTransportControllerSendInterface* Call::GetTransportControllerSend() {
Sebastian Janssone6256052018-05-04 12:08:15950 return transport_send_ptr_;
Sebastian Jansson8f83b422018-02-21 12:07:13951}
952
stefan@webrtc.org0bae1fa2014-11-05 14:05:29953Call::Stats Call::GetStats() const {
Tommi48b48e52019-08-09 09:42:32954 RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
955
956 // TODO(tommi): The following stats are managed on the process thread:
957 // - pacer_delay_ms (PacedSender::Process)
958 // - rtt_ms
959 // - recv_bandwidth_bps
960 // These are delivered on the network TQ:
961 // - send_bandwidth_bps (see OnTargetTransferRate)
962 // - max_padding_bitrate_bps (see OnAllocationLimitsChanged)
963
stefan@webrtc.org0bae1fa2014-11-05 14:05:29964 Stats stats;
Tommi48b48e52019-08-09 09:42:32965 // TODO(srte): It is unclear if we only want to report queues if network is
966 // available.
967 stats.pacer_delay_ms =
968 aggregate_network_up_ ? transport_send_ptr_->GetPacerQueuingDelayMs() : 0;
969
970 stats.rtt_ms = call_stats_->LastProcessedRtt();
971
Peter Boström45553ae2015-05-08 11:54:38972 // Fetch available send/receive bitrates.
Peter Boström45553ae2015-05-08 11:54:38973 std::vector<unsigned int> ssrcs;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29974 uint32_t recv_bandwidth = 0;
nisse559af382017-03-21 13:41:12975 receive_side_cc_.GetRemoteBitrateEstimator(false)->LatestEstimate(
mflodmana20de202015-10-19 05:08:19976 &ssrcs, &recv_bandwidth);
Tommi48b48e52019-08-09 09:42:32977 stats.recv_bandwidth_bps = recv_bandwidth;
Sebastian Jansson19704ec2018-03-12 14:59:12978
979 {
980 rtc::CritScope cs(&last_bandwidth_bps_crit_);
981 stats.send_bandwidth_bps = last_bandwidth_bps_;
982 }
Sebastian Janssona06e9192018-03-07 17:49:55983
sprang9c0b5512016-07-06 07:54:28984 {
985 rtc::CritScope cs(&bitrate_crit_);
986 stats.max_padding_bitrate_bps = configured_max_padding_bitrate_bps_;
987 }
Tommi48b48e52019-08-09 09:42:32988
stefan@webrtc.org0bae1fa2014-11-05 14:05:29989 return stats;
pbos@webrtc.org29d58392013-05-16 12:08:03990}
991
skvlad7a43d252016-03-22 22:32:27992void Call::SignalChannelNetworkState(MediaType media, NetworkState state) {
Sebastian Janssonb55015e2019-04-09 11:44:04993 RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
skvlad7a43d252016-03-22 22:32:27994 switch (media) {
995 case MediaType::AUDIO:
996 audio_network_state_ = state;
997 break;
998 case MediaType::VIDEO:
999 video_network_state_ = state;
1000 break;
1001 case MediaType::ANY:
1002 case MediaType::DATA:
1003 RTC_NOTREACHED();
1004 break;
1005 }
1006
1007 UpdateAggregateNetworkState();
pbos@webrtc.org26c0c412014-09-03 16:17:121008 {
skvlad7a43d252016-03-22 22:32:271009 ReadLockScoped read_lock(*receive_crit_);
nissee4bcd6d2017-05-16 11:47:041010 for (VideoReceiveStream* video_receive_stream : video_receive_streams_) {
1011 video_receive_stream->SignalNetworkState(video_network_state_);
pbos@webrtc.org26c0c412014-09-03 16:17:121012 }
1013 }
1014}
1015
Stefan Holmer64be7fa2018-10-04 13:21:551016void Call::OnAudioTransportOverheadChanged(int transport_overhead_per_packet) {
1017 ReadLockScoped read_lock(*send_crit_);
1018 for (auto& kv : audio_send_ssrcs_) {
1019 kv.second->SetTransportOverhead(transport_overhead_per_packet);
michaelt79e05882016-11-08 10:50:091020 }
1021}
1022
skvlad7a43d252016-03-22 22:32:271023void Call::UpdateAggregateNetworkState() {
Sebastian Janssonb55015e2019-04-09 11:44:041024 RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
skvlad7a43d252016-03-22 22:32:271025
1026 bool have_audio = false;
1027 bool have_video = false;
1028 {
1029 ReadLockScoped read_lock(*send_crit_);
Benjamin Wright41f9f2c2019-03-14 01:03:291030 if (!audio_send_ssrcs_.empty())
skvlad7a43d252016-03-22 22:32:271031 have_audio = true;
Benjamin Wright41f9f2c2019-03-14 01:03:291032 if (!video_send_ssrcs_.empty())
skvlad7a43d252016-03-22 22:32:271033 have_video = true;
1034 }
1035 {
1036 ReadLockScoped read_lock(*receive_crit_);
Benjamin Wright41f9f2c2019-03-14 01:03:291037 if (!audio_receive_streams_.empty())
skvlad7a43d252016-03-22 22:32:271038 have_audio = true;
Benjamin Wright41f9f2c2019-03-14 01:03:291039 if (!video_receive_streams_.empty())
skvlad7a43d252016-03-22 22:32:271040 have_video = true;
1041 }
1042
Sebastian Janssona06e9192018-03-07 17:49:551043 bool aggregate_network_up =
1044 ((have_video && video_network_state_ == kNetworkUp) ||
1045 (have_audio && audio_network_state_ == kNetworkUp));
skvlad7a43d252016-03-22 22:32:271046
Harald Alvestrand977b2652019-12-12 12:40:501047 if (aggregate_network_up != aggregate_network_up_) {
1048 RTC_LOG(LS_INFO)
1049 << "UpdateAggregateNetworkState: aggregate_state change to "
1050 << (aggregate_network_up ? "up" : "down");
1051 } else {
1052 RTC_LOG(LS_VERBOSE)
1053 << "UpdateAggregateNetworkState: aggregate_state remains at "
1054 << (aggregate_network_up ? "up" : "down");
1055 }
Tommi48b48e52019-08-09 09:42:321056 aggregate_network_up_ = aggregate_network_up;
1057
Sebastian Janssone6256052018-05-04 12:08:151058 transport_send_ptr_->OnNetworkAvailability(aggregate_network_up);
skvlad7a43d252016-03-22 22:32:271059}
1060
stefanc1aeaf02015-10-15 14:26:071061void Call::OnSentPacket(const rtc::SentPacket& sent_packet) {
asapersson35151f32016-05-03 06:44:011062 video_send_delay_stats_->OnSentPacket(sent_packet.packet_id,
1063 clock_->TimeInMilliseconds());
Sebastian Janssone6256052018-05-04 12:08:151064 transport_send_ptr_->OnSentPacket(sent_packet);
stefanc1aeaf02015-10-15 14:26:071065}
1066
Sebastian Jansson2701bc92018-12-11 14:02:471067void Call::OnStartRateUpdate(DataRate start_rate) {
Tommi48b48e52019-08-09 09:42:321068 RTC_DCHECK(network_queue()->IsCurrent());
Sebastian Jansson2701bc92018-12-11 14:02:471069 bitrate_allocator_->UpdateStartRate(start_rate.bps<uint32_t>());
1070}
1071
Sebastian Jansson19704ec2018-03-12 14:59:121072void Call::OnTargetTransferRate(TargetTransferRate msg) {
Tommi48b48e52019-08-09 09:42:321073 RTC_DCHECK(network_queue()->IsCurrent());
Tommi78a71382019-08-08 10:27:531074 RTC_DCHECK_RUN_ON(&worker_sequence_checker_);
Sebastian Jansson19704ec2018-03-12 14:59:121075 {
1076 rtc::CritScope cs(&last_bandwidth_bps_crit_);
Sebastian Janssonf34116e2019-09-24 15:55:501077 last_bandwidth_bps_ = msg.target_rate.bps();
Sebastian Jansson19704ec2018-03-12 14:59:121078 }
Sebastian Jansson40de3cc2019-09-19 12:54:431079
1080 uint32_t target_bitrate_bps = msg.target_rate.bps();
nisse559af382017-03-21 13:41:121081 // For controlling the rate of feedback messages.
1082 receive_side_cc_.OnBitrateChanged(target_bitrate_bps);
Sebastian Jansson40de3cc2019-09-19 12:54:431083 bitrate_allocator_->OnNetworkEstimateChanged(msg);
mflodman0e7e2592015-11-13 05:02:421084
asaperssonce2e1362016-09-09 07:13:351085 // Ignore updates if bitrate is zero (the aggregate network state is down).
1086 if (target_bitrate_bps == 0) {
stefan18adf0a2015-11-17 14:24:561087 rtc::CritScope lock(&bitrate_crit_);
asaperssonce2e1362016-09-09 07:13:351088 estimated_send_bitrate_kbps_counter_.ProcessAndPause();
1089 pacer_bitrate_kbps_counter_.ProcessAndPause();
1090 return;
stefan18adf0a2015-11-17 14:24:561091 }
asaperssonce2e1362016-09-09 07:13:351092
1093 bool sending_video;
1094 {
1095 ReadLockScoped read_lock(*send_crit_);
1096 sending_video = !video_send_streams_.empty();
1097 }
1098
1099 rtc::CritScope lock(&bitrate_crit_);
1100 if (!sending_video) {
1101 // Do not update the stats if we are not sending video.
1102 estimated_send_bitrate_kbps_counter_.ProcessAndPause();
1103 pacer_bitrate_kbps_counter_.ProcessAndPause();
1104 return;
1105 }
1106 estimated_send_bitrate_kbps_counter_.Add(target_bitrate_bps / 1000);
1107 // Pacer bitrate may be higher than bitrate estimate if enforcing min bitrate.
1108 uint32_t pacer_bitrate_bps =
1109 std::max(target_bitrate_bps, min_allocated_send_bitrate_bps_);
1110 pacer_bitrate_kbps_counter_.Add(pacer_bitrate_bps / 1000);
perkj71ee44c2016-06-15 07:47:531111}
mflodman101f2502016-06-09 15:21:191112
Sebastian Jansson93b1ea22019-09-18 16:31:521113void Call::OnAllocationLimitsChanged(BitrateAllocationLimits limits) {
Tommi48b48e52019-08-09 09:42:321114 RTC_DCHECK(network_queue()->IsCurrent());
Tommi78a71382019-08-08 10:27:531115 RTC_DCHECK_RUN_ON(&worker_sequence_checker_);
Tommi48b48e52019-08-09 09:42:321116
Sebastian Jansson93b1ea22019-09-18 16:31:521117 transport_send_ptr_->SetAllocatedSendBitrateLimits(limits);
Sebastian Jansson35fa2802018-10-01 07:16:121118
Sebastian Jansson93b1ea22019-09-18 16:31:521119 min_allocated_send_bitrate_bps_ = limits.min_allocatable_rate.bps();
Piotr (Peter) Slatala48c54932019-01-28 14:50:381120
perkj71ee44c2016-06-15 07:47:531121 rtc::CritScope lock(&bitrate_crit_);
Sebastian Jansson93b1ea22019-09-18 16:31:521122 configured_max_padding_bitrate_bps_ = limits.max_padding_rate.bps();
mflodman0e7e2592015-11-13 05:02:421123}
1124
pbos8fc7fa72015-07-15 15:02:581125void Call::ConfigureSync(const std::string& sync_group) {
1126 // Set sync only if there was no previous one.
solenberg3ebbcb52017-01-31 11:58:401127 if (sync_group.empty())
pbos8fc7fa72015-07-15 15:02:581128 return;
1129
1130 AudioReceiveStream* sync_audio_stream = nullptr;
1131 // Find existing audio stream.
1132 const auto it = sync_stream_mapping_.find(sync_group);
1133 if (it != sync_stream_mapping_.end()) {
1134 sync_audio_stream = it->second;
1135 } else {
1136 // No configured audio stream, see if we can find one.
nissee4bcd6d2017-05-16 11:47:041137 for (AudioReceiveStream* stream : audio_receive_streams_) {
1138 if (stream->config().sync_group == sync_group) {
pbos8fc7fa72015-07-15 15:02:581139 if (sync_audio_stream != nullptr) {
Mirko Bonadei675513b2017-11-09 10:09:251140 RTC_LOG(LS_WARNING)
1141 << "Attempting to sync more than one audio stream "
1142 "within the same sync group. This is not "
1143 "supported in the current implementation.";
pbos8fc7fa72015-07-15 15:02:581144 break;
1145 }
nissee4bcd6d2017-05-16 11:47:041146 sync_audio_stream = stream;
pbos8fc7fa72015-07-15 15:02:581147 }
1148 }
1149 }
1150 if (sync_audio_stream)
1151 sync_stream_mapping_[sync_group] = sync_audio_stream;
1152 size_t num_synced_streams = 0;
1153 for (VideoReceiveStream* video_stream : video_receive_streams_) {
1154 if (video_stream->config().sync_group != sync_group)
1155 continue;
1156 ++num_synced_streams;
1157 if (num_synced_streams > 1) {
1158 // TODO(pbos): Support synchronizing more than one A/V pair.
1159 // https://code.google.com/p/webrtc/issues/detail?id=4762
Mirko Bonadei675513b2017-11-09 10:09:251160 RTC_LOG(LS_WARNING)
1161 << "Attempting to sync more than one audio/video pair "
1162 "within the same sync group. This is not supported in "
1163 "the current implementation.";
pbos8fc7fa72015-07-15 15:02:581164 }
1165 // Only sync the first A/V pair within this sync group.
solenberg3ebbcb52017-01-31 11:58:401166 if (num_synced_streams == 1) {
1167 // sync_audio_stream may be null and that's ok.
1168 video_stream->SetSync(sync_audio_stream);
pbos8fc7fa72015-07-15 15:02:581169 } else {
solenberg3ebbcb52017-01-31 11:58:401170 video_stream->SetSync(nullptr);
pbos8fc7fa72015-07-15 15:02:581171 }
1172 }
1173}
1174
Fredrik Solenberg23fba1f2015-04-29 13:24:011175PacketReceiver::DeliveryStatus Call::DeliverRtcp(MediaType media_type,
1176 const uint8_t* packet,
1177 size_t length) {
Peter Boström6f28cf02015-12-07 22:17:151178 TRACE_EVENT0("webrtc", "Call::DeliverRtcp");
mflodman3d7db262016-04-29 07:57:131179 // TODO(pbos): Make sure it's a valid packet.
pbos@webrtc.orgcaba2d22014-05-14 13:57:121180 // Return DELIVERY_UNKNOWN_SSRC if it can be determined that
1181 // there's no receiver of the packet.
asapersson250fd972016-09-08 07:07:211182 if (received_bytes_per_second_counter_.HasSample()) {
1183 // First RTP packet has been received.
1184 received_bytes_per_second_counter_.Add(static_cast<int>(length));
1185 received_rtcp_bytes_per_second_counter_.Add(static_cast<int>(length));
1186 }
pbos@webrtc.org29d58392013-05-16 12:08:031187 bool rtcp_delivered = false;
Fredrik Solenberg23fba1f2015-04-29 13:24:011188 if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) {
pbos@webrtc.org26c0c412014-09-03 16:17:121189 ReadLockScoped read_lock(*receive_crit_);
Fredrik Solenberg23fba1f2015-04-29 13:24:011190 for (VideoReceiveStream* stream : video_receive_streams_) {
mflodman3d7db262016-04-29 07:57:131191 if (stream->DeliverRtcp(packet, length))
pbos@webrtc.org40523702013-08-05 12:49:221192 rtcp_delivered = true;
mflodman3d7db262016-04-29 07:57:131193 }
1194 }
1195 if (media_type == MediaType::ANY || media_type == MediaType::AUDIO) {
1196 ReadLockScoped read_lock(*receive_crit_);
nissee4bcd6d2017-05-16 11:47:041197 for (AudioReceiveStream* stream : audio_receive_streams_) {
Niels Möller8fb1a6a2019-03-05 13:29:421198 stream->DeliverRtcp(packet, length);
1199 rtcp_delivered = true;
pbos@webrtc.orgbbb07e62013-08-05 12:01:361200 }
1201 }
Fredrik Solenberg23fba1f2015-04-29 13:24:011202 if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) {
pbos@webrtc.org26c0c412014-09-03 16:17:121203 ReadLockScoped read_lock(*send_crit_);
Fredrik Solenberg23fba1f2015-04-29 13:24:011204 for (VideoSendStream* stream : video_send_streams_) {
Niels Möller8fb1a6a2019-03-05 13:29:421205 stream->DeliverRtcp(packet, length);
1206 rtcp_delivered = true;
pbos@webrtc.org29d58392013-05-16 12:08:031207 }
1208 }
mflodman3d7db262016-04-29 07:57:131209 if (media_type == MediaType::ANY || media_type == MediaType::AUDIO) {
1210 ReadLockScoped read_lock(*send_crit_);
1211 for (auto& kv : audio_send_ssrcs_) {
Niels Möller8fb1a6a2019-03-05 13:29:421212 kv.second->DeliverRtcp(packet, length);
1213 rtcp_delivered = true;
mflodman3d7db262016-04-29 07:57:131214 }
1215 }
1216
Elad Alon4a87e1c2017-10-03 14:11:341217 if (rtcp_delivered) {
Mirko Bonadei317a1f02019-09-17 15:06:181218 event_log_->Log(std::make_unique<RtcEventRtcpPacketIncoming>(
Elad Alon4a87e1c2017-10-03 14:11:341219 rtc::MakeArrayView(packet, length)));
1220 }
mflodman3d7db262016-04-29 07:57:131221
pbos@webrtc.orgcaba2d22014-05-14 13:57:121222 return rtcp_delivered ? DELIVERY_OK : DELIVERY_PACKET_ERROR;
pbos@webrtc.org29d58392013-05-16 12:08:031223}
1224
Fredrik Solenberg23fba1f2015-04-29 13:24:011225PacketReceiver::DeliveryStatus Call::DeliverRtp(MediaType media_type,
Danil Chapovalov292a73e2017-12-07 16:00:401226 rtc::CopyOnWriteBuffer packet,
Niels Möller70082872018-08-07 09:03:121227 int64_t packet_time_us) {
Peter Boström6f28cf02015-12-07 22:17:151228 TRACE_EVENT0("webrtc", "Call::DeliverRtp");
nissed44ce052017-02-06 10:23:001229
Danil Chapovalovb709cf82017-10-04 12:01:451230 RtpPacketReceived parsed_packet;
Danil Chapovalov292a73e2017-12-07 16:00:401231 if (!parsed_packet.Parse(std::move(packet)))
Danil Chapovalovb709cf82017-10-04 12:01:451232 return DELIVERY_PACKET_ERROR;
1233
Niels Möller70082872018-08-07 09:03:121234 if (packet_time_us != -1) {
Sebastian Janssonb34556e2018-03-21 13:38:321235 if (receive_time_calculator_) {
Christoffer Rodbro992a8682018-10-30 14:14:361236 // Repair packet_time_us for clock resets by comparing a new read of
1237 // the same clock (TimeUTCMicros) to a monotonic clock reading.
Niels Möller70082872018-08-07 09:03:121238 packet_time_us = receive_time_calculator_->ReconcileReceiveTimes(
Christoffer Rodbro992a8682018-10-30 14:14:361239 packet_time_us, rtc::TimeUTCMicros(), clock_->TimeInMicroseconds());
Sebastian Janssonb34556e2018-03-21 13:38:321240 }
Niels Möller70082872018-08-07 09:03:121241 parsed_packet.set_arrival_time_ms((packet_time_us + 500) / 1000);
Danil Chapovalovb709cf82017-10-04 12:01:451242 } else {
1243 parsed_packet.set_arrival_time_ms(clock_->TimeInMilliseconds());
1244 }
nissed44ce052017-02-06 10:23:001245
sprangc1abde72017-07-11 10:56:211246 // We might get RTP keep-alive packets in accordance with RFC6263 section 4.6.
1247 // These are empty (zero length payload) RTP packets with an unsignaled
1248 // payload type.
Danil Chapovalovb709cf82017-10-04 12:01:451249 const bool is_keep_alive_packet = parsed_packet.payload_size() == 0;
sprangc1abde72017-07-11 10:56:211250
1251 RTC_DCHECK(media_type == MediaType::AUDIO || media_type == MediaType::VIDEO ||
1252 is_keep_alive_packet);
1253
sprangc1abde72017-07-11 10:56:211254 ReadLockScoped read_lock(*receive_crit_);
Danil Chapovalovb709cf82017-10-04 12:01:451255 auto it = receive_rtp_config_.find(parsed_packet.Ssrc());
nisse0f15f922017-06-21 08:05:221256 if (it == receive_rtp_config_.end()) {
Mirko Bonadei675513b2017-11-09 10:09:251257 RTC_LOG(LS_ERROR) << "receive_rtp_config_ lookup failed for ssrc "
1258 << parsed_packet.Ssrc();
nisse0f15f922017-06-21 08:05:221259 // Destruction of the receive stream, including deregistering from the
1260 // RtpDemuxer, is not protected by the |receive_crit_| lock. But
1261 // deregistering in the |receive_rtp_config_| map is protected by that lock.
1262 // So by not passing the packet on to demuxing in this case, we prevent
1263 // incoming packets to be passed on via the demuxer to a receive stream
1264 // which is being torned down.
1265 return DELIVERY_UNKNOWN_SSRC;
1266 }
Jonas Oreland6d835922019-03-18 09:59:401267
Danil Chapovalovb709cf82017-10-04 12:01:451268 parsed_packet.IdentifyExtensions(it->second.extensions);
nisse0f15f922017-06-21 08:05:221269
Danil Chapovalovb709cf82017-10-04 12:01:451270 NotifyBweOfReceivedPacket(parsed_packet, media_type);
nissed44ce052017-02-06 10:23:001271
Danil Chapovalovcbf5b732017-12-08 13:05:201272 // RateCounters expect input parameter as int, save it as int,
1273 // instead of converting each time it is passed to RateCounter::Add below.
1274 int length = static_cast<int>(parsed_packet.size());
nissee5ad5ca2017-03-30 06:57:431275 if (media_type == MediaType::AUDIO) {
Danil Chapovalovb709cf82017-10-04 12:01:451276 if (audio_receiver_controller_.OnRtpPacket(parsed_packet)) {
Danil Chapovalov292a73e2017-12-07 16:00:401277 received_bytes_per_second_counter_.Add(length);
1278 received_audio_bytes_per_second_counter_.Add(length);
Elad Alon4a87e1c2017-10-03 14:11:341279 event_log_->Log(
Mirko Bonadei317a1f02019-09-17 15:06:181280 std::make_unique<RtcEventRtpPacketIncoming>(parsed_packet));
Danil Chapovalovb709cf82017-10-04 12:01:451281 const int64_t arrival_time_ms = parsed_packet.arrival_time_ms();
saza0d7f04d2017-07-04 11:05:061282 if (!first_received_rtp_audio_ms_) {
1283 first_received_rtp_audio_ms_.emplace(arrival_time_ms);
1284 }
1285 last_received_rtp_audio_ms_.emplace(arrival_time_ms);
nisse657bab22017-02-21 14:28:101286 return DELIVERY_OK;
Fredrik Solenberg23fba1f2015-04-29 13:24:011287 }
nissee4bcd6d2017-05-16 11:47:041288 } else if (media_type == MediaType::VIDEO) {
Niels Möller2ff1f2a2018-08-09 14:16:341289 parsed_packet.set_payload_type_frequency(kVideoPayloadTypeFrequency);
Danil Chapovalovb709cf82017-10-04 12:01:451290 if (video_receiver_controller_.OnRtpPacket(parsed_packet)) {
Danil Chapovalov292a73e2017-12-07 16:00:401291 received_bytes_per_second_counter_.Add(length);
1292 received_video_bytes_per_second_counter_.Add(length);
Elad Alon4a87e1c2017-10-03 14:11:341293 event_log_->Log(
Mirko Bonadei317a1f02019-09-17 15:06:181294 std::make_unique<RtcEventRtpPacketIncoming>(parsed_packet));
Danil Chapovalovb709cf82017-10-04 12:01:451295 const int64_t arrival_time_ms = parsed_packet.arrival_time_ms();
saza0d7f04d2017-07-04 11:05:061296 if (!first_received_rtp_video_ms_) {
1297 first_received_rtp_video_ms_.emplace(arrival_time_ms);
1298 }
1299 last_received_rtp_video_ms_.emplace(arrival_time_ms);
nisse5c29a7a2017-02-16 14:52:321300 return DELIVERY_OK;
Fredrik Solenberg23fba1f2015-04-29 13:24:011301 }
1302 }
1303 return DELIVERY_UNKNOWN_SSRC;
pbos@webrtc.org29d58392013-05-16 12:08:031304}
1305
stefan68786d22015-09-08 12:36:151306PacketReceiver::DeliveryStatus Call::DeliverPacket(
1307 MediaType media_type,
Danil Chapovalov292a73e2017-12-07 16:00:401308 rtc::CopyOnWriteBuffer packet,
Niels Möller70082872018-08-07 09:03:121309 int64_t packet_time_us) {
Sebastian Janssonb55015e2019-04-09 11:44:041310 RTC_DCHECK_RUN_ON(&configuration_sequence_checker_);
Tommi25eb47c2019-08-29 14:39:051311 if (IsRtcp(packet.cdata(), packet.size()))
Danil Chapovalov292a73e2017-12-07 16:00:401312 return DeliverRtcp(media_type, packet.cdata(), packet.size());
pbos@webrtc.org29d58392013-05-16 12:08:031313
Niels Möller70082872018-08-07 09:03:121314 return DeliverRtp(media_type, std::move(packet), packet_time_us);
pbos@webrtc.org29d58392013-05-16 12:08:031315}
1316
nissed2ef3142017-05-11 15:00:581317void Call::OnRecoveredPacket(const uint8_t* packet, size_t length) {
Danil Chapovalovb709cf82017-10-04 12:01:451318 RtpPacketReceived parsed_packet;
1319 if (!parsed_packet.Parse(packet, length))
nissed2ef3142017-05-11 15:00:581320 return;
1321
Danil Chapovalovb709cf82017-10-04 12:01:451322 parsed_packet.set_recovered(true);
nissed2ef3142017-05-11 15:00:581323
brandtrcaea68f2017-08-23 07:55:171324 ReadLockScoped read_lock(*receive_crit_);
Danil Chapovalovb709cf82017-10-04 12:01:451325 auto it = receive_rtp_config_.find(parsed_packet.Ssrc());
brandtrcaea68f2017-08-23 07:55:171326 if (it == receive_rtp_config_.end()) {
Mirko Bonadei675513b2017-11-09 10:09:251327 RTC_LOG(LS_ERROR) << "receive_rtp_config_ lookup failed for ssrc "
1328 << parsed_packet.Ssrc();
brandtrcaea68f2017-08-23 07:55:171329 // Destruction of the receive stream, including deregistering from the
1330 // RtpDemuxer, is not protected by the |receive_crit_| lock. But
1331 // deregistering in the |receive_rtp_config_| map is protected by that lock.
1332 // So by not passing the packet on to demuxing in this case, we prevent
1333 // incoming packets to be passed on via the demuxer to a receive stream
Erik Språng09708512018-03-14 14:16:501334 // which is being torn down.
brandtrcaea68f2017-08-23 07:55:171335 return;
1336 }
Danil Chapovalovb709cf82017-10-04 12:01:451337 parsed_packet.IdentifyExtensions(it->second.extensions);
brandtrcaea68f2017-08-23 07:55:171338
1339 // TODO(brandtr): Update here when we support protecting audio packets too.
Niels Möller2ff1f2a2018-08-09 14:16:341340 parsed_packet.set_payload_type_frequency(kVideoPayloadTypeFrequency);
Danil Chapovalovb709cf82017-10-04 12:01:451341 video_receiver_controller_.OnRtpPacket(parsed_packet);
brandtr4e523862016-10-19 06:50:451342}
1343
nissed44ce052017-02-06 10:23:001344void Call::NotifyBweOfReceivedPacket(const RtpPacketReceived& packet,
1345 MediaType media_type) {
1346 auto it = receive_rtp_config_.find(packet.Ssrc());
nisse4709e892017-02-07 09:18:431347 bool use_send_side_bwe =
1348 (it != receive_rtp_config_.end()) && it->second.use_send_side_bwe;
nissed44ce052017-02-06 10:23:001349
brandtrb29e6522016-12-21 14:37:181350 RTPHeader header;
1351 packet.GetHeader(&header);
nissed44ce052017-02-06 10:23:001352
Sebastian Jansson607a6f12019-06-13 15:48:531353 ReceivedPacket packet_msg;
1354 packet_msg.size = DataSize::bytes(packet.payload_size());
1355 packet_msg.receive_time = Timestamp::ms(packet.arrival_time_ms());
Sebastian Jansson3d61ab12019-06-14 11:35:511356 if (header.extension.hasAbsoluteSendTime) {
1357 packet_msg.send_time = header.extension.GetAbsoluteSendTimestamp();
1358 }
Sebastian Jansson607a6f12019-06-13 15:48:531359 transport_send_ptr_->OnReceivedPacket(packet_msg);
Ying Wang8b279102019-05-27 15:19:081360
nisse4709e892017-02-07 09:18:431361 if (!use_send_side_bwe && header.extension.hasTransportSequenceNumber) {
nissed44ce052017-02-06 10:23:001362 // Inconsistent configuration of send side BWE. Do nothing.
1363 // TODO(nisse): Without this check, we may produce RTCP feedback
1364 // packets even when not negotiated. But it would be cleaner to
1365 // move the check down to RTCPSender::SendFeedbackPacket, which
1366 // would also help the PacketRouter to select an appropriate rtp
1367 // module in the case that some, but not all, have RTCP feedback
1368 // enabled.
1369 return;
1370 }
1371 // For audio, we only support send side BWE.
nissee5ad5ca2017-03-30 06:57:431372 if (media_type == MediaType::VIDEO ||
nisse4709e892017-02-07 09:18:431373 (use_send_side_bwe && header.extension.hasTransportSequenceNumber)) {
nisse559af382017-03-21 13:41:121374 receive_side_cc_.OnReceivedPacket(
nissed44ce052017-02-06 10:23:001375 packet.arrival_time_ms(), packet.payload_size() + packet.padding_size(),
1376 header);
1377 }
brandtrb29e6522016-12-21 14:37:181378}
1379
pbos@webrtc.org29d58392013-05-16 12:08:031380} // namespace internal
nisseb8f9a322017-03-27 12:36:151381
pbos@webrtc.org29d58392013-05-16 12:08:031382} // namespace webrtc