| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 callback_ = callback; | 40 callback_ = callback; |
| 41 } | 41 } |
| 42 | 42 |
| 43 void ScreenCapturerWinDirectx::SetSharedMemoryFactory( | 43 void ScreenCapturerWinDirectx::SetSharedMemoryFactory( |
| 44 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) { | 44 std::unique_ptr<SharedMemoryFactory> shared_memory_factory) { |
| 45 shared_memory_factory_ = std::move(shared_memory_factory); | 45 shared_memory_factory_ = std::move(shared_memory_factory); |
| 46 } | 46 } |
| 47 | 47 |
| 48 DesktopSize ScreenCapturerWinDirectx::SelectedDesktopSize() const { | 48 DesktopSize ScreenCapturerWinDirectx::SelectedDesktopSize() const { |
| 49 if (current_screen_id == kFullDesktopScreenId) { | 49 if (current_screen_id_ == kFullDesktopScreenId) { |
| 50 return DxgiDuplicatorController::Instance()->desktop_size(); | 50 return DxgiDuplicatorController::Instance()->desktop_size(); |
| 51 } | 51 } |
| 52 return DxgiDuplicatorController::Instance() | 52 return DxgiDuplicatorController::Instance() |
| 53 ->ScreenRect(current_screen_id) | 53 ->ScreenRect(current_screen_id_) |
| 54 .size(); | 54 .size(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void ScreenCapturerWinDirectx::CaptureFrame() { | 57 void ScreenCapturerWinDirectx::CaptureFrame() { |
| 58 RTC_DCHECK(callback_); | 58 RTC_DCHECK(callback_); |
| 59 | 59 |
| 60 int64_t capture_start_time_nanos = rtc::TimeNanos(); | 60 int64_t capture_start_time_nanos = rtc::TimeNanos(); |
| 61 | 61 |
| 62 frames_.MoveToNextFrame(); | 62 frames_.MoveToNextFrame(); |
| 63 if (!frames_.current_frame()) { | 63 if (!frames_.current_frame()) { |
| 64 std::unique_ptr<DesktopFrame> new_frame; | 64 std::unique_ptr<DesktopFrame> new_frame; |
| 65 if (shared_memory_factory_) { | 65 if (shared_memory_factory_) { |
| 66 new_frame = SharedMemoryDesktopFrame::Create( | 66 new_frame = SharedMemoryDesktopFrame::Create( |
| 67 SelectedDesktopSize(), shared_memory_factory_.get()); | 67 SelectedDesktopSize(), shared_memory_factory_.get()); |
| 68 } else { | 68 } else { |
| 69 new_frame.reset(new BasicDesktopFrame(SelectedDesktopSize())); | 69 new_frame.reset(new BasicDesktopFrame(SelectedDesktopSize())); |
| 70 } | 70 } |
| 71 if (!new_frame) { | 71 if (!new_frame) { |
| 72 LOG(LS_ERROR) << "Failed to allocate a new DesktopFrame."; | 72 LOG(LS_ERROR) << "Failed to allocate a new DesktopFrame."; |
| 73 // This usually means we do not have enough memory or SharedMemoryFactory | 73 // This usually means we do not have enough memory or SharedMemoryFactory |
| 74 // cannot work correctly. | 74 // cannot work correctly. |
| 75 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); | 75 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); |
| 76 return; | 76 return; |
| 77 } | 77 } |
| 78 frames_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(std::move(new_frame))); | 78 frames_.ReplaceCurrentFrame(SharedDesktopFrame::Wrap(std::move(new_frame))); |
| 79 } | 79 } |
| 80 | 80 |
| 81 if (current_screen_id == kFullDesktopScreenId) { | 81 if (current_screen_id_ == kFullDesktopScreenId) { |
| 82 if (!DxgiDuplicatorController::Instance()->Duplicate( | 82 if (!DxgiDuplicatorController::Instance()->Duplicate( |
| 83 &context_, frames_.current_frame())) { | 83 &context_, frames_.current_frame())) { |
| 84 // Screen size may be changed, so we need to reset the frames. | 84 // Screen size may be changed, so we need to reset the frames. |
| 85 frames_.Reset(); | 85 frames_.Reset(); |
| 86 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); | 86 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); |
| 87 return; | 87 return; |
| 88 } | 88 } |
| 89 } else { | 89 } else { |
| 90 if (!DxgiDuplicatorController::Instance()->DuplicateMonitor( | 90 if (!DxgiDuplicatorController::Instance()->DuplicateMonitor( |
| 91 &context_, current_screen_id, frames_.current_frame())) { | 91 &context_, current_screen_id_, frames_.current_frame())) { |
| 92 // Screen size may be changed, so we need to reset the frames. | 92 // Screen size may be changed, so we need to reset the frames. |
| 93 frames_.Reset(); | 93 frames_.Reset(); |
| 94 if (current_screen_id >= | 94 if (current_screen_id_ >= |
| 95 DxgiDuplicatorController::Instance()->ScreenCount()) { | 95 DxgiDuplicatorController::Instance()->ScreenCount()) { |
| 96 // Current monitor has been removed from the system. | 96 // Current monitor has been removed from the system. |
| 97 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); | 97 callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); |
| 98 } else { | 98 } else { |
| 99 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); | 99 callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); |
| 100 } | 100 } |
| 101 return; | 101 return; |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 std::unique_ptr<DesktopFrame> result = frames_.current_frame()->Share(); | 105 std::unique_ptr<DesktopFrame> result = frames_.current_frame()->Share(); |
| 106 result->set_capture_time_ms( | 106 result->set_capture_time_ms( |
| 107 (rtc::TimeNanos() - capture_start_time_nanos) / | 107 (rtc::TimeNanos() - capture_start_time_nanos) / |
| 108 rtc::kNumNanosecsPerMillisec); | 108 rtc::kNumNanosecsPerMillisec); |
| 109 callback_->OnCaptureResult(Result::SUCCESS, std::move(result)); | 109 callback_->OnCaptureResult(Result::SUCCESS, std::move(result)); |
| 110 } | 110 } |
| 111 | 111 |
| 112 bool ScreenCapturerWinDirectx::GetScreenList(ScreenList* screens) { | 112 bool ScreenCapturerWinDirectx::GetScreenList(ScreenList* screens) { |
| 113 int screen_count = DxgiDuplicatorController::Instance()->ScreenCount(); | 113 int screen_count = DxgiDuplicatorController::Instance()->ScreenCount(); |
| 114 for (int i = 0; i < screen_count; i++) { | 114 for (int i = 0; i < screen_count; i++) { |
| 115 screens->push_back(Screen{i}); | 115 screens->push_back(Screen{i}); |
| 116 } | 116 } |
| 117 return true; | 117 return true; |
| 118 } | 118 } |
| 119 | 119 |
| 120 bool ScreenCapturerWinDirectx::SelectScreen(ScreenId id) { | 120 bool ScreenCapturerWinDirectx::SelectScreen(ScreenId id) { |
| 121 if (id == current_screen_id) { | 121 if (id == current_screen_id_) { |
| 122 return true; | 122 return true; |
| 123 } | 123 } |
| 124 | 124 |
| 125 // Changing target screen may or may not impact frame size. So resetting | 125 // Changing target screen may or may not impact frame size. So resetting |
| 126 // frames only when a Duplicate() function call returns false. | 126 // frames only when a Duplicate() function call returns false. |
| 127 if (id == kFullDesktopScreenId) { | 127 if (id == kFullDesktopScreenId) { |
| 128 current_screen_id = id; | 128 current_screen_id_ = id; |
| 129 return true; | 129 return true; |
| 130 } | 130 } |
| 131 | 131 |
| 132 int screen_count = DxgiDuplicatorController::Instance()->ScreenCount(); | 132 int screen_count = DxgiDuplicatorController::Instance()->ScreenCount(); |
| 133 if (id >= 0 && id < screen_count) { | 133 if (id >= 0 && id < screen_count) { |
| 134 current_screen_id = id; | 134 current_screen_id_ = id; |
| 135 return true; | 135 return true; |
| 136 } | 136 } |
| 137 return false; | 137 return false; |
| 138 } | 138 } |
| 139 | 139 |
| 140 } // namespace webrtc | 140 } // namespace webrtc |
| OLD | NEW |