Select camera capture rate and verify 30/60 fps pacing
This commit is contained in:
1 parent
cb52ac1b2e
commit
bd5d3f3296
3 files changed
+36
-15
No files matched your search
@@ -49,7 +49,7 @@ public:
|
||||
}
|
||||
return result;
|
||||
}
|
||||
bool start(const QByteArray& device, int width, int height) override {
|
||||
bool start(const QByteArray& device, int width, int height, int fps) override {
|
||||
QCameraDevice selected;
|
||||
for (const auto& item : QMediaDevices::videoInputs()) if (item.id() == device) selected = item;
|
||||
if (selected.isNull()) { emit error(QStringLiteral("Camera is unavailable")); return false; }
|
||||
@@ -59,18 +59,18 @@ public:
|
||||
QCameraFormat best;
|
||||
for (const auto& format : selected.videoFormats()) {
|
||||
if (!stream_video_camera_supports(format.resolution(), format.minFrameRate(), format.maxFrameRate(),
|
||||
{QSize(width, height), 1})) continue;
|
||||
{QSize(width, height), fps})) continue;
|
||||
if (best.isNull() || format.maxFrameRate() < best.maxFrameRate()) best = format;
|
||||
}
|
||||
if (best.isNull()) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CALL, "camera mode unavailable device=%s size=%dx%d fps=30", device.constData(), width, height);
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CALL, "camera mode unavailable device=%s size=%dx%d output_fps=%d", device.constData(), width, height, fps);
|
||||
emit error(QStringLiteral("Selected camera mode is unavailable")); return false;
|
||||
}
|
||||
camera->setCameraFormat(best);
|
||||
const auto format = camera->cameraFormat();
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CALL, "camera selected device=%s size=%dx%d pixel=%d fps=%.3f..%.3f",
|
||||
DEBUG_INFO(DEBUG_CATEGORY_CALL, "camera selected device=%s size=%dx%d pixel=%d capture_fps=%.3f..%.3f output_fps=%d",
|
||||
device.constData(), format.resolution().width(), format.resolution().height(), format.pixelFormat(),
|
||||
format.minFrameRate(), format.maxFrameRate());
|
||||
format.minFrameRate(), format.maxFrameRate(), fps);
|
||||
connect(camera.get(), &QCamera::activeChanged, this, [this, device](bool active) {
|
||||
if (active) rate.activate(device); else rate.restore();
|
||||
});
|
||||
@@ -211,7 +211,7 @@ class CameraWorker : public QObject {
|
||||
post = !slot->posted; slot->posted = true; }
|
||||
if (post) QMetaObject::invokeMethod(this, [this, slot, revision] { convert(slot, revision); }, Qt::QueuedConnection);
|
||||
}, Qt::DirectConnection);
|
||||
if (source->start(device, width, height)) stage(QStringLiteral("running"));
|
||||
if (source->start(device, width, height, fps)) stage(QStringLiteral("running"));
|
||||
} else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user