OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <assert.h> | 11 #include <assert.h> |
12 #include <ApplicationServices/ApplicationServices.h> | 12 #include <ApplicationServices/ApplicationServices.h> |
13 #include <Cocoa/Cocoa.h> | 13 #include <Cocoa/Cocoa.h> |
14 #include <CoreFoundation/CoreFoundation.h> | 14 #include <CoreFoundation/CoreFoundation.h> |
15 | 15 |
16 #include "webrtc/base/constructormagic.h" | 16 #include "webrtc/base/constructormagic.h" |
17 #include "webrtc/base/macutils.h" | 17 #include "webrtc/base/macutils.h" |
18 #include "webrtc/base/scoped_ref_ptr.h" | 18 #include "webrtc/base/scoped_ref_ptr.h" |
19 #include "webrtc/modules/desktop_capture/desktop_capturer.h" | 19 #include "webrtc/modules/desktop_capture/desktop_capturer.h" |
20 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | 20 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
21 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 21 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
22 #include "webrtc/modules/desktop_capture/mac/desktop_configuration.h" | 22 #include "webrtc/modules/desktop_capture/mac/desktop_configuration.h" |
23 #include "webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.
h" | 23 #include "webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.
h" |
24 #include "webrtc/modules/desktop_capture/mac/window_list_utils.h" | 24 #include "webrtc/modules/desktop_capture/mac/window_list_utils.h" |
25 #include "webrtc/system_wrappers/include/logging.h" | |
26 | 25 |
27 namespace webrtc { | 26 namespace webrtc { |
28 | 27 |
29 namespace { | 28 namespace { |
30 | 29 |
31 // Returns true if the window exists. | 30 // Returns true if the window exists. |
32 bool IsWindowValid(CGWindowID id) { | 31 bool IsWindowValid(CGWindowID id) { |
33 CFArrayRef window_id_array = | 32 CFArrayRef window_id_array = |
34 CFArrayCreate(nullptr, reinterpret_cast<const void**>(&id), 1, nullptr); | 33 CFArrayCreate(nullptr, reinterpret_cast<const void**>(&id), 1, nullptr); |
35 CFArrayRef window_array = | 34 CFArrayRef window_array = |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 89 |
91 CGWindowID ids[1]; | 90 CGWindowID ids[1]; |
92 ids[0] = window_id_; | 91 ids[0] = window_id_; |
93 CFArrayRef window_id_array = | 92 CFArrayRef window_id_array = |
94 CFArrayCreate(nullptr, reinterpret_cast<const void**>(&ids), 1, nullptr); | 93 CFArrayCreate(nullptr, reinterpret_cast<const void**>(&ids), 1, nullptr); |
95 | 94 |
96 CFArrayRef window_array = | 95 CFArrayRef window_array = |
97 CGWindowListCreateDescriptionFromArray(window_id_array); | 96 CGWindowListCreateDescriptionFromArray(window_id_array); |
98 if (!window_array || 0 == CFArrayGetCount(window_array)) { | 97 if (!window_array || 0 == CFArrayGetCount(window_array)) { |
99 // Could not find the window. It might have been closed. | 98 // Could not find the window. It might have been closed. |
100 LOG(LS_INFO) << "Window not found"; | |
101 CFRelease(window_id_array); | 99 CFRelease(window_id_array); |
102 return false; | 100 return false; |
103 } | 101 } |
104 | 102 |
105 CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>( | 103 CFDictionaryRef window = reinterpret_cast<CFDictionaryRef>( |
106 CFArrayGetValueAtIndex(window_array, 0)); | 104 CFArrayGetValueAtIndex(window_array, 0)); |
107 CFNumberRef pid_ref = reinterpret_cast<CFNumberRef>( | 105 CFNumberRef pid_ref = reinterpret_cast<CFNumberRef>( |
108 CFDictionaryGetValue(window, kCGWindowOwnerPID)); | 106 CFDictionaryGetValue(window, kCGWindowOwnerPID)); |
109 | 107 |
110 int pid; | 108 int pid; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 CGRectNull, kCGWindowListOptionIncludingWindow, | 145 CGRectNull, kCGWindowListOptionIncludingWindow, |
148 on_screen_window, kCGWindowImageBoundsIgnoreFraming); | 146 on_screen_window, kCGWindowImageBoundsIgnoreFraming); |
149 | 147 |
150 if (!window_image) { | 148 if (!window_image) { |
151 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); | 149 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); |
152 return; | 150 return; |
153 } | 151 } |
154 | 152 |
155 int bits_per_pixel = CGImageGetBitsPerPixel(window_image); | 153 int bits_per_pixel = CGImageGetBitsPerPixel(window_image); |
156 if (bits_per_pixel != 32) { | 154 if (bits_per_pixel != 32) { |
157 LOG(LS_ERROR) << "Unsupported window image depth: " << bits_per_pixel; | |
158 CFRelease(window_image); | 155 CFRelease(window_image); |
159 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); | 156 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); |
160 return; | 157 return; |
161 } | 158 } |
162 | 159 |
163 int width = CGImageGetWidth(window_image); | 160 int width = CGImageGetWidth(window_image); |
164 int height = CGImageGetHeight(window_image); | 161 int height = CGImageGetHeight(window_image); |
165 CGDataProviderRef provider = CGImageGetDataProvider(window_image); | 162 CGDataProviderRef provider = CGImageGetDataProvider(window_image); |
166 CFDataRef cf_data = CGDataProviderCopyData(provider); | 163 CFDataRef cf_data = CGDataProviderCopyData(provider); |
167 std::unique_ptr<DesktopFrame> frame( | 164 std::unique_ptr<DesktopFrame> frame( |
(...skipping 21 matching lines...) Expand all Loading... |
189 } // namespace | 186 } // namespace |
190 | 187 |
191 // static | 188 // static |
192 std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawWindowCapturer( | 189 std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawWindowCapturer( |
193 const DesktopCaptureOptions& options) { | 190 const DesktopCaptureOptions& options) { |
194 return std::unique_ptr<DesktopCapturer>( | 191 return std::unique_ptr<DesktopCapturer>( |
195 new WindowCapturerMac(options.full_screen_chrome_window_detector())); | 192 new WindowCapturerMac(options.full_screen_chrome_window_detector())); |
196 } | 193 } |
197 | 194 |
198 } // namespace webrtc | 195 } // namespace webrtc |
OLD | NEW |