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