camera: actually check whether the formats we attempt using are supported
This commit is contained in:
parent
a1a342143b
commit
42a33b9282
|
@ -165,16 +165,41 @@ void CameraManager::init()
|
||||||
|
|
||||||
#if QT_VERSION >= 0x060000
|
#if QT_VERSION >= 0x060000
|
||||||
const QList<QCameraDevice> cameras = QMediaDevices::videoInputs();
|
const QList<QCameraDevice> cameras = QMediaDevices::videoInputs();
|
||||||
for (const QCameraDevice &cam : cameras)
|
const QCameraDevice& dev;
|
||||||
|
for (const QCameraDevice& cam : cameras)
|
||||||
{
|
{
|
||||||
if (QString(cam.id()) == camDeviceName)
|
if (QString(cam.id()) == camDeviceName)
|
||||||
{
|
{
|
||||||
|
dev = cam;
|
||||||
camDevice = new QCamera(cam);
|
camDevice = new QCamera(cam);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (camDevice)
|
if (camDevice)
|
||||||
|
{
|
||||||
|
const QList<QCameraFormat> supported = dev.videoFormats();
|
||||||
|
bool good = false;
|
||||||
|
for (const QCameraFormat& item : supported)
|
||||||
|
{
|
||||||
|
if (item.pixelFormat() != QVideoFrameFormat::Format_YUYV &&
|
||||||
|
item.pixelFormat() != QVideoFrameFormat::Format_XRGB8888)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (item.resolution().width() != 640 && item.resolution().height() != 480)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
camDevice->setCameraFormat(item);
|
||||||
|
good = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!good)
|
||||||
|
{
|
||||||
|
delete camDevice;
|
||||||
|
camDevice = nullptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
camDumper = new CameraFrameDumper(this);
|
camDumper = new CameraFrameDumper(this);
|
||||||
|
|
||||||
|
@ -182,29 +207,47 @@ void CameraManager::init()
|
||||||
camSession->setCamera(camDevice);
|
camSession->setCamera(camDevice);
|
||||||
camSession->setVideoOutput(camDumper);
|
camSession->setVideoOutput(camDumper);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
camDevice = new QCamera(camDeviceName.toUtf8());
|
camDevice = new QCamera(camDeviceName.toUtf8());
|
||||||
|
if (camDevice->error() != QCamera::NoError)
|
||||||
|
{
|
||||||
|
delete camDevice;
|
||||||
|
camDevice = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
if (camDevice)
|
if (camDevice)
|
||||||
{
|
{
|
||||||
camDumper = new CameraFrameDumper(this);
|
camDevice->load();
|
||||||
camDevice->setViewfinder(camDumper);
|
|
||||||
|
|
||||||
/*camDevice->load();
|
const QList<QCameraViewfinderSettings> supported = camDevice->supportedViewfinderSettings();
|
||||||
QCameraViewfinderSettings settings;
|
bool good = false;
|
||||||
|
for (const QCameraViewfinderSettings& item : supported)
|
||||||
auto resolutions = camDevice->supportedViewfinderResolutions();
|
|
||||||
for (auto& res : resolutions)
|
|
||||||
{
|
{
|
||||||
printf("RESOLUTION: %d x %d\n", res.width(), res.height());
|
if (item.pixelFormat() != QVideoFrame::Format_YUYV &&
|
||||||
|
item.pixelFormat() != QVideoFrame::Format_RGB32)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (item.resolution().width() != 640 && item.resolution().height() != 480)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
camDevice->setViewfinderSettings(item);
|
||||||
|
good = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
camDevice->unload();*/
|
camDevice->unload();
|
||||||
|
|
||||||
QCameraViewfinderSettings settings;
|
if (!good)
|
||||||
settings.setResolution(640, 480);
|
{
|
||||||
settings.setPixelFormat(QVideoFrame::Format_YUYV);
|
delete camDevice;
|
||||||
camDevice->setViewfinderSettings(settings);
|
camDevice = nullptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
camDumper = new CameraFrameDumper(this);
|
||||||
|
camDevice->setViewfinder(camDumper);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue