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; | |
254 if (create_source_that_fails_) { | 253 if (create_source_that_fails_) { |
255 class FailedAtLifeAudioSource : public MediaStreamAudioSource { | 254 class FailedAtLifeAudioSource : public MediaStreamAudioSource { |
256 public: | 255 public: |
257 FailedAtLifeAudioSource() : MediaStreamAudioSource(true) {} | 256 FailedAtLifeAudioSource() : MediaStreamAudioSource(true) {} |
258 ~FailedAtLifeAudioSource() override {} | 257 ~FailedAtLifeAudioSource() override {} |
259 protected: | 258 protected: |
260 bool EnsureSourceIsStarted() override { | 259 bool EnsureSourceIsStarted() override { |
261 return false; | 260 return false; |
262 } | 261 } |
263 }; | 262 }; |
264 source = new FailedAtLifeAudioSource(); | 263 FailedAtLifeAudioSource* source = new FailedAtLifeAudioSource(); |
| 264 source->SetDeviceInfo(device); |
| 265 return source; |
265 } else { | 266 } else { |
266 source = new MediaStreamAudioSource(true); | 267 class GeneratingAudioSource : public MediaStreamAudioSource { |
267 } | 268 public: |
268 source->SetDeviceInfo(device); | 269 GeneratingAudioSource() : MediaStreamAudioSource(true) { |
| 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 }; |
269 | 293 |
270 if (!create_source_that_fails_) { | 294 GeneratingAudioSource* source = new GeneratingAudioSource(); |
271 // RunUntilIdle is required for this task to complete. | 295 source->SetDeviceInfo(device); |
| 296 // Queue a task to inform about the source being ready. |
272 base::ThreadTaskRunnerHandle::Get()->PostTask( | 297 base::ThreadTaskRunnerHandle::Get()->PostTask( |
273 FROM_HERE, | 298 FROM_HERE, |
274 base::Bind(&UserMediaClientImplUnderTest::SignalSourceReady, | 299 base::Bind(&UserMediaClientImplUnderTest::SignalSourceReady, |
275 source_ready, source)); | 300 source_ready, source)); |
| 301 return source; |
276 } | 302 } |
277 | |
278 return source; | |
279 } | 303 } |
280 | 304 |
281 MediaStreamVideoSource* CreateVideoSource( | 305 MediaStreamVideoSource* CreateVideoSource( |
282 const StreamDeviceInfo& device, | 306 const StreamDeviceInfo& device, |
283 const MediaStreamSource::SourceStoppedCallback& stop_callback) override { | 307 const MediaStreamSource::SourceStoppedCallback& stop_callback) override { |
284 video_source_ = new MockMediaStreamVideoCapturerSource(device, | 308 video_source_ = new MockMediaStreamVideoCapturerSource(device, |
285 stop_callback, | 309 stop_callback, |
286 factory_); | 310 factory_); |
287 return video_source_; | 311 return video_source_; |
288 } | 312 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 } | 379 } |
356 | 380 |
357 void LoadNewDocumentInFrame() { | 381 void LoadNewDocumentInFrame() { |
358 user_media_client_impl_->WillCommitProvisionalLoad(); | 382 user_media_client_impl_->WillCommitProvisionalLoad(); |
359 } | 383 } |
360 | 384 |
361 blink::WebMediaStream RequestLocalMediaStream() { | 385 blink::WebMediaStream RequestLocalMediaStream() { |
362 user_media_client_impl_->RequestUserMediaForTest(); | 386 user_media_client_impl_->RequestUserMediaForTest(); |
363 FakeMediaStreamDispatcherRequestUserMediaComplete(); | 387 FakeMediaStreamDispatcherRequestUserMediaComplete(); |
364 StartMockedVideoSource(); | 388 StartMockedVideoSource(); |
365 | |
366 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_SUCCEEDED, | 389 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_SUCCEEDED, |
367 user_media_client_impl_->request_state()); | 390 user_media_client_impl_->request_state()); |
368 | 391 |
369 blink::WebMediaStream desc = | 392 blink::WebMediaStream desc = |
370 user_media_client_impl_->last_generated_stream(); | 393 user_media_client_impl_->last_generated_stream(); |
371 content::MediaStream* native_stream = | 394 content::MediaStream* native_stream = |
372 content::MediaStream::GetMediaStream(desc); | 395 content::MediaStream::GetMediaStream(desc); |
373 if (!native_stream) { | 396 if (!native_stream) { |
374 ADD_FAILURE(); | 397 ADD_FAILURE(); |
375 return desc; | 398 return desc; |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 CreateDeviceConstraints(kFakeAudioInputDeviceId1); | 948 CreateDeviceConstraints(kFakeAudioInputDeviceId1); |
926 blink::WebMediaConstraints video_constraints = | 949 blink::WebMediaConstraints video_constraints = |
927 CreateFacingModeConstraints("environment"); | 950 CreateFacingModeConstraints("environment"); |
928 // kFakeVideoInputDeviceId2 has environment facing mode. | 951 // kFakeVideoInputDeviceId2 has environment facing mode. |
929 TestValidRequestWithConstraints(audio_constraints, video_constraints, | 952 TestValidRequestWithConstraints(audio_constraints, video_constraints, |
930 kFakeAudioInputDeviceId1, | 953 kFakeAudioInputDeviceId1, |
931 kFakeVideoInputDeviceId2); | 954 kFakeVideoInputDeviceId2); |
932 } | 955 } |
933 | 956 |
934 } // namespace content | 957 } // namespace content |
OLD | NEW |