OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/extensions/api/desktop_capture/desktop_capture_base.h" | 5 #include "chrome/browser/extensions/api/desktop_capture/desktop_capture_base.h" |
6 | 6 |
7 #include <tuple> | 7 #include <tuple> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/feature_list.h" | |
11 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
14 #include "chrome/browser/extensions/extension_tab_util.h" | 15 #include "chrome/browser/extensions/extension_tab_util.h" |
15 #include "chrome/browser/media/webrtc/desktop_media_list_ash.h" | 16 #include "chrome/browser/media/webrtc/desktop_media_list_ash.h" |
16 #include "chrome/browser/media/webrtc/desktop_streams_registry.h" | 17 #include "chrome/browser/media/webrtc/desktop_streams_registry.h" |
17 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" | 18 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" |
18 #include "chrome/browser/media/webrtc/native_desktop_media_list.h" | 19 #include "chrome/browser/media/webrtc/native_desktop_media_list.h" |
19 #include "chrome/browser/media/webrtc/tab_desktop_media_list.h" | 20 #include "chrome/browser/media/webrtc/tab_desktop_media_list.h" |
20 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
38 const char kInvalidSourceNameError[] = "Invalid source type specified."; | 39 const char kInvalidSourceNameError[] = "Invalid source type specified."; |
39 const char kEmptySourcesListError[] = | 40 const char kEmptySourcesListError[] = |
40 "At least one source type must be specified."; | 41 "At least one source type must be specified."; |
41 | 42 |
42 DesktopCaptureChooseDesktopMediaFunctionBase::PickerFactory* g_picker_factory = | 43 DesktopCaptureChooseDesktopMediaFunctionBase::PickerFactory* g_picker_factory = |
43 NULL; | 44 NULL; |
44 | 45 |
46 #if !defined(USE_ASH) | |
47 // Creates a DesktopCaptureOptions with required settings. This function should | |
48 // be consistent with CreateDesktopCaptureOptions() function in | |
49 // desktop_capture_device.cc file at | |
50 // https://cs.chromium.org/chromium/src/content/browser/media/capture/desktop_ca pture_device.cc | |
Sergey Ulanov
2017/06/29 23:49:01
Instead of duplicating the code here, can this fil
Hzj_jie
2017/06/29 23:56:27
It's do a little bit confusing, but one file is in
Sergey Ulanov
2017/07/05 19:31:07
Sorry I missed that. Maybe put this function in we
Hzj_jie
2017/07/07 01:45:08
Placing this logic in webrtc seems not a good idea
| |
51 webrtc::DesktopCaptureOptions CreateDesktopCaptureOptions() { | |
52 auto options = webrtc::DesktopCaptureOptions::CreateDefault(); | |
53 // Leave desktop effects enabled during WebRTC captures. | |
54 options.set_disable_effects(false); | |
55 #if defined(OS_WIN) | |
56 static constexpr base::Feature kDirectXCapturer{ | |
57 "DirectXCapturer", | |
58 base::FEATURE_ENABLED_BY_DEFAULT}; | |
59 if (base::FeatureList::IsEnabled(kDirectXCapturer)) { | |
60 options.set_allow_directx_capturer(true); | |
61 options.set_allow_use_magnification_api(false); | |
62 } else { | |
63 options.set_allow_use_magnification_api(true); | |
64 } | |
65 #endif | |
Sergey Ulanov
2017/06/29 23:49:01
// defined(OS_WIN)
Hzj_jie
2017/06/29 23:56:27
Done.
| |
66 return options; | |
67 } | |
68 #endif | |
Sergey Ulanov
2017/06/29 23:49:01
// defined(OS_ASH)
Hzj_jie
2017/06/29 23:56:27
Done.
| |
69 | |
45 } // namespace | 70 } // namespace |
46 | 71 |
47 // static | 72 // static |
48 void DesktopCaptureChooseDesktopMediaFunctionBase::SetPickerFactoryForTests( | 73 void DesktopCaptureChooseDesktopMediaFunctionBase::SetPickerFactoryForTests( |
49 PickerFactory* factory) { | 74 PickerFactory* factory) { |
50 g_picker_factory = factory; | 75 g_picker_factory = factory; |
51 } | 76 } |
52 | 77 |
53 DesktopCaptureChooseDesktopMediaFunctionBase:: | 78 DesktopCaptureChooseDesktopMediaFunctionBase:: |
54 DesktopCaptureChooseDesktopMediaFunctionBase() { | 79 DesktopCaptureChooseDesktopMediaFunctionBase() { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 } | 137 } |
113 std::unique_ptr<DesktopMediaList> screen_list; | 138 std::unique_ptr<DesktopMediaList> screen_list; |
114 if (g_picker_factory) { | 139 if (g_picker_factory) { |
115 screen_list = | 140 screen_list = |
116 g_picker_factory->CreateMediaList(DesktopMediaID::TYPE_SCREEN); | 141 g_picker_factory->CreateMediaList(DesktopMediaID::TYPE_SCREEN); |
117 } else { | 142 } else { |
118 #if defined(USE_ASH) | 143 #if defined(USE_ASH) |
119 screen_list = base::MakeUnique<DesktopMediaListAsh>( | 144 screen_list = base::MakeUnique<DesktopMediaListAsh>( |
120 DesktopMediaID::TYPE_SCREEN); | 145 DesktopMediaID::TYPE_SCREEN); |
121 #else // !defined(USE_ASH) | 146 #else // !defined(USE_ASH) |
122 webrtc::DesktopCaptureOptions capture_options = | |
123 webrtc::DesktopCaptureOptions::CreateDefault(); | |
124 capture_options.set_disable_effects(false); | |
125 screen_list = base::MakeUnique<NativeDesktopMediaList>( | 147 screen_list = base::MakeUnique<NativeDesktopMediaList>( |
126 DesktopMediaID::TYPE_SCREEN, | 148 content::DesktopMediaID::TYPE_SCREEN, |
127 webrtc::DesktopCapturer::CreateScreenCapturer(capture_options)); | 149 webrtc::DesktopCapturer::CreateScreenCapturer( |
150 CreateDesktopCaptureOptions())); | |
128 #endif // !defined(USE_ASH) | 151 #endif // !defined(USE_ASH) |
129 } | 152 } |
130 have_screen_list = true; | 153 have_screen_list = true; |
131 source_lists.push_back(std::move(screen_list)); | 154 source_lists.push_back(std::move(screen_list)); |
132 break; | 155 break; |
133 } | 156 } |
134 case api::desktop_capture::DESKTOP_CAPTURE_SOURCE_TYPE_WINDOW: { | 157 case api::desktop_capture::DESKTOP_CAPTURE_SOURCE_TYPE_WINDOW: { |
135 if (have_window_list) { | 158 if (have_window_list) { |
136 continue; | 159 continue; |
137 } | 160 } |
138 std::unique_ptr<DesktopMediaList> window_list; | 161 std::unique_ptr<DesktopMediaList> window_list; |
139 if (g_picker_factory) { | 162 if (g_picker_factory) { |
140 window_list = | 163 window_list = |
141 g_picker_factory->CreateMediaList(DesktopMediaID::TYPE_WINDOW); | 164 g_picker_factory->CreateMediaList(DesktopMediaID::TYPE_WINDOW); |
142 } else { | 165 } else { |
143 #if defined(USE_ASH) | 166 #if defined(USE_ASH) |
144 window_list = base::MakeUnique<DesktopMediaListAsh>( | 167 window_list = base::MakeUnique<DesktopMediaListAsh>( |
145 DesktopMediaID::TYPE_WINDOW); | 168 DesktopMediaID::TYPE_WINDOW); |
146 #else // !defined(USE_ASH) | 169 #else // !defined(USE_ASH) |
147 // NativeDesktopMediaList calls the capturers on a background thread. | 170 // NativeDesktopMediaList calls the capturers on a background thread. |
148 // This means that the two DesktopCapturer instances (for screens and | 171 // This means that the two DesktopCapturer instances (for screens and |
149 // windows) created here cannot share the same DesktopCaptureOptions | 172 // windows) created here cannot share the same DesktopCaptureOptions |
150 // instance. DesktopCaptureOptions owns X connection, which cannot be | 173 // instance. DesktopCaptureOptions owns X connection, which cannot be |
151 // used on multiple threads concurrently. | 174 // used on multiple threads concurrently. |
152 webrtc::DesktopCaptureOptions capture_options = | |
153 webrtc::DesktopCaptureOptions::CreateDefault(); | |
154 capture_options.set_disable_effects(false); | |
155 window_list = base::MakeUnique<NativeDesktopMediaList>( | 175 window_list = base::MakeUnique<NativeDesktopMediaList>( |
156 DesktopMediaID::TYPE_WINDOW, | 176 content::DesktopMediaID::TYPE_WINDOW, |
157 webrtc::DesktopCapturer::CreateWindowCapturer(capture_options)); | 177 webrtc::DesktopCapturer::CreateWindowCapturer( |
178 CreateDesktopCaptureOptions())); | |
158 #endif // !defined(USE_ASH) | 179 #endif // !defined(USE_ASH) |
159 } | 180 } |
160 have_window_list = true; | 181 have_window_list = true; |
161 source_lists.push_back(std::move(window_list)); | 182 source_lists.push_back(std::move(window_list)); |
162 break; | 183 break; |
163 } | 184 } |
164 case api::desktop_capture::DESKTOP_CAPTURE_SOURCE_TYPE_TAB: { | 185 case api::desktop_capture::DESKTOP_CAPTURE_SOURCE_TYPE_TAB: { |
165 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 186 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
166 extensions::switches::kDisableTabForDesktopShare) || | 187 extensions::switches::kDisableTabForDesktopShare) || |
167 have_tab_list) { | 188 have_tab_list) { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 | 331 |
311 void DesktopCaptureRequestsRegistry::CancelRequest(int process_id, | 332 void DesktopCaptureRequestsRegistry::CancelRequest(int process_id, |
312 int request_id) { | 333 int request_id) { |
313 RequestsMap::iterator it = requests_.find(RequestId(process_id, request_id)); | 334 RequestsMap::iterator it = requests_.find(RequestId(process_id, request_id)); |
314 if (it != requests_.end()) | 335 if (it != requests_.end()) |
315 it->second->Cancel(); | 336 it->second->Cancel(); |
316 } | 337 } |
317 | 338 |
318 | 339 |
319 } // namespace extensions | 340 } // namespace extensions |
OLD | NEW |