libuvc摄像头设备重新打开(uvc_open)崩溃

时间:2020-08-17 02:06:29

标签: android macos uvc

我有一个Android应用,该应用使用libuvc来呈现MJPEG格式的视频以捕获MJPEG帧,除了Logitech BRIO和Logitech Rally的分辨率为720P +(800x600、640x480以下)之外,大多数网络摄像头都不错,libuvc通过了部分,回调到应用程序的MJPEG帧损坏。 但是macOS工具使用这两个网络摄像头渲染720P +时没有问题,为了调查问题,我创建了一个macOS测试应用程序(与GUI调用libuvc的Swift GUI交谈),当我同时选择两个设备时,我将两个网络摄像头连接到了Mac第一次,我没有任何问题,但是当我再次选择其中一个设备时,uvc_open会崩溃:

通过以下步骤重现该问题:

  1. 运行应用程序
  2. 选择BRIO(关闭现有的,uvc_open新的),没问题
  3. 选择拉力赛,没问题
  4. 再次选择BRIO,uvc_open崩溃。

我有一个向量,可以检测所有设备:

std::vector<uvc_device_t*> devAry;
uvc_device_handle_t *devh = NULL;

设备选择方法(按索引)

int Camera::setCurrentDevice(int idx)
{
    if (idx < 0 || idx >= (int)devAry.size())
    {
        return -1;
    }

    //Need close current device
    if (devh != NULL)
    {
        //TODO: do we need other clean up before close the devic handle?
        uvc_close(devh);
        uvc_unref_device(devAry[currentDeviceIdx]->dev);
        devh = NULL;
    }
    currentDeviceIdx = idx;
    try
    {
        auto res = uvc_open(devAry[currentDeviceIdx]->dev, &devh);
        if (res != UVC_SUCCESS)
        {
            loggerEx(LOG_DEBUG, "Failed to open device: %s", uvc_strerror(res));
            return res;
        }
    } catch(std::exception& e)
    {
        loggerEx(LOG_DEBUG, "Failed to open the device:%s", e.what());
        return -1;
    }
    return 0;
}

是libuvc的错误还是我的错误?

谢谢

0 个答案:

没有答案