4a9863e05397eaba46330e9ebeacad5e0e73f991
The libcamera documentation comprises two parts: pages generated by Sphinx into the Documentation/html/ directory within the build tree, and API reference documentation generated by Doxygen into Documentation/internal-api-html/ and Documentation/api-html/. The two parts are generated separately, but link to each other. From Sphinx to Doxygen, we use the doxylink extension for Sphinx to generate links to the Doxygen pages corresponding to API elements. The extension needs to be configured with the paths to the Doxygen documentation, which are set based on the html/, api-html/ and internal-api-html/ directories being placed side by side in the same parent directory. Furthermore, we also want to link to the API documentation from the Sphinx toctree. As toctrees can only link to pages within the Sphinx documents tree (or to http URLs), we have placeholder .rst documents for api-html and internal-api-html in the Sphinx documentation tree. Those generate the Documentation/html/internal-api-html/index.html and Documentation/html/api-html/index.html placeholder files in the build tree. The other way around, the API documentation's introduction pagelinks to Sphinx pages using relative paths. Those paths are hardcoded based on the api-html/ and internal-api-html/ directories being children of the html/ directory. This results in links being broken in different ways in the build tree, as well as in the installation directory: the toctree links direct to the placeholder pages within the html/ directory instead of the Doxygen documentation in sibling directories, and the Doxygen introduction links to Sphinx are simply broken. When publishing documentation on the website we work around those issues by overriding conf.py with a custom version and moving the api-html/ and internal-api-html/ directories to the html/ directory. Fixing this is surprisingly difficult. The toctree links can't be changed to point to a path outside of the Sphinx document tree as this isn't supported by Sphinx. Using http URLs would link to the libcamera.org website inside of local documentation, which isn't acceptable. It may be possible to develop a Sphinx extension to patch the toctree after it gets parsed, but that would be complex and likely fragile. Modifying the install path of the Doxygen documentation to html/api-html/ and html/internal-api-html/ causes issues as the Sphinx documentation will then overwrite the Doxygen index.html files with the placeholder indexes. Creating symlinks from html/api-html/ to api-html/ in the installation directory causes similar problems if 'meson install' is run twice. Creating the symlinks in the build directory (which was attempted with a custom Sphinx extension) is also a no-go: starting with meson v1.8.0, installing symlinks to directories causes an exception due to a bug in meson. The right solution is probably to investigate usage of the doxysphinx extension. As that's no small amount of work, let's start with a non-perfect but simple improvement: configure doxylink based on the api-html/ and internal-api-html/ directories being children of the Sphinx html/ documentation, and move those two API documentation directories to html/ during installation with a post-install script. This fixes links in the installation directory. Links in the build directory remain broken, with the toctree links and the links from Doxygen to Sphinx being broken already, and the links to API elements through doxylink now being broken too. This is considered as an acceptable compromise and an overall improvement. The installation directory is more important, as in the build tree people also have access to sources. Application developers in particular are less likely to read documentation from the libcamera build tree, they may not even have a copy of the libcamera source tree. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>
.. SPDX-License-Identifier: CC-BY-SA-4.0
===========
libcamera
===========
**A complex camera support library for Linux, Android, and ChromeOS**
Cameras are complex devices that need heavy hardware image processing
operations. Control of the processing is based on advanced algorithms that must
run on a programmable processor. This has traditionally been implemented in a
dedicated MCU in the camera, but in embedded devices algorithms have been moved
to the main CPU to save cost. Blurring the boundary between camera devices and
Linux often left the user with no other option than a vendor-specific
closed-source solution.
To address this problem the Linux media community has very recently started
collaboration with the industry to develop a camera stack that will be
open-source-friendly while still protecting vendor core IP. libcamera was born
out of that collaboration and will offer modern camera support to Linux-based
systems, including traditional Linux distributions, ChromeOS and Android.
.. section-begin-getting-started
Getting Started
---------------
To fetch the sources, build and install:
.. code::
git clone https://git.libcamera.org/libcamera/libcamera.git
cd libcamera
meson setup build
ninja -C build install
Dependencies
~~~~~~~~~~~~
The following Debian/Ubuntu packages are required for building libcamera.
Other distributions may have differing package names:
A C++ toolchain: [required]
Either {g++, clang}
Meson Build system: [required]
meson (>= 1.0.1) ninja-build pkg-config
for the libcamera core: [required]
libyaml-dev python3-yaml python3-ply python3-jinja2
for IPA module signing: [recommended]
Either libgnutls28-dev or libssl-dev, openssl
Without IPA module signing, all IPA modules will be isolated in a
separate process. This adds an unnecessary extra overhead at runtime.
for improved debugging: [optional]
libdw-dev libunwind-dev
libdw and libunwind provide backtraces to help debugging assertion
failures. Their functions overlap, libdw provides the most detailed
information, and libunwind is not needed if both libdw and the glibc
backtrace() function are available.
for device hotplug enumeration: [optional]
libudev-dev
for documentation: [optional]
doxygen graphviz python3-sphinx python3-sphinx-book-theme
python3-sphinxcontrib.doxylink (>= 1.6.1) texlive-latex-extra
for gstreamer: [optional]
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
for Python bindings: [optional]
libpython3-dev pybind11-dev
for cam: [optional]
libevent-dev is required to support cam, however the following
optional dependencies bring more functionality to the cam test
tool:
- libdrm-dev: Enables the KMS sink
- libjpeg-dev: Enables MJPEG on the SDL sink
- libsdl2-dev: Enables the SDL sink
- libtiff-dev: Enables writing DNG
for qcam: [optional]
libtiff-dev qt6-base-dev
for tracing with lttng: [optional]
liblttng-ust-dev python3-jinja2 lttng-tools
for android: [optional]
libexif-dev libjpeg-dev
for lc-compliance: [optional]
libevent-dev libgtest-dev
for abi-compat.sh: [optional]
abi-compliance-checker
Basic testing with cam utility
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The ``cam`` utility can be used for basic testing. You can list the cameras
detected on the system with ``cam -l``, and capture ten frames from the first
camera and save them to disk with ``cam -c 1 --capture=10 --file``. See
``cam -h`` for more information about the ``cam`` tool.
In case of problems, a detailed debug log can be obtained from libcamera by
setting the ``LIBCAMERA_LOG_LEVELS`` environment variable:
.. code::
:~$ LIBCAMERA_LOG_LEVELS=*:DEBUG cam -l
Using GStreamer plugin
~~~~~~~~~~~~~~~~~~~~~~
To use the GStreamer plugin from the source tree, use the meson ``devenv``
command. This will create a new shell instance with the ``GST_PLUGIN_PATH``
environment set accordingly.
.. code::
meson devenv -C build
The debugging tool ``gst-launch-1.0`` can be used to construct a pipeline and
test it. The following pipeline will stream from the camera named "Camera 1"
onto the OpenGL accelerated display element on your system.
.. code::
gst-launch-1.0 libcamerasrc camera-name="Camera 1" ! queue ! glimagesink
To show the first camera found you can omit the camera-name property, or you
can list the cameras and their capabilities using:
.. code::
gst-device-monitor-1.0 Video
This will also show the supported stream sizes which can be manually selected
if desired with a pipeline such as:
.. code::
gst-launch-1.0 libcamerasrc ! 'video/x-raw,width=1280,height=720' ! \
queue ! glimagesink
The libcamerasrc element has two log categories, named libcamera-provider (for
the video device provider) and libcamerasrc (for the operation of the camera).
All corresponding debug messages can be enabled by setting the ``GST_DEBUG``
environment variable to ``libcamera*:7``.
Presently, to prevent element negotiation failures it is required to specify
the colorimetry and framerate as part of your pipeline construction. For
instance, to capture and encode as a JPEG stream and receive on another device
the following example could be used as a starting point:
.. code::
gst-launch-1.0 libcamerasrc ! \
video/x-raw,colorimetry=bt709,format=NV12,width=1280,height=720,framerate=30/1 ! \
queue ! jpegenc ! multipartmux ! \
tcpserversink host=0.0.0.0 port=5000
Which can be received on another device over the network with:
.. code::
gst-launch-1.0 tcpclientsrc host=$DEVICE_IP port=5000 ! \
multipartdemux ! jpegdec ! autovideosink
The GStreamer element also supports multiple streams. This is achieved by
requesting additional source pads. Downstream caps filters can be used
to choose specific parameters like resolution and pixel format. The pad
property ``stream-role`` can be used to select a role.
The following example displays a 640x480 view finder while streaming JPEG
encoded 800x600 video. You can use the receiver pipeline above to view the
remote stream from another device.
.. code::
gst-launch-1.0 libcamerasrc name=cs src::stream-role=view-finder src_0::stream-role=video-recording \
cs.src ! queue ! video/x-raw,width=640,height=480 ! videoconvert ! autovideosink \
cs.src_0 ! queue ! video/x-raw,width=800,height=600 ! videoconvert ! \
jpegenc ! multipartmux ! tcpserversink host=0.0.0.0 port=5000
.. section-end-getting-started
Troubleshooting
~~~~~~~~~~~~~~~
Several users have reported issues with meson installation, crux of the issue
is a potential version mismatch between the version that root uses, and the
version that the normal user uses. On calling `ninja -C build`, it can't find
the build.ninja module. This is a snippet of the error message.
::
ninja: Entering directory `build'
ninja: error: loading 'build.ninja': No such file or directory
This can be solved in two ways:
1. Don't install meson again if it is already installed system-wide.
2. If a version of meson which is different from the system-wide version is
already installed, uninstall that meson using pip3, and install again without
the --user argument.
Description
Languages
C++
69.3%
C
17.8%
Python
10.4%
Meson
1.5%
Shell
0.7%
Other
0.3%