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/browser/renderer_host/media/media_stream_dispatcher_host.h" | 5 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <memory> | 8 #include <memory> |
9 #include <queue> | 9 #include <queue> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/callback_helpers.h" | 14 #include "base/callback_helpers.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/location.h" | 16 #include "base/location.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
19 #include "base/system_monitor/system_monitor.h" | 19 #include "base/system_monitor/system_monitor.h" |
20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
22 #include "content/browser/browser_thread_impl.h" | 22 #include "content/browser/browser_thread_impl.h" |
23 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 23 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
24 #include "content/browser/renderer_host/media/media_stream_manager.h" | 24 #include "content/browser/renderer_host/media/media_stream_manager.h" |
25 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 25 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
26 #include "content/browser/renderer_host/media/mock_video_capture_provider.h" | 26 #include "content/browser/renderer_host/media/mock_video_capture_provider.h" |
27 #include "content/browser/renderer_host/media/video_capture_manager.h" | 27 #include "content/browser/renderer_host/media/video_capture_manager.h" |
28 #include "content/common/media/media_stream_messages.h" | 28 #include "content/common/media/media_stream_messages.h" |
29 #include "content/common/media/media_stream_options.h" | 29 #include "content/common/media/media_stream_options.h" |
| 30 #include "content/public/browser/browser_context.h" |
30 #include "content/public/browser/media_device_id.h" | 31 #include "content/public/browser/media_device_id.h" |
31 #include "content/public/common/content_switches.h" | 32 #include "content/public/common/content_switches.h" |
32 #include "content/public/test/mock_resource_context.h" | |
33 #include "content/public/test/test_browser_context.h" | 33 #include "content/public/test/test_browser_context.h" |
34 #include "content/public/test/test_browser_thread_bundle.h" | 34 #include "content/public/test/test_browser_thread_bundle.h" |
35 #include "content/test/test_content_browser_client.h" | 35 #include "content/test/test_content_browser_client.h" |
36 #include "content/test/test_content_client.h" | 36 #include "content/test/test_content_client.h" |
37 #include "ipc/ipc_message_macros.h" | 37 #include "ipc/ipc_message_macros.h" |
38 #include "media/audio/audio_device_description.h" | 38 #include "media/audio/audio_device_description.h" |
39 #include "media/audio/audio_system_impl.h" | 39 #include "media/audio/audio_system_impl.h" |
40 #include "media/audio/mock_audio_manager.h" | 40 #include "media/audio/mock_audio_manager.h" |
41 #include "media/base/media_switches.h" | 41 #include "media/base/media_switches.h" |
42 #include "media/capture/video/fake_video_capture_device_factory.h" | 42 #include "media/capture/video/fake_video_capture_device_factory.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 // Make sure we use fake devices to avoid long delays. | 250 // Make sure we use fake devices to avoid long delays. |
251 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 251 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
252 switches::kUseFakeDeviceForMediaStream); | 252 switches::kUseFakeDeviceForMediaStream); |
253 auto mock_video_capture_provider = | 253 auto mock_video_capture_provider = |
254 base::MakeUnique<MockVideoCaptureProvider>(); | 254 base::MakeUnique<MockVideoCaptureProvider>(); |
255 mock_video_capture_provider_ = mock_video_capture_provider.get(); | 255 mock_video_capture_provider_ = mock_video_capture_provider.get(); |
256 // Create our own MediaStreamManager. | 256 // Create our own MediaStreamManager. |
257 media_stream_manager_ = base::MakeUnique<MediaStreamManager>( | 257 media_stream_manager_ = base::MakeUnique<MediaStreamManager>( |
258 audio_system_.get(), std::move(mock_video_capture_provider)); | 258 audio_system_.get(), std::move(mock_video_capture_provider)); |
259 | 259 |
260 MockResourceContext* mock_resource_context = | |
261 static_cast<MockResourceContext*>( | |
262 browser_context_.GetResourceContext()); | |
263 | |
264 host_ = new MockMediaStreamDispatcherHost( | 260 host_ = new MockMediaStreamDispatcherHost( |
265 mock_resource_context->GetMediaDeviceIDSalt(), | 261 browser_context_.GetMediaDeviceIDSalt(), |
266 base::ThreadTaskRunnerHandle::Get(), media_stream_manager_.get()); | 262 base::ThreadTaskRunnerHandle::Get(), media_stream_manager_.get()); |
267 | 263 |
268 // Use the fake content client and browser. | 264 // Use the fake content client and browser. |
269 content_client_.reset(new TestContentClient()); | 265 content_client_.reset(new TestContentClient()); |
270 SetContentClient(content_client_.get()); | 266 SetContentClient(content_client_.get()); |
271 old_browser_client_ = SetBrowserClientForTesting(host_.get()); | 267 old_browser_client_ = SetBrowserClientForTesting(host_.get()); |
272 | 268 |
273 #if defined(OS_CHROMEOS) | 269 #if defined(OS_CHROMEOS) |
274 chromeos::CrasAudioHandler::InitializeForTesting(); | 270 chromeos::CrasAudioHandler::InitializeForTesting(); |
275 #endif | 271 #endif |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 398 } |
403 | 399 |
404 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, | 400 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, |
405 const url::Origin& origin) { | 401 const url::Origin& origin) { |
406 for (size_t i = 0; i < devices.size(); ++i) { | 402 for (size_t i = 0; i < devices.size(); ++i) { |
407 bool found_match = false; | 403 bool found_match = false; |
408 media::AudioDeviceDescriptions::const_iterator audio_it = | 404 media::AudioDeviceDescriptions::const_iterator audio_it = |
409 audio_device_descriptions_.begin(); | 405 audio_device_descriptions_.begin(); |
410 for (; audio_it != audio_device_descriptions_.end(); ++audio_it) { | 406 for (; audio_it != audio_device_descriptions_.end(); ++audio_it) { |
411 if (content::DoesMediaDeviceIDMatchHMAC( | 407 if (content::DoesMediaDeviceIDMatchHMAC( |
412 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 408 browser_context_.GetMediaDeviceIDSalt(), origin, |
413 origin, | 409 devices[i].device.id, audio_it->unique_id)) { |
414 devices[i].device.id, | |
415 audio_it->unique_id)) { | |
416 EXPECT_FALSE(found_match); | 410 EXPECT_FALSE(found_match); |
417 found_match = true; | 411 found_match = true; |
418 } | 412 } |
419 } | 413 } |
420 for (const std::string& device_id : stub_video_device_ids_) { | 414 for (const std::string& device_id : stub_video_device_ids_) { |
421 if (content::DoesMediaDeviceIDMatchHMAC( | 415 if (content::DoesMediaDeviceIDMatchHMAC( |
422 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 416 browser_context_.GetMediaDeviceIDSalt(), origin, |
423 origin, devices[i].device.id, device_id)) { | 417 devices[i].device.id, device_id)) { |
424 EXPECT_FALSE(found_match); | 418 EXPECT_FALSE(found_match); |
425 found_match = true; | 419 found_match = true; |
426 } | 420 } |
427 } | 421 } |
428 if (!found_match) | 422 if (!found_match) |
429 return false; | 423 return false; |
430 } | 424 } |
431 return true; | 425 return true; |
432 } | 426 } |
433 | 427 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 496 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
503 | 497 |
504 EXPECT_EQ(host_->audio_devices_.size(), 1u); | 498 EXPECT_EQ(host_->audio_devices_.size(), 1u); |
505 EXPECT_EQ(host_->video_devices_.size(), 1u); | 499 EXPECT_EQ(host_->video_devices_.size(), 1u); |
506 } | 500 } |
507 | 501 |
508 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithDepthVideo) { | 502 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithDepthVideo) { |
509 // We specify to generate both audio and video stream. | 503 // We specify to generate both audio and video stream. |
510 StreamControls controls(true, true); | 504 StreamControls controls(true, true); |
511 std::string source_id = content::GetHMACForMediaDeviceID( | 505 std::string source_id = content::GetHMACForMediaDeviceID( |
512 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_, | 506 browser_context_.GetMediaDeviceIDSalt(), origin_, kDepthVideoDeviceId); |
513 kDepthVideoDeviceId); | |
514 // |source_id| corresponds to the depth device. As we can generate only one | 507 // |source_id| corresponds to the depth device. As we can generate only one |
515 // video stream using GenerateStreamAndWaitForResult, we use | 508 // video stream using GenerateStreamAndWaitForResult, we use |
516 // controls.video.source_id to specify that the stream is depth video. | 509 // controls.video.source_id to specify that the stream is depth video. |
517 // See also MediaStreamManager::GenerateStream and other tests here. | 510 // See also MediaStreamManager::GenerateStream and other tests here. |
518 controls.video.device_id = source_id; | 511 controls.video.device_id = source_id; |
519 | 512 |
520 SetupFakeUI(true); | 513 SetupFakeUI(true); |
521 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 514 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
522 | 515 |
523 // We specified the generation and expect to get | 516 // We specified the generation and expect to get |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 // Test that we can generate streams where a sourceId is specified in | 649 // Test that we can generate streams where a sourceId is specified in |
657 // the request. | 650 // the request. |
658 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) { | 651 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) { |
659 ASSERT_GE(audio_device_descriptions_.size(), 1u); | 652 ASSERT_GE(audio_device_descriptions_.size(), 1u); |
660 ASSERT_GE(stub_video_device_ids_.size(), 1u); | 653 ASSERT_GE(stub_video_device_ids_.size(), 1u); |
661 | 654 |
662 media::AudioDeviceDescriptions::const_iterator audio_it = | 655 media::AudioDeviceDescriptions::const_iterator audio_it = |
663 audio_device_descriptions_.begin(); | 656 audio_device_descriptions_.begin(); |
664 for (; audio_it != audio_device_descriptions_.end(); ++audio_it) { | 657 for (; audio_it != audio_device_descriptions_.end(); ++audio_it) { |
665 std::string source_id = content::GetHMACForMediaDeviceID( | 658 std::string source_id = content::GetHMACForMediaDeviceID( |
666 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), | 659 browser_context_.GetMediaDeviceIDSalt(), origin_, audio_it->unique_id); |
667 origin_, | |
668 audio_it->unique_id); | |
669 ASSERT_FALSE(source_id.empty()); | 660 ASSERT_FALSE(source_id.empty()); |
670 StreamControls controls(true, true); | 661 StreamControls controls(true, true); |
671 controls.audio.device_id = source_id; | 662 controls.audio.device_id = source_id; |
672 | 663 |
673 SetupFakeUI(true); | 664 SetupFakeUI(true); |
674 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 665 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
675 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id); | 666 EXPECT_EQ(host_->audio_devices_[0].device.id, source_id); |
676 } | 667 } |
677 | 668 |
678 for (const std::string& device_id : stub_video_device_ids_) { | 669 for (const std::string& device_id : stub_video_device_ids_) { |
679 std::string source_id = content::GetHMACForMediaDeviceID( | 670 std::string source_id = content::GetHMACForMediaDeviceID( |
680 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), origin_, | 671 browser_context_.GetMediaDeviceIDSalt(), origin_, device_id); |
681 device_id); | |
682 ASSERT_FALSE(source_id.empty()); | 672 ASSERT_FALSE(source_id.empty()); |
683 StreamControls controls(true, true); | 673 StreamControls controls(true, true); |
684 controls.video.device_id = source_id; | 674 controls.video.device_id = source_id; |
685 | 675 |
686 SetupFakeUI(true); | 676 SetupFakeUI(true); |
687 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 677 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
688 EXPECT_EQ(host_->video_devices_[0].device.id, source_id); | 678 EXPECT_EQ(host_->video_devices_[0].device.id, source_id); |
689 } | 679 } |
690 } | 680 } |
691 | 681 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 base::RunLoop run_loop; | 859 base::RunLoop run_loop; |
870 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) | 860 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) |
871 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 861 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
872 media_stream_manager_->media_devices_manager()->OnDevicesChanged( | 862 media_stream_manager_->media_devices_manager()->OnDevicesChanged( |
873 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); | 863 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); |
874 | 864 |
875 run_loop.Run(); | 865 run_loop.Run(); |
876 } | 866 } |
877 | 867 |
878 }; // namespace content | 868 }; // namespace content |
OLD | NEW |