gpt4 book ai didi

c++ - 在 Desktop Duplication API 中获取的帧之间的 CPU 使用率高,超时间隔不同

转载 作者:太空宇宙 更新时间:2023-11-04 12:30:44 28 4
gpt4 key购买 nike

我正在尝试以 16 毫秒 的超时时间捕获屏幕,并且在全屏 4k 60fps 上测试捕获时我得到 60-65 FPS视频。在这种情况下,CPU 使用率大约为 0-1%。但是,当鼠标光标在屏幕上移动时,FPS 和 CPU 使用率分别上升到 100+ 帧25-30%。那么,问题来了:如果超时设置为 16,为什么我可以得到大于 70 的 FPS

如果超时设置为 0:FPS 数量 将使用相同的值 捕获,但CPU 使用率 保持稳定在 < strong>20-30%,即使屏幕上有静态图像。在这种情况下,超时错误数量显着增加。这是否与上一个问题有某种关联?

do
{
hr = lDeskDupl->AcquireNextFrame(
TimeoutMS,
&lFrameInfo,
&lDesktopResource);

if (SUCCEEDED(hr)) {
accumFramesCount += lFrameInfo.AccumulatedFrames;
break;
}

if (hr == DXGI_ERROR_INVALID_CALL)
{
lDeskDupl->ReleaseFrame();
}

if (hr == DXGI_ERROR_WAIT_TIMEOUT)
{
timeoutsCount++;
}
}
while (true);

最佳答案

答案在AcquireNextFrame文档中:

AcquireNextFrame acquires a new desktop frame when the operating system either updates the desktop bitmap image or changes the shape or position of a hardware pointer. The new frame that AcquireNextFrame acquires might have only the desktop image updated, only the pointer shape or position updated, or both.

当您移动鼠标时,您会在超时前从桌面复制 API 获得更新。通过这种方式,您获得的更新数量超过超时值所暗示的数量。

至于异常高的 CPU 负载,很可能是 API 的问题:是的,鼠标移动与过度的 CPU 消耗有关,没有明显的原因。也许是一些与自旋锁相关的问题。

关于c++ - 在 Desktop Duplication API 中获取的帧之间的 CPU 使用率高,超时间隔不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58741430/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com