| 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 "component/arc/video_facing.h" |
| 22 #include "content/browser/browser_thread_impl.h" | 23 #include "content/browser/browser_thread_impl.h" |
| 23 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 24 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
| 24 #include "content/browser/renderer_host/media/media_stream_manager.h" | 25 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 25 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 26 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
| 26 #include "content/browser/renderer_host/media/video_capture_manager.h" | 27 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 27 #include "content/common/media/media_stream_messages.h" | 28 #include "content/common/media/media_stream_messages.h" |
| 28 #include "content/common/media/media_stream_options.h" | 29 #include "content/common/media/media_stream_options.h" |
| 29 #include "content/public/browser/media_device_id.h" | 30 #include "content/public/browser/media_device_id.h" |
| 30 #include "content/public/common/content_switches.h" | 31 #include "content/public/common/content_switches.h" |
| 31 #include "content/public/test/mock_resource_context.h" | 32 #include "content/public/test/mock_resource_context.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 66 |
| 66 void AudioInputDevicesEnumerated(base::Closure quit_closure, | 67 void AudioInputDevicesEnumerated(base::Closure quit_closure, |
| 67 media::AudioDeviceDescriptions* out, | 68 media::AudioDeviceDescriptions* out, |
| 68 const MediaDeviceEnumeration& enumeration) { | 69 const MediaDeviceEnumeration& enumeration) { |
| 69 for (const auto& info : enumeration[MEDIA_DEVICE_TYPE_AUDIO_INPUT]) { | 70 for (const auto& info : enumeration[MEDIA_DEVICE_TYPE_AUDIO_INPUT]) { |
| 70 out->emplace_back(info.label, info.device_id, info.group_id); | 71 out->emplace_back(info.label, info.device_id, info.group_id); |
| 71 } | 72 } |
| 72 quit_closure.Run(); | 73 quit_closure.Run(); |
| 73 } | 74 } |
| 74 | 75 |
| 76 class MockVideoCaptureObserver : public component::VideoCaptureObserver { |
| 77 public: |
| 78 MOCK_METHOD1(OnVideoCaptureStarted, void(component::VideoFacingMode)); |
| 79 MOCK_METHOD1(OnVideoCaptureStopped, void(component::VideoFacingMode)); |
| 80 }; |
| 81 |
| 75 } // namespace | 82 } // namespace |
| 76 | 83 |
| 77 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, | 84 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, |
| 78 public TestContentBrowserClient { | 85 public TestContentBrowserClient { |
| 79 public: | 86 public: |
| 80 MockMediaStreamDispatcherHost( | 87 MockMediaStreamDispatcherHost( |
| 81 const std::string& salt, | 88 const std::string& salt, |
| 82 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 89 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 83 MediaStreamManager* manager) | 90 MediaStreamManager* manager) |
| 84 : MediaStreamDispatcherHost(kProcessId, salt, manager), | 91 : MediaStreamDispatcherHost(kProcessId, salt, manager), |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 MediaStreamDispatcherHostTest() | 232 MediaStreamDispatcherHostTest() |
| 226 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 233 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 227 old_browser_client_(NULL), | 234 old_browser_client_(NULL), |
| 228 origin_(GURL("https://test.com")) { | 235 origin_(GURL("https://test.com")) { |
| 229 audio_manager_.reset( | 236 audio_manager_.reset( |
| 230 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get())); | 237 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get())); |
| 231 // Make sure we use fake devices to avoid long delays. | 238 // Make sure we use fake devices to avoid long delays. |
| 232 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 239 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 233 switches::kUseFakeDeviceForMediaStream); | 240 switches::kUseFakeDeviceForMediaStream); |
| 234 // Create our own MediaStreamManager. | 241 // Create our own MediaStreamManager. |
| 235 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); | 242 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get(), new
MockVideoCaptureObserver())); |
| 236 video_capture_device_factory_ = | 243 video_capture_device_factory_ = |
| 237 static_cast<media::FakeVideoCaptureDeviceFactory*>( | 244 static_cast<media::FakeVideoCaptureDeviceFactory*>( |
| 238 media_stream_manager_->video_capture_manager() | 245 media_stream_manager_->video_capture_manager() |
| 239 ->video_capture_device_factory()); | 246 ->video_capture_device_factory()); |
| 240 DCHECK(video_capture_device_factory_); | 247 DCHECK(video_capture_device_factory_); |
| 241 #if defined(OS_WIN) | 248 #if defined(OS_WIN) |
| 242 // Override the Video Capture Thread that MediaStreamManager constructs. | 249 // Override the Video Capture Thread that MediaStreamManager constructs. |
| 243 media_stream_manager_->video_capture_manager()->set_device_task_runner( | 250 media_stream_manager_->video_capture_manager()->set_device_task_runner( |
| 244 base::ThreadTaskRunnerHandle::Get()); | 251 base::ThreadTaskRunnerHandle::Get()); |
| 245 #endif | 252 #endif |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 base::RunLoop run_loop; | 814 base::RunLoop run_loop; |
| 808 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) | 815 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) |
| 809 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 816 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
| 810 media_stream_manager_->media_devices_manager()->OnDevicesChanged( | 817 media_stream_manager_->media_devices_manager()->OnDevicesChanged( |
| 811 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); | 818 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); |
| 812 | 819 |
| 813 run_loop.Run(); | 820 run_loop.Run(); |
| 814 } | 821 } |
| 815 | 822 |
| 816 }; // namespace content | 823 }; // namespace content |
| OLD | NEW |