| 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/rtc_media_constraints.h" |
| 7 #include "content/renderer/media/webrtc_audio_capturer.h" | 8 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 8 #include "content/renderer/media/webrtc_local_audio_track.h" | 9 #include "content/renderer/media/webrtc_local_audio_track.h" |
| 9 #include "media/audio/audio_parameters.h" | 10 #include "media/audio/audio_parameters.h" |
| 10 #include "media/base/audio_bus.h" | 11 #include "media/base/audio_bus.h" |
| 11 #include "media/base/audio_capturer_source.h" | 12 #include "media/base/audio_capturer_source.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" | 15 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" |
| 15 | 16 |
| 16 using ::testing::_; | 17 using ::testing::_; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 scoped_refptr<WebRtcAudioCapturer> capturer_; | 158 scoped_refptr<WebRtcAudioCapturer> capturer_; |
| 158 scoped_ptr<FakeAudioThread> audio_thread_; | 159 scoped_ptr<FakeAudioThread> audio_thread_; |
| 159 }; | 160 }; |
| 160 | 161 |
| 161 // Creates a capturer and audio track, fakes its audio thread, and | 162 // Creates a capturer and audio track, fakes its audio thread, and |
| 162 // connect/disconnect the sink to the audio track on the fly, the sink should | 163 // connect/disconnect the sink to the audio track on the fly, the sink should |
| 163 // get data callback when the track is connected to the capturer but not when | 164 // get data callback when the track is connected to the capturer but not when |
| 164 // the track is disconnected from the capturer. | 165 // the track is disconnected from the capturer. |
| 165 TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) { | 166 TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) { |
| 166 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); | 167 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); |
| 168 RTCMediaConstraints constraints; |
| 167 scoped_refptr<WebRtcLocalAudioTrack> track = | 169 scoped_refptr<WebRtcLocalAudioTrack> track = |
| 168 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); | 170 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, |
| 171 &constraints); |
| 169 track->Start(); | 172 track->Start(); |
| 170 EXPECT_TRUE(track->enabled()); | 173 EXPECT_TRUE(track->enabled()); |
| 171 | 174 |
| 172 // Connect a number of network channels to the audio track. | 175 // Connect a number of network channels to the audio track. |
| 173 static const int kNumberOfNetworkChannels = 4; | 176 static const int kNumberOfNetworkChannels = 4; |
| 174 for (int i = 0; i < kNumberOfNetworkChannels; ++i) { | 177 for (int i = 0; i < kNumberOfNetworkChannels; ++i) { |
| 175 static_cast<webrtc::AudioTrackInterface*>(track.get())-> | 178 static_cast<webrtc::AudioTrackInterface*>(track.get())-> |
| 176 GetRenderer()->AddChannel(i); | 179 GetRenderer()->AddChannel(i); |
| 177 } | 180 } |
| 178 scoped_ptr<MockWebRtcAudioCapturerSink> sink( | 181 scoped_ptr<MockWebRtcAudioCapturerSink> sink( |
| 179 new MockWebRtcAudioCapturerSink()); | 182 new MockWebRtcAudioCapturerSink()); |
| 180 const media::AudioParameters params = capturer_->audio_parameters(); | 183 const media::AudioParameters params = capturer_->audio_parameters(); |
| 181 base::WaitableEvent event(false, false); | 184 base::WaitableEvent event(false, false); |
| 182 EXPECT_CALL(*sink, SetCaptureFormat(_)).WillOnce(Return()); | 185 EXPECT_CALL(*sink, SetCaptureFormat(_)).WillOnce(Return()); |
| 183 EXPECT_CALL(*sink, | 186 EXPECT_CALL(*sink, |
| 184 CaptureData(kNumberOfNetworkChannels, | 187 CaptureData(kNumberOfNetworkChannels, |
| 185 params.sample_rate(), | 188 params.sample_rate(), |
| 186 params.channels(), | 189 params.channels(), |
| 187 params.frames_per_buffer(), | 190 params.frames_per_buffer(), |
| 188 0, | 191 0, |
| 189 0, | 192 0, |
| 190 // TODO(tommi): Change to |false| when issue 277134 is fixed. | 193 false, |
| 191 _, | |
| 192 false)).Times(AtLeast(1)) | 194 false)).Times(AtLeast(1)) |
| 193 .WillRepeatedly(SignalEvent(&event)); | 195 .WillRepeatedly(SignalEvent(&event)); |
| 194 track->AddSink(sink.get()); | 196 track->AddSink(sink.get()); |
| 195 | 197 |
| 196 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 198 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
| 197 track->RemoveSink(sink.get()); | 199 track->RemoveSink(sink.get()); |
| 198 | 200 |
| 199 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); | 201 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); |
| 200 track->Stop(); | 202 track->Stop(); |
| 201 track = NULL; | 203 track = NULL; |
| 202 } | 204 } |
| 203 | 205 |
| 204 // The same setup as ConnectAndDisconnectOneSink, but enable and disable the | 206 // The same setup as ConnectAndDisconnectOneSink, but enable and disable the |
| 205 // audio track on the fly. When the audio track is disabled, there is no data | 207 // audio track on the fly. When the audio track is disabled, there is no data |
| 206 // callback to the sink; when the audio track is enabled, there comes data | 208 // callback to the sink; when the audio track is enabled, there comes data |
| 207 // callback. | 209 // callback. |
| 208 // TODO(xians): Enable this test after resolving the racing issue that TSAN | 210 // TODO(xians): Enable this test after resolving the racing issue that TSAN |
| 209 // reports on MediaStreamTrack::enabled(); | 211 // reports on MediaStreamTrack::enabled(); |
| 210 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) { | 212 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) { |
| 211 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); | 213 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); |
| 214 RTCMediaConstraints constraints; |
| 212 scoped_refptr<WebRtcLocalAudioTrack> track = | 215 scoped_refptr<WebRtcLocalAudioTrack> track = |
| 213 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); | 216 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, |
| 217 &constraints); |
| 214 track->Start(); | 218 track->Start(); |
| 215 static_cast<webrtc::AudioTrackInterface*>(track.get())-> | 219 static_cast<webrtc::AudioTrackInterface*>(track.get())-> |
| 216 GetRenderer()->AddChannel(0); | 220 GetRenderer()->AddChannel(0); |
| 217 EXPECT_TRUE(track->enabled()); | 221 EXPECT_TRUE(track->enabled()); |
| 218 EXPECT_TRUE(track->set_enabled(false)); | 222 EXPECT_TRUE(track->set_enabled(false)); |
| 219 scoped_ptr<MockWebRtcAudioCapturerSink> sink( | 223 scoped_ptr<MockWebRtcAudioCapturerSink> sink( |
| 220 new MockWebRtcAudioCapturerSink()); | 224 new MockWebRtcAudioCapturerSink()); |
| 221 const media::AudioParameters params = capturer_->audio_parameters(); | 225 const media::AudioParameters params = capturer_->audio_parameters(); |
| 222 base::WaitableEvent event(false, false); | 226 base::WaitableEvent event(false, false); |
| 223 EXPECT_CALL(*sink, SetCaptureFormat(_)).WillOnce(Return()); | 227 EXPECT_CALL(*sink, SetCaptureFormat(_)).WillOnce(Return()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 250 | 254 |
| 251 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); | 255 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); |
| 252 track->Stop(); | 256 track->Stop(); |
| 253 track = NULL; | 257 track = NULL; |
| 254 } | 258 } |
| 255 | 259 |
| 256 // Create multiple audio tracks and enable/disable them, verify that the audio | 260 // Create multiple audio tracks and enable/disable them, verify that the audio |
| 257 // callbacks appear/disappear. | 261 // callbacks appear/disappear. |
| 258 TEST_F(WebRtcLocalAudioTrackTest, MultipleAudioTracks) { | 262 TEST_F(WebRtcLocalAudioTrackTest, MultipleAudioTracks) { |
| 259 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); | 263 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); |
| 264 RTCMediaConstraints constraints; |
| 260 scoped_refptr<WebRtcLocalAudioTrack> track_1 = | 265 scoped_refptr<WebRtcLocalAudioTrack> track_1 = |
| 261 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); | 266 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, |
| 267 &constraints); |
| 262 track_1->Start(); | 268 track_1->Start(); |
| 263 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> | 269 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> |
| 264 GetRenderer()->AddChannel(0); | 270 GetRenderer()->AddChannel(0); |
| 265 EXPECT_TRUE(track_1->enabled()); | 271 EXPECT_TRUE(track_1->enabled()); |
| 266 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( | 272 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( |
| 267 new MockWebRtcAudioCapturerSink()); | 273 new MockWebRtcAudioCapturerSink()); |
| 268 const media::AudioParameters params = capturer_->audio_parameters(); | 274 const media::AudioParameters params = capturer_->audio_parameters(); |
| 269 base::WaitableEvent event_1(false, false); | 275 base::WaitableEvent event_1(false, false); |
| 270 EXPECT_CALL(*sink_1, SetCaptureFormat(_)).WillOnce(Return()); | 276 EXPECT_CALL(*sink_1, SetCaptureFormat(_)).WillOnce(Return()); |
| 271 EXPECT_CALL(*sink_1, | 277 EXPECT_CALL(*sink_1, |
| 272 CaptureData(1, | 278 CaptureData(1, |
| 273 params.sample_rate(), | 279 params.sample_rate(), |
| 274 params.channels(), | 280 params.channels(), |
| 275 params.frames_per_buffer(), | 281 params.frames_per_buffer(), |
| 276 0, | 282 0, |
| 277 0, | 283 0, |
| 278 // TODO(tommi): Change to |false| when issue 277134 is fixed. | 284 false, |
| 279 _, | |
| 280 false)).Times(AtLeast(1)) | 285 false)).Times(AtLeast(1)) |
| 281 .WillRepeatedly(SignalEvent(&event_1)); | 286 .WillRepeatedly(SignalEvent(&event_1)); |
| 282 track_1->AddSink(sink_1.get()); | 287 track_1->AddSink(sink_1.get()); |
| 283 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 288 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
| 284 | 289 |
| 285 scoped_refptr<WebRtcLocalAudioTrack> track_2 = | 290 scoped_refptr<WebRtcLocalAudioTrack> track_2 = |
| 286 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); | 291 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, |
| 292 &constraints); |
| 287 track_2->Start(); | 293 track_2->Start(); |
| 288 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> | 294 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> |
| 289 GetRenderer()->AddChannel(1); | 295 GetRenderer()->AddChannel(1); |
| 290 EXPECT_TRUE(track_2->enabled()); | 296 EXPECT_TRUE(track_2->enabled()); |
| 291 | 297 |
| 292 // Verify both |sink_1| and |sink_2| get data. | 298 // Verify both |sink_1| and |sink_2| get data. |
| 293 event_1.Reset(); | 299 event_1.Reset(); |
| 294 base::WaitableEvent event_2(false, false); | 300 base::WaitableEvent event_2(false, false); |
| 295 | 301 |
| 296 scoped_ptr<MockWebRtcAudioCapturerSink> sink_2( | 302 scoped_ptr<MockWebRtcAudioCapturerSink> sink_2( |
| 297 new MockWebRtcAudioCapturerSink()); | 303 new MockWebRtcAudioCapturerSink()); |
| 298 EXPECT_CALL(*sink_2, SetCaptureFormat(_)).WillOnce(Return()); | 304 EXPECT_CALL(*sink_2, SetCaptureFormat(_)).WillOnce(Return()); |
| 299 EXPECT_CALL(*sink_1, | 305 EXPECT_CALL(*sink_1, |
| 300 CaptureData(1, | 306 CaptureData(1, |
| 301 params.sample_rate(), | 307 params.sample_rate(), |
| 302 params.channels(), | 308 params.channels(), |
| 303 params.frames_per_buffer(), | 309 params.frames_per_buffer(), |
| 304 0, | 310 0, |
| 305 0, | 311 0, |
| 306 // TODO(tommi): Change to |false| when issue 277134 is fixed. | 312 false, |
| 307 _, | |
| 308 false)).Times(AtLeast(1)) | 313 false)).Times(AtLeast(1)) |
| 309 .WillRepeatedly(SignalEvent(&event_1)); | 314 .WillRepeatedly(SignalEvent(&event_1)); |
| 310 EXPECT_CALL(*sink_2, | 315 EXPECT_CALL(*sink_2, |
| 311 CaptureData(1, | 316 CaptureData(1, |
| 312 params.sample_rate(), | 317 params.sample_rate(), |
| 313 params.channels(), | 318 params.channels(), |
| 314 params.frames_per_buffer(), | 319 params.frames_per_buffer(), |
| 315 0, | 320 0, |
| 316 0, | 321 0, |
| 317 // TODO(tommi): Change to |false| when issue 277134 is fixed. | 322 false, |
| 318 _, | |
| 319 false)).Times(AtLeast(1)) | 323 false)).Times(AtLeast(1)) |
| 320 .WillRepeatedly(SignalEvent(&event_2)); | 324 .WillRepeatedly(SignalEvent(&event_2)); |
| 321 track_2->AddSink(sink_2.get()); | 325 track_2->AddSink(sink_2.get()); |
| 322 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 326 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
| 323 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); | 327 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); |
| 324 | 328 |
| 325 track_1->RemoveSink(sink_1.get()); | 329 track_1->RemoveSink(sink_1.get()); |
| 326 track_1->Stop(); | 330 track_1->Stop(); |
| 327 track_1 = NULL; | 331 track_1 = NULL; |
| 328 | 332 |
| 329 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); | 333 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); |
| 330 track_2->RemoveSink(sink_2.get()); | 334 track_2->RemoveSink(sink_2.get()); |
| 331 track_2->Stop(); | 335 track_2->Stop(); |
| 332 track_2 = NULL; | 336 track_2 = NULL; |
| 333 } | 337 } |
| 334 | 338 |
| 335 | 339 |
| 336 // Start one track and verify the capturer is correctly starting its source. | 340 // Start one track and verify the capturer is correctly starting its source. |
| 337 // And it should be fine to not to call Stop() explicitly. | 341 // And it should be fine to not to call Stop() explicitly. |
| 338 TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) { | 342 TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) { |
| 339 EXPECT_CALL(*capturer_source_.get(), Start()).Times(1); | 343 EXPECT_CALL(*capturer_source_.get(), Start()).Times(1); |
| 344 RTCMediaConstraints constraints; |
| 340 scoped_refptr<WebRtcLocalAudioTrack> track = | 345 scoped_refptr<WebRtcLocalAudioTrack> track = |
| 341 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); | 346 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, |
| 347 &constraints); |
| 342 track->Start(); | 348 track->Start(); |
| 343 | 349 |
| 344 // When the track goes away, it will automatically stop the | 350 // When the track goes away, it will automatically stop the |
| 345 // |capturer_source_|. | 351 // |capturer_source_|. |
| 346 EXPECT_CALL(*capturer_source_.get(), Stop()); | 352 EXPECT_CALL(*capturer_source_.get(), Stop()); |
| 347 track->Stop(); | 353 track->Stop(); |
| 348 track = NULL; | 354 track = NULL; |
| 349 } | 355 } |
| 350 | 356 |
| 351 // Start/Stop tracks and verify the capturer is correctly starting/stopping | 357 // Start/Stop tracks and verify the capturer is correctly starting/stopping |
| 352 // its source. | 358 // its source. |
| 353 TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { | 359 TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { |
| 354 // Starting the first audio track will start the |capturer_source_|. | 360 // Starting the first audio track will start the |capturer_source_|. |
| 355 base::WaitableEvent event(false, false); | 361 base::WaitableEvent event(false, false); |
| 356 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(SignalEvent(&event)); | 362 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(SignalEvent(&event)); |
| 363 RTCMediaConstraints constraints; |
| 357 scoped_refptr<WebRtcLocalAudioTrack> track_1 = | 364 scoped_refptr<WebRtcLocalAudioTrack> track_1 = |
| 358 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); | 365 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, |
| 366 &constraints); |
| 359 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> | 367 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> |
| 360 GetRenderer()->AddChannel(0); | 368 GetRenderer()->AddChannel(0); |
| 361 track_1->Start(); | 369 track_1->Start(); |
| 362 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 370 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
| 363 | 371 |
| 364 // Verify the data flow by connecting the sink to |track_1|. | 372 // Verify the data flow by connecting the sink to |track_1|. |
| 365 scoped_ptr<MockWebRtcAudioCapturerSink> sink( | 373 scoped_ptr<MockWebRtcAudioCapturerSink> sink( |
| 366 new MockWebRtcAudioCapturerSink()); | 374 new MockWebRtcAudioCapturerSink()); |
| 367 event.Reset(); | 375 event.Reset(); |
| 368 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, | 376 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, false, false)) |
| 369 // TODO(tommi): Change to |false| when issue 277134 is fixed. | |
| 370 _, | |
| 371 false)) | |
| 372 .Times(AnyNumber()).WillRepeatedly(Return()); | 377 .Times(AnyNumber()).WillRepeatedly(Return()); |
| 373 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1); | 378 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1); |
| 374 track_1->AddSink(sink.get()); | 379 track_1->AddSink(sink.get()); |
| 375 | 380 |
| 376 // Start the second audio track will not start the |capturer_source_| | 381 // Start the second audio track will not start the |capturer_source_| |
| 377 // since it has been started. | 382 // since it has been started. |
| 378 EXPECT_CALL(*capturer_source_.get(), Start()).Times(0); | 383 EXPECT_CALL(*capturer_source_.get(), Start()).Times(0); |
| 379 scoped_refptr<WebRtcLocalAudioTrack> track_2 = | 384 scoped_refptr<WebRtcLocalAudioTrack> track_2 = |
| 380 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); | 385 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, |
| 386 &constraints); |
| 381 track_2->Start(); | 387 track_2->Start(); |
| 382 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> | 388 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> |
| 383 GetRenderer()->AddChannel(1); | 389 GetRenderer()->AddChannel(1); |
| 384 | 390 |
| 385 // Stop the first audio track will not stop the |capturer_source_|. | 391 // Stop the first audio track will not stop the |capturer_source_|. |
| 386 EXPECT_CALL(*capturer_source_.get(), Stop()).Times(0); | 392 EXPECT_CALL(*capturer_source_.get(), Stop()).Times(0); |
| 387 track_1->RemoveSink(sink.get()); | 393 track_1->RemoveSink(sink.get()); |
| 388 track_1->Stop(); | 394 track_1->Stop(); |
| 389 track_1 = NULL; | 395 track_1 = NULL; |
| 390 | 396 |
| 391 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, false, false)) | 397 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, false, false)) |
| 392 .Times(AnyNumber()).WillRepeatedly(Return()); | 398 .Times(AnyNumber()).WillRepeatedly(Return()); |
| 393 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1); | 399 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1); |
| 394 track_2->AddSink(sink.get()); | 400 track_2->AddSink(sink.get()); |
| 395 | 401 |
| 396 // Stop the last audio track will stop the |capturer_source_|. | 402 // Stop the last audio track will stop the |capturer_source_|. |
| 397 event.Reset(); | 403 event.Reset(); |
| 398 EXPECT_CALL(*capturer_source_.get(), Stop()) | 404 EXPECT_CALL(*capturer_source_.get(), Stop()) |
| 399 .Times(1).WillOnce(SignalEvent(&event)); | 405 .Times(1).WillOnce(SignalEvent(&event)); |
| 400 track_2->Stop(); | 406 track_2->Stop(); |
| 401 track_2->RemoveSink(sink.get()); | 407 track_2->RemoveSink(sink.get()); |
| 402 track_2 = NULL; | 408 track_2 = NULL; |
| 403 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 409 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
| 404 } | 410 } |
| 405 | 411 |
| 406 // Set new source to the existing capturer. | 412 // Set new source to the existing capturer. |
| 407 TEST_F(WebRtcLocalAudioTrackTest, SetNewSourceForCapturerAfterStartTrack) { | 413 TEST_F(WebRtcLocalAudioTrackTest, SetNewSourceForCapturerAfterStartTrack) { |
| 408 // Setup the audio track and start the track. | 414 // Setup the audio track and start the track. |
| 409 EXPECT_CALL(*capturer_source_.get(), Start()).Times(1); | 415 EXPECT_CALL(*capturer_source_.get(), Start()).Times(1); |
| 416 RTCMediaConstraints constraints; |
| 410 scoped_refptr<WebRtcLocalAudioTrack> track = | 417 scoped_refptr<WebRtcLocalAudioTrack> track = |
| 411 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); | 418 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, |
| 419 &constraints); |
| 412 track->Start(); | 420 track->Start(); |
| 413 | 421 |
| 414 // Setting new source to the capturer and the track should still get packets. | 422 // Setting new source to the capturer and the track should still get packets. |
| 415 scoped_refptr<MockCapturerSource> new_source(new MockCapturerSource()); | 423 scoped_refptr<MockCapturerSource> new_source(new MockCapturerSource()); |
| 416 EXPECT_CALL(*capturer_source_.get(), Stop()); | 424 EXPECT_CALL(*capturer_source_.get(), Stop()); |
| 417 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(false)); | 425 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(false)); |
| 418 EXPECT_CALL(*new_source.get(), Initialize(_, capturer_.get(), 0)) | 426 EXPECT_CALL(*new_source.get(), Initialize(_, capturer_.get(), 0)) |
| 419 .WillOnce(Return()); | 427 .WillOnce(Return()); |
| 420 EXPECT_CALL(*new_source.get(), Start()).WillOnce(Return()); | 428 EXPECT_CALL(*new_source.get(), Start()).WillOnce(Return()); |
| 421 capturer_->SetCapturerSource(new_source, | 429 capturer_->SetCapturerSource(new_source, |
| 422 media::CHANNEL_LAYOUT_STEREO, | 430 media::CHANNEL_LAYOUT_STEREO, |
| 423 48000); | 431 48000); |
| 424 | 432 |
| 425 // Stop the track. | 433 // Stop the track. |
| 426 EXPECT_CALL(*new_source.get(), Stop()); | 434 EXPECT_CALL(*new_source.get(), Stop()); |
| 427 track->Stop(); | 435 track->Stop(); |
| 428 track = NULL; | 436 track = NULL; |
| 429 } | 437 } |
| 430 | 438 |
| 431 // Create a new capturer with new source, connect it to a new audio track. | 439 // Create a new capturer with new source, connect it to a new audio track. |
| 432 TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) { | 440 TEST_F(WebRtcLocalAudioTrackTest, ConnectTracksToDifferentCapturers) { |
| 433 // Setup the first audio track and start it. | 441 // Setup the first audio track and start it. |
| 434 EXPECT_CALL(*capturer_source_.get(), Start()).Times(1); | 442 EXPECT_CALL(*capturer_source_.get(), Start()).Times(1); |
| 443 RTCMediaConstraints constraints; |
| 435 scoped_refptr<WebRtcLocalAudioTrack> track_1 = | 444 scoped_refptr<WebRtcLocalAudioTrack> track_1 = |
| 436 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); | 445 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL, |
| 446 &constraints); |
| 437 track_1->Start(); | 447 track_1->Start(); |
| 438 | 448 |
| 439 // Connect a number of network channels to the |track_1|. | 449 // Connect a number of network channels to the |track_1|. |
| 440 static const int kNumberOfNetworkChannelsForTrack1 = 2; | 450 static const int kNumberOfNetworkChannelsForTrack1 = 2; |
| 441 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) { | 451 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) { |
| 442 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> | 452 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> |
| 443 GetRenderer()->AddChannel(i); | 453 GetRenderer()->AddChannel(i); |
| 444 } | 454 } |
| 445 // Verify the data flow by connecting the |sink_1| to |track_1|. | 455 // Verify the data flow by connecting the |sink_1| to |track_1|. |
| 446 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( | 456 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( |
| 447 new MockWebRtcAudioCapturerSink()); | 457 new MockWebRtcAudioCapturerSink()); |
| 448 EXPECT_CALL( | 458 EXPECT_CALL( |
| 449 *sink_1.get(), | 459 *sink_1.get(), |
| 450 CaptureData( | 460 CaptureData( |
| 451 kNumberOfNetworkChannelsForTrack1, 48000, 2, _, 0, 0, | 461 kNumberOfNetworkChannelsForTrack1, 48000, 2, _, 0, 0, false, false)) |
| 452 // TODO(tommi): Change to |false| when issue 277134 is fixed. | |
| 453 _, | |
| 454 false)) | |
| 455 .Times(AnyNumber()).WillRepeatedly(Return()); | 462 .Times(AnyNumber()).WillRepeatedly(Return()); |
| 456 EXPECT_CALL(*sink_1.get(), SetCaptureFormat(_)).Times(1); | 463 EXPECT_CALL(*sink_1.get(), SetCaptureFormat(_)).Times(1); |
| 457 track_1->AddSink(sink_1.get()); | 464 track_1->AddSink(sink_1.get()); |
| 458 | 465 |
| 459 // Create a new capturer with new source with different audio format. | 466 // Create a new capturer with new source with different audio format. |
| 460 scoped_refptr<WebRtcAudioCapturer> new_capturer( | 467 scoped_refptr<WebRtcAudioCapturer> new_capturer( |
| 461 WebRtcAudioCapturer::CreateCapturer()); | 468 WebRtcAudioCapturer::CreateCapturer()); |
| 462 scoped_refptr<MockCapturerSource> new_source(new MockCapturerSource()); | 469 scoped_refptr<MockCapturerSource> new_source(new MockCapturerSource()); |
| 463 EXPECT_CALL(*new_source.get(), Initialize(_, new_capturer.get(), 0)) | 470 EXPECT_CALL(*new_source.get(), Initialize(_, new_capturer.get(), 0)) |
| 464 .WillOnce(Return()); | 471 .WillOnce(Return()); |
| 465 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(false)) | 472 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(false)) |
| 466 .WillOnce(Return()); | 473 .WillOnce(Return()); |
| 467 new_capturer->SetCapturerSource(new_source, | 474 new_capturer->SetCapturerSource(new_source, |
| 468 media::CHANNEL_LAYOUT_MONO, | 475 media::CHANNEL_LAYOUT_MONO, |
| 469 44100); | 476 44100); |
| 470 | 477 |
| 471 // Start the audio thread used by the new source. | 478 // Start the audio thread used by the new source. |
| 472 scoped_ptr<FakeAudioThread> audio_thread(new FakeAudioThread(new_capturer)); | 479 scoped_ptr<FakeAudioThread> audio_thread(new FakeAudioThread(new_capturer)); |
| 473 audio_thread->Start(); | 480 audio_thread->Start(); |
| 474 | 481 |
| 475 // Setup the second audio track, connect it to the new capturer and start it. | 482 // Setup the second audio track, connect it to the new capturer and start it. |
| 476 EXPECT_CALL(*new_source.get(), Start()).Times(1); | 483 EXPECT_CALL(*new_source.get(), Start()).Times(1); |
| 477 scoped_refptr<WebRtcLocalAudioTrack> track_2 = | 484 scoped_refptr<WebRtcLocalAudioTrack> track_2 = |
| 478 WebRtcLocalAudioTrack::Create(std::string(), new_capturer, NULL); | 485 WebRtcLocalAudioTrack::Create(std::string(), new_capturer, NULL, |
| 486 &constraints); |
| 479 track_2->Start(); | 487 track_2->Start(); |
| 480 | 488 |
| 481 // Connect a number of network channels to the |track_2|. | 489 // Connect a number of network channels to the |track_2|. |
| 482 static const int kNumberOfNetworkChannelsForTrack2 = 3; | 490 static const int kNumberOfNetworkChannelsForTrack2 = 3; |
| 483 for (int i = 0; i < kNumberOfNetworkChannelsForTrack2; ++i) { | 491 for (int i = 0; i < kNumberOfNetworkChannelsForTrack2; ++i) { |
| 484 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> | 492 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> |
| 485 GetRenderer()->AddChannel(i); | 493 GetRenderer()->AddChannel(i); |
| 486 } | 494 } |
| 487 // Verify the data flow by connecting the |sink_2| to |track_2|. | 495 // Verify the data flow by connecting the |sink_2| to |track_2|. |
| 488 scoped_ptr<MockWebRtcAudioCapturerSink> sink_2( | 496 scoped_ptr<MockWebRtcAudioCapturerSink> sink_2( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 505 audio_thread->Stop(); | 513 audio_thread->Stop(); |
| 506 audio_thread.reset(); | 514 audio_thread.reset(); |
| 507 | 515 |
| 508 // Stop the first audio track. | 516 // Stop the first audio track. |
| 509 EXPECT_CALL(*capturer_source_.get(), Stop()); | 517 EXPECT_CALL(*capturer_source_.get(), Stop()); |
| 510 track_1->Stop(); | 518 track_1->Stop(); |
| 511 track_1 = NULL; | 519 track_1 = NULL; |
| 512 } | 520 } |
| 513 | 521 |
| 514 } // namespace content | 522 } // namespace content |
| OLD | NEW |