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

Side by Side Diff: webrtc/audio/audio_receive_stream.cc

Issue 2436033002: Replace AudioConferenceMixer with AudioMixer. (Closed)
Patch Set: Consistent thread checker, errcode handling in RecStream. Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // Configure bandwidth estimation. 134 // Configure bandwidth estimation.
135 channel_proxy_->RegisterReceiverCongestionControlObjects( 135 channel_proxy_->RegisterReceiverCongestionControlObjects(
136 congestion_controller->packet_router()); 136 congestion_controller->packet_router());
137 if (UseSendSideBwe(config)) { 137 if (UseSendSideBwe(config)) {
138 remote_bitrate_estimator_ = 138 remote_bitrate_estimator_ =
139 congestion_controller->GetRemoteBitrateEstimator(true); 139 congestion_controller->GetRemoteBitrateEstimator(true);
140 } 140 }
141 } 141 }
142 142
143 AudioReceiveStream::~AudioReceiveStream() { 143 AudioReceiveStream::~AudioReceiveStream() {
144 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 144 RTC_DCHECK_RUN_ON(&thread_checker_);
145 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); 145 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString();
146 Stop(); 146 if (playing_) {
147 channel_proxy_->DisassociateSendChannel(); 147 Stop();
the sun 2016/11/16 20:22:57 Bad merge
aleloi 2016/11/17 18:12:26 Good spot! Thanks!
148 }
148 channel_proxy_->DeRegisterExternalTransport(); 149 channel_proxy_->DeRegisterExternalTransport();
149 channel_proxy_->ResetCongestionControlObjects(); 150 channel_proxy_->ResetCongestionControlObjects();
150 channel_proxy_->SetRtcEventLog(nullptr); 151 channel_proxy_->SetRtcEventLog(nullptr);
151 if (remote_bitrate_estimator_) { 152 if (remote_bitrate_estimator_) {
152 remote_bitrate_estimator_->RemoveStream(config_.rtp.remote_ssrc); 153 remote_bitrate_estimator_->RemoveStream(config_.rtp.remote_ssrc);
153 } 154 }
154 } 155 }
155 156
156 void AudioReceiveStream::Start() { 157 void AudioReceiveStream::Start() {
157 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 158 RTC_DCHECK_RUN_ON(&thread_checker_);
159 if (playing_) {
160 return;
161 }
162
158 ScopedVoEInterface<VoEBase> base(voice_engine()); 163 ScopedVoEInterface<VoEBase> base(voice_engine());
159 int error = base->StartPlayout(config_.voe_channel_id); 164 int error = base->StartPlayout(config_.voe_channel_id);
160 if (error != 0) { 165 if (error != 0) {
161 LOG(LS_ERROR) << "AudioReceiveStream::Start failed with error: " << error; 166 LOG(LS_ERROR) << "AudioReceiveStream::Start failed with error: " << error;
167 return;
162 } 168 }
169
170 auto* const the_audio_state = audio_state();
171
172 // TODO(aleloi): rethink handling of error flags and the
173 // AudioMixer::AddSource()/::RemoveSource() interface.
174 if (!the_audio_state->mixer()->AddSource(this)) {
175 LOG(LS_ERROR) << "Failed to add source to mixer.";
176 return;
177 }
178
179 playing_ = true;
163 } 180 }
164 181
165 void AudioReceiveStream::Stop() { 182 void AudioReceiveStream::Stop() {
166 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 183 RTC_DCHECK_RUN_ON(&thread_checker_);
184
the sun 2016/11/16 20:22:57 dd
185 if (!playing_) {
186 return;
187 }
188 playing_ = false;
189
190 auto* const the_audio_state = audio_state();
the sun 2016/11/16 20:22:57 Don't need this local
aleloi 2016/11/17 18:12:26 Acknowledged.
191 if (!the_audio_state->mixer()->RemoveSource(this)) {
192 LOG(LS_ERROR) << "Failed to remove stream from mixer.";
193 }
194
167 ScopedVoEInterface<VoEBase> base(voice_engine()); 195 ScopedVoEInterface<VoEBase> base(voice_engine());
168 base->StopPlayout(config_.voe_channel_id); 196 base->StopPlayout(config_.voe_channel_id);
169 } 197 }
170 198
171 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { 199 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const {
172 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 200 RTC_DCHECK_RUN_ON(&thread_checker_);
173 webrtc::AudioReceiveStream::Stats stats; 201 webrtc::AudioReceiveStream::Stats stats;
174 stats.remote_ssrc = config_.rtp.remote_ssrc; 202 stats.remote_ssrc = config_.rtp.remote_ssrc;
175 ScopedVoEInterface<VoECodec> codec(voice_engine()); 203 ScopedVoEInterface<VoECodec> codec(voice_engine());
176 204
177 webrtc::CallStatistics call_stats = channel_proxy_->GetRTCPStatistics(); 205 webrtc::CallStatistics call_stats = channel_proxy_->GetRTCPStatistics();
178 webrtc::CodecInst codec_inst = {0}; 206 webrtc::CodecInst codec_inst = {0};
179 if (codec->GetRecCodec(config_.voe_channel_id, codec_inst) == -1) { 207 if (codec->GetRecCodec(config_.voe_channel_id, codec_inst) == -1) {
180 return stats; 208 return stats;
181 } 209 }
182 210
(...skipping 28 matching lines...) Expand all
211 stats.decoding_normal = ds.decoded_normal; 239 stats.decoding_normal = ds.decoded_normal;
212 stats.decoding_plc = ds.decoded_plc; 240 stats.decoding_plc = ds.decoded_plc;
213 stats.decoding_cng = ds.decoded_cng; 241 stats.decoding_cng = ds.decoded_cng;
214 stats.decoding_plc_cng = ds.decoded_plc_cng; 242 stats.decoding_plc_cng = ds.decoded_plc_cng;
215 stats.decoding_muted_output = ds.decoded_muted_output; 243 stats.decoding_muted_output = ds.decoded_muted_output;
216 244
217 return stats; 245 return stats;
218 } 246 }
219 247
220 void AudioReceiveStream::SetSink(std::unique_ptr<AudioSinkInterface> sink) { 248 void AudioReceiveStream::SetSink(std::unique_ptr<AudioSinkInterface> sink) {
221 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 249 RTC_DCHECK_RUN_ON(&thread_checker_);
222 channel_proxy_->SetSink(std::move(sink)); 250 channel_proxy_->SetSink(std::move(sink));
223 } 251 }
224 252
225 void AudioReceiveStream::SetGain(float gain) { 253 void AudioReceiveStream::SetGain(float gain) {
226 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 254 RTC_DCHECK_RUN_ON(&thread_checker_);
227 channel_proxy_->SetChannelOutputVolumeScaling(gain); 255 channel_proxy_->SetChannelOutputVolumeScaling(gain);
228 } 256 }
229 257
230 const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const { 258 const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const {
231 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 259 RTC_DCHECK_RUN_ON(&thread_checker_);
232 return config_; 260 return config_;
233 } 261 }
234 262
235 void AudioReceiveStream::AssociateSendStream(AudioSendStream* send_stream) { 263 void AudioReceiveStream::AssociateSendStream(AudioSendStream* send_stream) {
236 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 264 RTC_DCHECK(thread_checker_.CalledOnValidThread());
237 if (send_stream) { 265 if (send_stream) {
238 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); 266 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine());
239 std::unique_ptr<voe::ChannelProxy> send_channel_proxy = 267 std::unique_ptr<voe::ChannelProxy> send_channel_proxy =
240 voe_impl->GetChannelProxy(send_stream->config().voe_channel_id); 268 voe_impl->GetChannelProxy(send_stream->config().voe_channel_id);
241 channel_proxy_->AssociateSendChannel(*send_channel_proxy.get()); 269 channel_proxy_->AssociateSendChannel(*send_channel_proxy.get());
242 } else { 270 } else {
243 channel_proxy_->DisassociateSendChannel(); 271 channel_proxy_->DisassociateSendChannel();
244 } 272 }
245 } 273 }
246 274
247 void AudioReceiveStream::SignalNetworkState(NetworkState state) { 275 void AudioReceiveStream::SignalNetworkState(NetworkState state) {
248 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 276 RTC_DCHECK_RUN_ON(&thread_checker_);
249 } 277 }
250 278
251 bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { 279 bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) {
252 // TODO(solenberg): Tests call this function on a network thread, libjingle 280 // TODO(solenberg): Tests call this function on a network thread, libjingle
253 // calls on the worker thread. We should move towards always using a network 281 // calls on the worker thread. We should move towards always using a network
254 // thread. Then this check can be enabled. 282 // thread. Then this check can be enabled.
255 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); 283 // RTC_DCHECK(!thread_checker_.CalledOnValidThread());
256 return channel_proxy_->ReceivedRTCPPacket(packet, length); 284 return channel_proxy_->ReceivedRTCPPacket(packet, length);
257 } 285 }
258 286
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 319 }
292 320
293 int AudioReceiveStream::PreferredSampleRate() const { 321 int AudioReceiveStream::PreferredSampleRate() const {
294 return channel_proxy_->NeededFrequency(); 322 return channel_proxy_->NeededFrequency();
295 } 323 }
296 324
297 int AudioReceiveStream::Ssrc() const { 325 int AudioReceiveStream::Ssrc() const {
298 return config_.rtp.local_ssrc; 326 return config_.rtp.local_ssrc;
299 } 327 }
300 328
329 internal::AudioState* AudioReceiveStream::audio_state() const {
330 auto* audio_state = static_cast<internal::AudioState*>(audio_state_.get());
331 RTC_DCHECK(audio_state);
332 return audio_state;
333 }
334
301 VoiceEngine* AudioReceiveStream::voice_engine() const { 335 VoiceEngine* AudioReceiveStream::voice_engine() const {
302 internal::AudioState* audio_state = 336 auto* voice_engine = audio_state()->voice_engine();
the sun 2016/11/16 20:22:57 Yes, nicer! :)
303 static_cast<internal::AudioState*>(audio_state_.get());
304 VoiceEngine* voice_engine = audio_state->voice_engine();
305 RTC_DCHECK(voice_engine); 337 RTC_DCHECK(voice_engine);
306 return voice_engine; 338 return voice_engine;
307 } 339 }
308 } // namespace internal 340 } // namespace internal
309 } // namespace webrtc 341 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698