OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/macros.h" | 5 #include "base/macros.h" |
6 #include "base/synchronization/waitable_event.h" | 6 #include "base/synchronization/waitable_event.h" |
7 #include "base/test/test_timeouts.h" | 7 #include "base/test/test_timeouts.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "content/public/renderer/media_stream_audio_sink.h" | 9 #include "content/public/renderer/media_stream_audio_sink.h" |
10 #include "content/renderer/media/media_stream_audio_source.h" | 10 #include "content/renderer/media/media_stream_audio_source.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 | 88 |
89 class MockCapturerSource : public media::AudioCapturerSource { | 89 class MockCapturerSource : public media::AudioCapturerSource { |
90 public: | 90 public: |
91 explicit MockCapturerSource(WebRtcAudioCapturer* capturer) | 91 explicit MockCapturerSource(WebRtcAudioCapturer* capturer) |
92 : capturer_(capturer) {} | 92 : capturer_(capturer) {} |
93 MOCK_METHOD3(OnInitialize, void(const media::AudioParameters& params, | 93 MOCK_METHOD3(OnInitialize, void(const media::AudioParameters& params, |
94 CaptureCallback* callback, | 94 CaptureCallback* callback, |
95 int session_id)); | 95 int session_id)); |
96 MOCK_METHOD0(OnStart, void()); | 96 MOCK_METHOD0(OnStart, void()); |
97 MOCK_METHOD0(OnStop, void()); | 97 MOCK_METHOD0(OnStop, void()); |
98 MOCK_METHOD1(SetVolume, void(double volume)); | 98 void SetVolume(double volume) final {} |
99 MOCK_METHOD1(SetAutomaticGainControl, void(bool enable)); | 99 MOCK_METHOD1(SetAutomaticGainControl, void(bool enable)); |
100 | 100 |
101 void Initialize(const media::AudioParameters& params, | 101 void Initialize(const media::AudioParameters& params, |
102 CaptureCallback* callback, | 102 CaptureCallback* callback, |
103 int session_id) override { | 103 int session_id) override { |
104 DCHECK(params.IsValid()); | 104 DCHECK(params.IsValid()); |
105 params_ = params; | 105 params_ = params; |
106 OnInitialize(params, callback, session_id); | 106 OnInitialize(params, callback, session_id); |
107 } | 107 } |
108 void Start() override { | 108 void Start() override { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 480); | 158 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 480); |
159 MockMediaConstraintFactory constraint_factory; | 159 MockMediaConstraintFactory constraint_factory; |
160 blink_source_.initialize("dummy", blink::WebMediaStreamSource::TypeAudio, | 160 blink_source_.initialize("dummy", blink::WebMediaStreamSource::TypeAudio, |
161 "dummy", | 161 "dummy", |
162 false /* remote */, true /* readonly */); | 162 false /* remote */, true /* readonly */); |
163 MediaStreamAudioSource* audio_source = new MediaStreamAudioSource(); | 163 MediaStreamAudioSource* audio_source = new MediaStreamAudioSource(); |
164 blink_source_.setExtraData(audio_source); | 164 blink_source_.setExtraData(audio_source); |
165 | 165 |
166 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE, | 166 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE, |
167 std::string(), std::string()); | 167 std::string(), std::string()); |
168 capturer_ = WebRtcAudioCapturer::CreateCapturer( | 168 { |
169 -1, device, constraint_factory.CreateWebMediaConstraints(), NULL, | 169 scoped_ptr<WebRtcAudioCapturer> capturer = |
170 audio_source); | 170 WebRtcAudioCapturer::CreateCapturer( |
171 audio_source->SetAudioCapturer(capturer_.get()); | 171 -1, device, constraint_factory.CreateWebMediaConstraints(), |
172 capturer_source_ = new MockCapturerSource(capturer_.get()); | 172 nullptr, audio_source); |
173 EXPECT_CALL(*capturer_source_.get(), OnInitialize(_, capturer_.get(), -1)) | 173 capturer_ = capturer.get(); |
| 174 audio_source->SetAudioCapturer(std::move(capturer)); |
| 175 } |
| 176 capturer_source_ = new MockCapturerSource(capturer_); |
| 177 EXPECT_CALL(*capturer_source_.get(), OnInitialize(_, capturer_, -1)) |
174 .WillOnce(Return()); | 178 .WillOnce(Return()); |
175 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); | 179 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); |
176 EXPECT_CALL(*capturer_source_.get(), OnStart()); | 180 EXPECT_CALL(*capturer_source_.get(), OnStart()); |
177 capturer_->SetCapturerSource(capturer_source_, params_); | 181 capturer_->SetCapturerSource(capturer_source_, params_); |
178 } | 182 } |
179 | 183 |
180 void TearDown() override { | 184 void TearDown() override { |
181 blink_source_.reset(); | 185 blink_source_.reset(); |
182 blink::WebHeap::collectAllGarbageForTesting(); | 186 blink::WebHeap::collectAllGarbageForTesting(); |
183 } | 187 } |
184 | 188 |
185 media::AudioParameters params_; | 189 media::AudioParameters params_; |
186 blink::WebMediaStreamSource blink_source_; | 190 blink::WebMediaStreamSource blink_source_; |
| 191 WebRtcAudioCapturer* capturer_; // Owned by |blink_source_|. |
187 scoped_refptr<MockCapturerSource> capturer_source_; | 192 scoped_refptr<MockCapturerSource> capturer_source_; |
188 scoped_refptr<WebRtcAudioCapturer> capturer_; | |
189 }; | 193 }; |
190 | 194 |
191 // Creates a capturer and audio track, fakes its audio thread, and | 195 // Creates a capturer and audio track, fakes its audio thread, and |
192 // connect/disconnect the sink to the audio track on the fly, the sink should | 196 // connect/disconnect the sink to the audio track on the fly, the sink should |
193 // get data callback when the track is connected to the capturer but not when | 197 // get data callback when the track is connected to the capturer but not when |
194 // the track is disconnected from the capturer. | 198 // the track is disconnected from the capturer. |
195 TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) { | 199 TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) { |
196 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 200 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
197 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 201 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
198 scoped_ptr<WebRtcLocalAudioTrack> track( | 202 scoped_ptr<WebRtcLocalAudioTrack> track( |
199 new WebRtcLocalAudioTrack(adapter.get(), capturer_, NULL)); | 203 new WebRtcLocalAudioTrack(adapter.get())); |
200 track->Start(); | 204 capturer_->AddTrack(track.get()); |
201 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); | 205 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); |
202 | 206 |
203 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 207 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
204 base::WaitableEvent event(false, false); | 208 base::WaitableEvent event(false, false); |
205 EXPECT_CALL(*sink, FormatIsSet()); | 209 EXPECT_CALL(*sink, FormatIsSet()); |
206 EXPECT_CALL(*sink, | 210 EXPECT_CALL(*sink, |
207 CaptureData()).Times(AtLeast(1)) | 211 CaptureData()).Times(AtLeast(1)) |
208 .WillRepeatedly(SignalEvent(&event)); | 212 .WillRepeatedly(SignalEvent(&event)); |
209 track->AddSink(sink.get()); | 213 track->AddSink(sink.get()); |
210 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 214 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
211 track->RemoveSink(sink.get()); | 215 track->RemoveSink(sink.get()); |
212 | 216 |
213 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); | 217 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); |
214 capturer_->Stop(); | 218 capturer_->Stop(); |
215 } | 219 } |
216 | 220 |
217 // The same setup as ConnectAndDisconnectOneSink, but enable and disable the | 221 // The same setup as ConnectAndDisconnectOneSink, but enable and disable the |
218 // audio track on the fly. When the audio track is disabled, there is no data | 222 // audio track on the fly. When the audio track is disabled, there is no data |
219 // callback to the sink; when the audio track is enabled, there comes data | 223 // callback to the sink; when the audio track is enabled, there comes data |
220 // callback. | 224 // callback. |
221 // TODO(xians): Enable this test after resolving the racing issue that TSAN | 225 // TODO(xians): Enable this test after resolving the racing issue that TSAN |
222 // reports on MediaStreamTrack::enabled(); | 226 // reports on MediaStreamTrack::enabled(); |
223 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) { | 227 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) { |
224 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); | 228 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); |
225 EXPECT_CALL(*capturer_source_.get(), OnStart()); | 229 EXPECT_CALL(*capturer_source_.get(), OnStart()); |
226 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 230 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
227 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 231 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
228 scoped_ptr<WebRtcLocalAudioTrack> track( | 232 scoped_ptr<WebRtcLocalAudioTrack> track( |
229 new WebRtcLocalAudioTrack(adapter.get(), capturer_, NULL)); | 233 new WebRtcLocalAudioTrack(adapter.get())); |
230 track->Start(); | 234 capturer_->AddTrack(track.get()); |
231 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); | 235 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); |
232 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(false)); | 236 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(false)); |
233 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 237 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
234 const media::AudioParameters params = capturer_->source_audio_parameters(); | 238 const media::AudioParameters params = capturer_->GetInputFormat(); |
235 base::WaitableEvent event(false, false); | 239 base::WaitableEvent event(false, false); |
236 EXPECT_CALL(*sink, FormatIsSet()).Times(1); | 240 EXPECT_CALL(*sink, FormatIsSet()).Times(1); |
237 EXPECT_CALL(*sink, CaptureData()).Times(0); | 241 EXPECT_CALL(*sink, CaptureData()).Times(0); |
238 EXPECT_EQ(sink->audio_params().frames_per_buffer(), | 242 EXPECT_EQ(sink->audio_params().frames_per_buffer(), |
239 params.sample_rate() / 100); | 243 params.sample_rate() / 100); |
240 track->AddSink(sink.get()); | 244 track->AddSink(sink.get()); |
241 EXPECT_FALSE(event.TimedWait(TestTimeouts::tiny_timeout())); | 245 EXPECT_FALSE(event.TimedWait(TestTimeouts::tiny_timeout())); |
242 | 246 |
243 event.Reset(); | 247 event.Reset(); |
244 EXPECT_CALL(*sink, CaptureData()).Times(AtLeast(1)) | 248 EXPECT_CALL(*sink, CaptureData()).Times(AtLeast(1)) |
245 .WillRepeatedly(SignalEvent(&event)); | 249 .WillRepeatedly(SignalEvent(&event)); |
246 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(true)); | 250 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(true)); |
247 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 251 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
248 track->RemoveSink(sink.get()); | 252 track->RemoveSink(sink.get()); |
249 | 253 |
250 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); | 254 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); |
251 capturer_->Stop(); | 255 capturer_->Stop(); |
252 track.reset(); | 256 track.reset(); |
253 } | 257 } |
254 | 258 |
255 // Create multiple audio tracks and enable/disable them, verify that the audio | 259 // Create multiple audio tracks and enable/disable them, verify that the audio |
256 // callbacks appear/disappear. | 260 // callbacks appear/disappear. |
257 // Flaky due to a data race, see http://crbug.com/295418 | 261 // Flaky due to a data race, see http://crbug.com/295418 |
258 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) { | 262 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) { |
259 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( | 263 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( |
260 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 264 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
261 scoped_ptr<WebRtcLocalAudioTrack> track_1( | 265 scoped_ptr<WebRtcLocalAudioTrack> track_1( |
262 new WebRtcLocalAudioTrack(adapter_1.get(), capturer_, NULL)); | 266 new WebRtcLocalAudioTrack(adapter_1.get())); |
263 track_1->Start(); | 267 capturer_->AddTrack(track_1.get()); |
264 EXPECT_TRUE(track_1->GetAudioAdapter()->enabled()); | 268 EXPECT_TRUE(track_1->GetAudioAdapter()->enabled()); |
265 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); | 269 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); |
266 const media::AudioParameters params = capturer_->source_audio_parameters(); | 270 const media::AudioParameters params = capturer_->GetInputFormat(); |
267 base::WaitableEvent event_1(false, false); | 271 base::WaitableEvent event_1(false, false); |
268 EXPECT_CALL(*sink_1, FormatIsSet()).WillOnce(Return()); | 272 EXPECT_CALL(*sink_1, FormatIsSet()).WillOnce(Return()); |
269 EXPECT_CALL(*sink_1, CaptureData()).Times(AtLeast(1)) | 273 EXPECT_CALL(*sink_1, CaptureData()).Times(AtLeast(1)) |
270 .WillRepeatedly(SignalEvent(&event_1)); | 274 .WillRepeatedly(SignalEvent(&event_1)); |
271 EXPECT_EQ(sink_1->audio_params().frames_per_buffer(), | 275 EXPECT_EQ(sink_1->audio_params().frames_per_buffer(), |
272 params.sample_rate() / 100); | 276 params.sample_rate() / 100); |
273 track_1->AddSink(sink_1.get()); | 277 track_1->AddSink(sink_1.get()); |
274 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 278 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
275 | 279 |
276 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( | 280 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( |
277 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 281 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
278 scoped_ptr<WebRtcLocalAudioTrack> track_2( | 282 scoped_ptr<WebRtcLocalAudioTrack> track_2( |
279 new WebRtcLocalAudioTrack(adapter_2.get(), capturer_, NULL)); | 283 new WebRtcLocalAudioTrack(adapter_2.get())); |
280 track_2->Start(); | 284 capturer_->AddTrack(track_2.get()); |
281 EXPECT_TRUE(track_2->GetAudioAdapter()->enabled()); | 285 EXPECT_TRUE(track_2->GetAudioAdapter()->enabled()); |
282 | 286 |
283 // Verify both |sink_1| and |sink_2| get data. | 287 // Verify both |sink_1| and |sink_2| get data. |
284 event_1.Reset(); | 288 event_1.Reset(); |
285 base::WaitableEvent event_2(false, false); | 289 base::WaitableEvent event_2(false, false); |
286 | 290 |
287 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); | 291 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); |
288 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(Return()); | 292 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(Return()); |
289 EXPECT_CALL(*sink_1, CaptureData()).Times(AtLeast(1)) | 293 EXPECT_CALL(*sink_1, CaptureData()).Times(AtLeast(1)) |
290 .WillRepeatedly(SignalEvent(&event_1)); | 294 .WillRepeatedly(SignalEvent(&event_1)); |
(...skipping 17 matching lines...) Expand all Loading... |
308 track_2.reset(); | 312 track_2.reset(); |
309 } | 313 } |
310 | 314 |
311 | 315 |
312 // Start one track and verify the capturer is correctly starting its source. | 316 // Start one track and verify the capturer is correctly starting its source. |
313 // And it should be fine to not to call Stop() explicitly. | 317 // And it should be fine to not to call Stop() explicitly. |
314 TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) { | 318 TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) { |
315 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 319 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
316 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 320 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
317 scoped_ptr<WebRtcLocalAudioTrack> track( | 321 scoped_ptr<WebRtcLocalAudioTrack> track( |
318 new WebRtcLocalAudioTrack(adapter.get(), capturer_, NULL)); | 322 new WebRtcLocalAudioTrack(adapter.get())); |
319 track->Start(); | 323 capturer_->AddTrack(track.get()); |
320 | 324 |
321 // When the track goes away, it will automatically stop the | 325 // When the track goes away, it will automatically stop the |
322 // |capturer_source_|. | 326 // |capturer_source_|. |
323 EXPECT_CALL(*capturer_source_.get(), OnStop()); | 327 EXPECT_CALL(*capturer_source_.get(), OnStop()); |
324 track.reset(); | 328 track.reset(); |
325 } | 329 } |
326 | 330 |
327 // Start two tracks and verify the capturer is correctly starting its source. | 331 // Start two tracks and verify the capturer is correctly starting its source. |
328 // When the last track connected to the capturer is stopped, the source is | 332 // When the last track connected to the capturer is stopped, the source is |
329 // stopped. | 333 // stopped. |
330 TEST_F(WebRtcLocalAudioTrackTest, StartTwoAudioTracks) { | 334 TEST_F(WebRtcLocalAudioTrackTest, StartTwoAudioTracks) { |
331 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter1( | 335 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter1( |
332 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 336 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
333 scoped_ptr<WebRtcLocalAudioTrack> track1( | 337 scoped_ptr<WebRtcLocalAudioTrack> track1( |
334 new WebRtcLocalAudioTrack(adapter1.get(), capturer_, NULL)); | 338 new WebRtcLocalAudioTrack(adapter1.get())); |
335 track1->Start(); | 339 capturer_->AddTrack(track1.get()); |
336 | 340 |
337 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter2( | 341 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter2( |
338 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 342 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
339 scoped_ptr<WebRtcLocalAudioTrack> track2( | 343 scoped_ptr<WebRtcLocalAudioTrack> track2( |
340 new WebRtcLocalAudioTrack(adapter2.get(), capturer_, NULL)); | 344 new WebRtcLocalAudioTrack(adapter2.get())); |
341 track2->Start(); | 345 capturer_->AddTrack(track2.get()); |
342 | 346 |
343 track1->Stop(); | 347 track1->Stop(); |
344 // When the last track is stopped, it will automatically stop the | 348 // When the last track is stopped, it will automatically stop the |
345 // |capturer_source_|. | 349 // |capturer_source_|. |
346 EXPECT_CALL(*capturer_source_.get(), OnStop()); | 350 EXPECT_CALL(*capturer_source_.get(), OnStop()); |
347 track2->Stop(); | 351 track2->Stop(); |
348 } | 352 } |
349 | 353 |
350 // Start/Stop tracks and verify the capturer is correctly starting/stopping | 354 // Start/Stop tracks and verify the capturer is correctly starting/stopping |
351 // its source. | 355 // its source. |
352 TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { | 356 TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { |
353 base::WaitableEvent event(false, false); | 357 base::WaitableEvent event(false, false); |
354 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( | 358 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( |
355 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 359 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
356 scoped_ptr<WebRtcLocalAudioTrack> track_1( | 360 scoped_ptr<WebRtcLocalAudioTrack> track_1( |
357 new WebRtcLocalAudioTrack(adapter_1.get(), capturer_, NULL)); | 361 new WebRtcLocalAudioTrack(adapter_1.get())); |
358 track_1->Start(); | 362 capturer_->AddTrack(track_1.get()); |
359 | 363 |
360 // Verify the data flow by connecting the sink to |track_1|. | 364 // Verify the data flow by connecting the sink to |track_1|. |
361 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 365 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
362 event.Reset(); | 366 event.Reset(); |
363 EXPECT_CALL(*sink, FormatIsSet()).WillOnce(SignalEvent(&event)); | 367 EXPECT_CALL(*sink, FormatIsSet()).WillOnce(SignalEvent(&event)); |
364 EXPECT_CALL(*sink, CaptureData()) | 368 EXPECT_CALL(*sink, CaptureData()) |
365 .Times(AnyNumber()).WillRepeatedly(Return()); | 369 .Times(AnyNumber()).WillRepeatedly(Return()); |
366 track_1->AddSink(sink.get()); | 370 track_1->AddSink(sink.get()); |
367 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 371 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
368 | 372 |
369 // Start the second audio track will not start the |capturer_source_| | 373 // Start the second audio track will not start the |capturer_source_| |
370 // since it has been started. | 374 // since it has been started. |
371 EXPECT_CALL(*capturer_source_.get(), OnStart()).Times(0); | 375 EXPECT_CALL(*capturer_source_.get(), OnStart()).Times(0); |
372 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( | 376 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( |
373 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 377 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
374 scoped_ptr<WebRtcLocalAudioTrack> track_2( | 378 scoped_ptr<WebRtcLocalAudioTrack> track_2( |
375 new WebRtcLocalAudioTrack(adapter_2.get(), capturer_, NULL)); | 379 new WebRtcLocalAudioTrack(adapter_2.get())); |
376 track_2->Start(); | 380 capturer_->AddTrack(track_2.get()); |
377 | 381 |
378 // Stop the capturer will clear up the track lists in the capturer. | 382 // Stop the capturer will clear up the track lists in the capturer. |
379 EXPECT_CALL(*capturer_source_.get(), OnStop()); | 383 EXPECT_CALL(*capturer_source_.get(), OnStop()); |
380 capturer_->Stop(); | 384 capturer_->Stop(); |
381 | 385 |
382 // Adding a new track to the capturer. | 386 // Adding a new track to the capturer. |
383 track_2->AddSink(sink.get()); | 387 track_2->AddSink(sink.get()); |
384 EXPECT_CALL(*sink, FormatIsSet()).Times(0); | 388 EXPECT_CALL(*sink, FormatIsSet()).Times(0); |
385 | 389 |
386 // Stop the capturer again will not trigger stopping the source of the | 390 // Stop the capturer again will not trigger stopping the source of the |
(...skipping 10 matching lines...) Expand all Loading... |
397 DISABLED_ConnectTracksToDifferentCapturers | 401 DISABLED_ConnectTracksToDifferentCapturers |
398 #else | 402 #else |
399 #define MAYBE_ConnectTracksToDifferentCapturers \ | 403 #define MAYBE_ConnectTracksToDifferentCapturers \ |
400 ConnectTracksToDifferentCapturers | 404 ConnectTracksToDifferentCapturers |
401 #endif | 405 #endif |
402 TEST_F(WebRtcLocalAudioTrackTest, MAYBE_ConnectTracksToDifferentCapturers) { | 406 TEST_F(WebRtcLocalAudioTrackTest, MAYBE_ConnectTracksToDifferentCapturers) { |
403 // Setup the first audio track and start it. | 407 // Setup the first audio track and start it. |
404 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( | 408 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( |
405 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 409 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
406 scoped_ptr<WebRtcLocalAudioTrack> track_1( | 410 scoped_ptr<WebRtcLocalAudioTrack> track_1( |
407 new WebRtcLocalAudioTrack(adapter_1.get(), capturer_, NULL)); | 411 new WebRtcLocalAudioTrack(adapter_1.get())); |
408 track_1->Start(); | 412 capturer_->AddTrack(track_1.get()); |
409 | 413 |
410 // Verify the data flow by connecting the |sink_1| to |track_1|. | 414 // Verify the data flow by connecting the |sink_1| to |track_1|. |
411 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); | 415 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); |
412 EXPECT_CALL(*sink_1.get(), CaptureData()) | 416 EXPECT_CALL(*sink_1.get(), CaptureData()) |
413 .Times(AnyNumber()).WillRepeatedly(Return()); | 417 .Times(AnyNumber()).WillRepeatedly(Return()); |
414 EXPECT_CALL(*sink_1.get(), FormatIsSet()).Times(AnyNumber()); | 418 EXPECT_CALL(*sink_1.get(), FormatIsSet()).Times(AnyNumber()); |
415 track_1->AddSink(sink_1.get()); | 419 track_1->AddSink(sink_1.get()); |
416 | 420 |
417 // Create a new capturer with new source with different audio format. | 421 // Create a new capturer with new source with different audio format. |
418 MockMediaConstraintFactory constraint_factory; | 422 MockMediaConstraintFactory constraint_factory; |
419 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE, | 423 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE, |
420 std::string(), std::string()); | 424 std::string(), std::string()); |
421 scoped_refptr<WebRtcAudioCapturer> new_capturer( | 425 scoped_ptr<WebRtcAudioCapturer> new_capturer( |
422 WebRtcAudioCapturer::CreateCapturer( | 426 WebRtcAudioCapturer::CreateCapturer( |
423 -1, device, constraint_factory.CreateWebMediaConstraints(), NULL, | 427 -1, device, constraint_factory.CreateWebMediaConstraints(), NULL, |
424 NULL)); | 428 NULL)); |
425 scoped_refptr<MockCapturerSource> new_source( | 429 scoped_refptr<MockCapturerSource> new_source( |
426 new MockCapturerSource(new_capturer.get())); | 430 new MockCapturerSource(new_capturer.get())); |
427 EXPECT_CALL(*new_source.get(), OnInitialize(_, new_capturer.get(), -1)); | 431 EXPECT_CALL(*new_source.get(), OnInitialize(_, new_capturer.get(), -1)); |
428 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true)); | 432 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true)); |
429 EXPECT_CALL(*new_source.get(), OnStart()); | 433 EXPECT_CALL(*new_source.get(), OnStart()); |
430 | 434 |
431 media::AudioParameters new_param( | 435 media::AudioParameters new_param( |
432 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 436 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
433 media::CHANNEL_LAYOUT_MONO, 44100, 16, 441); | 437 media::CHANNEL_LAYOUT_MONO, 44100, 16, 441); |
434 new_capturer->SetCapturerSource(new_source, new_param); | 438 new_capturer->SetCapturerSource(new_source, new_param); |
435 | 439 |
436 // Setup the second audio track, connect it to the new capturer and start it. | 440 // Setup the second audio track, connect it to the new capturer and start it. |
437 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( | 441 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( |
438 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 442 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
439 scoped_ptr<WebRtcLocalAudioTrack> track_2( | 443 scoped_ptr<WebRtcLocalAudioTrack> track_2( |
440 new WebRtcLocalAudioTrack(adapter_2.get(), new_capturer, NULL)); | 444 new WebRtcLocalAudioTrack(adapter_2.get())); |
441 track_2->Start(); | 445 new_capturer->AddTrack(track_2.get()); |
442 | 446 |
443 // Verify the data flow by connecting the |sink_2| to |track_2|. | 447 // Verify the data flow by connecting the |sink_2| to |track_2|. |
444 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); | 448 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); |
445 base::WaitableEvent event(false, false); | 449 base::WaitableEvent event(false, false); |
446 EXPECT_CALL(*sink_2, CaptureData()) | 450 EXPECT_CALL(*sink_2, CaptureData()) |
447 .Times(AnyNumber()).WillRepeatedly(Return()); | 451 .Times(AnyNumber()).WillRepeatedly(Return()); |
448 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(SignalEvent(&event)); | 452 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(SignalEvent(&event)); |
449 track_2->AddSink(sink_2.get()); | 453 track_2->AddSink(sink_2.get()); |
450 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 454 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
451 | 455 |
(...skipping 12 matching lines...) Expand all Loading... |
464 // Make sure a audio track can deliver packets with a buffer size smaller than | 468 // Make sure a audio track can deliver packets with a buffer size smaller than |
465 // 10ms when it is not connected with a peer connection. | 469 // 10ms when it is not connected with a peer connection. |
466 TEST_F(WebRtcLocalAudioTrackTest, TrackWorkWithSmallBufferSize) { | 470 TEST_F(WebRtcLocalAudioTrackTest, TrackWorkWithSmallBufferSize) { |
467 // Setup a capturer which works with a buffer size smaller than 10ms. | 471 // Setup a capturer which works with a buffer size smaller than 10ms. |
468 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 472 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
469 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 128); | 473 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 128); |
470 | 474 |
471 // Create a capturer with new source which works with the format above. | 475 // Create a capturer with new source which works with the format above. |
472 MockMediaConstraintFactory factory; | 476 MockMediaConstraintFactory factory; |
473 factory.DisableDefaultAudioConstraints(); | 477 factory.DisableDefaultAudioConstraints(); |
474 scoped_refptr<WebRtcAudioCapturer> capturer( | 478 scoped_ptr<WebRtcAudioCapturer> capturer(WebRtcAudioCapturer::CreateCapturer( |
475 WebRtcAudioCapturer::CreateCapturer( | 479 -1, |
476 -1, StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "", "", | 480 StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "", "", params.sample_rate(), |
477 params.sample_rate(), params.channel_layout(), | 481 params.channel_layout(), params.frames_per_buffer()), |
478 params.frames_per_buffer()), | 482 factory.CreateWebMediaConstraints(), NULL, NULL)); |
479 factory.CreateWebMediaConstraints(), NULL, NULL)); | |
480 scoped_refptr<MockCapturerSource> source( | 483 scoped_refptr<MockCapturerSource> source( |
481 new MockCapturerSource(capturer.get())); | 484 new MockCapturerSource(capturer.get())); |
482 EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), -1)); | 485 EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), -1)); |
483 EXPECT_CALL(*source.get(), SetAutomaticGainControl(true)); | 486 EXPECT_CALL(*source.get(), SetAutomaticGainControl(true)); |
484 EXPECT_CALL(*source.get(), OnStart()); | 487 EXPECT_CALL(*source.get(), OnStart()); |
485 capturer->SetCapturerSource(source, params); | 488 capturer->SetCapturerSource(source, params); |
486 | 489 |
487 // Setup a audio track, connect it to the capturer and start it. | 490 // Setup a audio track, connect it to the capturer and start it. |
488 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 491 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
489 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 492 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
490 scoped_ptr<WebRtcLocalAudioTrack> track( | 493 scoped_ptr<WebRtcLocalAudioTrack> track( |
491 new WebRtcLocalAudioTrack(adapter.get(), capturer, NULL)); | 494 new WebRtcLocalAudioTrack(adapter.get())); |
492 track->Start(); | 495 capturer->AddTrack(track.get()); |
493 | 496 |
494 // Verify the data flow by connecting the |sink| to |track|. | 497 // Verify the data flow by connecting the |sink| to |track|. |
495 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 498 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
496 base::WaitableEvent event(false, false); | 499 base::WaitableEvent event(false, false); |
497 EXPECT_CALL(*sink, FormatIsSet()).Times(1); | 500 EXPECT_CALL(*sink, FormatIsSet()).Times(1); |
498 // Verify the sinks are getting the packets with an expecting buffer size. | 501 // Verify the sinks are getting the packets with an expecting buffer size. |
499 #if defined(OS_ANDROID) | 502 #if defined(OS_ANDROID) |
500 const int expected_buffer_size = params.sample_rate() / 100; | 503 const int expected_buffer_size = params.sample_rate() / 100; |
501 #else | 504 #else |
502 const int expected_buffer_size = params.frames_per_buffer(); | 505 const int expected_buffer_size = params.frames_per_buffer(); |
503 #endif | 506 #endif |
504 EXPECT_CALL(*sink, CaptureData()) | 507 EXPECT_CALL(*sink, CaptureData()) |
505 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); | 508 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); |
506 track->AddSink(sink.get()); | 509 track->AddSink(sink.get()); |
507 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 510 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
508 EXPECT_EQ(expected_buffer_size, sink->audio_params().frames_per_buffer()); | 511 EXPECT_EQ(expected_buffer_size, sink->audio_params().frames_per_buffer()); |
509 | 512 |
510 // Stopping the new source will stop the second track. | 513 // Stopping the new source will stop the second track. |
511 EXPECT_CALL(*source.get(), OnStop()).Times(1); | 514 EXPECT_CALL(*source.get(), OnStop()).Times(1); |
512 capturer->Stop(); | 515 capturer->Stop(); |
513 | 516 |
514 // Even though this test don't use |capturer_source_| it will be stopped | 517 // Even though this test don't use |capturer_source_| it will be stopped |
515 // during teardown of the test harness. | 518 // during teardown of the test harness. |
516 EXPECT_CALL(*capturer_source_.get(), OnStop()); | 519 EXPECT_CALL(*capturer_source_.get(), OnStop()); |
517 } | 520 } |
518 | 521 |
519 } // namespace content | 522 } // namespace content |
OLD | NEW |