summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxians@chromium.org <xians@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-04 13:34:42 +0000
committerxians@chromium.org <xians@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-04 13:34:42 +0000
commit0787ddee87bd9f3c2c1f5abe974c333fbd83ebb5 (patch)
treef313c6ca7a30a58a8bde56d5e50cc446eb1ead59
parentff5fd94140097638abb9d4b877ece9760e37daac (diff)
downloadchromium_src-0787ddee87bd9f3c2c1f5abe974c333fbd83ebb5.zip
chromium_src-0787ddee87bd9f3c2c1f5abe974c333fbd83ebb5.tar.gz
chromium_src-0787ddee87bd9f3c2c1f5abe974c333fbd83ebb5.tar.bz2
WIP: Isolate the libjingle dependency of WebRtcLocalAudioTrack into an adapter class.
This CL is taking over from https://codereview.chromium.org/123943003/ which creates an adapter for the local audio track and hide all the libjingle webrtc interfaces/objects into the adapter. BUG=325675 TEST=content_unittests and content_browsertets, nothing breaks. R=jamesr@chromium.org, joi@chromium.org Review URL: https://codereview.chromium.org/151503004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@248712 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/content_renderer.gypi2
-rw-r--r--content/public/renderer/media_stream_audio_sink.cc4
-rw-r--r--content/renderer/media/media_stream_dependency_factory.cc44
-rw-r--r--content/renderer/media/media_stream_dependency_factory.h2
-rw-r--r--content/renderer/media/mock_media_stream_dependency_factory.cc12
-rw-r--r--content/renderer/media/mock_media_stream_dependency_factory.h2
-rw-r--r--content/renderer/media/rtc_peer_connection_handler_unittest.cc9
-rw-r--r--content/renderer/media/webrtc/webrtc_local_audio_track_adapter.cc82
-rw-r--r--content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h75
-rw-r--r--content/renderer/media/webrtc_audio_capturer_unittest.cc10
-rw-r--r--content/renderer/media/webrtc_audio_device_unittest.cc49
-rw-r--r--content/renderer/media/webrtc_local_audio_track.cc71
-rw-r--r--content/renderer/media/webrtc_local_audio_track.h62
-rw-r--r--content/renderer/media/webrtc_local_audio_track_unittest.cc113
14 files changed, 321 insertions, 216 deletions
diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi
index 66df31b..3f2a696 100644
--- a/content/content_renderer.gypi
+++ b/content/content_renderer.gypi
@@ -676,6 +676,8 @@
'renderer/media/webrtc_local_audio_track.h',
'renderer/media/webrtc_logging.cc',
'renderer/media/webrtc_logging.h',
+ 'renderer/media/webrtc/webrtc_local_audio_track_adapter.cc',
+ 'renderer/media/webrtc/webrtc_local_audio_track_adapter.h',
'renderer/media/webrtc/webrtc_video_sink_adapter.cc',
'renderer/media/webrtc/webrtc_video_sink_adapter.h',
'renderer/p2p/host_address_request.cc',
diff --git a/content/public/renderer/media_stream_audio_sink.cc b/content/public/renderer/media_stream_audio_sink.cc
index f96c92b..f62fc19 100644
--- a/content/public/renderer/media_stream_audio_sink.cc
+++ b/content/public/renderer/media_stream_audio_sink.cc
@@ -21,7 +21,7 @@ void MediaStreamAudioSink::AddToAudioTrack(
// TODO(xians): Support remote audio track.
DCHECK(extra_data->is_local_track());
WebRtcLocalAudioTrack* audio_track =
- static_cast<WebRtcLocalAudioTrack*>(extra_data->track().get());
+ static_cast<WebRtcLocalAudioTrack*>(extra_data);
audio_track->AddSink(sink);
}
@@ -33,7 +33,7 @@ void MediaStreamAudioSink::RemoveFromAudioTrack(
// TODO(xians): Support remote audio track.
DCHECK(extra_data->is_local_track());
WebRtcLocalAudioTrack* audio_track =
- static_cast<WebRtcLocalAudioTrack*>(extra_data->track().get());
+ static_cast<WebRtcLocalAudioTrack*>(extra_data);
audio_track->RemoveSink(sink);
}
diff --git a/content/renderer/media/media_stream_dependency_factory.cc b/content/renderer/media/media_stream_dependency_factory.cc
index d335737..d07457f 100644
--- a/content/renderer/media/media_stream_dependency_factory.cc
+++ b/content/renderer/media/media_stream_dependency_factory.cc
@@ -23,6 +23,7 @@
#include "content/renderer/media/rtc_video_decoder_factory.h"
#include "content/renderer/media/rtc_video_encoder_factory.h"
#include "content/renderer/media/webaudio_capturer_source.h"
+#include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h"
#include "content/renderer/media/webrtc_audio_device_impl.h"
#include "content/renderer/media/webrtc_local_audio_track.h"
#include "content/renderer/media/webrtc_uma_histograms.h"
@@ -294,21 +295,10 @@ MediaStreamDependencyFactory::CreateNativeAudioMediaStreamTrack(
}
}
- scoped_refptr<webrtc::AudioTrackInterface> audio_track(
- CreateLocalAudioTrack(track.id().utf8(),
- source_data->GetAudioCapturer(),
- webaudio_source.get(),
- source_data->local_audio_source()));
- AddNativeTrackToBlinkTrack(audio_track.get(), track, true);
-
- audio_track->set_enabled(track.isEnabled());
-
- // Pass the pointer of the source provider to the blink audio track.
- blink::WebMediaStreamTrack writable_track = track;
- writable_track.setSourceProvider(static_cast<WebRtcLocalAudioTrack*>(
- audio_track.get())->audio_source_provider());
-
- return audio_track;
+ return CreateLocalAudioTrack(track,
+ source_data->GetAudioCapturer(),
+ webaudio_source.get(),
+ source_data->local_audio_source());
}
scoped_refptr<webrtc::VideoTrackInterface>
@@ -654,23 +644,39 @@ MediaStreamDependencyFactory::CreateLocalVideoTrack(
scoped_refptr<webrtc::AudioTrackInterface>
MediaStreamDependencyFactory::CreateLocalAudioTrack(
- const std::string& id,
+ const blink::WebMediaStreamTrack& blink_track,
const scoped_refptr<WebRtcAudioCapturer>& capturer,
WebAudioCapturerSource* webaudio_source,
webrtc::AudioSourceInterface* source) {
+ // Creates an adapter to hold all the libjingle objects.
+ scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
+ WebRtcLocalAudioTrackAdapter::Create(blink_track.id().utf8(), source));
+ static_cast<webrtc::AudioTrackInterface*>(adapter.get())->set_enabled(
+ blink_track.isEnabled());
+
// TODO(xians): Merge |source| to the capturer(). We can't do this today
// because only one capturer() is supported while one |source| is created
// for each audio track.
- scoped_refptr<WebRtcLocalAudioTrack> audio_track(
- WebRtcLocalAudioTrack::Create(id, capturer, webaudio_source, source));
+ scoped_ptr<WebRtcLocalAudioTrack> audio_track(
+ new WebRtcLocalAudioTrack(adapter, capturer, webaudio_source));
// Add the WebRtcAudioDevice as the sink to the local audio track.
+ // TODO(xians): Implement a PeerConnection sink adapter and remove this
+ // AddSink() call.
audio_track->AddSink(GetWebRtcAudioDevice());
// Start the audio track. This will hook the |audio_track| to the capturer
// as the sink of the audio, and only start the source of the capturer if
// it is the first audio track connecting to the capturer.
audio_track->Start();
- return audio_track;
+
+ // Pass the pointer of the source provider to the blink audio track.
+ blink::WebMediaStreamTrack writable_track = blink_track;
+ writable_track.setSourceProvider(audio_track->audio_source_provider());
+
+ // Pass the ownership of the native local audio track to the blink track.
+ writable_track.setExtraData(audio_track.release());
+
+ return adapter;
}
webrtc::SessionDescriptionInterface*
diff --git a/content/renderer/media/media_stream_dependency_factory.h b/content/renderer/media/media_stream_dependency_factory.h
index f638cae..f41c31a 100644
--- a/content/renderer/media/media_stream_dependency_factory.h
+++ b/content/renderer/media/media_stream_dependency_factory.h
@@ -180,7 +180,7 @@ class CONTENT_EXPORT MediaStreamDependencyFactory
// Asks the PeerConnection factory to create a Local AudioTrack object.
virtual scoped_refptr<webrtc::AudioTrackInterface>
CreateLocalAudioTrack(
- const std::string& id,
+ const blink::WebMediaStreamTrack& blink_track,
const scoped_refptr<WebRtcAudioCapturer>& capturer,
WebAudioCapturerSource* webaudio_source,
webrtc::AudioSourceInterface* source);
diff --git a/content/renderer/media/mock_media_stream_dependency_factory.cc b/content/renderer/media/mock_media_stream_dependency_factory.cc
index 0fd8150..3b2dc9b5 100644
--- a/content/renderer/media/mock_media_stream_dependency_factory.cc
+++ b/content/renderer/media/mock_media_stream_dependency_factory.cc
@@ -8,8 +8,9 @@
#include "base/strings/utf_string_conversions.h"
#include "content/renderer/media/mock_peer_connection_impl.h"
#include "content/renderer/media/webaudio_capturer_source.h"
+#include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h"
#include "content/renderer/media/webrtc_audio_capturer.h"
-#include "content/renderer/media/webrtc_local_audio_track.h"
+#include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
#include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
#include "third_party/libjingle/source/talk/base/scoped_ref_ptr.h"
#include "third_party/libjingle/source/talk/media/base/videocapturer.h"
@@ -441,16 +442,11 @@ MockMediaStreamDependencyFactory::CreateLocalVideoTrack(
scoped_refptr<webrtc::AudioTrackInterface>
MockMediaStreamDependencyFactory::CreateLocalAudioTrack(
- const std::string& id,
+ const blink::WebMediaStreamTrack& blink_track,
const scoped_refptr<WebRtcAudioCapturer>& capturer,
WebAudioCapturerSource* webaudio_source,
webrtc::AudioSourceInterface* source) {
- blink::WebMediaConstraints constraints;
- scoped_refptr<WebRtcAudioCapturer> audio_capturer = capturer ?
- capturer : WebRtcAudioCapturer::CreateCapturer(-1, StreamDeviceInfo(),
- constraints, NULL);
- return WebRtcLocalAudioTrack::Create(
- id, audio_capturer, webaudio_source, source);
+ return WebRtcLocalAudioTrackAdapter::Create(blink_track.id().utf8(), source);
}
SessionDescriptionInterface*
diff --git a/content/renderer/media/mock_media_stream_dependency_factory.h b/content/renderer/media/mock_media_stream_dependency_factory.h
index ad4241e..cc42cf2 100644
--- a/content/renderer/media/mock_media_stream_dependency_factory.h
+++ b/content/renderer/media/mock_media_stream_dependency_factory.h
@@ -165,7 +165,7 @@ class MockMediaStreamDependencyFactory : public MediaStreamDependencyFactory {
CreateLocalVideoTrack(const std::string& id,
cricket::VideoCapturer* capturer) OVERRIDE;
virtual scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack(
- const std::string& id,
+ const blink::WebMediaStreamTrack& blink_track,
const scoped_refptr<WebRtcAudioCapturer>& capturer,
WebAudioCapturerSource* webaudio_source,
webrtc::AudioSourceInterface* source) OVERRIDE;
diff --git a/content/renderer/media/rtc_peer_connection_handler_unittest.cc b/content/renderer/media/rtc_peer_connection_handler_unittest.cc
index 780eb5c..b9df887 100644
--- a/content/renderer/media/rtc_peer_connection_handler_unittest.cc
+++ b/content/renderer/media/rtc_peer_connection_handler_unittest.cc
@@ -15,6 +15,7 @@
#include "content/renderer/media/peer_connection_tracker.h"
#include "content/renderer/media/rtc_media_constraints.h"
#include "content/renderer/media/rtc_peer_connection_handler.h"
+#include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h"
#include "content/renderer/media/webrtc_audio_capturer.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -240,11 +241,10 @@ class RTCPeerConnectionHandlerTest : public ::testing::Test {
mock_dependency_factory_->CreateLocalMediaStream(stream_label));
local_stream.audioTracks(audio_tracks);
- const std::string audio_track_id = base::UTF16ToUTF8(audio_tracks[0].id());
scoped_refptr<WebRtcAudioCapturer> capturer;
scoped_refptr<webrtc::AudioTrackInterface> audio_track(
mock_dependency_factory_->CreateLocalAudioTrack(
- audio_track_id, capturer, NULL, NULL));
+ audio_tracks[0], capturer, NULL, NULL));
MediaStreamDependencyFactory::AddNativeTrackToBlinkTrack(
audio_track.get(), audio_tracks[0], true);
native_stream->AddTrack(audio_track.get());
@@ -282,10 +282,7 @@ class RTCPeerConnectionHandlerTest : public ::testing::Test {
if (!audio_track_label.empty()) {
scoped_refptr<WebRtcAudioCapturer> capturer;
scoped_refptr<webrtc::AudioTrackInterface> audio_track(
- mock_dependency_factory_->CreateLocalAudioTrack(audio_track_label,
- capturer,
- NULL,
- NULL));
+ WebRtcLocalAudioTrackAdapter::Create(audio_track_label, NULL));
stream->AddTrack(audio_track.get());
}
mock_peer_connection_->AddRemoteStream(stream.get());
diff --git a/content/renderer/media/webrtc/webrtc_local_audio_track_adapter.cc b/content/renderer/media/webrtc/webrtc_local_audio_track_adapter.cc
new file mode 100644
index 0000000..4d1b33e
--- /dev/null
+++ b/content/renderer/media/webrtc/webrtc_local_audio_track_adapter.cc
@@ -0,0 +1,82 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h"
+
+#include "base/logging.h"
+#include "content/renderer/media/webrtc_local_audio_track.h"
+
+namespace content {
+
+static const char kAudioTrackKind[] = "audio";
+
+scoped_refptr<WebRtcLocalAudioTrackAdapter>
+WebRtcLocalAudioTrackAdapter::Create(
+ const std::string& label,
+ webrtc::AudioSourceInterface* track_source) {
+ talk_base::RefCountedObject<WebRtcLocalAudioTrackAdapter>* adapter =
+ new talk_base::RefCountedObject<WebRtcLocalAudioTrackAdapter>(
+ label, track_source);
+ return adapter;
+}
+
+WebRtcLocalAudioTrackAdapter::WebRtcLocalAudioTrackAdapter(
+ const std::string& label,
+ webrtc::AudioSourceInterface* track_source)
+ : webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>(label),
+ owner_(NULL),
+ track_source_(track_source) {
+}
+
+WebRtcLocalAudioTrackAdapter::~WebRtcLocalAudioTrackAdapter() {
+}
+
+void WebRtcLocalAudioTrackAdapter::Initialize(WebRtcLocalAudioTrack* owner) {
+ DCHECK(!owner_);
+ DCHECK(owner);
+ owner_ = owner;
+}
+
+std::string WebRtcLocalAudioTrackAdapter::kind() const {
+ return kAudioTrackKind;
+}
+
+std::vector<int> WebRtcLocalAudioTrackAdapter::VoeChannels() const {
+ base::AutoLock auto_lock(lock_);
+ return voe_channels_;
+}
+
+void WebRtcLocalAudioTrackAdapter::AddChannel(int channel_id) {
+ DVLOG(1) << "WebRtcLocalAudioTrack::AddChannel(channel_id="
+ << channel_id << ")";
+ base::AutoLock auto_lock(lock_);
+ if (std::find(voe_channels_.begin(), voe_channels_.end(), channel_id) !=
+ voe_channels_.end()) {
+ // We need to handle the case when the same channel is connected to the
+ // track more than once.
+ return;
+ }
+
+ voe_channels_.push_back(channel_id);
+}
+
+void WebRtcLocalAudioTrackAdapter::RemoveChannel(int channel_id) {
+ DVLOG(1) << "WebRtcLocalAudioTrack::RemoveChannel(channel_id="
+ << channel_id << ")";
+ base::AutoLock auto_lock(lock_);
+ std::vector<int>::iterator iter =
+ std::find(voe_channels_.begin(), voe_channels_.end(), channel_id);
+ DCHECK(iter != voe_channels_.end());
+ voe_channels_.erase(iter);
+}
+
+webrtc::AudioSourceInterface* WebRtcLocalAudioTrackAdapter::GetSource() const {
+ return track_source_;
+}
+
+cricket::AudioRenderer* WebRtcLocalAudioTrackAdapter::GetRenderer() {
+ return this;
+}
+
+} // namespace content
diff --git a/content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h b/content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h
new file mode 100644
index 0000000..2aecb6c
--- /dev/null
+++ b/content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h
@@ -0,0 +1,75 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_
+#define CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_
+
+#include <vector>
+
+#include "base/memory/ref_counted.h"
+#include "base/synchronization/lock.h"
+#include "content/common/content_export.h"
+#include "third_party/libjingle/source/talk/app/webrtc/mediastreamtrack.h"
+#include "third_party/libjingle/source/talk/media/base/audiorenderer.h"
+
+namespace cricket {
+class AudioRenderer;
+}
+
+namespace webrtc {
+class AudioSourceInterface;
+}
+
+namespace content {
+
+class WebRtcLocalAudioTrack;
+
+class CONTENT_EXPORT WebRtcLocalAudioTrackAdapter
+ : NON_EXPORTED_BASE(public cricket::AudioRenderer),
+ NON_EXPORTED_BASE(
+ public webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>) {
+ public:
+ static scoped_refptr<WebRtcLocalAudioTrackAdapter> Create(
+ const std::string& label,
+ webrtc::AudioSourceInterface* track_source);
+
+ WebRtcLocalAudioTrackAdapter(
+ const std::string& label,
+ webrtc::AudioSourceInterface* track_source);
+
+ virtual ~WebRtcLocalAudioTrackAdapter();
+
+ void Initialize(WebRtcLocalAudioTrack* owner);
+
+ std::vector<int> VoeChannels() const;
+
+ private:
+ // webrtc::MediaStreamTrack implementation.
+ virtual std::string kind() const OVERRIDE;
+
+ // cricket::AudioCapturer implementation.
+ virtual void AddChannel(int channel_id) OVERRIDE;
+ virtual void RemoveChannel(int channel_id) OVERRIDE;
+
+ // webrtc::AudioTrackInterface implementation.
+ virtual webrtc::AudioSourceInterface* GetSource() const OVERRIDE;
+ virtual cricket::AudioRenderer* GetRenderer() OVERRIDE;
+
+ // Weak reference.
+ WebRtcLocalAudioTrack* owner_;
+
+ // The source of the audio track which handles the audio constraints.
+ // TODO(xians): merge |track_source_| to |capturer_| in WebRtcLocalAudioTrack.
+ talk_base::scoped_refptr<webrtc::AudioSourceInterface> track_source_;
+
+ // A vector of WebRtc VoE channels that the capturer sends data to.
+ std::vector<int> voe_channels_;
+
+ // Protects |voe_channels_|.
+ mutable base::Lock lock_;
+};
+
+} // namespace content
+
+#endif // CONTENT_RENDERER_MEDIA_WEBRTC_WEBRTC_LOCAL_AUDIO_TRACK_ADAPTER_H_
diff --git a/content/renderer/media/webrtc_audio_capturer_unittest.cc b/content/renderer/media/webrtc_audio_capturer_unittest.cc
index d227186..abba40c 100644
--- a/content/renderer/media/webrtc_audio_capturer_unittest.cc
+++ b/content/renderer/media/webrtc_audio_capturer_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/logging.h"
+#include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h"
#include "content/renderer/media/webrtc_audio_capturer.h"
#include "content/renderer/media/webrtc_local_audio_track.h"
#include "media/audio/audio_parameters.h"
@@ -76,18 +77,19 @@ class WebRtcAudioCapturerTest : public testing::Test {
EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
EXPECT_CALL(*capturer_source_.get(), Start());
- track_ = WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL,
- NULL);
+ scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
+ WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
+ track_.reset(new WebRtcLocalAudioTrack(adapter, capturer_, NULL));
static_cast<WebRtcLocalAudioSourceProvider*>(
track_->audio_source_provider())->SetSinkParamsForTesting(params_);
track_->Start();
- EXPECT_TRUE(track_->enabled());
+ EXPECT_TRUE(track_->track()->enabled());
}
media::AudioParameters params_;
scoped_refptr<MockCapturerSource> capturer_source_;
scoped_refptr<WebRtcAudioCapturer> capturer_;
- scoped_refptr<WebRtcLocalAudioTrack> track_;
+ scoped_ptr<WebRtcLocalAudioTrack> track_;
};
// Pass the delay value, vollume and key_pressed info via capture callback, and
diff --git a/content/renderer/media/webrtc_audio_device_unittest.cc b/content/renderer/media/webrtc_audio_device_unittest.cc
index 5545ec7..70efcdd 100644
--- a/content/renderer/media/webrtc_audio_device_unittest.cc
+++ b/content/renderer/media/webrtc_audio_device_unittest.cc
@@ -10,6 +10,7 @@
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "base/test/test_timeouts.h"
+#include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h"
#include "content/renderer/media/webrtc_audio_capturer.h"
#include "content/renderer/media/webrtc_audio_device_impl.h"
#include "content/renderer/media/webrtc_audio_renderer.h"
@@ -131,14 +132,16 @@ scoped_refptr<WebRtcAudioCapturer> CreateAudioCapturer(
// Create and start a local audio track. Starting the audio track will connect
// the audio track to the capturer and also start the source of the capturer.
// Also, connect the sink to the audio track.
-scoped_refptr<WebRtcLocalAudioTrack>
-CreateAndStartLocalAudioTrack(WebRtcAudioCapturer* capturer,
+scoped_ptr<WebRtcLocalAudioTrack>
+CreateAndStartLocalAudioTrack(WebRtcLocalAudioTrackAdapter* adapter,
+ WebRtcAudioCapturer* capturer,
PeerConnectionAudioSink* sink) {
- scoped_refptr<WebRtcLocalAudioTrack> local_audio_track(
- WebRtcLocalAudioTrack::Create(std::string(), capturer, NULL, NULL));
+ scoped_ptr<WebRtcLocalAudioTrack> local_audio_track(
+ new WebRtcLocalAudioTrack(adapter, capturer, NULL));
+
local_audio_track->AddSink(sink);
local_audio_track->Start();
- return local_audio_track;
+ return local_audio_track.Pass();
}
class WebRTCMediaProcessImpl : public webrtc::VoEMediaProcess {
@@ -641,11 +644,13 @@ TEST_F(MAYBE_WebRTCAudioDeviceTest, MAYBE_StartRecording) {
// Create and start a local audio track which is bridging the data flow
// between the capturer and WebRtcAudioDeviceImpl.
- scoped_refptr<WebRtcLocalAudioTrack> local_audio_track(
- CreateAndStartLocalAudioTrack(capturer, webrtc_audio_device));
+ scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
+ WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
+ scoped_ptr<WebRtcLocalAudioTrack> local_audio_track(
+ CreateAndStartLocalAudioTrack(adapter, capturer, webrtc_audio_device));
// connect the VoE voice channel to the audio track
- static_cast<webrtc::AudioTrackInterface*>(local_audio_track.get())->
- GetRenderer()->AddChannel(ch);
+ static_cast<webrtc::AudioTrackInterface*>(
+ adapter.get())->GetRenderer()->AddChannel(ch);
// Verify we get the data flow.
EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout()));
@@ -791,14 +796,16 @@ TEST_F(MAYBE_WebRTCAudioDeviceTest, MAYBE_FullDuplexAudioWithAGC) {
int ch = base->CreateChannel();
EXPECT_NE(-1, ch);
+ scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
+ WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
scoped_refptr<WebRtcAudioCapturer> capturer(
CreateAudioCapturer(webrtc_audio_device));
EXPECT_TRUE(capturer);
- scoped_refptr<WebRtcLocalAudioTrack> local_audio_track(
- CreateAndStartLocalAudioTrack(capturer, webrtc_audio_device));
- // connect the VoE voice channel to the audio track
- static_cast<webrtc::AudioTrackInterface*>(local_audio_track.get())->
- GetRenderer()->AddChannel(ch);
+ scoped_ptr<WebRtcLocalAudioTrack> local_audio_track(
+ CreateAndStartLocalAudioTrack(adapter, capturer, webrtc_audio_device));
+ // connect the VoE voice channel to the audio track adapter.
+ static_cast<webrtc::AudioTrackInterface*>(
+ adapter.get())->GetRenderer()->AddChannel(ch);
ScopedWebRTCPtr<webrtc::VoENetwork> network(engine.get());
ASSERT_TRUE(network.valid());
@@ -867,12 +874,14 @@ TEST_F(MAYBE_WebRTCAudioDeviceTest, DISABLED_WebRtcRecordingSetupTime) {
// Create and start a local audio track. Starting the audio track will connect
// the audio track to the capturer and also start the source of the capturer.
- scoped_refptr<WebRtcLocalAudioTrack> local_audio_track(
- CreateAndStartLocalAudioTrack(capturer, sink.get()));
-
- // connect the VoE voice channel to the audio track.
- static_cast<webrtc::AudioTrackInterface*>(local_audio_track.get())->
- GetRenderer()->AddChannel(ch);
+ scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
+ WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
+ scoped_ptr<WebRtcLocalAudioTrack> local_audio_track(
+ CreateAndStartLocalAudioTrack(adapter, capturer, sink.get()));
+
+ // connect the VoE voice channel to the audio track adapter.
+ static_cast<webrtc::AudioTrackInterface*>(
+ adapter.get())->GetRenderer()->AddChannel(ch);
base::Time start_time = base::Time::Now();
EXPECT_EQ(0, base->StartSend(ch));
diff --git a/content/renderer/media/webrtc_local_audio_track.cc b/content/renderer/media/webrtc_local_audio_track.cc
index ce680c0..2adf246 100644
--- a/content/renderer/media/webrtc_local_audio_track.cc
+++ b/content/renderer/media/webrtc_local_audio_track.cc
@@ -9,36 +9,23 @@
#include "content/renderer/media/media_stream_audio_track_sink.h"
#include "content/renderer/media/peer_connection_audio_sink_owner.h"
#include "content/renderer/media/webaudio_capturer_source.h"
+#include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h"
#include "content/renderer/media/webrtc_audio_capturer.h"
-#include "content/renderer/media/webrtc_local_audio_source_provider.h"
-#include "media/base/audio_fifo.h"
-#include "third_party/libjingle/source/talk/media/base/audiorenderer.h"
namespace content {
-static const char kAudioTrackKind[] = "audio";
-
-scoped_refptr<WebRtcLocalAudioTrack> WebRtcLocalAudioTrack::Create(
- const std::string& id,
- const scoped_refptr<WebRtcAudioCapturer>& capturer,
- WebAudioCapturerSource* webaudio_source,
- webrtc::AudioSourceInterface* track_source) {
- talk_base::RefCountedObject<WebRtcLocalAudioTrack>* track =
- new talk_base::RefCountedObject<WebRtcLocalAudioTrack>(
- id, capturer, webaudio_source, track_source);
- return track;
-}
-
WebRtcLocalAudioTrack::WebRtcLocalAudioTrack(
- const std::string& label,
+ WebRtcLocalAudioTrackAdapter* adapter,
const scoped_refptr<WebRtcAudioCapturer>& capturer,
- WebAudioCapturerSource* webaudio_source,
- webrtc::AudioSourceInterface* track_source)
- : webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>(label),
+ WebAudioCapturerSource* webaudio_source)
+ : MediaStreamTrackExtraData(adapter, true),
+ adapter_(adapter),
capturer_(capturer),
- webaudio_source_(webaudio_source),
- track_source_(track_source) {
+ webaudio_source_(webaudio_source) {
DCHECK(capturer.get() || webaudio_source);
+
+ adapter_->Initialize(this);
+
if (!webaudio_source_) {
source_provider_.reset(new WebRtcLocalAudioSourceProvider());
AddSink(source_provider_.get());
@@ -60,13 +47,11 @@ void WebRtcLocalAudioTrack::Capture(const int16* audio_data,
bool need_audio_processing) {
DCHECK(capture_thread_checker_.CalledOnValidThread());
scoped_refptr<WebRtcAudioCapturer> capturer;
- std::vector<int> voe_channels;
SinkList::ItemList sinks;
SinkList::ItemList sinks_to_notify_format;
{
base::AutoLock auto_lock(lock_);
capturer = capturer_;
- voe_channels = voe_channels_;
sinks = sinks_.Items();
sinks_.RetrieveAndClearTags(&sinks_to_notify_format);
}
@@ -83,6 +68,7 @@ void WebRtcLocalAudioTrack::Capture(const int16* audio_data,
// disabled. This is currently done so to feed input to WebRTC typing
// detection and should be changed when audio processing is moved from
// WebRTC to the track.
+ std::vector<int> voe_channels = adapter_->VoeChannels();
for (SinkList::ItemList::const_iterator it = sinks.begin();
it != sinks.end();
++it) {
@@ -118,43 +104,6 @@ void WebRtcLocalAudioTrack::OnSetFormat(
sinks_.TagAll();
}
-void WebRtcLocalAudioTrack::AddChannel(int channel_id) {
- DVLOG(1) << "WebRtcLocalAudioTrack::AddChannel(channel_id="
- << channel_id << ")";
- base::AutoLock auto_lock(lock_);
- if (std::find(voe_channels_.begin(), voe_channels_.end(), channel_id) !=
- voe_channels_.end()) {
- // We need to handle the case when the same channel is connected to the
- // track more than once.
- return;
- }
-
- voe_channels_.push_back(channel_id);
-}
-
-void WebRtcLocalAudioTrack::RemoveChannel(int channel_id) {
- DVLOG(1) << "WebRtcLocalAudioTrack::RemoveChannel(channel_id="
- << channel_id << ")";
- base::AutoLock auto_lock(lock_);
- std::vector<int>::iterator iter =
- std::find(voe_channels_.begin(), voe_channels_.end(), channel_id);
- DCHECK(iter != voe_channels_.end());
- voe_channels_.erase(iter);
-}
-
-// webrtc::AudioTrackInterface implementation.
-webrtc::AudioSourceInterface* WebRtcLocalAudioTrack::GetSource() const {
- return track_source_;
-}
-
-cricket::AudioRenderer* WebRtcLocalAudioTrack::GetRenderer() {
- return this;
-}
-
-std::string WebRtcLocalAudioTrack::kind() const {
- return kAudioTrackKind;
-}
-
void WebRtcLocalAudioTrack::AddSink(MediaStreamAudioSink* sink) {
DCHECK(main_render_thread_checker_.CalledOnValidThread());
DVLOG(1) << "WebRtcLocalAudioTrack::AddSink()";
diff --git a/content/renderer/media/webrtc_local_audio_track.h b/content/renderer/media/webrtc_local_audio_track.h
index 53444ec..0ead7ee 100644
--- a/content/renderer/media/webrtc_local_audio_track.h
+++ b/content/renderer/media/webrtc_local_audio_track.h
@@ -8,47 +8,37 @@
#include <list>
#include <string>
+#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "base/threading/thread_checker.h"
-#include "content/renderer/media/media_stream_audio_track_sink.h"
+#include "content/renderer/media/media_stream_track_extra_data.h"
#include "content/renderer/media/tagged_list.h"
#include "content/renderer/media/webrtc_audio_device_impl.h"
#include "content/renderer/media/webrtc_local_audio_source_provider.h"
-#include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
-#include "third_party/libjingle/source/talk/app/webrtc/mediastreamtrack.h"
-#include "third_party/libjingle/source/talk/media/base/audiorenderer.h"
-
-namespace cricket {
-class AudioRenderer;
-} // namespace cricket
-
-namespace media {
-class AudioBus;
-} // namespace media
namespace content {
class MediaStreamAudioSink;
class MediaStreamAudioSinkOwner;
+class MediaStreamAudioTrackSink;
class PeerConnectionAudioSink;
class WebAudioCapturerSource;
class WebRtcAudioCapturer;
+class WebRtcLocalAudioTrackAdapter;
// A WebRtcLocalAudioTrack instance contains the implementations of
-// MediaStreamTrack and MediaStreamAudioSink.
+// MediaStreamTrackExtraData.
// When an instance is created, it will register itself as a track to the
// WebRtcAudioCapturer to get the captured data, and forward the data to
// its |sinks_|. The data flow can be stopped by disabling the audio track.
class CONTENT_EXPORT WebRtcLocalAudioTrack
- : NON_EXPORTED_BASE(public cricket::AudioRenderer),
- NON_EXPORTED_BASE(
- public webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>) {
+ : NON_EXPORTED_BASE(public MediaStreamTrackExtraData) {
public:
- static scoped_refptr<WebRtcLocalAudioTrack> Create(
- const std::string& id,
- const scoped_refptr<WebRtcAudioCapturer>& capturer,
- WebAudioCapturerSource* webaudio_source,
- webrtc::AudioSourceInterface* track_source);
+ WebRtcLocalAudioTrack(WebRtcLocalAudioTrackAdapter* adapter,
+ const scoped_refptr<WebRtcAudioCapturer>& capturer,
+ WebAudioCapturerSource* webaudio_source);
+
+ virtual ~WebRtcLocalAudioTrack();
// Add a sink to the track. This function will trigger a OnSetFormat()
// call on the |sink|.
@@ -90,41 +80,20 @@ class CONTENT_EXPORT WebRtcLocalAudioTrack
return source_provider_.get();
}
- protected:
- WebRtcLocalAudioTrack(
- const std::string& label,
- const scoped_refptr<WebRtcAudioCapturer>& capturer,
- WebAudioCapturerSource* webaudio_source,
- webrtc::AudioSourceInterface* track_source);
-
- virtual ~WebRtcLocalAudioTrack();
-
private:
typedef TaggedList<MediaStreamAudioTrackSink> SinkList;
- // cricket::AudioCapturer implementation.
- virtual void AddChannel(int channel_id) OVERRIDE;
- virtual void RemoveChannel(int channel_id) OVERRIDE;
-
- // webrtc::AudioTrackInterface implementation.
- virtual webrtc::AudioSourceInterface* GetSource() const OVERRIDE;
- virtual cricket::AudioRenderer* GetRenderer() OVERRIDE;
-
- // webrtc::MediaStreamTrack implementation.
- virtual std::string kind() const OVERRIDE;
+ // All usage of libjingle is through this adapter. The adapter holds
+ // a reference on this object, but not vice versa.
+ WebRtcLocalAudioTrackAdapter* adapter_;
// The provider of captured data to render.
- // The WebRtcAudioCapturer is today created by WebRtcAudioDeviceImpl.
scoped_refptr<WebRtcAudioCapturer> capturer_;
// The source of the audio track which is used by WebAudio, which provides
// data to the audio track when hooking up with WebAudio.
scoped_refptr<WebAudioCapturerSource> webaudio_source_;
- // The source of the audio track which handles the audio constraints.
- // TODO(xians): merge |track_source_| to |capturer_|.
- talk_base::scoped_refptr<webrtc::AudioSourceInterface> track_source_;
-
// A tagged list of sinks that the audio data is fed to. Tags
// indicate tracks that need to be notified that the audio format
// has changed.
@@ -139,9 +108,6 @@ class CONTENT_EXPORT WebRtcLocalAudioTrack
// Protects |params_| and |sinks_|.
mutable base::Lock lock_;
- // A vector of WebRtc VoE channels that the capturer sends data to.
- std::vector<int> voe_channels_;
-
// Audio parameters of the audio capture stream.
// Accessed on only the audio capture thread.
media::AudioParameters audio_parameters_;
diff --git a/content/renderer/media/webrtc_local_audio_track_unittest.cc b/content/renderer/media/webrtc_local_audio_track_unittest.cc
index ea3c3bb..b17d8bc 100644
--- a/content/renderer/media/webrtc_local_audio_track_unittest.cc
+++ b/content/renderer/media/webrtc_local_audio_track_unittest.cc
@@ -4,6 +4,7 @@
#include "base/synchronization/waitable_event.h"
#include "base/test/test_timeouts.h"
+#include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h"
#include "content/renderer/media/webrtc_audio_capturer.h"
#include "content/renderer/media/webrtc_audio_device_impl.h"
#include "content/renderer/media/webrtc_local_audio_source_provider.h"
@@ -183,18 +184,20 @@ class WebRtcLocalAudioTrackTest : public ::testing::Test {
TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) {
EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
EXPECT_CALL(*capturer_source_.get(), OnStart());
- scoped_refptr<WebRtcLocalAudioTrack> track =
- WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL);
+ scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
+ WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
+ scoped_ptr<WebRtcLocalAudioTrack> track(
+ new WebRtcLocalAudioTrack(adapter, capturer_, NULL));
static_cast<WebRtcLocalAudioSourceProvider*>(
track->audio_source_provider())->SetSinkParamsForTesting(params_);
track->Start();
- EXPECT_TRUE(track->enabled());
+ EXPECT_TRUE(track->track()->enabled());
// Connect a number of network channels to the audio track.
static const int kNumberOfNetworkChannels = 4;
for (int i = 0; i < kNumberOfNetworkChannels; ++i) {
- static_cast<webrtc::AudioTrackInterface*>(track.get())->
- GetRenderer()->AddChannel(i);
+ static_cast<webrtc::AudioTrackInterface*>(
+ adapter.get())->GetRenderer()->AddChannel(i);
}
scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink());
const media::AudioParameters params = capturer_->source_audio_parameters();
@@ -228,15 +231,17 @@ TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) {
TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) {
EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
EXPECT_CALL(*capturer_source_.get(), OnStart());
- scoped_refptr<WebRtcLocalAudioTrack> track =
- WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL);
+ scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
+ WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
+ scoped_ptr<WebRtcLocalAudioTrack> track(
+ new WebRtcLocalAudioTrack(adapter, capturer_, NULL));
static_cast<WebRtcLocalAudioSourceProvider*>(
track->audio_source_provider())->SetSinkParamsForTesting(params_);
track->Start();
- static_cast<webrtc::AudioTrackInterface*>(track.get())->
- GetRenderer()->AddChannel(0);
- EXPECT_TRUE(track->enabled());
- EXPECT_TRUE(track->set_enabled(false));
+ static_cast<webrtc::AudioTrackInterface*>(
+ adapter.get())->GetRenderer()->AddChannel(0);
+ EXPECT_TRUE(track->track()->enabled());
+ EXPECT_TRUE(track->track()->set_enabled(false));
scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink());
const media::AudioParameters params = capturer_->source_audio_parameters();
base::WaitableEvent event(false, false);
@@ -264,13 +269,13 @@ TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) {
true,
false)).Times(AtLeast(1))
.WillRepeatedly(SignalEvent(&event));
- EXPECT_TRUE(track->set_enabled(true));
+ EXPECT_TRUE(track->track()->set_enabled(true));
EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout()));
track->RemoveSink(sink.get());
EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return());
capturer_->Stop();
- track = NULL;
+ track.reset();
}
// Create multiple audio tracks and enable/disable them, verify that the audio
@@ -279,14 +284,16 @@ TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) {
TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) {
EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
EXPECT_CALL(*capturer_source_.get(), OnStart());
- scoped_refptr<WebRtcLocalAudioTrack> track_1 =
- WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL);
+ scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1(
+ WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
+ scoped_ptr<WebRtcLocalAudioTrack> track_1(
+ new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL));
static_cast<WebRtcLocalAudioSourceProvider*>(
track_1->audio_source_provider())->SetSinkParamsForTesting(params_);
track_1->Start();
- static_cast<webrtc::AudioTrackInterface*>(track_1.get())->
- GetRenderer()->AddChannel(0);
- EXPECT_TRUE(track_1->enabled());
+ static_cast<webrtc::AudioTrackInterface*>(
+ adapter_1.get())->GetRenderer()->AddChannel(0);
+ EXPECT_TRUE(track_1->track()->enabled());
scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink());
const media::AudioParameters params = capturer_->source_audio_parameters();
base::WaitableEvent event_1(false, false);
@@ -304,14 +311,16 @@ TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) {
track_1->AddSink(sink_1.get());
EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout()));
- scoped_refptr<WebRtcLocalAudioTrack> track_2 =
- WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL);
+ scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2(
+ WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
+ scoped_ptr<WebRtcLocalAudioTrack> track_2(
+ new WebRtcLocalAudioTrack(adapter_2, capturer_, NULL));
static_cast<WebRtcLocalAudioSourceProvider*>(
track_2->audio_source_provider())->SetSinkParamsForTesting(params_);
track_2->Start();
- static_cast<webrtc::AudioTrackInterface*>(track_2.get())->
- GetRenderer()->AddChannel(1);
- EXPECT_TRUE(track_2->enabled());
+ static_cast<webrtc::AudioTrackInterface*>(
+ adapter_2.get())->GetRenderer()->AddChannel(1);
+ EXPECT_TRUE(track_2->track()->enabled());
// Verify both |sink_1| and |sink_2| get data.
event_1.Reset();
@@ -345,12 +354,12 @@ TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) {
track_1->RemoveSink(sink_1.get());
track_1->Stop();
- track_1 = NULL;
+ track_1.reset();
EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return());
track_2->RemoveSink(sink_2.get());
track_2->Stop();
- track_2 = NULL;
+ track_2.reset();
capturer_->Stop();
}
@@ -361,8 +370,10 @@ TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) {
TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) {
EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
EXPECT_CALL(*capturer_source_.get(), OnStart());
- scoped_refptr<WebRtcLocalAudioTrack> track =
- WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL);
+ scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
+ WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
+ scoped_ptr<WebRtcLocalAudioTrack> track(
+ new WebRtcLocalAudioTrack(adapter, capturer_, NULL));
static_cast<WebRtcLocalAudioSourceProvider*>(
track->audio_source_provider())->SetSinkParamsForTesting(params_);
track->Start();
@@ -371,7 +382,7 @@ TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) {
// |capturer_source_|.
EXPECT_CALL(*capturer_source_.get(), OnStop());
capturer_->Stop();
- track = NULL;
+ track.reset();
}
// Start/Stop tracks and verify the capturer is correctly starting/stopping
@@ -381,10 +392,12 @@ TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) {
base::WaitableEvent event(false, false);
EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
EXPECT_CALL(*capturer_source_.get(), OnStart()).WillOnce(SignalEvent(&event));
- scoped_refptr<WebRtcLocalAudioTrack> track_1 =
- WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL);
- static_cast<webrtc::AudioTrackInterface*>(track_1.get())->
- GetRenderer()->AddChannel(0);
+ scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1(
+ WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
+ scoped_ptr<WebRtcLocalAudioTrack> track_1(
+ new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL));
+ static_cast<webrtc::AudioTrackInterface*>(
+ adapter_1.get())->GetRenderer()->AddChannel(0);
static_cast<WebRtcLocalAudioSourceProvider*>(
track_1->audio_source_provider())->SetSinkParamsForTesting(params_);
track_1->Start();
@@ -402,13 +415,15 @@ TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) {
// Start the second audio track will not start the |capturer_source_|
// since it has been started.
EXPECT_CALL(*capturer_source_.get(), OnStart()).Times(0);
- scoped_refptr<WebRtcLocalAudioTrack> track_2 =
- WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL);
+ scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2(
+ WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
+ scoped_ptr<WebRtcLocalAudioTrack> track_2(
+ new WebRtcLocalAudioTrack(adapter_2, capturer_, NULL));
static_cast<WebRtcLocalAudioSourceProvider*>(
track_2->audio_source_provider())->SetSinkParamsForTesting(params_);
track_2->Start();
- static_cast<webrtc::AudioTrackInterface*>(track_2.get())->
- GetRenderer()->AddChannel(1);
+ static_cast<webrtc::AudioTrackInterface*>(
+ adapter_2.get())->GetRenderer()->AddChannel(1);
// Stop the capturer will clear up the track lists in the capturer.
EXPECT_CALL(*capturer_source_.get(), OnStop());
@@ -430,8 +445,10 @@ TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) {
// Setup the first audio track and start it.
EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
EXPECT_CALL(*capturer_source_.get(), OnStart());
- scoped_refptr<WebRtcLocalAudioTrack> track_1 =
- WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL);
+ scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1(
+ WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
+ scoped_ptr<WebRtcLocalAudioTrack> track_1(
+ new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL));
static_cast<WebRtcLocalAudioSourceProvider*>(
track_1->audio_source_provider())->SetSinkParamsForTesting(params_);
track_1->Start();
@@ -439,8 +456,8 @@ TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) {
// Connect a number of network channels to the |track_1|.
static const int kNumberOfNetworkChannelsForTrack1 = 2;
for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) {
- static_cast<webrtc::AudioTrackInterface*>(track_1.get())->
- GetRenderer()->AddChannel(i);
+ static_cast<webrtc::AudioTrackInterface*>(
+ adapter_1.get())->GetRenderer()->AddChannel(i);
}
// Verify the data flow by connecting the |sink_1| to |track_1|.
scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink());
@@ -468,8 +485,10 @@ TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) {
// Setup the second audio track, connect it to the new capturer and start it.
EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true));
EXPECT_CALL(*new_source.get(), OnStart());
- scoped_refptr<WebRtcLocalAudioTrack> track_2 =
- WebRtcLocalAudioTrack::Create(std::string(), new_capturer, NULL, NULL);
+ scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2(
+ WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
+ scoped_ptr<WebRtcLocalAudioTrack> track_2(
+ new WebRtcLocalAudioTrack(adapter_2, new_capturer, NULL));
static_cast<WebRtcLocalAudioSourceProvider*>(
track_2->audio_source_provider())->SetSinkParamsForTesting(params_);
track_2->Start();
@@ -477,8 +496,8 @@ TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) {
// Connect a number of network channels to the |track_2|.
static const int kNumberOfNetworkChannelsForTrack2 = 3;
for (int i = 0; i < kNumberOfNetworkChannelsForTrack2; ++i) {
- static_cast<webrtc::AudioTrackInterface*>(track_2.get())->
- GetRenderer()->AddChannel(i);
+ static_cast<webrtc::AudioTrackInterface*>(
+ adapter_2.get())->GetRenderer()->AddChannel(i);
}
// Verify the data flow by connecting the |sink_2| to |track_2|.
scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink());
@@ -532,8 +551,10 @@ TEST_F(WebRtcLocalAudioTrackTest, TrackWorkWithSmallBufferSize) {
// Setup a audio track, connect it to the capturer and start it.
EXPECT_CALL(*source.get(), SetAutomaticGainControl(true));
EXPECT_CALL(*source.get(), OnStart());
- scoped_refptr<WebRtcLocalAudioTrack> track =
- WebRtcLocalAudioTrack::Create(std::string(), capturer, NULL, NULL);
+ scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
+ WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
+ scoped_ptr<WebRtcLocalAudioTrack> track(
+ new WebRtcLocalAudioTrack(adapter, capturer, NULL));
static_cast<WebRtcLocalAudioSourceProvider*>(
track->audio_source_provider())->SetSinkParamsForTesting(params);
track->Start();