| 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/public/renderer/media_stream_audio_sink.h" |
| 7 #include "content/renderer/media/media_stream_audio_source.h" | 8 #include "content/renderer/media/media_stream_audio_source.h" |
| 8 #include "content/renderer/media/mock_media_constraint_factory.h" | 9 #include "content/renderer/media/mock_media_constraint_factory.h" |
| 9 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | 10 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" |
| 10 #include "content/renderer/media/webrtc_audio_capturer.h" | 11 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 11 #include "content/renderer/media/webrtc_audio_device_impl.h" | |
| 12 #include "content/renderer/media/webrtc_local_audio_track.h" | 12 #include "content/renderer/media/webrtc_local_audio_track.h" |
| 13 #include "media/audio/audio_parameters.h" | 13 #include "media/audio/audio_parameters.h" |
| 14 #include "media/base/audio_bus.h" | 14 #include "media/base/audio_bus.h" |
| 15 #include "media/base/audio_capturer_source.h" | 15 #include "media/base/audio_capturer_source.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 18 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 19 #include "third_party/WebKit/public/web/WebHeap.h" | 19 #include "third_party/WebKit/public/web/WebHeap.h" |
| 20 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" | 20 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" |
| 21 | 21 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 } | 115 } |
| 116 protected: | 116 protected: |
| 117 virtual ~MockCapturerSource() {} | 117 virtual ~MockCapturerSource() {} |
| 118 | 118 |
| 119 private: | 119 private: |
| 120 scoped_ptr<FakeAudioThread> audio_thread_; | 120 scoped_ptr<FakeAudioThread> audio_thread_; |
| 121 WebRtcAudioCapturer* capturer_; | 121 WebRtcAudioCapturer* capturer_; |
| 122 media::AudioParameters params_; | 122 media::AudioParameters params_; |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 // TODO(xians): Use MediaStreamAudioSink. | 125 class MockMediaStreamAudioSink : public MediaStreamAudioSink { |
| 126 class MockMediaStreamAudioSink : public PeerConnectionAudioSink { | |
| 127 public: | 126 public: |
| 128 MockMediaStreamAudioSink() {} | 127 MockMediaStreamAudioSink() {} |
| 129 ~MockMediaStreamAudioSink() {} | 128 ~MockMediaStreamAudioSink() {} |
| 130 int OnData(const int16* audio_data, | 129 void OnData(const int16* audio_data, |
| 131 int sample_rate, | 130 int sample_rate, |
| 132 int number_of_channels, | 131 int number_of_channels, |
| 133 int number_of_frames, | 132 int number_of_frames) override { |
| 134 const std::vector<int>& channels, | |
| 135 int audio_delay_milliseconds, | |
| 136 int current_volume, | |
| 137 bool need_audio_processing, | |
| 138 bool key_pressed) override { | |
| 139 EXPECT_EQ(params_.sample_rate(), sample_rate); | 133 EXPECT_EQ(params_.sample_rate(), sample_rate); |
| 140 EXPECT_EQ(params_.channels(), number_of_channels); | 134 EXPECT_EQ(params_.channels(), number_of_channels); |
| 141 EXPECT_EQ(params_.frames_per_buffer(), number_of_frames); | 135 EXPECT_EQ(params_.frames_per_buffer(), number_of_frames); |
| 142 CaptureData(channels.size(), | 136 CaptureData(); |
| 143 audio_delay_milliseconds, | |
| 144 current_volume, | |
| 145 need_audio_processing, | |
| 146 key_pressed); | |
| 147 return 0; | |
| 148 } | 137 } |
| 149 MOCK_METHOD5(CaptureData, | 138 MOCK_METHOD0(CaptureData, void()); |
| 150 void(int number_of_network_channels, | |
| 151 int audio_delay_milliseconds, | |
| 152 int current_volume, | |
| 153 bool need_audio_processing, | |
| 154 bool key_pressed)); | |
| 155 void OnSetFormat(const media::AudioParameters& params) { | 139 void OnSetFormat(const media::AudioParameters& params) { |
| 156 params_ = params; | 140 params_ = params; |
| 157 FormatIsSet(); | 141 FormatIsSet(); |
| 158 } | 142 } |
| 159 MOCK_METHOD0(FormatIsSet, void()); | 143 MOCK_METHOD0(FormatIsSet, void()); |
| 160 | 144 |
| 161 const media::AudioParameters& audio_params() const { return params_; } | 145 const media::AudioParameters& audio_params() const { return params_; } |
| 162 | 146 |
| 163 private: | 147 private: |
| 164 media::AudioParameters params_; | 148 media::AudioParameters params_; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 195 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 212 scoped_ptr<WebRtcLocalAudioTrack> track( | 196 scoped_ptr<WebRtcLocalAudioTrack> track( |
| 213 new WebRtcLocalAudioTrack(adapter.get(), capturer_, NULL)); | 197 new WebRtcLocalAudioTrack(adapter.get(), capturer_, NULL)); |
| 214 track->Start(); | 198 track->Start(); |
| 215 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); | 199 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); |
| 216 | 200 |
| 217 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 201 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
| 218 base::WaitableEvent event(false, false); | 202 base::WaitableEvent event(false, false); |
| 219 EXPECT_CALL(*sink, FormatIsSet()); | 203 EXPECT_CALL(*sink, FormatIsSet()); |
| 220 EXPECT_CALL(*sink, | 204 EXPECT_CALL(*sink, |
| 221 CaptureData(0, | 205 CaptureData()).Times(AtLeast(1)) |
| 222 0, | |
| 223 0, | |
| 224 _, | |
| 225 false)).Times(AtLeast(1)) | |
| 226 .WillRepeatedly(SignalEvent(&event)); | 206 .WillRepeatedly(SignalEvent(&event)); |
| 227 track->AddSink(sink.get()); | 207 track->AddSink(sink.get()); |
| 228 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 208 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
| 229 track->RemoveSink(sink.get()); | 209 track->RemoveSink(sink.get()); |
| 230 | 210 |
| 231 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); | 211 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); |
| 232 capturer_->Stop(); | 212 capturer_->Stop(); |
| 233 } | 213 } |
| 234 | 214 |
| 235 // The same setup as ConnectAndDisconnectOneSink, but enable and disable the | 215 // The same setup as ConnectAndDisconnectOneSink, but enable and disable the |
| 236 // audio track on the fly. When the audio track is disabled, there is no data | 216 // audio track on the fly. When the audio track is disabled, there is no data |
| 237 // callback to the sink; when the audio track is enabled, there comes data | 217 // callback to the sink; when the audio track is enabled, there comes data |
| 238 // callback. | 218 // callback. |
| 239 // TODO(xians): Enable this test after resolving the racing issue that TSAN | 219 // TODO(xians): Enable this test after resolving the racing issue that TSAN |
| 240 // reports on MediaStreamTrack::enabled(); | 220 // reports on MediaStreamTrack::enabled(); |
| 241 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) { | 221 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) { |
| 242 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); | 222 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); |
| 243 EXPECT_CALL(*capturer_source_.get(), OnStart()); | 223 EXPECT_CALL(*capturer_source_.get(), OnStart()); |
| 244 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 224 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
| 245 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 225 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 246 scoped_ptr<WebRtcLocalAudioTrack> track( | 226 scoped_ptr<WebRtcLocalAudioTrack> track( |
| 247 new WebRtcLocalAudioTrack(adapter.get(), capturer_, NULL)); | 227 new WebRtcLocalAudioTrack(adapter.get(), capturer_, NULL)); |
| 248 track->Start(); | 228 track->Start(); |
| 249 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); | 229 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); |
| 250 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(false)); | 230 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(false)); |
| 251 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 231 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
| 252 const media::AudioParameters params = capturer_->source_audio_parameters(); | 232 const media::AudioParameters params = capturer_->source_audio_parameters(); |
| 253 base::WaitableEvent event(false, false); | 233 base::WaitableEvent event(false, false); |
| 254 EXPECT_CALL(*sink, FormatIsSet()).Times(1); | 234 EXPECT_CALL(*sink, FormatIsSet()).Times(1); |
| 255 EXPECT_CALL(*sink, | 235 EXPECT_CALL(*sink, CaptureData()).Times(0); |
| 256 CaptureData(0, 0, 0, _, false)).Times(0); | |
| 257 EXPECT_EQ(sink->audio_params().frames_per_buffer(), | 236 EXPECT_EQ(sink->audio_params().frames_per_buffer(), |
| 258 params.sample_rate() / 100); | 237 params.sample_rate() / 100); |
| 259 track->AddSink(sink.get()); | 238 track->AddSink(sink.get()); |
| 260 EXPECT_FALSE(event.TimedWait(TestTimeouts::tiny_timeout())); | 239 EXPECT_FALSE(event.TimedWait(TestTimeouts::tiny_timeout())); |
| 261 | 240 |
| 262 event.Reset(); | 241 event.Reset(); |
| 263 EXPECT_CALL(*sink, CaptureData(0, 0, 0, _, false)).Times(AtLeast(1)) | 242 EXPECT_CALL(*sink, CaptureData()).Times(AtLeast(1)) |
| 264 .WillRepeatedly(SignalEvent(&event)); | 243 .WillRepeatedly(SignalEvent(&event)); |
| 265 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(true)); | 244 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(true)); |
| 266 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 245 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
| 267 track->RemoveSink(sink.get()); | 246 track->RemoveSink(sink.get()); |
| 268 | 247 |
| 269 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); | 248 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); |
| 270 capturer_->Stop(); | 249 capturer_->Stop(); |
| 271 track.reset(); | 250 track.reset(); |
| 272 } | 251 } |
| 273 | 252 |
| 274 // Create multiple audio tracks and enable/disable them, verify that the audio | 253 // Create multiple audio tracks and enable/disable them, verify that the audio |
| 275 // callbacks appear/disappear. | 254 // callbacks appear/disappear. |
| 276 // Flaky due to a data race, see http://crbug.com/295418 | 255 // Flaky due to a data race, see http://crbug.com/295418 |
| 277 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) { | 256 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) { |
| 278 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( | 257 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( |
| 279 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 258 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 280 scoped_ptr<WebRtcLocalAudioTrack> track_1( | 259 scoped_ptr<WebRtcLocalAudioTrack> track_1( |
| 281 new WebRtcLocalAudioTrack(adapter_1.get(), capturer_, NULL)); | 260 new WebRtcLocalAudioTrack(adapter_1.get(), capturer_, NULL)); |
| 282 track_1->Start(); | 261 track_1->Start(); |
| 283 EXPECT_TRUE(track_1->GetAudioAdapter()->enabled()); | 262 EXPECT_TRUE(track_1->GetAudioAdapter()->enabled()); |
| 284 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); | 263 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); |
| 285 const media::AudioParameters params = capturer_->source_audio_parameters(); | 264 const media::AudioParameters params = capturer_->source_audio_parameters(); |
| 286 base::WaitableEvent event_1(false, false); | 265 base::WaitableEvent event_1(false, false); |
| 287 EXPECT_CALL(*sink_1, FormatIsSet()).WillOnce(Return()); | 266 EXPECT_CALL(*sink_1, FormatIsSet()).WillOnce(Return()); |
| 288 EXPECT_CALL(*sink_1, | 267 EXPECT_CALL(*sink_1, CaptureData()).Times(AtLeast(1)) |
| 289 CaptureData(0, 0, 0, _, false)).Times(AtLeast(1)) | |
| 290 .WillRepeatedly(SignalEvent(&event_1)); | 268 .WillRepeatedly(SignalEvent(&event_1)); |
| 291 EXPECT_EQ(sink_1->audio_params().frames_per_buffer(), | 269 EXPECT_EQ(sink_1->audio_params().frames_per_buffer(), |
| 292 params.sample_rate() / 100); | 270 params.sample_rate() / 100); |
| 293 track_1->AddSink(sink_1.get()); | 271 track_1->AddSink(sink_1.get()); |
| 294 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 272 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
| 295 | 273 |
| 296 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( | 274 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( |
| 297 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 275 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 298 scoped_ptr<WebRtcLocalAudioTrack> track_2( | 276 scoped_ptr<WebRtcLocalAudioTrack> track_2( |
| 299 new WebRtcLocalAudioTrack(adapter_2.get(), capturer_, NULL)); | 277 new WebRtcLocalAudioTrack(adapter_2.get(), capturer_, NULL)); |
| 300 track_2->Start(); | 278 track_2->Start(); |
| 301 EXPECT_TRUE(track_2->GetAudioAdapter()->enabled()); | 279 EXPECT_TRUE(track_2->GetAudioAdapter()->enabled()); |
| 302 | 280 |
| 303 // Verify both |sink_1| and |sink_2| get data. | 281 // Verify both |sink_1| and |sink_2| get data. |
| 304 event_1.Reset(); | 282 event_1.Reset(); |
| 305 base::WaitableEvent event_2(false, false); | 283 base::WaitableEvent event_2(false, false); |
| 306 | 284 |
| 307 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); | 285 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); |
| 308 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(Return()); | 286 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(Return()); |
| 309 EXPECT_CALL(*sink_1, CaptureData(0, 0, 0, _, false)).Times(AtLeast(1)) | 287 EXPECT_CALL(*sink_1, CaptureData()).Times(AtLeast(1)) |
| 310 .WillRepeatedly(SignalEvent(&event_1)); | 288 .WillRepeatedly(SignalEvent(&event_1)); |
| 311 EXPECT_EQ(sink_1->audio_params().frames_per_buffer(), | 289 EXPECT_EQ(sink_1->audio_params().frames_per_buffer(), |
| 312 params.sample_rate() / 100); | 290 params.sample_rate() / 100); |
| 313 EXPECT_CALL(*sink_2, CaptureData(0, 0, 0, _, false)).Times(AtLeast(1)) | 291 EXPECT_CALL(*sink_2, CaptureData()).Times(AtLeast(1)) |
| 314 .WillRepeatedly(SignalEvent(&event_2)); | 292 .WillRepeatedly(SignalEvent(&event_2)); |
| 315 EXPECT_EQ(sink_2->audio_params().frames_per_buffer(), | 293 EXPECT_EQ(sink_2->audio_params().frames_per_buffer(), |
| 316 params.sample_rate() / 100); | 294 params.sample_rate() / 100); |
| 317 track_2->AddSink(sink_2.get()); | 295 track_2->AddSink(sink_2.get()); |
| 318 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 296 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
| 319 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); | 297 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); |
| 320 | 298 |
| 321 track_1->RemoveSink(sink_1.get()); | 299 track_1->RemoveSink(sink_1.get()); |
| 322 track_1->Stop(); | 300 track_1->Stop(); |
| 323 track_1.reset(); | 301 track_1.reset(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( | 352 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( |
| 375 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 353 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 376 scoped_ptr<WebRtcLocalAudioTrack> track_1( | 354 scoped_ptr<WebRtcLocalAudioTrack> track_1( |
| 377 new WebRtcLocalAudioTrack(adapter_1.get(), capturer_, NULL)); | 355 new WebRtcLocalAudioTrack(adapter_1.get(), capturer_, NULL)); |
| 378 track_1->Start(); | 356 track_1->Start(); |
| 379 | 357 |
| 380 // Verify the data flow by connecting the sink to |track_1|. | 358 // Verify the data flow by connecting the sink to |track_1|. |
| 381 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 359 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
| 382 event.Reset(); | 360 event.Reset(); |
| 383 EXPECT_CALL(*sink, FormatIsSet()).WillOnce(SignalEvent(&event)); | 361 EXPECT_CALL(*sink, FormatIsSet()).WillOnce(SignalEvent(&event)); |
| 384 EXPECT_CALL(*sink, CaptureData(_, 0, 0, _, false)) | 362 EXPECT_CALL(*sink, CaptureData()) |
| 385 .Times(AnyNumber()).WillRepeatedly(Return()); | 363 .Times(AnyNumber()).WillRepeatedly(Return()); |
| 386 track_1->AddSink(sink.get()); | 364 track_1->AddSink(sink.get()); |
| 387 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 365 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
| 388 | 366 |
| 389 // Start the second audio track will not start the |capturer_source_| | 367 // Start the second audio track will not start the |capturer_source_| |
| 390 // since it has been started. | 368 // since it has been started. |
| 391 EXPECT_CALL(*capturer_source_.get(), OnStart()).Times(0); | 369 EXPECT_CALL(*capturer_source_.get(), OnStart()).Times(0); |
| 392 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( | 370 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( |
| 393 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 371 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 394 scoped_ptr<WebRtcLocalAudioTrack> track_2( | 372 scoped_ptr<WebRtcLocalAudioTrack> track_2( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 422 DISABLE_ON_TSAN(ConnectTracksToDifferentCapturers)) { | 400 DISABLE_ON_TSAN(ConnectTracksToDifferentCapturers)) { |
| 423 // Setup the first audio track and start it. | 401 // Setup the first audio track and start it. |
| 424 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( | 402 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( |
| 425 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 403 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 426 scoped_ptr<WebRtcLocalAudioTrack> track_1( | 404 scoped_ptr<WebRtcLocalAudioTrack> track_1( |
| 427 new WebRtcLocalAudioTrack(adapter_1.get(), capturer_, NULL)); | 405 new WebRtcLocalAudioTrack(adapter_1.get(), capturer_, NULL)); |
| 428 track_1->Start(); | 406 track_1->Start(); |
| 429 | 407 |
| 430 // Verify the data flow by connecting the |sink_1| to |track_1|. | 408 // Verify the data flow by connecting the |sink_1| to |track_1|. |
| 431 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); | 409 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); |
| 432 EXPECT_CALL(*sink_1.get(), CaptureData(0, 0, 0, _, false)) | 410 EXPECT_CALL(*sink_1.get(), CaptureData()) |
| 433 .Times(AnyNumber()).WillRepeatedly(Return()); | 411 .Times(AnyNumber()).WillRepeatedly(Return()); |
| 434 EXPECT_CALL(*sink_1.get(), FormatIsSet()).Times(AnyNumber()); | 412 EXPECT_CALL(*sink_1.get(), FormatIsSet()).Times(AnyNumber()); |
| 435 track_1->AddSink(sink_1.get()); | 413 track_1->AddSink(sink_1.get()); |
| 436 | 414 |
| 437 // Create a new capturer with new source with different audio format. | 415 // Create a new capturer with new source with different audio format. |
| 438 MockMediaConstraintFactory constraint_factory; | 416 MockMediaConstraintFactory constraint_factory; |
| 439 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE, | 417 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE, |
| 440 std::string(), std::string()); | 418 std::string(), std::string()); |
| 441 scoped_refptr<WebRtcAudioCapturer> new_capturer( | 419 scoped_refptr<WebRtcAudioCapturer> new_capturer( |
| 442 WebRtcAudioCapturer::CreateCapturer( | 420 WebRtcAudioCapturer::CreateCapturer( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 456 // Setup the second audio track, connect it to the new capturer and start it. | 434 // Setup the second audio track, connect it to the new capturer and start it. |
| 457 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( | 435 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( |
| 458 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 436 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
| 459 scoped_ptr<WebRtcLocalAudioTrack> track_2( | 437 scoped_ptr<WebRtcLocalAudioTrack> track_2( |
| 460 new WebRtcLocalAudioTrack(adapter_2.get(), new_capturer, NULL)); | 438 new WebRtcLocalAudioTrack(adapter_2.get(), new_capturer, NULL)); |
| 461 track_2->Start(); | 439 track_2->Start(); |
| 462 | 440 |
| 463 // Verify the data flow by connecting the |sink_2| to |track_2|. | 441 // Verify the data flow by connecting the |sink_2| to |track_2|. |
| 464 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); | 442 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); |
| 465 base::WaitableEvent event(false, false); | 443 base::WaitableEvent event(false, false); |
| 466 EXPECT_CALL(*sink_2, CaptureData(0, 0, 0, _, false)) | 444 EXPECT_CALL(*sink_2, CaptureData()) |
| 467 .Times(AnyNumber()).WillRepeatedly(Return()); | 445 .Times(AnyNumber()).WillRepeatedly(Return()); |
| 468 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(SignalEvent(&event)); | 446 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(SignalEvent(&event)); |
| 469 track_2->AddSink(sink_2.get()); | 447 track_2->AddSink(sink_2.get()); |
| 470 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 448 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
| 471 | 449 |
| 472 // Stopping the new source will stop the second track. | 450 // Stopping the new source will stop the second track. |
| 473 event.Reset(); | 451 event.Reset(); |
| 474 EXPECT_CALL(*new_source.get(), OnStop()) | 452 EXPECT_CALL(*new_source.get(), OnStop()) |
| 475 .Times(1).WillOnce(SignalEvent(&event)); | 453 .Times(1).WillOnce(SignalEvent(&event)); |
| 476 new_capturer->Stop(); | 454 new_capturer->Stop(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 // Verify the data flow by connecting the |sink| to |track|. | 495 // Verify the data flow by connecting the |sink| to |track|. |
| 518 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 496 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
| 519 base::WaitableEvent event(false, false); | 497 base::WaitableEvent event(false, false); |
| 520 EXPECT_CALL(*sink, FormatIsSet()).Times(1); | 498 EXPECT_CALL(*sink, FormatIsSet()).Times(1); |
| 521 // Verify the sinks are getting the packets with an expecting buffer size. | 499 // Verify the sinks are getting the packets with an expecting buffer size. |
| 522 #if defined(OS_ANDROID) | 500 #if defined(OS_ANDROID) |
| 523 const int expected_buffer_size = params.sample_rate() / 100; | 501 const int expected_buffer_size = params.sample_rate() / 100; |
| 524 #else | 502 #else |
| 525 const int expected_buffer_size = params.frames_per_buffer(); | 503 const int expected_buffer_size = params.frames_per_buffer(); |
| 526 #endif | 504 #endif |
| 527 EXPECT_CALL(*sink, CaptureData( | 505 EXPECT_CALL(*sink, CaptureData()) |
| 528 0, 0, 0, _, false)) | |
| 529 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); | 506 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); |
| 530 track->AddSink(sink.get()); | 507 track->AddSink(sink.get()); |
| 531 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 508 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
| 532 EXPECT_EQ(expected_buffer_size, sink->audio_params().frames_per_buffer()); | 509 EXPECT_EQ(expected_buffer_size, sink->audio_params().frames_per_buffer()); |
| 533 | 510 |
| 534 // Stopping the new source will stop the second track. | 511 // Stopping the new source will stop the second track. |
| 535 EXPECT_CALL(*source.get(), OnStop()).Times(1); | 512 EXPECT_CALL(*source.get(), OnStop()).Times(1); |
| 536 capturer->Stop(); | 513 capturer->Stop(); |
| 537 | 514 |
| 538 // Even though this test don't use |capturer_source_| it will be stopped | 515 // Even though this test don't use |capturer_source_| it will be stopped |
| 539 // during teardown of the test harness. | 516 // during teardown of the test harness. |
| 540 EXPECT_CALL(*capturer_source_.get(), OnStop()); | 517 EXPECT_CALL(*capturer_source_.get(), OnStop()); |
| 541 } | 518 } |
| 542 | 519 |
| 543 } // namespace content | 520 } // namespace content |
| OLD | NEW |