OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <memory> | 5 #include <memory> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "content/public/renderer/media_stream_audio_sink.h" | 11 #include "content/public/renderer/media_stream_audio_sink.h" |
12 #include "content/renderer/media/media_stream_audio_processor_options.h" | |
12 #include "content/renderer/media/media_stream_audio_track.h" | 13 #include "content/renderer/media/media_stream_audio_track.h" |
13 #include "content/renderer/media/mock_audio_device_factory.h" | 14 #include "content/renderer/media/mock_audio_device_factory.h" |
14 #include "content/renderer/media/mock_constraint_factory.h" | 15 #include "content/renderer/media/mock_constraint_factory.h" |
hbos_chromium
2017/06/16 17:27:14
nit: Here and perhaps other files: remove inclusio
Guido Urdaneta
2017/06/19 11:56:49
Done.
| |
15 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory. h" | 16 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory. h" |
16 #include "content/renderer/media/webrtc/processed_local_audio_source.h" | 17 #include "content/renderer/media/webrtc/processed_local_audio_source.h" |
17 #include "media/base/audio_bus.h" | 18 #include "media/base/audio_bus.h" |
18 #include "media/base/audio_parameters.h" | 19 #include "media/base/audio_parameters.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 22 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
22 #include "third_party/WebKit/public/web/WebHeap.h" | 23 #include "third_party/WebKit/public/web/WebHeap.h" |
23 | 24 |
24 using ::testing::_; | 25 using ::testing::_; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 void OnSetFormat(const media::AudioParameters& params) override { | 66 void OnSetFormat(const media::AudioParameters& params) override { |
66 params_ = params; | 67 params_ = params; |
67 FormatIsSet(params_); | 68 FormatIsSet(params_); |
68 } | 69 } |
69 MOCK_METHOD1(FormatIsSet, void(const media::AudioParameters& params)); | 70 MOCK_METHOD1(FormatIsSet, void(const media::AudioParameters& params)); |
70 | 71 |
71 private: | 72 private: |
72 media::AudioParameters params_; | 73 media::AudioParameters params_; |
73 }; | 74 }; |
74 | 75 |
76 void DisableDefaultAudioProcessingProperties( | |
77 AudioProcessingProperties* properties) { | |
78 properties->enable_sw_echo_cancellation = false; | |
79 properties->goog_experimental_echo_cancellation = false; | |
80 properties->goog_auto_gain_control = false; | |
81 properties->goog_experimental_auto_gain_control = false; | |
82 properties->goog_noise_suppression = false; | |
83 properties->goog_noise_suppression = false; | |
84 properties->goog_highpass_filter = false; | |
85 properties->goog_typing_noise_detection = false; | |
86 properties->goog_experimental_noise_suppression = false; | |
87 properties->goog_beamforming = false; | |
88 } | |
89 | |
75 } // namespace | 90 } // namespace |
76 | 91 |
77 class ProcessedLocalAudioSourceTest : public testing::Test { | 92 class ProcessedLocalAudioSourceTest : public testing::Test { |
78 protected: | 93 protected: |
79 ProcessedLocalAudioSourceTest() {} | 94 ProcessedLocalAudioSourceTest() {} |
80 | 95 |
81 ~ProcessedLocalAudioSourceTest() override {} | 96 ~ProcessedLocalAudioSourceTest() override {} |
82 | 97 |
83 void SetUp() override { | 98 void SetUp() override { |
84 blink_audio_source_.Initialize(blink::WebString::FromUTF8("audio_label"), | 99 blink_audio_source_.Initialize(blink::WebString::FromUTF8("audio_label"), |
85 blink::WebMediaStreamSource::kTypeAudio, | 100 blink::WebMediaStreamSource::kTypeAudio, |
86 blink::WebString::FromUTF8("audio_track"), | 101 blink::WebString::FromUTF8("audio_track"), |
87 false /* remote */); | 102 false /* remote */); |
88 blink_audio_track_.Initialize(blink_audio_source_.Id(), | 103 blink_audio_track_.Initialize(blink_audio_source_.Id(), |
89 blink_audio_source_); | 104 blink_audio_source_); |
90 } | 105 } |
91 | 106 |
92 void TearDown() override { | 107 void TearDown() override { |
93 blink_audio_track_.Reset(); | 108 blink_audio_track_.Reset(); |
94 blink_audio_source_.Reset(); | 109 blink_audio_source_.Reset(); |
95 blink::WebHeap::CollectAllGarbageForTesting(); | 110 blink::WebHeap::CollectAllGarbageForTesting(); |
96 } | 111 } |
97 | 112 |
98 void CreateProcessedLocalAudioSource( | 113 void CreateProcessedLocalAudioSource( |
99 const blink::WebMediaConstraints& constraints) { | 114 const AudioProcessingProperties& properties) { |
100 ProcessedLocalAudioSource* const source = new ProcessedLocalAudioSource( | 115 ProcessedLocalAudioSource* const source = new ProcessedLocalAudioSource( |
101 -1 /* consumer_render_frame_id is N/A for non-browser tests */, | 116 -1 /* consumer_render_frame_id is N/A for non-browser tests */, |
102 StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "Mock audio device", | 117 StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "Mock audio device", |
103 "mock_audio_device_id", kSampleRate, kChannelLayout, | 118 "mock_audio_device_id", kSampleRate, kChannelLayout, |
104 kRequestedBufferSize), | 119 kRequestedBufferSize), |
105 constraints, | 120 properties, |
106 base::Bind(&ProcessedLocalAudioSourceTest::OnAudioSourceStarted, | 121 base::Bind(&ProcessedLocalAudioSourceTest::OnAudioSourceStarted, |
107 base::Unretained(this)), | 122 base::Unretained(this)), |
108 &mock_dependency_factory_); | 123 &mock_dependency_factory_); |
109 source->SetAllowInvalidRenderFrameIdForTesting(true); | 124 source->SetAllowInvalidRenderFrameIdForTesting(true); |
110 blink_audio_source_.SetExtraData(source); // Takes ownership. | 125 blink_audio_source_.SetExtraData(source); // Takes ownership. |
111 } | 126 } |
112 | 127 |
113 void CheckSourceFormatMatches(const media::AudioParameters& params) { | 128 void CheckSourceFormatMatches(const media::AudioParameters& params) { |
114 EXPECT_EQ(kSampleRate, params.sample_rate()); | 129 EXPECT_EQ(kSampleRate, params.sample_rate()); |
115 EXPECT_EQ(kChannelLayout, params.channel_layout()); | 130 EXPECT_EQ(kChannelLayout, params.channel_layout()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 // Tests a basic end-to-end start-up, track+sink connections, audio flow, and | 169 // Tests a basic end-to-end start-up, track+sink connections, audio flow, and |
155 // shut-down. The unit tests in media_stream_audio_unittest.cc provide more | 170 // shut-down. The unit tests in media_stream_audio_unittest.cc provide more |
156 // comprehensive testing of the object graph connections and multi-threading | 171 // comprehensive testing of the object graph connections and multi-threading |
157 // concerns. | 172 // concerns. |
158 TEST_F(ProcessedLocalAudioSourceTest, VerifyAudioFlowWithoutAudioProcessing) { | 173 TEST_F(ProcessedLocalAudioSourceTest, VerifyAudioFlowWithoutAudioProcessing) { |
159 using ThisTest = | 174 using ThisTest = |
160 ProcessedLocalAudioSourceTest_VerifyAudioFlowWithoutAudioProcessing_Test; | 175 ProcessedLocalAudioSourceTest_VerifyAudioFlowWithoutAudioProcessing_Test; |
161 | 176 |
162 // Turn off the default constraints so the sink will get audio in chunks of | 177 // Turn off the default constraints so the sink will get audio in chunks of |
163 // the native buffer size. | 178 // the native buffer size. |
164 MockConstraintFactory constraint_factory; | 179 AudioProcessingProperties properties; |
165 constraint_factory.DisableDefaultAudioConstraints(); | 180 DisableDefaultAudioProcessingProperties(&properties); |
166 | 181 CreateProcessedLocalAudioSource(properties); |
167 CreateProcessedLocalAudioSource( | |
168 constraint_factory.CreateWebMediaConstraints()); | |
169 | 182 |
170 // Connect the track, and expect the MockCapturerSource to be initialized and | 183 // Connect the track, and expect the MockCapturerSource to be initialized and |
171 // started by ProcessedLocalAudioSource. | 184 // started by ProcessedLocalAudioSource. |
172 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), | 185 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), |
173 Initialize(_, capture_source_callback(), -1)) | 186 Initialize(_, capture_source_callback(), -1)) |
174 .WillOnce(WithArg<0>(Invoke(this, &ThisTest::CheckSourceFormatMatches))); | 187 .WillOnce(WithArg<0>(Invoke(this, &ThisTest::CheckSourceFormatMatches))); |
175 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), | 188 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), |
176 SetAutomaticGainControl(true)); | 189 SetAutomaticGainControl(true)); |
177 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), Start()) | 190 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), Start()) |
178 .WillOnce(Invoke( | 191 .WillOnce(Invoke( |
(...skipping 20 matching lines...) Expand all Loading... | |
199 EXPECT_CALL(*sink, OnDataCallback()).Times(AtLeast(1)); | 212 EXPECT_CALL(*sink, OnDataCallback()).Times(AtLeast(1)); |
200 capture_source_callback()->Capture(audio_bus.get(), delay_ms, volume, | 213 capture_source_callback()->Capture(audio_bus.get(), delay_ms, volume, |
201 key_pressed); | 214 key_pressed); |
202 | 215 |
203 // Expect the ProcessedLocalAudioSource to auto-stop the MockCapturerSource | 216 // Expect the ProcessedLocalAudioSource to auto-stop the MockCapturerSource |
204 // when the track is stopped. | 217 // when the track is stopped. |
205 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), Stop()); | 218 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), Stop()); |
206 MediaStreamAudioTrack::From(blink_audio_track())->Stop(); | 219 MediaStreamAudioTrack::From(blink_audio_track())->Stop(); |
207 } | 220 } |
208 | 221 |
209 // Tests that the source is not started when invalid audio constraints are | |
210 // present. | |
211 TEST_F(ProcessedLocalAudioSourceTest, FailToStartWithWrongConstraints) { | |
hbos_chromium
2017/06/16 17:27:14
Why is this test removed? If invalid constraints a
Guido Urdaneta
2017/06/19 11:56:49
The concept of "wrong" constraints does not exist
| |
212 MockConstraintFactory constraint_factory; | |
213 const std::string dummy_constraint = "dummy"; | |
214 // Set a non-audio constraint. | |
215 constraint_factory.basic().width.SetExact(240); | |
216 | |
217 CreateProcessedLocalAudioSource( | |
218 constraint_factory.CreateWebMediaConstraints()); | |
219 | |
220 // Expect the MockCapturerSource is never initialized/started and the | |
221 // ConnectToTrack() operation fails due to the invalid constraint. | |
222 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), | |
223 Initialize(_, capture_source_callback(), -1)) | |
224 .Times(0); | |
225 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), | |
226 SetAutomaticGainControl(true)).Times(0); | |
227 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), Start()) | |
228 .Times(0); | |
229 EXPECT_FALSE(audio_source()->ConnectToTrack(blink_audio_track())); | |
230 | |
231 // Even though ConnectToTrack() failed, there should still have been a new | |
232 // MediaStreamAudioTrack instance created, owned by the | |
233 // blink::WebMediaStreamTrack. | |
234 EXPECT_TRUE(MediaStreamAudioTrack::From(blink_audio_track())); | |
235 } | |
236 | |
237 // TODO(miu): There's a lot of logic in ProcessedLocalAudioSource around | |
238 // constraints processing and validation that should have unit testing. | |
239 | 222 |
240 } // namespace content | 223 } // namespace content |
OLD | NEW |