Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(333)

Side by Side Diff: webrtc/call/call.cc

Issue 1403363003: Move VoiceEngineObserver into AudioSendStream so that we detect typing noises and return properly i… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: that's all folks! (incl rebase), or is it? Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/call/bitrate_estimator_tests.cc ('k') | webrtc/call/call_perf_tests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <string.h> 11 #include <string.h>
12 12
13 #include <map> 13 #include <map>
14 #include <vector> 14 #include <vector>
15 15
16 #include "webrtc/audio/audio_receive_stream.h" 16 #include "webrtc/audio/audio_receive_stream.h"
17 #include "webrtc/audio/audio_send_stream.h" 17 #include "webrtc/audio/audio_send_stream.h"
18 #include "webrtc/audio/audio_state.h"
19 #include "webrtc/audio/scoped_voe_interface.h"
18 #include "webrtc/base/checks.h" 20 #include "webrtc/base/checks.h"
19 #include "webrtc/base/scoped_ptr.h" 21 #include "webrtc/base/scoped_ptr.h"
20 #include "webrtc/base/thread_annotations.h" 22 #include "webrtc/base/thread_annotations.h"
21 #include "webrtc/base/thread_checker.h" 23 #include "webrtc/base/thread_checker.h"
22 #include "webrtc/base/trace_event.h" 24 #include "webrtc/base/trace_event.h"
23 #include "webrtc/call.h" 25 #include "webrtc/call.h"
24 #include "webrtc/call/congestion_controller.h" 26 #include "webrtc/call/congestion_controller.h"
25 #include "webrtc/call/rtc_event_log.h" 27 #include "webrtc/call/rtc_event_log.h"
26 #include "webrtc/common.h" 28 #include "webrtc/common.h"
27 #include "webrtc/config.h" 29 #include "webrtc/config.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 DeliveryStatus DeliverRtcp(MediaType media_type, const uint8_t* packet, 89 DeliveryStatus DeliverRtcp(MediaType media_type, const uint8_t* packet,
88 size_t length); 90 size_t length);
89 DeliveryStatus DeliverRtp(MediaType media_type, 91 DeliveryStatus DeliverRtp(MediaType media_type,
90 const uint8_t* packet, 92 const uint8_t* packet,
91 size_t length, 93 size_t length,
92 const PacketTime& packet_time); 94 const PacketTime& packet_time);
93 95
94 void ConfigureSync(const std::string& sync_group) 96 void ConfigureSync(const std::string& sync_group)
95 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_); 97 EXCLUSIVE_LOCKS_REQUIRED(receive_crit_);
96 98
99 VoiceEngine* voice_engine() {
100 internal::AudioState* audio_state =
101 static_cast<internal::AudioState*>(config_.audio_state.get());
102 if (audio_state)
103 return audio_state->voice_engine();
104 else
105 return nullptr;
106 }
107
97 const int num_cpu_cores_; 108 const int num_cpu_cores_;
98 const rtc::scoped_ptr<ProcessThread> module_process_thread_; 109 const rtc::scoped_ptr<ProcessThread> module_process_thread_;
99 const rtc::scoped_ptr<CallStats> call_stats_; 110 const rtc::scoped_ptr<CallStats> call_stats_;
100 const rtc::scoped_ptr<CongestionController> congestion_controller_; 111 const rtc::scoped_ptr<CongestionController> congestion_controller_;
101 Call::Config config_; 112 Call::Config config_;
102 rtc::ThreadChecker configuration_thread_checker_; 113 rtc::ThreadChecker configuration_thread_checker_;
103 114
104 bool network_enabled_; 115 bool network_enabled_;
105 116
106 rtc::scoped_ptr<RWLockWrapper> receive_crit_; 117 rtc::scoped_ptr<RWLockWrapper> receive_crit_;
107 // Audio and Video receive streams are owned by the client that creates them. 118 // Audio and Video receive streams are owned by the client that creates them.
108 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_ 119 std::map<uint32_t, AudioReceiveStream*> audio_receive_ssrcs_
109 GUARDED_BY(receive_crit_); 120 GUARDED_BY(receive_crit_);
110 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_ 121 std::map<uint32_t, VideoReceiveStream*> video_receive_ssrcs_
111 GUARDED_BY(receive_crit_); 122 GUARDED_BY(receive_crit_);
112 std::set<VideoReceiveStream*> video_receive_streams_ 123 std::set<VideoReceiveStream*> video_receive_streams_
113 GUARDED_BY(receive_crit_); 124 GUARDED_BY(receive_crit_);
114 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_ 125 std::map<std::string, AudioReceiveStream*> sync_stream_mapping_
115 GUARDED_BY(receive_crit_); 126 GUARDED_BY(receive_crit_);
116 127
117 rtc::scoped_ptr<RWLockWrapper> send_crit_; 128 rtc::scoped_ptr<RWLockWrapper> send_crit_;
118 // Audio and Video send streams are owned by the client that creates them. 129 // 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_); 130 std::map<uint32_t, AudioSendStream*> audio_send_ssrcs_ GUARDED_BY(send_crit_);
120 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_); 131 std::map<uint32_t, VideoSendStream*> video_send_ssrcs_ GUARDED_BY(send_crit_);
121 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_); 132 std::set<VideoSendStream*> video_send_streams_ GUARDED_BY(send_crit_);
122 133
123 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_; 134 VideoSendStream::RtpStateMap suspended_video_send_ssrcs_;
124 135
125 RtcEventLog* event_log_ = nullptr; 136 RtcEventLog* event_log_ = nullptr;
126 VoECodec* voe_codec_ = nullptr;
127 137
128 RTC_DISALLOW_COPY_AND_ASSIGN(Call); 138 RTC_DISALLOW_COPY_AND_ASSIGN(Call);
129 }; 139 };
130 } // namespace internal 140 } // namespace internal
131 141
132 Call* Call::Create(const Call::Config& config) { 142 Call* Call::Create(const Call::Config& config) {
133 return new internal::Call(config); 143 return new internal::Call(config);
134 } 144 }
135 145
136 namespace internal { 146 namespace internal {
137 147
138 Call::Call(const Call::Config& config) 148 Call::Call(const Call::Config& config)
139 : num_cpu_cores_(CpuInfo::DetectNumberOfCores()), 149 : num_cpu_cores_(CpuInfo::DetectNumberOfCores()),
140 module_process_thread_(ProcessThread::Create("ModuleProcessThread")), 150 module_process_thread_(ProcessThread::Create("ModuleProcessThread")),
141 call_stats_(new CallStats()), 151 call_stats_(new CallStats()),
142 congestion_controller_(new CongestionController( 152 congestion_controller_(new CongestionController(
143 module_process_thread_.get(), call_stats_.get())), 153 module_process_thread_.get(), call_stats_.get())),
144 config_(config), 154 config_(config),
145 network_enabled_(true), 155 network_enabled_(true),
146 receive_crit_(RWLockWrapper::CreateRWLock()), 156 receive_crit_(RWLockWrapper::CreateRWLock()),
147 send_crit_(RWLockWrapper::CreateRWLock()) { 157 send_crit_(RWLockWrapper::CreateRWLock()) {
148 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0); 158 RTC_DCHECK_GE(config.bitrate_config.min_bitrate_bps, 0);
149 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps, 159 RTC_DCHECK_GE(config.bitrate_config.start_bitrate_bps,
150 config.bitrate_config.min_bitrate_bps); 160 config.bitrate_config.min_bitrate_bps);
151 if (config.bitrate_config.max_bitrate_bps != -1) { 161 if (config.bitrate_config.max_bitrate_bps != -1) {
152 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps, 162 RTC_DCHECK_GE(config.bitrate_config.max_bitrate_bps,
153 config.bitrate_config.start_bitrate_bps); 163 config.bitrate_config.start_bitrate_bps);
154 } 164 }
155 if (config.voice_engine) { 165 if (config.audio_state.get()) {
156 // Keep a reference to VoECodec, so we're sure the VoiceEngine lives for the 166 ScopedVoEInterface<VoECodec> voe_codec(voice_engine());
157 // duration of the call. 167 event_log_ = voe_codec->GetEventLog();
158 voe_codec_ = VoECodec::GetInterface(config.voice_engine);
159 if (voe_codec_)
160 event_log_ = voe_codec_->GetEventLog();
161 } 168 }
162 169
163 Trace::CreateTrace(); 170 Trace::CreateTrace();
164 module_process_thread_->Start(); 171 module_process_thread_->Start();
165 module_process_thread_->RegisterModule(call_stats_.get()); 172 module_process_thread_->RegisterModule(call_stats_.get());
166 173
167 congestion_controller_->SetBweBitrates( 174 congestion_controller_->SetBweBitrates(
168 config_.bitrate_config.min_bitrate_bps, 175 config_.bitrate_config.min_bitrate_bps,
169 config_.bitrate_config.start_bitrate_bps, 176 config_.bitrate_config.start_bitrate_bps,
170 config_.bitrate_config.max_bitrate_bps); 177 config_.bitrate_config.max_bitrate_bps);
171 178
172 congestion_controller_->GetBitrateController()->SetEventLog(event_log_); 179 congestion_controller_->GetBitrateController()->SetEventLog(event_log_);
173 } 180 }
174 181
175 Call::~Call() { 182 Call::~Call() {
176 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 183 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
177 RTC_CHECK(audio_send_ssrcs_.empty()); 184 RTC_CHECK(audio_send_ssrcs_.empty());
178 RTC_CHECK(video_send_ssrcs_.empty()); 185 RTC_CHECK(video_send_ssrcs_.empty());
179 RTC_CHECK(video_send_streams_.empty()); 186 RTC_CHECK(video_send_streams_.empty());
180 RTC_CHECK(audio_receive_ssrcs_.empty()); 187 RTC_CHECK(audio_receive_ssrcs_.empty());
181 RTC_CHECK(video_receive_ssrcs_.empty()); 188 RTC_CHECK(video_receive_ssrcs_.empty());
182 RTC_CHECK(video_receive_streams_.empty()); 189 RTC_CHECK(video_receive_streams_.empty());
183 190
184 module_process_thread_->DeRegisterModule(call_stats_.get()); 191 module_process_thread_->DeRegisterModule(call_stats_.get());
185 module_process_thread_->Stop(); 192 module_process_thread_->Stop();
186 Trace::ReturnTrace(); 193 Trace::ReturnTrace();
187
188 if (voe_codec_)
189 voe_codec_->Release();
190 } 194 }
191 195
192 PacketReceiver* Call::Receiver() { 196 PacketReceiver* Call::Receiver() {
193 // TODO(solenberg): Some test cases in EndToEndTest use this from a different 197 // TODO(solenberg): Some test cases in EndToEndTest use this from a different
194 // thread. Re-enable once that is fixed. 198 // thread. Re-enable once that is fixed.
195 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 199 // RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
196 return this; 200 return this;
197 } 201 }
198 202
199 webrtc::AudioSendStream* Call::CreateAudioSendStream( 203 webrtc::AudioSendStream* Call::CreateAudioSendStream(
200 const webrtc::AudioSendStream::Config& config) { 204 const webrtc::AudioSendStream::Config& config) {
201 TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream"); 205 TRACE_EVENT0("webrtc", "Call::CreateAudioSendStream");
202 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 206 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
203 AudioSendStream* send_stream = 207 AudioSendStream* send_stream =
204 new AudioSendStream(config, config_.voice_engine); 208 new AudioSendStream(config, config_.audio_state);
205 if (!network_enabled_) 209 if (!network_enabled_)
206 send_stream->SignalNetworkState(kNetworkDown); 210 send_stream->SignalNetworkState(kNetworkDown);
207 { 211 {
208 WriteLockScoped write_lock(*send_crit_); 212 WriteLockScoped write_lock(*send_crit_);
209 RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) == 213 RTC_DCHECK(audio_send_ssrcs_.find(config.rtp.ssrc) ==
210 audio_send_ssrcs_.end()); 214 audio_send_ssrcs_.end());
211 audio_send_ssrcs_[config.rtp.ssrc] = send_stream; 215 audio_send_ssrcs_[config.rtp.ssrc] = send_stream;
212 } 216 }
213 return send_stream; 217 return send_stream;
214 } 218 }
(...skipping 15 matching lines...) Expand all
230 } 234 }
231 delete audio_send_stream; 235 delete audio_send_stream;
232 } 236 }
233 237
234 webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream( 238 webrtc::AudioReceiveStream* Call::CreateAudioReceiveStream(
235 const webrtc::AudioReceiveStream::Config& config) { 239 const webrtc::AudioReceiveStream::Config& config) {
236 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream"); 240 TRACE_EVENT0("webrtc", "Call::CreateAudioReceiveStream");
237 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 241 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
238 AudioReceiveStream* receive_stream = new AudioReceiveStream( 242 AudioReceiveStream* receive_stream = new AudioReceiveStream(
239 congestion_controller_->GetRemoteBitrateEstimator(false), config, 243 congestion_controller_->GetRemoteBitrateEstimator(false), config,
240 config_.voice_engine); 244 config_.audio_state);
241 { 245 {
242 WriteLockScoped write_lock(*receive_crit_); 246 WriteLockScoped write_lock(*receive_crit_);
243 RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) == 247 RTC_DCHECK(audio_receive_ssrcs_.find(config.rtp.remote_ssrc) ==
244 audio_receive_ssrcs_.end()); 248 audio_receive_ssrcs_.end());
245 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; 249 audio_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream;
246 ConfigureSync(config.sync_group); 250 ConfigureSync(config.sync_group);
247 } 251 }
248 return receive_stream; 252 return receive_stream;
249 } 253 }
250 254
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 337
334 delete send_stream_impl; 338 delete send_stream_impl;
335 } 339 }
336 340
337 webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream( 341 webrtc::VideoReceiveStream* Call::CreateVideoReceiveStream(
338 const webrtc::VideoReceiveStream::Config& config) { 342 const webrtc::VideoReceiveStream::Config& config) {
339 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream"); 343 TRACE_EVENT0("webrtc", "Call::CreateVideoReceiveStream");
340 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread()); 344 RTC_DCHECK(configuration_thread_checker_.CalledOnValidThread());
341 VideoReceiveStream* receive_stream = new VideoReceiveStream( 345 VideoReceiveStream* receive_stream = new VideoReceiveStream(
342 num_cpu_cores_, congestion_controller_.get(), config, 346 num_cpu_cores_, congestion_controller_.get(), config,
343 config_.voice_engine, module_process_thread_.get(), call_stats_.get()); 347 voice_engine(), module_process_thread_.get(), call_stats_.get());
344 348
345 WriteLockScoped write_lock(*receive_crit_); 349 WriteLockScoped write_lock(*receive_crit_);
346 RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) == 350 RTC_DCHECK(video_receive_ssrcs_.find(config.rtp.remote_ssrc) ==
347 video_receive_ssrcs_.end()); 351 video_receive_ssrcs_.end());
348 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream; 352 video_receive_ssrcs_[config.rtp.remote_ssrc] = receive_stream;
349 // TODO(pbos): Configure different RTX payloads per receive payload. 353 // TODO(pbos): Configure different RTX payloads per receive payload.
350 VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it = 354 VideoReceiveStream::Config::Rtp::RtxMap::const_iterator it =
351 config.rtp.rtx.begin(); 355 config.rtp.rtx.begin();
352 if (it != config.rtp.rtx.end()) 356 if (it != config.rtp.rtx.end())
353 video_receive_ssrcs_[it->second.ssrc] = receive_stream; 357 video_receive_ssrcs_[it->second.ssrc] = receive_stream;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 } 467 }
464 } 468 }
465 } 469 }
466 470
467 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) { 471 void Call::OnSentPacket(const rtc::SentPacket& sent_packet) {
468 congestion_controller_->OnSentPacket(sent_packet); 472 congestion_controller_->OnSentPacket(sent_packet);
469 } 473 }
470 474
471 void Call::ConfigureSync(const std::string& sync_group) { 475 void Call::ConfigureSync(const std::string& sync_group) {
472 // Set sync only if there was no previous one. 476 // Set sync only if there was no previous one.
473 if (config_.voice_engine == nullptr || sync_group.empty()) 477 if (voice_engine() == nullptr || sync_group.empty())
474 return; 478 return;
475 479
476 AudioReceiveStream* sync_audio_stream = nullptr; 480 AudioReceiveStream* sync_audio_stream = nullptr;
477 // Find existing audio stream. 481 // Find existing audio stream.
478 const auto it = sync_stream_mapping_.find(sync_group); 482 const auto it = sync_stream_mapping_.find(sync_group);
479 if (it != sync_stream_mapping_.end()) { 483 if (it != sync_stream_mapping_.end()) {
480 sync_audio_stream = it->second; 484 sync_audio_stream = it->second;
481 } else { 485 } else {
482 // No configured audio stream, see if we can find one. 486 // No configured audio stream, see if we can find one.
483 for (const auto& kv : audio_receive_ssrcs_) { 487 for (const auto& kv : audio_receive_ssrcs_) {
(...skipping 17 matching lines...) Expand all
501 ++num_synced_streams; 505 ++num_synced_streams;
502 if (num_synced_streams > 1) { 506 if (num_synced_streams > 1) {
503 // TODO(pbos): Support synchronizing more than one A/V pair. 507 // TODO(pbos): Support synchronizing more than one A/V pair.
504 // https://code.google.com/p/webrtc/issues/detail?id=4762 508 // https://code.google.com/p/webrtc/issues/detail?id=4762
505 LOG(LS_WARNING) << "Attempting to sync more than one audio/video pair " 509 LOG(LS_WARNING) << "Attempting to sync more than one audio/video pair "
506 "within the same sync group. This is not supported in " 510 "within the same sync group. This is not supported in "
507 "the current implementation."; 511 "the current implementation.";
508 } 512 }
509 // Only sync the first A/V pair within this sync group. 513 // Only sync the first A/V pair within this sync group.
510 if (sync_audio_stream != nullptr && num_synced_streams == 1) { 514 if (sync_audio_stream != nullptr && num_synced_streams == 1) {
511 video_stream->SetSyncChannel(config_.voice_engine, 515 video_stream->SetSyncChannel(voice_engine(),
512 sync_audio_stream->config().voe_channel_id); 516 sync_audio_stream->config().voe_channel_id);
513 } else { 517 } else {
514 video_stream->SetSyncChannel(config_.voice_engine, -1); 518 video_stream->SetSyncChannel(voice_engine(), -1);
515 } 519 }
516 } 520 }
517 } 521 }
518 522
519 PacketReceiver::DeliveryStatus Call::DeliverRtcp(MediaType media_type, 523 PacketReceiver::DeliveryStatus Call::DeliverRtcp(MediaType media_type,
520 const uint8_t* packet, 524 const uint8_t* packet,
521 size_t length) { 525 size_t length) {
522 // TODO(pbos): Figure out what channel needs it actually. 526 // TODO(pbos): Figure out what channel needs it actually.
523 // Do NOT broadcast! Also make sure it's a valid packet. 527 // Do NOT broadcast! Also make sure it's a valid packet.
524 // Return DELIVERY_UNKNOWN_SSRC if it can be determined that 528 // Return DELIVERY_UNKNOWN_SSRC if it can be determined that
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 // thread. Then this check can be enabled. 597 // thread. Then this check can be enabled.
594 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread()); 598 // RTC_DCHECK(!configuration_thread_checker_.CalledOnValidThread());
595 if (RtpHeaderParser::IsRtcp(packet, length)) 599 if (RtpHeaderParser::IsRtcp(packet, length))
596 return DeliverRtcp(media_type, packet, length); 600 return DeliverRtcp(media_type, packet, length);
597 601
598 return DeliverRtp(media_type, packet, length, packet_time); 602 return DeliverRtp(media_type, packet, length, packet_time);
599 } 603 }
600 604
601 } // namespace internal 605 } // namespace internal
602 } // namespace webrtc 606 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/call/bitrate_estimator_tests.cc ('k') | webrtc/call/call_perf_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698