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/rtc_media_constraints.h" | 7 #include "content/renderer/media/rtc_media_constraints.h" |
8 #include "content/renderer/media/webrtc_audio_capturer.h" | 8 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 9 #include "content/renderer/media/webrtc_audio_device_impl.h" |
9 #include "content/renderer/media/webrtc_local_audio_source_provider.h" | 10 #include "content/renderer/media/webrtc_local_audio_source_provider.h" |
10 #include "content/renderer/media/webrtc_local_audio_track.h" | 11 #include "content/renderer/media/webrtc_local_audio_track.h" |
11 #include "media/audio/audio_parameters.h" | 12 #include "media/audio/audio_parameters.h" |
12 #include "media/base/audio_bus.h" | 13 #include "media/base/audio_bus.h" |
13 #include "media/base/audio_capturer_source.h" | 14 #include "media/base/audio_capturer_source.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" | 17 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" |
17 | 18 |
18 using ::testing::_; | 19 using ::testing::_; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 } | 112 } |
112 protected: | 113 protected: |
113 virtual ~MockCapturerSource() {} | 114 virtual ~MockCapturerSource() {} |
114 | 115 |
115 private: | 116 private: |
116 scoped_ptr<FakeAudioThread> audio_thread_; | 117 scoped_ptr<FakeAudioThread> audio_thread_; |
117 WebRtcAudioCapturer* capturer_; | 118 WebRtcAudioCapturer* capturer_; |
118 media::AudioParameters params_; | 119 media::AudioParameters params_; |
119 }; | 120 }; |
120 | 121 |
121 class MockWebRtcAudioCapturerSink : public WebRtcAudioCapturerSink { | 122 // TODO(xians): Use MediaStreamAudioSink. |
| 123 class MockMediaStreamAudioSink : public PeerConnectionAudioSink { |
122 public: | 124 public: |
123 MockWebRtcAudioCapturerSink() {} | 125 MockMediaStreamAudioSink() {} |
124 ~MockWebRtcAudioCapturerSink() {} | 126 ~MockMediaStreamAudioSink() {} |
125 int CaptureData(const std::vector<int>& channels, | 127 int OnData(const int16* audio_data, |
126 const int16* audio_data, | 128 int sample_rate, |
127 int sample_rate, | 129 int number_of_channels, |
128 int number_of_channels, | 130 int number_of_frames, |
129 int number_of_frames, | 131 const std::vector<int>& channels, |
130 int audio_delay_milliseconds, | 132 int audio_delay_milliseconds, |
131 int current_volume, | 133 int current_volume, |
132 bool need_audio_processing, | 134 bool need_audio_processing, |
133 bool key_pressed) OVERRIDE { | 135 bool key_pressed) OVERRIDE { |
134 CaptureData(channels.size(), | 136 CaptureData(channels.size(), |
135 sample_rate, | 137 sample_rate, |
136 number_of_channels, | 138 number_of_channels, |
137 number_of_frames, | 139 number_of_frames, |
138 audio_delay_milliseconds, | 140 audio_delay_milliseconds, |
139 current_volume, | 141 current_volume, |
140 need_audio_processing, | 142 need_audio_processing, |
141 key_pressed); | 143 key_pressed); |
142 return 0; | 144 return 0; |
143 } | 145 } |
144 MOCK_METHOD8(CaptureData, | 146 MOCK_METHOD8(CaptureData, |
145 void(int number_of_network_channels, | 147 void(int number_of_network_channels, |
146 int sample_rate, | 148 int sample_rate, |
147 int number_of_channels, | 149 int number_of_channels, |
148 int number_of_frames, | 150 int number_of_frames, |
149 int audio_delay_milliseconds, | 151 int audio_delay_milliseconds, |
150 int current_volume, | 152 int current_volume, |
151 bool need_audio_processing, | 153 bool need_audio_processing, |
152 bool key_pressed)); | 154 bool key_pressed)); |
153 MOCK_METHOD1(SetCaptureFormat, void(const media::AudioParameters& params)); | 155 MOCK_METHOD1(OnSetFormat, void(const media::AudioParameters& params)); |
154 }; | 156 }; |
155 | 157 |
156 } // namespace | 158 } // namespace |
157 | 159 |
158 class WebRtcLocalAudioTrackTest : public ::testing::Test { | 160 class WebRtcLocalAudioTrackTest : public ::testing::Test { |
159 protected: | 161 protected: |
160 virtual void SetUp() OVERRIDE { | 162 virtual void SetUp() OVERRIDE { |
161 params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 163 params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
162 media::CHANNEL_LAYOUT_STEREO, 2, 0, 48000, 16, 480); | 164 media::CHANNEL_LAYOUT_STEREO, 2, 0, 48000, 16, 480); |
163 capturer_ = WebRtcAudioCapturer::CreateCapturer(); | 165 capturer_ = WebRtcAudioCapturer::CreateCapturer(); |
(...skipping 25 matching lines...) Expand all Loading... |
189 track->audio_source_provider())->SetSinkParamsForTesting(params_); | 191 track->audio_source_provider())->SetSinkParamsForTesting(params_); |
190 track->Start(); | 192 track->Start(); |
191 EXPECT_TRUE(track->enabled()); | 193 EXPECT_TRUE(track->enabled()); |
192 | 194 |
193 // Connect a number of network channels to the audio track. | 195 // Connect a number of network channels to the audio track. |
194 static const int kNumberOfNetworkChannels = 4; | 196 static const int kNumberOfNetworkChannels = 4; |
195 for (int i = 0; i < kNumberOfNetworkChannels; ++i) { | 197 for (int i = 0; i < kNumberOfNetworkChannels; ++i) { |
196 static_cast<webrtc::AudioTrackInterface*>(track.get())-> | 198 static_cast<webrtc::AudioTrackInterface*>(track.get())-> |
197 GetRenderer()->AddChannel(i); | 199 GetRenderer()->AddChannel(i); |
198 } | 200 } |
199 scoped_ptr<MockWebRtcAudioCapturerSink> sink( | 201 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
200 new MockWebRtcAudioCapturerSink()); | |
201 const media::AudioParameters params = capturer_->audio_parameters(); | 202 const media::AudioParameters params = capturer_->audio_parameters(); |
202 base::WaitableEvent event(false, false); | 203 base::WaitableEvent event(false, false); |
203 EXPECT_CALL(*sink, SetCaptureFormat(_)).WillOnce(Return()); | 204 EXPECT_CALL(*sink, OnSetFormat(_)).WillOnce(Return()); |
204 EXPECT_CALL(*sink, | 205 EXPECT_CALL(*sink, |
205 CaptureData(kNumberOfNetworkChannels, | 206 CaptureData(kNumberOfNetworkChannels, |
206 params.sample_rate(), | 207 params.sample_rate(), |
207 params.channels(), | 208 params.channels(), |
208 params.sample_rate() / 100, | 209 params.sample_rate() / 100, |
209 0, | 210 0, |
210 0, | 211 0, |
211 false, | 212 false, |
212 false)).Times(AtLeast(1)) | 213 false)).Times(AtLeast(1)) |
213 .WillRepeatedly(SignalEvent(&event)); | 214 .WillRepeatedly(SignalEvent(&event)); |
(...skipping 19 matching lines...) Expand all Loading... |
233 scoped_refptr<WebRtcLocalAudioTrack> track = | 234 scoped_refptr<WebRtcLocalAudioTrack> track = |
234 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, | 235 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, |
235 &constraints); | 236 &constraints); |
236 static_cast<WebRtcLocalAudioSourceProvider*>( | 237 static_cast<WebRtcLocalAudioSourceProvider*>( |
237 track->audio_source_provider())->SetSinkParamsForTesting(params_); | 238 track->audio_source_provider())->SetSinkParamsForTesting(params_); |
238 track->Start(); | 239 track->Start(); |
239 static_cast<webrtc::AudioTrackInterface*>(track.get())-> | 240 static_cast<webrtc::AudioTrackInterface*>(track.get())-> |
240 GetRenderer()->AddChannel(0); | 241 GetRenderer()->AddChannel(0); |
241 EXPECT_TRUE(track->enabled()); | 242 EXPECT_TRUE(track->enabled()); |
242 EXPECT_TRUE(track->set_enabled(false)); | 243 EXPECT_TRUE(track->set_enabled(false)); |
243 scoped_ptr<MockWebRtcAudioCapturerSink> sink( | 244 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
244 new MockWebRtcAudioCapturerSink()); | |
245 const media::AudioParameters params = capturer_->audio_parameters(); | 245 const media::AudioParameters params = capturer_->audio_parameters(); |
246 base::WaitableEvent event(false, false); | 246 base::WaitableEvent event(false, false); |
247 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1); | 247 EXPECT_CALL(*sink, OnSetFormat(_)).Times(1); |
248 EXPECT_CALL(*sink, | 248 EXPECT_CALL(*sink, |
249 CaptureData(1, | 249 CaptureData(1, |
250 params.sample_rate(), | 250 params.sample_rate(), |
251 params.channels(), | 251 params.channels(), |
252 params.sample_rate() / 100, | 252 params.sample_rate() / 100, |
253 0, | 253 0, |
254 0, | 254 0, |
255 false, | 255 false, |
256 false)).Times(0); | 256 false)).Times(0); |
257 track->AddSink(sink.get()); | 257 track->AddSink(sink.get()); |
(...skipping 28 matching lines...) Expand all Loading... |
286 RTCMediaConstraints constraints; | 286 RTCMediaConstraints constraints; |
287 scoped_refptr<WebRtcLocalAudioTrack> track_1 = | 287 scoped_refptr<WebRtcLocalAudioTrack> track_1 = |
288 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, | 288 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, |
289 &constraints); | 289 &constraints); |
290 static_cast<WebRtcLocalAudioSourceProvider*>( | 290 static_cast<WebRtcLocalAudioSourceProvider*>( |
291 track_1->audio_source_provider())->SetSinkParamsForTesting(params_); | 291 track_1->audio_source_provider())->SetSinkParamsForTesting(params_); |
292 track_1->Start(); | 292 track_1->Start(); |
293 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> | 293 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> |
294 GetRenderer()->AddChannel(0); | 294 GetRenderer()->AddChannel(0); |
295 EXPECT_TRUE(track_1->enabled()); | 295 EXPECT_TRUE(track_1->enabled()); |
296 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( | 296 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); |
297 new MockWebRtcAudioCapturerSink()); | |
298 const media::AudioParameters params = capturer_->audio_parameters(); | 297 const media::AudioParameters params = capturer_->audio_parameters(); |
299 base::WaitableEvent event_1(false, false); | 298 base::WaitableEvent event_1(false, false); |
300 EXPECT_CALL(*sink_1, SetCaptureFormat(_)).WillOnce(Return()); | 299 EXPECT_CALL(*sink_1, OnSetFormat(_)).WillOnce(Return()); |
301 EXPECT_CALL(*sink_1, | 300 EXPECT_CALL(*sink_1, |
302 CaptureData(1, | 301 CaptureData(1, |
303 params.sample_rate(), | 302 params.sample_rate(), |
304 params.channels(), | 303 params.channels(), |
305 params.sample_rate() / 100, | 304 params.sample_rate() / 100, |
306 0, | 305 0, |
307 0, | 306 0, |
308 false, | 307 false, |
309 false)).Times(AtLeast(1)) | 308 false)).Times(AtLeast(1)) |
310 .WillRepeatedly(SignalEvent(&event_1)); | 309 .WillRepeatedly(SignalEvent(&event_1)); |
311 track_1->AddSink(sink_1.get()); | 310 track_1->AddSink(sink_1.get()); |
312 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 311 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
313 | 312 |
314 scoped_refptr<WebRtcLocalAudioTrack> track_2 = | 313 scoped_refptr<WebRtcLocalAudioTrack> track_2 = |
315 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, | 314 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, |
316 &constraints); | 315 &constraints); |
317 static_cast<WebRtcLocalAudioSourceProvider*>( | 316 static_cast<WebRtcLocalAudioSourceProvider*>( |
318 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); | 317 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); |
319 track_2->Start(); | 318 track_2->Start(); |
320 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> | 319 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> |
321 GetRenderer()->AddChannel(1); | 320 GetRenderer()->AddChannel(1); |
322 EXPECT_TRUE(track_2->enabled()); | 321 EXPECT_TRUE(track_2->enabled()); |
323 | 322 |
324 // Verify both |sink_1| and |sink_2| get data. | 323 // Verify both |sink_1| and |sink_2| get data. |
325 event_1.Reset(); | 324 event_1.Reset(); |
326 base::WaitableEvent event_2(false, false); | 325 base::WaitableEvent event_2(false, false); |
327 | 326 |
328 scoped_ptr<MockWebRtcAudioCapturerSink> sink_2( | 327 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); |
329 new MockWebRtcAudioCapturerSink()); | 328 EXPECT_CALL(*sink_2, OnSetFormat(_)).WillOnce(Return()); |
330 EXPECT_CALL(*sink_2, SetCaptureFormat(_)).WillOnce(Return()); | |
331 EXPECT_CALL(*sink_1, | 329 EXPECT_CALL(*sink_1, |
332 CaptureData(1, | 330 CaptureData(1, |
333 params.sample_rate(), | 331 params.sample_rate(), |
334 params.channels(), | 332 params.channels(), |
335 params.sample_rate() / 100, | 333 params.sample_rate() / 100, |
336 0, | 334 0, |
337 0, | 335 0, |
338 false, | 336 false, |
339 false)).Times(AtLeast(1)) | 337 false)).Times(AtLeast(1)) |
340 .WillRepeatedly(SignalEvent(&event_1)); | 338 .WillRepeatedly(SignalEvent(&event_1)); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, | 395 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, |
398 &constraints); | 396 &constraints); |
399 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> | 397 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> |
400 GetRenderer()->AddChannel(0); | 398 GetRenderer()->AddChannel(0); |
401 static_cast<WebRtcLocalAudioSourceProvider*>( | 399 static_cast<WebRtcLocalAudioSourceProvider*>( |
402 track_1->audio_source_provider())->SetSinkParamsForTesting(params_); | 400 track_1->audio_source_provider())->SetSinkParamsForTesting(params_); |
403 track_1->Start(); | 401 track_1->Start(); |
404 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 402 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
405 | 403 |
406 // Verify the data flow by connecting the sink to |track_1|. | 404 // Verify the data flow by connecting the sink to |track_1|. |
407 scoped_ptr<MockWebRtcAudioCapturerSink> sink( | 405 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
408 new MockWebRtcAudioCapturerSink()); | |
409 event.Reset(); | 406 event.Reset(); |
410 EXPECT_CALL(*sink, SetCaptureFormat(_)).WillOnce(SignalEvent(&event)); | 407 EXPECT_CALL(*sink, OnSetFormat(_)).WillOnce(SignalEvent(&event)); |
411 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, false, false)) | 408 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, false, false)) |
412 .Times(AnyNumber()).WillRepeatedly(Return()); | 409 .Times(AnyNumber()).WillRepeatedly(Return()); |
413 track_1->AddSink(sink.get()); | 410 track_1->AddSink(sink.get()); |
414 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 411 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
415 | 412 |
416 // Start the second audio track will not start the |capturer_source_| | 413 // Start the second audio track will not start the |capturer_source_| |
417 // since it has been started. | 414 // since it has been started. |
418 EXPECT_CALL(*capturer_source_.get(), OnStart()).Times(0); | 415 EXPECT_CALL(*capturer_source_.get(), OnStart()).Times(0); |
419 scoped_refptr<WebRtcLocalAudioTrack> track_2 = | 416 scoped_refptr<WebRtcLocalAudioTrack> track_2 = |
420 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, | 417 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL, |
421 &constraints); | 418 &constraints); |
422 static_cast<WebRtcLocalAudioSourceProvider*>( | 419 static_cast<WebRtcLocalAudioSourceProvider*>( |
423 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); | 420 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); |
424 track_2->Start(); | 421 track_2->Start(); |
425 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> | 422 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> |
426 GetRenderer()->AddChannel(1); | 423 GetRenderer()->AddChannel(1); |
427 | 424 |
428 // Stop the capturer will clear up the track lists in the capturer. | 425 // Stop the capturer will clear up the track lists in the capturer. |
429 EXPECT_CALL(*capturer_source_.get(), OnStop()); | 426 EXPECT_CALL(*capturer_source_.get(), OnStop()); |
430 capturer_->Stop(); | 427 capturer_->Stop(); |
431 | 428 |
432 // Adding a new track to the capturer. | 429 // Adding a new track to the capturer. |
433 track_2->AddSink(sink.get()); | 430 track_2->AddSink(sink.get()); |
434 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(0); | 431 EXPECT_CALL(*sink, OnSetFormat(_)).Times(0); |
435 | 432 |
436 // Stop the capturer again will not trigger stopping the source of the | 433 // Stop the capturer again will not trigger stopping the source of the |
437 // capturer again.. | 434 // capturer again.. |
438 event.Reset(); | 435 event.Reset(); |
439 EXPECT_CALL(*capturer_source_.get(), OnStop()).Times(0); | 436 EXPECT_CALL(*capturer_source_.get(), OnStop()).Times(0); |
440 capturer_->Stop(); | 437 capturer_->Stop(); |
441 } | 438 } |
442 | 439 |
443 // Set new source to the existing capturer. | 440 // Set new source to the existing capturer. |
444 TEST_F(WebRtcLocalAudioTrackTest, SetNewSourceForCapturerAfterStartTrack) { | 441 TEST_F(WebRtcLocalAudioTrackTest, SetNewSourceForCapturerAfterStartTrack) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 track_1->audio_source_provider())->SetSinkParamsForTesting(params_); | 480 track_1->audio_source_provider())->SetSinkParamsForTesting(params_); |
484 track_1->Start(); | 481 track_1->Start(); |
485 | 482 |
486 // Connect a number of network channels to the |track_1|. | 483 // Connect a number of network channels to the |track_1|. |
487 static const int kNumberOfNetworkChannelsForTrack1 = 2; | 484 static const int kNumberOfNetworkChannelsForTrack1 = 2; |
488 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) { | 485 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) { |
489 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> | 486 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> |
490 GetRenderer()->AddChannel(i); | 487 GetRenderer()->AddChannel(i); |
491 } | 488 } |
492 // Verify the data flow by connecting the |sink_1| to |track_1|. | 489 // Verify the data flow by connecting the |sink_1| to |track_1|. |
493 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( | 490 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); |
494 new MockWebRtcAudioCapturerSink()); | |
495 EXPECT_CALL( | 491 EXPECT_CALL( |
496 *sink_1.get(), | 492 *sink_1.get(), |
497 CaptureData( | 493 CaptureData( |
498 kNumberOfNetworkChannelsForTrack1, 48000, 2, _, 0, 0, false, false)) | 494 kNumberOfNetworkChannelsForTrack1, 48000, 2, _, 0, 0, false, false)) |
499 .Times(AnyNumber()).WillRepeatedly(Return()); | 495 .Times(AnyNumber()).WillRepeatedly(Return()); |
500 EXPECT_CALL(*sink_1.get(), SetCaptureFormat(_)).Times(AnyNumber()); | 496 EXPECT_CALL(*sink_1.get(), OnSetFormat(_)).Times(AnyNumber()); |
501 track_1->AddSink(sink_1.get()); | 497 track_1->AddSink(sink_1.get()); |
502 | 498 |
503 // Create a new capturer with new source with different audio format. | 499 // Create a new capturer with new source with different audio format. |
504 scoped_refptr<WebRtcAudioCapturer> new_capturer( | 500 scoped_refptr<WebRtcAudioCapturer> new_capturer( |
505 WebRtcAudioCapturer::CreateCapturer()); | 501 WebRtcAudioCapturer::CreateCapturer()); |
506 scoped_refptr<MockCapturerSource> new_source( | 502 scoped_refptr<MockCapturerSource> new_source( |
507 new MockCapturerSource(new_capturer.get())); | 503 new MockCapturerSource(new_capturer.get())); |
508 EXPECT_CALL(*new_source.get(), OnInitialize(_, new_capturer.get(), 0)); | 504 EXPECT_CALL(*new_source.get(), OnInitialize(_, new_capturer.get(), 0)); |
509 new_capturer->SetCapturerSource(new_source, | 505 new_capturer->SetCapturerSource(new_source, |
510 media::CHANNEL_LAYOUT_MONO, | 506 media::CHANNEL_LAYOUT_MONO, |
511 44100); | 507 44100); |
512 | 508 |
513 // Setup the second audio track, connect it to the new capturer and start it. | 509 // Setup the second audio track, connect it to the new capturer and start it. |
514 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true)); | 510 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true)); |
515 EXPECT_CALL(*new_source.get(), OnStart()); | 511 EXPECT_CALL(*new_source.get(), OnStart()); |
516 scoped_refptr<WebRtcLocalAudioTrack> track_2 = | 512 scoped_refptr<WebRtcLocalAudioTrack> track_2 = |
517 WebRtcLocalAudioTrack::Create(std::string(), new_capturer, NULL, NULL, | 513 WebRtcLocalAudioTrack::Create(std::string(), new_capturer, NULL, NULL, |
518 &constraints); | 514 &constraints); |
519 static_cast<WebRtcLocalAudioSourceProvider*>( | 515 static_cast<WebRtcLocalAudioSourceProvider*>( |
520 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); | 516 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); |
521 track_2->Start(); | 517 track_2->Start(); |
522 | 518 |
523 // Connect a number of network channels to the |track_2|. | 519 // Connect a number of network channels to the |track_2|. |
524 static const int kNumberOfNetworkChannelsForTrack2 = 3; | 520 static const int kNumberOfNetworkChannelsForTrack2 = 3; |
525 for (int i = 0; i < kNumberOfNetworkChannelsForTrack2; ++i) { | 521 for (int i = 0; i < kNumberOfNetworkChannelsForTrack2; ++i) { |
526 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> | 522 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> |
527 GetRenderer()->AddChannel(i); | 523 GetRenderer()->AddChannel(i); |
528 } | 524 } |
529 // Verify the data flow by connecting the |sink_2| to |track_2|. | 525 // Verify the data flow by connecting the |sink_2| to |track_2|. |
530 scoped_ptr<MockWebRtcAudioCapturerSink> sink_2( | 526 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); |
531 new MockWebRtcAudioCapturerSink()); | |
532 base::WaitableEvent event(false, false); | 527 base::WaitableEvent event(false, false); |
533 EXPECT_CALL( | 528 EXPECT_CALL( |
534 *sink_2, | 529 *sink_2, |
535 CaptureData( | 530 CaptureData( |
536 kNumberOfNetworkChannelsForTrack2, 44100, 1, _, 0, 0, false, false)) | 531 kNumberOfNetworkChannelsForTrack2, 44100, 1, _, 0, 0, false, false)) |
537 .Times(AnyNumber()).WillRepeatedly(Return()); | 532 .Times(AnyNumber()).WillRepeatedly(Return()); |
538 EXPECT_CALL(*sink_2, SetCaptureFormat(_)).WillOnce(SignalEvent(&event)); | 533 EXPECT_CALL(*sink_2, OnSetFormat(_)).WillOnce(SignalEvent(&event)); |
539 track_2->AddSink(sink_2.get()); | 534 track_2->AddSink(sink_2.get()); |
540 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 535 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
541 | 536 |
542 // Stopping the new source will stop the second track. | 537 // Stopping the new source will stop the second track. |
543 event.Reset(); | 538 event.Reset(); |
544 EXPECT_CALL(*new_source.get(), OnStop()) | 539 EXPECT_CALL(*new_source.get(), OnStop()) |
545 .Times(1).WillOnce(SignalEvent(&event)); | 540 .Times(1).WillOnce(SignalEvent(&event)); |
546 new_capturer->Stop(); | 541 new_capturer->Stop(); |
547 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 542 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
548 | 543 |
(...skipping 27 matching lines...) Expand all Loading... |
576 EXPECT_CALL(*source.get(), OnStart()); | 571 EXPECT_CALL(*source.get(), OnStart()); |
577 RTCMediaConstraints constraints; | 572 RTCMediaConstraints constraints; |
578 scoped_refptr<WebRtcLocalAudioTrack> track = | 573 scoped_refptr<WebRtcLocalAudioTrack> track = |
579 WebRtcLocalAudioTrack::Create(std::string(), capturer, NULL, NULL, | 574 WebRtcLocalAudioTrack::Create(std::string(), capturer, NULL, NULL, |
580 &constraints); | 575 &constraints); |
581 static_cast<WebRtcLocalAudioSourceProvider*>( | 576 static_cast<WebRtcLocalAudioSourceProvider*>( |
582 track->audio_source_provider())->SetSinkParamsForTesting(params); | 577 track->audio_source_provider())->SetSinkParamsForTesting(params); |
583 track->Start(); | 578 track->Start(); |
584 | 579 |
585 // Verify the data flow by connecting the |sink| to |track|. | 580 // Verify the data flow by connecting the |sink| to |track|. |
586 scoped_ptr<MockWebRtcAudioCapturerSink> sink( | 581 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
587 new MockWebRtcAudioCapturerSink()); | |
588 base::WaitableEvent event(false, false); | 582 base::WaitableEvent event(false, false); |
589 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1); | 583 EXPECT_CALL(*sink, OnSetFormat(_)).Times(1); |
590 // Verify the sinks are getting the packets with an expecting buffer size. | 584 // Verify the sinks are getting the packets with an expecting buffer size. |
591 #if defined(OS_ANDROID) | 585 #if defined(OS_ANDROID) |
592 const int expected_buffer_size = params.sample_rate() / 100; | 586 const int expected_buffer_size = params.sample_rate() / 100; |
593 #else | 587 #else |
594 const int expected_buffer_size = params.frames_per_buffer(); | 588 const int expected_buffer_size = params.frames_per_buffer(); |
595 #endif | 589 #endif |
596 EXPECT_CALL(*sink, CaptureData( | 590 EXPECT_CALL(*sink, CaptureData( |
597 0, params.sample_rate(), params.channels(), expected_buffer_size, | 591 0, params.sample_rate(), params.channels(), expected_buffer_size, |
598 0, 0, false, false)) | 592 0, 0, false, false)) |
599 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); | 593 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); |
600 track->AddSink(sink.get()); | 594 track->AddSink(sink.get()); |
601 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 595 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
602 | 596 |
603 // Stopping the new source will stop the second track. | 597 // Stopping the new source will stop the second track. |
604 EXPECT_CALL(*source, OnStop()).Times(1); | 598 EXPECT_CALL(*source, OnStop()).Times(1); |
605 capturer->Stop(); | 599 capturer->Stop(); |
606 } | 600 } |
607 | 601 |
608 } // namespace content | 602 } // namespace content |
OLD | NEW |