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

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

Issue 218763007: Update MediaStreamTrack::Stop to latest draft. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 6 years, 8 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/media_stream_audio_source.h"
7 #include "content/renderer/media/mock_media_constraint_factory.h" 8 #include "content/renderer/media/mock_media_constraint_factory.h"
8 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" 9 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h"
9 #include "content/renderer/media/webrtc_audio_capturer.h" 10 #include "content/renderer/media/webrtc_audio_capturer.h"
10 #include "content/renderer/media/webrtc_audio_device_impl.h" 11 #include "content/renderer/media/webrtc_audio_device_impl.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 10 matching lines...) Expand all
27 namespace { 28 namespace {
28 29
29 ACTION_P(SignalEvent, event) { 30 ACTION_P(SignalEvent, event) {
30 event->Signal(); 31 event->Signal();
31 } 32 }
32 33
33 // A simple thread that we use to fake the audio thread which provides data to 34 // A simple thread that we use to fake the audio thread which provides data to
34 // the |WebRtcAudioCapturer|. 35 // the |WebRtcAudioCapturer|.
35 class FakeAudioThread : public base::PlatformThread::Delegate { 36 class FakeAudioThread : public base::PlatformThread::Delegate {
36 public: 37 public:
37 FakeAudioThread(const scoped_refptr<WebRtcAudioCapturer>& capturer, 38 FakeAudioThread(WebRtcAudioCapturer* capturer,
38 const media::AudioParameters& params) 39 const media::AudioParameters& params)
39 : capturer_(capturer), 40 : capturer_(capturer),
40 thread_(), 41 thread_(),
41 closure_(false, false) { 42 closure_(false, false) {
42 DCHECK(capturer.get()); 43 DCHECK(capturer);
43 audio_bus_ = media::AudioBus::Create(params); 44 audio_bus_ = media::AudioBus::Create(params);
44 } 45 }
45 46
46 virtual ~FakeAudioThread() { DCHECK(thread_.is_null()); } 47 virtual ~FakeAudioThread() { DCHECK(thread_.is_null()); }
47 48
48 // base::PlatformThread::Delegate: 49 // base::PlatformThread::Delegate:
49 virtual void ThreadMain() OVERRIDE { 50 virtual void ThreadMain() OVERRIDE {
50 while (true) { 51 while (true) {
51 if (closure_.IsSignaled()) 52 if (closure_.IsSignaled())
52 return; 53 return;
53 54
54 media::AudioCapturerSource::CaptureCallback* callback = 55 media::AudioCapturerSource::CaptureCallback* callback =
55 static_cast<media::AudioCapturerSource::CaptureCallback*>( 56 static_cast<media::AudioCapturerSource::CaptureCallback*>(
56 capturer_.get()); 57 capturer_);
57 audio_bus_->Zero(); 58 audio_bus_->Zero();
58 callback->Capture(audio_bus_.get(), 0, 0, false); 59 callback->Capture(audio_bus_.get(), 0, 0, false);
59 60
60 // Sleep 1ms to yield the resource for the main thread. 61 // Sleep 1ms to yield the resource for the main thread.
61 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); 62 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1));
62 } 63 }
63 } 64 }
64 65
65 void Start() { 66 void Start() {
66 base::PlatformThread::CreateWithPriority( 67 base::PlatformThread::CreateWithPriority(
67 0, this, &thread_, base::kThreadPriority_RealtimeAudio); 68 0, this, &thread_, base::kThreadPriority_RealtimeAudio);
68 CHECK(!thread_.is_null()); 69 CHECK(!thread_.is_null());
69 } 70 }
70 71
71 void Stop() { 72 void Stop() {
72 closure_.Signal(); 73 closure_.Signal();
73 base::PlatformThread::Join(thread_); 74 base::PlatformThread::Join(thread_);
74 thread_ = base::PlatformThreadHandle(); 75 thread_ = base::PlatformThreadHandle();
75 } 76 }
76 77
77 private: 78 private:
78 scoped_ptr<media::AudioBus> audio_bus_; 79 scoped_ptr<media::AudioBus> audio_bus_;
79 scoped_refptr<WebRtcAudioCapturer> capturer_; 80 WebRtcAudioCapturer* capturer_;
80 base::PlatformThreadHandle thread_; 81 base::PlatformThreadHandle thread_;
81 base::WaitableEvent closure_; 82 base::WaitableEvent closure_;
82 DISALLOW_COPY_AND_ASSIGN(FakeAudioThread); 83 DISALLOW_COPY_AND_ASSIGN(FakeAudioThread);
83 }; 84 };
84 85
85 class MockCapturerSource : public media::AudioCapturerSource { 86 class MockCapturerSource : public media::AudioCapturerSource {
86 public: 87 public:
87 explicit MockCapturerSource(WebRtcAudioCapturer* capturer) 88 explicit MockCapturerSource(WebRtcAudioCapturer* capturer)
88 : capturer_(capturer) {} 89 : capturer_(capturer) {}
89 MOCK_METHOD3(OnInitialize, void(const media::AudioParameters& params, 90 MOCK_METHOD3(OnInitialize, void(const media::AudioParameters& params,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 }; 164 };
164 165
165 } // namespace 166 } // namespace
166 167
167 class WebRtcLocalAudioTrackTest : public ::testing::Test { 168 class WebRtcLocalAudioTrackTest : public ::testing::Test {
168 protected: 169 protected:
169 virtual void SetUp() OVERRIDE { 170 virtual void SetUp() OVERRIDE {
170 params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 171 params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
171 media::CHANNEL_LAYOUT_STEREO, 2, 0, 48000, 16, 480); 172 media::CHANNEL_LAYOUT_STEREO, 2, 0, 48000, 16, 480);
172 blink::WebMediaConstraints constraints; 173 blink::WebMediaConstraints constraints;
174 blink_source_.initialize("dummy", blink::WebMediaStreamSource::TypeAudio,
175 "dummy");
176 MediaStreamAudioSource* audio_source = new MediaStreamAudioSource();
177 blink_source_.setExtraData(audio_source);
178
173 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE, 179 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE,
174 std::string(), std::string()); 180 std::string(), std::string());
175 capturer_ = WebRtcAudioCapturer::CreateCapturer(-1, device, 181 capturer_ = WebRtcAudioCapturer::CreateCapturer(-1, device,
176 constraints, NULL); 182 constraints, NULL,
183 audio_source);
184 audio_source->SetAudioCapturer(capturer_);
177 capturer_source_ = new MockCapturerSource(capturer_.get()); 185 capturer_source_ = new MockCapturerSource(capturer_.get());
178 EXPECT_CALL(*capturer_source_.get(), OnInitialize(_, capturer_.get(), -1)) 186 EXPECT_CALL(*capturer_source_.get(), OnInitialize(_, capturer_.get(), -1))
179 .WillOnce(Return()); 187 .WillOnce(Return());
188 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
189 EXPECT_CALL(*capturer_source_.get(), OnStart());
180 capturer_->SetCapturerSourceForTesting(capturer_source_, params_); 190 capturer_->SetCapturerSourceForTesting(capturer_source_, params_);
181 } 191 }
182 192
183 media::AudioParameters params_; 193 media::AudioParameters params_;
194 blink::WebMediaStreamSource blink_source_;
184 scoped_refptr<MockCapturerSource> capturer_source_; 195 scoped_refptr<MockCapturerSource> capturer_source_;
185 scoped_refptr<WebRtcAudioCapturer> capturer_; 196 scoped_refptr<WebRtcAudioCapturer> capturer_;
186 }; 197 };
187 198
188 // Creates a capturer and audio track, fakes its audio thread, and 199 // Creates a capturer and audio track, fakes its audio thread, and
189 // connect/disconnect the sink to the audio track on the fly, the sink should 200 // connect/disconnect the sink to the audio track on the fly, the sink should
190 // get data callback when the track is connected to the capturer but not when 201 // get data callback when the track is connected to the capturer but not when
191 // the track is disconnected from the capturer. 202 // the track is disconnected from the capturer.
192 TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) { 203 TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) {
193 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
194 EXPECT_CALL(*capturer_source_.get(), OnStart());
195 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( 204 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
196 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 205 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
197 scoped_ptr<WebRtcLocalAudioTrack> track( 206 scoped_ptr<WebRtcLocalAudioTrack> track(
198 new WebRtcLocalAudioTrack(adapter, capturer_, NULL)); 207 new WebRtcLocalAudioTrack(adapter, capturer_, NULL));
199 track->Start(); 208 track->Start();
200 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); 209 EXPECT_TRUE(track->GetAudioAdapter()->enabled());
201 210
202 // Connect a number of network channels to the audio track. 211 // Connect a number of network channels to the audio track.
203 static const int kNumberOfNetworkChannels = 4; 212 static const int kNumberOfNetworkChannels = 4;
204 for (int i = 0; i < kNumberOfNetworkChannels; ++i) { 213 for (int i = 0; i < kNumberOfNetworkChannels; ++i) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 271
263 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); 272 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return());
264 capturer_->Stop(); 273 capturer_->Stop();
265 track.reset(); 274 track.reset();
266 } 275 }
267 276
268 // Create multiple audio tracks and enable/disable them, verify that the audio 277 // Create multiple audio tracks and enable/disable them, verify that the audio
269 // callbacks appear/disappear. 278 // callbacks appear/disappear.
270 // Flaky due to a data race, see http://crbug.com/295418 279 // Flaky due to a data race, see http://crbug.com/295418
271 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) { 280 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) {
272 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
273 EXPECT_CALL(*capturer_source_.get(), OnStart());
274 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( 281 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1(
275 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 282 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
276 scoped_ptr<WebRtcLocalAudioTrack> track_1( 283 scoped_ptr<WebRtcLocalAudioTrack> track_1(
277 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); 284 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL));
278 track_1->Start(); 285 track_1->Start();
279 static_cast<webrtc::AudioTrackInterface*>( 286 static_cast<webrtc::AudioTrackInterface*>(
280 adapter_1.get())->GetRenderer()->AddChannel(0); 287 adapter_1.get())->GetRenderer()->AddChannel(0);
281 EXPECT_TRUE(track_1->GetAudioAdapter()->enabled()); 288 EXPECT_TRUE(track_1->GetAudioAdapter()->enabled());
282 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); 289 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink());
283 const media::AudioParameters params = capturer_->source_audio_parameters(); 290 const media::AudioParameters params = capturer_->source_audio_parameters();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); 326 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout()));
320 327
321 track_1->RemoveSink(sink_1.get()); 328 track_1->RemoveSink(sink_1.get());
322 track_1->Stop(); 329 track_1->Stop();
323 track_1.reset(); 330 track_1.reset();
324 331
325 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); 332 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return());
326 track_2->RemoveSink(sink_2.get()); 333 track_2->RemoveSink(sink_2.get());
327 track_2->Stop(); 334 track_2->Stop();
328 track_2.reset(); 335 track_2.reset();
329
330 capturer_->Stop();
331 } 336 }
332 337
333 338
334 // Start one track and verify the capturer is correctly starting its source. 339 // Start one track and verify the capturer is correctly starting its source.
335 // And it should be fine to not to call Stop() explicitly. 340 // And it should be fine to not to call Stop() explicitly.
336 TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) { 341 TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) {
337 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
338 EXPECT_CALL(*capturer_source_.get(), OnStart());
339 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( 342 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
340 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 343 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
341 scoped_ptr<WebRtcLocalAudioTrack> track( 344 scoped_ptr<WebRtcLocalAudioTrack> track(
342 new WebRtcLocalAudioTrack(adapter, capturer_, NULL)); 345 new WebRtcLocalAudioTrack(adapter, capturer_, NULL));
343 track->Start(); 346 track->Start();
344 347
345 // When the track goes away, it will automatically stop the 348 // When the track goes away, it will automatically stop the
346 // |capturer_source_|. 349 // |capturer_source_|.
347 EXPECT_CALL(*capturer_source_.get(), OnStop()); 350 EXPECT_CALL(*capturer_source_.get(), OnStop());
348 capturer_->Stop();
349 track.reset(); 351 track.reset();
350 } 352 }
351 353
354 // Start two tracks and verify the capturer is correctly starting its source.
355 // When the last track connected to the capturer is stopped, the source is
356 // stopped.
357 TEST_F(WebRtcLocalAudioTrackTest, StartTwoAudioTracks) {
358 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter1(
359 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
360 scoped_ptr<WebRtcLocalAudioTrack> track1(
361 new WebRtcLocalAudioTrack(adapter1, capturer_, NULL));
362 track1->Start();
363
364 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter2(
365 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
366 scoped_ptr<WebRtcLocalAudioTrack> track2(
367 new WebRtcLocalAudioTrack(adapter2, capturer_, NULL));
368 track2->Start();
369
370 track1->Stop();
371 // When the last track is stopped, it will automatically stop the
372 // |capturer_source_|.
373 EXPECT_CALL(*capturer_source_.get(), OnStop());
374 track2->Stop();
375 }
376
352 // Start/Stop tracks and verify the capturer is correctly starting/stopping 377 // Start/Stop tracks and verify the capturer is correctly starting/stopping
353 // its source. 378 // its source.
354 TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { 379 TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) {
355 // Starting the first audio track will start the |capturer_source_|.
356 base::WaitableEvent event(false, false); 380 base::WaitableEvent event(false, false);
357 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
358 EXPECT_CALL(*capturer_source_.get(), OnStart()).WillOnce(SignalEvent(&event));
359 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( 381 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1(
360 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 382 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
361 scoped_ptr<WebRtcLocalAudioTrack> track_1( 383 scoped_ptr<WebRtcLocalAudioTrack> track_1(
362 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); 384 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL));
363 static_cast<webrtc::AudioTrackInterface*>( 385 static_cast<webrtc::AudioTrackInterface*>(
364 adapter_1.get())->GetRenderer()->AddChannel(0); 386 adapter_1.get())->GetRenderer()->AddChannel(0);
365 track_1->Start(); 387 track_1->Start();
366 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout()));
367 388
368 // Verify the data flow by connecting the sink to |track_1|. 389 // Verify the data flow by connecting the sink to |track_1|.
369 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); 390 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink());
370 event.Reset(); 391 event.Reset();
371 EXPECT_CALL(*sink, FormatIsSet()).WillOnce(SignalEvent(&event)); 392 EXPECT_CALL(*sink, FormatIsSet()).WillOnce(SignalEvent(&event));
372 EXPECT_CALL(*sink, CaptureData(_, 0, 0, _, false)) 393 EXPECT_CALL(*sink, CaptureData(_, 0, 0, _, false))
373 .Times(AnyNumber()).WillRepeatedly(Return()); 394 .Times(AnyNumber()).WillRepeatedly(Return());
374 track_1->AddSink(sink.get()); 395 track_1->AddSink(sink.get());
375 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); 396 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout()));
376 397
(...skipping 19 matching lines...) Expand all
396 // Stop the capturer again will not trigger stopping the source of the 417 // Stop the capturer again will not trigger stopping the source of the
397 // capturer again.. 418 // capturer again..
398 event.Reset(); 419 event.Reset();
399 EXPECT_CALL(*capturer_source_.get(), OnStop()).Times(0); 420 EXPECT_CALL(*capturer_source_.get(), OnStop()).Times(0);
400 capturer_->Stop(); 421 capturer_->Stop();
401 } 422 }
402 423
403 // Create a new capturer with new source, connect it to a new audio track. 424 // Create a new capturer with new source, connect it to a new audio track.
404 TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) { 425 TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) {
405 // Setup the first audio track and start it. 426 // Setup the first audio track and start it.
406 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
407 EXPECT_CALL(*capturer_source_.get(), OnStart());
408 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( 427 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1(
409 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 428 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
410 scoped_ptr<WebRtcLocalAudioTrack> track_1( 429 scoped_ptr<WebRtcLocalAudioTrack> track_1(
411 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); 430 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL));
412 track_1->Start(); 431 track_1->Start();
413 432
414 // Connect a number of network channels to the |track_1|. 433 // Connect a number of network channels to the |track_1|.
415 static const int kNumberOfNetworkChannelsForTrack1 = 2; 434 static const int kNumberOfNetworkChannelsForTrack1 = 2;
416 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) { 435 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) {
417 static_cast<webrtc::AudioTrackInterface*>( 436 static_cast<webrtc::AudioTrackInterface*>(
418 adapter_1.get())->GetRenderer()->AddChannel(i); 437 adapter_1.get())->GetRenderer()->AddChannel(i);
419 } 438 }
420 // Verify the data flow by connecting the |sink_1| to |track_1|. 439 // Verify the data flow by connecting the |sink_1| to |track_1|.
421 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); 440 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink());
422 EXPECT_CALL(*sink_1.get(), 441 EXPECT_CALL(*sink_1.get(),
423 CaptureData(kNumberOfNetworkChannelsForTrack1, 442 CaptureData(kNumberOfNetworkChannelsForTrack1,
424 0, 0, _, false)) 443 0, 0, _, false))
425 .Times(AnyNumber()).WillRepeatedly(Return()); 444 .Times(AnyNumber()).WillRepeatedly(Return());
426 EXPECT_CALL(*sink_1.get(), FormatIsSet()).Times(AnyNumber()); 445 EXPECT_CALL(*sink_1.get(), FormatIsSet()).Times(AnyNumber());
427 track_1->AddSink(sink_1.get()); 446 track_1->AddSink(sink_1.get());
428 447
429 // Create a new capturer with new source with different audio format. 448 // Create a new capturer with new source with different audio format.
430 blink::WebMediaConstraints constraints; 449 blink::WebMediaConstraints constraints;
431 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE, 450 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE,
432 std::string(), std::string()); 451 std::string(), std::string());
433 scoped_refptr<WebRtcAudioCapturer> new_capturer( 452 scoped_refptr<WebRtcAudioCapturer> new_capturer(
434 WebRtcAudioCapturer::CreateCapturer(-1, device, constraints, NULL)); 453 WebRtcAudioCapturer::CreateCapturer(-1, device, constraints, NULL, NULL));
435 scoped_refptr<MockCapturerSource> new_source( 454 scoped_refptr<MockCapturerSource> new_source(
436 new MockCapturerSource(new_capturer.get())); 455 new MockCapturerSource(new_capturer.get()));
437 EXPECT_CALL(*new_source.get(), OnInitialize(_, new_capturer.get(), -1)); 456 EXPECT_CALL(*new_source.get(), OnInitialize(_, new_capturer.get(), -1));
457 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true));
458 EXPECT_CALL(*new_source.get(), OnStart());
459
438 media::AudioParameters new_param( 460 media::AudioParameters new_param(
439 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 461 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
440 media::CHANNEL_LAYOUT_MONO, 44100, 16, 441); 462 media::CHANNEL_LAYOUT_MONO, 44100, 16, 441);
441 new_capturer->SetCapturerSourceForTesting(new_source, new_param); 463 new_capturer->SetCapturerSourceForTesting(new_source, new_param);
442 464
443 // Setup the second audio track, connect it to the new capturer and start it. 465 // Setup the second audio track, connect it to the new capturer and start it.
444 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true));
445 EXPECT_CALL(*new_source.get(), OnStart());
446 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( 466 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2(
447 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 467 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
448 scoped_ptr<WebRtcLocalAudioTrack> track_2( 468 scoped_ptr<WebRtcLocalAudioTrack> track_2(
449 new WebRtcLocalAudioTrack(adapter_2, new_capturer, NULL)); 469 new WebRtcLocalAudioTrack(adapter_2, new_capturer, NULL));
450 track_2->Start(); 470 track_2->Start();
451 471
452 // Connect a number of network channels to the |track_2|. 472 // Connect a number of network channels to the |track_2|.
453 static const int kNumberOfNetworkChannelsForTrack2 = 3; 473 static const int kNumberOfNetworkChannelsForTrack2 = 3;
454 for (int i = 0; i < kNumberOfNetworkChannelsForTrack2; ++i) { 474 for (int i = 0; i < kNumberOfNetworkChannelsForTrack2; ++i) {
455 static_cast<webrtc::AudioTrackInterface*>( 475 static_cast<webrtc::AudioTrackInterface*>(
(...skipping 14 matching lines...) Expand all
470 EXPECT_CALL(*new_source.get(), OnStop()) 490 EXPECT_CALL(*new_source.get(), OnStop())
471 .Times(1).WillOnce(SignalEvent(&event)); 491 .Times(1).WillOnce(SignalEvent(&event));
472 new_capturer->Stop(); 492 new_capturer->Stop();
473 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); 493 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout()));
474 494
475 // Stop the capturer of the first audio track. 495 // Stop the capturer of the first audio track.
476 EXPECT_CALL(*capturer_source_.get(), OnStop()); 496 EXPECT_CALL(*capturer_source_.get(), OnStop());
477 capturer_->Stop(); 497 capturer_->Stop();
478 } 498 }
479 499
480
481 // 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
482 // 10ms when it is not connected with a peer connection. 501 // 10ms when it is not connected with a peer connection.
483 TEST_F(WebRtcLocalAudioTrackTest, TrackWorkWithSmallBufferSize) { 502 TEST_F(WebRtcLocalAudioTrackTest, TrackWorkWithSmallBufferSize) {
484 // 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.
485 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 504 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
486 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 128); 505 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 128);
487 506
488 // 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.
489 MockMediaConstraintFactory factory; 508 MockMediaConstraintFactory factory;
490 factory.DisableDefaultAudioConstraints(); 509 factory.DisableDefaultAudioConstraints();
491 scoped_refptr<WebRtcAudioCapturer> capturer( 510 scoped_refptr<WebRtcAudioCapturer> capturer(
492 WebRtcAudioCapturer::CreateCapturer( 511 WebRtcAudioCapturer::CreateCapturer(
493 -1, 512 -1,
494 StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, 513 StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE,
495 "", "", params.sample_rate(), 514 "", "", params.sample_rate(),
496 params.channel_layout(), 515 params.channel_layout(),
497 params.frames_per_buffer()), 516 params.frames_per_buffer()),
498 factory.CreateWebMediaConstraints(), 517 factory.CreateWebMediaConstraints(),
499 NULL)); 518 NULL, NULL));
500 scoped_refptr<MockCapturerSource> source( 519 scoped_refptr<MockCapturerSource> source(
501 new MockCapturerSource(capturer.get())); 520 new MockCapturerSource(capturer.get()));
502 EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), -1)); 521 EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), -1));
522 EXPECT_CALL(*source.get(), SetAutomaticGainControl(true));
523 EXPECT_CALL(*source.get(), OnStart());
503 capturer->SetCapturerSourceForTesting(source, params); 524 capturer->SetCapturerSourceForTesting(source, params);
504 525
505 // Setup a audio track, connect it to the capturer and start it. 526 // Setup a audio track, connect it to the capturer and start it.
506 EXPECT_CALL(*source.get(), SetAutomaticGainControl(true));
507 EXPECT_CALL(*source.get(), OnStart());
508 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( 527 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
509 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 528 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
510 scoped_ptr<WebRtcLocalAudioTrack> track( 529 scoped_ptr<WebRtcLocalAudioTrack> track(
511 new WebRtcLocalAudioTrack(adapter, capturer, NULL)); 530 new WebRtcLocalAudioTrack(adapter, capturer, NULL));
512 track->Start(); 531 track->Start();
513 532
514 // Verify the data flow by connecting the |sink| to |track|. 533 // Verify the data flow by connecting the |sink| to |track|.
515 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); 534 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink());
516 base::WaitableEvent event(false, false); 535 base::WaitableEvent event(false, false);
517 EXPECT_CALL(*sink, FormatIsSet()).Times(1); 536 EXPECT_CALL(*sink, FormatIsSet()).Times(1);
518 // Verify the sinks are getting the packets with an expecting buffer size. 537 // Verify the sinks are getting the packets with an expecting buffer size.
519 #if defined(OS_ANDROID) 538 #if defined(OS_ANDROID)
520 const int expected_buffer_size = params.sample_rate() / 100; 539 const int expected_buffer_size = params.sample_rate() / 100;
521 #else 540 #else
522 const int expected_buffer_size = params.frames_per_buffer(); 541 const int expected_buffer_size = params.frames_per_buffer();
523 #endif 542 #endif
524 EXPECT_CALL(*sink, CaptureData( 543 EXPECT_CALL(*sink, CaptureData(
525 0, 0, 0, _, false)) 544 0, 0, 0, _, false))
526 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); 545 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event));
527 track->AddSink(sink.get()); 546 track->AddSink(sink.get());
528 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); 547 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout()));
529 EXPECT_EQ(expected_buffer_size, sink->audio_params().frames_per_buffer()); 548 EXPECT_EQ(expected_buffer_size, sink->audio_params().frames_per_buffer());
530 549
531 // Stopping the new source will stop the second track. 550 // Stopping the new source will stop the second track.
532 EXPECT_CALL(*source, OnStop()).Times(1); 551 EXPECT_CALL(*source, OnStop()).Times(1);
533 capturer->Stop(); 552 capturer->Stop();
553
554 // Even though this test don't use |capturer_source_| it will be stopped
555 // during teardown of the test harness.
556 EXPECT_CALL(*capturer_source_.get(), OnStop());
534 } 557 }
535 558
536 } // namespace content 559 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_local_audio_track.h ('k') | content/test/data/media/getusermedia.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698