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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 for (int i = 0; i < kNumberOfNetworkChannels; ++i) { | 174 for (int i = 0; i < kNumberOfNetworkChannels; ++i) { |
175 static_cast<webrtc::AudioTrackInterface*>(track.get())-> | 175 static_cast<webrtc::AudioTrackInterface*>(track.get())-> |
176 GetRenderer()->AddChannel(i); | 176 GetRenderer()->AddChannel(i); |
177 } | 177 } |
178 scoped_ptr<MockWebRtcAudioCapturerSink> sink( | 178 scoped_ptr<MockWebRtcAudioCapturerSink> sink( |
179 new MockWebRtcAudioCapturerSink()); | 179 new MockWebRtcAudioCapturerSink()); |
180 const media::AudioParameters params = capturer_->audio_parameters(); | 180 const media::AudioParameters params = capturer_->audio_parameters(); |
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 false, | 190 // TODO(tommi): Change to |false| when issue 277134 is fixed. |
191 false)).Times(AtLeast(1)) | 191 true, |
| 192 false)).Times(AtLeast(1)) |
192 .WillRepeatedly(SignalEvent(&event)); | 193 .WillRepeatedly(SignalEvent(&event)); |
193 track->AddSink(sink.get()); | 194 track->AddSink(sink.get()); |
194 | 195 |
195 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 196 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
196 track->RemoveSink(sink.get()); | 197 track->RemoveSink(sink.get()); |
197 | 198 |
198 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); | 199 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); |
199 track->Stop(); | 200 track->Stop(); |
200 track = NULL; | 201 track = NULL; |
201 } | 202 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 track_1->Start(); | 262 track_1->Start(); |
262 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> | 263 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> |
263 GetRenderer()->AddChannel(0); | 264 GetRenderer()->AddChannel(0); |
264 EXPECT_TRUE(track_1->enabled()); | 265 EXPECT_TRUE(track_1->enabled()); |
265 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( | 266 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( |
266 new MockWebRtcAudioCapturerSink()); | 267 new MockWebRtcAudioCapturerSink()); |
267 const media::AudioParameters params = capturer_->audio_parameters(); | 268 const media::AudioParameters params = capturer_->audio_parameters(); |
268 base::WaitableEvent event_1(false, false); | 269 base::WaitableEvent event_1(false, false); |
269 EXPECT_CALL(*sink_1, SetCaptureFormat(_)).WillOnce(Return()); | 270 EXPECT_CALL(*sink_1, SetCaptureFormat(_)).WillOnce(Return()); |
270 EXPECT_CALL(*sink_1, | 271 EXPECT_CALL(*sink_1, |
271 CaptureData(1, | 272 CaptureData(1, |
272 params.sample_rate(), | 273 params.sample_rate(), |
273 params.channels(), | 274 params.channels(), |
274 params.frames_per_buffer(), | 275 params.frames_per_buffer(), |
275 0, | 276 0, |
276 0, | 277 0, |
277 false, | 278 // TODO(tommi): Change to |false| when issue 277134 is fixed. |
278 false)).Times(AtLeast(1)) | 279 true, |
| 280 false)).Times(AtLeast(1)) |
279 .WillRepeatedly(SignalEvent(&event_1)); | 281 .WillRepeatedly(SignalEvent(&event_1)); |
280 track_1->AddSink(sink_1.get()); | 282 track_1->AddSink(sink_1.get()); |
281 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 283 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
282 | 284 |
283 scoped_refptr<WebRtcLocalAudioTrack> track_2 = | 285 scoped_refptr<WebRtcLocalAudioTrack> track_2 = |
284 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); | 286 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); |
285 track_2->Start(); | 287 track_2->Start(); |
286 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> | 288 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> |
287 GetRenderer()->AddChannel(1); | 289 GetRenderer()->AddChannel(1); |
288 EXPECT_TRUE(track_2->enabled()); | 290 EXPECT_TRUE(track_2->enabled()); |
289 | 291 |
290 // Verify both |sink_1| and |sink_2| get data. | 292 // Verify both |sink_1| and |sink_2| get data. |
291 event_1.Reset(); | 293 event_1.Reset(); |
292 base::WaitableEvent event_2(false, false); | 294 base::WaitableEvent event_2(false, false); |
293 | 295 |
294 scoped_ptr<MockWebRtcAudioCapturerSink> sink_2( | 296 scoped_ptr<MockWebRtcAudioCapturerSink> sink_2( |
295 new MockWebRtcAudioCapturerSink()); | 297 new MockWebRtcAudioCapturerSink()); |
296 EXPECT_CALL(*sink_2, SetCaptureFormat(_)).WillOnce(Return()); | 298 EXPECT_CALL(*sink_2, SetCaptureFormat(_)).WillOnce(Return()); |
297 EXPECT_CALL(*sink_1, | 299 EXPECT_CALL(*sink_1, |
298 CaptureData(1, | 300 CaptureData(1, |
299 params.sample_rate(), | 301 params.sample_rate(), |
300 params.channels(), | 302 params.channels(), |
301 params.frames_per_buffer(), | 303 params.frames_per_buffer(), |
302 0, | 304 0, |
303 0, | 305 0, |
304 false, | 306 // TODO(tommi): Change to |false| when issue 277134 is fixed. |
305 false)).Times(AtLeast(1)) | 307 true, |
| 308 false)).Times(AtLeast(1)) |
306 .WillRepeatedly(SignalEvent(&event_1)); | 309 .WillRepeatedly(SignalEvent(&event_1)); |
307 EXPECT_CALL(*sink_2, | 310 EXPECT_CALL(*sink_2, |
308 CaptureData(1, | 311 CaptureData(1, |
309 params.sample_rate(), | 312 params.sample_rate(), |
310 params.channels(), | 313 params.channels(), |
311 params.frames_per_buffer(), | 314 params.frames_per_buffer(), |
312 0, | 315 0, |
313 0, | 316 0, |
314 false, | 317 // TODO(tommi): Change to |false| when issue 277134 is fixed. |
315 false)).Times(AtLeast(1)) | 318 true, |
| 319 false)).Times(AtLeast(1)) |
316 .WillRepeatedly(SignalEvent(&event_2)); | 320 .WillRepeatedly(SignalEvent(&event_2)); |
317 track_2->AddSink(sink_2.get()); | 321 track_2->AddSink(sink_2.get()); |
318 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 322 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
319 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); | 323 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); |
320 | 324 |
321 track_1->RemoveSink(sink_1.get()); | 325 track_1->RemoveSink(sink_1.get()); |
322 track_1->Stop(); | 326 track_1->Stop(); |
323 track_1 = NULL; | 327 track_1 = NULL; |
324 | 328 |
325 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); | 329 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); |
(...skipping 28 matching lines...) Expand all Loading... |
354 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); | 358 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); |
355 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> | 359 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> |
356 GetRenderer()->AddChannel(0); | 360 GetRenderer()->AddChannel(0); |
357 track_1->Start(); | 361 track_1->Start(); |
358 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 362 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
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<MockWebRtcAudioCapturerSink> sink( | 365 scoped_ptr<MockWebRtcAudioCapturerSink> sink( |
362 new MockWebRtcAudioCapturerSink()); | 366 new MockWebRtcAudioCapturerSink()); |
363 event.Reset(); | 367 event.Reset(); |
364 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, false, false)) | 368 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, |
| 369 // TODO(tommi): Change to |false| when issue 277134 is fixed. |
| 370 true, |
| 371 false)) |
365 .Times(AnyNumber()).WillRepeatedly(Return()); | 372 .Times(AnyNumber()).WillRepeatedly(Return()); |
366 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1); | 373 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1); |
367 track_1->AddSink(sink.get()); | 374 track_1->AddSink(sink.get()); |
368 | 375 |
369 // Start the second audio track will not start the |capturer_source_| | 376 // Start the second audio track will not start the |capturer_source_| |
370 // since it has been started. | 377 // since it has been started. |
371 EXPECT_CALL(*capturer_source_.get(), Start()).Times(0); | 378 EXPECT_CALL(*capturer_source_.get(), Start()).Times(0); |
372 scoped_refptr<WebRtcLocalAudioTrack> track_2 = | 379 scoped_refptr<WebRtcLocalAudioTrack> track_2 = |
373 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); | 380 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); |
374 track_2->Start(); | 381 track_2->Start(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) { | 441 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) { |
435 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> | 442 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> |
436 GetRenderer()->AddChannel(i); | 443 GetRenderer()->AddChannel(i); |
437 } | 444 } |
438 // 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|. |
439 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( | 446 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( |
440 new MockWebRtcAudioCapturerSink()); | 447 new MockWebRtcAudioCapturerSink()); |
441 EXPECT_CALL( | 448 EXPECT_CALL( |
442 *sink_1.get(), | 449 *sink_1.get(), |
443 CaptureData( | 450 CaptureData( |
444 kNumberOfNetworkChannelsForTrack1, 48000, 2, _, 0, 0, false, false)) | 451 kNumberOfNetworkChannelsForTrack1, 48000, 2, _, 0, 0, |
| 452 // TODO(tommi): Change to |false| when issue 277134 is fixed. |
| 453 true, |
| 454 false)) |
445 .Times(AnyNumber()).WillRepeatedly(Return()); | 455 .Times(AnyNumber()).WillRepeatedly(Return()); |
446 EXPECT_CALL(*sink_1.get(), SetCaptureFormat(_)).Times(1); | 456 EXPECT_CALL(*sink_1.get(), SetCaptureFormat(_)).Times(1); |
447 track_1->AddSink(sink_1.get()); | 457 track_1->AddSink(sink_1.get()); |
448 | 458 |
449 // Create a new capturer with new source with different audio format. | 459 // Create a new capturer with new source with different audio format. |
450 scoped_refptr<WebRtcAudioCapturer> new_capturer( | 460 scoped_refptr<WebRtcAudioCapturer> new_capturer( |
451 WebRtcAudioCapturer::CreateCapturer()); | 461 WebRtcAudioCapturer::CreateCapturer()); |
452 scoped_refptr<MockCapturerSource> new_source(new MockCapturerSource()); | 462 scoped_refptr<MockCapturerSource> new_source(new MockCapturerSource()); |
453 EXPECT_CALL(*new_source.get(), Initialize(_, new_capturer.get(), 0)) | 463 EXPECT_CALL(*new_source.get(), Initialize(_, new_capturer.get(), 0)) |
454 .WillOnce(Return()); | 464 .WillOnce(Return()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 audio_thread->Stop(); | 505 audio_thread->Stop(); |
496 audio_thread.reset(); | 506 audio_thread.reset(); |
497 | 507 |
498 // Stop the first audio track. | 508 // Stop the first audio track. |
499 EXPECT_CALL(*capturer_source_.get(), Stop()); | 509 EXPECT_CALL(*capturer_source_.get(), Stop()); |
500 track_1->Stop(); | 510 track_1->Stop(); |
501 track_1 = NULL; | 511 track_1 = NULL; |
502 } | 512 } |
503 | 513 |
504 } // namespace content | 514 } // namespace content |
OLD | NEW |