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/mock_media_constraint_factory.h" |
7 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | 8 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" |
8 #include "content/renderer/media/webrtc_audio_capturer.h" | 9 #include "content/renderer/media/webrtc_audio_capturer.h" |
9 #include "content/renderer/media/webrtc_audio_device_impl.h" | 10 #include "content/renderer/media/webrtc_audio_device_impl.h" |
10 #include "content/renderer/media/webrtc_local_audio_source_provider.h" | 11 #include "content/renderer/media/webrtc_local_audio_source_provider.h" |
11 #include "content/renderer/media/webrtc_local_audio_track.h" | 12 #include "content/renderer/media/webrtc_local_audio_track.h" |
12 #include "media/audio/audio_parameters.h" | 13 #include "media/audio/audio_parameters.h" |
13 #include "media/base/audio_bus.h" | 14 #include "media/base/audio_bus.h" |
14 #include "media/base/audio_capturer_source.h" | 15 #include "media/base/audio_capturer_source.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 ~MockMediaStreamAudioSink() {} | 128 ~MockMediaStreamAudioSink() {} |
128 int OnData(const int16* audio_data, | 129 int OnData(const int16* audio_data, |
129 int sample_rate, | 130 int sample_rate, |
130 int number_of_channels, | 131 int number_of_channels, |
131 int number_of_frames, | 132 int number_of_frames, |
132 const std::vector<int>& channels, | 133 const std::vector<int>& channels, |
133 int audio_delay_milliseconds, | 134 int audio_delay_milliseconds, |
134 int current_volume, | 135 int current_volume, |
135 bool need_audio_processing, | 136 bool need_audio_processing, |
136 bool key_pressed) OVERRIDE { | 137 bool key_pressed) OVERRIDE { |
| 138 EXPECT_EQ(params_.sample_rate(), sample_rate); |
| 139 EXPECT_EQ(params_.channels(), number_of_channels); |
| 140 EXPECT_EQ(params_.frames_per_buffer(), number_of_frames); |
137 CaptureData(channels.size(), | 141 CaptureData(channels.size(), |
138 sample_rate, | |
139 number_of_channels, | |
140 number_of_frames, | |
141 audio_delay_milliseconds, | 142 audio_delay_milliseconds, |
142 current_volume, | 143 current_volume, |
143 need_audio_processing, | 144 need_audio_processing, |
144 key_pressed); | 145 key_pressed); |
145 return 0; | 146 return 0; |
146 } | 147 } |
147 MOCK_METHOD8(CaptureData, | 148 MOCK_METHOD5(CaptureData, |
148 void(int number_of_network_channels, | 149 void(int number_of_network_channels, |
149 int sample_rate, | |
150 int number_of_channels, | |
151 int number_of_frames, | |
152 int audio_delay_milliseconds, | 150 int audio_delay_milliseconds, |
153 int current_volume, | 151 int current_volume, |
154 bool need_audio_processing, | 152 bool need_audio_processing, |
155 bool key_pressed)); | 153 bool key_pressed)); |
156 MOCK_METHOD1(OnSetFormat, void(const media::AudioParameters& params)); | 154 void OnSetFormat(const media::AudioParameters& params) { |
| 155 params_ = params; |
| 156 FormatIsSet(); |
| 157 } |
| 158 MOCK_METHOD0(FormatIsSet, void()); |
| 159 |
| 160 const media::AudioParameters& audio_params() const { return params_; } |
| 161 |
| 162 private: |
| 163 media::AudioParameters params_; |
157 }; | 164 }; |
158 | 165 |
159 } // namespace | 166 } // namespace |
160 | 167 |
161 class WebRtcLocalAudioTrackTest : public ::testing::Test { | 168 class WebRtcLocalAudioTrackTest : public ::testing::Test { |
162 protected: | 169 protected: |
163 virtual void SetUp() OVERRIDE { | 170 virtual void SetUp() OVERRIDE { |
164 params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 171 params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
165 media::CHANNEL_LAYOUT_STEREO, 2, 0, 48000, 16, 480); | 172 media::CHANNEL_LAYOUT_STEREO, 2, 0, 48000, 16, 480); |
166 blink::WebMediaConstraints constraints; | 173 blink::WebMediaConstraints constraints; |
(...skipping 28 matching lines...) Expand all Loading... |
195 track->Start(); | 202 track->Start(); |
196 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); | 203 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); |
197 | 204 |
198 // Connect a number of network channels to the audio track. | 205 // Connect a number of network channels to the audio track. |
199 static const int kNumberOfNetworkChannels = 4; | 206 static const int kNumberOfNetworkChannels = 4; |
200 for (int i = 0; i < kNumberOfNetworkChannels; ++i) { | 207 for (int i = 0; i < kNumberOfNetworkChannels; ++i) { |
201 static_cast<webrtc::AudioTrackInterface*>( | 208 static_cast<webrtc::AudioTrackInterface*>( |
202 adapter.get())->GetRenderer()->AddChannel(i); | 209 adapter.get())->GetRenderer()->AddChannel(i); |
203 } | 210 } |
204 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 211 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
205 const media::AudioParameters params = capturer_->source_audio_parameters(); | |
206 base::WaitableEvent event(false, false); | 212 base::WaitableEvent event(false, false); |
207 EXPECT_CALL(*sink, OnSetFormat(_)).WillOnce(Return()); | 213 EXPECT_CALL(*sink, FormatIsSet()); |
208 EXPECT_CALL(*sink, | 214 EXPECT_CALL(*sink, |
209 CaptureData(kNumberOfNetworkChannels, | 215 CaptureData(kNumberOfNetworkChannels, |
210 params.sample_rate(), | |
211 params.channels(), | |
212 params.sample_rate() / 100, | |
213 0, | 216 0, |
214 0, | 217 0, |
215 true, | 218 _, |
216 false)).Times(AtLeast(1)) | 219 false)).Times(AtLeast(1)) |
217 .WillRepeatedly(SignalEvent(&event)); | 220 .WillRepeatedly(SignalEvent(&event)); |
218 track->AddSink(sink.get()); | 221 track->AddSink(sink.get()); |
219 | |
220 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 222 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
221 track->RemoveSink(sink.get()); | 223 track->RemoveSink(sink.get()); |
222 | 224 |
223 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); | 225 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); |
224 capturer_->Stop(); | 226 capturer_->Stop(); |
225 } | 227 } |
226 | 228 |
227 // The same setup as ConnectAndDisconnectOneSink, but enable and disable the | 229 // The same setup as ConnectAndDisconnectOneSink, but enable and disable the |
228 // audio track on the fly. When the audio track is disabled, there is no data | 230 // audio track on the fly. When the audio track is disabled, there is no data |
229 // callback to the sink; when the audio track is enabled, there comes data | 231 // callback to the sink; when the audio track is enabled, there comes data |
(...skipping 10 matching lines...) Expand all Loading... |
240 static_cast<WebRtcLocalAudioSourceProvider*>( | 242 static_cast<WebRtcLocalAudioSourceProvider*>( |
241 track->audio_source_provider())->SetSinkParamsForTesting(params_); | 243 track->audio_source_provider())->SetSinkParamsForTesting(params_); |
242 track->Start(); | 244 track->Start(); |
243 static_cast<webrtc::AudioTrackInterface*>( | 245 static_cast<webrtc::AudioTrackInterface*>( |
244 adapter.get())->GetRenderer()->AddChannel(0); | 246 adapter.get())->GetRenderer()->AddChannel(0); |
245 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); | 247 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); |
246 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(false)); | 248 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(false)); |
247 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 249 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
248 const media::AudioParameters params = capturer_->source_audio_parameters(); | 250 const media::AudioParameters params = capturer_->source_audio_parameters(); |
249 base::WaitableEvent event(false, false); | 251 base::WaitableEvent event(false, false); |
250 EXPECT_CALL(*sink, OnSetFormat(_)).Times(1); | 252 EXPECT_CALL(*sink, FormatIsSet()).Times(1); |
251 EXPECT_CALL(*sink, | 253 EXPECT_CALL(*sink, |
252 CaptureData(1, | 254 CaptureData(1, 0, 0, _, false)).Times(0); |
253 params.sample_rate(), | 255 EXPECT_EQ(sink->audio_params().frames_per_buffer(), |
254 params.channels(), | 256 params.sample_rate() / 100); |
255 params.sample_rate() / 100, | |
256 0, | |
257 0, | |
258 true, | |
259 false)).Times(0); | |
260 track->AddSink(sink.get()); | 257 track->AddSink(sink.get()); |
261 EXPECT_FALSE(event.TimedWait(TestTimeouts::tiny_timeout())); | 258 EXPECT_FALSE(event.TimedWait(TestTimeouts::tiny_timeout())); |
262 | 259 |
263 event.Reset(); | 260 event.Reset(); |
264 EXPECT_CALL(*sink, | 261 EXPECT_CALL(*sink, |
265 CaptureData(1, | 262 CaptureData(1, 0, 0, _, false)).Times(AtLeast(1)) |
266 params.sample_rate(), | |
267 params.channels(), | |
268 params.sample_rate() / 100, | |
269 0, | |
270 0, | |
271 true, | |
272 false)).Times(AtLeast(1)) | |
273 .WillRepeatedly(SignalEvent(&event)); | 263 .WillRepeatedly(SignalEvent(&event)); |
274 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(true)); | 264 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(true)); |
275 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 265 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
276 track->RemoveSink(sink.get()); | 266 track->RemoveSink(sink.get()); |
277 | 267 |
278 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); | 268 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); |
279 capturer_->Stop(); | 269 capturer_->Stop(); |
280 track.reset(); | 270 track.reset(); |
281 } | 271 } |
282 | 272 |
283 // Create multiple audio tracks and enable/disable them, verify that the audio | 273 // Create multiple audio tracks and enable/disable them, verify that the audio |
284 // callbacks appear/disappear. | 274 // callbacks appear/disappear. |
285 // Flaky due to a data race, see http://crbug.com/295418 | 275 // Flaky due to a data race, see http://crbug.com/295418 |
286 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) { | 276 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) { |
287 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); | 277 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); |
288 EXPECT_CALL(*capturer_source_.get(), OnStart()); | 278 EXPECT_CALL(*capturer_source_.get(), OnStart()); |
289 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( | 279 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( |
290 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 280 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
291 scoped_ptr<WebRtcLocalAudioTrack> track_1( | 281 scoped_ptr<WebRtcLocalAudioTrack> track_1( |
292 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); | 282 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); |
293 static_cast<WebRtcLocalAudioSourceProvider*>( | 283 static_cast<WebRtcLocalAudioSourceProvider*>( |
294 track_1->audio_source_provider())->SetSinkParamsForTesting(params_); | 284 track_1->audio_source_provider())->SetSinkParamsForTesting(params_); |
295 track_1->Start(); | 285 track_1->Start(); |
296 static_cast<webrtc::AudioTrackInterface*>( | 286 static_cast<webrtc::AudioTrackInterface*>( |
297 adapter_1.get())->GetRenderer()->AddChannel(0); | 287 adapter_1.get())->GetRenderer()->AddChannel(0); |
298 EXPECT_TRUE(track_1->GetAudioAdapter()->enabled()); | 288 EXPECT_TRUE(track_1->GetAudioAdapter()->enabled()); |
299 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); | 289 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); |
300 const media::AudioParameters params = capturer_->source_audio_parameters(); | 290 const media::AudioParameters params = capturer_->source_audio_parameters(); |
301 base::WaitableEvent event_1(false, false); | 291 base::WaitableEvent event_1(false, false); |
302 EXPECT_CALL(*sink_1, OnSetFormat(_)).WillOnce(Return()); | 292 EXPECT_CALL(*sink_1, FormatIsSet()).WillOnce(Return()); |
303 EXPECT_CALL(*sink_1, | 293 EXPECT_CALL(*sink_1, |
304 CaptureData(1, | 294 CaptureData(1, 0, 0, _, false)).Times(AtLeast(1)) |
305 params.sample_rate(), | |
306 params.channels(), | |
307 params.sample_rate() / 100, | |
308 0, | |
309 0, | |
310 true, | |
311 false)).Times(AtLeast(1)) | |
312 .WillRepeatedly(SignalEvent(&event_1)); | 295 .WillRepeatedly(SignalEvent(&event_1)); |
| 296 EXPECT_EQ(sink_1->audio_params().frames_per_buffer(), |
| 297 params.sample_rate() / 100); |
313 track_1->AddSink(sink_1.get()); | 298 track_1->AddSink(sink_1.get()); |
314 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 299 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
315 | 300 |
316 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( | 301 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( |
317 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 302 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
318 scoped_ptr<WebRtcLocalAudioTrack> track_2( | 303 scoped_ptr<WebRtcLocalAudioTrack> track_2( |
319 new WebRtcLocalAudioTrack(adapter_2, capturer_, NULL)); | 304 new WebRtcLocalAudioTrack(adapter_2, capturer_, NULL)); |
320 static_cast<WebRtcLocalAudioSourceProvider*>( | 305 static_cast<WebRtcLocalAudioSourceProvider*>( |
321 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); | 306 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); |
322 track_2->Start(); | 307 track_2->Start(); |
323 static_cast<webrtc::AudioTrackInterface*>( | 308 static_cast<webrtc::AudioTrackInterface*>( |
324 adapter_2.get())->GetRenderer()->AddChannel(1); | 309 adapter_2.get())->GetRenderer()->AddChannel(1); |
325 EXPECT_TRUE(track_2->GetAudioAdapter()->enabled()); | 310 EXPECT_TRUE(track_2->GetAudioAdapter()->enabled()); |
326 | 311 |
327 // Verify both |sink_1| and |sink_2| get data. | 312 // Verify both |sink_1| and |sink_2| get data. |
328 event_1.Reset(); | 313 event_1.Reset(); |
329 base::WaitableEvent event_2(false, false); | 314 base::WaitableEvent event_2(false, false); |
330 | 315 |
331 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); | 316 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); |
332 EXPECT_CALL(*sink_2, OnSetFormat(_)).WillOnce(Return()); | 317 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(Return()); |
333 EXPECT_CALL(*sink_1, | 318 EXPECT_CALL(*sink_1, CaptureData(1, 0, 0, _, false)).Times(AtLeast(1)) |
334 CaptureData(1, | |
335 params.sample_rate(), | |
336 params.channels(), | |
337 params.sample_rate() / 100, | |
338 0, | |
339 0, | |
340 true, | |
341 false)).Times(AtLeast(1)) | |
342 .WillRepeatedly(SignalEvent(&event_1)); | 319 .WillRepeatedly(SignalEvent(&event_1)); |
343 EXPECT_CALL(*sink_2, | 320 EXPECT_EQ(sink_1->audio_params().frames_per_buffer(), |
344 CaptureData(1, | 321 params.sample_rate() / 100); |
345 params.sample_rate(), | 322 EXPECT_CALL(*sink_2, CaptureData(1, 0, 0, _, false)).Times(AtLeast(1)) |
346 params.channels(), | |
347 params.sample_rate() / 100, | |
348 0, | |
349 0, | |
350 true, | |
351 false)).Times(AtLeast(1)) | |
352 .WillRepeatedly(SignalEvent(&event_2)); | 323 .WillRepeatedly(SignalEvent(&event_2)); |
| 324 EXPECT_EQ(sink_2->audio_params().frames_per_buffer(), |
| 325 params.sample_rate() / 100); |
353 track_2->AddSink(sink_2.get()); | 326 track_2->AddSink(sink_2.get()); |
354 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 327 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
355 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); | 328 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); |
356 | 329 |
357 track_1->RemoveSink(sink_1.get()); | 330 track_1->RemoveSink(sink_1.get()); |
358 track_1->Stop(); | 331 track_1->Stop(); |
359 track_1.reset(); | 332 track_1.reset(); |
360 | 333 |
361 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); | 334 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); |
362 track_2->RemoveSink(sink_2.get()); | 335 track_2->RemoveSink(sink_2.get()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 static_cast<webrtc::AudioTrackInterface*>( | 374 static_cast<webrtc::AudioTrackInterface*>( |
402 adapter_1.get())->GetRenderer()->AddChannel(0); | 375 adapter_1.get())->GetRenderer()->AddChannel(0); |
403 static_cast<WebRtcLocalAudioSourceProvider*>( | 376 static_cast<WebRtcLocalAudioSourceProvider*>( |
404 track_1->audio_source_provider())->SetSinkParamsForTesting(params_); | 377 track_1->audio_source_provider())->SetSinkParamsForTesting(params_); |
405 track_1->Start(); | 378 track_1->Start(); |
406 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 379 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
407 | 380 |
408 // Verify the data flow by connecting the sink to |track_1|. | 381 // Verify the data flow by connecting the sink to |track_1|. |
409 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 382 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
410 event.Reset(); | 383 event.Reset(); |
411 EXPECT_CALL(*sink, OnSetFormat(_)).WillOnce(SignalEvent(&event)); | 384 EXPECT_CALL(*sink, FormatIsSet()).WillOnce(SignalEvent(&event)); |
412 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, true, false)) | 385 EXPECT_CALL(*sink, CaptureData(_, 0, 0, _, false)) |
413 .Times(AnyNumber()).WillRepeatedly(Return()); | 386 .Times(AnyNumber()).WillRepeatedly(Return()); |
414 track_1->AddSink(sink.get()); | 387 track_1->AddSink(sink.get()); |
415 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 388 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
416 | 389 |
417 // Start the second audio track will not start the |capturer_source_| | 390 // Start the second audio track will not start the |capturer_source_| |
418 // since it has been started. | 391 // since it has been started. |
419 EXPECT_CALL(*capturer_source_.get(), OnStart()).Times(0); | 392 EXPECT_CALL(*capturer_source_.get(), OnStart()).Times(0); |
420 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( | 393 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( |
421 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 394 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
422 scoped_ptr<WebRtcLocalAudioTrack> track_2( | 395 scoped_ptr<WebRtcLocalAudioTrack> track_2( |
423 new WebRtcLocalAudioTrack(adapter_2, capturer_, NULL)); | 396 new WebRtcLocalAudioTrack(adapter_2, capturer_, NULL)); |
424 static_cast<WebRtcLocalAudioSourceProvider*>( | 397 static_cast<WebRtcLocalAudioSourceProvider*>( |
425 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); | 398 track_2->audio_source_provider())->SetSinkParamsForTesting(params_); |
426 track_2->Start(); | 399 track_2->Start(); |
427 static_cast<webrtc::AudioTrackInterface*>( | 400 static_cast<webrtc::AudioTrackInterface*>( |
428 adapter_2.get())->GetRenderer()->AddChannel(1); | 401 adapter_2.get())->GetRenderer()->AddChannel(1); |
429 | 402 |
430 // Stop the capturer will clear up the track lists in the capturer. | 403 // Stop the capturer will clear up the track lists in the capturer. |
431 EXPECT_CALL(*capturer_source_.get(), OnStop()); | 404 EXPECT_CALL(*capturer_source_.get(), OnStop()); |
432 capturer_->Stop(); | 405 capturer_->Stop(); |
433 | 406 |
434 // Adding a new track to the capturer. | 407 // Adding a new track to the capturer. |
435 track_2->AddSink(sink.get()); | 408 track_2->AddSink(sink.get()); |
436 EXPECT_CALL(*sink, OnSetFormat(_)).Times(0); | 409 EXPECT_CALL(*sink, FormatIsSet()).Times(0); |
437 | 410 |
438 // Stop the capturer again will not trigger stopping the source of the | 411 // Stop the capturer again will not trigger stopping the source of the |
439 // capturer again.. | 412 // capturer again.. |
440 event.Reset(); | 413 event.Reset(); |
441 EXPECT_CALL(*capturer_source_.get(), OnStop()).Times(0); | 414 EXPECT_CALL(*capturer_source_.get(), OnStop()).Times(0); |
442 capturer_->Stop(); | 415 capturer_->Stop(); |
443 } | 416 } |
444 | 417 |
445 // Create a new capturer with new source, connect it to a new audio track. | 418 // Create a new capturer with new source, connect it to a new audio track. |
446 TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) { | 419 TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) { |
447 // Setup the first audio track and start it. | 420 // Setup the first audio track and start it. |
448 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); | 421 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); |
449 EXPECT_CALL(*capturer_source_.get(), OnStart()); | 422 EXPECT_CALL(*capturer_source_.get(), OnStart()); |
450 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( | 423 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( |
451 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 424 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
452 scoped_ptr<WebRtcLocalAudioTrack> track_1( | 425 scoped_ptr<WebRtcLocalAudioTrack> track_1( |
453 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); | 426 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); |
454 static_cast<WebRtcLocalAudioSourceProvider*>( | 427 static_cast<WebRtcLocalAudioSourceProvider*>( |
455 track_1->audio_source_provider())->SetSinkParamsForTesting(params_); | 428 track_1->audio_source_provider())->SetSinkParamsForTesting(params_); |
456 track_1->Start(); | 429 track_1->Start(); |
457 | 430 |
458 // Connect a number of network channels to the |track_1|. | 431 // Connect a number of network channels to the |track_1|. |
459 static const int kNumberOfNetworkChannelsForTrack1 = 2; | 432 static const int kNumberOfNetworkChannelsForTrack1 = 2; |
460 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) { | 433 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) { |
461 static_cast<webrtc::AudioTrackInterface*>( | 434 static_cast<webrtc::AudioTrackInterface*>( |
462 adapter_1.get())->GetRenderer()->AddChannel(i); | 435 adapter_1.get())->GetRenderer()->AddChannel(i); |
463 } | 436 } |
464 // Verify the data flow by connecting the |sink_1| to |track_1|. | 437 // Verify the data flow by connecting the |sink_1| to |track_1|. |
465 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); | 438 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); |
466 EXPECT_CALL( | 439 EXPECT_CALL(*sink_1.get(), |
467 *sink_1.get(), | 440 CaptureData(kNumberOfNetworkChannelsForTrack1, |
468 CaptureData( | 441 0, 0, _, false)) |
469 kNumberOfNetworkChannelsForTrack1, 48000, 2, _, 0, 0, true, false)) | |
470 .Times(AnyNumber()).WillRepeatedly(Return()); | 442 .Times(AnyNumber()).WillRepeatedly(Return()); |
471 EXPECT_CALL(*sink_1.get(), OnSetFormat(_)).Times(AnyNumber()); | 443 EXPECT_CALL(*sink_1.get(), FormatIsSet()).Times(AnyNumber()); |
472 track_1->AddSink(sink_1.get()); | 444 track_1->AddSink(sink_1.get()); |
473 | 445 |
474 // Create a new capturer with new source with different audio format. | 446 // Create a new capturer with new source with different audio format. |
475 blink::WebMediaConstraints constraints; | 447 blink::WebMediaConstraints constraints; |
476 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE, | 448 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE, |
477 std::string(), std::string()); | 449 std::string(), std::string()); |
478 scoped_refptr<WebRtcAudioCapturer> new_capturer( | 450 scoped_refptr<WebRtcAudioCapturer> new_capturer( |
479 WebRtcAudioCapturer::CreateCapturer(-1, device, constraints, NULL)); | 451 WebRtcAudioCapturer::CreateCapturer(-1, device, constraints, NULL)); |
480 scoped_refptr<MockCapturerSource> new_source( | 452 scoped_refptr<MockCapturerSource> new_source( |
481 new MockCapturerSource(new_capturer.get())); | 453 new MockCapturerSource(new_capturer.get())); |
(...skipping 16 matching lines...) Expand all Loading... |
498 | 470 |
499 // Connect a number of network channels to the |track_2|. | 471 // Connect a number of network channels to the |track_2|. |
500 static const int kNumberOfNetworkChannelsForTrack2 = 3; | 472 static const int kNumberOfNetworkChannelsForTrack2 = 3; |
501 for (int i = 0; i < kNumberOfNetworkChannelsForTrack2; ++i) { | 473 for (int i = 0; i < kNumberOfNetworkChannelsForTrack2; ++i) { |
502 static_cast<webrtc::AudioTrackInterface*>( | 474 static_cast<webrtc::AudioTrackInterface*>( |
503 adapter_2.get())->GetRenderer()->AddChannel(i); | 475 adapter_2.get())->GetRenderer()->AddChannel(i); |
504 } | 476 } |
505 // Verify the data flow by connecting the |sink_2| to |track_2|. | 477 // Verify the data flow by connecting the |sink_2| to |track_2|. |
506 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); | 478 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); |
507 base::WaitableEvent event(false, false); | 479 base::WaitableEvent event(false, false); |
508 EXPECT_CALL( | 480 EXPECT_CALL(*sink_2, |
509 *sink_2, | 481 CaptureData(kNumberOfNetworkChannelsForTrack2, 0, 0, _, false)) |
510 CaptureData( | |
511 kNumberOfNetworkChannelsForTrack2, new_param.sample_rate(), | |
512 new_param.channels(), _, 0, 0, true, false)) | |
513 .Times(AnyNumber()).WillRepeatedly(Return()); | 482 .Times(AnyNumber()).WillRepeatedly(Return()); |
514 EXPECT_CALL(*sink_2, OnSetFormat(_)).WillOnce(SignalEvent(&event)); | 483 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(SignalEvent(&event)); |
515 track_2->AddSink(sink_2.get()); | 484 track_2->AddSink(sink_2.get()); |
516 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 485 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
517 | 486 |
518 // Stopping the new source will stop the second track. | 487 // Stopping the new source will stop the second track. |
519 event.Reset(); | 488 event.Reset(); |
520 EXPECT_CALL(*new_source.get(), OnStop()) | 489 EXPECT_CALL(*new_source.get(), OnStop()) |
521 .Times(1).WillOnce(SignalEvent(&event)); | 490 .Times(1).WillOnce(SignalEvent(&event)); |
522 new_capturer->Stop(); | 491 new_capturer->Stop(); |
523 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 492 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
524 | 493 |
525 // Stop the capturer of the first audio track. | 494 // Stop the capturer of the first audio track. |
526 EXPECT_CALL(*capturer_source_.get(), OnStop()); | 495 EXPECT_CALL(*capturer_source_.get(), OnStop()); |
527 capturer_->Stop(); | 496 capturer_->Stop(); |
528 } | 497 } |
529 | 498 |
530 | 499 |
531 // Make sure a audio track can deliver packets with a buffer size smaller than | 500 // Make sure a audio track can deliver packets with a buffer size smaller than |
532 // 10ms when it is not connected with a peer connection. | 501 // 10ms when it is not connected with a peer connection. |
533 TEST_F(WebRtcLocalAudioTrackTest, TrackWorkWithSmallBufferSize) { | 502 TEST_F(WebRtcLocalAudioTrackTest, TrackWorkWithSmallBufferSize) { |
534 // Setup a capturer which works with a buffer size smaller than 10ms. | 503 // Setup a capturer which works with a buffer size smaller than 10ms. |
535 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 504 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
536 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 128); | 505 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 128); |
537 | 506 |
538 // Create a capturer with new source which works with the format above. | 507 // Create a capturer with new source which works with the format above. |
539 blink::WebMediaConstraints constraints; | 508 MockMediaConstraintFactory factory; |
| 509 factory.DisableDefaultAudioConstraints(); |
540 scoped_refptr<WebRtcAudioCapturer> capturer( | 510 scoped_refptr<WebRtcAudioCapturer> capturer( |
541 WebRtcAudioCapturer::CreateCapturer( | 511 WebRtcAudioCapturer::CreateCapturer( |
542 -1, | 512 -1, |
543 StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, | 513 StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, |
544 "", "", params.sample_rate(), | 514 "", "", params.sample_rate(), |
545 params.channel_layout(), | 515 params.channel_layout(), |
546 params.frames_per_buffer()), | 516 params.frames_per_buffer()), |
547 constraints, | 517 factory.CreateWebMediaConstraints(), |
548 NULL)); | 518 NULL)); |
549 scoped_refptr<MockCapturerSource> source( | 519 scoped_refptr<MockCapturerSource> source( |
550 new MockCapturerSource(capturer.get())); | 520 new MockCapturerSource(capturer.get())); |
551 EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), -1)); | 521 EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), -1)); |
552 capturer->SetCapturerSourceForTesting(source, params); | 522 capturer->SetCapturerSourceForTesting(source, params); |
553 | 523 |
554 // Setup a audio track, connect it to the capturer and start it. | 524 // Setup a audio track, connect it to the capturer and start it. |
555 EXPECT_CALL(*source.get(), SetAutomaticGainControl(true)); | 525 EXPECT_CALL(*source.get(), SetAutomaticGainControl(true)); |
556 EXPECT_CALL(*source.get(), OnStart()); | 526 EXPECT_CALL(*source.get(), OnStart()); |
557 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 527 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
558 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 528 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
559 scoped_ptr<WebRtcLocalAudioTrack> track( | 529 scoped_ptr<WebRtcLocalAudioTrack> track( |
560 new WebRtcLocalAudioTrack(adapter, capturer, NULL)); | 530 new WebRtcLocalAudioTrack(adapter, capturer, NULL)); |
561 static_cast<WebRtcLocalAudioSourceProvider*>( | 531 static_cast<WebRtcLocalAudioSourceProvider*>( |
562 track->audio_source_provider())->SetSinkParamsForTesting(params); | 532 track->audio_source_provider())->SetSinkParamsForTesting(params); |
563 track->Start(); | 533 track->Start(); |
564 | 534 |
565 // Verify the data flow by connecting the |sink| to |track|. | 535 // Verify the data flow by connecting the |sink| to |track|. |
566 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 536 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
567 base::WaitableEvent event(false, false); | 537 base::WaitableEvent event(false, false); |
568 EXPECT_CALL(*sink, OnSetFormat(_)).Times(1); | 538 EXPECT_CALL(*sink, FormatIsSet()).Times(1); |
569 // Verify the sinks are getting the packets with an expecting buffer size. | 539 // Verify the sinks are getting the packets with an expecting buffer size. |
570 #if defined(OS_ANDROID) | 540 #if defined(OS_ANDROID) |
571 const int expected_buffer_size = params.sample_rate() / 100; | 541 const int expected_buffer_size = params.sample_rate() / 100; |
572 #else | 542 #else |
573 const int expected_buffer_size = params.frames_per_buffer(); | 543 const int expected_buffer_size = params.frames_per_buffer(); |
574 #endif | 544 #endif |
575 EXPECT_CALL(*sink, CaptureData( | 545 EXPECT_CALL(*sink, CaptureData( |
576 0, params.sample_rate(), params.channels(), expected_buffer_size, | 546 0, 0, 0, _, false)) |
577 0, 0, true, false)) | |
578 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); | 547 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); |
579 track->AddSink(sink.get()); | 548 track->AddSink(sink.get()); |
580 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 549 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
| 550 EXPECT_EQ(expected_buffer_size, sink->audio_params().frames_per_buffer()); |
581 | 551 |
582 // Stopping the new source will stop the second track. | 552 // Stopping the new source will stop the second track. |
583 EXPECT_CALL(*source, OnStop()).Times(1); | 553 EXPECT_CALL(*source, OnStop()).Times(1); |
584 capturer->Stop(); | 554 capturer->Stop(); |
585 } | 555 } |
586 | 556 |
587 } // namespace content | 557 } // namespace content |
OLD | NEW |