Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: content/renderer/media/webrtc_local_audio_track_unittest.cc

Issue 23691038: Switch LiveAudio to source provider solution. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: updated the comments and added notreached() Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_local_audio_source_provider.h"
9 #include "content/renderer/media/webrtc_local_audio_track.h" 10 #include "content/renderer/media/webrtc_local_audio_track.h"
10 #include "media/audio/audio_parameters.h" 11 #include "media/audio/audio_parameters.h"
11 #include "media/base/audio_bus.h" 12 #include "media/base/audio_bus.h"
12 #include "media/base/audio_capturer_source.h" 13 #include "media/base/audio_capturer_source.h"
13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" 16 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
16 17
17 using ::testing::_; 18 using ::testing::_;
18 using ::testing::AnyNumber; 19 using ::testing::AnyNumber;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 bool need_audio_processing, 127 bool need_audio_processing,
127 bool key_pressed)); 128 bool key_pressed));
128 MOCK_METHOD1(SetCaptureFormat, void(const media::AudioParameters& params)); 129 MOCK_METHOD1(SetCaptureFormat, void(const media::AudioParameters& params));
129 }; 130 };
130 131
131 } // namespace 132 } // namespace
132 133
133 class WebRtcLocalAudioTrackTest : public ::testing::Test { 134 class WebRtcLocalAudioTrackTest : public ::testing::Test {
134 protected: 135 protected:
135 virtual void SetUp() OVERRIDE { 136 virtual void SetUp() OVERRIDE {
137 params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
138 media::CHANNEL_LAYOUT_STEREO, 2, 0, 48000, 16, 480);
136 capturer_ = WebRtcAudioCapturer::CreateCapturer(); 139 capturer_ = WebRtcAudioCapturer::CreateCapturer();
140 // WebRtcLocalAudioSourceProvider* source_provider =
tommi (sloooow) - chröme 2013/09/12 20:40:55 remove this?
no longer working on chromium 2013/09/17 13:08:01 Sorry, we need this, uncomment these lines.
141 // static_cast<WebRtcLocalAudioSourceProvider*>(
142 // capturer_->audio_source_provider());
143 // source_provider->SetSinkParamsForTesting(params_);
137 capturer_source_ = new MockCapturerSource(); 144 capturer_source_ = new MockCapturerSource();
138 EXPECT_CALL(*capturer_source_.get(), Initialize(_, capturer_.get(), 0)) 145 EXPECT_CALL(*capturer_source_.get(), Initialize(_, capturer_.get(), 0))
139 .WillOnce(Return()); 146 .WillOnce(Return());
140 capturer_->SetCapturerSource(capturer_source_, 147 capturer_->SetCapturerSource(capturer_source_,
141 media::CHANNEL_LAYOUT_STEREO, 148 params_.channel_layout(),
142 48000); 149 params_.sample_rate());
143 150
144 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(false)) 151 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(false))
145 .WillOnce(Return()); 152 .WillOnce(Return());
146 153
147 // Start the audio thread used by the |capturer_source_|. 154 // Start the audio thread used by the |capturer_source_|.
148 audio_thread_.reset(new FakeAudioThread(capturer_)); 155 audio_thread_.reset(new FakeAudioThread(capturer_));
149 audio_thread_->Start(); 156 audio_thread_->Start();
150 } 157 }
151 158
152 virtual void TearDown() { 159 virtual void TearDown() {
153 audio_thread_->Stop(); 160 audio_thread_->Stop();
154 audio_thread_.reset(); 161 audio_thread_.reset();
155 } 162 }
156 163
164 media::AudioParameters params_;
157 scoped_refptr<MockCapturerSource> capturer_source_; 165 scoped_refptr<MockCapturerSource> capturer_source_;
158 scoped_refptr<WebRtcAudioCapturer> capturer_; 166 scoped_refptr<WebRtcAudioCapturer> capturer_;
159 scoped_ptr<FakeAudioThread> audio_thread_; 167 scoped_ptr<FakeAudioThread> audio_thread_;
160 }; 168 };
161 169
162 // Creates a capturer and audio track, fakes its audio thread, and 170 // Creates a capturer and audio track, fakes its audio thread, and
163 // connect/disconnect the sink to the audio track on the fly, the sink should 171 // connect/disconnect the sink to the audio track on the fly, the sink should
164 // get data callback when the track is connected to the capturer but not when 172 // get data callback when the track is connected to the capturer but not when
165 // the track is disconnected from the capturer. 173 // the track is disconnected from the capturer.
166 TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) { 174 TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) {
167 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); 175 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return());
168 RTCMediaConstraints constraints; 176 RTCMediaConstraints constraints;
169 scoped_refptr<WebRtcLocalAudioTrack> track = 177 scoped_refptr<WebRtcLocalAudioTrack> track =
170 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, 178 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL,
171 &constraints); 179 &constraints);
172 track->Start(); 180 track->Start();
173 EXPECT_TRUE(track->enabled()); 181 EXPECT_TRUE(track->enabled());
174 182
175 // Connect a number of network channels to the audio track. 183 // Connect a number of network channels to the audio track.
176 static const int kNumberOfNetworkChannels = 4; 184 static const int kNumberOfNetworkChannels = 4;
177 for (int i = 0; i < kNumberOfNetworkChannels; ++i) { 185 for (int i = 0; i < kNumberOfNetworkChannels; ++i) {
178 static_cast<webrtc::AudioTrackInterface*>(track.get())-> 186 static_cast<webrtc::AudioTrackInterface*>(track.get())->
179 GetRenderer()->AddChannel(i); 187 GetRenderer()->AddChannel(i);
180 } 188 }
(...skipping 25 matching lines...) Expand all
206 // The same setup as ConnectAndDisconnectOneSink, but enable and disable the 214 // The same setup as ConnectAndDisconnectOneSink, but enable and disable the
207 // audio track on the fly. When the audio track is disabled, there is no data 215 // audio track on the fly. When the audio track is disabled, there is no data
208 // callback to the sink; when the audio track is enabled, there comes data 216 // callback to the sink; when the audio track is enabled, there comes data
209 // callback. 217 // callback.
210 // TODO(xians): Enable this test after resolving the racing issue that TSAN 218 // TODO(xians): Enable this test after resolving the racing issue that TSAN
211 // reports on MediaStreamTrack::enabled(); 219 // reports on MediaStreamTrack::enabled();
212 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) { 220 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) {
213 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); 221 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return());
214 RTCMediaConstraints constraints; 222 RTCMediaConstraints constraints;
215 scoped_refptr<WebRtcLocalAudioTrack> track = 223 scoped_refptr<WebRtcLocalAudioTrack> track =
216 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, 224 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL,
217 &constraints); 225 &constraints);
218 track->Start(); 226 track->Start();
219 static_cast<webrtc::AudioTrackInterface*>(track.get())-> 227 static_cast<webrtc::AudioTrackInterface*>(track.get())->
220 GetRenderer()->AddChannel(0); 228 GetRenderer()->AddChannel(0);
221 EXPECT_TRUE(track->enabled()); 229 EXPECT_TRUE(track->enabled());
222 EXPECT_TRUE(track->set_enabled(false)); 230 EXPECT_TRUE(track->set_enabled(false));
223 scoped_ptr<MockWebRtcAudioCapturerSink> sink( 231 scoped_ptr<MockWebRtcAudioCapturerSink> sink(
224 new MockWebRtcAudioCapturerSink()); 232 new MockWebRtcAudioCapturerSink());
225 const media::AudioParameters params = capturer_->audio_parameters(); 233 const media::AudioParameters params = capturer_->audio_parameters();
226 base::WaitableEvent event(false, false); 234 base::WaitableEvent event(false, false);
(...skipping 29 matching lines...) Expand all
256 track->Stop(); 264 track->Stop();
257 track = NULL; 265 track = NULL;
258 } 266 }
259 267
260 // Create multiple audio tracks and enable/disable them, verify that the audio 268 // Create multiple audio tracks and enable/disable them, verify that the audio
261 // callbacks appear/disappear. 269 // callbacks appear/disappear.
262 TEST_F(WebRtcLocalAudioTrackTest, MultipleAudioTracks) { 270 TEST_F(WebRtcLocalAudioTrackTest, MultipleAudioTracks) {
263 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); 271 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return());
264 RTCMediaConstraints constraints; 272 RTCMediaConstraints constraints;
265 scoped_refptr<WebRtcLocalAudioTrack> track_1 = 273 scoped_refptr<WebRtcLocalAudioTrack> track_1 =
266 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, 274 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL,
267 &constraints); 275 &constraints);
268 track_1->Start(); 276 track_1->Start();
269 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> 277 static_cast<webrtc::AudioTrackInterface*>(track_1.get())->
270 GetRenderer()->AddChannel(0); 278 GetRenderer()->AddChannel(0);
271 EXPECT_TRUE(track_1->enabled()); 279 EXPECT_TRUE(track_1->enabled());
272 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( 280 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1(
273 new MockWebRtcAudioCapturerSink()); 281 new MockWebRtcAudioCapturerSink());
274 const media::AudioParameters params = capturer_->audio_parameters(); 282 const media::AudioParameters params = capturer_->audio_parameters();
275 base::WaitableEvent event_1(false, false); 283 base::WaitableEvent event_1(false, false);
276 EXPECT_CALL(*sink_1, SetCaptureFormat(_)).WillOnce(Return()); 284 EXPECT_CALL(*sink_1, SetCaptureFormat(_)).WillOnce(Return());
277 EXPECT_CALL(*sink_1, 285 EXPECT_CALL(*sink_1,
278 CaptureData(1, 286 CaptureData(1,
279 params.sample_rate(), 287 params.sample_rate(),
280 params.channels(), 288 params.channels(),
281 params.frames_per_buffer(), 289 params.frames_per_buffer(),
282 0, 290 0,
283 0, 291 0,
284 false, 292 false,
285 false)).Times(AtLeast(1)) 293 false)).Times(AtLeast(1))
286 .WillRepeatedly(SignalEvent(&event_1)); 294 .WillRepeatedly(SignalEvent(&event_1));
287 track_1->AddSink(sink_1.get()); 295 track_1->AddSink(sink_1.get());
288 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); 296 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout()));
289 297
290 scoped_refptr<WebRtcLocalAudioTrack> track_2 = 298 scoped_refptr<WebRtcLocalAudioTrack> track_2 =
291 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, 299 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL,
292 &constraints); 300 &constraints);
293 track_2->Start(); 301 track_2->Start();
294 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> 302 static_cast<webrtc::AudioTrackInterface*>(track_2.get())->
295 GetRenderer()->AddChannel(1); 303 GetRenderer()->AddChannel(1);
296 EXPECT_TRUE(track_2->enabled()); 304 EXPECT_TRUE(track_2->enabled());
297 305
298 // Verify both |sink_1| and |sink_2| get data. 306 // Verify both |sink_1| and |sink_2| get data.
299 event_1.Reset(); 307 event_1.Reset();
300 base::WaitableEvent event_2(false, false); 308 base::WaitableEvent event_2(false, false);
301 309
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 track_2 = NULL; 344 track_2 = NULL;
337 } 345 }
338 346
339 347
340 // Start one track and verify the capturer is correctly starting its source. 348 // Start one track and verify the capturer is correctly starting its source.
341 // And it should be fine to not to call Stop() explicitly. 349 // And it should be fine to not to call Stop() explicitly.
342 TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) { 350 TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) {
343 EXPECT_CALL(*capturer_source_.get(), Start()).Times(1); 351 EXPECT_CALL(*capturer_source_.get(), Start()).Times(1);
344 RTCMediaConstraints constraints; 352 RTCMediaConstraints constraints;
345 scoped_refptr<WebRtcLocalAudioTrack> track = 353 scoped_refptr<WebRtcLocalAudioTrack> track =
346 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, 354 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL,
347 &constraints); 355 &constraints);
348 track->Start(); 356 track->Start();
349 357
350 // When the track goes away, it will automatically stop the 358 // When the track goes away, it will automatically stop the
351 // |capturer_source_|. 359 // |capturer_source_|.
352 EXPECT_CALL(*capturer_source_.get(), Stop()); 360 EXPECT_CALL(*capturer_source_.get(), Stop());
353 track->Stop(); 361 track->Stop();
354 track = NULL; 362 track = NULL;
355 } 363 }
356 364
357 // Start/Stop tracks and verify the capturer is correctly starting/stopping 365 // Start/Stop tracks and verify the capturer is correctly starting/stopping
358 // its source. 366 // its source.
359 TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { 367 TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) {
360 // Starting the first audio track will start the |capturer_source_|. 368 // Starting the first audio track will start the |capturer_source_|.
361 base::WaitableEvent event(false, false); 369 base::WaitableEvent event(false, false);
362 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(SignalEvent(&event)); 370 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(SignalEvent(&event));
363 RTCMediaConstraints constraints; 371 RTCMediaConstraints constraints;
364 scoped_refptr<WebRtcLocalAudioTrack> track_1 = 372 scoped_refptr<WebRtcLocalAudioTrack> track_1 =
365 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, 373 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL,
366 &constraints); 374 &constraints);
367 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> 375 static_cast<webrtc::AudioTrackInterface*>(track_1.get())->
368 GetRenderer()->AddChannel(0); 376 GetRenderer()->AddChannel(0);
369 track_1->Start(); 377 track_1->Start();
370 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); 378 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout()));
371 379
372 // Verify the data flow by connecting the sink to |track_1|. 380 // Verify the data flow by connecting the sink to |track_1|.
373 scoped_ptr<MockWebRtcAudioCapturerSink> sink( 381 scoped_ptr<MockWebRtcAudioCapturerSink> sink(
374 new MockWebRtcAudioCapturerSink()); 382 new MockWebRtcAudioCapturerSink());
375 event.Reset(); 383 event.Reset();
376 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, false, false)) 384 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, false, false))
377 .Times(AnyNumber()).WillRepeatedly(Return()); 385 .Times(AnyNumber()).WillRepeatedly(Return());
378 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1); 386 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1);
379 track_1->AddSink(sink.get()); 387 track_1->AddSink(sink.get());
380 388
381 // Start the second audio track will not start the |capturer_source_| 389 // Start the second audio track will not start the |capturer_source_|
382 // since it has been started. 390 // since it has been started.
383 EXPECT_CALL(*capturer_source_.get(), Start()).Times(0); 391 EXPECT_CALL(*capturer_source_.get(), Start()).Times(0);
384 scoped_refptr<WebRtcLocalAudioTrack> track_2 = 392 scoped_refptr<WebRtcLocalAudioTrack> track_2 =
385 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, 393 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL,
386 &constraints); 394 &constraints);
387 track_2->Start(); 395 track_2->Start();
388 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> 396 static_cast<webrtc::AudioTrackInterface*>(track_2.get())->
389 GetRenderer()->AddChannel(1); 397 GetRenderer()->AddChannel(1);
390 398
391 // Stop the first audio track will not stop the |capturer_source_|. 399 // Stop the first audio track will not stop the |capturer_source_|.
392 EXPECT_CALL(*capturer_source_.get(), Stop()).Times(0); 400 EXPECT_CALL(*capturer_source_.get(), Stop()).Times(0);
393 track_1->RemoveSink(sink.get()); 401 track_1->RemoveSink(sink.get());
394 track_1->Stop(); 402 track_1->Stop();
395 track_1 = NULL; 403 track_1 = NULL;
(...skipping 12 matching lines...) Expand all
408 track_2 = NULL; 416 track_2 = NULL;
409 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); 417 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout()));
410 } 418 }
411 419
412 // Set new source to the existing capturer. 420 // Set new source to the existing capturer.
413 TEST_F(WebRtcLocalAudioTrackTest, SetNewSourceForCapturerAfterStartTrack) { 421 TEST_F(WebRtcLocalAudioTrackTest, SetNewSourceForCapturerAfterStartTrack) {
414 // Setup the audio track and start the track. 422 // Setup the audio track and start the track.
415 EXPECT_CALL(*capturer_source_.get(), Start()).Times(1); 423 EXPECT_CALL(*capturer_source_.get(), Start()).Times(1);
416 RTCMediaConstraints constraints; 424 RTCMediaConstraints constraints;
417 scoped_refptr<WebRtcLocalAudioTrack> track = 425 scoped_refptr<WebRtcLocalAudioTrack> track =
418 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, 426 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL,
419 &constraints); 427 &constraints);
420 track->Start(); 428 track->Start();
421 429
422 // Setting new source to the capturer and the track should still get packets. 430 // Setting new source to the capturer and the track should still get packets.
423 scoped_refptr<MockCapturerSource> new_source(new MockCapturerSource()); 431 scoped_refptr<MockCapturerSource> new_source(new MockCapturerSource());
424 EXPECT_CALL(*capturer_source_.get(), Stop()); 432 EXPECT_CALL(*capturer_source_.get(), Stop());
425 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(false)); 433 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(false));
426 EXPECT_CALL(*new_source.get(), Initialize(_, capturer_.get(), 0)) 434 EXPECT_CALL(*new_source.get(), Initialize(_, capturer_.get(), 0))
427 .WillOnce(Return()); 435 .WillOnce(Return());
428 EXPECT_CALL(*new_source.get(), Start()).WillOnce(Return()); 436 EXPECT_CALL(*new_source.get(), Start()).WillOnce(Return());
429 capturer_->SetCapturerSource(new_source, 437 capturer_->SetCapturerSource(new_source,
430 media::CHANNEL_LAYOUT_STEREO, 438 params_.channel_layout(),
431 48000); 439 params_.sample_rate());
432 440
433 // Stop the track. 441 // Stop the track.
434 EXPECT_CALL(*new_source.get(), Stop()); 442 EXPECT_CALL(*new_source.get(), Stop());
435 track->Stop(); 443 track->Stop();
436 track = NULL; 444 track = NULL;
437 } 445 }
438 446
439 // Create a new capturer with new source, connect it to a new audio track. 447 // Create a new capturer with new source, connect it to a new audio track.
440 TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) { 448 TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) {
441 // Setup the first audio track and start it. 449 // Setup the first audio track and start it.
442 EXPECT_CALL(*capturer_source_.get(), Start()).Times(1); 450 EXPECT_CALL(*capturer_source_.get(), Start()).Times(1);
443 RTCMediaConstraints constraints; 451 RTCMediaConstraints constraints;
444 scoped_refptr<WebRtcLocalAudioTrack> track_1 = 452 scoped_refptr<WebRtcLocalAudioTrack> track_1 =
445 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, 453 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, NULL,
446 &constraints); 454 &constraints);
447 track_1->Start(); 455 track_1->Start();
448 456
449 // Connect a number of network channels to the |track_1|. 457 // Connect a number of network channels to the |track_1|.
450 static const int kNumberOfNetworkChannelsForTrack1 = 2; 458 static const int kNumberOfNetworkChannelsForTrack1 = 2;
451 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) { 459 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) {
452 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> 460 static_cast<webrtc::AudioTrackInterface*>(track_1.get())->
453 GetRenderer()->AddChannel(i); 461 GetRenderer()->AddChannel(i);
454 } 462 }
455 // Verify the data flow by connecting the |sink_1| to |track_1|. 463 // Verify the data flow by connecting the |sink_1| to |track_1|.
456 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( 464 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1(
457 new MockWebRtcAudioCapturerSink()); 465 new MockWebRtcAudioCapturerSink());
458 EXPECT_CALL( 466 EXPECT_CALL(
459 *sink_1.get(), 467 *sink_1.get(),
460 CaptureData( 468 CaptureData(
461 kNumberOfNetworkChannelsForTrack1, 48000, 2, _, 0, 0, false, false)) 469 kNumberOfNetworkChannelsForTrack1, 48000, 2, _, 0, 0, false, false))
462 .Times(AnyNumber()).WillRepeatedly(Return()); 470 .Times(AnyNumber()).WillRepeatedly(Return());
463 EXPECT_CALL(*sink_1.get(), SetCaptureFormat(_)).Times(1); 471 EXPECT_CALL(*sink_1.get(), SetCaptureFormat(_)).Times(1);
464 track_1->AddSink(sink_1.get()); 472 track_1->AddSink(sink_1.get());
465 473
466 // Create a new capturer with new source with different audio format. 474 // Create a new capturer with new source with different audio format.
467 scoped_refptr<WebRtcAudioCapturer> new_capturer( 475 scoped_refptr<WebRtcAudioCapturer> new_capturer(
468 WebRtcAudioCapturer::CreateCapturer()); 476 WebRtcAudioCapturer::CreateCapturer());
477 WebRtcLocalAudioSourceProvider* source_provider =
478 static_cast<WebRtcLocalAudioSourceProvider*>(
479 new_capturer->audio_source_provider());
480 source_provider->SetSinkParamsForTesting(params_);
469 scoped_refptr<MockCapturerSource> new_source(new MockCapturerSource()); 481 scoped_refptr<MockCapturerSource> new_source(new MockCapturerSource());
470 EXPECT_CALL(*new_source.get(), Initialize(_, new_capturer.get(), 0)) 482 EXPECT_CALL(*new_source.get(), Initialize(_, new_capturer.get(), 0))
471 .WillOnce(Return()); 483 .WillOnce(Return());
472 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(false)) 484 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(false))
473 .WillOnce(Return()); 485 .WillOnce(Return());
474 new_capturer->SetCapturerSource(new_source, 486 new_capturer->SetCapturerSource(new_source,
475 media::CHANNEL_LAYOUT_MONO, 487 media::CHANNEL_LAYOUT_MONO,
476 44100); 488 44100);
477 489
478 // Start the audio thread used by the new source. 490 // Start the audio thread used by the new source.
479 scoped_ptr<FakeAudioThread> audio_thread(new FakeAudioThread(new_capturer)); 491 scoped_ptr<FakeAudioThread> audio_thread(new FakeAudioThread(new_capturer));
480 audio_thread->Start(); 492 audio_thread->Start();
481 493
482 // Setup the second audio track, connect it to the new capturer and start it. 494 // Setup the second audio track, connect it to the new capturer and start it.
483 EXPECT_CALL(*new_source.get(), Start()).Times(1); 495 EXPECT_CALL(*new_source.get(), Start()).Times(1);
484 scoped_refptr<WebRtcLocalAudioTrack> track_2 = 496 scoped_refptr<WebRtcLocalAudioTrack> track_2 =
485 WebRtcLocalAudioTrack::Create(std::string(), new_capturer, NULL, 497 WebRtcLocalAudioTrack::Create(std::string(), new_capturer, NULL, NULL,
486 &constraints); 498 &constraints);
487 track_2->Start(); 499 track_2->Start();
488 500
489 // Connect a number of network channels to the |track_2|. 501 // Connect a number of network channels to the |track_2|.
490 static const int kNumberOfNetworkChannelsForTrack2 = 3; 502 static const int kNumberOfNetworkChannelsForTrack2 = 3;
491 for (int i = 0; i < kNumberOfNetworkChannelsForTrack2; ++i) { 503 for (int i = 0; i < kNumberOfNetworkChannelsForTrack2; ++i) {
492 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> 504 static_cast<webrtc::AudioTrackInterface*>(track_2.get())->
493 GetRenderer()->AddChannel(i); 505 GetRenderer()->AddChannel(i);
494 } 506 }
495 // Verify the data flow by connecting the |sink_2| to |track_2|. 507 // Verify the data flow by connecting the |sink_2| to |track_2|.
(...skipping 17 matching lines...) Expand all
513 audio_thread->Stop(); 525 audio_thread->Stop();
514 audio_thread.reset(); 526 audio_thread.reset();
515 527
516 // Stop the first audio track. 528 // Stop the first audio track.
517 EXPECT_CALL(*capturer_source_.get(), Stop()); 529 EXPECT_CALL(*capturer_source_.get(), Stop());
518 track_1->Stop(); 530 track_1->Stop();
519 track_1 = NULL; 531 track_1 = NULL;
520 } 532 }
521 533
522 } // namespace content 534 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698