summaryrefslogtreecommitdiff
path: root/src/v4l2/meson.build
AgeCommit message (Collapse)Author
2024-03-27v4l2: meson: Keep defines sorted alphabeticallyLaurent Pinchart
Due to my mistake, commit 705601781b6a ("v4l2: Unset _TIME_BITS in addition to _FILE_OFFSET_BITS") got merged with incorrect sorting of defines. Fix it. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
2024-03-27v4l2: Unset _TIME_BITS in addition to _FILE_OFFSET_BITSSteve Langasek
libcamera fails to build from source in Debian/Ubuntu on 32-bit architectures under 64-bit time_t (to avoid the 'year 2038 problem'), because its v4l2 module legitimately un-sets _FILE_OFFSET_BITS for building but this is not allowed without also unsetting _TIME_BITS. Having verified that nothing in this module is sensitive to 64-bit time_t (none of the functions it intercepts handle time), we also unset _TIME_BITS to allow this to build as before. Signed-off-by: Steve Langasek <steve.langasek@canonical.com> Reviewed-by: Dylan Aïssi <dylan.aissi@collabora.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-12-07meson: Tag all installed filesLaurent Pinchart
Meson uses tags to sort installed files in categories, and makes it possible to install a subset of the files using the '--tags' argument to 'meson install'. This is typically used by distributions to split the runtime, development and documentation files into separate packages. By default, meson tries to guess the correct tag for installed files, but can't always do so properly. Mark the install targets that meson can't guess with the correct install_tag. As the feature has been introduced in meson 0.60, bump the minimum meson version. The latest LTS release of all major distributions that libcamera currently targets ship a recent enough meson version. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
2023-05-04v4l2: Move the v4l2 compat layer to libexec/libcameraKieran Bingham
Move the v4l2-compat.so shared library installation to the libcamera directory under libexec. This is the same location that the proxy workers live and will facilitate easier packaging of the V4L2 compatibility layer with distributions. Create a new libcamera_libexecdir variable within meson to simplify representation of this path and update the proxy worker meson.build infrastructure to make use of it as well. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-02-04v4l2: Provide libcamerify wrapper scriptKieran Bingham
Support easier usage of the v4l2 compatibility layer with a script that handles the LD_PRELOAD for applications. The wrapper can be prefixed to launch any application with the preload set: $ libcamera-v4l2 v4l2-ctl --list-devices \_SB_.PCI0.GP13.XHC0.RHUB.PRT4- (libcamera:0): /dev/video0 platform/vimc.0 Sensor B (libcamera:1): /dev/video2 /dev/video3 /dev/video4 Specifying '-d' once before the command to run will enable V4L2Compat layer debug output from libcamera. Specifying '-d' twice will enable all debug levels from all libcamera components and provide a very detailed log for analysis. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2021-06-25libcamera/base: Validate internal headers as privateKieran Bingham
Headers which must not be exposed as part of the public libcamera API should include base/private.h. Any interface which includes the private.h header will only be able to build if the libcamera_private dependency is used (or the libcamera_base_private dependency directly). Build targets which are intended to use the private API's will use the libcamera_private to handle the automatic definition of the inclusion guard. Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-03-28meson: Summarize which applications and adaptation layers are builtLaurent Pinchart
Add the application and adaptation layers being built to the meson summary. The summary now prints libcamera 0.0.0 Configuration Enabled pipelines: ipu3 raspberrypi rkisp1 simple uvcvideo vimc Android support: True GStreamer support: True V4L2 emulation support: True cam application: True qcam application: True Unit tests: True Subprojects libyuv: YES Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
2021-02-11meson: Fix coding style when declaring arraysLaurent Pinchart
The meson.build files mix array declarations with and without a space after the opening and before the closing square bracket. The vast majority of cases don't use spaces, so standardize on that. While it it, fix indentation in a few places. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-12-30src: meson: Simplify v4l2 enablementKieran Bingham
Simplify the src level meson file by moving the declaration of the v4l2 subdir to match the other invocations, making use of 'subdir_done()' to break out if the adaptation layer is not enabled. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-25v4l2: v4l2_camera_file: Add V4L2CameraFile to model the opened camera filePaul Elder
With relation to opening files, the kernel has three objects related to files: - inodes, that represent files on disk - file objects, that are allocated at open() time and store all data related to the open file - file descriptors, that are integers that map to a file In the V4L2 compatibility layer, V4L2CameraProxy, which wraps a single libcamera camera via V4L2Camera, is more or less equivalent to the inode. We also already have file descriptors (that are really eventfds) that mirror the file descriptors. Here we create a V4L2CameraFile to model the file objects, to contain information related to the open file, namely if the file has been opened as non-blocking, and the V4L2 priority (to support VIDIOC_G/S_PRIORITY later on). This new class allows us to more cleanly support multiple open later on, since we can move out of V4L2CameraProxy the handling of mapping the fd to the open file information. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-06-19v4l2: v4l2_compat: Intercept open64, openat64, and mmap64Paul Elder
Some applications (eg. Firefox, Google Chrome, Skype) use open64, openat64, and mmap64 instead of their non-64 versions that we currently intercept. Intercept these calls as well. _LARGEFILE64_SOURCE needs to be set so that the 64-bit symbols are available and not synonymous to the non-64-bit versions on 64-bit systems. Also, since we set _FILE_OFFSET_BITS to 32 to force the various open and mmap symbols that we export to not be the 64-bit versions, our dlsym to get the original open and mmap calls will not automatically be converted to their 64-bit versions. Since we intercept both 32-bit and 64-bit versions of open and mmap, we should be using the 64-bit version to service both. Fetch the 64-bit versions of openat and mmap directly. musl defines the 64-bit symbols as macros that are equivalent to the non-64-bit symbols, so we put compile guards that check if the 64-bit symbols are defined. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> # Compile with musl Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-05-16libcamera: Move internal headers to include/libcamera/internal/Laurent Pinchart
The libcamera internal headers are located in src/libcamera/include/. The directory is added to the compiler headers search path with a meson include_directories() directive, and internal headers are included with (e.g. for the internal semaphore.h header) #include "semaphore.h" All was well, until libcxx decided to implement the C++20 synchronization library. The __threading_support header gained a #include <semaphore.h> to include the pthread's semaphore support. As include_directories() adds src/libcamera/include/ to the compiler search path with -I, the internal semaphore.h is included instead of the pthread version. Needless to say, the compiler isn't happy. Three options have been considered to fix this issue: - Use -iquote instead of -I. The -iquote option instructs gcc to only consider the header search path for headers included with the "" version. Meson unfortunately doesn't support this option. - Rename the internal semaphore.h header. This was deemed to be the beginning of a long whack-a-mole game, where namespace clashes with system libraries would appear over time (possibly dependent on particular system configurations) and would need to be constantly fixed. - Move the internal headers to another directory to create a unique namespace through path components. This causes lots of churn in all the existing source files through the all project. The first option would be best, but isn't available to us due to missing support in meson. Even if -iquote support was added, we would need to fix the problem before a new version of meson containing the required support would be released. The third option is thus the only practical solution available. Bite the bullet, and do it, moving headers to include/libcamera/internal/. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Jacopo Mondi <jacopo@jmondi.org>
2020-05-13licenses: License all meson files under CC0-1.0Laurent Pinchart
In an attempt to clarify the license terms of all files in the libcamera project, the build system files deserve particular attention. While they describe how the binaries are created, they are not themselves transformed into any part of binary distributions of the software, and thus don't influence the copyright on the binary packages. They are however subject to copyright, and thus influence the distribution terms of the source packages. Most of the meson.build files would not meet the threshold of originality criteria required for copyright protection. Some of the more complex meson.build files may be eligible for copyright protection. To avoid any ambiguity and uncertainty, state our intent to not assert copyrights on the build system files by putting them in the public domain with the CC0-1.0 license. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Acked-by: Giulio Benetti <giulio.benetti@micronovasrl.com> Acked-by: Jacopo Mondi <jacopo@jmondi.org> Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Acked-by: Naushir Patuck <naush@raspberrypi.com> Acked-by: Nicolas Dufresne <nicolas.dufresne@collabora.com> Acked-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Acked-by: Paul Elder <paul.elder@ideasonboard.com> Acked-by: Show Liu <show.liu@linaro.org>
2020-03-08v4l2: v4l2_compat: Use correct libcamera_dep dependencyLaurent Pinchart
The v4l2-compat shared library is declared as depending on libcamera_deps. This is not correct, as libcamera_deps contains the dependencies of libcamera itself. The correct dependency for users of libcamera is libcamera_dep. Fixing this allows dropping libcamera_includes from the list of includes required by v4l2-compat, and libcamera from the link_with list, as they are already contained in libcamera_dep. We however need to add an explicit dependency on libdl which was previously provided by libcamera_deps. 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-01-03v4l2: v4l2_compat: Add V4L2 compatibility layerPaul Elder
Add libcamera V4L2 compatibility layer. This initial implementation supports the minimal set of V4L2 operations, which allows getting, setting, and enumerating formats, and streaming frames from a video device. Some data about the wrapped V4L2 video device are hardcoded. Add a build option named 'v4l2' and adjust the build system to selectively compile the V4L2 compatibility layer. For now we match the V4L2 device node to a libcamera camera based on a devnum that a pipeline handler may optionally map to a libcamera camera. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
class="hl opt">< 0) { LOG(Process, Error) << "Failed to read byte from signal handler pipe"; return; } for (auto it = processes_.begin(); it != processes_.end(); ) { Process *process = *it; int wstatus; pid_t pid = waitpid(process->pid_, &wstatus, WNOHANG); if (process->pid_ != pid) { ++it; continue; } it = processes_.erase(it); process->died(wstatus); } } /** * \brief Register process with process manager * \param[in] proc Process to register * * This function registers the \a proc with the process manager. It * shall be called by the parent process after successfully forking, in * order to let the parent signal process termination. */ void ProcessManager::registerProcess(Process *proc) { processes_.push_back(proc); } ProcessManager *ProcessManager::self_ = nullptr; /** * \brief Construct a ProcessManager instance * * The ProcessManager class is meant to only be instantiated once, by the * CameraManager. */ ProcessManager::ProcessManager() { if (self_) LOG(Process, Fatal) << "Multiple ProcessManager objects are not allowed"; sigaction(SIGCHLD, NULL, &oldsa_); struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = &sigact; memcpy(&sa.sa_mask, &oldsa_.sa_mask, sizeof(sa.sa_mask)); sigaddset(&sa.sa_mask, SIGCHLD); sa.sa_flags = oldsa_.sa_flags | SA_SIGINFO; sigaction(SIGCHLD, &sa, NULL); int pipe[2]; if (pipe2(pipe, O_CLOEXEC | O_DIRECT | O_NONBLOCK)) LOG(Process, Fatal) << "Failed to initialize pipe for signal handling"; pipe_[0] = UniqueFD(pipe[0]); pipe_[1] = UniqueFD(pipe[1]); sigEvent_ = new EventNotifier(pipe_[0].get(), EventNotifier::Read); sigEvent_->activated.connect(this, &ProcessManager::sighandler); self_ = this; } ProcessManager::~ProcessManager() { sigaction(SIGCHLD, &oldsa_, NULL); delete sigEvent_; self_ = nullptr; } /** * \brief Retrieve the Process manager instance * * The ProcessManager is constructed by the CameraManager. This function shall * be used to retrieve the single instance of the manager. * * \return The Process manager instance */ ProcessManager *ProcessManager::instance() { return self_; } /** * \brief Retrieve the Process manager's write pipe * * This function is meant only to be used by the static signal handler. * * \return Pipe for writing */ int ProcessManager::writePipe() const { return pipe_[1].get(); } /** * \brief Retrive the old signal action data * * This function is meant only to be used by the static signal handler. * * \return The old signal action data */ const struct sigaction &ProcessManager::oldsa() const { return oldsa_; } /** * \class Process * \brief Process object * * The Process class models a process, and simplifies spawning new processes * and monitoring the exiting of a process. */ /** * \enum Process::ExitStatus * \brief Exit status of process * \var Process::NotExited * The process hasn't exited yet * \var Process::NormalExit * The process exited normally, either via exit() or returning from main * \var Process::SignalExit * The process was terminated by a signal (this includes crashing) */ Process::Process() : pid_(-1), running_(false), exitStatus_(NotExited), exitCode_(0) { } Process::~Process() { kill(); /* \todo wait for child process to exit */ } /** * \brief Fork and exec a process, and close fds * \param[in] path Path to executable * \param[in] args Arguments to pass to executable (optional) * \param[in] fds Vector of file descriptors to keep open (optional) * * Fork a process, and exec the executable specified by path. Prior to * exec'ing, but after forking, all file descriptors except for those * specified in fds will be closed. * * All indexes of args will be incremented by 1 before being fed to exec(), * so args[0] should not need to be equal to path. * * \return Zero on successful fork, exec, and closing the file descriptors, * or a negative error code otherwise */ int Process::start(const std::string &path, const std::vector<std::string> &args, const std::vector<int> &fds) { int ret; if (running_) return 0; int childPid = fork(); if (childPid == -1) { ret = -errno; LOG(Process, Error) << "Failed to fork: " << strerror(-ret); return ret; } else if (childPid) { pid_ = childPid; ProcessManager::instance()->registerProcess(this); running_ = true; return 0; } else { if (isolate()) _exit(EXIT_FAILURE); closeAllFdsExcept(fds); unsetenv("LIBCAMERA_LOG_FILE"); const char **argv = new const char *[args.size() + 2]; unsigned int len = args.size(); argv[0] = path.c_str(); for (unsigned int i = 0; i < len; i++) argv[i+1] = args[i].c_str(); argv[len+1] = nullptr; execv(path.c_str(), (char **)argv); exit(EXIT_FAILURE); } } void Process::closeAllFdsExcept(const std::vector<int> &fds) { std::vector<int> v(fds); sort(v.begin(), v.end()); DIR *dir = opendir("/proc/self/fd"); if (!dir) return; int dfd = dirfd(dir); struct dirent *ent; while ((ent = readdir(dir)) != nullptr) { char *endp; int fd = strtoul(ent->d_name, &endp, 10); if (*endp) continue; if (fd >= 0 && fd != dfd && !std::binary_search(v.begin(), v.end(), fd)) close(fd); } closedir(dir); } int Process::isolate() { int ret = unshare(CLONE_NEWUSER | CLONE_NEWNET); if (ret) { ret = -errno; LOG(Process, Error) << "Failed to unshare execution context: " << strerror(-ret); return ret; } return 0; } /** * \brief SIGCHLD handler * \param[in] wstatus The status as output by waitpid() * * This function is called when the process associated with Process terminates. * It emits the Process::finished signal. */ void Process::died(int wstatus) { running_ = false; exitStatus_ = WIFEXITED(wstatus) ? NormalExit : SignalExit; exitCode_ = exitStatus_ == NormalExit ? WEXITSTATUS(wstatus) : -1; finished.emit(exitStatus_, exitCode_); } /** * \fn Process::exitStatus() * \brief Retrieve the exit status of the process * * Return the exit status of the process, that is, whether the process * has exited via exit() or returning from main, or if the process was * terminated by a signal. * * \sa ExitStatus * * \return The process exit status */ /** * \fn Process::exitCode() * \brief Retrieve the exit code of the process * * This function is only valid if exitStatus() returned NormalExit. * * \return Exit code */ /** * \var Process::finished * * Signal that is emitted when the process is confirmed to have terminated. */ /** * \brief Kill the process * * Sends SIGKILL to the process. */ void Process::kill() { if (pid_ > 0) ::kill(pid_, SIGKILL); } } /* namespace libcamera */