Skip to content
This repository was archived by the owner on Oct 10, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/drivers/v4l2/v4l2device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ void V4L2Device::__ioctl(uint64_t ctl, void* data, const QString& errorLabel) co
//qDebug() << "IOCTL RUN: %1 with result %2"_q % d->ioctl_names.value(ctl, "%1"_q % ctl) % r;
}

int V4L2Device::__xioctl(uint64_t ctl, void* data, const QString& errorLabel) const
int V4L2Device::__xioctl(uint64_t ctl, void* data, const QString &errorLabel, int ok_errno) const
{
try {
this->ioctl(ctl, data, errorLabel);
return 0;
} catch(const V4L2Exception &e) {
qWarning() << e.what();
if (errno != ok_errno)
qWarning() << e.what();
return -1;
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/drivers/v4l2/v4l2device.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,17 @@ class V4L2Device {
inline operator bool() const;
int descriptor() const;

template<typename T> void ioctl(uint64_t ctl, T *data, const QString &errorLabel = {}) const { return __ioctl(ctl, reinterpret_cast<void*>(data), errorLabel); }
template<typename T> int xioctl(uint64_t ctl, T *data, const QString &errorLabel = {}) const { return __xioctl(ctl, reinterpret_cast<void*>(data), errorLabel); }
template<typename T> void ioctl(uint64_t ctl, T *data, const QString &errorLabel = {}) const {
return __ioctl(ctl, reinterpret_cast<void*>(data), errorLabel);
}

template<typename T> int xioctl(uint64_t ctl, T *data, const QString &errorLabel = {}, int ok_errno = 0) const {
return __xioctl(ctl, reinterpret_cast<void*>(data), errorLabel, ok_errno);
}

private:
void __ioctl(uint64_t ctl, void *data, const QString &errorLabel) const;
int __xioctl(uint64_t ctl, void *data, const QString &errorLabel) const;
int __xioctl(uint64_t ctl, void *data, const QString &errorLabel, int ok_errno) const;
DPTR
};

Expand Down
7 changes: 5 additions & 2 deletions src/drivers/v4l2/v4l2formats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ V4L2Formats::V4L2Formats(const V4L2DevicePtr& device) : dptr(device)
v4l2_fmtdesc formats;
formats.index = 0;
formats.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
for(formats.index = 0; 0 ==device->xioctl(VIDIOC_ENUM_FMT, &formats); formats.index++) {
while (0 == device->xioctl(VIDIOC_ENUM_FMT, &formats, {}, EINVAL)) {
d->formats.push_back(make_shared<V4L2Format>(formats, device));
formats.index++;
}
for(auto format: d->formats)
qDebug() << "Found format: " << *format;
Expand Down Expand Up @@ -106,9 +107,11 @@ V4L2ResolutionPtr V4L2Formats::current_resolution() const
V4L2Format::V4L2Format(const v4l2_fmtdesc &fmtdesc, const V4L2DevicePtr &device) : dptr(fmtdesc, device)
{
v4l2_frmsizeenum frmsize;
frmsize.index = 0;
frmsize.pixel_format = fmtdesc.pixelformat;
for(frmsize.index = 0; device->xioctl(VIDIOC_ENUM_FRAMESIZES, &frmsize, "querying resolutions") >= 0; frmsize.index++) {
while (device->xioctl(VIDIOC_ENUM_FRAMESIZES, &frmsize, "querying resolutions", EINVAL) >= 0) {
d->resolutions.push_back(make_shared<V4L2Resolution>(frmsize, device, *this));
frmsize.index++;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/drivers/v4l2/v4l2imagingworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ void V4L2ImagingWorker::Private::adjust_framerate()
fps_s.height = format.fmt.pix.height;
fps_s.pixel_format = format.fmt.pix.pixelformat;
qDebug() << "scanning for fps with pixel format " << FOURCC2QS(fps_s.pixel_format);
for(fps_s.index = 0; device->xioctl(VIDIOC_ENUM_FRAMEINTERVALS, &fps_s) >= 0; fps_s.index++) {
while (device->xioctl(VIDIOC_ENUM_FRAMEINTERVALS, &fps_s, {}, EINVAL) >= 0) {
qDebug() << "found fps: " << fps_s;
rates.push_back(fps_s);
fps_s.index++;
}
auto ratio = [=](const v4l2_frmivalenum &a) { return static_cast<double>(a.discrete.numerator)/static_cast<double>(a.discrete.denominator); };
sort(begin(rates), end(rates), [&](const v4l2_frmivalenum &a, const v4l2_frmivalenum &b){ return ratio(a) < ratio(b);} );
Expand Down