Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(479)

Side by Side Diff: content/renderer/media/webrtc_local_audio_track_unittest.cc

Issue 1780653002: Revert of MediaStream audio object graph untangling and clean-ups. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/macros.h" 5 #include "base/macros.h"
6 #include "base/synchronization/waitable_event.h" 6 #include "base/synchronization/waitable_event.h"
7 #include "base/test/test_timeouts.h" 7 #include "base/test/test_timeouts.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "content/public/renderer/media_stream_audio_sink.h" 9 #include "content/public/renderer/media_stream_audio_sink.h"
10 #include "content/renderer/media/media_stream_audio_source.h" 10 #include "content/renderer/media/media_stream_audio_source.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 class MockCapturerSource : public media::AudioCapturerSource { 89 class MockCapturerSource : public media::AudioCapturerSource {
90 public: 90 public:
91 explicit MockCapturerSource(WebRtcAudioCapturer* capturer) 91 explicit MockCapturerSource(WebRtcAudioCapturer* capturer)
92 : capturer_(capturer) {} 92 : capturer_(capturer) {}
93 MOCK_METHOD3(OnInitialize, void(const media::AudioParameters& params, 93 MOCK_METHOD3(OnInitialize, void(const media::AudioParameters& params,
94 CaptureCallback* callback, 94 CaptureCallback* callback,
95 int session_id)); 95 int session_id));
96 MOCK_METHOD0(OnStart, void()); 96 MOCK_METHOD0(OnStart, void());
97 MOCK_METHOD0(OnStop, void()); 97 MOCK_METHOD0(OnStop, void());
98 void SetVolume(double volume) final {} 98 MOCK_METHOD1(SetVolume, void(double volume));
99 MOCK_METHOD1(SetAutomaticGainControl, void(bool enable)); 99 MOCK_METHOD1(SetAutomaticGainControl, void(bool enable));
100 100
101 void Initialize(const media::AudioParameters& params, 101 void Initialize(const media::AudioParameters& params,
102 CaptureCallback* callback, 102 CaptureCallback* callback,
103 int session_id) override { 103 int session_id) override {
104 DCHECK(params.IsValid()); 104 DCHECK(params.IsValid());
105 params_ = params; 105 params_ = params;
106 OnInitialize(params, callback, session_id); 106 OnInitialize(params, callback, session_id);
107 } 107 }
108 void Start() override { 108 void Start() override {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 480); 158 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 480);
159 MockConstraintFactory constraint_factory; 159 MockConstraintFactory constraint_factory;
160 blink_source_.initialize("dummy", blink::WebMediaStreamSource::TypeAudio, 160 blink_source_.initialize("dummy", blink::WebMediaStreamSource::TypeAudio,
161 "dummy", 161 "dummy",
162 false /* remote */, true /* readonly */); 162 false /* remote */, true /* readonly */);
163 MediaStreamAudioSource* audio_source = new MediaStreamAudioSource(); 163 MediaStreamAudioSource* audio_source = new MediaStreamAudioSource();
164 blink_source_.setExtraData(audio_source); 164 blink_source_.setExtraData(audio_source);
165 165
166 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE, 166 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE,
167 std::string(), std::string()); 167 std::string(), std::string());
168 { 168 capturer_ = WebRtcAudioCapturer::CreateCapturer(
169 scoped_ptr<WebRtcAudioCapturer> capturer = 169 -1, device, constraint_factory.CreateWebMediaConstraints(), NULL,
170 WebRtcAudioCapturer::CreateCapturer( 170 audio_source);
171 -1, device, constraint_factory.CreateWebMediaConstraints(), 171 audio_source->SetAudioCapturer(capturer_.get());
172 nullptr, audio_source); 172 capturer_source_ = new MockCapturerSource(capturer_.get());
173 capturer_ = capturer.get(); 173 EXPECT_CALL(*capturer_source_.get(), OnInitialize(_, capturer_.get(), -1))
174 audio_source->SetAudioCapturer(std::move(capturer));
175 }
176 capturer_source_ = new MockCapturerSource(capturer_);
177 EXPECT_CALL(*capturer_source_.get(), OnInitialize(_, capturer_, -1))
178 .WillOnce(Return()); 174 .WillOnce(Return());
179 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); 175 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
180 EXPECT_CALL(*capturer_source_.get(), OnStart()); 176 EXPECT_CALL(*capturer_source_.get(), OnStart());
181 capturer_->SetCapturerSource(capturer_source_, params_); 177 capturer_->SetCapturerSource(capturer_source_, params_);
182 } 178 }
183 179
184 void TearDown() override { 180 void TearDown() override {
185 blink_source_.reset(); 181 blink_source_.reset();
186 blink::WebHeap::collectAllGarbageForTesting(); 182 blink::WebHeap::collectAllGarbageForTesting();
187 } 183 }
188 184
189 media::AudioParameters params_; 185 media::AudioParameters params_;
190 blink::WebMediaStreamSource blink_source_; 186 blink::WebMediaStreamSource blink_source_;
191 WebRtcAudioCapturer* capturer_; // Owned by |blink_source_|.
192 scoped_refptr<MockCapturerSource> capturer_source_; 187 scoped_refptr<MockCapturerSource> capturer_source_;
188 scoped_refptr<WebRtcAudioCapturer> capturer_;
193 }; 189 };
194 190
195 // Creates a capturer and audio track, fakes its audio thread, and 191 // Creates a capturer and audio track, fakes its audio thread, and
196 // connect/disconnect the sink to the audio track on the fly, the sink should 192 // connect/disconnect the sink to the audio track on the fly, the sink should
197 // get data callback when the track is connected to the capturer but not when 193 // get data callback when the track is connected to the capturer but not when
198 // the track is disconnected from the capturer. 194 // the track is disconnected from the capturer.
199 TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) { 195 TEST_F(WebRtcLocalAudioTrackTest, ConnectAndDisconnectOneSink) {
200 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( 196 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
201 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 197 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
202 scoped_ptr<WebRtcLocalAudioTrack> track( 198 scoped_ptr<WebRtcLocalAudioTrack> track(
203 new WebRtcLocalAudioTrack(adapter.get())); 199 new WebRtcLocalAudioTrack(adapter.get(), capturer_, NULL));
204 track->Start( 200 track->Start();
205 base::Bind(&MediaStreamAudioSource::StopAudioDeliveryTo,
206 MediaStreamAudioSource::From(blink_source_)->GetWeakPtr(),
207 track.get()));
208 capturer_->AddTrack(track.get());
209 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); 201 EXPECT_TRUE(track->GetAudioAdapter()->enabled());
210 202
211 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); 203 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink());
212 base::WaitableEvent event(false, false); 204 base::WaitableEvent event(false, false);
213 EXPECT_CALL(*sink, FormatIsSet()); 205 EXPECT_CALL(*sink, FormatIsSet());
214 EXPECT_CALL(*sink, 206 EXPECT_CALL(*sink,
215 CaptureData()).Times(AtLeast(1)) 207 CaptureData()).Times(AtLeast(1))
216 .WillRepeatedly(SignalEvent(&event)); 208 .WillRepeatedly(SignalEvent(&event));
217 track->AddSink(sink.get()); 209 track->AddSink(sink.get());
218 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); 210 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout()));
219 track->RemoveSink(sink.get()); 211 track->RemoveSink(sink.get());
220 212
221 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); 213 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return());
222 capturer_->Stop(); 214 capturer_->Stop();
223 } 215 }
224 216
225 // The same setup as ConnectAndDisconnectOneSink, but enable and disable the 217 // The same setup as ConnectAndDisconnectOneSink, but enable and disable the
226 // audio track on the fly. When the audio track is disabled, there is no data 218 // audio track on the fly. When the audio track is disabled, there is no data
227 // callback to the sink; when the audio track is enabled, there comes data 219 // callback to the sink; when the audio track is enabled, there comes data
228 // callback. 220 // callback.
229 // TODO(xians): Enable this test after resolving the racing issue that TSAN 221 // TODO(xians): Enable this test after resolving the racing issue that TSAN
230 // reports on MediaStreamTrack::enabled(); 222 // reports on MediaStreamTrack::enabled();
231 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) { 223 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_DisableEnableAudioTrack) {
232 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); 224 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
233 EXPECT_CALL(*capturer_source_.get(), OnStart()); 225 EXPECT_CALL(*capturer_source_.get(), OnStart());
234 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( 226 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
235 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 227 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
236 scoped_ptr<WebRtcLocalAudioTrack> track( 228 scoped_ptr<WebRtcLocalAudioTrack> track(
237 new WebRtcLocalAudioTrack(adapter.get())); 229 new WebRtcLocalAudioTrack(adapter.get(), capturer_, NULL));
238 track->Start( 230 track->Start();
239 base::Bind(&MediaStreamAudioSource::StopAudioDeliveryTo,
240 MediaStreamAudioSource::From(blink_source_)->GetWeakPtr(),
241 track.get()));
242 capturer_->AddTrack(track.get());
243 EXPECT_TRUE(track->GetAudioAdapter()->enabled()); 231 EXPECT_TRUE(track->GetAudioAdapter()->enabled());
244 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(false)); 232 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(false));
245 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); 233 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink());
246 const media::AudioParameters params = capturer_->GetInputFormat(); 234 const media::AudioParameters params = capturer_->source_audio_parameters();
247 base::WaitableEvent event(false, false); 235 base::WaitableEvent event(false, false);
248 EXPECT_CALL(*sink, FormatIsSet()).Times(1); 236 EXPECT_CALL(*sink, FormatIsSet()).Times(1);
249 EXPECT_CALL(*sink, CaptureData()).Times(0); 237 EXPECT_CALL(*sink, CaptureData()).Times(0);
250 EXPECT_EQ(sink->audio_params().frames_per_buffer(), 238 EXPECT_EQ(sink->audio_params().frames_per_buffer(),
251 params.sample_rate() / 100); 239 params.sample_rate() / 100);
252 track->AddSink(sink.get()); 240 track->AddSink(sink.get());
253 EXPECT_FALSE(event.TimedWait(TestTimeouts::tiny_timeout())); 241 EXPECT_FALSE(event.TimedWait(TestTimeouts::tiny_timeout()));
254 242
255 event.Reset(); 243 event.Reset();
256 EXPECT_CALL(*sink, CaptureData()).Times(AtLeast(1)) 244 EXPECT_CALL(*sink, CaptureData()).Times(AtLeast(1))
257 .WillRepeatedly(SignalEvent(&event)); 245 .WillRepeatedly(SignalEvent(&event));
258 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(true)); 246 EXPECT_TRUE(track->GetAudioAdapter()->set_enabled(true));
259 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); 247 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout()));
260 track->RemoveSink(sink.get()); 248 track->RemoveSink(sink.get());
261 249
262 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return()); 250 EXPECT_CALL(*capturer_source_.get(), OnStop()).WillOnce(Return());
263 capturer_->Stop(); 251 capturer_->Stop();
264 track.reset(); 252 track.reset();
265 } 253 }
266 254
267 // 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
268 // callbacks appear/disappear. 256 // callbacks appear/disappear.
269 // Flaky due to a data race, see http://crbug.com/295418 257 // Flaky due to a data race, see http://crbug.com/295418
270 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) { 258 TEST_F(WebRtcLocalAudioTrackTest, DISABLED_MultipleAudioTracks) {
271 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( 259 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1(
272 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 260 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
273 scoped_ptr<WebRtcLocalAudioTrack> track_1( 261 scoped_ptr<WebRtcLocalAudioTrack> track_1(
274 new WebRtcLocalAudioTrack(adapter_1.get())); 262 new WebRtcLocalAudioTrack(adapter_1.get(), capturer_, NULL));
275 track_1->Start( 263 track_1->Start();
276 base::Bind(&MediaStreamAudioSource::StopAudioDeliveryTo,
277 MediaStreamAudioSource::From(blink_source_)->GetWeakPtr(),
278 track_1.get()));
279 capturer_->AddTrack(track_1.get());
280 EXPECT_TRUE(track_1->GetAudioAdapter()->enabled()); 264 EXPECT_TRUE(track_1->GetAudioAdapter()->enabled());
281 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); 265 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink());
282 const media::AudioParameters params = capturer_->GetInputFormat(); 266 const media::AudioParameters params = capturer_->source_audio_parameters();
283 base::WaitableEvent event_1(false, false); 267 base::WaitableEvent event_1(false, false);
284 EXPECT_CALL(*sink_1, FormatIsSet()).WillOnce(Return()); 268 EXPECT_CALL(*sink_1, FormatIsSet()).WillOnce(Return());
285 EXPECT_CALL(*sink_1, CaptureData()).Times(AtLeast(1)) 269 EXPECT_CALL(*sink_1, CaptureData()).Times(AtLeast(1))
286 .WillRepeatedly(SignalEvent(&event_1)); 270 .WillRepeatedly(SignalEvent(&event_1));
287 EXPECT_EQ(sink_1->audio_params().frames_per_buffer(), 271 EXPECT_EQ(sink_1->audio_params().frames_per_buffer(),
288 params.sample_rate() / 100); 272 params.sample_rate() / 100);
289 track_1->AddSink(sink_1.get()); 273 track_1->AddSink(sink_1.get());
290 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout())); 274 EXPECT_TRUE(event_1.TimedWait(TestTimeouts::tiny_timeout()));
291 275
292 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( 276 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2(
293 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 277 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
294 scoped_ptr<WebRtcLocalAudioTrack> track_2( 278 scoped_ptr<WebRtcLocalAudioTrack> track_2(
295 new WebRtcLocalAudioTrack(adapter_2.get())); 279 new WebRtcLocalAudioTrack(adapter_2.get(), capturer_, NULL));
296 track_2->Start( 280 track_2->Start();
297 base::Bind(&MediaStreamAudioSource::StopAudioDeliveryTo,
298 MediaStreamAudioSource::From(blink_source_)->GetWeakPtr(),
299 track_2.get()));
300 capturer_->AddTrack(track_2.get());
301 EXPECT_TRUE(track_2->GetAudioAdapter()->enabled()); 281 EXPECT_TRUE(track_2->GetAudioAdapter()->enabled());
302 282
303 // Verify both |sink_1| and |sink_2| get data. 283 // Verify both |sink_1| and |sink_2| get data.
304 event_1.Reset(); 284 event_1.Reset();
305 base::WaitableEvent event_2(false, false); 285 base::WaitableEvent event_2(false, false);
306 286
307 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); 287 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink());
308 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(Return()); 288 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(Return());
309 EXPECT_CALL(*sink_1, CaptureData()).Times(AtLeast(1)) 289 EXPECT_CALL(*sink_1, CaptureData()).Times(AtLeast(1))
310 .WillRepeatedly(SignalEvent(&event_1)); 290 .WillRepeatedly(SignalEvent(&event_1));
(...skipping 17 matching lines...) Expand all
328 track_2.reset(); 308 track_2.reset();
329 } 309 }
330 310
331 311
332 // Start one track and verify the capturer is correctly starting its source. 312 // Start one track and verify the capturer is correctly starting its source.
333 // And it should be fine to not to call Stop() explicitly. 313 // And it should be fine to not to call Stop() explicitly.
334 TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) { 314 TEST_F(WebRtcLocalAudioTrackTest, StartOneAudioTrack) {
335 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( 315 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
336 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 316 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
337 scoped_ptr<WebRtcLocalAudioTrack> track( 317 scoped_ptr<WebRtcLocalAudioTrack> track(
338 new WebRtcLocalAudioTrack(adapter.get())); 318 new WebRtcLocalAudioTrack(adapter.get(), capturer_, NULL));
339 track->Start( 319 track->Start();
340 base::Bind(&MediaStreamAudioSource::StopAudioDeliveryTo,
341 MediaStreamAudioSource::From(blink_source_)->GetWeakPtr(),
342 track.get()));
343 capturer_->AddTrack(track.get());
344 320
345 // When the track goes away, it will automatically stop the 321 // When the track goes away, it will automatically stop the
346 // |capturer_source_|. 322 // |capturer_source_|.
347 EXPECT_CALL(*capturer_source_.get(), OnStop()); 323 EXPECT_CALL(*capturer_source_.get(), OnStop());
348 track.reset(); 324 track.reset();
349 } 325 }
350 326
351 // Start two tracks and verify the capturer is correctly starting its source. 327 // Start two tracks and verify the capturer is correctly starting its source.
352 // When the last track connected to the capturer is stopped, the source is 328 // When the last track connected to the capturer is stopped, the source is
353 // stopped. 329 // stopped.
354 TEST_F(WebRtcLocalAudioTrackTest, StartTwoAudioTracks) { 330 TEST_F(WebRtcLocalAudioTrackTest, StartTwoAudioTracks) {
355 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter1( 331 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter1(
356 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 332 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
357 scoped_ptr<WebRtcLocalAudioTrack> track1( 333 scoped_ptr<WebRtcLocalAudioTrack> track1(
358 new WebRtcLocalAudioTrack(adapter1.get())); 334 new WebRtcLocalAudioTrack(adapter1.get(), capturer_, NULL));
359 track1->Start( 335 track1->Start();
360 base::Bind(&MediaStreamAudioSource::StopAudioDeliveryTo,
361 MediaStreamAudioSource::From(blink_source_)->GetWeakPtr(),
362 track1.get()));
363 capturer_->AddTrack(track1.get());
364 336
365 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter2( 337 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter2(
366 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 338 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
367 scoped_ptr<WebRtcLocalAudioTrack> track2( 339 scoped_ptr<WebRtcLocalAudioTrack> track2(
368 new WebRtcLocalAudioTrack(adapter2.get())); 340 new WebRtcLocalAudioTrack(adapter2.get(), capturer_, NULL));
369 track2->Start( 341 track2->Start();
370 base::Bind(&MediaStreamAudioSource::StopAudioDeliveryTo,
371 MediaStreamAudioSource::From(blink_source_)->GetWeakPtr(),
372 track2.get()));
373 capturer_->AddTrack(track2.get());
374 342
375 track1->Stop(); 343 track1->Stop();
376 // When the last track is stopped, it will automatically stop the 344 // When the last track is stopped, it will automatically stop the
377 // |capturer_source_|. 345 // |capturer_source_|.
378 EXPECT_CALL(*capturer_source_.get(), OnStop()); 346 EXPECT_CALL(*capturer_source_.get(), OnStop());
379 track2->Stop(); 347 track2->Stop();
380 } 348 }
381 349
382 // Start/Stop tracks and verify the capturer is correctly starting/stopping 350 // Start/Stop tracks and verify the capturer is correctly starting/stopping
383 // its source. 351 // its source.
384 TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) { 352 TEST_F(WebRtcLocalAudioTrackTest, StartAndStopAudioTracks) {
385 base::WaitableEvent event(false, false); 353 base::WaitableEvent event(false, false);
386 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( 354 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1(
387 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 355 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
388 scoped_ptr<WebRtcLocalAudioTrack> track_1( 356 scoped_ptr<WebRtcLocalAudioTrack> track_1(
389 new WebRtcLocalAudioTrack(adapter_1.get())); 357 new WebRtcLocalAudioTrack(adapter_1.get(), capturer_, NULL));
390 track_1->Start( 358 track_1->Start();
391 base::Bind(&MediaStreamAudioSource::StopAudioDeliveryTo,
392 MediaStreamAudioSource::From(blink_source_)->GetWeakPtr(),
393 track_1.get()));
394 capturer_->AddTrack(track_1.get());
395 359
396 // Verify the data flow by connecting the sink to |track_1|. 360 // Verify the data flow by connecting the sink to |track_1|.
397 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); 361 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink());
398 event.Reset(); 362 event.Reset();
399 EXPECT_CALL(*sink, FormatIsSet()).WillOnce(SignalEvent(&event)); 363 EXPECT_CALL(*sink, FormatIsSet()).WillOnce(SignalEvent(&event));
400 EXPECT_CALL(*sink, CaptureData()) 364 EXPECT_CALL(*sink, CaptureData())
401 .Times(AnyNumber()).WillRepeatedly(Return()); 365 .Times(AnyNumber()).WillRepeatedly(Return());
402 track_1->AddSink(sink.get()); 366 track_1->AddSink(sink.get());
403 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); 367 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout()));
404 368
405 // Start the second audio track will not start the |capturer_source_| 369 // Start the second audio track will not start the |capturer_source_|
406 // since it has been started. 370 // since it has been started.
407 EXPECT_CALL(*capturer_source_.get(), OnStart()).Times(0); 371 EXPECT_CALL(*capturer_source_.get(), OnStart()).Times(0);
408 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( 372 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2(
409 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 373 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
410 scoped_ptr<WebRtcLocalAudioTrack> track_2( 374 scoped_ptr<WebRtcLocalAudioTrack> track_2(
411 new WebRtcLocalAudioTrack(adapter_2.get())); 375 new WebRtcLocalAudioTrack(adapter_2.get(), capturer_, NULL));
412 track_2->Start( 376 track_2->Start();
413 base::Bind(&MediaStreamAudioSource::StopAudioDeliveryTo,
414 MediaStreamAudioSource::From(blink_source_)->GetWeakPtr(),
415 track_2.get()));
416 capturer_->AddTrack(track_2.get());
417 377
418 // Stop the capturer will clear up the track lists in the capturer. 378 // Stop the capturer will clear up the track lists in the capturer.
419 EXPECT_CALL(*capturer_source_.get(), OnStop()); 379 EXPECT_CALL(*capturer_source_.get(), OnStop());
420 capturer_->Stop(); 380 capturer_->Stop();
421 381
422 // Adding a new track to the capturer. 382 // Adding a new track to the capturer.
423 track_2->AddSink(sink.get()); 383 track_2->AddSink(sink.get());
424 EXPECT_CALL(*sink, FormatIsSet()).Times(0); 384 EXPECT_CALL(*sink, FormatIsSet()).Times(0);
425 385
426 // Stop the capturer again will not trigger stopping the source of the 386 // Stop the capturer again will not trigger stopping the source of the
(...skipping 10 matching lines...) Expand all
437 DISABLED_ConnectTracksToDifferentCapturers 397 DISABLED_ConnectTracksToDifferentCapturers
438 #else 398 #else
439 #define MAYBE_ConnectTracksToDifferentCapturers \ 399 #define MAYBE_ConnectTracksToDifferentCapturers \
440 ConnectTracksToDifferentCapturers 400 ConnectTracksToDifferentCapturers
441 #endif 401 #endif
442 TEST_F(WebRtcLocalAudioTrackTest, MAYBE_ConnectTracksToDifferentCapturers) { 402 TEST_F(WebRtcLocalAudioTrackTest, MAYBE_ConnectTracksToDifferentCapturers) {
443 // Setup the first audio track and start it. 403 // Setup the first audio track and start it.
444 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1( 404 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_1(
445 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 405 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
446 scoped_ptr<WebRtcLocalAudioTrack> track_1( 406 scoped_ptr<WebRtcLocalAudioTrack> track_1(
447 new WebRtcLocalAudioTrack(adapter_1.get())); 407 new WebRtcLocalAudioTrack(adapter_1.get(), capturer_, NULL));
448 track_1->Start( 408 track_1->Start();
449 base::Bind(&MediaStreamAudioSource::StopAudioDeliveryTo,
450 MediaStreamAudioSource::From(blink_source_)->GetWeakPtr(),
451 track_1.get()));
452 capturer_->AddTrack(track_1.get());
453 409
454 // Verify the data flow by connecting the |sink_1| to |track_1|. 410 // Verify the data flow by connecting the |sink_1| to |track_1|.
455 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink()); 411 scoped_ptr<MockMediaStreamAudioSink> sink_1(new MockMediaStreamAudioSink());
456 EXPECT_CALL(*sink_1.get(), CaptureData()) 412 EXPECT_CALL(*sink_1.get(), CaptureData())
457 .Times(AnyNumber()).WillRepeatedly(Return()); 413 .Times(AnyNumber()).WillRepeatedly(Return());
458 EXPECT_CALL(*sink_1.get(), FormatIsSet()).Times(AnyNumber()); 414 EXPECT_CALL(*sink_1.get(), FormatIsSet()).Times(AnyNumber());
459 track_1->AddSink(sink_1.get()); 415 track_1->AddSink(sink_1.get());
460 416
461 // Create a new capturer with new source with different audio format. 417 // Create a new capturer with new source with different audio format.
462 MockConstraintFactory constraint_factory; 418 MockConstraintFactory constraint_factory;
463 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE, 419 StreamDeviceInfo device(MEDIA_DEVICE_AUDIO_CAPTURE,
464 std::string(), std::string()); 420 std::string(), std::string());
465 scoped_ptr<WebRtcAudioCapturer> new_capturer( 421 scoped_refptr<WebRtcAudioCapturer> new_capturer(
466 WebRtcAudioCapturer::CreateCapturer( 422 WebRtcAudioCapturer::CreateCapturer(
467 -1, device, constraint_factory.CreateWebMediaConstraints(), NULL, 423 -1, device, constraint_factory.CreateWebMediaConstraints(), NULL,
468 NULL)); 424 NULL));
469 scoped_refptr<MockCapturerSource> new_source( 425 scoped_refptr<MockCapturerSource> new_source(
470 new MockCapturerSource(new_capturer.get())); 426 new MockCapturerSource(new_capturer.get()));
471 EXPECT_CALL(*new_source.get(), OnInitialize(_, new_capturer.get(), -1)); 427 EXPECT_CALL(*new_source.get(), OnInitialize(_, new_capturer.get(), -1));
472 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true)); 428 EXPECT_CALL(*new_source.get(), SetAutomaticGainControl(true));
473 EXPECT_CALL(*new_source.get(), OnStart()); 429 EXPECT_CALL(*new_source.get(), OnStart());
474 430
475 media::AudioParameters new_param( 431 media::AudioParameters new_param(
476 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 432 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
477 media::CHANNEL_LAYOUT_MONO, 44100, 16, 441); 433 media::CHANNEL_LAYOUT_MONO, 44100, 16, 441);
478 new_capturer->SetCapturerSource(new_source, new_param); 434 new_capturer->SetCapturerSource(new_source, new_param);
479 435
480 // Setup the second audio track, connect it to the new capturer and start it. 436 // Setup the second audio track, connect it to the new capturer and start it.
481 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2( 437 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter_2(
482 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 438 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
483 scoped_ptr<WebRtcLocalAudioTrack> track_2( 439 scoped_ptr<WebRtcLocalAudioTrack> track_2(
484 new WebRtcLocalAudioTrack(adapter_2.get())); 440 new WebRtcLocalAudioTrack(adapter_2.get(), new_capturer, NULL));
485 track_2->Start( 441 track_2->Start();
486 base::Bind(&MediaStreamAudioSource::StopAudioDeliveryTo,
487 MediaStreamAudioSource::From(blink_source_)->GetWeakPtr(),
488 track_2.get()));
489 new_capturer->AddTrack(track_2.get());
490 442
491 // Verify the data flow by connecting the |sink_2| to |track_2|. 443 // Verify the data flow by connecting the |sink_2| to |track_2|.
492 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink()); 444 scoped_ptr<MockMediaStreamAudioSink> sink_2(new MockMediaStreamAudioSink());
493 base::WaitableEvent event(false, false); 445 base::WaitableEvent event(false, false);
494 EXPECT_CALL(*sink_2, CaptureData()) 446 EXPECT_CALL(*sink_2, CaptureData())
495 .Times(AnyNumber()).WillRepeatedly(Return()); 447 .Times(AnyNumber()).WillRepeatedly(Return());
496 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(SignalEvent(&event)); 448 EXPECT_CALL(*sink_2, FormatIsSet()).WillOnce(SignalEvent(&event));
497 track_2->AddSink(sink_2.get()); 449 track_2->AddSink(sink_2.get());
498 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); 450 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout()));
499 451
(...skipping 12 matching lines...) Expand all
512 // Make sure a audio track can deliver packets with a buffer size smaller than 464 // Make sure a audio track can deliver packets with a buffer size smaller than
513 // 10ms when it is not connected with a peer connection. 465 // 10ms when it is not connected with a peer connection.
514 TEST_F(WebRtcLocalAudioTrackTest, TrackWorkWithSmallBufferSize) { 466 TEST_F(WebRtcLocalAudioTrackTest, TrackWorkWithSmallBufferSize) {
515 // Setup a capturer which works with a buffer size smaller than 10ms. 467 // Setup a capturer which works with a buffer size smaller than 10ms.
516 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 468 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
517 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 128); 469 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 128);
518 470
519 // Create a capturer with new source which works with the format above. 471 // Create a capturer with new source which works with the format above.
520 MockConstraintFactory factory; 472 MockConstraintFactory factory;
521 factory.DisableDefaultAudioConstraints(); 473 factory.DisableDefaultAudioConstraints();
522 scoped_ptr<WebRtcAudioCapturer> capturer(WebRtcAudioCapturer::CreateCapturer( 474 scoped_refptr<WebRtcAudioCapturer> capturer(
523 -1, 475 WebRtcAudioCapturer::CreateCapturer(
524 StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "", "", params.sample_rate(), 476 -1, StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "", "",
525 params.channel_layout(), params.frames_per_buffer()), 477 params.sample_rate(), params.channel_layout(),
526 factory.CreateWebMediaConstraints(), NULL, NULL)); 478 params.frames_per_buffer()),
479 factory.CreateWebMediaConstraints(), NULL, NULL));
527 scoped_refptr<MockCapturerSource> source( 480 scoped_refptr<MockCapturerSource> source(
528 new MockCapturerSource(capturer.get())); 481 new MockCapturerSource(capturer.get()));
529 EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), -1)); 482 EXPECT_CALL(*source.get(), OnInitialize(_, capturer.get(), -1));
530 EXPECT_CALL(*source.get(), SetAutomaticGainControl(true)); 483 EXPECT_CALL(*source.get(), SetAutomaticGainControl(true));
531 EXPECT_CALL(*source.get(), OnStart()); 484 EXPECT_CALL(*source.get(), OnStart());
532 capturer->SetCapturerSource(source, params); 485 capturer->SetCapturerSource(source, params);
533 486
534 // Setup a audio track, connect it to the capturer and start it. 487 // Setup a audio track, connect it to the capturer and start it.
535 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( 488 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
536 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 489 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
537 scoped_ptr<WebRtcLocalAudioTrack> track( 490 scoped_ptr<WebRtcLocalAudioTrack> track(
538 new WebRtcLocalAudioTrack(adapter.get())); 491 new WebRtcLocalAudioTrack(adapter.get(), capturer, NULL));
539 track->Start( 492 track->Start();
540 base::Bind(&MediaStreamAudioSource::StopAudioDeliveryTo,
541 MediaStreamAudioSource::From(blink_source_)->GetWeakPtr(),
542 track.get()));
543 capturer->AddTrack(track.get());
544 493
545 // Verify the data flow by connecting the |sink| to |track|. 494 // Verify the data flow by connecting the |sink| to |track|.
546 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); 495 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink());
547 base::WaitableEvent event(false, false); 496 base::WaitableEvent event(false, false);
548 EXPECT_CALL(*sink, FormatIsSet()).Times(1); 497 EXPECT_CALL(*sink, FormatIsSet()).Times(1);
549 // Verify the sinks are getting the packets with an expecting buffer size. 498 // Verify the sinks are getting the packets with an expecting buffer size.
550 #if defined(OS_ANDROID) 499 #if defined(OS_ANDROID)
551 const int expected_buffer_size = params.sample_rate() / 100; 500 const int expected_buffer_size = params.sample_rate() / 100;
552 #else 501 #else
553 const int expected_buffer_size = params.frames_per_buffer(); 502 const int expected_buffer_size = params.frames_per_buffer();
554 #endif 503 #endif
555 EXPECT_CALL(*sink, CaptureData()) 504 EXPECT_CALL(*sink, CaptureData())
556 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event)); 505 .Times(AtLeast(1)).WillRepeatedly(SignalEvent(&event));
557 track->AddSink(sink.get()); 506 track->AddSink(sink.get());
558 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout())); 507 EXPECT_TRUE(event.TimedWait(TestTimeouts::tiny_timeout()));
559 EXPECT_EQ(expected_buffer_size, sink->audio_params().frames_per_buffer()); 508 EXPECT_EQ(expected_buffer_size, sink->audio_params().frames_per_buffer());
560 509
561 // Stopping the new source will stop the second track. 510 // Stopping the new source will stop the second track.
562 EXPECT_CALL(*source.get(), OnStop()).Times(1); 511 EXPECT_CALL(*source.get(), OnStop()).Times(1);
563 capturer->Stop(); 512 capturer->Stop();
564 513
565 // Even though this test don't use |capturer_source_| it will be stopped 514 // Even though this test don't use |capturer_source_| it will be stopped
566 // during teardown of the test harness. 515 // during teardown of the test harness.
567 EXPECT_CALL(*capturer_source_.get(), OnStop()); 516 EXPECT_CALL(*capturer_source_.get(), OnStop());
568 } 517 }
569 518
570 } // namespace content 519 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_local_audio_track.cc ('k') | content/renderer/renderer_blink_platform_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698