桌面复制 API - DXGI_OUTDUPL_FRAME_INFO.LastPresentTime 在我重新启动计算机后的前 5 分钟为 0

问题描述 投票:0回答:1

我使用桌面复制 API 来截取桌面屏幕截图。除了重新启动计算机后的前 5 分钟外,它工作正常。在前 5 分钟内,

lFrameInfo.LastPresentTime.HighPart
始终为 0,因此 CaptureScreen() 函数会退出而不进行屏幕截图。如果我用
lFrameInfo.LastPresentTime.HighPart == 0
检查去掉 if,那么代码可以工作,但每次鼠标移动时都会截取屏幕截图,即使屏幕没有改变。

根据 LastPresentTime 的文档:“零值表示自应用程序上次调用 IDXGIOutputDuplication::AcquireNextFrame 方法来获取桌面图像的下一帧以来,桌面图像未更新。”但这对于我,即使我观看 60fps 的 youtube 视频,电脑重启后的前 5 分钟 LastPresentTime 也是 0。

我的系统:Win10 x64,13900k,RTX 4700

这是代码:

bool DXGIScreenCapture::CaptureScreen()
{
    HRESULT hr(E_FAIL);
    IDXGIResource* lDesktopResource = nullptr;
    DXGI_OUTDUPL_FRAME_INFO lFrameInfo;

    hr = _lDeskDupl->AcquireNextFrame(500, &lFrameInfo, &lDesktopResource);
    if (FAILED(hr))
        return false;

    if (lFrameInfo.LastPresentTime.HighPart == 0) // not interested in just mouse updates, which can happen much faster than 60fps if you really shake the mouse
    {
        hr = _lDeskDupl->ReleaseFrame();
        return false;
    }

    // QI for ID3D11Texture2D
    hr = lDesktopResource->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&_lAcquiredDesktopImage));
    lDesktopResource->Release();
    lDesktopResource = nullptr;
    if (FAILED(hr))
    {
        hr = _lDeskDupl->ReleaseFrame();
        return false;
    }

    _lImmediateContext->CopyResource(currTexture, _lAcquiredDesktopImage);
    UINT subresource = D3D11CalcSubresource(0, 0, 0);
    _lImmediateContext->Map(currTexture, subresource, D3D11_MAP_READ, 0, &_resource);
    _lImmediateContext->Unmap(currTexture, 0);
    hr = _lDeskDupl->ReleaseFrame();

    return true;
}
c++ winapi directx screen-capture desktop-duplication
1个回答
0
投票

根据DXGI_OUTDUPL_FRAME_INFO结构,

操作系统调用QueryPerformanceCounter函数来 获取值。

并根据获取高分辨率时间戳

QueryPerformanceCounter 读取性能计数器并返回 自 Windows 运行以来 发生的刻度总数 系统已启动,包括机器处于睡眠状态的时间 状态,例如待机、休眠或连接待机。

所以,自 Windows 操作系统启动以来,刻度线的

HighPart
0
是正确的。要使用 LARGE_INTEGER 联合,

如果您的编译器内置了对 64 位整数的支持,请使用 QuadPart 成员存储 64 位整数。否则,请使用 LowPart 和 HighPart 成员存储 64 位整数。

© www.soinside.com 2019 - 2024. All rights reserved.