| 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/media_stream_audio_source.h" | 7 #include "content/renderer/media/media_stream_audio_source.h" |
| 8 #include "content/renderer/media/mock_media_constraint_factory.h" | 8 #include "content/renderer/media/mock_media_constraint_factory.h" |
| 9 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | 9 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" |
| 10 #include "content/renderer/media/webrtc_audio_capturer.h" | 10 #include "content/renderer/media/webrtc_audio_capturer.h" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 blink_source_.initialize("dummy", blink::WebMediaStreamSource::TypeAudio, | 174 blink_source_.initialize("dummy", blink::WebMediaStreamSource::TypeAudio, |
| 175 "dummy"); | 175 "dummy"); |
| 176 MediaStreamAudioSource* audio_source = new MediaStreamAudioSource(); | 176 MediaStreamAudioSource* audio_source = new MediaStreamAudioSource(); |
| 177 blink_source_.setExtraData(audio_source); | 177 blink_source_.setExtraData(audio_source); |
| 178 | 178 |
| 179 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE, | 179 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE, |
| 180 std::string(), std::string()); | 180 std::string(), std::string()); |
| 181 capturer_ = WebRtcAudioCapturer::CreateCapturer( | 181 capturer_ = WebRtcAudioCapturer::CreateCapturer( |
| 182 -1, device, constraint_factory.CreateWebMediaConstraints(), NULL, | 182 -1, device, constraint_factory.CreateWebMediaConstraints(), NULL, |
| 183 audio_source); | 183 audio_source); |
| 184 audio_source->SetAudioCapturer(capturer_); | 184 audio_source->SetAudioCapturer(capturer_.get()); |
| 185 capturer_source_ = new MockCapturerSource(capturer_.get()); | 185 capturer_source_ = new MockCapturerSource(capturer_.get()); |
| 186 EXPECT_CALL(*capturer_source_.get(), OnInitialize(_, capturer_.get(), -1)) | 186 EXPECT_CALL(*capturer_source_.get(), OnInitialize(_, capturer_.get(), -1)) |
| 187 .WillOnce(Return()); | 187 .WillOnce(Return()); |
| 188 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); | 188 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); |
| 189 EXPECT_CALL(*capturer_source_.get(), OnStart()); | 189 EXPECT_CALL(*capturer_source_.get(), OnStart()); |
| 190 capturer_->SetCapturerSourceForTesting(capturer_source_, params_); | 190 capturer_->SetCapturerSourceForTesting(capturer_source_, params_); |
| 191 } | 191 } |
| 192 | 192 |
| 193 media::AudioParameters params_; | 193 media::AudioParameters params_; |
| 194 blink::WebMediaStreamSource blink_source_; | 194 blink::WebMediaStreamSource blink_source_; |
| 195 scoped_refptr<MockCapturerSource> capturer_source_; | 195 scoped_refptr<MockCapturerSource> capturer_source_; |
| 196 scoped_refptr<WebRtcAudioCapturer> capturer_; | 196 scoped_refptr<WebRtcAudioCapturer> capturer_; |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 // Creates a capturer and audio track, fakes its audio thread, and | 199 // Creates a capturer and audio track, fakes its audio thread, and |
| 200 // 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 |
| 201 // 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 |
| 202 // the track is disconnected from the capturer. | 202 // the track is disconnected from the capturer. |
| 203 TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) { | 203 TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) { |
| 204 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 204 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
| 205 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 205 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 206 scoped_ptr<WebRtcLocalAudioTrack> track( | 206 scoped_ptr<WebRtcLocalAudioTrack> track( |
| 207 new WebRtcLocalAudioTrack(adapter, capturer_, NULL)); | 207 new WebRtcLocalAudioTrack(adapter.get(), capturer_, NULL)); |
| 208 track->Start(); | 208 track->Start(); |
| 209 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); | 209 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); |
| 210 | 210 |
| 211 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 211 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
| 212 base::WaitableEvent event(false, false); | 212 base::WaitableEvent event(false, false); |
| 213 EXPECT_CALL(*sink, FormatIsSet()); | 213 EXPECT_CALL(*sink, FormatIsSet()); |
| 214 EXPECT_CALL(*sink, | 214 EXPECT_CALL(*sink, |
| 215 CaptureData(0, | 215 CaptureData(0, |
| 216 0, | 216 0, |
| 217 0, | 217 0, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 231 // 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 |
| 232 // callback. | 232 // callback. |
| 233 // TODO(xians): Enable this test after resolving the racing issue that TSAN | 233 // TODO(xians): Enable this test after resolving the racing issue that TSAN |
| 234 // reports on MediaStreamTrack::enabled(); | 234 // reports on MediaStreamTrack::enabled(); |
| 235 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) { | 235 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) { |
| 236 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); | 236 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); |
| 237 EXPECT_CALL(*capturer_source_.get(), OnStart()); | 237 EXPECT_CALL(*capturer_source_.get(), OnStart()); |
| 238 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 238 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
| 239 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 239 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 240 scoped_ptr<WebRtcLocalAudioTrack> track( | 240 scoped_ptr<WebRtcLocalAudioTrack> track( |
| 241 new WebRtcLocalAudioTrack(adapter, capturer_, NULL)); | 241 new WebRtcLocalAudioTrack(adapter.get(), capturer_, NULL)); |
| 242 track->Start(); | 242 track->Start(); |
| 243 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); | 243 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); |
| 244 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(false)); | 244 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(false)); |
| 245 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 245 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
| 246 const media::AudioParameters params = capturer_->source_audio_parameters(); | 246 const media::AudioParameters params = capturer_->source_audio_parameters(); |
| 247 base::WaitableEvent event(false, false); | 247 base::WaitableEvent event(false, false); |
| 248 EXPECT_CALL(*sink, FormatIsSet()).Times(1); | 248 EXPECT_CALL(*sink, FormatIsSet()).Times(1); |
| 249 EXPECT_CALL(*sink, | 249 EXPECT_CALL(*sink, |
| 250 CaptureData(0, 0, 0, _, false)).Times(0); | 250 CaptureData(0, 0, 0, _, false)).Times(0); |
| 251 EXPECT_EQ(sink->audio_params().frames_per_buffer(), | 251 EXPECT_EQ(sink->audio_params().frames_per_buffer(), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 265 track.reset(); | 265 track.reset(); |
| 266 } | 266 } |
| 267 | 267 |
| 268 // 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 |
| 269 // callbacks appear/disappear. | 269 // callbacks appear/disappear. |
| 270 // Flaky due to a data race, see http://crbug.com/295418 | 270 // Flaky due to a data race, see http://crbug.com/295418 |
| 271 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) { | 271 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) { |
| 272 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( | 272 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( |
| 273 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 273 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 274 scoped_ptr<WebRtcLocalAudioTrack> track_1( | 274 scoped_ptr<WebRtcLocalAudioTrack> track_1( |
| 275 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); | 275 new WebRtcLocalAudioTrack(adapter_1.get(), capturer_, NULL)); |
| 276 track_1->Start(); | 276 track_1->Start(); |
| 277 EXPECT_TRUE(track_1->GetAudioAdapter()->enabled()); | 277 EXPECT_TRUE(track_1->GetAudioAdapter()->enabled()); |
| 278 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); | 278 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); |
| 279 const media::AudioParameters params = capturer_->source_audio_parameters(); | 279 const media::AudioParameters params = capturer_->source_audio_parameters(); |
| 280 base::WaitableEvent event_1(false, false); | 280 base::WaitableEvent event_1(false, false); |
| 281 EXPECT_CALL(*sink_1, FormatIsSet()).WillOnce(Return()); | 281 EXPECT_CALL(*sink_1, FormatIsSet()).WillOnce(Return()); |
| 282 EXPECT_CALL(*sink_1, | 282 EXPECT_CALL(*sink_1, |
| 283 CaptureData(0, 0, 0, _, false)).Times(AtLeast(1)) | 283 CaptureData(0, 0, 0, _, false)).Times(AtLeast(1)) |
| 284 .WillRepeatedly(SignalEvent(&event_1)); | 284 .WillRepeatedly(SignalEvent(&event_1)); |
| 285 EXPECT_EQ(sink_1->audio_params().frames_per_buffer(), | 285 EXPECT_EQ(sink_1->audio_params().frames_per_buffer(), |
| 286 params.sample_rate() / 100); | 286 params.sample_rate() / 100); |
| 287 track_1->AddSink(sink_1.get()); | 287 track_1->AddSink(sink_1.get()); |
| 288 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 288 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
| 289 | 289 |
| 290 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( | 290 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( |
| 291 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 291 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 292 scoped_ptr<WebRtcLocalAudioTrack> track_2( | 292 scoped_ptr<WebRtcLocalAudioTrack> track_2( |
| 293 new WebRtcLocalAudioTrack(adapter_2, capturer_, NULL)); | 293 new WebRtcLocalAudioTrack(adapter_2.get(), capturer_, NULL)); |
| 294 track_2->Start(); | 294 track_2->Start(); |
| 295 EXPECT_TRUE(track_2->GetAudioAdapter()->enabled()); | 295 EXPECT_TRUE(track_2->GetAudioAdapter()->enabled()); |
| 296 | 296 |
| 297 // Verify both |sink_1| and |sink_2| get data. | 297 // Verify both |sink_1| and |sink_2| get data. |
| 298 event_1.Reset(); | 298 event_1.Reset(); |
| 299 base::WaitableEvent event_2(false, false); | 299 base::WaitableEvent event_2(false, false); |
| 300 | 300 |
| 301 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); | 301 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); |
| 302 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(Return()); | 302 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(Return()); |
| 303 EXPECT_CALL(*sink_1, CaptureData(0, 0, 0, _, false)).Times(AtLeast(1)) | 303 EXPECT_CALL(*sink_1, CaptureData(0, 0, 0, _, false)).Times(AtLeast(1)) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 322 track_2.reset(); | 322 track_2.reset(); |
| 323 } | 323 } |
| 324 | 324 |
| 325 | 325 |
| 326 // Start one track and verify the capturer is correctly starting its source. | 326 // Start one track and verify the capturer is correctly starting its source. |
| 327 // And it should be fine to not to call Stop() explicitly. | 327 // And it should be fine to not to call Stop() explicitly. |
| 328 TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) { | 328 TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) { |
| 329 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 329 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
| 330 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 330 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 331 scoped_ptr<WebRtcLocalAudioTrack> track( | 331 scoped_ptr<WebRtcLocalAudioTrack> track( |
| 332 new WebRtcLocalAudioTrack(adapter, capturer_, NULL)); | 332 new WebRtcLocalAudioTrack(adapter.get(), capturer_, NULL)); |
| 333 track->Start(); | 333 track->Start(); |
| 334 | 334 |
| 335 // When the track goes away, it will automatically stop the | 335 // When the track goes away, it will automatically stop the |
| 336 // |capturer_source_|. | 336 // |capturer_source_|. |
| 337 EXPECT_CALL(*capturer_source_.get(), OnStop()); | 337 EXPECT_CALL(*capturer_source_.get(), OnStop()); |
| 338 track.reset(); | 338 track.reset(); |
| 339 } | 339 } |
| 340 | 340 |
| 341 // Start two tracks and verify the capturer is correctly starting its source. | 341 // Start two tracks and verify the capturer is correctly starting its source. |
| 342 // When the last track connected to the capturer is stopped, the source is | 342 // When the last track connected to the capturer is stopped, the source is |
| 343 // stopped. | 343 // stopped. |
| 344 TEST_F(WebRtcLocalAudioTrackTest, StartTwoAudioTracks) { | 344 TEST_F(WebRtcLocalAudioTrackTest, StartTwoAudioTracks) { |
| 345 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter1( | 345 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter1( |
| 346 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 346 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 347 scoped_ptr<WebRtcLocalAudioTrack> track1( | 347 scoped_ptr<WebRtcLocalAudioTrack> track1( |
| 348 new WebRtcLocalAudioTrack(adapter1, capturer_, NULL)); | 348 new WebRtcLocalAudioTrack(adapter1.get(), capturer_, NULL)); |
| 349 track1->Start(); | 349 track1->Start(); |
| 350 | 350 |
| 351 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter2( | 351 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter2( |
| 352 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 352 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 353 scoped_ptr<WebRtcLocalAudioTrack> track2( | 353 scoped_ptr<WebRtcLocalAudioTrack> track2( |
| 354 new WebRtcLocalAudioTrack(adapter2, capturer_, NULL)); | 354 new WebRtcLocalAudioTrack(adapter2.get(), capturer_, NULL)); |
| 355 track2->Start(); | 355 track2->Start(); |
| 356 | 356 |
| 357 track1->Stop(); | 357 track1->Stop(); |
| 358 // When the last track is stopped, it will automatically stop the | 358 // When the last track is stopped, it will automatically stop the |
| 359 // |capturer_source_|. | 359 // |capturer_source_|. |
| 360 EXPECT_CALL(*capturer_source_.get(), OnStop()); | 360 EXPECT_CALL(*capturer_source_.get(), OnStop()); |
| 361 track2->Stop(); | 361 track2->Stop(); |
| 362 } | 362 } |
| 363 | 363 |
| 364 // Start/Stop tracks and verify the capturer is correctly starting/stopping | 364 // Start/Stop tracks and verify the capturer is correctly starting/stopping |
| 365 // its source. | 365 // its source. |
| 366 TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { | 366 TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { |
| 367 base::WaitableEvent event(false, false); | 367 base::WaitableEvent event(false, false); |
| 368 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( | 368 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( |
| 369 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 369 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 370 scoped_ptr<WebRtcLocalAudioTrack> track_1( | 370 scoped_ptr<WebRtcLocalAudioTrack> track_1( |
| 371 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); | 371 new WebRtcLocalAudioTrack(adapter_1.get(), capturer_, NULL)); |
| 372 track_1->Start(); | 372 track_1->Start(); |
| 373 | 373 |
| 374 // Verify the data flow by connecting the sink to |track_1|. | 374 // Verify the data flow by connecting the sink to |track_1|. |
| 375 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 375 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
| 376 event.Reset(); | 376 event.Reset(); |
| 377 EXPECT_CALL(*sink, FormatIsSet()).WillOnce(SignalEvent(&event)); | 377 EXPECT_CALL(*sink, FormatIsSet()).WillOnce(SignalEvent(&event)); |
| 378 EXPECT_CALL(*sink, CaptureData(_, 0, 0, _, false)) | 378 EXPECT_CALL(*sink, CaptureData(_, 0, 0, _, false)) |
| 379 .Times(AnyNumber()).WillRepeatedly(Return()); | 379 .Times(AnyNumber()).WillRepeatedly(Return()); |
| 380 track_1->AddSink(sink.get()); | 380 track_1->AddSink(sink.get()); |
| 381 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 381 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
| 382 | 382 |
| 383 // Start the second audio track will not start the |capturer_source_| | 383 // Start the second audio track will not start the |capturer_source_| |
| 384 // since it has been started. | 384 // since it has been started. |
| 385 EXPECT_CALL(*capturer_source_.get(), OnStart()).Times(0); | 385 EXPECT_CALL(*capturer_source_.get(), OnStart()).Times(0); |
| 386 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( | 386 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( |
| 387 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 387 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 388 scoped_ptr<WebRtcLocalAudioTrack> track_2( | 388 scoped_ptr<WebRtcLocalAudioTrack> track_2( |
| 389 new WebRtcLocalAudioTrack(adapter_2, capturer_, NULL)); | 389 new WebRtcLocalAudioTrack(adapter_2.get(), capturer_, NULL)); |
| 390 track_2->Start(); | 390 track_2->Start(); |
| 391 | 391 |
| 392 // Stop the capturer will clear up the track lists in the capturer. | 392 // Stop the capturer will clear up the track lists in the capturer. |
| 393 EXPECT_CALL(*capturer_source_.get(), OnStop()); | 393 EXPECT_CALL(*capturer_source_.get(), OnStop()); |
| 394 capturer_->Stop(); | 394 capturer_->Stop(); |
| 395 | 395 |
| 396 // Adding a new track to the capturer. | 396 // Adding a new track to the capturer. |
| 397 track_2->AddSink(sink.get()); | 397 track_2->AddSink(sink.get()); |
| 398 EXPECT_CALL(*sink, FormatIsSet()).Times(0); | 398 EXPECT_CALL(*sink, FormatIsSet()).Times(0); |
| 399 | 399 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 411 #define DISABLE_ON_TSAN(function) function | 411 #define DISABLE_ON_TSAN(function) function |
| 412 #endif | 412 #endif |
| 413 | 413 |
| 414 // Create a new capturer with new source, connect it to a new audio track. | 414 // Create a new capturer with new source, connect it to a new audio track. |
| 415 TEST_F(WebRtcLocalAudioTrackTest, | 415 TEST_F(WebRtcLocalAudioTrackTest, |
| 416 DISABLE_ON_TSAN(ConnectTracksToDifferentCapturers)) { | 416 DISABLE_ON_TSAN(ConnectTracksToDifferentCapturers)) { |
| 417 // Setup the first audio track and start it. | 417 // Setup the first audio track and start it. |
| 418 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( | 418 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( |
| 419 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 419 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 420 scoped_ptr<WebRtcLocalAudioTrack> track_1( | 420 scoped_ptr<WebRtcLocalAudioTrack> track_1( |
| 421 new WebRtcLocalAudioTrack(adapter_1, capturer_, NULL)); | 421 new WebRtcLocalAudioTrack(adapter_1.get(), capturer_, NULL)); |
| 422 track_1->Start(); | 422 track_1->Start(); |
| 423 | 423 |
| 424 // Verify the data flow by connecting the |sink_1| to |track_1|. | 424 // Verify the data flow by connecting the |sink_1| to |track_1|. |
| 425 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); | 425 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); |
| 426 EXPECT_CALL(*sink_1.get(), CaptureData(0, 0, 0, _, false)) | 426 EXPECT_CALL(*sink_1.get(), CaptureData(0, 0, 0, _, false)) |
| 427 .Times(AnyNumber()).WillRepeatedly(Return()); | 427 .Times(AnyNumber()).WillRepeatedly(Return()); |
| 428 EXPECT_CALL(*sink_1.get(), FormatIsSet()).Times(AnyNumber()); | 428 EXPECT_CALL(*sink_1.get(), FormatIsSet()).Times(AnyNumber()); |
| 429 track_1->AddSink(sink_1.get()); | 429 track_1->AddSink(sink_1.get()); |
| 430 | 430 |
| 431 // Create a new capturer with new source with different audio format. | 431 // Create a new capturer with new source with different audio format. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 444 | 444 |
| 445 media::AudioParameters new_param( | 445 media::AudioParameters new_param( |
| 446 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 446 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 447 media::CHANNEL_LAYOUT_MONO, 44100, 16, 441); | 447 media::CHANNEL_LAYOUT_MONO, 44100, 16, 441); |
| 448 new_capturer->SetCapturerSourceForTesting(new_source, new_param); | 448 new_capturer->SetCapturerSourceForTesting(new_source, new_param); |
| 449 | 449 |
| 450 // Setup the second audio track, connect it to the new capturer and start it. | 450 // Setup the second audio track, connect it to the new capturer and start it. |
| 451 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( | 451 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( |
| 452 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 452 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 453 scoped_ptr<WebRtcLocalAudioTrack> track_2( | 453 scoped_ptr<WebRtcLocalAudioTrack> track_2( |
| 454 new WebRtcLocalAudioTrack(adapter_2, new_capturer, NULL)); | 454 new WebRtcLocalAudioTrack(adapter_2.get(), new_capturer, NULL)); |
| 455 track_2->Start(); | 455 track_2->Start(); |
| 456 | 456 |
| 457 // Verify the data flow by connecting the |sink_2| to |track_2|. | 457 // Verify the data flow by connecting the |sink_2| to |track_2|. |
| 458 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); | 458 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); |
| 459 base::WaitableEvent event(false, false); | 459 base::WaitableEvent event(false, false); |
| 460 EXPECT_CALL(*sink_2, CaptureData(0, 0, 0, _, false)) | 460 EXPECT_CALL(*sink_2, CaptureData(0, 0, 0, _, false)) |
| 461 .Times(AnyNumber()).WillRepeatedly(Return()); | 461 .Times(AnyNumber()).WillRepeatedly(Return()); |
| 462 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(SignalEvent(&event)); | 462 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(SignalEvent(&event)); |
| 463 track_2->AddSink(sink_2.get()); | 463 track_2->AddSink(sink_2.get()); |
| 464 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 464 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 new MockCapturerSource(capturer.get())); | 498 new MockCapturerSource(capturer.get())); |
| 499 EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), -1)); | 499 EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), -1)); |
| 500 EXPECT_CALL(*source.get(), SetAutomaticGainControl(true)); | 500 EXPECT_CALL(*source.get(), SetAutomaticGainControl(true)); |
| 501 EXPECT_CALL(*source.get(), OnStart()); | 501 EXPECT_CALL(*source.get(), OnStart()); |
| 502 capturer->SetCapturerSourceForTesting(source, params); | 502 capturer->SetCapturerSourceForTesting(source, params); |
| 503 | 503 |
| 504 // Setup a audio track, connect it to the capturer and start it. | 504 // Setup a audio track, connect it to the capturer and start it. |
| 505 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 505 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
| 506 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 506 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 507 scoped_ptr<WebRtcLocalAudioTrack> track( | 507 scoped_ptr<WebRtcLocalAudioTrack> track( |
| 508 new WebRtcLocalAudioTrack(adapter, capturer, NULL)); | 508 new WebRtcLocalAudioTrack(adapter.get(), capturer, NULL)); |
| 509 track->Start(); | 509 track->Start(); |
| 510 | 510 |
| 511 // Verify the data flow by connecting the |sink| to |track|. | 511 // Verify the data flow by connecting the |sink| to |track|. |
| 512 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 512 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
| 513 base::WaitableEvent event(false, false); | 513 base::WaitableEvent event(false, false); |
| 514 EXPECT_CALL(*sink, FormatIsSet()).Times(1); | 514 EXPECT_CALL(*sink, FormatIsSet()).Times(1); |
| 515 // Verify the sinks are getting the packets with an expecting buffer size. | 515 // Verify the sinks are getting the packets with an expecting buffer size. |
| 516 #if defined(OS_ANDROID) | 516 #if defined(OS_ANDROID) |
| 517 const int expected_buffer_size = params.sample_rate() / 100; | 517 const int expected_buffer_size = params.sample_rate() / 100; |
| 518 #else | 518 #else |
| 519 const int expected_buffer_size = params.frames_per_buffer(); | 519 const int expected_buffer_size = params.frames_per_buffer(); |
| 520 #endif | 520 #endif |
| 521 EXPECT_CALL(*sink, CaptureData( | 521 EXPECT_CALL(*sink, CaptureData( |
| 522 0, 0, 0, _, false)) | 522 0, 0, 0, _, false)) |
| 523 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); | 523 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); |
| 524 track->AddSink(sink.get()); | 524 track->AddSink(sink.get()); |
| 525 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 525 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
| 526 EXPECT_EQ(expected_buffer_size, sink->audio_params().frames_per_buffer()); | 526 EXPECT_EQ(expected_buffer_size, sink->audio_params().frames_per_buffer()); |
| 527 | 527 |
| 528 // Stopping the new source will stop the second track. | 528 // Stopping the new source will stop the second track. |
| 529 EXPECT_CALL(*source, OnStop()).Times(1); | 529 EXPECT_CALL(*source.get(), OnStop()).Times(1); |
| 530 capturer->Stop(); | 530 capturer->Stop(); |
| 531 | 531 |
| 532 // Even though this test don't use |capturer_source_| it will be stopped | 532 // Even though this test don't use |capturer_source_| it will be stopped |
| 533 // during teardown of the test harness. | 533 // during teardown of the test harness. |
| 534 EXPECT_CALL(*capturer_source_.get(), OnStop()); | 534 EXPECT_CALL(*capturer_source_.get(), OnStop()); |
| 535 } | 535 } |
| 536 | 536 |
| 537 } // namespace content | 537 } // namespace content |
| OLD | NEW |