OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/media/user_media_client_impl.h" | 5 #include "content/renderer/media/user_media_client_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 static void SignalSourceReady( | 243 static void SignalSourceReady( |
244 const MediaStreamSource::ConstraintsCallback& source_ready, | 244 const MediaStreamSource::ConstraintsCallback& source_ready, |
245 MediaStreamSource* source) { | 245 MediaStreamSource* source) { |
246 source_ready.Run(source, MEDIA_DEVICE_OK, ""); | 246 source_ready.Run(source, MEDIA_DEVICE_OK, ""); |
247 } | 247 } |
248 | 248 |
249 MediaStreamAudioSource* CreateAudioSource( | 249 MediaStreamAudioSource* CreateAudioSource( |
250 const StreamDeviceInfo& device, | 250 const StreamDeviceInfo& device, |
251 const blink::WebMediaConstraints& constraints, | 251 const blink::WebMediaConstraints& constraints, |
252 const MediaStreamSource::ConstraintsCallback& source_ready) override { | 252 const MediaStreamSource::ConstraintsCallback& source_ready) override { |
| 253 MediaStreamAudioSource* source; |
253 if (create_source_that_fails_) { | 254 if (create_source_that_fails_) { |
254 class FailedAtLifeAudioSource : public MediaStreamAudioSource { | 255 class FailedAtLifeAudioSource : public MediaStreamAudioSource { |
255 public: | 256 public: |
256 FailedAtLifeAudioSource() : MediaStreamAudioSource(true) {} | 257 FailedAtLifeAudioSource() : MediaStreamAudioSource(true) {} |
257 ~FailedAtLifeAudioSource() override {} | 258 ~FailedAtLifeAudioSource() override {} |
258 protected: | 259 protected: |
259 bool EnsureSourceIsStarted() override { | 260 bool EnsureSourceIsStarted() override { |
260 return false; | 261 return false; |
261 } | 262 } |
262 }; | 263 }; |
263 FailedAtLifeAudioSource* source = new FailedAtLifeAudioSource(); | 264 source = new FailedAtLifeAudioSource(); |
264 source->SetDeviceInfo(device); | |
265 return source; | |
266 } else { | 265 } else { |
267 class GeneratingAudioSource : public MediaStreamAudioSource { | 266 source = new MediaStreamAudioSource(true); |
268 public: | 267 } |
269 GeneratingAudioSource() : MediaStreamAudioSource(true) { | 268 source->SetDeviceInfo(device); |
270 SetFormat( | |
271 media::AudioParameters(media::AudioParameters::AUDIO_PCM_LINEAR, | |
272 media::CHANNEL_LAYOUT_MONO, 8000, 8, 1)); | |
273 } | |
274 ~GeneratingAudioSource() override {} | |
275 void InjectAudio() { | |
276 std::unique_ptr<media::AudioBus> data = | |
277 media::AudioBus::Create(GetAudioParameters()); | |
278 DeliverDataToTracks(*data, base::TimeTicks()); | |
279 } | |
280 bool ConnectToTrack( | |
281 const blink::WebMediaStreamTrack& blink_track) override { | |
282 bool result = MediaStreamAudioSource::ConnectToTrack(blink_track); | |
283 // Queue a task to inject an audio sample after other stuff finishes. | |
284 // RunUntilIdle is required for this task to complete. | |
285 // We assume that "source" will survive long enough that it's safe | |
286 // to use base::Unretained. | |
287 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
288 FROM_HERE, base::Bind(&GeneratingAudioSource::InjectAudio, | |
289 base::Unretained(this))); | |
290 return result; | |
291 } | |
292 }; | |
293 | 269 |
294 GeneratingAudioSource* source = new GeneratingAudioSource(); | 270 if (!create_source_that_fails_) { |
295 source->SetDeviceInfo(device); | 271 // RunUntilIdle is required for this task to complete. |
296 // Queue a task to inform about the source being ready. | |
297 base::ThreadTaskRunnerHandle::Get()->PostTask( | 272 base::ThreadTaskRunnerHandle::Get()->PostTask( |
298 FROM_HERE, | 273 FROM_HERE, |
299 base::Bind(&UserMediaClientImplUnderTest::SignalSourceReady, | 274 base::Bind(&UserMediaClientImplUnderTest::SignalSourceReady, |
300 source_ready, source)); | 275 source_ready, source)); |
301 return source; | |
302 } | 276 } |
| 277 |
| 278 return source; |
303 } | 279 } |
304 | 280 |
305 MediaStreamVideoSource* CreateVideoSource( | 281 MediaStreamVideoSource* CreateVideoSource( |
306 const StreamDeviceInfo& device, | 282 const StreamDeviceInfo& device, |
307 const MediaStreamSource::SourceStoppedCallback& stop_callback) override { | 283 const MediaStreamSource::SourceStoppedCallback& stop_callback) override { |
308 video_source_ = new MockMediaStreamVideoCapturerSource(device, | 284 video_source_ = new MockMediaStreamVideoCapturerSource(device, |
309 stop_callback, | 285 stop_callback, |
310 factory_); | 286 factory_); |
311 return video_source_; | 287 return video_source_; |
312 } | 288 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 } | 355 } |
380 | 356 |
381 void LoadNewDocumentInFrame() { | 357 void LoadNewDocumentInFrame() { |
382 user_media_client_impl_->WillCommitProvisionalLoad(); | 358 user_media_client_impl_->WillCommitProvisionalLoad(); |
383 } | 359 } |
384 | 360 |
385 blink::WebMediaStream RequestLocalMediaStream() { | 361 blink::WebMediaStream RequestLocalMediaStream() { |
386 user_media_client_impl_->RequestUserMediaForTest(); | 362 user_media_client_impl_->RequestUserMediaForTest(); |
387 FakeMediaStreamDispatcherRequestUserMediaComplete(); | 363 FakeMediaStreamDispatcherRequestUserMediaComplete(); |
388 StartMockedVideoSource(); | 364 StartMockedVideoSource(); |
| 365 |
389 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_SUCCEEDED, | 366 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_SUCCEEDED, |
390 user_media_client_impl_->request_state()); | 367 user_media_client_impl_->request_state()); |
391 | 368 |
392 blink::WebMediaStream desc = | 369 blink::WebMediaStream desc = |
393 user_media_client_impl_->last_generated_stream(); | 370 user_media_client_impl_->last_generated_stream(); |
394 content::MediaStream* native_stream = | 371 content::MediaStream* native_stream = |
395 content::MediaStream::GetMediaStream(desc); | 372 content::MediaStream::GetMediaStream(desc); |
396 if (!native_stream) { | 373 if (!native_stream) { |
397 ADD_FAILURE(); | 374 ADD_FAILURE(); |
398 return desc; | 375 return desc; |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 CreateDeviceConstraints(kFakeAudioInputDeviceId1); | 925 CreateDeviceConstraints(kFakeAudioInputDeviceId1); |
949 blink::WebMediaConstraints video_constraints = | 926 blink::WebMediaConstraints video_constraints = |
950 CreateFacingModeConstraints("environment"); | 927 CreateFacingModeConstraints("environment"); |
951 // kFakeVideoInputDeviceId2 has environment facing mode. | 928 // kFakeVideoInputDeviceId2 has environment facing mode. |
952 TestValidRequestWithConstraints(audio_constraints, video_constraints, | 929 TestValidRequestWithConstraints(audio_constraints, video_constraints, |
953 kFakeAudioInputDeviceId1, | 930 kFakeAudioInputDeviceId1, |
954 kFakeVideoInputDeviceId2); | 931 kFakeVideoInputDeviceId2); |
955 } | 932 } |
956 | 933 |
957 } // namespace content | 934 } // namespace content |
OLD | NEW |