| 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..a363baa1c380be116c520b86af5049082a23a63b 100644
|
| --- a/webrtc/audio/audio_receive_stream.cc
|
| +++ b/webrtc/audio/audio_receive_stream.cc
|
| @@ -141,9 +141,11 @@ AudioReceiveStream::AudioReceiveStream(
|
| }
|
|
|
| AudioReceiveStream::~AudioReceiveStream() {
|
| - RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
| + RTC_DCHECK_RUN_ON(&thread_checker_);
|
| LOG(LS_INFO) << "~AudioReceiveStream: " << config_.ToString();
|
| - Stop();
|
| + if (playing_) {
|
| + Stop();
|
| + }
|
| channel_proxy_->DisassociateSendChannel();
|
| channel_proxy_->DeRegisterExternalTransport();
|
| channel_proxy_->ResetCongestionControlObjects();
|
| @@ -153,23 +155,57 @@ AudioReceiveStream::~AudioReceiveStream() {
|
| }
|
| }
|
|
|
| -void AudioReceiveStream::Start() {
|
| - RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
| +int AudioReceiveStream::SetVoiceEnginePlayout(bool playout) {
|
| ScopedVoEInterface<VoEBase> base(voice_engine());
|
| - int error = base->StartPlayout(config_.voe_channel_id);
|
| + if (playout) {
|
| + return base->StartPlayout(config_.voe_channel_id);
|
| + } else {
|
| + return base->StopPlayout(config_.voe_channel_id);
|
| + }
|
| +}
|
| +
|
| +void AudioReceiveStream::Start() {
|
| + RTC_DCHECK_RUN_ON(&thread_checker_);
|
| + if (playing_) {
|
| + return;
|
| + }
|
| +
|
| + int error = SetVoiceEnginePlayout(true);
|
| 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.";
|
| + SetVoiceEnginePlayout(false);
|
| + return;
|
| + }
|
| +
|
| + playing_ = true;
|
| }
|
|
|
| void AudioReceiveStream::Stop() {
|
| - RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
| - ScopedVoEInterface<VoEBase> base(voice_engine());
|
| - base->StopPlayout(config_.voe_channel_id);
|
| + RTC_DCHECK_RUN_ON(&thread_checker_);
|
| +
|
| + if (!playing_) {
|
| + return;
|
| + }
|
| + playing_ = false;
|
| +
|
| + if (!audio_state()->mixer()->RemoveSource(this)) {
|
| + LOG(LS_ERROR) << "Failed to remove stream from mixer.";
|
| + }
|
| +
|
| + SetVoiceEnginePlayout(false);
|
| }
|
|
|
| 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 +254,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 +281,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 +334,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();
|
| RTC_DCHECK(voice_engine);
|
| return voice_engine;
|
| }
|
|
|