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 <queue> | 9 #include <queue> |
9 #include <string> | 10 #include <string> |
10 #include <utility> | 11 #include <utility> |
11 | 12 |
12 #include "base/bind.h" | 13 #include "base/bind.h" |
13 #include "base/callback_helpers.h" | 14 #include "base/callback_helpers.h" |
14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
15 #include "base/location.h" | 16 #include "base/location.h" |
16 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
18 #include "base/system_monitor/system_monitor.h" | 19 #include "base/system_monitor/system_monitor.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
20 #include "build/build_config.h" | 21 #include "build/build_config.h" |
21 #include "content/browser/browser_thread_impl.h" | 22 #include "content/browser/browser_thread_impl.h" |
22 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 23 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
23 #include "content/browser/renderer_host/media/media_stream_manager.h" | 24 #include "content/browser/renderer_host/media/media_stream_manager.h" |
24 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 25 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
25 #include "content/browser/renderer_host/media/video_capture_manager.h" | 26 #include "content/browser/renderer_host/media/video_capture_manager.h" |
26 #include "content/common/media/media_stream_messages.h" | 27 #include "content/common/media/media_stream_messages.h" |
27 #include "content/common/media/media_stream_options.h" | 28 #include "content/common/media/media_stream_options.h" |
28 #include "content/public/browser/media_device_id.h" | 29 #include "content/public/browser/media_device_id.h" |
29 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
30 #include "content/public/test/mock_resource_context.h" | 31 #include "content/public/test/mock_resource_context.h" |
31 #include "content/public/test/test_browser_context.h" | 32 #include "content/public/test/test_browser_context.h" |
32 #include "content/public/test/test_browser_thread_bundle.h" | 33 #include "content/public/test/test_browser_thread_bundle.h" |
33 #include "content/test/test_content_browser_client.h" | 34 #include "content/test/test_content_browser_client.h" |
34 #include "content/test/test_content_client.h" | 35 #include "content/test/test_content_client.h" |
35 #include "ipc/ipc_message_macros.h" | 36 #include "ipc/ipc_message_macros.h" |
37 #include "media/audio/audio_device_description.h" | |
36 #include "media/audio/mock_audio_manager.h" | 38 #include "media/audio/mock_audio_manager.h" |
37 #include "media/base/media_switches.h" | 39 #include "media/base/media_switches.h" |
38 #include "media/capture/video/fake_video_capture_device_factory.h" | 40 #include "media/capture/video/fake_video_capture_device_factory.h" |
39 #include "net/url_request/url_request_context.h" | 41 #include "net/url_request/url_request_context.h" |
40 #include "testing/gmock/include/gmock/gmock.h" | 42 #include "testing/gmock/include/gmock/gmock.h" |
41 #include "testing/gtest/include/gtest/gtest.h" | 43 #include "testing/gtest/include/gtest/gtest.h" |
42 #include "url/gurl.h" | 44 #include "url/gurl.h" |
43 #include "url/origin.h" | 45 #include "url/origin.h" |
44 | 46 |
45 #if defined(OS_CHROMEOS) | 47 #if defined(OS_CHROMEOS) |
46 #include "chromeos/audio/cras_audio_handler.h" | 48 #include "chromeos/audio/cras_audio_handler.h" |
47 #endif | 49 #endif |
48 | 50 |
49 using ::testing::_; | 51 using ::testing::_; |
50 using ::testing::DeleteArg; | 52 using ::testing::DeleteArg; |
51 using ::testing::DoAll; | 53 using ::testing::DoAll; |
52 using ::testing::InSequence; | 54 using ::testing::InSequence; |
53 using ::testing::Return; | 55 using ::testing::Return; |
54 using ::testing::SaveArg; | 56 using ::testing::SaveArg; |
55 | 57 |
56 const int kProcessId = 5; | 58 const int kProcessId = 5; |
57 const int kRenderId = 6; | 59 const int kRenderId = 6; |
58 const int kPageRequestId = 7; | 60 const int kPageRequestId = 7; |
59 | 61 |
60 namespace content { | 62 namespace content { |
61 | 63 |
64 namespace { | |
65 | |
66 void AudioInputDevicesEnumerated(base::Closure quit_closure, | |
67 media::AudioDeviceNames* out, | |
68 const MediaDeviceEnumeration& enumeration) { | |
69 for (const auto& info : enumeration[MEDIA_DEVICE_TYPE_AUDIO_INPUT]) { | |
70 out->emplace_back(info.label, info.device_id); | |
71 } | |
72 quit_closure.Run(); | |
73 } | |
74 | |
75 } // namespace | |
76 | |
62 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, | 77 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, |
63 public TestContentBrowserClient { | 78 public TestContentBrowserClient { |
64 public: | 79 public: |
65 MockMediaStreamDispatcherHost( | 80 MockMediaStreamDispatcherHost( |
66 const std::string& salt, | 81 const std::string& salt, |
67 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 82 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
68 MediaStreamManager* manager) | 83 MediaStreamManager* manager) |
69 : MediaStreamDispatcherHost(kProcessId, salt, manager, true), | 84 : MediaStreamDispatcherHost(kProcessId, salt, manager, true), |
70 task_runner_(task_runner), | 85 task_runner_(task_runner), |
71 current_ipc_(NULL) {} | 86 current_ipc_(NULL) {} |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 #if defined(OS_CHROMEOS) | 307 #if defined(OS_CHROMEOS) |
293 chromeos::CrasAudioHandler::Shutdown(); | 308 chromeos::CrasAudioHandler::Shutdown(); |
294 #endif | 309 #endif |
295 } | 310 } |
296 | 311 |
297 void SetUp() override { | 312 void SetUp() override { |
298 video_capture_device_factory_->GetDeviceDescriptors( | 313 video_capture_device_factory_->GetDeviceDescriptors( |
299 &physical_video_devices_); | 314 &physical_video_devices_); |
300 ASSERT_GT(physical_video_devices_.size(), 0u); | 315 ASSERT_GT(physical_video_devices_.size(), 0u); |
301 | 316 |
302 media_stream_manager_->audio_input_device_manager()->GetFakeDeviceNames( | 317 base::RunLoop run_loop; |
303 &physical_audio_devices_); | 318 media_stream_manager_->media_devices_manager()->EnumerateDevices( |
319 {{true, false, false}}, | |
320 base::Bind(&AudioInputDevicesEnumerated, run_loop.QuitClosure(), | |
321 &physical_audio_devices_)); | |
322 run_loop.Run(); | |
323 | |
304 ASSERT_GT(physical_audio_devices_.size(), 0u); | 324 ASSERT_GT(physical_audio_devices_.size(), 0u); |
305 } | 325 } |
306 | 326 |
307 void TearDown() override { host_->OnChannelClosing(); } | 327 void TearDown() override { host_->OnChannelClosing(); } |
308 | 328 |
309 protected: | 329 protected: |
310 virtual void SetupFakeUI(bool expect_started) { | 330 virtual void SetupFakeUI(bool expect_started) { |
311 stream_ui_ = new MockMediaStreamUIProxy(); | 331 stream_ui_ = new MockMediaStreamUIProxy(); |
312 if (expect_started) { | 332 if (expect_started) { |
313 EXPECT_CALL(*stream_ui_, OnStarted(_, _)); | 333 EXPECT_CALL(*stream_ui_, OnStarted(_, _)); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 host_->OnCancelEnumerateDevices(render_frame_id, page_request_id); | 398 host_->OnCancelEnumerateDevices(render_frame_id, page_request_id); |
379 } | 399 } |
380 | 400 |
381 void SubscribeToDeviceChangeNotificationsAndWaitForNotification( | 401 void SubscribeToDeviceChangeNotificationsAndWaitForNotification( |
382 int render_frame_id) { | 402 int render_frame_id) { |
383 base::RunLoop run_loop; | 403 base::RunLoop run_loop; |
384 host_->OnSubscribeToDeviceChangeNotifications(render_frame_id, origin_, | 404 host_->OnSubscribeToDeviceChangeNotifications(render_frame_id, origin_, |
385 run_loop.QuitClosure()); | 405 run_loop.QuitClosure()); |
386 // Simulate a change in the set of devices. | 406 // Simulate a change in the set of devices. |
387 video_capture_device_factory_->set_number_of_devices(5); | 407 video_capture_device_factory_->set_number_of_devices(5); |
388 media_stream_manager_->OnDevicesChanged( | 408 media_stream_manager_->media_devices_manager()->OnDevicesChanged( |
389 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); | 409 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); |
390 run_loop.Run(); | 410 run_loop.Run(); |
391 } | 411 } |
392 | 412 |
393 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) { | 413 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) { |
394 for (size_t i = 0; i < devices.size(); ++i) { | 414 for (size_t i = 0; i < devices.size(); ++i) { |
395 media::AudioDeviceNames::const_iterator audio_it = | 415 media::AudioDeviceNames::const_iterator audio_it = |
396 physical_audio_devices_.begin(); | 416 physical_audio_devices_.begin(); |
397 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | 417 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { |
418 // Skip default and communications audio devices, whose IDs are not | |
419 // translated. | |
420 if (devices[i].device.id == | |
421 media::AudioDeviceDescription::kDefaultDeviceId || | |
422 devices[i].device.id == | |
423 media::AudioDeviceDescription::kCommunicationsDeviceId) | |
tommi (sloooow) - chröme
2016/09/20 08:47:15
nit: {}
Guido Urdaneta
2016/09/20 13:59:26
Done.
| |
424 continue; | |
398 if (audio_it->unique_id == devices[i].device.id) | 425 if (audio_it->unique_id == devices[i].device.id) |
399 return true; | 426 return true; |
400 } | 427 } |
401 media::VideoCaptureDeviceDescriptors::const_iterator video_it = | 428 media::VideoCaptureDeviceDescriptors::const_iterator video_it = |
402 physical_video_devices_.begin(); | 429 physical_video_devices_.begin(); |
403 for (; video_it != physical_video_devices_.end(); ++video_it) { | 430 for (; video_it != physical_video_devices_.end(); ++video_it) { |
404 if (video_it->device_id == devices[i].device.id) | 431 if (video_it->device_id == devices[i].device.id) |
405 return true; | 432 return true; |
406 } | 433 } |
407 } | 434 } |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
906 SetupFakeUI(true); | 933 SetupFakeUI(true); |
907 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); | 934 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, controls); |
908 EXPECT_EQ(host_->audio_devices_.size(), 1u); | 935 EXPECT_EQ(host_->audio_devices_.size(), 1u); |
909 EXPECT_EQ(host_->video_devices_.size(), 1u); | 936 EXPECT_EQ(host_->video_devices_.size(), 1u); |
910 | 937 |
911 video_capture_device_factory_->set_number_of_devices(0); | 938 video_capture_device_factory_->set_number_of_devices(0); |
912 | 939 |
913 base::RunLoop run_loop; | 940 base::RunLoop run_loop; |
914 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) | 941 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) |
915 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 942 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
916 media_stream_manager_->OnDevicesChanged( | 943 media_stream_manager_->media_devices_manager()->OnDevicesChanged( |
917 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); | 944 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); |
918 | 945 |
919 run_loop.Run(); | 946 run_loop.Run(); |
920 } | 947 } |
921 | 948 |
922 TEST_F(MediaStreamDispatcherHostTest, EnumerateAudioDevices) { | 949 TEST_F(MediaStreamDispatcherHostTest, EnumerateAudioDevices) { |
923 SetupFakeUI(false); | 950 SetupFakeUI(false); |
924 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | 951 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, |
925 MEDIA_DEVICE_AUDIO_CAPTURE); | 952 MEDIA_DEVICE_AUDIO_CAPTURE); |
926 EXPECT_TRUE(DoesContainLabels(host_->enumerated_devices_)); | 953 EXPECT_TRUE(DoesContainLabels(host_->enumerated_devices_)); |
(...skipping 24 matching lines...) Expand all Loading... | |
951 | 978 |
952 TEST_F(MediaStreamDispatcherHostTest, DeviceChangeNotification) { | 979 TEST_F(MediaStreamDispatcherHostTest, DeviceChangeNotification) { |
953 SetupFakeUI(false); | 980 SetupFakeUI(false); |
954 // warm up the cache | 981 // warm up the cache |
955 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | 982 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, |
956 MEDIA_DEVICE_VIDEO_CAPTURE); | 983 MEDIA_DEVICE_VIDEO_CAPTURE); |
957 SubscribeToDeviceChangeNotificationsAndWaitForNotification(kRenderId); | 984 SubscribeToDeviceChangeNotificationsAndWaitForNotification(kRenderId); |
958 } | 985 } |
959 | 986 |
960 }; // namespace content | 987 }; // namespace content |
OLD | NEW |