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/synchronization/waitable_event.h" | 5 #include "base/synchronization/waitable_event.h" |
6 #include "base/test/test_timeouts.h" | 6 #include "base/test/test_timeouts.h" |
7 #include "content/renderer/media/webrtc_audio_capturer.h" | 7 #include "content/renderer/media/webrtc_audio_capturer.h" |
8 #include "content/renderer/media/webrtc_local_audio_track.h" | 8 #include "content/renderer/media/webrtc_local_audio_track.h" |
9 #include "media/audio/audio_parameters.h" | 9 #include "media/audio/audio_parameters.h" |
10 #include "media/base/audio_bus.h" | 10 #include "media/base/audio_bus.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 base::WaitableEvent event(false, false); | 181 base::WaitableEvent event(false, false); |
182 EXPECT_CALL(*sink, SetCaptureFormat(_)).WillOnce(Return()); | 182 EXPECT_CALL(*sink, SetCaptureFormat(_)).WillOnce(Return()); |
183 EXPECT_CALL(*sink, | 183 EXPECT_CALL(*sink, |
184 CaptureData(kNumberOfNetworkChannels, | 184 CaptureData(kNumberOfNetworkChannels, |
185 params.sample_rate(), | 185 params.sample_rate(), |
186 params.channels(), | 186 params.channels(), |
187 params.frames_per_buffer(), | 187 params.frames_per_buffer(), |
188 0, | 188 0, |
189 0, | 189 0, |
190 // TODO(tommi): Change to |false| when issue 277134 is fixed. | 190 // TODO(tommi): Change to |false| when issue 277134 is fixed. |
191 true, | 191 _, |
192 false)).Times(AtLeast(1)) | 192 false)).Times(AtLeast(1)) |
193 .WillRepeatedly(SignalEvent(&event)); | 193 .WillRepeatedly(SignalEvent(&event)); |
194 track->AddSink(sink.get()); | 194 track->AddSink(sink.get()); |
195 | 195 |
196 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 196 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
197 track->RemoveSink(sink.get()); | 197 track->RemoveSink(sink.get()); |
198 | 198 |
199 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); | 199 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); |
200 track->Stop(); | 200 track->Stop(); |
201 track = NULL; | 201 track = NULL; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 base::WaitableEvent event_1(false, false); | 269 base::WaitableEvent event_1(false, false); |
270 EXPECT_CALL(*sink_1, SetCaptureFormat(_)).WillOnce(Return()); | 270 EXPECT_CALL(*sink_1, SetCaptureFormat(_)).WillOnce(Return()); |
271 EXPECT_CALL(*sink_1, | 271 EXPECT_CALL(*sink_1, |
272 CaptureData(1, | 272 CaptureData(1, |
273 params.sample_rate(), | 273 params.sample_rate(), |
274 params.channels(), | 274 params.channels(), |
275 params.frames_per_buffer(), | 275 params.frames_per_buffer(), |
276 0, | 276 0, |
277 0, | 277 0, |
278 // TODO(tommi): Change to |false| when issue 277134 is fixed. | 278 // TODO(tommi): Change to |false| when issue 277134 is fixed. |
279 true, | 279 _, |
280 false)).Times(AtLeast(1)) | 280 false)).Times(AtLeast(1)) |
281 .WillRepeatedly(SignalEvent(&event_1)); | 281 .WillRepeatedly(SignalEvent(&event_1)); |
282 track_1->AddSink(sink_1.get()); | 282 track_1->AddSink(sink_1.get()); |
283 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 283 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
284 | 284 |
285 scoped_refptr<WebRtcLocalAudioTrack> track_2 = | 285 scoped_refptr<WebRtcLocalAudioTrack> track_2 = |
286 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); | 286 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); |
287 track_2->Start(); | 287 track_2->Start(); |
288 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> | 288 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> |
289 GetRenderer()->AddChannel(1); | 289 GetRenderer()->AddChannel(1); |
290 EXPECT_TRUE(track_2->enabled()); | 290 EXPECT_TRUE(track_2->enabled()); |
291 | 291 |
292 // Verify both |sink_1| and |sink_2| get data. | 292 // Verify both |sink_1| and |sink_2| get data. |
293 event_1.Reset(); | 293 event_1.Reset(); |
294 base::WaitableEvent event_2(false, false); | 294 base::WaitableEvent event_2(false, false); |
295 | 295 |
296 scoped_ptr<MockWebRtcAudioCapturerSink> sink_2( | 296 scoped_ptr<MockWebRtcAudioCapturerSink> sink_2( |
297 new MockWebRtcAudioCapturerSink()); | 297 new MockWebRtcAudioCapturerSink()); |
298 EXPECT_CALL(*sink_2, SetCaptureFormat(_)).WillOnce(Return()); | 298 EXPECT_CALL(*sink_2, SetCaptureFormat(_)).WillOnce(Return()); |
299 EXPECT_CALL(*sink_1, | 299 EXPECT_CALL(*sink_1, |
300 CaptureData(1, | 300 CaptureData(1, |
301 params.sample_rate(), | 301 params.sample_rate(), |
302 params.channels(), | 302 params.channels(), |
303 params.frames_per_buffer(), | 303 params.frames_per_buffer(), |
304 0, | 304 0, |
305 0, | 305 0, |
306 // TODO(tommi): Change to |false| when issue 277134 is fixed. | 306 // TODO(tommi): Change to |false| when issue 277134 is fixed. |
307 true, | 307 _, |
308 false)).Times(AtLeast(1)) | 308 false)).Times(AtLeast(1)) |
309 .WillRepeatedly(SignalEvent(&event_1)); | 309 .WillRepeatedly(SignalEvent(&event_1)); |
310 EXPECT_CALL(*sink_2, | 310 EXPECT_CALL(*sink_2, |
311 CaptureData(1, | 311 CaptureData(1, |
312 params.sample_rate(), | 312 params.sample_rate(), |
313 params.channels(), | 313 params.channels(), |
314 params.frames_per_buffer(), | 314 params.frames_per_buffer(), |
315 0, | 315 0, |
316 0, | 316 0, |
317 // TODO(tommi): Change to |false| when issue 277134 is fixed. | 317 // TODO(tommi): Change to |false| when issue 277134 is fixed. |
318 true, | 318 _, |
319 false)).Times(AtLeast(1)) | 319 false)).Times(AtLeast(1)) |
320 .WillRepeatedly(SignalEvent(&event_2)); | 320 .WillRepeatedly(SignalEvent(&event_2)); |
321 track_2->AddSink(sink_2.get()); | 321 track_2->AddSink(sink_2.get()); |
322 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 322 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
323 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); | 323 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); |
324 | 324 |
325 track_1->RemoveSink(sink_1.get()); | 325 track_1->RemoveSink(sink_1.get()); |
326 track_1->Stop(); | 326 track_1->Stop(); |
327 track_1 = NULL; | 327 track_1 = NULL; |
328 | 328 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 GetRenderer()->AddChannel(0); | 360 GetRenderer()->AddChannel(0); |
361 track_1->Start(); | 361 track_1->Start(); |
362 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 362 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
363 | 363 |
364 // Verify the data flow by connecting the sink to |track_1|. | 364 // Verify the data flow by connecting the sink to |track_1|. |
365 scoped_ptr<MockWebRtcAudioCapturerSink> sink( | 365 scoped_ptr<MockWebRtcAudioCapturerSink> sink( |
366 new MockWebRtcAudioCapturerSink()); | 366 new MockWebRtcAudioCapturerSink()); |
367 event.Reset(); | 367 event.Reset(); |
368 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, | 368 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, |
369 // TODO(tommi): Change to |false| when issue 277134 is fixed. | 369 // TODO(tommi): Change to |false| when issue 277134 is fixed. |
370 true, | 370 _, |
371 false)) | 371 false)) |
372 .Times(AnyNumber()).WillRepeatedly(Return()); | 372 .Times(AnyNumber()).WillRepeatedly(Return()); |
373 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1); | 373 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1); |
374 track_1->AddSink(sink.get()); | 374 track_1->AddSink(sink.get()); |
375 | 375 |
376 // Start the second audio track will not start the |capturer_source_| | 376 // Start the second audio track will not start the |capturer_source_| |
377 // since it has been started. | 377 // since it has been started. |
378 EXPECT_CALL(*capturer_source_.get(), Start()).Times(0); | 378 EXPECT_CALL(*capturer_source_.get(), Start()).Times(0); |
379 scoped_refptr<WebRtcLocalAudioTrack> track_2 = | 379 scoped_refptr<WebRtcLocalAudioTrack> track_2 = |
380 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); | 380 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 GetRenderer()->AddChannel(i); | 443 GetRenderer()->AddChannel(i); |
444 } | 444 } |
445 // Verify the data flow by connecting the |sink_1| to |track_1|. | 445 // Verify the data flow by connecting the |sink_1| to |track_1|. |
446 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( | 446 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( |
447 new MockWebRtcAudioCapturerSink()); | 447 new MockWebRtcAudioCapturerSink()); |
448 EXPECT_CALL( | 448 EXPECT_CALL( |
449 *sink_1.get(), | 449 *sink_1.get(), |
450 CaptureData( | 450 CaptureData( |
451 kNumberOfNetworkChannelsForTrack1, 48000, 2, _, 0, 0, | 451 kNumberOfNetworkChannelsForTrack1, 48000, 2, _, 0, 0, |
452 // TODO(tommi): Change to |false| when issue 277134 is fixed. | 452 // TODO(tommi): Change to |false| when issue 277134 is fixed. |
453 true, | 453 _, |
454 false)) | 454 false)) |
455 .Times(AnyNumber()).WillRepeatedly(Return()); | 455 .Times(AnyNumber()).WillRepeatedly(Return()); |
456 EXPECT_CALL(*sink_1.get(), SetCaptureFormat(_)).Times(1); | 456 EXPECT_CALL(*sink_1.get(), SetCaptureFormat(_)).Times(1); |
457 track_1->AddSink(sink_1.get()); | 457 track_1->AddSink(sink_1.get()); |
458 | 458 |
459 // Create a new capturer with new source with different audio format. | 459 // Create a new capturer with new source with different audio format. |
460 scoped_refptr<WebRtcAudioCapturer> new_capturer( | 460 scoped_refptr<WebRtcAudioCapturer> new_capturer( |
461 WebRtcAudioCapturer::CreateCapturer()); | 461 WebRtcAudioCapturer::CreateCapturer()); |
462 scoped_refptr<MockCapturerSource> new_source(new MockCapturerSource()); | 462 scoped_refptr<MockCapturerSource> new_source(new MockCapturerSource()); |
463 EXPECT_CALL(*new_source.get(), Initialize(_, new_capturer.get(), 0)) | 463 EXPECT_CALL(*new_source.get(), Initialize(_, new_capturer.get(), 0)) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 audio_thread->Stop(); | 505 audio_thread->Stop(); |
506 audio_thread.reset(); | 506 audio_thread.reset(); |
507 | 507 |
508 // Stop the first audio track. | 508 // Stop the first audio track. |
509 EXPECT_CALL(*capturer_source_.get(), Stop()); | 509 EXPECT_CALL(*capturer_source_.get(), Stop()); |
510 track_1->Stop(); | 510 track_1->Stop(); |
511 track_1 = NULL; | 511 track_1 = NULL; |
512 } | 512 } |
513 | 513 |
514 } // namespace content | 514 } // namespace content |
OLD | NEW |