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}
This commit is contained in:
torbjorng
2015-10-08 13:10:36 -07:00
committed by Commit bot
parent f0159a742f
commit eefbc3bbd7
7 changed files with 153 additions and 5 deletions

View File

@ -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

View File

@ -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_

View File

@ -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);
}

View File

@ -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',

View File

@ -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() {}
};

View File

@ -308,9 +308,11 @@ class FakeVoiceMediaChannel : public RtpHelper<VoiceMediaChannel> {
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<VoiceMediaChannel> {
public:
explicit VoiceChannelAudioSink(AudioRenderer* renderer)
: renderer_(renderer) {
renderer_->AddChannel(0);
renderer_->SetSink(this);
}
virtual ~VoiceChannelAudioSink() {
if (renderer_) {
renderer_->RemoveChannel(0);
renderer_->SetSink(NULL);
}
}

View File

@ -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.