高 CPU 使用率,超时间隔不同,在桌面复制中获取的帧之间 API
High CPU usage, with different timeouts interval, between frames acquiring in Desktop Duplication API
我正在尝试以 16 毫秒 的超时时间捕获屏幕,并且当捕获在全屏 4k 60fps 视频上进行了测试。 CPU 使用率,在这种情况下,大约是 0-1%。但是当鼠标光标在屏幕上移动时,FPS 和 CPU 使用率上升到 100+ 帧 和 25-30%,分别。所以,有一个问题:为什么我可以得到 FPS 大于 70,如果超时设置为 16?
如果超时设置为 0:使用 相同的值 捕获 FPS 的数量,但 CPU 使用率 保持稳定在 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消耗有关,原因不明.也许是一些自旋锁相关的问题。
我正在尝试以 16 毫秒 的超时时间捕获屏幕,并且当捕获在全屏 4k 60fps 视频上进行了测试。 CPU 使用率,在这种情况下,大约是 0-1%。但是当鼠标光标在屏幕上移动时,FPS 和 CPU 使用率上升到 100+ 帧 和 25-30%,分别。所以,有一个问题:为什么我可以得到 FPS 大于 70,如果超时设置为 16?
如果超时设置为 0:使用 相同的值 捕获 FPS 的数量,但 CPU 使用率 保持稳定在 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 thatAcquireNextFrame
acquires might have only the desktop image updated, only the pointer shape or position updated, or both.
当您移动鼠标时,您会在超时前从桌面复制 API 获得更新。通过这种方式,您可以获得比超时值更多的更新。
至于异常高CPU负载,很可能是API的问题:是的,鼠标移动与过度CPU消耗有关,原因不明.也许是一些自旋锁相关的问题。