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 "webrtc/modules/desktop_capture/screen_capturer.h" | 11 #include "webrtc/modules/desktop_capture/screen_capturer.h" |
12 | 12 |
13 #include <stddef.h> | 13 #include <stddef.h> |
14 | 14 |
15 #include <memory> | 15 #include <memory> |
16 #include <set> | 16 #include <set> |
17 | 17 |
18 #include <ApplicationServices/ApplicationServices.h> | 18 #include <ApplicationServices/ApplicationServices.h> |
19 #include <Cocoa/Cocoa.h> | 19 #include <Cocoa/Cocoa.h> |
20 #include <dlfcn.h> | 20 #include <dlfcn.h> |
21 #include <IOKit/pwr_mgt/IOPMLib.h> | 21 #include <IOKit/pwr_mgt/IOPMLib.h> |
22 #include <OpenGL/CGLMacro.h> | 22 #include <OpenGL/CGLMacro.h> |
23 #include <OpenGL/OpenGL.h> | 23 #include <OpenGL/OpenGL.h> |
24 | 24 |
25 #include "webrtc/base/checks.h" | |
26 #include "webrtc/base/macutils.h" | 25 #include "webrtc/base/macutils.h" |
27 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | 26 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
28 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 27 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
29 #include "webrtc/modules/desktop_capture/desktop_geometry.h" | 28 #include "webrtc/modules/desktop_capture/desktop_geometry.h" |
30 #include "webrtc/modules/desktop_capture/desktop_region.h" | 29 #include "webrtc/modules/desktop_capture/desktop_region.h" |
31 #include "webrtc/modules/desktop_capture/mac/desktop_configuration.h" | 30 #include "webrtc/modules/desktop_capture/mac/desktop_configuration.h" |
32 #include "webrtc/modules/desktop_capture/mac/desktop_configuration_monitor.h" | 31 #include "webrtc/modules/desktop_capture/mac/desktop_configuration_monitor.h" |
33 #include "webrtc/modules/desktop_capture/mac/scoped_pixel_buffer_object.h" | 32 #include "webrtc/modules/desktop_capture/mac/scoped_pixel_buffer_object.h" |
34 #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" | 33 #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" |
35 #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" | 34 #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" |
36 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" | |
37 #include "webrtc/system_wrappers/include/logging.h" | 35 #include "webrtc/system_wrappers/include/logging.h" |
38 #include "webrtc/system_wrappers/include/tick_util.h" | 36 #include "webrtc/system_wrappers/include/tick_util.h" |
39 | 37 |
40 namespace webrtc { | 38 namespace webrtc { |
41 | 39 |
42 namespace { | 40 namespace { |
43 | 41 |
44 // Definitions used to dynamic-link to deprecated OS 10.6 functions. | 42 // Definitions used to dynamic-link to deprecated OS 10.6 functions. |
45 const char* kApplicationServicesLibraryName = | 43 const char* kApplicationServicesLibraryName = |
46 "/System/Library/Frameworks/ApplicationServices.framework/" | 44 "/System/Library/Frameworks/ApplicationServices.framework/" |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 void ReleaseBuffers(); | 227 void ReleaseBuffers(); |
230 | 228 |
231 DesktopFrame* CreateFrame(); | 229 DesktopFrame* CreateFrame(); |
232 | 230 |
233 Callback* callback_; | 231 Callback* callback_; |
234 | 232 |
235 CGLContextObj cgl_context_; | 233 CGLContextObj cgl_context_; |
236 ScopedPixelBufferObject pixel_buffer_object_; | 234 ScopedPixelBufferObject pixel_buffer_object_; |
237 | 235 |
238 // Queue of the frames buffers. | 236 // Queue of the frames buffers. |
239 ScreenCaptureFrameQueue<SharedDesktopFrame> queue_; | 237 ScreenCaptureFrameQueue queue_; |
240 | 238 |
241 // Current display configuration. | 239 // Current display configuration. |
242 MacDesktopConfiguration desktop_config_; | 240 MacDesktopConfiguration desktop_config_; |
243 | 241 |
244 // Currently selected display, or 0 if the full desktop is selected. On OS X | 242 // Currently selected display, or 0 if the full desktop is selected. On OS X |
245 // 10.6 and before, this is always 0. | 243 // 10.6 and before, this is always 0. |
246 CGDirectDisplayID current_display_; | 244 CGDirectDisplayID current_display_; |
247 | 245 |
248 // The physical pixel bounds of the current screen. | 246 // The physical pixel bounds of the current screen. |
249 DesktopRect screen_pixel_bounds_; | 247 DesktopRect screen_pixel_bounds_; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 IOPMAssertionCreateWithName(CFSTR("UserIsActive"), | 377 IOPMAssertionCreateWithName(CFSTR("UserIsActive"), |
380 kIOPMAssertionLevelOn, | 378 kIOPMAssertionLevelOn, |
381 CFSTR("Chrome Remote Desktop connection active"), | 379 CFSTR("Chrome Remote Desktop connection active"), |
382 &power_assertion_id_user_); | 380 &power_assertion_id_user_); |
383 } | 381 } |
384 | 382 |
385 void ScreenCapturerMac::Capture(const DesktopRegion& region_to_capture) { | 383 void ScreenCapturerMac::Capture(const DesktopRegion& region_to_capture) { |
386 TickTime capture_start_time = TickTime::Now(); | 384 TickTime capture_start_time = TickTime::Now(); |
387 | 385 |
388 queue_.MoveToNextFrame(); | 386 queue_.MoveToNextFrame(); |
389 RTC_DCHECK(!queue_.current_frame() || !queue_.current_frame()->IsShared()); | |
390 | 387 |
391 desktop_config_monitor_->Lock(); | 388 desktop_config_monitor_->Lock(); |
392 MacDesktopConfiguration new_config = | 389 MacDesktopConfiguration new_config = |
393 desktop_config_monitor_->desktop_configuration(); | 390 desktop_config_monitor_->desktop_configuration(); |
394 if (!desktop_config_.Equals(new_config)) { | 391 if (!desktop_config_.Equals(new_config)) { |
395 desktop_config_ = new_config; | 392 desktop_config_ = new_config; |
396 // If the display configuraiton has changed then refresh capturer data | 393 // If the display configuraiton has changed then refresh capturer data |
397 // structures. Occasionally, the refresh and move handlers are lost when | 394 // structures. Occasionally, the refresh and move handlers are lost when |
398 // the screen mode changes, so re-register them here. | 395 // the screen mode changes, so re-register them here. |
399 UnregisterRefreshAndMoveHandlers(); | 396 UnregisterRefreshAndMoveHandlers(); |
400 RegisterRefreshAndMoveHandlers(); | 397 RegisterRefreshAndMoveHandlers(); |
401 ScreenConfigurationChanged(); | 398 ScreenConfigurationChanged(); |
402 } | 399 } |
403 | 400 |
404 DesktopRegion region; | 401 DesktopRegion region; |
405 helper_.TakeInvalidRegion(®ion); | 402 helper_.TakeInvalidRegion(®ion); |
406 | 403 |
407 // If the current buffer is from an older generation then allocate a new one. | 404 // If the current buffer is from an older generation then allocate a new one. |
408 // Note that we can't reallocate other buffers at this point, since the caller | 405 // Note that we can't reallocate other buffers at this point, since the caller |
409 // may still be reading from them. | 406 // may still be reading from them. |
410 if (!queue_.current_frame()) | 407 if (!queue_.current_frame()) |
411 queue_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(CreateFrame())); | 408 queue_.ReplaceCurrentFrame(CreateFrame()); |
412 | 409 |
413 DesktopFrame* current_frame = queue_.current_frame(); | 410 DesktopFrame* current_frame = queue_.current_frame(); |
414 | 411 |
415 bool flip = false; // GL capturers need flipping. | 412 bool flip = false; // GL capturers need flipping. |
416 if (rtc::GetOSVersionName() >= rtc::kMacOSLion) { | 413 if (rtc::GetOSVersionName() >= rtc::kMacOSLion) { |
417 // Lion requires us to use their new APIs for doing screen capture. These | 414 // Lion requires us to use their new APIs for doing screen capture. These |
418 // APIS currently crash on 10.6.8 if there is no monitor attached. | 415 // APIS currently crash on 10.6.8 if there is no monitor attached. |
419 if (!CgBlitPostLion(*current_frame, region)) { | 416 if (!CgBlitPostLion(*current_frame, region)) { |
420 desktop_config_monitor_->Unlock(); | 417 desktop_config_monitor_->Unlock(); |
421 callback_->OnCaptureCompleted(NULL); | 418 callback_->OnCaptureCompleted(NULL); |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
984 return NULL; | 981 return NULL; |
985 | 982 |
986 std::unique_ptr<ScreenCapturerMac> capturer( | 983 std::unique_ptr<ScreenCapturerMac> capturer( |
987 new ScreenCapturerMac(options.configuration_monitor())); | 984 new ScreenCapturerMac(options.configuration_monitor())); |
988 if (!capturer->Init()) | 985 if (!capturer->Init()) |
989 capturer.reset(); | 986 capturer.reset(); |
990 return capturer.release(); | 987 return capturer.release(); |
991 } | 988 } |
992 | 989 |
993 } // namespace webrtc | 990 } // namespace webrtc |
OLD | NEW |