Expose IsCurrentSessionSupported() from ScreenCapturerWinDirectx

IsCurrentSessionSupported() is useful to decide whether Windows version should
be used to evaluate the capability of DirectX capturer on the system.

Bug: 741926
Change-Id: Iaaf6011a9e464d7cf5e7dda097007778c73953e0
Reviewed-on: https://chromium-review.googlesource.com/571378
Commit-Queue: Zijie He <zijiehe@chromium.org>
Reviewed-by: Sergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#19060}
This commit is contained in:
Zijie He 2017-07-13 16:20:02 -07:00 committed by Commit Bot
parent cfd3c327a8
commit 44967e41c5
4 changed files with 27 additions and 17 deletions

View File

@ -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>
DxgiDuplicatorController::Instance() {
@ -50,6 +34,17 @@ DxgiDuplicatorController::Instance() {
return rtc::scoped_refptr<DxgiDuplicatorController>(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;

View File

@ -71,6 +71,9 @@ class DxgiDuplicatorController {
// Returns the singleton instance of DxgiDuplicatorController.
static rtc::scoped_refptr<DxgiDuplicatorController> Instance();
// See ScreenCapturerWinDirectx::IsCurrentSessionSupported().
static bool IsCurrentSessionSupported();
// All the following public functions implicitly call Initialize() function.
// Detects whether the system supports DXGI based capturer.

View File

@ -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()) {}

View File

@ -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;