Commit 1b163742 authored by tommi@chromium.org's avatar tommi@chromium.org

Feed audio constraints over to WebRtcLocalAudioTrack

and check them to see if audio processing should be applied.
Previously this check was just being based on a device id being
empty or not, which doesn't do the right thing for WebAudio.

BUG=277134

Review URL: https://chromiumcodereview.appspot.com/23171026

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220617 0039d316-1c4b-4281-b951-d872f2087c98
parent 6ec5acc3
...@@ -70,23 +70,12 @@ struct { ...@@ -70,23 +70,12 @@ struct {
webrtc::MediaConstraintsInterface::kValueTrue}, webrtc::MediaConstraintsInterface::kValueTrue},
}; };
class WebAudioConstraints : public RTCMediaConstraints { void ApplyFixedWebAudioConstraints(RTCMediaConstraints* constraints) {
public: for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kWebAudioConstraints); ++i) {
WebAudioConstraints() constraints->AddMandatory(kWebAudioConstraints[i].key,
: RTCMediaConstraints(WebKit::WebMediaConstraints()) { kWebAudioConstraints[i].value, false);
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kWebAudioConstraints); ++i) {
webrtc::MediaConstraintsInterface::Constraint constraint;
constraint.key = kWebAudioConstraints[i].key;
constraint.value = kWebAudioConstraints[i].value;
DVLOG(1) << "WebAudioConstraints: " << constraint.key
<< " : " << constraint.value;
mandatory_.push_back(constraint);
}
} }
}
virtual ~WebAudioConstraints() {}
};
class P2PPortAllocatorFactory : public webrtc::PortAllocatorFactoryInterface { class P2PPortAllocatorFactory : public webrtc::PortAllocatorFactoryInterface {
public: public:
...@@ -325,6 +314,10 @@ void MediaStreamDependencyFactory::CreateNativeMediaSources( ...@@ -325,6 +314,10 @@ void MediaStreamDependencyFactory::CreateNativeMediaSources(
DLOG(WARNING) << "Failed to create the capturer for device " DLOG(WARNING) << "Failed to create the capturer for device "
<< device_info.device.id; << device_info.device.id;
sources_created.Run(web_stream, false); sources_created.Run(web_stream, false);
// TODO(xians): Don't we need to check if source_observer is observing
// something? If not, then it looks like we have a leak here.
// OTOH, if it _is_ observing something, then the callback might
// be called multiple times which is likely also a bug.
return; return;
} }
...@@ -390,12 +383,16 @@ bool MediaStreamDependencyFactory::AddNativeMediaStreamTrack( ...@@ -390,12 +383,16 @@ bool MediaStreamDependencyFactory::AddNativeMediaStreamTrack(
MediaStreamSourceExtraData* source_data = MediaStreamSourceExtraData* source_data =
static_cast<MediaStreamSourceExtraData*>(source.extraData()); static_cast<MediaStreamSourceExtraData*>(source.extraData());
// In the future the constraints will belong to the track itself, but
// right now they're on the source, so we fetch them from there.
RTCMediaConstraints track_constraints(source.constraints());
scoped_refptr<WebRtcAudioCapturer> capturer; scoped_refptr<WebRtcAudioCapturer> capturer;
if (!source_data) { if (!source_data) {
if (source.requiresAudioConsumer()) { if (source.requiresAudioConsumer()) {
// We're adding a WebAudio MediaStream. // We're adding a WebAudio MediaStream.
// Create a specific capturer for each WebAudio consumer. // Create a specific capturer for each WebAudio consumer.
capturer = CreateWebAudioSource(&source); capturer = CreateWebAudioSource(&source, &track_constraints);
source_data = source_data =
static_cast<MediaStreamSourceExtraData*>(source.extraData()); static_cast<MediaStreamSourceExtraData*>(source.extraData());
} else { } else {
...@@ -418,7 +415,8 @@ bool MediaStreamDependencyFactory::AddNativeMediaStreamTrack( ...@@ -418,7 +415,8 @@ bool MediaStreamDependencyFactory::AddNativeMediaStreamTrack(
scoped_refptr<webrtc::AudioTrackInterface> audio_track( scoped_refptr<webrtc::AudioTrackInterface> audio_track(
CreateLocalAudioTrack(track_id, CreateLocalAudioTrack(track_id,
capturer, capturer,
source_data->local_audio_source())); source_data->local_audio_source(),
&track_constraints));
audio_track->set_enabled(track.isEnabled()); audio_track->set_enabled(track.isEnabled());
return native_stream->AddTrack(audio_track.get()); return native_stream->AddTrack(audio_track.get());
} else { } else {
...@@ -598,7 +596,8 @@ MediaStreamDependencyFactory::CreateLocalVideoSource( ...@@ -598,7 +596,8 @@ MediaStreamDependencyFactory::CreateLocalVideoSource(
scoped_refptr<WebRtcAudioCapturer> scoped_refptr<WebRtcAudioCapturer>
MediaStreamDependencyFactory::CreateWebAudioSource( MediaStreamDependencyFactory::CreateWebAudioSource(
WebKit::WebMediaStreamSource* source) { WebKit::WebMediaStreamSource* source,
RTCMediaConstraints* constraints) {
DVLOG(1) << "MediaStreamDependencyFactory::CreateWebAudioSource()"; DVLOG(1) << "MediaStreamDependencyFactory::CreateWebAudioSource()";
DCHECK(GetWebRtcAudioDevice()); DCHECK(GetWebRtcAudioDevice());
...@@ -621,9 +620,8 @@ MediaStreamDependencyFactory::CreateWebAudioSource( ...@@ -621,9 +620,8 @@ MediaStreamDependencyFactory::CreateWebAudioSource(
// echo cancellation, automatic gain control, noise suppression and // echo cancellation, automatic gain control, noise suppression and
// high-pass filter. SetLocalAudioSource() affects core audio parts in // high-pass filter. SetLocalAudioSource() affects core audio parts in
// third_party/Libjingle. // third_party/Libjingle.
WebAudioConstraints webaudio_audio_constraints_all_true; ApplyFixedWebAudioConstraints(constraints);
source_data->SetLocalAudioSource( source_data->SetLocalAudioSource(CreateLocalAudioSource(constraints).get());
CreateLocalAudioSource(&webaudio_audio_constraints_all_true).get());
source->setExtraData(source_data); source->setExtraData(source_data);
// Replace the default source with WebAudio as source instead. // Replace the default source with WebAudio as source instead.
...@@ -659,12 +657,13 @@ scoped_refptr<webrtc::AudioTrackInterface> ...@@ -659,12 +657,13 @@ scoped_refptr<webrtc::AudioTrackInterface>
MediaStreamDependencyFactory::CreateLocalAudioTrack( MediaStreamDependencyFactory::CreateLocalAudioTrack(
const std::string& id, const std::string& id,
const scoped_refptr<WebRtcAudioCapturer>& capturer, const scoped_refptr<WebRtcAudioCapturer>& capturer,
webrtc::AudioSourceInterface* source) { webrtc::AudioSourceInterface* source,
const webrtc::MediaConstraintsInterface* constraints) {
// TODO(xians): Merge |source| to the capturer(). We can't do this today // TODO(xians): Merge |source| to the capturer(). We can't do this today
// because only one capturer() is supported while one |source| is created // because only one capturer() is supported while one |source| is created
// for each audio track. // for each audio track.
scoped_refptr<WebRtcLocalAudioTrack> audio_track( scoped_refptr<WebRtcLocalAudioTrack> audio_track(
WebRtcLocalAudioTrack::Create(id, capturer, source)); WebRtcLocalAudioTrack::Create(id, capturer, source, constraints));
// Add the WebRtcAudioDevice as the sink to the local audio track. // Add the WebRtcAudioDevice as the sink to the local audio track.
audio_track->AddSink(GetWebRtcAudioDevice()); audio_track->AddSink(GetWebRtcAudioDevice());
// Start the audio track. This will hook the |audio_track| to the capturer // Start the audio track. This will hook the |audio_track| to the capturer
......
...@@ -42,6 +42,7 @@ namespace content { ...@@ -42,6 +42,7 @@ namespace content {
class IpcNetworkManager; class IpcNetworkManager;
class IpcPacketSocketFactory; class IpcPacketSocketFactory;
class RTCMediaConstraints;
class VideoCaptureImplManager; class VideoCaptureImplManager;
class WebRtcAudioCapturer; class WebRtcAudioCapturer;
class WebRtcAudioDeviceImpl; class WebRtcAudioDeviceImpl;
...@@ -161,14 +162,19 @@ class CONTENT_EXPORT MediaStreamDependencyFactory ...@@ -161,14 +162,19 @@ class CONTENT_EXPORT MediaStreamDependencyFactory
// specific for a WebAudio source. The created WebAudioCapturerSource // specific for a WebAudio source. The created WebAudioCapturerSource
// instance will function as audio source instead of the default // instance will function as audio source instead of the default
// WebRtcAudioCapturer. // WebRtcAudioCapturer.
// The |constraints| will be modified to include the default, mandatory
// WebAudio constraints.
virtual scoped_refptr<WebRtcAudioCapturer> CreateWebAudioSource( virtual scoped_refptr<WebRtcAudioCapturer> CreateWebAudioSource(
WebKit::WebMediaStreamSource* source); WebKit::WebMediaStreamSource* source,
RTCMediaConstraints* constraints);
// Asks the PeerConnection factory to create a Local AudioTrack object. // Asks the PeerConnection factory to create a Local AudioTrack object.
virtual scoped_refptr<webrtc::AudioTrackInterface> virtual scoped_refptr<webrtc::AudioTrackInterface>
CreateLocalAudioTrack(const std::string& id, CreateLocalAudioTrack(
const scoped_refptr<WebRtcAudioCapturer>& capturer, const std::string& id,
webrtc::AudioSourceInterface* source); const scoped_refptr<WebRtcAudioCapturer>& capturer,
webrtc::AudioSourceInterface* source,
const webrtc::MediaConstraintsInterface* constraints);
// Asks the PeerConnection factory to create a Local VideoTrack object. // Asks the PeerConnection factory to create a Local VideoTrack object.
virtual scoped_refptr<webrtc::VideoTrackInterface> virtual scoped_refptr<webrtc::VideoTrackInterface>
......
...@@ -408,7 +408,8 @@ MockMediaStreamDependencyFactory::CreateLocalVideoSource( ...@@ -408,7 +408,8 @@ MockMediaStreamDependencyFactory::CreateLocalVideoSource(
scoped_refptr<WebRtcAudioCapturer> scoped_refptr<WebRtcAudioCapturer>
MockMediaStreamDependencyFactory::CreateWebAudioSource( MockMediaStreamDependencyFactory::CreateWebAudioSource(
WebKit::WebMediaStreamSource* source) { WebKit::WebMediaStreamSource* source,
RTCMediaConstraints* constraints) {
return NULL; return NULL;
} }
...@@ -447,11 +448,12 @@ scoped_refptr<webrtc::AudioTrackInterface> ...@@ -447,11 +448,12 @@ scoped_refptr<webrtc::AudioTrackInterface>
MockMediaStreamDependencyFactory::CreateLocalAudioTrack( MockMediaStreamDependencyFactory::CreateLocalAudioTrack(
const std::string& id, const std::string& id,
const scoped_refptr<WebRtcAudioCapturer>& capturer, const scoped_refptr<WebRtcAudioCapturer>& capturer,
webrtc::AudioSourceInterface* source) { webrtc::AudioSourceInterface* source,
const webrtc::MediaConstraintsInterface* constraints) {
DCHECK(mock_pc_factory_created_); DCHECK(mock_pc_factory_created_);
DCHECK(!capturer.get()); DCHECK(!capturer.get());
return WebRtcLocalAudioTrack::Create( return WebRtcLocalAudioTrack::Create(
id, WebRtcAudioCapturer::CreateCapturer(), source); id, WebRtcAudioCapturer::CreateCapturer(), source, constraints);
} }
SessionDescriptionInterface* SessionDescriptionInterface*
......
...@@ -127,7 +127,8 @@ class MockMediaStreamDependencyFactory : public MediaStreamDependencyFactory { ...@@ -127,7 +127,8 @@ class MockMediaStreamDependencyFactory : public MediaStreamDependencyFactory {
bool is_screencast, bool is_screencast,
const webrtc::MediaConstraintsInterface* constraints) OVERRIDE; const webrtc::MediaConstraintsInterface* constraints) OVERRIDE;
virtual scoped_refptr<WebRtcAudioCapturer> CreateWebAudioSource( virtual scoped_refptr<WebRtcAudioCapturer> CreateWebAudioSource(
WebKit::WebMediaStreamSource* source) OVERRIDE; WebKit::WebMediaStreamSource* source,
RTCMediaConstraints* constraints) OVERRIDE;
virtual scoped_refptr<webrtc::MediaStreamInterface> virtual scoped_refptr<webrtc::MediaStreamInterface>
CreateLocalMediaStream(const std::string& label) OVERRIDE; CreateLocalMediaStream(const std::string& label) OVERRIDE;
virtual scoped_refptr<webrtc::VideoTrackInterface> virtual scoped_refptr<webrtc::VideoTrackInterface>
...@@ -136,10 +137,11 @@ class MockMediaStreamDependencyFactory : public MediaStreamDependencyFactory { ...@@ -136,10 +137,11 @@ class MockMediaStreamDependencyFactory : public MediaStreamDependencyFactory {
virtual scoped_refptr<webrtc::VideoTrackInterface> virtual scoped_refptr<webrtc::VideoTrackInterface>
CreateLocalVideoTrack(const std::string& id, CreateLocalVideoTrack(const std::string& id,
cricket::VideoCapturer* capturer) OVERRIDE; cricket::VideoCapturer* capturer) OVERRIDE;
virtual scoped_refptr<webrtc::AudioTrackInterface> virtual scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack(
CreateLocalAudioTrack(const std::string& id, const std::string& id,
const scoped_refptr<WebRtcAudioCapturer>& capturer, const scoped_refptr<WebRtcAudioCapturer>& capturer,
webrtc::AudioSourceInterface* source) OVERRIDE; webrtc::AudioSourceInterface* source,
const webrtc::MediaConstraintsInterface* constraints) OVERRIDE;
virtual webrtc::SessionDescriptionInterface* CreateSessionDescription( virtual webrtc::SessionDescriptionInterface* CreateSessionDescription(
const std::string& type, const std::string& type,
const std::string& sdp, const std::string& sdp,
......
...@@ -42,6 +42,8 @@ void GetNativeMediaConstraints( ...@@ -42,6 +42,8 @@ void GetNativeMediaConstraints(
} // namespace } // namespace
RTCMediaConstraints::RTCMediaConstraints() {}
RTCMediaConstraints::RTCMediaConstraints( RTCMediaConstraints::RTCMediaConstraints(
const WebKit::WebMediaConstraints& constraints) { const WebKit::WebMediaConstraints& constraints) {
if (constraints.isNull()) if (constraints.isNull())
...@@ -71,4 +73,21 @@ void RTCMediaConstraints::AddOptional(const std::string& key, ...@@ -71,4 +73,21 @@ void RTCMediaConstraints::AddOptional(const std::string& key,
optional_.push_back(Constraint(key, value)); optional_.push_back(Constraint(key, value));
} }
bool RTCMediaConstraints::AddMandatory(const std::string& key,
const std::string& value,
bool override_if_exists) {
for (Constraints::iterator iter = mandatory_.begin();
iter != mandatory_.end();
++iter) {
if (iter->key == key) {
if (override_if_exists)
iter->value = value;
return override_if_exists;
}
}
// The key wasn't found, add it.
mandatory_.push_back(Constraint(key, value));
return true;
}
} // namespace content } // namespace content
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define CONTENT_RENDERER_MEDIA_RTC_MEDIA_CONSTRAINTS_H_ #define CONTENT_RENDERER_MEDIA_RTC_MEDIA_CONSTRAINTS_H_
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "content/common/content_export.h"
#include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface.h" #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface.h"
namespace WebKit { namespace WebKit {
...@@ -17,14 +18,21 @@ namespace content { ...@@ -17,14 +18,21 @@ namespace content {
// RTCMediaConstraints acts as a glue layer between WebKits MediaConstraints and // RTCMediaConstraints acts as a glue layer between WebKits MediaConstraints and
// libjingle webrtc::MediaConstraintsInterface. // libjingle webrtc::MediaConstraintsInterface.
// Constraints are used by PeerConnection and getUserMedia API calls. // Constraints are used by PeerConnection and getUserMedia API calls.
class RTCMediaConstraints : public webrtc::MediaConstraintsInterface { class CONTENT_EXPORT RTCMediaConstraints
: public NON_EXPORTED_BASE(webrtc::MediaConstraintsInterface) {
public: public:
RTCMediaConstraints();
explicit RTCMediaConstraints( explicit RTCMediaConstraints(
const WebKit::WebMediaConstraints& constraints); const WebKit::WebMediaConstraints& constraints);
virtual ~RTCMediaConstraints(); virtual ~RTCMediaConstraints();
virtual const Constraints& GetMandatory() const OVERRIDE; virtual const Constraints& GetMandatory() const OVERRIDE;
virtual const Constraints& GetOptional() const OVERRIDE; virtual const Constraints& GetOptional() const OVERRIDE;
void AddOptional(const std::string& key, const std::string& value); void AddOptional(const std::string& key, const std::string& value);
// Adds a mandatory constraint, optionally overriding an existing one.
// If the constraint is already set and |override_if_exists| is false,
// the function will return false, otherwise true.
bool AddMandatory(const std::string& key, const std::string& value,
bool override_if_exists);
protected: protected:
Constraints mandatory_; Constraints mandatory_;
......
...@@ -250,10 +250,11 @@ class RTCPeerConnectionHandlerTest : public ::testing::Test { ...@@ -250,10 +250,11 @@ class RTCPeerConnectionHandlerTest : public ::testing::Test {
local_stream.audioTracks(audio_tracks); local_stream.audioTracks(audio_tracks);
const std::string audio_track_id = UTF16ToUTF8(audio_tracks[0].id()); const std::string audio_track_id = UTF16ToUTF8(audio_tracks[0].id());
scoped_refptr<WebRtcAudioCapturer> capturer; scoped_refptr<WebRtcAudioCapturer> capturer;
RTCMediaConstraints audio_constraints(audio_source.constraints());
scoped_refptr<webrtc::AudioTrackInterface> audio_track( scoped_refptr<webrtc::AudioTrackInterface> audio_track(
mock_dependency_factory_->CreateLocalAudioTrack(audio_track_id, mock_dependency_factory_->CreateLocalAudioTrack(
capturer, audio_track_id, capturer, NULL,
NULL)); &audio_constraints));
native_stream->AddTrack(audio_track.get()); native_stream->AddTrack(audio_track.get());
local_stream.videoTracks(video_tracks); local_stream.videoTracks(video_tracks);
...@@ -289,6 +290,7 @@ class RTCPeerConnectionHandlerTest : public ::testing::Test { ...@@ -289,6 +290,7 @@ class RTCPeerConnectionHandlerTest : public ::testing::Test {
scoped_refptr<webrtc::AudioTrackInterface> audio_track( scoped_refptr<webrtc::AudioTrackInterface> audio_track(
mock_dependency_factory_->CreateLocalAudioTrack(audio_track_label, mock_dependency_factory_->CreateLocalAudioTrack(audio_track_label,
capturer, capturer,
NULL,
NULL)); NULL));
stream->AddTrack(audio_track.get()); stream->AddTrack(audio_track.get());
} }
......
...@@ -137,7 +137,7 @@ scoped_refptr<WebRtcLocalAudioTrack> ...@@ -137,7 +137,7 @@ scoped_refptr<WebRtcLocalAudioTrack>
CreateAndStartLocalAudioTrack(WebRtcAudioCapturer* capturer, CreateAndStartLocalAudioTrack(WebRtcAudioCapturer* capturer,
WebRtcAudioCapturerSink* sink) { WebRtcAudioCapturerSink* sink) {
scoped_refptr<WebRtcLocalAudioTrack> local_audio_track( scoped_refptr<WebRtcLocalAudioTrack> local_audio_track(
WebRtcLocalAudioTrack::Create(std::string(), capturer, NULL)); WebRtcLocalAudioTrack::Create(std::string(), capturer, NULL, NULL));
local_audio_track->AddSink(sink); local_audio_track->AddSink(sink);
local_audio_track->Start(); local_audio_track->Start();
return local_audio_track; return local_audio_track;
......
...@@ -12,34 +12,65 @@ namespace content { ...@@ -12,34 +12,65 @@ namespace content {
static const char kAudioTrackKind[] = "audio"; static const char kAudioTrackKind[] = "audio";
namespace {
using webrtc::MediaConstraintsInterface;
// This helper function checks if any audio constraints are set that require
// audio processing to be applied. Right now this is a big, single switch for
// all of the properties, but in the future they'll be handled one by one.
bool NeedsAudioProcessing(
const webrtc::MediaConstraintsInterface* constraints) {
if (!constraints)
return false;
static const char* kAudioProcessingProperties[] = {
MediaConstraintsInterface::kEchoCancellation,
MediaConstraintsInterface::kExperimentalEchoCancellation,
MediaConstraintsInterface::kAutoGainControl,
MediaConstraintsInterface::kExperimentalAutoGainControl,
MediaConstraintsInterface::kNoiseSuppression,
MediaConstraintsInterface::kHighpassFilter,
};
for (size_t i = 0; i < arraysize(kAudioProcessingProperties); ++i) {
bool value = false;
if (webrtc::FindConstraint(constraints, kAudioProcessingProperties[i],
&value, NULL) &&
value) {
return true;
}
}
return false;
}
} // namespace.
scoped_refptr<WebRtcLocalAudioTrack> WebRtcLocalAudioTrack::Create( scoped_refptr<WebRtcLocalAudioTrack> WebRtcLocalAudioTrack::Create(
const std::string& id, const std::string& id,
const scoped_refptr<WebRtcAudioCapturer>& capturer, const scoped_refptr<WebRtcAudioCapturer>& capturer,
webrtc::AudioSourceInterface* track_source) { webrtc::AudioSourceInterface* track_source,
const webrtc::MediaConstraintsInterface* constraints) {
talk_base::RefCountedObject<WebRtcLocalAudioTrack>* track = talk_base::RefCountedObject<WebRtcLocalAudioTrack>* track =
new talk_base::RefCountedObject<WebRtcLocalAudioTrack>( new talk_base::RefCountedObject<WebRtcLocalAudioTrack>(
id, capturer, track_source); id, capturer, track_source, constraints);
return track; return track;
} }
WebRtcLocalAudioTrack::WebRtcLocalAudioTrack( WebRtcLocalAudioTrack::WebRtcLocalAudioTrack(
const std::string& label, const std::string& label,
const scoped_refptr<WebRtcAudioCapturer>& capturer, const scoped_refptr<WebRtcAudioCapturer>& capturer,
webrtc::AudioSourceInterface* track_source) webrtc::AudioSourceInterface* track_source,
const webrtc::MediaConstraintsInterface* constraints)
: webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>(label), : webrtc::MediaStreamTrack<webrtc::AudioTrackInterface>(label),
capturer_(capturer), capturer_(capturer),
track_source_(track_source), track_source_(track_source),
need_audio_processing_(!capturer->device_id().empty()) { need_audio_processing_(NeedsAudioProcessing(constraints)) {
// The capturer with a valid device id is using microphone as source, // The capturer with a valid device id is using microphone as source,
// and APM (AudioProcessingModule) is turned on only for microphone data. // and APM (AudioProcessingModule) is turned on only for microphone data.
DCHECK(capturer.get()); DCHECK(capturer.get());
DVLOG(1) << "WebRtcLocalAudioTrack::WebRtcLocalAudioTrack()"; DVLOG(1) << "WebRtcLocalAudioTrack::WebRtcLocalAudioTrack()";
// TODO(tommi): Remove this, feed audio constraints to WebRtcLocalAudioTrack
// and check the constraints. This is here to fix a recent regression whereby
// audio processing is not enabled for WebAudio regardless of the hard coded
// audio constraints. For more info: http://crbug.com/277134
need_audio_processing_ = true;
} }
WebRtcLocalAudioTrack::~WebRtcLocalAudioTrack() { WebRtcLocalAudioTrack::~WebRtcLocalAudioTrack() {
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "content/renderer/media/webrtc_audio_device_impl.h" #include "content/renderer/media/webrtc_audio_device_impl.h"
#include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface.h"
#include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.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/app/webrtc/mediastreamtrack.h"
#include "third_party/libjingle/source/talk/media/base/audiorenderer.h" #include "third_party/libjingle/source/talk/media/base/audiorenderer.h"
...@@ -37,7 +38,8 @@ class CONTENT_EXPORT WebRtcLocalAudioTrack ...@@ -37,7 +38,8 @@ class CONTENT_EXPORT WebRtcLocalAudioTrack
static scoped_refptr<WebRtcLocalAudioTrack> Create( static scoped_refptr<WebRtcLocalAudioTrack> Create(
const std::string& id, const std::string& id,
const scoped_refptr<WebRtcAudioCapturer>& capturer, const scoped_refptr<WebRtcAudioCapturer>& capturer,
webrtc::AudioSourceInterface* stream_source); webrtc::AudioSourceInterface* stream_source,
const webrtc::MediaConstraintsInterface* constraints);
// Add a sink to the track. This function will trigger a SetCaptureFormat() // Add a sink to the track. This function will trigger a SetCaptureFormat()
// call on the |sink|. // call on the |sink|.
...@@ -72,7 +74,8 @@ class CONTENT_EXPORT WebRtcLocalAudioTrack ...@@ -72,7 +74,8 @@ class CONTENT_EXPORT WebRtcLocalAudioTrack
protected: protected:
WebRtcLocalAudioTrack(const std::string& label, WebRtcLocalAudioTrack(const std::string& label,
const scoped_refptr<WebRtcAudioCapturer>& capturer, const scoped_refptr<WebRtcAudioCapturer>& capturer,
webrtc::AudioSourceInterface* track_source); webrtc::AudioSourceInterface* track_source,
const webrtc::MediaConstraintsInterface* constraints);
virtual ~WebRtcLocalAudioTrack(); virtual ~WebRtcLocalAudioTrack();
private: private:
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/test/test_timeouts.h" #include "base/test/test_timeouts.h"
#include "content/renderer/media/rtc_media_constraints.h"
#include "content/renderer/media/webrtc_audio_capturer.h" #include "content/renderer/media/webrtc_audio_capturer.h"
#include "content/renderer/media/webrtc_local_audio_track.h" #include "content/renderer/media/webrtc_local_audio_track.h"
#include "media/audio/audio_parameters.h" #include "media/audio/audio_parameters.h"
...@@ -164,8 +165,10 @@ class WebRtcLocalAudioTrackTest : public ::testing::Test { ...@@ -164,8 +165,10 @@ class WebRtcLocalAudioTrackTest : public ::testing::Test {
// the track is disconnected from the capturer. // the track is disconnected from the capturer.
TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) { TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) {
EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return());
RTCMediaConstraints constraints;
scoped_refptr<WebRtcLocalAudioTrack> track = scoped_refptr<WebRtcLocalAudioTrack> track =
WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL,
&constraints);
track->Start(); track->Start();
EXPECT_TRUE(track->enabled()); EXPECT_TRUE(track->enabled());
...@@ -187,8 +190,7 @@ TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) { ...@@ -187,8 +190,7 @@ TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) {
params.frames_per_buffer(), params.frames_per_buffer(),
0, 0,
0, 0,
// TODO(tommi): Change to |false| when issue 277134 is fixed. false,
_,
false)).Times(AtLeast(1)) false)).Times(AtLeast(1))
.WillRepeatedly(SignalEvent(&event)); .WillRepeatedly(SignalEvent(&event));
track->AddSink(sink.get()); track->AddSink(sink.get());
...@@ -209,8 +211,10 @@ TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) { ...@@ -209,8 +211,10 @@ TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) {
// reports on MediaStreamTrack::enabled(); // reports on MediaStreamTrack::enabled();
TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) { TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) {
EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return());
RTCMediaConstraints constraints;
scoped_refptr<WebRtcLocalAudioTrack> track = scoped_refptr<WebRtcLocalAudioTrack> track =
WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL,
&constraints);
track->Start(); track->Start();
static_cast<webrtc::AudioTrackInterface*>(track.get())-> static_cast<webrtc::AudioTrackInterface*>(track.get())->
GetRenderer()->AddChannel(0); GetRenderer()->AddChannel(0);
...@@ -257,8 +261,10 @@ TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) { ...@@ -257,8 +261,10 @@ TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) {
// callbacks appear/disappear. // callbacks appear/disappear.
TEST_F(WebRtcLocalAudioTrackTest, MultipleAudioTracks) { TEST_F(WebRtcLocalAudioTrackTest, MultipleAudioTracks) {
EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return());
RTCMediaConstraints constraints;
scoped_refptr<WebRtcLocalAudioTrack> track_1 = scoped_refptr<WebRtcLocalAudioTrack> track_1 =
WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL,
&constraints);
track_1->Start(); track_1->Start();
static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> static_cast<webrtc::AudioTrackInterface*>(track_1.get())->
GetRenderer()->AddChannel(0); GetRenderer()->AddChannel(0);
...@@ -275,15 +281,15 @@ TEST_F(WebRtcLocalAudioTrackTest, MultipleAudioTracks) { ...@@ -275,15 +281,15 @@ TEST_F(WebRtcLocalAudioTrackTest, MultipleAudioTracks) {
params.frames_per_buffer(), params.frames_per_buffer(),
0, 0,
0, 0,
// TODO(tommi): Change to |false| when issue 277134 is fixed. false,
_,
false)).Times(AtLeast(1)) false)).Times(AtLeast(1))
.WillRepeatedly(SignalEvent(&event_1)); .WillRepeatedly(SignalEvent(&event_1));
track_1->AddSink(sink_1.get()); track_1->AddSink(sink_1.get());
EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout()));
scoped_refptr<WebRtcLocalAudioTrack> track_2 = scoped_refptr<WebRtcLocalAudioTrack> track_2 =
WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL,
&constraints);
track_2->Start(); track_2->Start();
static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> static_cast<webrtc::AudioTrackInterface*>(track_2.get())->
GetRenderer()->AddChannel(1); GetRenderer()->AddChannel(1);
...@@ -303,8 +309,7 @@ TEST_F(WebRtcLocalAudioTrackTest, MultipleAudioTracks) { ...@@ -303,8 +309,7 @@ TEST_F(WebRtcLocalAudioTrackTest, MultipleAudioTracks) {
params.frames_per_buffer(), params.frames_per_buffer(),
0, 0,
0, 0,
// TODO(tommi): Change to |false| when issue 277134 is fixed. false,
_,
false)).Times(AtLeast(1)) false)).Times(AtLeast(1))
.WillRepeatedly(SignalEvent(&event_1)); .WillRepeatedly(SignalEvent(&event_1));
EXPECT_CALL(*sink_2, EXPECT_CALL(*sink_2,
...@@ -314,8 +319,7 @@ TEST_F(WebRtcLocalAudioTrackTest, MultipleAudioTracks) { ...@@ -314,8 +319,7 @@ TEST_F(WebRtcLocalAudioTrackTest, MultipleAudioTracks) {
params.frames_per_buffer(), params.frames_per_buffer(),
0, 0,
0, 0,
// TODO(tommi): Change to |false| when issue 277134 is fixed. false,
_,
false)).Times(AtLeast(1)) false)).Times(AtLeast(1))
.WillRepeatedly(SignalEvent(&event_2)); .WillRepeatedly(SignalEvent(&event_2));
track_2->AddSink(sink_2.get()); track_2->AddSink(sink_2.get());
...@@ -337,8 +341,10 @@ TEST_F(WebRtcLocalAudioTrackTest, MultipleAudioTracks) { ...@@ -337,8 +341,10 @@ TEST_F(WebRtcLocalAudioTrackTest, MultipleAudioTracks) {
// And it should be fine to not to call Stop() explicitly. // And it should be fine to not to call Stop() explicitly.
TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) { TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) {
EXPECT_CALL(*capturer_source_.get(), Start()).Times(1); EXPECT_CALL(*capturer_source_.get(), Start()).Times(1);
RTCMediaConstraints constraints;
scoped_refptr<WebRtcLocalAudioTrack> track = scoped_refptr<WebRtcLocalAudioTrack> track =
WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL,
&constraints);
track->Start(); track->Start();
// When the track goes away, it will automatically stop the // When the track goes away, it will automatically stop the
...@@ -354,8 +360,10 @@ TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { ...@@ -354,8 +360,10 @@ TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) {
// Starting the first audio track will start the |capturer_source_|. // Starting the first audio track will start the |capturer_source_|.
base::WaitableEvent event(false, false); base::WaitableEvent event(false, false);
EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(SignalEvent(&event)); EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(SignalEvent(&event));
RTCMediaConstraints constraints;
scoped_refptr<WebRtcLocalAudioTrack> track_1 = scoped_refptr<WebRtcLocalAudioTrack> track_1 =
WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL,
&constraints);
static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> static_cast<webrtc::AudioTrackInterface*>(track_1.get())->
GetRenderer()->AddChannel(0); GetRenderer()->AddChannel(0);
track_1->Start(); track_1->Start();
...@@ -365,10 +373,7 @@ TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { ...@@ -365,10 +373,7 @@ TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) {
scoped_ptr<MockWebRtcAudioCapturerSink> sink( scoped_ptr<MockWebRtcAudioCapturerSink> sink(
new MockWebRtcAudioCapturerSink()); new MockWebRtcAudioCapturerSink());
event.Reset(); event.Reset();
EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, false, false))
// TODO(tommi): Change to |false| when issue 277134 is fixed.
_,
false))
.Times(AnyNumber()).WillRepeatedly(Return()); .Times(AnyNumber()).WillRepeatedly(Return());
EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1); EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1);
track_1->AddSink(sink.get()); track_1->AddSink(sink.get());
...@@ -377,7 +382,8 @@ TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { ...@@ -377,7 +382,8 @@ TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) {
// since it has been started. // since it has been started.
EXPECT_CALL(*capturer_source_.get(), Start()).Times(0); EXPECT_CALL(*capturer_source_.get(), Start()).Times(0);
scoped_refptr<WebRtcLocalAudioTrack> track_2 = scoped_refptr<WebRtcLocalAudioTrack> track_2 =
WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL,
&constraints);
track_2->Start(); track_2->Start();
static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> static_cast<webrtc::AudioTrackInterface*>(track_2.get())->
GetRenderer()->AddChannel(1); GetRenderer()->AddChannel(1);
...@@ -407,8 +413,10 @@ TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { ...@@ -407,8 +413,10 @@ TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) {
TEST_F(WebRtcLocalAudioTrackTest, SetNewSourceForCapturerAfterStartTrack) { TEST_F(WebRtcLocalAudioTrackTest, SetNewSourceForCapturerAfterStartTrack) {
// Setup the audio track and start the track. // Setup the audio track and start the track.
EXPECT_CALL(*capturer_source_.get(), Start()).Times(1); EXPECT_CALL(*capturer_source_.get(), Start()).Times(1);
RTCMediaConstraints constraints;
scoped_refptr<WebRtcLocalAudioTrack> track = scoped_refptr<WebRtcLocalAudioTrack> track =
WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL,
&constraints);
track->Start(); track->Start();
// Setting new source to the capturer and the track should still get packets. // Setting new source to the capturer and the track should still get packets.
...@@ -432,8 +440,10 @@ TEST_F(WebRtcLocalAudioTrackTest, SetNewSourceForCapturerAfterStartTrack) { ...@@ -432,8 +440,10 @@ TEST_F(WebRtcLocalAudioTrackTest, SetNewSourceForCapturerAfterStartTrack) {
TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) { TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) {
// Setup the first audio track and start it. // Setup the first audio track and start it.
EXPECT_CALL(*capturer_source_.get(), Start()).Times(1); EXPECT_CALL(*capturer_source_.get(), Start()).Times(1);
RTCMediaConstraints constraints;
scoped_refptr<WebRtcLocalAudioTrack> track_1 = scoped_refptr<WebRtcLocalAudioTrack> track_1 =
WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL,
&constraints);
track_1->Start(); track_1->Start();
// Connect a number of network channels to the |track_1|. // Connect a number of network channels to the |track_1|.
...@@ -448,10 +458,7 @@ TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) { ...@@ -448,10 +458,7 @@ TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) {
EXPECT_CALL( EXPECT_CALL(
*sink_1.get(), *sink_1.get(),
CaptureData( CaptureData(
kNumberOfNetworkChannelsForTrack1, 48000, 2, _, 0, 0, kNumberOfNetworkChannelsForTrack1, 48000, 2, _, 0, 0, false, false))
// TODO(tommi): Change to |false| when issue 277134 is fixed.
_,
false))
.Times(AnyNumber()).WillRepeatedly(Return()); .Times(AnyNumber()).WillRepeatedly(Return());
EXPECT_CALL(*sink_1.get(), SetCaptureFormat(_)).Times(1); EXPECT_CALL(*sink_1.get(), SetCaptureFormat(_)).Times(1);
track_1->AddSink(sink_1.get()); track_1->AddSink(sink_1.get());
...@@ -475,7 +482,8 @@ TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) { ...@@ -475,7 +482,8 @@ TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) {
// Setup the second audio track, connect it to the new capturer and start it. // Setup the second audio track, connect it to the new capturer and start it.
EXPECT_CALL(*new_source.get(), Start()).Times(1); EXPECT_CALL(*new_source.get(), Start()).Times(1);
scoped_refptr<WebRtcLocalAudioTrack> track_2 = scoped_refptr<WebRtcLocalAudioTrack> track_2 =
WebRtcLocalAudioTrack::Create(std::string(), new_capturer, NULL); WebRtcLocalAudioTrack::Create(std::string(), new_capturer, NULL,
&constraints);
track_2->Start(); track_2->Start();
// Connect a number of network channels to the |track_2|. // Connect a number of network channels to the |track_2|.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment