minicap 增加自动转屏功能

在进入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);
        }
      }
}
.........
}

....为后续代码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值