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/webrtc_audio_capturer.h" | 7 #include "content/renderer/media/webrtc_audio_capturer.h" |
8 #include "content/renderer/media/webrtc_local_audio_track.h" | 8 #include "content/renderer/media/webrtc_local_audio_track.h" |
9 #include "media/audio/audio_parameters.h" | 9 #include "media/audio/audio_parameters.h" |
10 #include "media/base/audio_bus.h" | 10 #include "media/base/audio_bus.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // base::PlatformThread::Delegate: | 43 // base::PlatformThread::Delegate: |
44 virtual void ThreadMain() OVERRIDE { | 44 virtual void ThreadMain() OVERRIDE { |
45 while (true) { | 45 while (true) { |
46 if (closure_.IsSignaled()) | 46 if (closure_.IsSignaled()) |
47 return; | 47 return; |
48 | 48 |
49 media::AudioCapturerSource::CaptureCallback* callback = | 49 media::AudioCapturerSource::CaptureCallback* callback = |
50 static_cast<media::AudioCapturerSource::CaptureCallback*>( | 50 static_cast<media::AudioCapturerSource::CaptureCallback*>( |
51 capturer_.get()); | 51 capturer_.get()); |
52 audio_bus_->Zero(); | 52 audio_bus_->Zero(); |
53 callback->Capture(audio_bus_.get(), 0, 0, false); | 53 callback->Capture(audio_bus_.get(), 0, 0); |
54 | 54 |
55 // Sleep 1ms to yield the resource for the main thread. | 55 // Sleep 1ms to yield the resource for the main thread. |
56 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); | 56 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(1)); |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 void Start() { | 60 void Start() { |
61 base::PlatformThread::CreateWithPriority( | 61 base::PlatformThread::CreateWithPriority( |
62 0, this, &thread_, base::kThreadPriority_RealtimeAudio); | 62 0, this, &thread_, base::kThreadPriority_RealtimeAudio); |
63 CHECK(!thread_.is_null()); | 63 CHECK(!thread_.is_null()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 public: | 96 public: |
97 MockWebRtcAudioCapturerSink() {} | 97 MockWebRtcAudioCapturerSink() {} |
98 ~MockWebRtcAudioCapturerSink() {} | 98 ~MockWebRtcAudioCapturerSink() {} |
99 int CaptureData(const std::vector<int>& channels, | 99 int CaptureData(const std::vector<int>& channels, |
100 const int16* audio_data, | 100 const int16* audio_data, |
101 int sample_rate, | 101 int sample_rate, |
102 int number_of_channels, | 102 int number_of_channels, |
103 int number_of_frames, | 103 int number_of_frames, |
104 int audio_delay_milliseconds, | 104 int audio_delay_milliseconds, |
105 int current_volume, | 105 int current_volume, |
106 bool need_audio_processing, | 106 bool need_audio_processing) OVERRIDE { |
107 bool key_pressed) OVERRIDE { | 107 CaptureData(channels.size(), sample_rate, number_of_channels, |
108 CaptureData(channels.size(), | 108 number_of_frames, audio_delay_milliseconds, current_volume, |
109 sample_rate, | 109 need_audio_processing); |
110 number_of_channels, | |
111 number_of_frames, | |
112 audio_delay_milliseconds, | |
113 current_volume, | |
114 need_audio_processing, | |
115 key_pressed); | |
116 return 0; | 110 return 0; |
117 } | 111 } |
118 MOCK_METHOD8(CaptureData, | 112 MOCK_METHOD7(CaptureData, void(int number_of_network_channels, |
119 void(int number_of_network_channels, | 113 int sample_rate, |
120 int sample_rate, | 114 int number_of_channels, |
121 int number_of_channels, | 115 int number_of_frames, |
122 int number_of_frames, | 116 int audio_delay_milliseconds, |
123 int audio_delay_milliseconds, | 117 int current_volume, |
124 int current_volume, | 118 bool need_audio_processing)); |
125 bool need_audio_processing, | 119 |
126 bool key_pressed)); | |
127 MOCK_METHOD1(SetCaptureFormat, void(const media::AudioParameters& params)); | 120 MOCK_METHOD1(SetCaptureFormat, void(const media::AudioParameters& params)); |
128 }; | 121 }; |
129 | 122 |
130 } // namespace | 123 } // namespace |
131 | 124 |
132 class WebRtcLocalAudioTrackTest : public ::testing::Test { | 125 class WebRtcLocalAudioTrackTest : public ::testing::Test { |
133 protected: | 126 protected: |
134 virtual void SetUp() OVERRIDE { | 127 virtual void SetUp() OVERRIDE { |
135 capturer_ = WebRtcAudioCapturer::CreateCapturer(); | 128 capturer_ = WebRtcAudioCapturer::CreateCapturer(); |
136 capturer_source_ = new MockCapturerSource(); | 129 capturer_source_ = new MockCapturerSource(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 static const int kNumberOfNetworkChannels = 4; | 166 static const int kNumberOfNetworkChannels = 4; |
174 for (int i = 0; i < kNumberOfNetworkChannels; ++i) { | 167 for (int i = 0; i < kNumberOfNetworkChannels; ++i) { |
175 static_cast<webrtc::AudioTrackInterface*>(track.get())-> | 168 static_cast<webrtc::AudioTrackInterface*>(track.get())-> |
176 GetRenderer()->AddChannel(i); | 169 GetRenderer()->AddChannel(i); |
177 } | 170 } |
178 scoped_ptr<MockWebRtcAudioCapturerSink> sink( | 171 scoped_ptr<MockWebRtcAudioCapturerSink> sink( |
179 new MockWebRtcAudioCapturerSink()); | 172 new MockWebRtcAudioCapturerSink()); |
180 const media::AudioParameters params = capturer_->audio_parameters(); | 173 const media::AudioParameters params = capturer_->audio_parameters(); |
181 base::WaitableEvent event(false, false); | 174 base::WaitableEvent event(false, false); |
182 EXPECT_CALL(*sink, SetCaptureFormat(_)).WillOnce(Return()); | 175 EXPECT_CALL(*sink, SetCaptureFormat(_)).WillOnce(Return()); |
183 EXPECT_CALL(*sink, | 176 EXPECT_CALL(*sink, CaptureData( |
184 CaptureData(kNumberOfNetworkChannels, | 177 kNumberOfNetworkChannels, params.sample_rate(), params.channels(), |
185 params.sample_rate(), | 178 params.frames_per_buffer(), 0, 0, false)) |
186 params.channels(), | 179 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); |
187 params.frames_per_buffer(), | |
188 0, | |
189 0, | |
190 false, | |
191 false)).Times(AtLeast(1)) | |
192 .WillRepeatedly(SignalEvent(&event)); | |
193 track->AddSink(sink.get()); | 180 track->AddSink(sink.get()); |
194 | 181 |
195 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 182 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
196 track->RemoveSink(sink.get()); | 183 track->RemoveSink(sink.get()); |
197 | 184 |
198 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); | 185 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); |
199 track->Stop(); | 186 track->Stop(); |
200 track = NULL; | 187 track = NULL; |
201 } | 188 } |
202 | 189 |
(...skipping 10 matching lines...) Expand all Loading... |
213 track->Start(); | 200 track->Start(); |
214 static_cast<webrtc::AudioTrackInterface*>(track.get())-> | 201 static_cast<webrtc::AudioTrackInterface*>(track.get())-> |
215 GetRenderer()->AddChannel(0); | 202 GetRenderer()->AddChannel(0); |
216 EXPECT_TRUE(track->enabled()); | 203 EXPECT_TRUE(track->enabled()); |
217 EXPECT_TRUE(track->set_enabled(false)); | 204 EXPECT_TRUE(track->set_enabled(false)); |
218 scoped_ptr<MockWebRtcAudioCapturerSink> sink( | 205 scoped_ptr<MockWebRtcAudioCapturerSink> sink( |
219 new MockWebRtcAudioCapturerSink()); | 206 new MockWebRtcAudioCapturerSink()); |
220 const media::AudioParameters params = capturer_->audio_parameters(); | 207 const media::AudioParameters params = capturer_->audio_parameters(); |
221 base::WaitableEvent event(false, false); | 208 base::WaitableEvent event(false, false); |
222 EXPECT_CALL(*sink, SetCaptureFormat(_)).WillOnce(Return()); | 209 EXPECT_CALL(*sink, SetCaptureFormat(_)).WillOnce(Return()); |
223 EXPECT_CALL(*sink, | 210 EXPECT_CALL(*sink, CaptureData( |
224 CaptureData(1, | 211 1, params.sample_rate(), params.channels(), |
225 params.sample_rate(), | 212 params.frames_per_buffer(), 0, 0, false)) |
226 params.channels(), | 213 .Times(0); |
227 params.frames_per_buffer(), | |
228 0, | |
229 0, | |
230 false, | |
231 false)).Times(0); | |
232 track->AddSink(sink.get()); | 214 track->AddSink(sink.get()); |
233 EXPECT_FALSE(event.TimedWait(TestTimeouts::tiny_timeout())); | 215 EXPECT_FALSE(event.TimedWait(TestTimeouts::tiny_timeout())); |
234 | 216 |
235 event.Reset(); | 217 event.Reset(); |
236 EXPECT_CALL(*sink, | 218 EXPECT_CALL(*sink, CaptureData( |
237 CaptureData(1, | 219 1, params.sample_rate(), params.channels(), |
238 params.sample_rate(), | 220 params.frames_per_buffer(), 0, 0, false)) |
239 params.channels(), | 221 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); |
240 params.frames_per_buffer(), | |
241 0, | |
242 0, | |
243 false, | |
244 false)).Times(AtLeast(1)) | |
245 .WillRepeatedly(SignalEvent(&event)); | |
246 EXPECT_TRUE(track->set_enabled(true)); | 222 EXPECT_TRUE(track->set_enabled(true)); |
247 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 223 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
248 track->RemoveSink(sink.get()); | 224 track->RemoveSink(sink.get()); |
249 | 225 |
250 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); | 226 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); |
251 track->Stop(); | 227 track->Stop(); |
252 track = NULL; | 228 track = NULL; |
253 } | 229 } |
254 | 230 |
255 // Create multiple audio tracks and enable/disable them, verify that the audio | 231 // Create multiple audio tracks and enable/disable them, verify that the audio |
256 // callbacks appear/disappear. | 232 // callbacks appear/disappear. |
257 TEST_F(WebRtcLocalAudioTrackTest, MultipleAudioTracks) { | 233 TEST_F(WebRtcLocalAudioTrackTest, MultipleAudioTracks) { |
258 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); | 234 EXPECT_CALL(*capturer_source_.get(), Start()).WillOnce(Return()); |
259 scoped_refptr<WebRtcLocalAudioTrack> track_1 = | 235 scoped_refptr<WebRtcLocalAudioTrack> track_1 = |
260 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); | 236 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); |
261 track_1->Start(); | 237 track_1->Start(); |
262 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> | 238 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> |
263 GetRenderer()->AddChannel(0); | 239 GetRenderer()->AddChannel(0); |
264 EXPECT_TRUE(track_1->enabled()); | 240 EXPECT_TRUE(track_1->enabled()); |
265 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( | 241 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( |
266 new MockWebRtcAudioCapturerSink()); | 242 new MockWebRtcAudioCapturerSink()); |
267 const media::AudioParameters params = capturer_->audio_parameters(); | 243 const media::AudioParameters params = capturer_->audio_parameters(); |
268 base::WaitableEvent event_1(false, false); | 244 base::WaitableEvent event_1(false, false); |
269 EXPECT_CALL(*sink_1, SetCaptureFormat(_)).WillOnce(Return()); | 245 EXPECT_CALL(*sink_1, SetCaptureFormat(_)).WillOnce(Return()); |
270 EXPECT_CALL(*sink_1, | 246 EXPECT_CALL(*sink_1, CaptureData( |
271 CaptureData(1, | 247 1, params.sample_rate(), params.channels(), |
272 params.sample_rate(), | 248 params.frames_per_buffer(), 0, 0, false)) |
273 params.channels(), | 249 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event_1)); |
274 params.frames_per_buffer(), | |
275 0, | |
276 0, | |
277 false, | |
278 false)).Times(AtLeast(1)) | |
279 .WillRepeatedly(SignalEvent(&event_1)); | |
280 track_1->AddSink(sink_1.get()); | 250 track_1->AddSink(sink_1.get()); |
281 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 251 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
282 | 252 |
283 scoped_refptr<WebRtcLocalAudioTrack> track_2 = | 253 scoped_refptr<WebRtcLocalAudioTrack> track_2 = |
284 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); | 254 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); |
285 track_2->Start(); | 255 track_2->Start(); |
286 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> | 256 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> |
287 GetRenderer()->AddChannel(1); | 257 GetRenderer()->AddChannel(1); |
288 EXPECT_TRUE(track_2->enabled()); | 258 EXPECT_TRUE(track_2->enabled()); |
289 | 259 |
290 // Verify both |sink_1| and |sink_2| get data. | 260 // Verify both |sink_1| and |sink_2| get data. |
291 event_1.Reset(); | 261 event_1.Reset(); |
292 base::WaitableEvent event_2(false, false); | 262 base::WaitableEvent event_2(false, false); |
293 | 263 |
294 scoped_ptr<MockWebRtcAudioCapturerSink> sink_2( | 264 scoped_ptr<MockWebRtcAudioCapturerSink> sink_2( |
295 new MockWebRtcAudioCapturerSink()); | 265 new MockWebRtcAudioCapturerSink()); |
296 EXPECT_CALL(*sink_2, SetCaptureFormat(_)).WillOnce(Return()); | 266 EXPECT_CALL(*sink_2, SetCaptureFormat(_)).WillOnce(Return()); |
297 EXPECT_CALL(*sink_1, | 267 EXPECT_CALL(*sink_1, CaptureData( |
298 CaptureData(1, | 268 1, params.sample_rate(), params.channels(), |
299 params.sample_rate(), | 269 params.frames_per_buffer(), 0, 0, false)) |
300 params.channels(), | 270 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event_1)); |
301 params.frames_per_buffer(), | 271 EXPECT_CALL(*sink_2, CaptureData( |
302 0, | 272 1, params.sample_rate(), params.channels(), |
303 0, | 273 params.frames_per_buffer(), 0, 0, false)) |
304 false, | 274 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event_2)); |
305 false)).Times(AtLeast(1)) | |
306 .WillRepeatedly(SignalEvent(&event_1)); | |
307 EXPECT_CALL(*sink_2, | |
308 CaptureData(1, | |
309 params.sample_rate(), | |
310 params.channels(), | |
311 params.frames_per_buffer(), | |
312 0, | |
313 0, | |
314 false, | |
315 false)).Times(AtLeast(1)) | |
316 .WillRepeatedly(SignalEvent(&event_2)); | |
317 track_2->AddSink(sink_2.get()); | 275 track_2->AddSink(sink_2.get()); |
318 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); | 276 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); |
319 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); | 277 EXPECT_TRUE(event_2.TimedWait(TestTimeouts::tiny_timeout())); |
320 | 278 |
321 track_1->RemoveSink(sink_1.get()); | 279 track_1->RemoveSink(sink_1.get()); |
322 track_1->Stop(); | 280 track_1->Stop(); |
323 track_1 = NULL; | 281 track_1 = NULL; |
324 | 282 |
325 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); | 283 EXPECT_CALL(*capturer_source_.get(), Stop()).WillOnce(Return()); |
326 track_2->RemoveSink(sink_2.get()); | 284 track_2->RemoveSink(sink_2.get()); |
(...skipping 27 matching lines...) Expand all Loading... |
354 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); | 312 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); |
355 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> | 313 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> |
356 GetRenderer()->AddChannel(0); | 314 GetRenderer()->AddChannel(0); |
357 track_1->Start(); | 315 track_1->Start(); |
358 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 316 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
359 | 317 |
360 // Verify the data flow by connecting the sink to |track_1|. | 318 // Verify the data flow by connecting the sink to |track_1|. |
361 scoped_ptr<MockWebRtcAudioCapturerSink> sink( | 319 scoped_ptr<MockWebRtcAudioCapturerSink> sink( |
362 new MockWebRtcAudioCapturerSink()); | 320 new MockWebRtcAudioCapturerSink()); |
363 event.Reset(); | 321 event.Reset(); |
364 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, false, false)) | 322 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, false)) |
365 .Times(AnyNumber()).WillRepeatedly(Return()); | 323 .Times(AnyNumber()).WillRepeatedly(Return()); |
366 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1); | 324 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1); |
367 track_1->AddSink(sink.get()); | 325 track_1->AddSink(sink.get()); |
368 | 326 |
369 // Start the second audio track will not start the |capturer_source_| | 327 // Start the second audio track will not start the |capturer_source_| |
370 // since it has been started. | 328 // since it has been started. |
371 EXPECT_CALL(*capturer_source_.get(), Start()).Times(0); | 329 EXPECT_CALL(*capturer_source_.get(), Start()).Times(0); |
372 scoped_refptr<WebRtcLocalAudioTrack> track_2 = | 330 scoped_refptr<WebRtcLocalAudioTrack> track_2 = |
373 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); | 331 WebRtcLocalAudioTrack::Create(std::string(), capturer_, NULL); |
374 track_2->Start(); | 332 track_2->Start(); |
375 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> | 333 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> |
376 GetRenderer()->AddChannel(1); | 334 GetRenderer()->AddChannel(1); |
377 | 335 |
378 // Stop the first audio track will not stop the |capturer_source_|. | 336 // Stop the first audio track will not stop the |capturer_source_|. |
379 EXPECT_CALL(*capturer_source_.get(), Stop()).Times(0); | 337 EXPECT_CALL(*capturer_source_.get(), Stop()).Times(0); |
380 track_1->RemoveSink(sink.get()); | 338 track_1->RemoveSink(sink.get()); |
381 track_1->Stop(); | 339 track_1->Stop(); |
382 track_1 = NULL; | 340 track_1 = NULL; |
383 | 341 |
384 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, false, false)) | 342 EXPECT_CALL(*sink, CaptureData(_, _, _, _, 0, 0, false)) |
385 .Times(AnyNumber()).WillRepeatedly(Return()); | 343 .Times(AnyNumber()).WillRepeatedly(Return()); |
386 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1); | 344 EXPECT_CALL(*sink, SetCaptureFormat(_)).Times(1); |
387 track_2->AddSink(sink.get()); | 345 track_2->AddSink(sink.get()); |
388 | 346 |
389 // Stop the last audio track will stop the |capturer_source_|. | 347 // Stop the last audio track will stop the |capturer_source_|. |
390 event.Reset(); | 348 event.Reset(); |
391 EXPECT_CALL(*capturer_source_.get(), Stop()) | 349 EXPECT_CALL(*capturer_source_.get(), Stop()) |
392 .Times(1).WillOnce(SignalEvent(&event)); | 350 .Times(1).WillOnce(SignalEvent(&event)); |
393 track_2->Stop(); | 351 track_2->Stop(); |
394 track_2->RemoveSink(sink.get()); | 352 track_2->RemoveSink(sink.get()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 | 389 |
432 // Connect a number of network channels to the |track_1|. | 390 // Connect a number of network channels to the |track_1|. |
433 static const int kNumberOfNetworkChannelsForTrack1 = 2; | 391 static const int kNumberOfNetworkChannelsForTrack1 = 2; |
434 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) { | 392 for (int i = 0; i < kNumberOfNetworkChannelsForTrack1; ++i) { |
435 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> | 393 static_cast<webrtc::AudioTrackInterface*>(track_1.get())-> |
436 GetRenderer()->AddChannel(i); | 394 GetRenderer()->AddChannel(i); |
437 } | 395 } |
438 // Verify the data flow by connecting the |sink_1| to |track_1|. | 396 // Verify the data flow by connecting the |sink_1| to |track_1|. |
439 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( | 397 scoped_ptr<MockWebRtcAudioCapturerSink> sink_1( |
440 new MockWebRtcAudioCapturerSink()); | 398 new MockWebRtcAudioCapturerSink()); |
441 EXPECT_CALL( | 399 EXPECT_CALL(*sink_1.get(), CaptureData(kNumberOfNetworkChannelsForTrack1, |
442 *sink_1.get(), | 400 48000, 2, _, 0, 0, false)) |
443 CaptureData( | |
444 kNumberOfNetworkChannelsForTrack1, 48000, 2, _, 0, 0, false, false)) | |
445 .Times(AnyNumber()).WillRepeatedly(Return()); | 401 .Times(AnyNumber()).WillRepeatedly(Return()); |
446 EXPECT_CALL(*sink_1.get(), SetCaptureFormat(_)).Times(1); | 402 EXPECT_CALL(*sink_1.get(), SetCaptureFormat(_)).Times(1); |
447 track_1->AddSink(sink_1.get()); | 403 track_1->AddSink(sink_1.get()); |
448 | 404 |
449 // Create a new capturer with new source with different audio format. | 405 // Create a new capturer with new source with different audio format. |
450 scoped_refptr<WebRtcAudioCapturer> new_capturer( | 406 scoped_refptr<WebRtcAudioCapturer> new_capturer( |
451 WebRtcAudioCapturer::CreateCapturer()); | 407 WebRtcAudioCapturer::CreateCapturer()); |
452 scoped_refptr<MockCapturerSource> new_source(new MockCapturerSource()); | 408 scoped_refptr<MockCapturerSource> new_source(new MockCapturerSource()); |
453 EXPECT_CALL(*new_source.get(), Initialize(_, new_capturer.get(), 0)) | 409 EXPECT_CALL(*new_source.get(), Initialize(_, new_capturer.get(), 0)) |
454 .WillOnce(Return()); | 410 .WillOnce(Return()); |
(...skipping 15 matching lines...) Expand all Loading... |
470 | 426 |
471 // Connect a number of network channels to the |track_2|. | 427 // Connect a number of network channels to the |track_2|. |
472 static const int kNumberOfNetworkChannelsForTrack2 = 3; | 428 static const int kNumberOfNetworkChannelsForTrack2 = 3; |
473 for (int i = 0; i < kNumberOfNetworkChannelsForTrack2; ++i) { | 429 for (int i = 0; i < kNumberOfNetworkChannelsForTrack2; ++i) { |
474 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> | 430 static_cast<webrtc::AudioTrackInterface*>(track_2.get())-> |
475 GetRenderer()->AddChannel(i); | 431 GetRenderer()->AddChannel(i); |
476 } | 432 } |
477 // Verify the data flow by connecting the |sink_2| to |track_2|. | 433 // Verify the data flow by connecting the |sink_2| to |track_2|. |
478 scoped_ptr<MockWebRtcAudioCapturerSink> sink_2( | 434 scoped_ptr<MockWebRtcAudioCapturerSink> sink_2( |
479 new MockWebRtcAudioCapturerSink()); | 435 new MockWebRtcAudioCapturerSink()); |
480 EXPECT_CALL( | 436 EXPECT_CALL(*sink_2, CaptureData(kNumberOfNetworkChannelsForTrack2, |
481 *sink_2, | 437 44100, 1, _, 0, 0, false)) |
482 CaptureData( | |
483 kNumberOfNetworkChannelsForTrack2, 44100, 1, _, 0, 0, false, false)) | |
484 .Times(AnyNumber()).WillRepeatedly(Return()); | 438 .Times(AnyNumber()).WillRepeatedly(Return()); |
485 EXPECT_CALL(*sink_2, SetCaptureFormat(_)).Times(1); | 439 EXPECT_CALL(*sink_2, SetCaptureFormat(_)).Times(1); |
486 track_2->AddSink(sink_2.get()); | 440 track_2->AddSink(sink_2.get()); |
487 | 441 |
488 // Stop the second audio track will stop the new source. | 442 // Stop the second audio track will stop the new source. |
489 base::WaitableEvent event(false, false); | 443 base::WaitableEvent event(false, false); |
490 EXPECT_CALL(*new_source.get(), Stop()).Times(1).WillOnce(SignalEvent(&event)); | 444 EXPECT_CALL(*new_source.get(), Stop()).Times(1).WillOnce(SignalEvent(&event)); |
491 track_2->Stop(); | 445 track_2->Stop(); |
492 track_2->RemoveSink(sink_2.get()); | 446 track_2->RemoveSink(sink_2.get()); |
493 track_2 = NULL; | 447 track_2 = NULL; |
494 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); | 448 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); |
495 audio_thread->Stop(); | 449 audio_thread->Stop(); |
496 audio_thread.reset(); | 450 audio_thread.reset(); |
497 | 451 |
498 // Stop the first audio track. | 452 // Stop the first audio track. |
499 EXPECT_CALL(*capturer_source_.get(), Stop()); | 453 EXPECT_CALL(*capturer_source_.get(), Stop()); |
500 track_1->Stop(); | 454 track_1->Stop(); |
501 track_1 = NULL; | 455 track_1 = NULL; |
502 } | 456 } |
503 | 457 |
504 } // namespace content | 458 } // namespace content |
OLD | NEW |