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