From eefbc3bbd7a6962265b028cf259b5028944561d1 Mon Sep 17 00:00:00 2001 From: torbjorng Date: Thu, 8 Oct 2015 13:10:36 -0700 Subject: [PATCH] Revert of Remove AudioTrackRenderer (patchset #3 id:40001 of https://codereview.webrtc.org/1399553003/ ) Reason for revert: Breaks Chrome since its build files were not updated prior to file removal. Original issue's description: > - Remove AudioTrackRenderer. > - Remove AddChannel/RemoveChannel from AudioRenderer interface. > > BUG=webrtc:4690 > > Committed: https://crrev.com/1c0bb386b67835feb5934f503dddfe0912bce3ac > Cr-Commit-Position: refs/heads/master@{#10226} TBR=tommi@webrtc.org,solenberg@webrtc.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=webrtc:4690 Review URL: https://codereview.webrtc.org/1393343003 Cr-Commit-Position: refs/heads/master@{#10228} --- talk/app/webrtc/audiotrackrenderer.cc | 49 +++++++++++++++++++ talk/app/webrtc/audiotrackrenderer.h | 59 +++++++++++++++++++++++ talk/app/webrtc/webrtcsession_unittest.cc | 16 +++++- talk/libjingle.gyp | 2 + talk/media/base/audiorenderer.h | 14 ++++++ talk/media/base/fakemediaengine.h | 4 ++ talk/media/webrtc/webrtcvoiceengine.cc | 14 ++++-- 7 files changed, 153 insertions(+), 5 deletions(-) create mode 100644 talk/app/webrtc/audiotrackrenderer.cc create mode 100644 talk/app/webrtc/audiotrackrenderer.h diff --git a/talk/app/webrtc/audiotrackrenderer.cc b/talk/app/webrtc/audiotrackrenderer.cc new file mode 100644 index 0000000000..264a3cb734 --- /dev/null +++ b/talk/app/webrtc/audiotrackrenderer.cc @@ -0,0 +1,49 @@ +/* + * libjingle + * Copyright 2013 Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "talk/app/webrtc/audiotrackrenderer.h" +#include "webrtc/base/common.h" + +namespace webrtc { + +AudioTrackRenderer::AudioTrackRenderer() : channel_id_(-1) { +} + +AudioTrackRenderer::~AudioTrackRenderer() { +} + +void AudioTrackRenderer::AddChannel(int channel_id) { + ASSERT(channel_id_ == -1 || channel_id_ == channel_id); + channel_id_ = channel_id; +} + +void AudioTrackRenderer::RemoveChannel(int channel_id) { + ASSERT(channel_id_ == -1 || channel_id_ == channel_id); + channel_id_ = -1; +} + +} // namespace webrtc diff --git a/talk/app/webrtc/audiotrackrenderer.h b/talk/app/webrtc/audiotrackrenderer.h new file mode 100644 index 0000000000..e22805fe19 --- /dev/null +++ b/talk/app/webrtc/audiotrackrenderer.h @@ -0,0 +1,59 @@ +/* + * libjingle + * Copyright 2013 Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef TALK_APP_WEBRTC_AUDIOTRACKRENDERER_H_ +#define TALK_APP_WEBRTC_AUDIOTRACKRENDERER_H_ + +#include "talk/media/base/audiorenderer.h" +#include "webrtc/base/thread.h" + +namespace webrtc { + +// Class used for AudioTrack to get the ID of WebRtc voice channel that +// the AudioTrack is connecting to. +// Each AudioTrack owns a AudioTrackRenderer instance. +// AddChannel() will be called when an AudioTrack is added to a MediaStream. +// RemoveChannel will be called when the AudioTrack or WebRtc VoE channel is +// going away. +// This implementation only supports one channel, and it is only used by +// Chrome for remote audio tracks." +class AudioTrackRenderer : public cricket::AudioRenderer { + public: + AudioTrackRenderer(); + ~AudioTrackRenderer(); + + // Implements cricket::AudioRenderer. + void AddChannel(int channel_id) override; + void RemoveChannel(int channel_id) override; + + private: + int channel_id_; +}; + +} // namespace webrtc + +#endif // TALK_APP_WEBRTC_AUDIOTRACKRENDERER_H_ diff --git a/talk/app/webrtc/webrtcsession_unittest.cc b/talk/app/webrtc/webrtcsession_unittest.cc index ff41383c32..2853ca43a7 100644 --- a/talk/app/webrtc/webrtcsession_unittest.cc +++ b/talk/app/webrtc/webrtcsession_unittest.cc @@ -330,16 +330,26 @@ class WebRtcSessionCreateSDPObserverForTest class FakeAudioRenderer : public cricket::AudioRenderer { public: - FakeAudioRenderer() : sink_(NULL) {} + FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {} virtual ~FakeAudioRenderer() { if (sink_) sink_->OnClose(); } + void AddChannel(int channel_id) override { + ASSERT(channel_id_ == -1); + channel_id_ = channel_id; + } + void RemoveChannel(int channel_id) override { + ASSERT(channel_id == channel_id_); + channel_id_ = -1; + } void SetSink(Sink* sink) override { sink_ = sink; } + int channel_id() const { return channel_id_; } cricket::AudioRenderer::Sink* sink() const { return sink_; } private: + int channel_id_; cricket::AudioRenderer::Sink* sink_; }; @@ -3107,10 +3117,12 @@ TEST_F(WebRtcSessionTest, SetAudioPlayout) { EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol)); EXPECT_EQ(0, left_vol); EXPECT_EQ(0, right_vol); + EXPECT_EQ(0, renderer->channel_id()); session_->SetAudioPlayout(receive_ssrc, true, NULL); EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol)); EXPECT_EQ(1, left_vol); EXPECT_EQ(1, right_vol); + EXPECT_EQ(-1, renderer->channel_id()); } TEST_F(WebRtcSessionTest, SetAudioSend) { @@ -3130,6 +3142,7 @@ TEST_F(WebRtcSessionTest, SetAudioSend) { session_->SetAudioSend(send_ssrc, false, options, renderer.get()); EXPECT_TRUE(channel->IsStreamMuted(send_ssrc)); EXPECT_FALSE(channel->options().echo_cancellation.IsSet()); + EXPECT_EQ(0, renderer->channel_id()); EXPECT_TRUE(renderer->sink() != NULL); // This will trigger SetSink(NULL) to the |renderer|. @@ -3138,6 +3151,7 @@ TEST_F(WebRtcSessionTest, SetAudioSend) { bool value; EXPECT_TRUE(channel->options().echo_cancellation.Get(&value)); EXPECT_TRUE(value); + EXPECT_EQ(-1, renderer->channel_id()); EXPECT_TRUE(renderer->sink() == NULL); } diff --git a/talk/libjingle.gyp b/talk/libjingle.gyp index 3268d01493..fd2d969d5d 100755 --- a/talk/libjingle.gyp +++ b/talk/libjingle.gyp @@ -712,6 +712,8 @@ 'sources': [ 'app/webrtc/audiotrack.cc', 'app/webrtc/audiotrack.h', + 'app/webrtc/audiotrackrenderer.cc', + 'app/webrtc/audiotrackrenderer.h', 'app/webrtc/datachannel.cc', 'app/webrtc/datachannel.h', 'app/webrtc/datachannelinterface.h', diff --git a/talk/media/base/audiorenderer.h b/talk/media/base/audiorenderer.h index 229c36e8b1..5c03576fa7 100644 --- a/talk/media/base/audiorenderer.h +++ b/talk/media/base/audiorenderer.h @@ -55,6 +55,20 @@ class AudioRenderer { // to the renderer at a time. virtual void SetSink(Sink* sink) {} + // Add the WebRtc VoE channel to the renderer. + // For local stream, multiple WebRtc VoE channels can be connected to the + // renderer. While for remote stream, only one WebRtc VoE channel can be + // connected to the renderer. + // TODO(xians): Remove this interface after Chrome switches to the + // AudioRenderer::Sink interface. + virtual void AddChannel(int channel_id) {} + + // Remove the WebRtc VoE channel from the renderer. + // This method is called when the VoE channel is going away. + // TODO(xians): Remove this interface after Chrome switches to the + // AudioRenderer::Sink interface. + virtual void RemoveChannel(int channel_id) {} + protected: virtual ~AudioRenderer() {} }; diff --git a/talk/media/base/fakemediaengine.h b/talk/media/base/fakemediaengine.h index e5c4c53241..7325667aa5 100644 --- a/talk/media/base/fakemediaengine.h +++ b/talk/media/base/fakemediaengine.h @@ -308,9 +308,11 @@ class FakeVoiceMediaChannel : public RtpHelper { ASSERT(it->second == renderer); } else { remote_renderers_.insert(std::make_pair(ssrc, renderer)); + renderer->AddChannel(0); } } else { if (it != remote_renderers_.end()) { + it->second->RemoveChannel(0); remote_renderers_.erase(it); } else { return false; @@ -380,10 +382,12 @@ class FakeVoiceMediaChannel : public RtpHelper { public: explicit VoiceChannelAudioSink(AudioRenderer* renderer) : renderer_(renderer) { + renderer_->AddChannel(0); renderer_->SetSink(this); } virtual ~VoiceChannelAudioSink() { if (renderer_) { + renderer_->RemoveChannel(0); renderer_->SetSink(NULL); } } diff --git a/talk/media/webrtc/webrtcvoiceengine.cc b/talk/media/webrtc/webrtcvoiceengine.cc index db22b41fc0..54fac221d8 100644 --- a/talk/media/webrtc/webrtcvoiceengine.cc +++ b/talk/media/webrtc/webrtcvoiceengine.cc @@ -1305,6 +1305,10 @@ class WebRtcVoiceMediaChannel::WebRtcVoiceChannelRenderer RTC_DCHECK(renderer_ == renderer); return; } + + // TODO(xians): Remove AddChannel() call after Chrome turns on APM + // in getUserMedia by default. + renderer->AddChannel(channel_); renderer->SetSink(this); renderer_ = renderer; } @@ -1314,10 +1318,12 @@ class WebRtcVoiceMediaChannel::WebRtcVoiceChannelRenderer // This method is called on the libjingle worker thread. void Stop() { rtc::CritScope lock(&lock_); - if (renderer_ != NULL) { - renderer_->SetSink(NULL); - renderer_ = NULL; - } + if (renderer_ == NULL) + return; + + renderer_->RemoveChannel(channel_); + renderer_->SetSink(NULL); + renderer_ = NULL; } // AudioRenderer::Sink implementation.