diff --git a/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc b/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc index 83e0fda5ff..0cefb86cdc 100644 --- a/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc +++ b/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.cc @@ -25,22 +25,6 @@ namespace webrtc { -namespace { - -// TODO(zijiehe): This function should be public as -// static bool DxgiDuplicatorController::IsSessionUnsupported() -bool IsRunningInSession0() { - DWORD session_id = 0; - if (!::ProcessIdToSessionId(::GetCurrentProcessId(), &session_id)) { - LOG(LS_WARNING) << "Failed to retrieve current session Id, current binary " - "may not have required priviledge."; - return true; - } - return session_id == 0; -} - -} // namespace - // static rtc::scoped_refptr DxgiDuplicatorController::Instance() { @@ -50,6 +34,17 @@ DxgiDuplicatorController::Instance() { return rtc::scoped_refptr(instance); } +// static +bool DxgiDuplicatorController::IsCurrentSessionSupported() { + DWORD session_id = 0; + if (!::ProcessIdToSessionId(::GetCurrentProcessId(), &session_id)) { + LOG(LS_WARNING) << "Failed to retrieve current session Id, current binary " + "may not have required priviledge."; + return false; + } + return session_id != 0; +} + DxgiDuplicatorController::DxgiDuplicatorController() : refcount_(0) {} @@ -148,7 +143,7 @@ DxgiDuplicatorController::DoDuplicate(DxgiFrame* frame, int monitor_id) { } if (!Initialize()) { - if (succeeded_duplications_ == 0 && IsRunningInSession0()) { + if (succeeded_duplications_ == 0 && !IsCurrentSessionSupported()) { LOG(LS_WARNING) << "Current binary is running in session 0. DXGI " "components cannot be initialized."; return Result::UNSUPPORTED_SESSION; diff --git a/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h b/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h index 0b0990d73d..8ea7f183c2 100644 --- a/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h +++ b/webrtc/modules/desktop_capture/win/dxgi_duplicator_controller.h @@ -71,6 +71,9 @@ class DxgiDuplicatorController { // Returns the singleton instance of DxgiDuplicatorController. static rtc::scoped_refptr Instance(); + // See ScreenCapturerWinDirectx::IsCurrentSessionSupported(). + static bool IsCurrentSessionSupported(); + // All the following public functions implicitly call Initialize() function. // Detects whether the system supports DXGI based capturer. diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.cc b/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.cc index 74b7b4501a..722353e4f3 100644 --- a/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.cc +++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.cc @@ -36,6 +36,11 @@ bool ScreenCapturerWinDirectx::RetrieveD3dInfo(D3dInfo* info) { return DxgiDuplicatorController::Instance()->RetrieveD3dInfo(info); } +// static +bool ScreenCapturerWinDirectx::IsCurrentSessionSupported() { + return DxgiDuplicatorController::IsCurrentSessionSupported(); +} + ScreenCapturerWinDirectx::ScreenCapturerWinDirectx() : controller_(DxgiDuplicatorController::Instance()) {} diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h b/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h index 5064a9623b..f383303b5d 100644 --- a/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h +++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.h @@ -44,6 +44,13 @@ class ScreenCapturerWinDirectx : public DesktopCapturer { // consumers should not cache the result returned by this function. static bool RetrieveD3dInfo(D3dInfo* info); + // Whether current process is running in a Windows session which is supported + // by ScreenCapturerWinDirectx. + // Usually using ScreenCapturerWinDirectx in unsupported sessions will fail. + // But this behavior may vary on different Windows version. So consumers can + // always try IsSupported() function. + static bool IsCurrentSessionSupported(); + explicit ScreenCapturerWinDirectx(); ~ScreenCapturerWinDirectx() override;