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