OLD | NEW |
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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // Configure bandwidth estimation. | 131 // Configure bandwidth estimation. |
132 channel_proxy_->RegisterReceiverCongestionControlObjects( | 132 channel_proxy_->RegisterReceiverCongestionControlObjects( |
133 congestion_controller->packet_router()); | 133 congestion_controller->packet_router()); |
134 if (UseSendSideBwe(config)) { | 134 if (UseSendSideBwe(config)) { |
135 remote_bitrate_estimator_ = | 135 remote_bitrate_estimator_ = |
136 congestion_controller->GetRemoteBitrateEstimator(true); | 136 congestion_controller->GetRemoteBitrateEstimator(true); |
137 } | 137 } |
138 } | 138 } |
139 | 139 |
140 AudioReceiveStream::~AudioReceiveStream() { | 140 AudioReceiveStream::~AudioReceiveStream() { |
141 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 141 RTC_DCHECK_RUN_ON(&thread_checker_); |
142 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); | 142 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); |
143 Stop(); | 143 if (playing_) { |
| 144 Stop(); |
| 145 } |
144 channel_proxy_->DisassociateSendChannel(); | 146 channel_proxy_->DisassociateSendChannel(); |
145 channel_proxy_->DeRegisterExternalTransport(); | 147 channel_proxy_->DeRegisterExternalTransport(); |
146 channel_proxy_->ResetCongestionControlObjects(); | 148 channel_proxy_->ResetCongestionControlObjects(); |
147 channel_proxy_->SetRtcEventLog(nullptr); | 149 channel_proxy_->SetRtcEventLog(nullptr); |
148 if (remote_bitrate_estimator_) { | 150 if (remote_bitrate_estimator_) { |
149 remote_bitrate_estimator_->RemoveStream(config_.rtp.remote_ssrc); | 151 remote_bitrate_estimator_->RemoveStream(config_.rtp.remote_ssrc); |
150 } | 152 } |
151 } | 153 } |
152 | 154 |
153 void AudioReceiveStream::Start() { | 155 void AudioReceiveStream::Start() { |
154 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 156 RTC_DCHECK_RUN_ON(&thread_checker_); |
155 ScopedVoEInterface<VoEBase> base(voice_engine()); | 157 if (playing_) { |
156 int error = base->StartPlayout(config_.voe_channel_id); | 158 return; |
| 159 } |
| 160 |
| 161 int error = SetVoiceEnginePlayout(true); |
157 if (error != 0) { | 162 if (error != 0) { |
158 LOG(LS_ERROR) << "AudioReceiveStream::Start failed with error: " << error; | 163 LOG(LS_ERROR) << "AudioReceiveStream::Start failed with error: " << error; |
| 164 return; |
159 } | 165 } |
| 166 |
| 167 if (!audio_state()->mixer()->AddSource(this)) { |
| 168 LOG(LS_ERROR) << "Failed to add source to mixer."; |
| 169 SetVoiceEnginePlayout(false); |
| 170 return; |
| 171 } |
| 172 |
| 173 playing_ = true; |
160 } | 174 } |
161 | 175 |
162 void AudioReceiveStream::Stop() { | 176 void AudioReceiveStream::Stop() { |
163 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 177 RTC_DCHECK_RUN_ON(&thread_checker_); |
164 ScopedVoEInterface<VoEBase> base(voice_engine()); | 178 if (!playing_) { |
165 base->StopPlayout(config_.voe_channel_id); | 179 return; |
| 180 } |
| 181 playing_ = false; |
| 182 |
| 183 audio_state()->mixer()->RemoveSource(this); |
| 184 SetVoiceEnginePlayout(false); |
166 } | 185 } |
167 | 186 |
168 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { | 187 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { |
169 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 188 RTC_DCHECK_RUN_ON(&thread_checker_); |
170 webrtc::AudioReceiveStream::Stats stats; | 189 webrtc::AudioReceiveStream::Stats stats; |
171 stats.remote_ssrc = config_.rtp.remote_ssrc; | 190 stats.remote_ssrc = config_.rtp.remote_ssrc; |
172 ScopedVoEInterface<VoECodec> codec(voice_engine()); | 191 ScopedVoEInterface<VoECodec> codec(voice_engine()); |
173 | 192 |
174 webrtc::CallStatistics call_stats = channel_proxy_->GetRTCPStatistics(); | 193 webrtc::CallStatistics call_stats = channel_proxy_->GetRTCPStatistics(); |
175 webrtc::CodecInst codec_inst = {0}; | 194 webrtc::CodecInst codec_inst = {0}; |
176 if (codec->GetRecCodec(config_.voe_channel_id, codec_inst) == -1) { | 195 if (codec->GetRecCodec(config_.voe_channel_id, codec_inst) == -1) { |
177 return stats; | 196 return stats; |
178 } | 197 } |
179 | 198 |
(...skipping 29 matching lines...) Expand all Loading... |
209 stats.decoding_normal = ds.decoded_normal; | 228 stats.decoding_normal = ds.decoded_normal; |
210 stats.decoding_plc = ds.decoded_plc; | 229 stats.decoding_plc = ds.decoded_plc; |
211 stats.decoding_cng = ds.decoded_cng; | 230 stats.decoding_cng = ds.decoded_cng; |
212 stats.decoding_plc_cng = ds.decoded_plc_cng; | 231 stats.decoding_plc_cng = ds.decoded_plc_cng; |
213 stats.decoding_muted_output = ds.decoded_muted_output; | 232 stats.decoding_muted_output = ds.decoded_muted_output; |
214 | 233 |
215 return stats; | 234 return stats; |
216 } | 235 } |
217 | 236 |
218 void AudioReceiveStream::SetSink(std::unique_ptr<AudioSinkInterface> sink) { | 237 void AudioReceiveStream::SetSink(std::unique_ptr<AudioSinkInterface> sink) { |
219 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 238 RTC_DCHECK_RUN_ON(&thread_checker_); |
220 channel_proxy_->SetSink(std::move(sink)); | 239 channel_proxy_->SetSink(std::move(sink)); |
221 } | 240 } |
222 | 241 |
223 void AudioReceiveStream::SetGain(float gain) { | 242 void AudioReceiveStream::SetGain(float gain) { |
224 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 243 RTC_DCHECK_RUN_ON(&thread_checker_); |
225 channel_proxy_->SetChannelOutputVolumeScaling(gain); | 244 channel_proxy_->SetChannelOutputVolumeScaling(gain); |
226 } | 245 } |
227 | 246 |
228 const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const { | 247 const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const { |
229 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 248 RTC_DCHECK_RUN_ON(&thread_checker_); |
230 return config_; | 249 return config_; |
231 } | 250 } |
232 | 251 |
233 void AudioReceiveStream::AssociateSendStream(AudioSendStream* send_stream) { | 252 void AudioReceiveStream::AssociateSendStream(AudioSendStream* send_stream) { |
234 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 253 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
235 if (send_stream) { | 254 if (send_stream) { |
236 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); | 255 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); |
237 std::unique_ptr<voe::ChannelProxy> send_channel_proxy = | 256 std::unique_ptr<voe::ChannelProxy> send_channel_proxy = |
238 voe_impl->GetChannelProxy(send_stream->config().voe_channel_id); | 257 voe_impl->GetChannelProxy(send_stream->config().voe_channel_id); |
239 channel_proxy_->AssociateSendChannel(*send_channel_proxy.get()); | 258 channel_proxy_->AssociateSendChannel(*send_channel_proxy.get()); |
240 } else { | 259 } else { |
241 channel_proxy_->DisassociateSendChannel(); | 260 channel_proxy_->DisassociateSendChannel(); |
242 } | 261 } |
243 } | 262 } |
244 | 263 |
245 void AudioReceiveStream::SignalNetworkState(NetworkState state) { | 264 void AudioReceiveStream::SignalNetworkState(NetworkState state) { |
246 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 265 RTC_DCHECK_RUN_ON(&thread_checker_); |
247 } | 266 } |
248 | 267 |
249 bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 268 bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
250 // TODO(solenberg): Tests call this function on a network thread, libjingle | 269 // TODO(solenberg): Tests call this function on a network thread, libjingle |
251 // calls on the worker thread. We should move towards always using a network | 270 // calls on the worker thread. We should move towards always using a network |
252 // thread. Then this check can be enabled. | 271 // thread. Then this check can be enabled. |
253 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); | 272 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); |
254 return channel_proxy_->ReceivedRTCPPacket(packet, length); | 273 return channel_proxy_->ReceivedRTCPPacket(packet, length); |
255 } | 274 } |
256 | 275 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 } | 308 } |
290 | 309 |
291 int AudioReceiveStream::PreferredSampleRate() const { | 310 int AudioReceiveStream::PreferredSampleRate() const { |
292 return channel_proxy_->NeededFrequency(); | 311 return channel_proxy_->NeededFrequency(); |
293 } | 312 } |
294 | 313 |
295 int AudioReceiveStream::Ssrc() const { | 314 int AudioReceiveStream::Ssrc() const { |
296 return config_.rtp.local_ssrc; | 315 return config_.rtp.local_ssrc; |
297 } | 316 } |
298 | 317 |
| 318 internal::AudioState* AudioReceiveStream::audio_state() const { |
| 319 auto* audio_state = static_cast<internal::AudioState*>(audio_state_.get()); |
| 320 RTC_DCHECK(audio_state); |
| 321 return audio_state; |
| 322 } |
| 323 |
299 VoiceEngine* AudioReceiveStream::voice_engine() const { | 324 VoiceEngine* AudioReceiveStream::voice_engine() const { |
300 internal::AudioState* audio_state = | 325 auto* voice_engine = audio_state()->voice_engine(); |
301 static_cast<internal::AudioState*>(audio_state_.get()); | |
302 VoiceEngine* voice_engine = audio_state->voice_engine(); | |
303 RTC_DCHECK(voice_engine); | 326 RTC_DCHECK(voice_engine); |
304 return voice_engine; | 327 return voice_engine; |
305 } | 328 } |
| 329 |
| 330 int AudioReceiveStream::SetVoiceEnginePlayout(bool playout) { |
| 331 ScopedVoEInterface<VoEBase> base(voice_engine()); |
| 332 if (playout) { |
| 333 return base->StartPlayout(config_.voe_channel_id); |
| 334 } else { |
| 335 return base->StopPlayout(config_.voe_channel_id); |
| 336 } |
| 337 } |
| 338 |
306 } // namespace internal | 339 } // namespace internal |
307 } // namespace webrtc | 340 } // namespace webrtc |
OLD | NEW |