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/webrtc/mock_peer_connection_dependency_factory.
h" | 15 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.
h" |
16 #include "content/renderer/media/webrtc/processed_local_audio_source.h" | 16 #include "content/renderer/media/webrtc/processed_local_audio_source.h" |
17 #include "media/base/audio_bus.h" | 17 #include "media/base/audio_bus.h" |
18 #include "media/base/audio_parameters.h" | 18 #include "media/base/audio_parameters.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 21 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
22 #include "third_party/WebKit/public/web/WebHeap.h" | 22 #include "third_party/WebKit/public/web/WebHeap.h" |
23 | 23 |
24 using ::testing::_; | 24 using ::testing::_; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 blink_audio_source_); | 89 blink_audio_source_); |
90 } | 90 } |
91 | 91 |
92 void TearDown() override { | 92 void TearDown() override { |
93 blink_audio_track_.Reset(); | 93 blink_audio_track_.Reset(); |
94 blink_audio_source_.Reset(); | 94 blink_audio_source_.Reset(); |
95 blink::WebHeap::CollectAllGarbageForTesting(); | 95 blink::WebHeap::CollectAllGarbageForTesting(); |
96 } | 96 } |
97 | 97 |
98 void CreateProcessedLocalAudioSource( | 98 void CreateProcessedLocalAudioSource( |
99 const blink::WebMediaConstraints& constraints) { | 99 const AudioProcessingProperties& properties) { |
100 ProcessedLocalAudioSource* const source = new ProcessedLocalAudioSource( | 100 ProcessedLocalAudioSource* const source = new ProcessedLocalAudioSource( |
101 -1 /* consumer_render_frame_id is N/A for non-browser tests */, | 101 -1 /* consumer_render_frame_id is N/A for non-browser tests */, |
102 StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "Mock audio device", | 102 StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "Mock audio device", |
103 "mock_audio_device_id", kSampleRate, kChannelLayout, | 103 "mock_audio_device_id", kSampleRate, kChannelLayout, |
104 kRequestedBufferSize), | 104 kRequestedBufferSize), |
105 constraints, | 105 properties, |
106 base::Bind(&ProcessedLocalAudioSourceTest::OnAudioSourceStarted, | 106 base::Bind(&ProcessedLocalAudioSourceTest::OnAudioSourceStarted, |
107 base::Unretained(this)), | 107 base::Unretained(this)), |
108 &mock_dependency_factory_); | 108 &mock_dependency_factory_); |
109 source->SetAllowInvalidRenderFrameIdForTesting(true); | 109 source->SetAllowInvalidRenderFrameIdForTesting(true); |
110 blink_audio_source_.SetExtraData(source); // Takes ownership. | 110 blink_audio_source_.SetExtraData(source); // Takes ownership. |
111 } | 111 } |
112 | 112 |
113 void CheckSourceFormatMatches(const media::AudioParameters& params) { | 113 void CheckSourceFormatMatches(const media::AudioParameters& params) { |
114 EXPECT_EQ(kSampleRate, params.sample_rate()); | 114 EXPECT_EQ(kSampleRate, params.sample_rate()); |
115 EXPECT_EQ(kChannelLayout, params.channel_layout()); | 115 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 | 154 // 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 | 155 // shut-down. The unit tests in media_stream_audio_unittest.cc provide more |
156 // comprehensive testing of the object graph connections and multi-threading | 156 // comprehensive testing of the object graph connections and multi-threading |
157 // concerns. | 157 // concerns. |
158 TEST_F(ProcessedLocalAudioSourceTest, VerifyAudioFlowWithoutAudioProcessing) { | 158 TEST_F(ProcessedLocalAudioSourceTest, VerifyAudioFlowWithoutAudioProcessing) { |
159 using ThisTest = | 159 using ThisTest = |
160 ProcessedLocalAudioSourceTest_VerifyAudioFlowWithoutAudioProcessing_Test; | 160 ProcessedLocalAudioSourceTest_VerifyAudioFlowWithoutAudioProcessing_Test; |
161 | 161 |
162 // Turn off the default constraints so the sink will get audio in chunks of | 162 // Turn off the default constraints so the sink will get audio in chunks of |
163 // the native buffer size. | 163 // the native buffer size. |
164 MockConstraintFactory constraint_factory; | 164 AudioProcessingProperties properties; |
165 constraint_factory.DisableDefaultAudioConstraints(); | 165 properties.DisableDefaultPropertiesForTesting(); |
166 | 166 CreateProcessedLocalAudioSource(properties); |
167 CreateProcessedLocalAudioSource( | |
168 constraint_factory.CreateWebMediaConstraints()); | |
169 | 167 |
170 // Connect the track, and expect the MockCapturerSource to be initialized and | 168 // Connect the track, and expect the MockCapturerSource to be initialized and |
171 // started by ProcessedLocalAudioSource. | 169 // started by ProcessedLocalAudioSource. |
172 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), | 170 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), |
173 Initialize(_, capture_source_callback(), -1)) | 171 Initialize(_, capture_source_callback(), -1)) |
174 .WillOnce(WithArg<0>(Invoke(this, &ThisTest::CheckSourceFormatMatches))); | 172 .WillOnce(WithArg<0>(Invoke(this, &ThisTest::CheckSourceFormatMatches))); |
175 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), | 173 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), |
176 SetAutomaticGainControl(true)); | 174 SetAutomaticGainControl(true)); |
177 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), Start()) | 175 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), Start()) |
178 .WillOnce(Invoke( | 176 .WillOnce(Invoke( |
(...skipping 20 matching lines...) Expand all Loading... |
199 EXPECT_CALL(*sink, OnDataCallback()).Times(AtLeast(1)); | 197 EXPECT_CALL(*sink, OnDataCallback()).Times(AtLeast(1)); |
200 capture_source_callback()->Capture(audio_bus.get(), delay_ms, volume, | 198 capture_source_callback()->Capture(audio_bus.get(), delay_ms, volume, |
201 key_pressed); | 199 key_pressed); |
202 | 200 |
203 // Expect the ProcessedLocalAudioSource to auto-stop the MockCapturerSource | 201 // Expect the ProcessedLocalAudioSource to auto-stop the MockCapturerSource |
204 // when the track is stopped. | 202 // when the track is stopped. |
205 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), Stop()); | 203 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), Stop()); |
206 MediaStreamAudioTrack::From(blink_audio_track())->Stop(); | 204 MediaStreamAudioTrack::From(blink_audio_track())->Stop(); |
207 } | 205 } |
208 | 206 |
209 // Tests that the source is not started when invalid audio constraints are | |
210 // present. | |
211 TEST_F(ProcessedLocalAudioSourceTest, FailToStartWithWrongConstraints) { | |
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 | 207 |
240 } // namespace content | 208 } // namespace content |
OLD | NEW |