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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Stop(); |
| 148 } |
147 channel_proxy_->DisassociateSendChannel(); | 149 channel_proxy_->DisassociateSendChannel(); |
148 channel_proxy_->DeRegisterExternalTransport(); | 150 channel_proxy_->DeRegisterExternalTransport(); |
149 channel_proxy_->ResetCongestionControlObjects(); | 151 channel_proxy_->ResetCongestionControlObjects(); |
150 channel_proxy_->SetRtcEventLog(nullptr); | 152 channel_proxy_->SetRtcEventLog(nullptr); |
151 if (remote_bitrate_estimator_) { | 153 if (remote_bitrate_estimator_) { |
152 remote_bitrate_estimator_->RemoveStream(config_.rtp.remote_ssrc); | 154 remote_bitrate_estimator_->RemoveStream(config_.rtp.remote_ssrc); |
153 } | 155 } |
154 } | 156 } |
155 | 157 |
| 158 int AudioReceiveStream::SetVoiceEnginePlayout(bool playout) { |
| 159 ScopedVoEInterface<VoEBase> base(voice_engine()); |
| 160 if (playout) { |
| 161 return base->StartPlayout(config_.voe_channel_id); |
| 162 } else { |
| 163 return base->StopPlayout(config_.voe_channel_id); |
| 164 } |
| 165 } |
| 166 |
156 void AudioReceiveStream::Start() { | 167 void AudioReceiveStream::Start() { |
157 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 168 RTC_DCHECK_RUN_ON(&thread_checker_); |
158 ScopedVoEInterface<VoEBase> base(voice_engine()); | 169 if (playing_) { |
159 int error = base->StartPlayout(config_.voe_channel_id); | 170 return; |
| 171 } |
| 172 |
| 173 int error = SetVoiceEnginePlayout(true); |
160 if (error != 0) { | 174 if (error != 0) { |
161 LOG(LS_ERROR) << "AudioReceiveStream::Start failed with error: " << error; | 175 LOG(LS_ERROR) << "AudioReceiveStream::Start failed with error: " << error; |
| 176 return; |
162 } | 177 } |
| 178 |
| 179 auto* const the_audio_state = audio_state(); |
| 180 |
| 181 // TODO(aleloi): rethink handling of error flags and the |
| 182 // AudioMixer::AddSource()/::RemoveSource() interface. |
| 183 if (!the_audio_state->mixer()->AddSource(this)) { |
| 184 LOG(LS_ERROR) << "Failed to add source to mixer."; |
| 185 SetVoiceEnginePlayout(false); |
| 186 return; |
| 187 } |
| 188 |
| 189 playing_ = true; |
163 } | 190 } |
164 | 191 |
165 void AudioReceiveStream::Stop() { | 192 void AudioReceiveStream::Stop() { |
166 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 193 RTC_DCHECK_RUN_ON(&thread_checker_); |
167 ScopedVoEInterface<VoEBase> base(voice_engine()); | 194 |
168 base->StopPlayout(config_.voe_channel_id); | 195 if (!playing_) { |
| 196 return; |
| 197 } |
| 198 playing_ = false; |
| 199 |
| 200 if (!audio_state()->mixer()->RemoveSource(this)) { |
| 201 LOG(LS_ERROR) << "Failed to remove stream from mixer."; |
| 202 } |
| 203 |
| 204 SetVoiceEnginePlayout(false); |
169 } | 205 } |
170 | 206 |
171 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { | 207 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { |
172 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 208 RTC_DCHECK_RUN_ON(&thread_checker_); |
173 webrtc::AudioReceiveStream::Stats stats; | 209 webrtc::AudioReceiveStream::Stats stats; |
174 stats.remote_ssrc = config_.rtp.remote_ssrc; | 210 stats.remote_ssrc = config_.rtp.remote_ssrc; |
175 ScopedVoEInterface<VoECodec> codec(voice_engine()); | 211 ScopedVoEInterface<VoECodec> codec(voice_engine()); |
176 | 212 |
177 webrtc::CallStatistics call_stats = channel_proxy_->GetRTCPStatistics(); | 213 webrtc::CallStatistics call_stats = channel_proxy_->GetRTCPStatistics(); |
178 webrtc::CodecInst codec_inst = {0}; | 214 webrtc::CodecInst codec_inst = {0}; |
179 if (codec->GetRecCodec(config_.voe_channel_id, codec_inst) == -1) { | 215 if (codec->GetRecCodec(config_.voe_channel_id, codec_inst) == -1) { |
180 return stats; | 216 return stats; |
181 } | 217 } |
182 | 218 |
(...skipping 28 matching lines...) Expand all Loading... |
211 stats.decoding_normal = ds.decoded_normal; | 247 stats.decoding_normal = ds.decoded_normal; |
212 stats.decoding_plc = ds.decoded_plc; | 248 stats.decoding_plc = ds.decoded_plc; |
213 stats.decoding_cng = ds.decoded_cng; | 249 stats.decoding_cng = ds.decoded_cng; |
214 stats.decoding_plc_cng = ds.decoded_plc_cng; | 250 stats.decoding_plc_cng = ds.decoded_plc_cng; |
215 stats.decoding_muted_output = ds.decoded_muted_output; | 251 stats.decoding_muted_output = ds.decoded_muted_output; |
216 | 252 |
217 return stats; | 253 return stats; |
218 } | 254 } |
219 | 255 |
220 void AudioReceiveStream::SetSink(std::unique_ptr<AudioSinkInterface> sink) { | 256 void AudioReceiveStream::SetSink(std::unique_ptr<AudioSinkInterface> sink) { |
221 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 257 RTC_DCHECK_RUN_ON(&thread_checker_); |
222 channel_proxy_->SetSink(std::move(sink)); | 258 channel_proxy_->SetSink(std::move(sink)); |
223 } | 259 } |
224 | 260 |
225 void AudioReceiveStream::SetGain(float gain) { | 261 void AudioReceiveStream::SetGain(float gain) { |
226 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 262 RTC_DCHECK_RUN_ON(&thread_checker_); |
227 channel_proxy_->SetChannelOutputVolumeScaling(gain); | 263 channel_proxy_->SetChannelOutputVolumeScaling(gain); |
228 } | 264 } |
229 | 265 |
230 const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const { | 266 const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const { |
231 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 267 RTC_DCHECK_RUN_ON(&thread_checker_); |
232 return config_; | 268 return config_; |
233 } | 269 } |
234 | 270 |
235 void AudioReceiveStream::AssociateSendStream(AudioSendStream* send_stream) { | 271 void AudioReceiveStream::AssociateSendStream(AudioSendStream* send_stream) { |
236 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 272 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
237 if (send_stream) { | 273 if (send_stream) { |
238 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); | 274 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine()); |
239 std::unique_ptr<voe::ChannelProxy> send_channel_proxy = | 275 std::unique_ptr<voe::ChannelProxy> send_channel_proxy = |
240 voe_impl->GetChannelProxy(send_stream->config().voe_channel_id); | 276 voe_impl->GetChannelProxy(send_stream->config().voe_channel_id); |
241 channel_proxy_->AssociateSendChannel(*send_channel_proxy.get()); | 277 channel_proxy_->AssociateSendChannel(*send_channel_proxy.get()); |
242 } else { | 278 } else { |
243 channel_proxy_->DisassociateSendChannel(); | 279 channel_proxy_->DisassociateSendChannel(); |
244 } | 280 } |
245 } | 281 } |
246 | 282 |
247 void AudioReceiveStream::SignalNetworkState(NetworkState state) { | 283 void AudioReceiveStream::SignalNetworkState(NetworkState state) { |
248 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 284 RTC_DCHECK_RUN_ON(&thread_checker_); |
249 } | 285 } |
250 | 286 |
251 bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 287 bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
252 // TODO(solenberg): Tests call this function on a network thread, libjingle | 288 // 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 | 289 // calls on the worker thread. We should move towards always using a network |
254 // thread. Then this check can be enabled. | 290 // thread. Then this check can be enabled. |
255 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); | 291 // RTC_DCHECK(!thread_checker_.CalledOnValidThread()); |
256 return channel_proxy_->ReceivedRTCPPacket(packet, length); | 292 return channel_proxy_->ReceivedRTCPPacket(packet, length); |
257 } | 293 } |
258 | 294 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 } | 327 } |
292 | 328 |
293 int AudioReceiveStream::PreferredSampleRate() const { | 329 int AudioReceiveStream::PreferredSampleRate() const { |
294 return channel_proxy_->NeededFrequency(); | 330 return channel_proxy_->NeededFrequency(); |
295 } | 331 } |
296 | 332 |
297 int AudioReceiveStream::Ssrc() const { | 333 int AudioReceiveStream::Ssrc() const { |
298 return config_.rtp.local_ssrc; | 334 return config_.rtp.local_ssrc; |
299 } | 335 } |
300 | 336 |
| 337 internal::AudioState* AudioReceiveStream::audio_state() const { |
| 338 auto* audio_state = static_cast<internal::AudioState*>(audio_state_.get()); |
| 339 RTC_DCHECK(audio_state); |
| 340 return audio_state; |
| 341 } |
| 342 |
301 VoiceEngine* AudioReceiveStream::voice_engine() const { | 343 VoiceEngine* AudioReceiveStream::voice_engine() const { |
302 internal::AudioState* audio_state = | 344 auto* voice_engine = audio_state()->voice_engine(); |
303 static_cast<internal::AudioState*>(audio_state_.get()); | |
304 VoiceEngine* voice_engine = audio_state->voice_engine(); | |
305 RTC_DCHECK(voice_engine); | 345 RTC_DCHECK(voice_engine); |
306 return voice_engine; | 346 return voice_engine; |
307 } | 347 } |
308 } // namespace internal | 348 } // namespace internal |
309 } // namespace webrtc | 349 } // namespace webrtc |
OLD | NEW |