pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [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 +0000 | [diff] [blame] | 11 | #include <string.h> |
| 12 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 13 | #include <map> |
| 14 | #include <vector> |
| 15 | |
Peter Boström | 5c389d3 | 2015-09-25 13:58:30 +0200 | [diff] [blame] | 16 | #include "webrtc/audio/audio_receive_stream.h" |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 17 | #include "webrtc/audio/audio_send_stream.h" |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 18 | #include "webrtc/base/checks.h" |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 +0000 | [diff] [blame] | 19 | #include "webrtc/base/scoped_ptr.h" |
pbos@webrtc.org | 38344ed | 2014-09-24 06:05:00 +0000 | [diff] [blame] | 20 | #include "webrtc/base/thread_annotations.h" |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 21 | #include "webrtc/base/thread_checker.h" |
tommi | e4f9650 | 2015-10-20 23:00:48 -0700 | [diff] [blame] | 22 | #include "webrtc/base/trace_event.h" |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 23 | #include "webrtc/call.h" |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 24 | #include "webrtc/call/congestion_controller.h" |
Peter Boström | 5c389d3 | 2015-09-25 13:58:30 +0200 | [diff] [blame] | 25 | #include "webrtc/call/rtc_event_log.h" |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 26 | #include "webrtc/common.h" |
pbos@webrtc.org | c49d5b7 | 2013-12-05 12:11:47 +0000 | [diff] [blame] | 27 | #include "webrtc/config.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 28 | #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
sprang@webrtc.org | 2a6558c | 2015-01-28 12:37:36 +0000 | [diff] [blame] | 29 | #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 30 | #include "webrtc/modules/utility/include/process_thread.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 31 | #include "webrtc/system_wrappers/include/cpu_info.h" |
| 32 | #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| 33 | #include "webrtc/system_wrappers/include/logging.h" |
| 34 | #include "webrtc/system_wrappers/include/rw_lock_wrapper.h" |
| 35 | #include "webrtc/system_wrappers/include/trace.h" |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 36 | #include "webrtc/video/video_receive_stream.h" |
| 37 | #include "webrtc/video/video_send_stream.h" |
mflodman | e378702 | 2015-10-21 13:24:28 +0200 | [diff] [blame] | 38 | #include "webrtc/video_engine/call_stats.h" |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 39 | #include "webrtc/voice_engine/include/voe_codec.h" |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 40 | |
| 41 | namespace webrtc { |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 42 | |
pbos@webrtc.org | a73a678 | 2014-10-14 11:52:10 +0000 | [diff] [blame] | 43 | const int Call::Config::kDefaultStartBitrateBps = 300000; |
| 44 | |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 45 | namespace internal { |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 +0000 | [diff] [blame] | 46 | |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 47 | class Call : public webrtc::Call, public PacketReceiver { |
| 48 | public: |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 49 | explicit Call(const Call::Config& config); |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 50 | virtual ~Call(); |
| 51 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 52 | PacketReceiver* Receiver() override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 53 | |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 54 | webrtc::AudioSendStream* CreateAudioSendStream( |
| 55 | const webrtc::AudioSendStream::Config& config) override; |
| 56 | void DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) override; |
| 57 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 58 | webrtc::AudioReceiveStream* CreateAudioReceiveStream( |
| 59 | const webrtc::AudioReceiveStream::Config& config) override; |
| 60 | void DestroyAudioReceiveStream( |
| 61 | webrtc::AudioReceiveStream* receive_stream) override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 62 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 63 | webrtc::VideoSendStream* CreateVideoSendStream( |
| 64 | const webrtc::VideoSendStream::Config& config, |
| 65 | const VideoEncoderConfig& encoder_config) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 66 | void DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 67 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 68 | webrtc::VideoReceiveStream* CreateVideoReceiveStream( |
| 69 | const webrtc::VideoReceiveStream::Config& config) override; |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 70 | void DestroyVideoReceiveStream( |
| 71 | webrtc::VideoReceiveStream* receive_stream) override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 72 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 73 | Stats GetStats() const override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 74 | |
stefan | 68786d2 | 2015-09-08 05:36:15 -0700 | [diff] [blame] | 75 | DeliveryStatus DeliverPacket(MediaType media_type, |
| 76 | const uint8_t* packet, |
| 77 | size_t length, |
| 78 | const PacketTime& packet_time) override; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 79 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 80 | void SetBitrateConfig( |
| 81 | const webrtc::Call::Config::BitrateConfig& bitrate_config) override; |
| 82 | void SignalNetworkState(NetworkState state) override; |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 83 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 84 | void OnSentPacket(const rtc::SentPacket& sent_packet) override; |
| 85 | |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 86 | private: |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 87 | DeliveryStatus DeliverRtcp(MediaType media_type, const uint8_t* packet, |
| 88 | size_t length); |
stefan | 68786d2 | 2015-09-08 05:36:15 -0700 | [diff] [blame] | 89 | DeliveryStatus DeliverRtp(MediaType media_type, |
| 90 | const uint8_t* packet, |
| 91 | size_t length, |
| 92 | const PacketTime& packet_time); |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 93 | |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 94 | void ConfigureSync(const std::string& sync_group) |
| 95 | EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); |
| 96 | |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 97 | const int num_cpu_cores_; |
| 98 | const rtc::scoped_ptr<ProcessThread> module_process_thread_; |
mflodman | e378702 | 2015-10-21 13:24:28 +0200 | [diff] [blame] | 99 | const rtc::scoped_ptr<CallStats> call_stats_; |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 100 | const rtc::scoped_ptr<CongestionController> congestion_controller_; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 101 | Call::Config config_; |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 102 | rtc::ThreadChecker configuration_thread_checker_; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 103 | |
mflodman | 717432f | 2015-10-26 16:34:46 +0100 | [diff] [blame] | 104 | bool network_enabled_; |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 105 | |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 +0000 | [diff] [blame] | 106 | rtc::scoped_ptr<RWLockWrapper> receive_crit_; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 107 | // Audio and Video receive streams are owned by the client that creates them. |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 108 | std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 109 | GUARDED_BY(receive_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 110 | std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ |
| 111 | GUARDED_BY(receive_crit_); |
| 112 | std::set<VideoReceiveStream*> video_receive_streams_ |
| 113 | GUARDED_BY(receive_crit_); |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 114 | std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ |
| 115 | GUARDED_BY(receive_crit_); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 116 | |
kwiberg@webrtc.org | 00b8f6b | 2015-02-26 14:34:55 +0000 | [diff] [blame] | 117 | rtc::scoped_ptr<RWLockWrapper> send_crit_; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 118 | // Audio and Video send streams are owned by the client that creates them. |
| 119 | std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ GUARDED_BY(send_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 120 | std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); |
| 121 | std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 122 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 123 | VideoSendStream::RtpStateMap suspended_video_send_ssrcs_; |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 124 | |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 125 | RtcEventLog* event_log_ = nullptr; |
| 126 | VoECodec* voe_codec_ = nullptr; |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 127 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 128 | RTC_DISALLOW_COPY_AND_ASSIGN(Call); |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 129 | }; |
pbos@webrtc.org | c49d5b7 | 2013-12-05 12:11:47 +0000 | [diff] [blame] | 130 | } // namespace internal |
pbos@webrtc.org | fd39e13 | 2013-08-14 13:52:52 +0000 | [diff] [blame] | 131 | |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 132 | Call* Call::Create(const Call::Config& config) { |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 133 | return new internal::Call(config); |
pbos@webrtc.org | fd39e13 | 2013-08-14 13:52:52 +0000 | [diff] [blame] | 134 | } |
pbos@webrtc.org | fd39e13 | 2013-08-14 13:52:52 +0000 | [diff] [blame] | 135 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 136 | namespace internal { |
| 137 | |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 138 | Call::Call(const Call::Config& config) |
| 139 | : num_cpu_cores_(CpuInfo::DetectNumberOfCores()), |
stefan | 847855b | 2015-09-11 09:52:15 -0700 | [diff] [blame] | 140 | module_process_thread_(ProcessThread::Create("ModuleProcessThread")), |
mflodman | e378702 | 2015-10-21 13:24:28 +0200 | [diff] [blame] | 141 | call_stats_(new CallStats()), |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 142 | congestion_controller_(new CongestionController( |
| 143 | module_process_thread_.get(), call_stats_.get())), |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 144 | config_(config), |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 145 | network_enabled_(true), |
| 146 | receive_crit_(RWLockWrapper::CreateRWLock()), |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 147 | send_crit_(RWLockWrapper::CreateRWLock()) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 148 | RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); |
| 149 | RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, |
| 150 | config.bitrate_config.min_bitrate_bps); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 151 | if (config.bitrate_config.max_bitrate_bps != -1) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 152 | RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, |
| 153 | config.bitrate_config.start_bitrate_bps); |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 154 | } |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 155 | if (config.voice_engine) { |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 156 | // Keep a reference to VoECodec, so we're sure the VoiceEngine lives for the |
| 157 | // duration of the call. |
| 158 | voe_codec_ = VoECodec::GetInterface(config.voice_engine); |
| 159 | if (voe_codec_) |
| 160 | event_log_ = voe_codec_->GetEventLog(); |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 161 | } |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 162 | |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 163 | Trace::CreateTrace(); |
| 164 | module_process_thread_->Start(); |
mflodman | e378702 | 2015-10-21 13:24:28 +0200 | [diff] [blame] | 165 | module_process_thread_->RegisterModule(call_stats_.get()); |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 166 | |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 167 | congestion_controller_->SetBweBitrates( |
| 168 | config_.bitrate_config.min_bitrate_bps, |
| 169 | config_.bitrate_config.start_bitrate_bps, |
| 170 | config_.bitrate_config.max_bitrate_bps); |
terelius | 006d93d | 2015-11-05 12:02:15 -0800 | [diff] [blame] | 171 | |
| 172 | congestion_controller_->GetBitrateController()->SetEventLog(event_log_); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 173 | } |
| 174 | |
pbos@webrtc.org | 841c8a4 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 175 | Call::~Call() { |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 176 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 177 | RTC_CHECK(audio_send_ssrcs_.empty()); |
| 178 | RTC_CHECK(video_send_ssrcs_.empty()); |
| 179 | RTC_CHECK(video_send_streams_.empty()); |
| 180 | RTC_CHECK(audio_receive_ssrcs_.empty()); |
| 181 | RTC_CHECK(video_receive_ssrcs_.empty()); |
| 182 | RTC_CHECK(video_receive_streams_.empty()); |
pbos@webrtc.org | 9e4e524 | 2015-02-12 10:48:23 +0000 | [diff] [blame] | 183 | |
mflodman | e378702 | 2015-10-21 13:24:28 +0200 | [diff] [blame] | 184 | module_process_thread_->DeRegisterModule(call_stats_.get()); |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 185 | module_process_thread_->Stop(); |
| 186 | Trace::ReturnTrace(); |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 187 | |
| 188 | if (voe_codec_) |
| 189 | voe_codec_->Release(); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 190 | } |
| 191 | |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 192 | PacketReceiver* Call::Receiver() { |
| 193 | // TODO(solenberg): Some test cases in EndToEndTest use this from a different |
| 194 | // thread. Re-enable once that is fixed. |
| 195 | // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
| 196 | return this; |
| 197 | } |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 198 | |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 199 | webrtc::AudioSendStream* Call::CreateAudioSendStream( |
| 200 | const webrtc::AudioSendStream::Config& config) { |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 201 | TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream"); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 202 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
solenberg | 85a0496 | 2015-10-27 03:35:21 -0700 | [diff] [blame] | 203 | AudioSendStream* send_stream = |
| 204 | new AudioSendStream(config, config_.voice_engine); |
mflodman | 717432f | 2015-10-26 16:34:46 +0100 | [diff] [blame] | 205 | if (!network_enabled_) |
| 206 | send_stream->SignalNetworkState(kNetworkDown); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 207 | { |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 208 | WriteLockScoped write_lock(*send_crit_); |
| 209 | RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == |
| 210 | audio_send_ssrcs_.end()); |
| 211 | audio_send_ssrcs_[config.rtp.ssrc] = send_stream; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 212 | } |
| 213 | return send_stream; |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | void Call::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 217 | TRACE_EVENT0("webrtc", "Call::DestroyAudioSendStream"); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 218 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 219 | RTC_DCHECK(send_stream != nullptr); |
| 220 | |
| 221 | send_stream->Stop(); |
| 222 | |
| 223 | webrtc::internal::AudioSendStream* audio_send_stream = |
| 224 | static_cast<webrtc::internal::AudioSendStream*>(send_stream); |
| 225 | { |
| 226 | WriteLockScoped write_lock(*send_crit_); |
| 227 | size_t num_deleted = audio_send_ssrcs_.erase( |
| 228 | audio_send_stream->config().rtp.ssrc); |
| 229 | RTC_DCHECK(num_deleted == 1); |
| 230 | } |
| 231 | delete audio_send_stream; |
Fredrik Solenberg | 04f4931 | 2015-06-08 13:04:56 +0200 | [diff] [blame] | 232 | } |
| 233 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 234 | webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( |
| 235 | const webrtc::AudioReceiveStream::Config& config) { |
| 236 | TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 237 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 238 | AudioReceiveStream* receive_stream = new AudioReceiveStream( |
Fredrik Solenberg | 4f4ec0a | 2015-10-22 10:49:27 +0200 | [diff] [blame] | 239 | congestion_controller_->GetRemoteBitrateEstimator(false), config, |
| 240 | config_.voice_engine); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 241 | { |
| 242 | WriteLockScoped write_lock(*receive_crit_); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 243 | RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) == |
| 244 | audio_receive_ssrcs_.end()); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 245 | audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 246 | ConfigureSync(config.sync_group); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 247 | } |
| 248 | return receive_stream; |
| 249 | } |
| 250 | |
| 251 | void Call::DestroyAudioReceiveStream( |
| 252 | webrtc::AudioReceiveStream* receive_stream) { |
| 253 | TRACE_EVENT0("webrtc", "Call::DestroyAudioReceiveStream"); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 254 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 255 | RTC_DCHECK(receive_stream != nullptr); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 256 | webrtc::internal::AudioReceiveStream* audio_receive_stream = |
| 257 | static_cast<webrtc::internal::AudioReceiveStream*>(receive_stream); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 258 | { |
| 259 | WriteLockScoped write_lock(*receive_crit_); |
| 260 | size_t num_deleted = audio_receive_ssrcs_.erase( |
| 261 | audio_receive_stream->config().rtp.remote_ssrc); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 262 | RTC_DCHECK(num_deleted == 1); |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 263 | const std::string& sync_group = audio_receive_stream->config().sync_group; |
| 264 | const auto it = sync_stream_mapping_.find(sync_group); |
| 265 | if (it != sync_stream_mapping_.end() && |
| 266 | it->second == audio_receive_stream) { |
| 267 | sync_stream_mapping_.erase(it); |
| 268 | ConfigureSync(sync_group); |
| 269 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 270 | } |
| 271 | delete audio_receive_stream; |
| 272 | } |
| 273 | |
| 274 | webrtc::VideoSendStream* Call::CreateVideoSendStream( |
| 275 | const webrtc::VideoSendStream::Config& config, |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 276 | const VideoEncoderConfig& encoder_config) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 +0000 | [diff] [blame] | 277 | TRACE_EVENT0("webrtc", "Call::CreateVideoSendStream"); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 278 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
pbos@webrtc.org | 1819fd7 | 2013-06-10 13:48:26 +0000 | [diff] [blame] | 279 | |
mflodman@webrtc.org | eb16b81 | 2014-06-16 08:57:39 +0000 | [diff] [blame] | 280 | // TODO(mflodman): Base the start bitrate on a current bandwidth estimate, if |
| 281 | // the call has already started. |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 282 | VideoSendStream* send_stream = new VideoSendStream( |
| 283 | num_cpu_cores_, module_process_thread_.get(), call_stats_.get(), |
| 284 | congestion_controller_.get(), config, encoder_config, |
| 285 | suspended_video_send_ssrcs_); |
pbos@webrtc.org | 1819fd7 | 2013-06-10 13:48:26 +0000 | [diff] [blame] | 286 | |
mflodman | 717432f | 2015-10-26 16:34:46 +0100 | [diff] [blame] | 287 | if (!network_enabled_) |
| 288 | send_stream->SignalNetworkState(kNetworkDown); |
| 289 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 290 | WriteLockScoped write_lock(*send_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 291 | for (uint32_t ssrc : config.rtp.ssrcs) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 292 | RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end()); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 293 | video_send_ssrcs_[ssrc] = send_stream; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 294 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 295 | video_send_streams_.insert(send_stream); |
| 296 | |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 297 | if (event_log_) |
| 298 | event_log_->LogVideoSendStreamConfig(config); |
| 299 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 300 | return send_stream; |
| 301 | } |
| 302 | |
pbos@webrtc.org | 2c46f8d | 2013-11-21 13:49:43 +0000 | [diff] [blame] | 303 | void Call::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 +0000 | [diff] [blame] | 304 | TRACE_EVENT0("webrtc", "Call::DestroyVideoSendStream"); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 305 | RTC_DCHECK(send_stream != nullptr); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 306 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 307 | |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 308 | send_stream->Stop(); |
| 309 | |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 310 | VideoSendStream* send_stream_impl = nullptr; |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 311 | { |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 312 | WriteLockScoped write_lock(*send_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 313 | auto it = video_send_ssrcs_.begin(); |
| 314 | while (it != video_send_ssrcs_.end()) { |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 315 | if (it->second == static_cast<VideoSendStream*>(send_stream)) { |
| 316 | send_stream_impl = it->second; |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 317 | video_send_ssrcs_.erase(it++); |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 318 | } else { |
| 319 | ++it; |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 320 | } |
| 321 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 322 | video_send_streams_.erase(send_stream_impl); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 323 | } |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 324 | RTC_CHECK(send_stream_impl != nullptr); |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 325 | |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 326 | VideoSendStream::RtpStateMap rtp_state = send_stream_impl->GetRtpStates(); |
| 327 | |
| 328 | for (VideoSendStream::RtpStateMap::iterator it = rtp_state.begin(); |
| 329 | it != rtp_state.end(); |
| 330 | ++it) { |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 331 | suspended_video_send_ssrcs_[it->first] = it->second; |
pbos@webrtc.org | 2bb1bda | 2014-07-07 13:06:48 +0000 | [diff] [blame] | 332 | } |
| 333 | |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 334 | delete send_stream_impl; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 335 | } |
| 336 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 337 | webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( |
| 338 | const webrtc::VideoReceiveStream::Config& config) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 +0000 | [diff] [blame] | 339 | TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 340 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
Peter Boström | c4188fd | 2015-04-24 15:16:03 +0200 | [diff] [blame] | 341 | VideoReceiveStream* receive_stream = new VideoReceiveStream( |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 342 | num_cpu_cores_, congestion_controller_.get(), config, |
| 343 | config_.voice_engine, module_process_thread_.get(), call_stats_.get()); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 344 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 345 | WriteLockScoped write_lock(*receive_crit_); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 346 | RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == |
| 347 | video_receive_ssrcs_.end()); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 348 | video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 349 | // TODO(pbos): Configure different RTX payloads per receive payload. |
| 350 | VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it = |
| 351 | config.rtp.rtx.begin(); |
| 352 | if (it != config.rtp.rtx.end()) |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 353 | video_receive_ssrcs_[it->second.ssrc] = receive_stream; |
| 354 | video_receive_streams_.insert(receive_stream); |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 355 | |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 356 | ConfigureSync(config.sync_group); |
| 357 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 358 | if (!network_enabled_) |
| 359 | receive_stream->SignalNetworkState(kNetworkDown); |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 360 | |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 361 | if (event_log_) |
| 362 | event_log_->LogVideoReceiveStreamConfig(config); |
| 363 | |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 364 | return receive_stream; |
| 365 | } |
| 366 | |
pbos@webrtc.org | 2c46f8d | 2013-11-21 13:49:43 +0000 | [diff] [blame] | 367 | void Call::DestroyVideoReceiveStream( |
| 368 | webrtc::VideoReceiveStream* receive_stream) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 +0000 | [diff] [blame] | 369 | TRACE_EVENT0("webrtc", "Call::DestroyVideoReceiveStream"); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 370 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 371 | RTC_DCHECK(receive_stream != nullptr); |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 372 | VideoReceiveStream* receive_stream_impl = nullptr; |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 373 | { |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 374 | WriteLockScoped write_lock(*receive_crit_); |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 375 | // Remove all ssrcs pointing to a receive stream. As RTX retransmits on a |
| 376 | // separate SSRC there can be either one or two. |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 377 | auto it = video_receive_ssrcs_.begin(); |
| 378 | while (it != video_receive_ssrcs_.end()) { |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 379 | if (it->second == static_cast<VideoReceiveStream*>(receive_stream)) { |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 380 | if (receive_stream_impl != nullptr) |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 381 | RTC_DCHECK(receive_stream_impl == it->second); |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 382 | receive_stream_impl = it->second; |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 383 | video_receive_ssrcs_.erase(it++); |
pbos@webrtc.org | c279a5d | 2014-01-24 09:30:53 +0000 | [diff] [blame] | 384 | } else { |
| 385 | ++it; |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 386 | } |
| 387 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 388 | video_receive_streams_.erase(receive_stream_impl); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 389 | RTC_CHECK(receive_stream_impl != nullptr); |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 390 | ConfigureSync(receive_stream_impl->config().sync_group); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 391 | } |
pbos@webrtc.org | 95e51f5 | 2013-09-05 12:38:54 +0000 | [diff] [blame] | 392 | delete receive_stream_impl; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 393 | } |
| 394 | |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 395 | Call::Stats Call::GetStats() const { |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 396 | // TODO(solenberg): Some test cases in EndToEndTest use this from a different |
| 397 | // thread. Re-enable once that is fixed. |
| 398 | // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 399 | Stats stats; |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 400 | // Fetch available send/receive bitrates. |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 401 | uint32_t send_bandwidth = 0; |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 402 | congestion_controller_->GetBitrateController()->AvailableBandwidth( |
| 403 | &send_bandwidth); |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 404 | std::vector<unsigned int> ssrcs; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 405 | uint32_t recv_bandwidth = 0; |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 406 | congestion_controller_->GetRemoteBitrateEstimator(false)->LatestEstimate( |
mflodman | a20de20 | 2015-10-18 22:08:19 -0700 | [diff] [blame] | 407 | &ssrcs, &recv_bandwidth); |
Peter Boström | 45553ae | 2015-05-08 13:54:38 +0200 | [diff] [blame] | 408 | stats.send_bandwidth_bps = send_bandwidth; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 409 | stats.recv_bandwidth_bps = recv_bandwidth; |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 410 | stats.pacer_delay_ms = congestion_controller_->GetPacerQueuingDelayMs(); |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 411 | { |
| 412 | ReadLockScoped read_lock(*send_crit_); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 413 | // TODO(solenberg): Add audio send streams. |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 414 | for (const auto& kv : video_send_ssrcs_) { |
| 415 | int rtt_ms = kv.second->GetRtt(); |
pbos@webrtc.org | 2b19f06 | 2014-12-11 13:26:09 +0000 | [diff] [blame] | 416 | if (rtt_ms > 0) |
| 417 | stats.rtt_ms = rtt_ms; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | return stats; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 421 | } |
| 422 | |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 423 | void Call::SetBitrateConfig( |
| 424 | const webrtc::Call::Config::BitrateConfig& bitrate_config) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 +0000 | [diff] [blame] | 425 | TRACE_EVENT0("webrtc", "Call::SetBitrateConfig"); |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 426 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 427 | RTC_DCHECK_GE(bitrate_config.min_bitrate_bps, 0); |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 428 | if (bitrate_config.max_bitrate_bps != -1) |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 429 | RTC_DCHECK_GT(bitrate_config.max_bitrate_bps, 0); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 430 | if (config_.bitrate_config.min_bitrate_bps == |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 431 | bitrate_config.min_bitrate_bps && |
| 432 | (bitrate_config.start_bitrate_bps <= 0 || |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 433 | config_.bitrate_config.start_bitrate_bps == |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 434 | bitrate_config.start_bitrate_bps) && |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 435 | config_.bitrate_config.max_bitrate_bps == |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 436 | bitrate_config.max_bitrate_bps) { |
| 437 | // Nothing new to set, early abort to avoid encoder reconfigurations. |
| 438 | return; |
| 439 | } |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 440 | config_.bitrate_config = bitrate_config; |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 441 | congestion_controller_->SetBweBitrates(bitrate_config.min_bitrate_bps, |
| 442 | bitrate_config.start_bitrate_bps, |
| 443 | bitrate_config.max_bitrate_bps); |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 444 | } |
| 445 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 446 | void Call::SignalNetworkState(NetworkState state) { |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 447 | RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 448 | network_enabled_ = state == kNetworkUp; |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 449 | congestion_controller_->SignalNetworkState(state); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 450 | { |
| 451 | ReadLockScoped write_lock(*send_crit_); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 452 | for (auto& kv : audio_send_ssrcs_) { |
| 453 | kv.second->SignalNetworkState(state); |
| 454 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 455 | for (auto& kv : video_send_ssrcs_) { |
| 456 | kv.second->SignalNetworkState(state); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | { |
| 460 | ReadLockScoped write_lock(*receive_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 461 | for (auto& kv : video_receive_ssrcs_) { |
| 462 | kv.second->SignalNetworkState(state); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | } |
| 466 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 467 | void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { |
mflodman | 0c478b3 | 2015-10-21 15:52:16 +0200 | [diff] [blame] | 468 | congestion_controller_->OnSentPacket(sent_packet); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 469 | } |
| 470 | |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 471 | void Call::ConfigureSync(const std::string& sync_group) { |
| 472 | // Set sync only if there was no previous one. |
| 473 | if (config_.voice_engine == nullptr || sync_group.empty()) |
| 474 | return; |
| 475 | |
| 476 | AudioReceiveStream* sync_audio_stream = nullptr; |
| 477 | // Find existing audio stream. |
| 478 | const auto it = sync_stream_mapping_.find(sync_group); |
| 479 | if (it != sync_stream_mapping_.end()) { |
| 480 | sync_audio_stream = it->second; |
| 481 | } else { |
| 482 | // No configured audio stream, see if we can find one. |
| 483 | for (const auto& kv : audio_receive_ssrcs_) { |
| 484 | if (kv.second->config().sync_group == sync_group) { |
| 485 | if (sync_audio_stream != nullptr) { |
| 486 | LOG(LS_WARNING) << "Attempting to sync more than one audio stream " |
| 487 | "within the same sync group. This is not " |
| 488 | "supported in the current implementation."; |
| 489 | break; |
| 490 | } |
| 491 | sync_audio_stream = kv.second; |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | if (sync_audio_stream) |
| 496 | sync_stream_mapping_[sync_group] = sync_audio_stream; |
| 497 | size_t num_synced_streams = 0; |
| 498 | for (VideoReceiveStream* video_stream : video_receive_streams_) { |
| 499 | if (video_stream->config().sync_group != sync_group) |
| 500 | continue; |
| 501 | ++num_synced_streams; |
| 502 | if (num_synced_streams > 1) { |
| 503 | // TODO(pbos): Support synchronizing more than one A/V pair. |
| 504 | // https://code.google.com/p/webrtc/issues/detail?id=4762 |
| 505 | LOG(LS_WARNING) << "Attempting to sync more than one audio/video pair " |
| 506 | "within the same sync group. This is not supported in " |
| 507 | "the current implementation."; |
| 508 | } |
| 509 | // Only sync the first A/V pair within this sync group. |
| 510 | if (sync_audio_stream != nullptr && num_synced_streams == 1) { |
| 511 | video_stream->SetSyncChannel(config_.voice_engine, |
| 512 | sync_audio_stream->config().voe_channel_id); |
| 513 | } else { |
| 514 | video_stream->SetSyncChannel(config_.voice_engine, -1); |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 519 | PacketReceiver::DeliveryStatus Call::DeliverRtcp(MediaType media_type, |
| 520 | const uint8_t* packet, |
| 521 | size_t length) { |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 522 | // TODO(pbos): Figure out what channel needs it actually. |
| 523 | // Do NOT broadcast! Also make sure it's a valid packet. |
pbos@webrtc.org | caba2d2 | 2014-05-14 13:57:12 +0000 | [diff] [blame] | 524 | // Return DELIVERY_UNKNOWN_SSRC if it can be determined that |
| 525 | // there's no receiver of the packet. |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 526 | bool rtcp_delivered = false; |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 527 | if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 528 | ReadLockScoped read_lock(*receive_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 529 | for (VideoReceiveStream* stream : video_receive_streams_) { |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 530 | if (stream->DeliverRtcp(packet, length)) { |
pbos@webrtc.org | 4052370 | 2013-08-05 12:49:22 +0000 | [diff] [blame] | 531 | rtcp_delivered = true; |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 532 | if (event_log_) |
| 533 | event_log_->LogRtcpPacket(true, media_type, packet, length); |
| 534 | } |
pbos@webrtc.org | bbb07e6 | 2013-08-05 12:01:36 +0000 | [diff] [blame] | 535 | } |
| 536 | } |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 537 | if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 538 | ReadLockScoped read_lock(*send_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 539 | for (VideoSendStream* stream : video_send_streams_) { |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 540 | if (stream->DeliverRtcp(packet, length)) { |
pbos@webrtc.org | 4052370 | 2013-08-05 12:49:22 +0000 | [diff] [blame] | 541 | rtcp_delivered = true; |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 542 | if (event_log_) |
| 543 | event_log_->LogRtcpPacket(false, media_type, packet, length); |
| 544 | } |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 545 | } |
| 546 | } |
pbos@webrtc.org | caba2d2 | 2014-05-14 13:57:12 +0000 | [diff] [blame] | 547 | return rtcp_delivered ? DELIVERY_OK : DELIVERY_PACKET_ERROR; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 548 | } |
| 549 | |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 550 | PacketReceiver::DeliveryStatus Call::DeliverRtp(MediaType media_type, |
| 551 | const uint8_t* packet, |
stefan | 68786d2 | 2015-09-08 05:36:15 -0700 | [diff] [blame] | 552 | size_t length, |
| 553 | const PacketTime& packet_time) { |
pbos@webrtc.org | af38f4e | 2014-07-08 07:38:12 +0000 | [diff] [blame] | 554 | // Minimum RTP header size. |
| 555 | if (length < 12) |
| 556 | return DELIVERY_PACKET_ERROR; |
| 557 | |
sprang@webrtc.org | 2a6558c | 2015-01-28 12:37:36 +0000 | [diff] [blame] | 558 | uint32_t ssrc = ByteReader<uint32_t>::ReadBigEndian(&packet[8]); |
pbos@webrtc.org | af38f4e | 2014-07-08 07:38:12 +0000 | [diff] [blame] | 559 | |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 560 | ReadLockScoped read_lock(*receive_crit_); |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 561 | if (media_type == MediaType::ANY || media_type == MediaType::AUDIO) { |
| 562 | auto it = audio_receive_ssrcs_.find(ssrc); |
| 563 | if (it != audio_receive_ssrcs_.end()) { |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 564 | auto status = it->second->DeliverRtp(packet, length, packet_time) |
| 565 | ? DELIVERY_OK |
| 566 | : DELIVERY_PACKET_ERROR; |
| 567 | if (status == DELIVERY_OK && event_log_) |
| 568 | event_log_->LogRtpHeader(true, media_type, packet, length); |
| 569 | return status; |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 570 | } |
| 571 | } |
| 572 | if (media_type == MediaType::ANY || media_type == MediaType::VIDEO) { |
| 573 | auto it = video_receive_ssrcs_.find(ssrc); |
| 574 | if (it != video_receive_ssrcs_.end()) { |
ivoc | b04965c | 2015-09-09 00:09:43 -0700 | [diff] [blame] | 575 | auto status = it->second->DeliverRtp(packet, length, packet_time) |
| 576 | ? DELIVERY_OK |
| 577 | : DELIVERY_PACKET_ERROR; |
| 578 | if (status == DELIVERY_OK && event_log_) |
| 579 | event_log_->LogRtpHeader(true, media_type, packet, length); |
| 580 | return status; |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 581 | } |
| 582 | } |
| 583 | return DELIVERY_UNKNOWN_SSRC; |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 584 | } |
| 585 | |
stefan | 68786d2 | 2015-09-08 05:36:15 -0700 | [diff] [blame] | 586 | PacketReceiver::DeliveryStatus Call::DeliverPacket( |
| 587 | MediaType media_type, |
| 588 | const uint8_t* packet, |
| 589 | size_t length, |
| 590 | const PacketTime& packet_time) { |
solenberg | 5a28939 | 2015-10-19 03:39:20 -0700 | [diff] [blame] | 591 | // TODO(solenberg): Tests call this function on a network thread, libjingle |
| 592 | // calls on the worker thread. We should move towards always using a network |
| 593 | // thread. Then this check can be enabled. |
| 594 | // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); |
pbos@webrtc.org | 62bafae | 2014-07-08 12:10:51 +0000 | [diff] [blame] | 595 | if (RtpHeaderParser::IsRtcp(packet, length)) |
Fredrik Solenberg | 23fba1f | 2015-04-29 15:24:01 +0200 | [diff] [blame] | 596 | return DeliverRtcp(media_type, packet, length); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 597 | |
stefan | 68786d2 | 2015-09-08 05:36:15 -0700 | [diff] [blame] | 598 | return DeliverRtp(media_type, packet, length, packet_time); |
pbos@webrtc.org | 29d5839 | 2013-05-16 12:08:03 +0000 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | } // namespace internal |
| 602 | } // namespace webrtc |