Index: webrtc/audio/audio_receive_stream.cc |
diff --git a/webrtc/audio/audio_receive_stream.cc b/webrtc/audio/audio_receive_stream.cc |
index e2f8f148365dc466d994f7870d747a39c9e56ef8..0fcf039c6b35d32313b8b73971e8496069133068 100644 |
--- a/webrtc/audio/audio_receive_stream.cc |
+++ b/webrtc/audio/audio_receive_stream.cc |
@@ -141,10 +141,11 @@ AudioReceiveStream::AudioReceiveStream( |
} |
AudioReceiveStream::~AudioReceiveStream() { |
- RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
+ RTC_DCHECK_RUN_ON(&thread_checker_); |
LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString(); |
- Stop(); |
- channel_proxy_->DisassociateSendChannel(); |
the sun
2016/11/16 20:22:57
Bad merge
aleloi
2016/11/17 18:12:26
Good spot! Thanks!
|
+ if (playing_) { |
+ Stop(); |
+ } |
channel_proxy_->DeRegisterExternalTransport(); |
channel_proxy_->ResetCongestionControlObjects(); |
channel_proxy_->SetRtcEventLog(nullptr); |
@@ -154,22 +155,49 @@ AudioReceiveStream::~AudioReceiveStream() { |
} |
void AudioReceiveStream::Start() { |
- RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
+ RTC_DCHECK_RUN_ON(&thread_checker_); |
+ if (playing_) { |
+ return; |
+ } |
+ |
ScopedVoEInterface<VoEBase> base(voice_engine()); |
int error = base->StartPlayout(config_.voe_channel_id); |
if (error != 0) { |
LOG(LS_ERROR) << "AudioReceiveStream::Start failed with error: " << error; |
+ return; |
} |
+ |
+ auto* const the_audio_state = audio_state(); |
+ |
+ // TODO(aleloi): rethink handling of error flags and the |
+ // AudioMixer::AddSource()/::RemoveSource() interface. |
+ if (!the_audio_state->mixer()->AddSource(this)) { |
+ LOG(LS_ERROR) << "Failed to add source to mixer."; |
+ return; |
+ } |
+ |
+ playing_ = true; |
} |
void AudioReceiveStream::Stop() { |
- RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
+ RTC_DCHECK_RUN_ON(&thread_checker_); |
+ |
the sun
2016/11/16 20:22:57
dd
|
+ if (!playing_) { |
+ return; |
+ } |
+ playing_ = false; |
+ |
+ 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.
|
+ if (!the_audio_state->mixer()->RemoveSource(this)) { |
+ LOG(LS_ERROR) << "Failed to remove stream from mixer."; |
+ } |
+ |
ScopedVoEInterface<VoEBase> base(voice_engine()); |
base->StopPlayout(config_.voe_channel_id); |
} |
webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { |
- RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
+ RTC_DCHECK_RUN_ON(&thread_checker_); |
webrtc::AudioReceiveStream::Stats stats; |
stats.remote_ssrc = config_.rtp.remote_ssrc; |
ScopedVoEInterface<VoECodec> codec(voice_engine()); |
@@ -218,17 +246,17 @@ webrtc::AudioReceiveStream::Stats AudioReceiveStream::GetStats() const { |
} |
void AudioReceiveStream::SetSink(std::unique_ptr<AudioSinkInterface> sink) { |
- RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
+ RTC_DCHECK_RUN_ON(&thread_checker_); |
channel_proxy_->SetSink(std::move(sink)); |
} |
void AudioReceiveStream::SetGain(float gain) { |
- RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
+ RTC_DCHECK_RUN_ON(&thread_checker_); |
channel_proxy_->SetChannelOutputVolumeScaling(gain); |
} |
const webrtc::AudioReceiveStream::Config& AudioReceiveStream::config() const { |
- RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
+ RTC_DCHECK_RUN_ON(&thread_checker_); |
return config_; |
} |
@@ -245,7 +273,7 @@ void AudioReceiveStream::AssociateSendStream(AudioSendStream* send_stream) { |
} |
void AudioReceiveStream::SignalNetworkState(NetworkState state) { |
- RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
+ RTC_DCHECK_RUN_ON(&thread_checker_); |
} |
bool AudioReceiveStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
@@ -298,10 +326,14 @@ int AudioReceiveStream::Ssrc() const { |
return config_.rtp.local_ssrc; |
} |
+internal::AudioState* AudioReceiveStream::audio_state() const { |
+ auto* audio_state = static_cast<internal::AudioState*>(audio_state_.get()); |
+ RTC_DCHECK(audio_state); |
+ return audio_state; |
+} |
+ |
VoiceEngine* AudioReceiveStream::voice_engine() const { |
- internal::AudioState* audio_state = |
- static_cast<internal::AudioState*>(audio_state_.get()); |
- VoiceEngine* voice_engine = audio_state->voice_engine(); |
+ auto* voice_engine = audio_state()->voice_engine(); |
the sun
2016/11/16 20:22:57
Yes, nicer! :)
|
RTC_DCHECK(voice_engine); |
return voice_engine; |
} |