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 |
11 #include "webrtc/audio/audio_receive_stream.h" | 11 #include "webrtc/audio/audio_receive_stream.h" |
12 | 12 |
13 #include <string> | 13 #include <string> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "webrtc/api/call/audio_sink.h" | 16 #include "webrtc/api/call/audio_sink.h" |
17 #include "webrtc/audio/audio_state.h" | |
18 #include "webrtc/audio/conversion.h" | 17 #include "webrtc/audio/conversion.h" |
19 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
20 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
21 #include "webrtc/base/timeutils.h" | 20 #include "webrtc/base/timeutils.h" |
22 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" | 21 #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
23 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat or.h" | 22 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat or.h" |
24 #include "webrtc/voice_engine/channel_proxy.h" | 23 #include "webrtc/voice_engine/channel_proxy.h" |
25 #include "webrtc/voice_engine/include/voe_base.h" | 24 #include "webrtc/voice_engine/include/voe_base.h" |
26 #include "webrtc/voice_engine/include/voe_codec.h" | 25 #include "webrtc/voice_engine/include/voe_codec.h" |
27 #include "webrtc/voice_engine/include/voe_neteq_stats.h" | 26 #include "webrtc/voice_engine/include/voe_neteq_stats.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 congestion_controller->packet_router()); | 134 congestion_controller->packet_router()); |
136 if (UseSendSideBwe(config)) { | 135 if (UseSendSideBwe(config)) { |
137 remote_bitrate_estimator_ = | 136 remote_bitrate_estimator_ = |
138 congestion_controller->GetRemoteBitrateEstimator(true); | 137 congestion_controller->GetRemoteBitrateEstimator(true); |
139 } | 138 } |
140 } | 139 } |
141 | 140 |
142 AudioReceiveStream::~AudioReceiveStream() { | 141 AudioReceiveStream::~AudioReceiveStream() { |
143 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 142 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
144 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); | 143 LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); |
145 Stop(); | 144 if (playing_) { |
145 Stop(); | |
146 } | |
146 channel_proxy_->DeRegisterExternalTransport(); | 147 channel_proxy_->DeRegisterExternalTransport(); |
147 channel_proxy_->ResetCongestionControlObjects(); | 148 channel_proxy_->ResetCongestionControlObjects(); |
148 channel_proxy_->SetRtcEventLog(nullptr); | 149 channel_proxy_->SetRtcEventLog(nullptr); |
149 if (remote_bitrate_estimator_) { | 150 if (remote_bitrate_estimator_) { |
150 remote_bitrate_estimator_->RemoveStream(config_.rtp.remote_ssrc); | 151 remote_bitrate_estimator_->RemoveStream(config_.rtp.remote_ssrc); |
151 } | 152 } |
152 } | 153 } |
153 | 154 |
154 void AudioReceiveStream::Start() { | 155 void AudioReceiveStream::Start() { |
155 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 156 RTC_DCHECK_RUN_ON(&thread_checker_); |
the sun
2016/11/14 20:03:46
I don't like that some methods in this class use
R
aleloi
2016/11/15 16:56:54
Done.
| |
157 if (playing_) { | |
158 return; | |
159 } | |
160 | |
156 ScopedVoEInterface<VoEBase> base(voice_engine()); | 161 ScopedVoEInterface<VoEBase> base(voice_engine()); |
157 int error = base->StartPlayout(config_.voe_channel_id); | 162 int error = base->StartPlayout(config_.voe_channel_id); |
158 if (error != 0) { | 163 if (error != 0) { |
159 LOG(LS_ERROR) << "AudioReceiveStream::Start failed with error: " << error; | 164 RTC_NOTREACHED() << "AudioReceiveStream::Start failed with error: " |
the sun
2016/11/14 20:03:46
Why did you change this? We can conceivably end up
aleloi
2016/11/15 16:56:54
Point, that was wrong.
| |
165 << error; | |
166 return; | |
167 } | |
168 | |
169 playing_ = true; | |
the sun
2016/11/14 20:03:46
Note that you're violating the AudioMixer promises
aleloi
2016/11/15 16:56:54
Acknowledged.
| |
170 | |
171 auto* const the_audio_state = audio_state(); | |
172 | |
173 if (!the_audio_state->mixer()->AddSource(this)) { | |
174 LOG(LS_ERROR) << "Failed to add source to mixer."; | |
160 } | 175 } |
161 } | 176 } |
162 | 177 |
163 void AudioReceiveStream::Stop() { | 178 void AudioReceiveStream::Stop() { |
164 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 179 RTC_DCHECK_RUN_ON(&thread_checker_); |
180 | |
181 if (!playing_) { | |
182 return; | |
183 } | |
184 playing_ = false; | |
185 | |
186 auto* const the_audio_state = audio_state(); | |
187 if (!the_audio_state->mixer()->RemoveSource(this)) { | |
188 RTC_NOTREACHED() << "Failed to remove stream from mixer."; | |
the sun
2016/11/14 20:03:46
If the return code is *supposed* to always be true
aleloi
2016/11/15 16:56:54
For AudioMixerImpl it's supposed to always be true
| |
189 } | |
190 | |
165 ScopedVoEInterface<VoEBase> base(voice_engine()); | 191 ScopedVoEInterface<VoEBase> base(voice_engine()); |
166 base->StopPlayout(config_.voe_channel_id); | 192 base->StopPlayout(config_.voe_channel_id); |
167 } | 193 } |
168 | 194 |
169 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { | 195 webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { |
170 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 196 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
171 webrtc::AudioReceiveStream::Stats stats; | 197 webrtc::AudioReceiveStream::Stats stats; |
172 stats.remote_ssrc = config_.rtp.remote_ssrc; | 198 stats.remote_ssrc = config_.rtp.remote_ssrc; |
173 ScopedVoEInterface<VoECodec> codec(voice_engine()); | 199 ScopedVoEInterface<VoECodec> codec(voice_engine()); |
174 | 200 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 } | 303 } |
278 | 304 |
279 int AudioReceiveStream::PreferredSampleRate() const { | 305 int AudioReceiveStream::PreferredSampleRate() const { |
280 return channel_proxy_->NeededFrequency(); | 306 return channel_proxy_->NeededFrequency(); |
281 } | 307 } |
282 | 308 |
283 int AudioReceiveStream::Ssrc() const { | 309 int AudioReceiveStream::Ssrc() const { |
284 return config_.rtp.local_ssrc; | 310 return config_.rtp.local_ssrc; |
285 } | 311 } |
286 | 312 |
313 internal::AudioState* AudioReceiveStream::audio_state() const { | |
314 return static_cast<internal::AudioState*>(audio_state_.get()); | |
the sun
2016/11/14 20:03:46
Pull into a local variable and DCHECK it's not nul
aleloi
2016/11/15 16:56:54
Done.
| |
315 } | |
316 | |
287 VoiceEngine* AudioReceiveStream::voice_engine() const { | 317 VoiceEngine* AudioReceiveStream::voice_engine() const { |
288 internal::AudioState* audio_state = | 318 internal::AudioState* the_audio_state = audio_state(); |
the sun
2016/11/14 20:03:46
Make that a one-liner instead
aleloi
2016/11/15 16:56:54
Done.
| |
289 static_cast<internal::AudioState*>(audio_state_.get()); | 319 VoiceEngine* voice_engine = the_audio_state->voice_engine(); |
290 VoiceEngine* voice_engine = audio_state->voice_engine(); | |
291 RTC_DCHECK(voice_engine); | 320 RTC_DCHECK(voice_engine); |
292 return voice_engine; | 321 return voice_engine; |
293 } | 322 } |
294 } // namespace internal | 323 } // namespace internal |
295 } // namespace webrtc | 324 } // namespace webrtc |
OLD | NEW |