在进入while (!gWaiter.isStopped() && (pending = gWaiter.waitForFrame()) > 0)循环后
刷新当前的屏幕旋转信息(使用minicap自带函数)
if (minicap_try_get_display_info(displayId, &info) != 0)
{
if (try_get_framebuffer_display_info(displayId, &info) != 0)
{
MCERROR("Unable to get display info");
return EXIT_FAILURE;
}
}
然后判断屏幕角度是否改变,进行修改
if (desiredInfo.orientation != info.orientation)
{
desiredInfo.orientation = info.orientation;
if (minicap->setDesiredInfo(desiredInfo) != 0)
{
MCERROR("Minicap did not accept desired display info");
goto disaster;
}
if (minicap->applyConfigChanges() != 0)
{
MCERROR("Unable to start minicap with current config");
goto disaster;
}
else
continue;
}
continue很重要因,因为涉及到对象的创建与销毁,不跳出就会有概率出现
ERROR: (external/MY_minicap/src/minicap_26.cpp:124: errno: None) Unable to lock next buffer BAD_VALUE (-22)
ERROR: (jni/minicap/minicap.cpp:608: errno: None) Unable to consume pending frame
INFO: (external/MY_minicap/src/minicap_26.cpp:291) Destroying virtual display
所以请尽可能早的进行方向判断
全部代码
while (!gWaiter.isStopped() && (pending = gWaiter.waitForFrame()) > 0)
{
if (minicap_try_get_display_info(displayId, &info) != 0)
{
if (try_get_framebuffer_display_info(displayId, &info) != 0)
{
MCERROR("Unable to get display info");
return EXIT_FAILURE;
}
}
if (desiredInfo.orientation != info.orientation)
{
desiredInfo.orientation = info.orientation;
if (minicap->setDesiredInfo(desiredInfo) != 0)
{
MCERROR("Minicap did not accept desired display info");
goto disaster;
}
if (minicap->applyConfigChanges() != 0)
{
MCERROR("Unable to start minicap with current config");
goto disaster;
}
else
continue;
}
auto frameAvailableAt = std::chrono::steady_clock::now();
if (skipFrames && pending > 1)
{
// Skip frames if we have too many. Not particularly thread safe,
// but this loop should be the only consumer anyway (i.e. nothing
// else decreases the frame count).
gWaiter.reportExtraConsumption(pending - 1);
while (--pending >= 1)
{
if ((err = minicap->consumePendingFrame(&frame)) != 0)
{
if (err == -EINTR)
{
MCINFO("Frame consumption interrupted by EINTR");
goto close;
}
else
{
MCERROR("Unable to skip pending frame");
goto disaster;
}
}
minicap->releaseConsumedFrame(&frame);
}
}
}
.........
}
....为后续代码