Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5715)

Unified Diff: content/renderer/media/media_stream_audio_processor_unittest.cc

Issue 227743004: Added a kEchoCancellation constraint to turn off the audio processing. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: moved some of the constraints code to MediaAudioConstraints class, and hope it makes the code more … Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/media/media_stream_audio_processor_unittest.cc
diff --git a/content/renderer/media/media_stream_audio_processor_unittest.cc b/content/renderer/media/media_stream_audio_processor_unittest.cc
index ba938a6d019adcf101f9d03f4df938520dff8d2b..eb1a06e1a6291f3ce9e45acf93907db7856e7077 100644
--- a/content/renderer/media/media_stream_audio_processor_unittest.cc
+++ b/content/renderer/media/media_stream_audio_processor_unittest.cc
@@ -11,6 +11,7 @@
#include "content/public/common/content_switches.h"
#include "content/public/common/media_stream_request.h"
#include "content/renderer/media/media_stream_audio_processor.h"
+#include "content/renderer/media/media_stream_audio_processor_options.h"
#include "content/renderer/media/mock_media_constraint_factory.h"
#include "media/audio/audio_parameters.h"
#include "media/base/audio_bus.h"
@@ -153,12 +154,12 @@ class MediaStreamAudioProcessorTest : public ::testing::Test {
TEST_F(MediaStreamAudioProcessorTest, WithoutAudioProcessing) {
// Setup the audio processor without enabling the flag.
- blink::WebMediaConstraints constraints;
+ MockMediaConstraintFactory constraint_factory;
scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
new WebRtcAudioDeviceImpl());
scoped_refptr<MediaStreamAudioProcessor> audio_processor(
new talk_base::RefCountedObject<MediaStreamAudioProcessor>(
- constraints, 0, MEDIA_DEVICE_AUDIO_CAPTURE,
+ constraint_factory.CreateWebMediaConstraints(), 0,
webrtc_audio_device.get()));
EXPECT_FALSE(audio_processor->has_audio_processing());
audio_processor->OnCaptureFormatChanged(params_);
@@ -176,12 +177,12 @@ TEST_F(MediaStreamAudioProcessorTest, WithAudioProcessing) {
// Setup the audio processor with the flag enabled.
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableAudioTrackProcessing);
- blink::WebMediaConstraints constraints;
+ MockMediaConstraintFactory constraint_factory;
scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
new WebRtcAudioDeviceImpl());
scoped_refptr<MediaStreamAudioProcessor> audio_processor(
new talk_base::RefCountedObject<MediaStreamAudioProcessor>(
- constraints, 0, MEDIA_DEVICE_AUDIO_CAPTURE,
+ constraint_factory.CreateWebMediaConstraints(), 0,
webrtc_audio_device.get()));
EXPECT_TRUE(audio_processor->has_audio_processing());
audio_processor->OnCaptureFormatChanged(params_);
@@ -200,13 +201,15 @@ TEST_F(MediaStreamAudioProcessorTest, VerifyTabCaptureWithoutAudioProcessing) {
// Setup the audio processor with enabling the flag.
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableAudioTrackProcessing);
- blink::WebMediaConstraints constraints;
scoped_refptr<WebRtcAudioDeviceImpl> webrtc_audio_device(
new WebRtcAudioDeviceImpl());
- // Create MediaStreamAudioProcessor instance for MEDIA_TAB_AUDIO_CAPTURE type.
+ // Create MediaStreamAudioProcessor instance for kMediaStreamSourceTab source.
+ MockMediaConstraintFactory tab_constraint_factory;
+ tab_constraint_factory.AddMandatory(kMediaStreamSource,
+ kMediaStreamSourceTab);
scoped_refptr<MediaStreamAudioProcessor> audio_processor(
new talk_base::RefCountedObject<MediaStreamAudioProcessor>(
- constraints, 0, MEDIA_TAB_AUDIO_CAPTURE,
+ tab_constraint_factory.CreateWebMediaConstraints(), 0,
webrtc_audio_device.get()));
EXPECT_FALSE(audio_processor->has_audio_processing());
audio_processor->OnCaptureFormatChanged(params_);
@@ -216,11 +219,14 @@ TEST_F(MediaStreamAudioProcessorTest, VerifyTabCaptureWithoutAudioProcessing) {
params_.channels(),
params_.sample_rate() / 100);
- // Create MediaStreamAudioProcessor instance for MEDIA_LOOPBACK_AUDIO_CAPTURE.
- audio_processor =
- new talk_base::RefCountedObject<MediaStreamAudioProcessor>(
- constraints, 0, MEDIA_LOOPBACK_AUDIO_CAPTURE,
- webrtc_audio_device.get());
+ // Create MediaStreamAudioProcessor instance for kMediaStreamSourceSystem
+ // source.
+ MockMediaConstraintFactory system_constraint_factory;
+ system_constraint_factory.AddMandatory(kMediaStreamSource,
+ kMediaStreamSourceSystem);
+ audio_processor = new talk_base::RefCountedObject<MediaStreamAudioProcessor>(
+ system_constraint_factory.CreateWebMediaConstraints(), 0,
+ webrtc_audio_device.get());
EXPECT_FALSE(audio_processor->has_audio_processing());
// Set |audio_processor| to NULL to make sure |webrtc_audio_device| outlives
@@ -241,7 +247,7 @@ TEST_F(MediaStreamAudioProcessorTest, TurnOffDefaultConstraints) {
scoped_refptr<MediaStreamAudioProcessor> audio_processor(
new talk_base::RefCountedObject<MediaStreamAudioProcessor>(
constraint_factory.CreateWebMediaConstraints(), 0,
- MEDIA_DEVICE_AUDIO_CAPTURE, webrtc_audio_device.get()));
+ webrtc_audio_device.get()));
EXPECT_FALSE(audio_processor->has_audio_processing());
audio_processor->OnCaptureFormatChanged(params_);
@@ -254,4 +260,61 @@ TEST_F(MediaStreamAudioProcessorTest, TurnOffDefaultConstraints) {
audio_processor = NULL;
}
+TEST_F(MediaStreamAudioProcessorTest, VerifyConstraints) {
+ // Setup the audio processor with enabling the flag.
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnableAudioTrackProcessing);
+
+ static const char* kDefaultAudioConstraints[] = {
+ MediaAudioConstraints::kEchoCancellation,
+ MediaAudioConstraints::kGoogEchoCancellation,
+ MediaAudioConstraints::kGoogExperimentalEchoCancellation,
+ MediaAudioConstraints::kGoogAutoGainControl,
+ MediaAudioConstraints::kGoogExperimentalAutoGainControl,
+ MediaAudioConstraints::kGoogNoiseSuppression,
+ MediaAudioConstraints::kGoogExperimentalNoiseSuppression,
+ MediaAudioConstraints::kGoogHighpassFilter,
+ MediaAudioConstraints::kGoogTypingNoiseDetection,
+ MediaAudioConstraints::kGoogAudioMirroring
+ };
+
+ // Verify mandatory constraints.
+ for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) {
+ MockMediaConstraintFactory constraint_factory;
+ constraint_factory.AddMandatory(kDefaultAudioConstraints[i], false);
+ blink::WebMediaConstraints constraints =
+ constraint_factory.CreateWebMediaConstraints();
+ MediaAudioConstraints audio_constraints(constraints, 0);
+ EXPECT_FALSE(audio_constraints.GetProperty(kDefaultAudioConstraints[i]));
+ }
+
+ // Verify optional constraints.
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDefaultAudioConstraints); ++i) {
+ MockMediaConstraintFactory constraint_factory;
+ constraint_factory.AddOptional(kDefaultAudioConstraints[i], false);
+ blink::WebMediaConstraints constraints =
+ constraint_factory.CreateWebMediaConstraints();
+ MediaAudioConstraints audio_constraints(constraints, 0);
+ EXPECT_FALSE(audio_constraints.GetProperty(kDefaultAudioConstraints[i]));
+ }
+
+ // Verify echo cancellation is off when platform aec effect is on.
+ MockMediaConstraintFactory constraint_factory;
+ MediaAudioConstraints audio_constraints(
+ constraint_factory.CreateWebMediaConstraints(),
+ media::AudioParameters::ECHO_CANCELLER);
+ EXPECT_FALSE(audio_constraints.GetProperty(
+ MediaAudioConstraints::kGoogEchoCancellation));
+}
+
+TEST_F(MediaStreamAudioProcessorTest, VerifyAllMandatoryConstraints) {
+ // Verify gUM will fail if getting an invalid mandatory audio constraint.
+ MockMediaConstraintFactory constraint_factory;
+ const std::string dummy_constraint = "dummy";
+ constraint_factory.AddMandatory(dummy_constraint, true);
+ MediaAudioConstraints audio_constraints(
+ constraint_factory.CreateWebMediaConstraints(), 0);
+ EXPECT_FALSE(audio_constraints.IsValid());
perkj_chrome 2014/04/14 12:15:19 Add test to make sure guM fail? ie, media_stream_i
no longer working on chromium 2014/04/14 14:40:50 I don't see any existing framework in media_stream
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698