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" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 blink::WebMediaConstraints& constraints) { |
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, |
| 106 base::Bind(&ProcessedLocalAudioSourceTest::OnAudioSourceStarted, |
| 107 base::Unretained(this)), |
105 &mock_dependency_factory_); | 108 &mock_dependency_factory_); |
106 source->SetAllowInvalidRenderFrameIdForTesting(true); | 109 source->SetAllowInvalidRenderFrameIdForTesting(true); |
107 source->SetSourceConstraints(constraints); | |
108 blink_audio_source_.setExtraData(source); // Takes ownership. | 110 blink_audio_source_.setExtraData(source); // Takes ownership. |
109 } | 111 } |
110 | 112 |
111 void CheckSourceFormatMatches(const media::AudioParameters& params) { | 113 void CheckSourceFormatMatches(const media::AudioParameters& params) { |
112 EXPECT_EQ(kSampleRate, params.sample_rate()); | 114 EXPECT_EQ(kSampleRate, params.sample_rate()); |
113 EXPECT_EQ(kChannelLayout, params.channel_layout()); | 115 EXPECT_EQ(kChannelLayout, params.channel_layout()); |
114 EXPECT_EQ(kExpectedSourceBufferSize, params.frames_per_buffer()); | 116 EXPECT_EQ(kExpectedSourceBufferSize, params.frames_per_buffer()); |
115 } | 117 } |
116 | 118 |
117 void CheckOutputFormatMatches(const media::AudioParameters& params) { | 119 void CheckOutputFormatMatches(const media::AudioParameters& params) { |
(...skipping 12 matching lines...) Expand all Loading... |
130 } | 132 } |
131 | 133 |
132 MediaStreamAudioSource* audio_source() const { | 134 MediaStreamAudioSource* audio_source() const { |
133 return MediaStreamAudioSource::From(blink_audio_source_); | 135 return MediaStreamAudioSource::From(blink_audio_source_); |
134 } | 136 } |
135 | 137 |
136 const blink::WebMediaStreamTrack& blink_audio_track() { | 138 const blink::WebMediaStreamTrack& blink_audio_track() { |
137 return blink_audio_track_; | 139 return blink_audio_track_; |
138 } | 140 } |
139 | 141 |
| 142 void OnAudioSourceStarted(MediaStreamSource* source, |
| 143 MediaStreamRequestResult result, |
| 144 const blink::WebString& result_name) {} |
| 145 |
140 private: | 146 private: |
141 base::MessageLoop main_thread_message_loop_; // Needed for MSAudioProcessor. | 147 base::MessageLoop main_thread_message_loop_; // Needed for MSAudioProcessor. |
142 MockAudioDeviceFactory mock_audio_device_factory_; | 148 MockAudioDeviceFactory mock_audio_device_factory_; |
143 MockPeerConnectionDependencyFactory mock_dependency_factory_; | 149 MockPeerConnectionDependencyFactory mock_dependency_factory_; |
144 blink::WebMediaStreamSource blink_audio_source_; | 150 blink::WebMediaStreamSource blink_audio_source_; |
145 blink::WebMediaStreamTrack blink_audio_track_; | 151 blink::WebMediaStreamTrack blink_audio_track_; |
146 }; | 152 }; |
147 | 153 |
148 // 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 |
149 // 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 |
(...skipping 11 matching lines...) Expand all Loading... |
161 CreateProcessedLocalAudioSource( | 167 CreateProcessedLocalAudioSource( |
162 constraint_factory.CreateWebMediaConstraints()); | 168 constraint_factory.CreateWebMediaConstraints()); |
163 | 169 |
164 // Connect the track, and expect the MockCapturerSource to be initialized and | 170 // Connect the track, and expect the MockCapturerSource to be initialized and |
165 // started by ProcessedLocalAudioSource. | 171 // started by ProcessedLocalAudioSource. |
166 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), | 172 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), |
167 Initialize(_, capture_source_callback(), -1)) | 173 Initialize(_, capture_source_callback(), -1)) |
168 .WillOnce(WithArg<0>(Invoke(this, &ThisTest::CheckSourceFormatMatches))); | 174 .WillOnce(WithArg<0>(Invoke(this, &ThisTest::CheckSourceFormatMatches))); |
169 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), | 175 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), |
170 SetAutomaticGainControl(true)); | 176 SetAutomaticGainControl(true)); |
171 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), Start()); | 177 EXPECT_CALL(*mock_audio_device_factory()->mock_capturer_source(), Start()) |
| 178 .WillOnce(Invoke( |
| 179 capture_source_callback(), |
| 180 &media::AudioCapturerSource::CaptureCallback::OnCaptureStarted)); |
172 ASSERT_TRUE(audio_source()->ConnectToTrack(blink_audio_track())); | 181 ASSERT_TRUE(audio_source()->ConnectToTrack(blink_audio_track())); |
173 CheckOutputFormatMatches(audio_source()->GetAudioParameters()); | 182 CheckOutputFormatMatches(audio_source()->GetAudioParameters()); |
174 | 183 |
175 // Connect a sink to the track. | 184 // Connect a sink to the track. |
176 std::unique_ptr<MockMediaStreamAudioSink> sink( | 185 std::unique_ptr<MockMediaStreamAudioSink> sink( |
177 new MockMediaStreamAudioSink()); | 186 new MockMediaStreamAudioSink()); |
178 EXPECT_CALL(*sink, FormatIsSet(_)) | 187 EXPECT_CALL(*sink, FormatIsSet(_)) |
179 .WillOnce(Invoke(this, &ThisTest::CheckOutputFormatMatches)); | 188 .WillOnce(Invoke(this, &ThisTest::CheckOutputFormatMatches)); |
180 MediaStreamAudioTrack::From(blink_audio_track())->AddSink(sink.get()); | 189 MediaStreamAudioTrack::From(blink_audio_track())->AddSink(sink.get()); |
181 | 190 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 // Even though ConnectToTrack() failed, there should still have been a new | 231 // Even though ConnectToTrack() failed, there should still have been a new |
223 // MediaStreamAudioTrack instance created, owned by the | 232 // MediaStreamAudioTrack instance created, owned by the |
224 // blink::WebMediaStreamTrack. | 233 // blink::WebMediaStreamTrack. |
225 EXPECT_TRUE(MediaStreamAudioTrack::From(blink_audio_track())); | 234 EXPECT_TRUE(MediaStreamAudioTrack::From(blink_audio_track())); |
226 } | 235 } |
227 | 236 |
228 // TODO(miu): There's a lot of logic in ProcessedLocalAudioSource around | 237 // TODO(miu): There's a lot of logic in ProcessedLocalAudioSource around |
229 // constraints processing and validation that should have unit testing. | 238 // constraints processing and validation that should have unit testing. |
230 | 239 |
231 } // namespace content | 240 } // namespace content |
OLD | NEW |