Chromium Code Reviews| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 void OnSetFormat(const media::AudioParameters& params) override { | 65 void OnSetFormat(const media::AudioParameters& params) override { |
| 66 params_ = params; | 66 params_ = params; |
| 67 FormatIsSet(params_); | 67 FormatIsSet(params_); |
| 68 } | 68 } |
| 69 MOCK_METHOD1(FormatIsSet, void(const media::AudioParameters& params)); | 69 MOCK_METHOD1(FormatIsSet, void(const media::AudioParameters& params)); |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 media::AudioParameters params_; | 72 media::AudioParameters params_; |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 void DisableDefaultAudioProcessingProperties( | |
|
miu
2017/06/19 21:18:44
Looks like this same code is in two places. I'd su
Guido Urdaneta
2017/06/20 12:18:48
Done.
| |
| 76 AudioProcessingProperties* properties) { | |
| 77 properties->enable_sw_echo_cancellation = false; | |
| 78 properties->goog_experimental_echo_cancellation = false; | |
| 79 properties->goog_auto_gain_control = false; | |
| 80 properties->goog_experimental_auto_gain_control = false; | |
| 81 properties->goog_noise_suppression = false; | |
| 82 properties->goog_noise_suppression = false; | |
| 83 properties->goog_highpass_filter = false; | |
| 84 properties->goog_typing_noise_detection = false; | |
| 85 properties->goog_experimental_noise_suppression = false; | |
| 86 properties->goog_beamforming = false; | |
| 87 } | |
| 88 | |
| 75 } // namespace | 89 } // namespace |
| 76 | 90 |
| 77 class ProcessedLocalAudioSourceTest : public testing::Test { | 91 class ProcessedLocalAudioSourceTest : public testing::Test { |
| 78 protected: | 92 protected: |
| 79 ProcessedLocalAudioSourceTest() {} | 93 ProcessedLocalAudioSourceTest() {} |
| 80 | 94 |
| 81 ~ProcessedLocalAudioSourceTest() override {} | 95 ~ProcessedLocalAudioSourceTest() override {} |
| 82 | 96 |
| 83 void SetUp() override { | 97 void SetUp() override { |
| 84 blink_audio_source_.Initialize(blink::WebString::FromUTF8("audio_label"), | 98 blink_audio_source_.Initialize(blink::WebString::FromUTF8("audio_label"), |
| 85 blink::WebMediaStreamSource::kTypeAudio, | 99 blink::WebMediaStreamSource::kTypeAudio, |
| 86 blink::WebString::FromUTF8("audio_track"), | 100 blink::WebString::FromUTF8("audio_track"), |
| 87 false /* remote */); | 101 false /* remote */); |
| 88 blink_audio_track_.Initialize(blink_audio_source_.Id(), | 102 blink_audio_track_.Initialize(blink_audio_source_.Id(), |
| 89 blink_audio_source_); | 103 blink_audio_source_); |
| 90 } | 104 } |
| 91 | 105 |
| 92 void TearDown() override { | 106 void TearDown() override { |
| 93 blink_audio_track_.Reset(); | 107 blink_audio_track_.Reset(); |
| 94 blink_audio_source_.Reset(); | 108 blink_audio_source_.Reset(); |
| 95 blink::WebHeap::CollectAllGarbageForTesting(); | 109 blink::WebHeap::CollectAllGarbageForTesting(); |
| 96 } | 110 } |
| 97 | 111 |
| 98 void CreateProcessedLocalAudioSource( | 112 void CreateProcessedLocalAudioSource( |
| 99 const blink::WebMediaConstraints& constraints) { | 113 const AudioProcessingProperties& properties) { |
| 100 ProcessedLocalAudioSource* const source = new ProcessedLocalAudioSource( | 114 ProcessedLocalAudioSource* const source = new ProcessedLocalAudioSource( |
| 101 -1 /* consumer_render_frame_id is N/A for non-browser tests */, | 115 -1 /* consumer_render_frame_id is N/A for non-browser tests */, |
| 102 StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "Mock audio device", | 116 StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "Mock audio device", |
| 103 "mock_audio_device_id", kSampleRate, kChannelLayout, | 117 "mock_audio_device_id", kSampleRate, kChannelLayout, |
| 104 kRequestedBufferSize), | 118 kRequestedBufferSize), |
| 105 constraints, | 119 properties, |
| 106 base::Bind(&ProcessedLocalAudioSourceTest::OnAudioSourceStarted, | 120 base::Bind(&ProcessedLocalAudioSourceTest::OnAudioSourceStarted, |
| 107 base::Unretained(this)), | 121 base::Unretained(this)), |
| 108 &mock_dependency_factory_); | 122 &mock_dependency_factory_); |
| 109 source->SetAllowInvalidRenderFrameIdForTesting(true); | 123 source->SetAllowInvalidRenderFrameIdForTesting(true); |
| 110 blink_audio_source_.SetExtraData(source); // Takes ownership. | 124 blink_audio_source_.SetExtraData(source); // Takes ownership. |
| 111 } | 125 } |
| 112 | 126 |
| 113 void CheckSourceFormatMatches(const media::AudioParameters& params) { | 127 void CheckSourceFormatMatches(const media::AudioParameters& params) { |
| 114 EXPECT_EQ(kSampleRate, params.sample_rate()); | 128 EXPECT_EQ(kSampleRate, params.sample_rate()); |
| 115 EXPECT_EQ(kChannelLayout, params.channel_layout()); | 129 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 | 168 // 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 | 169 // shut-down. The unit tests in media_stream_audio_unittest.cc provide more |
| 156 // comprehensive testing of the object graph connections and multi-threading | 170 // comprehensive testing of the object graph connections and multi-threading |
| 157 // concerns. | 171 // concerns. |
| 158 TEST_F(ProcessedLocalAudioSourceTest, VerifyAudioFlowWithoutAudioProcessing) { | 172 TEST_F(ProcessedLocalAudioSourceTest, VerifyAudioFlowWithoutAudioProcessing) { |
| 159 using ThisTest = | 173 using ThisTest = |
| 160 ProcessedLocalAudioSourceTest_VerifyAudioFlowWithoutAudioProcessing_Test; | 174 ProcessedLocalAudioSourceTest_VerifyAudioFlowWithoutAudioProcessing_Test; |
| 161 | 175 |
| 162 // Turn off the default constraints so the sink will get audio in chunks of | 176 // Turn off the default constraints so the sink will get audio in chunks of |
| 163 // the native buffer size. | 177 // the native buffer size. |
| 164 MockConstraintFactory constraint_factory; | 178 AudioProcessingProperties properties; |
| 165 constraint_factory.DisableDefaultAudioConstraints(); | 179 DisableDefaultAudioProcessingProperties(&properties); |
| 166 | 180 CreateProcessedLocalAudioSource(properties); |
| 167 CreateProcessedLocalAudioSource( | |
| 168 constraint_factory.CreateWebMediaConstraints()); | |
| 169 | 181 |
| 170 // Connect the track, and expect the MockCapturerSource to be initialized and | 182 // Connect the track, and expect the MockCapturerSource to be initialized and |
| 171 // started by ProcessedLocalAudioSource. | 183 // started by ProcessedLocalAudioSource. |
| 172 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), | 184 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), |
| 173 Initialize(_, capture_source_callback(), -1)) | 185 Initialize(_, capture_source_callback(), -1)) |
| 174 .WillOnce(WithArg<0>(Invoke(this, &ThisTest::CheckSourceFormatMatches))); | 186 .WillOnce(WithArg<0>(Invoke(this, &ThisTest::CheckSourceFormatMatches))); |
| 175 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), | 187 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), |
| 176 SetAutomaticGainControl(true)); | 188 SetAutomaticGainControl(true)); |
| 177 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), Start()) | 189 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), Start()) |
| 178 .WillOnce(Invoke( | 190 .WillOnce(Invoke( |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 199 EXPECT_CALL(*sink, OnDataCallback()).Times(AtLeast(1)); | 211 EXPECT_CALL(*sink, OnDataCallback()).Times(AtLeast(1)); |
| 200 capture_source_callback()->Capture(audio_bus.get(), delay_ms, volume, | 212 capture_source_callback()->Capture(audio_bus.get(), delay_ms, volume, |
| 201 key_pressed); | 213 key_pressed); |
| 202 | 214 |
| 203 // Expect the ProcessedLocalAudioSource to auto-stop the MockCapturerSource | 215 // Expect the ProcessedLocalAudioSource to auto-stop the MockCapturerSource |
| 204 // when the track is stopped. | 216 // when the track is stopped. |
| 205 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), Stop()); | 217 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), Stop()); |
| 206 MediaStreamAudioTrack::From(blink_audio_track())->Stop(); | 218 MediaStreamAudioTrack::From(blink_audio_track())->Stop(); |
| 207 } | 219 } |
| 208 | 220 |
| 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 | 221 |
| 240 } // namespace content | 222 } // namespace content |
| OLD | NEW |