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

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: Self review. 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/mock_media_constraint_factory.h" 7 #include "content/renderer/media/mock_media_constraint_factory.h"
8 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" 8 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h"
9 #include "content/renderer/media/webrtc_audio_capturer.h" 9 #include "content/renderer/media/webrtc_audio_capturer.h"
10 #include "content/renderer/media/webrtc_audio_device_impl.h" 10 #include "content/renderer/media/webrtc_audio_device_impl.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 167
168 class WebRtcLocalAudioTrackTest : public ::testing::Test { 168 class WebRtcLocalAudioTrackTest : public ::testing::Test {
169 protected: 169 protected:
170 virtual void SetUp() OVERRIDE { 170 virtual void SetUp() OVERRIDE {
171 params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 171 params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
172 media::CHANNEL_LAYOUT_STEREO, 2, 0, 48000, 16, 480); 172 media::CHANNEL_LAYOUT_STEREO, 2, 0, 48000, 16, 480);
173 blink::WebMediaConstraints constraints; 173 blink::WebMediaConstraints constraints;
174 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE, 174 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE,
175 std::string(), std::string()); 175 std::string(), std::string());
176 capturer_ = WebRtcAudioCapturer::CreateCapturer(-1, device, 176 capturer_ = WebRtcAudioCapturer::CreateCapturer(-1, device,
177 constraints, NULL); 177 constraints, NULL, NULL);
178 capturer_source_ = new MockCapturerSource(capturer_.get()); 178 capturer_source_ = new MockCapturerSource(capturer_.get());
179 EXPECT_CALL(*capturer_source_.get(), OnInitialize(_, capturer_.get(), -1)) 179 EXPECT_CALL(*capturer_source_.get(), OnInitialize(_, capturer_.get(), -1))
180 .WillOnce(Return()); 180 .WillOnce(Return());
181 capturer_->SetCapturerSourceForTesting(capturer_source_, params_); 181 capturer_->SetCapturerSourceForTesting(capturer_source_, params_);
182 } 182 }
183 183
184 media::AudioParameters params_; 184 media::AudioParameters params_;
185 scoped_refptr<MockCapturerSource> capturer_source_; 185 scoped_refptr<MockCapturerSource> capturer_source_;
186 scoped_refptr<WebRtcAudioCapturer> capturer_; 186 scoped_refptr<WebRtcAudioCapturer> capturer_;
187 }; 187 };
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 params.sample_rate() / 100); 321 params.sample_rate() / 100);
322 EXPECT_CALL(*sink_2, CaptureData(1, 0, 0, _, false)).Times(AtLeast(1)) 322 EXPECT_CALL(*sink_2, CaptureData(1, 0, 0, _, false)).Times(AtLeast(1))
323 .WillRepeatedly(SignalEvent(&event_2)); 323 .WillRepeatedly(SignalEvent(&event_2));
324 EXPECT_EQ(sink_2->audio_params().frames_per_buffer(), 324 EXPECT_EQ(sink_2->audio_params().frames_per_buffer(),
325 params.sample_rate() / 100); 325 params.sample_rate() / 100);
326 track_2->AddSink(sink_2.get()); 326 track_2->AddSink(sink_2.get());
327 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); 327 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout()));
328 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); 328 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout()));
329 329
330 track_1->RemoveSink(sink_1.get()); 330 track_1->RemoveSink(sink_1.get());
331 track_1->Stop(); 331 track_1->StopTrack();
332 track_1.reset(); 332 track_1.reset();
333 333
334 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); 334 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return());
335 track_2->RemoveSink(sink_2.get()); 335 track_2->RemoveSink(sink_2.get());
336 track_2->Stop(); 336 track_2->StopTrack();
337 track_2.reset(); 337 track_2.reset();
338 338
339 capturer_->Stop(); 339 capturer_->Stop();
no longer working on chromium 2014/04/01 18:29:58 I think you should skip this capturer_->Stop(); bu
perkj_chrome 2014/04/02 13:35:49 Do you have any plans to fix http://crbug.com/2954
340 } 340 }
341 341
342 342
343 // Start one track and verify the capturer is correctly starting its source. 343 // Start one track and verify the capturer is correctly starting its source.
344 // And it should be fine to not to call Stop() explicitly. 344 // And it should be fine to not to call Stop() explicitly.
345 TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) { 345 TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) {
346 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); 346 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
347 EXPECT_CALL(*capturer_source_.get(), OnStart()); 347 EXPECT_CALL(*capturer_source_.get(), OnStart());
348 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( 348 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
349 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 349 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 0, 0, _, false)) 441 0, 0, _, false))
442 .Times(AnyNumber()).WillRepeatedly(Return()); 442 .Times(AnyNumber()).WillRepeatedly(Return());
443 EXPECT_CALL(*sink_1.get(), FormatIsSet()).Times(AnyNumber()); 443 EXPECT_CALL(*sink_1.get(), FormatIsSet()).Times(AnyNumber());
444 track_1->AddSink(sink_1.get()); 444 track_1->AddSink(sink_1.get());
445 445
446 // Create a new capturer with new source with different audio format. 446 // Create a new capturer with new source with different audio format.
447 blink::WebMediaConstraints constraints; 447 blink::WebMediaConstraints constraints;
448 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE, 448 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE,
449 std::string(), std::string()); 449 std::string(), std::string());
450 scoped_refptr<WebRtcAudioCapturer> new_capturer( 450 scoped_refptr<WebRtcAudioCapturer> new_capturer(
451 WebRtcAudioCapturer::CreateCapturer(-1, device, constraints, NULL)); 451 WebRtcAudioCapturer::CreateCapturer(-1, device, constraints, NULL, NULL));
452 scoped_refptr<MockCapturerSource> new_source( 452 scoped_refptr<MockCapturerSource> new_source(
453 new MockCapturerSource(new_capturer.get())); 453 new MockCapturerSource(new_capturer.get()));
454 EXPECT_CALL(*new_source.get(), OnInitialize(_, new_capturer.get(), -1)); 454 EXPECT_CALL(*new_source.get(), OnInitialize(_, new_capturer.get(), -1));
455 media::AudioParameters new_param( 455 media::AudioParameters new_param(
456 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 456 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
457 media::CHANNEL_LAYOUT_MONO, 44100, 16, 441); 457 media::CHANNEL_LAYOUT_MONO, 44100, 16, 441);
458 new_capturer->SetCapturerSourceForTesting(new_source, new_param); 458 new_capturer->SetCapturerSourceForTesting(new_source, new_param);
459 459
460 // Setup the second audio track, connect it to the new capturer and start it. 460 // Setup the second audio track, connect it to the new capturer and start it.
461 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true)); 461 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 MockMediaConstraintFactory factory; 508 MockMediaConstraintFactory factory;
509 factory.DisableDefaultAudioConstraints(); 509 factory.DisableDefaultAudioConstraints();
510 scoped_refptr<WebRtcAudioCapturer> capturer( 510 scoped_refptr<WebRtcAudioCapturer> capturer(
511 WebRtcAudioCapturer::CreateCapturer( 511 WebRtcAudioCapturer::CreateCapturer(
512 -1, 512 -1,
513 StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, 513 StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE,
514 "", "", params.sample_rate(), 514 "", "", params.sample_rate(),
515 params.channel_layout(), 515 params.channel_layout(),
516 params.frames_per_buffer()), 516 params.frames_per_buffer()),
517 factory.CreateWebMediaConstraints(), 517 factory.CreateWebMediaConstraints(),
518 NULL)); 518 NULL, NULL));
519 scoped_refptr<MockCapturerSource> source( 519 scoped_refptr<MockCapturerSource> source(
520 new MockCapturerSource(capturer.get())); 520 new MockCapturerSource(capturer.get()));
521 EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), -1)); 521 EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), -1));
522 capturer->SetCapturerSourceForTesting(source, params); 522 capturer->SetCapturerSourceForTesting(source, params);
523 523
524 // 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.
525 EXPECT_CALL(*source.get(), SetAutomaticGainControl(true)); 525 EXPECT_CALL(*source.get(), SetAutomaticGainControl(true));
526 EXPECT_CALL(*source.get(), OnStart()); 526 EXPECT_CALL(*source.get(), OnStart());
527 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( 527 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
528 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 528 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
(...skipping 19 matching lines...) Expand all
548 track->AddSink(sink.get()); 548 track->AddSink(sink.get());
549 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()); 550 EXPECT_EQ(expected_buffer_size, sink->audio_params().frames_per_buffer());
551 551
552 // Stopping the new source will stop the second track. 552 // Stopping the new source will stop the second track.
553 EXPECT_CALL(*source, OnStop()).Times(1); 553 EXPECT_CALL(*source, OnStop()).Times(1);
554 capturer->Stop(); 554 capturer->Stop();
555 } 555 }
556 556
557 } // namespace content 557 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698