summaryrefslogtreecommitdiff
path: root/src/qcam/main.cpp
AgeCommit message (Collapse)Author
2020-12-01qcam: Make log less verbose by defaultLaurent Pinchart
The qcam log prints one message per frame, which is pretty verbose. This feature is useful for debugging, but not necessarily as a default option. Silence it by default, and add a -v/--verbose command line parameter to make the log verbose. While this could have been handled manually by checking a verbose flag when printing the message, the feature is instead integrated with the Qt log infrastructure to make it more flexible. Messages printed by qDebug() are now silenced by default and controlled by the -v/--verbose argument. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2020-12-01qcam: main: Fix comment incorrectly referring to the cam applicationLaurent Pinchart
The top file description comment was incorrectly copied from the cam application. Fix it. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2020-09-15qcam: Add additional command line option to select the renderer typeShow Liu
Add new option "--renderer=qt|gles" to select the renderer type, "--renderer=gles" to accelerate format conversion and rendering "--renderer=qt" is the original Qt rendering. Signed-off-by: Show Liu <show.liu@linaro.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-08-25meson: Remove -Wno-unused-parameterLaurent Pinchart
We build libcamera with -Wno-unused-parameter and this doesn't cause much issue internally. However, it prevents catching unused parameters in inline functions defined in public headers. This can lead to compilation warnings for applications compiled without -Wno-unused-parameter. To catch those issues, remove -Wno-unused-parameter and fix all the related warnings with [[maybe_unused]]. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-05-01qcam: Make use of StreamKeyValueParserNiklas Söderlund
Use the StreamKeyValueParser helper to parse stream configuration from the command line. This extends qcam to accept role hints and pixel format in addition to a size. Currently only one viewfinder stream is supported, add a check to keep this behavior. Going forward this restriction will be lifted to support more then one stream. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-24qcam: Use Qt qInfo() and qWarning() logging facilitiesLaurent Pinchart
Replace manual usage of std::cout and std::cerr with the Qt logging facilities. This allows redirection log output if needed, and integrates better with Qt. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-03-24qcam: Remove custom event dispatcherLaurent Pinchart
The qcam application installs a custom event dispatcher based on the Qt event loop. As the camera manager now creates an internal thread, it doesn't use that event dispatcher of the application thread at all. Furthermore, the custom event dispatcher is buggy, as it doesn't dispatch messages posted to the main thread's event loop. This isn't an issue as no messages are posted there in the first place, but would cause incorrect behaviour if we were to use that feature (for instance to deliver signals from the camera manager thread to the application thread). Fixing the event dispatcher requires a change in the libcamera public API, as there's currently no way to dispatch messages using the public API (Thread::dispatchMessages() is not exposed). This isn't worth it at the moment, so just remove the custom event dispatcher. If qcam later needs the libcamera request and buffer completion signals to be delivered in the application thread, it will need to handle that internally, using Qt's cross-thread signal delivery. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-08-19libcamera: camera_manager: Construct CameraManager instances manuallyLaurent Pinchart
The CameraManager class is not supposed to be instantiated multiple times, which led to a singleton implementation. This requires a global instance of the CameraManager, which is destroyed when the global destructors are executed. Relying on global instances causes issues with cleanup, as the order in which the global destructors are run can't be controlled. In particular, the Android camera HAL implementation ends up destroying the CameraHalManager after the CameraManager, which leads to use-after-free problems. To solve this, remove the CameraManager::instance() method and make the CameraManager class instantiable directly. Multiple instances are still not allowed, and this is enforced by storing the instance pointer internally to be checked when an instance is created. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-08-19qcam: Pass camera manager to MainWindow classLaurent Pinchart
Pass the CameraManager instance from the main() function to the MainWindow class instead of accessing it through CameraManager::instance(). This prepares for the removal of the CameraManager::instance() method. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-07-17libcamera: qcam: Allow specifying sizes on command lineJacopo Mondi
Add a '-s|--size' option to qcam to allow selecting the stream resolution using a command line option. If the sizes are not supported by the camera, they get automatically adjusted and the user notified via an output message. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-03-29qcam: Add Qt-based GUI applicationLaurent Pinchart
qcam is a sample camera GUI application based on Qt. It demonstrates integration of the Qt event loop with libcamera. The application lets the user select a camera through the GUI, and then captures a single stream from the camera and displays it in a window. Only streams in YUYV formats are supported for now. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
s="hl opt">::V4L2CompatManager() : cm_(nullptr) { get_symbol(fops_.openat, "openat64"); get_symbol(fops_.dup, "dup"); get_symbol(fops_.close, "close"); get_symbol(fops_.ioctl, "ioctl"); get_symbol(fops_.mmap, "mmap64"); get_symbol(fops_.munmap, "munmap"); } V4L2CompatManager::~V4L2CompatManager() { files_.clear(); mmaps_.clear(); if (cm_) { proxies_.clear(); cm_->stop(); delete cm_; cm_ = nullptr; } } int V4L2CompatManager::start() { cm_ = new CameraManager(); int ret = cm_->start(); if (ret) { LOG(V4L2Compat, Error) << "Failed to start camera manager: " << strerror(-ret); delete cm_; cm_ = nullptr; return ret; } LOG(V4L2Compat, Debug) << "Started camera manager"; /* * For each Camera registered in the system, a V4L2CameraProxy gets * created here to wrap a camera device. */ auto cameras = cm_->cameras(); for (auto [index, camera] : utils::enumerate(cameras)) { V4L2CameraProxy *proxy = new V4L2CameraProxy(index, camera); proxies_.emplace_back(proxy); } return 0; } V4L2CompatManager *V4L2CompatManager::instance() { static V4L2CompatManager instance; return &instance; } std::shared_ptr<V4L2CameraFile> V4L2CompatManager::cameraFile(int fd) { auto file = files_.find(fd); if (file == files_.end()) return nullptr; return file->second; } int V4L2CompatManager::getCameraIndex(int fd) { struct stat statbuf; int ret = fstat(fd, &statbuf); if (ret < 0) return -1; std::shared_ptr<Camera> target = cm_->get(statbuf.st_rdev); if (!target) return -1; auto cameras = cm_->cameras(); for (auto [index, camera] : utils::enumerate(cameras)) { if (camera == target) return index; } return -1; } int V4L2CompatManager::openat(int dirfd, const char *path, int oflag, mode_t mode) { int fd = fops_.openat(dirfd, path, oflag, mode); if (fd < 0) return fd; struct stat statbuf; int ret = fstat(fd, &statbuf); if (ret < 0 || (statbuf.st_mode & S_IFMT) != S_IFCHR || major(statbuf.st_rdev) != 81) return fd; if (!cm_) start(); ret = getCameraIndex(fd); if (ret < 0) { LOG(V4L2Compat, Debug) << "No camera found for " << path; return fd; } fops_.close(fd); int efd = eventfd(0, EFD_SEMAPHORE | ((oflag & O_CLOEXEC) ? EFD_CLOEXEC : 0) | ((oflag & O_NONBLOCK) ? EFD_NONBLOCK : 0)); if (efd < 0) return efd; V4L2CameraProxy *proxy = proxies_[ret].get(); files_.emplace(efd, std::make_shared<V4L2CameraFile>(dirfd, path, efd, oflag & O_NONBLOCK, proxy)); LOG(V4L2Compat, Debug) << "Opened " << path << " -> fd " << efd; return efd; } int V4L2CompatManager::dup(int oldfd) { int newfd = fops_.dup(oldfd); if (newfd < 0) return newfd; auto file = files_.find(oldfd); if (file != files_.end()) files_[newfd] = file->second; return newfd; } int V4L2CompatManager::close(int fd) { auto file = files_.find(fd); if (file != files_.end()) files_.erase(file); /* We still need to close the eventfd. */ return fops_.close(fd); } void *V4L2CompatManager::mmap(void *addr, size_t length, int prot, int flags, int fd, off64_t offset) { std::shared_ptr<V4L2CameraFile> file = cameraFile(fd); if (!file) return fops_.mmap(addr, length, prot, flags, fd, offset); void *map = file->proxy()->mmap(file.get(), addr, length, prot, flags, offset); if (map == MAP_FAILED) return map; mmaps_[map] = file; return map; } int V4L2CompatManager::munmap(void *addr, size_t length) { auto device = mmaps_.find(addr); if (device == mmaps_.end()) return fops_.munmap(addr, length); V4L2CameraFile *file = device->second.get(); int ret = file->proxy()->munmap(file, addr, length); if (ret < 0) return ret; mmaps_.erase(device); return 0; } int V4L2CompatManager::ioctl(int fd, unsigned long request, void *arg) { std::shared_ptr<V4L2CameraFile> file = cameraFile(fd); if (!file) return fops_.ioctl(fd, request, arg); return file->proxy()->ioctl(file.get(), request, arg); }