66b0bcbbee6bcb77ed3f90cc1560f1116a7afa63
This is a combination of 31 commits.
android: hal: provider: Import legacy provider 2.4 HAL from AOSP
AOSP does not ship an up-to-date (libhardware) camera provider HAL.
In order to write an AIDL HAL compatible with libcamera, we need
some reference codebase to start from.
Import the 2.4 legacy HAL from AOSP from tag android-15.0.0_r12.
Folder path: //hardware/interfaces/camera/provider/2.4/default/
commit ad2ba1b851b6 ("[DON'T BLOCK] Test ownership migration rules")
Note: only the "legacy" part has been imported since external cameras are
supported via android.hardware.camera.provider-V1-external-service.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: device: Import helpers from camera.device-external-impl
The ExternalCameraDevice AIDL HAL provides some convience functions to
convert between libhardware structures and AIDL classes.
It also provides a wrapper to convert common::Status to ScopedAStatus.
We need those convience functions for our HAL implementation as well.
Since they are not in a separate library, we can't simply link against it.
Make a local copy for our own usage here.
Import from android-15.0.0_r12 tag
Folder path: //hardware/interfaces/camera/device/default/
commit ad2ba1b851b6 ("[DON'T BLOCK] Test ownership migration rules")
Note: this only imports the conversion code.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: device: Rename device-external-impl -> device-libcamera-impl
For now camera.device-libcamera-impl only supports conversion functions.
This is already useful for the provider implementation in order to
convert from common::Status to AScopedStatus.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: Use Android-Apache-2.0 instead of hardware_interfaces_license
hardware_interfaces_license is only available for projects in:
//hardware/interfaces//
Since our HAL is not located in that folder, we cannot use it.
variant "android_common": depends on
//hardware/interfaces:hardware_interfaces_license which is
not visible to this module
Switch to Android-Apache-2.0 which is the same license and is
available in all Android projects.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: provider: Remove 32-bits build targets
Recent Android versions (with kernel version 6.2+) require 64-bits userspace.
Therefore, there is no point in keeping unused 32-bits build targets.
Remove them.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: provider: Rename 2.4 -> 2.5 to prepare HIDL update
The most recent libbhardware (legacy) based camera provider HAL in AOSP
is the 2.5 version located in //hardware/interfaces/camera/provider/2.5/default/
LegacyCameraProviderImpl_2_5 is implemented as a subclass of
LegacyCameraProviderImpl_2_4.
We don't want this subclassing to be done because it makes converting to AIDL
more difficult.
Instead, we want the new 2.5 function (notifyDeviceStateChange()) to
be part of our class.
In order to prepare for importing the 2.5 codebase, rename all mentions
from 2.4 -> 2.5.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: provider: Import HIDL v2.5 provider HAL from AOSP
The most recent libbhardware (legacy) based camera provider HAL in AOSP
is the 2.5 version located in //hardware/interfaces/camera/provider/2.5/default/
LegacyCameraProviderImpl_2_5 is implemented as a subclass of
LegacyCameraProviderImpl_2_4.
We don't want tho subclass because it makes converting to AIDL more difficult.
Instead, we want the new 2.5 function (notifyDeviceStateChange()) to
be part of our class.
Import the 2.5 code from tag android-15.0.0_r12.
Folder path: //hardware/interfaces/camera/provider/2.5/default/
commit ad2ba1b851b6 ("[DON'T BLOCK] Test ownership migration rules")
This:
- Removes the '-impl' library (it's a template-based header only)
- Add notifyDeviceStateChange() method
- Update copyright notice
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: provider: Remove templated CameraProvider struct
CameraProvider is implemented as a wrapper structure in order to
be backwards compatible with various HIDL versions.
Since this code is about to get upgraded to AIDL, we don't care about the
deprecated HIDL support.
Remove the HIDL interface layer and make LegacyCameraProviderImpl
implement the ICameraProvider interface.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: provider: Rename legacy -> libcamera
This provider HAL is libcamera specific. As a first step we will still rely on
libhardware as interface, but that can get plumbed in future reworks.
Rename from "legacy" to "libcamera" to make it clear that this provider HAL is
for supporting cameras using libcamera.
While at it, also update the LOG_TAGs to match the new naming.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: provider: Send libcamera logs to logcat
By default libcamera logs only warnings and errors to stdout.
Use LIBCAMERA_LOG_LEVELS and LIBCAMERA_LOG_FILE to ensure
that libcamera logs info+ logs are send to logcat.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: provider: Remove V2_5 namespace to prepare for AIDL
Most AIDL HALs don't use the AIDL version inside the C++ namespace.
Follow that practice and remove it here as well.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: provider: Don't hard-code the hwbinder thread count
Following example from //hardware/interfaces/camera/provider/default,
use a constant instead of hard-coding the thread count.
This will simplify AIDL migration to match what is done for the
ExternalCameraProvider.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: provider: Don't use intermediate variable for LAZY_SERVICE
The intermediate bool variable is not needed since we can use the pre-processor
for this.
Remove it as done in ExternalCameraProvider.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: device: Add a stub implementation for provider
In order to implement the provider HAL in AIDL, we need to
instantiate a ICameraDevice.
A ICameraDevice implementation must inherit from BnCameraDevice.
Add a minimal stub, named LibcameraDevice which builds.
This can be used by the provider HAL in getCameraDeviceInterface().
Note that we no longer depend on hidl_defaults so get rid of that as well.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: provider: Migrate from v3.5 HIDL to AIDL v1
This migrates the provider HAL from HIDL into AIDL.
This includes the following changes:
- Replace use std::string instead of hidl_string
- Use CameraDeviceStatus enum instead of CAMERA_DEVICE_STATUS
- Use std::shared_ptr<> instead of android::sp<>
- Use method argument naming from ExternalCameraProvider
- Return ndk::ScopedAStatus instead of camera::common::Status
- Remove support of vendor tags as it's un-implemented in libcamera
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: device: Implement BnCameraDevice interface
Implement all required operations of a BnCameraDevice with the exception
for session handling.
Session being a quite complex topic, it will be enabled after the
LibcameraDeviceSession class is implemented.
This is based on the both the legacy 3.2 HIDL HAL and
the External AIDL located in:
//hardware/interfaces/camera/device/3.2/default/CameraDevice
//hardware/interfaces/camera/device/default/ExternalCameraDevice
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: session: Import legacy 3.2 CameraDeviceSession from AOSP
In order to write an AIDL HAL compatible with libcamera, we need
some reference codebase to start from.
Import the 3.2 legacy HAL from AOSP from tag android-15.0.0_r12.
Folder path: //hardware/interfaces/camera/device/3.2/default/
commit ad2ba1b851b6 ("[DON'T BLOCK] Test ownership migration rules")
Note: only the "legacy" part has been imported since external cameras are
supported via android.hardware.camera.provider-V1-external-service.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: session: rename CameraDeviceSession -> LibcameraDeviceSession
This is going to be libcamera specific, so rename it accordingly.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: session: Remove V3_2 namespace to prepare for AIDL
Most AIDL HALs don't use the AIDL version inside the C++ namespace.
Follow that practice and remove it here as well.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: session: Remove HIDL trampoline code to prepare for AIDL
We don't need this, as it's HIDL specific.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: session: Migrate from v3.2 HIDL to AIDL v1
This migrates the DeviceSession class from HIDL into AIDL.
This includes the following changes:
- Use std::shared_ptr<> instead of android::sp<>
- Use std::string instead of hidl_string
- Use std::vector instead of hidl_vec
- Remove V1_0 namespace for camera::common::helper
- Use HandleImporter from camera::common::helper
- Use AIDLMessageQueues and change data type from uint8_t -> int8_t
- Use makeFromAidl() for fence handling
- Use std::move() instead of hand-cloning fences
- Use new NotifyMsg API with class enums
- Use NativeHandle instead off native_handle_t* when needed
Note: by switching to dupToAidl(), we must ensure that the original handle
is deleted.
Note: All AIDL specific operations are stubbed for now, as we are not sure that
those are implemented by libcamera's hw_module.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: device: Use LibcameraDeviceSession class
Now that LibcameraDeviceSession is implemented, we can use it in
LibcameraDevice.
With this change, we can see preview using com.android.camera2 app and
take pictures via libcamera.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: Rename outdated LOG_TAGs
These were leftovers from the code import from AOSP.
Update to use the new naming scheme so that it's easier to grep
for this HAL in logcat.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: Remove un-needed dependencies
While converting to AIDL, we failed to remove the HIDL
dependencies.
Cleanup the dependencies and also depend on common-helper instead of
the deprecated common@1.0-helper.
Note that for device, we cannot get rid of libhidlbase because of our
usage of HandleImporter.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: Remove lazy service support
We have never used the lazy implementation and don't even know how
to test it.
To simplify the codebase, get rid of it.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: provider: add libcamera_aidl_defaults
Add a new libcamera_aidl_defaults which is used by the
camera library.
This allows us to remove lots of duplicated shared_libs since
they are defined in the new defaults.
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: provider: Return ILLEGAL_ARGUMENT when callback is nullptr
When a user attempts to setCallback() using a nullptr, we should
return ILLEGAL_ARGUMENT, not OK.
Update the condition and while at it, drop the braces which are
not needed for a single statement.
Not: this is tested by VTS.
Test: atest PerInstance/CameraAidlTest#setCallback/1_android_hardware_camera_provider_ICameraProvider_libcamera_0
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: device: Fix openInjectSession() return code
The AIDL doc states that we should return OPERATION_NOT_SUPPORTED when
this is not implemented.
Fix the return code. This is tested with VTS.
Test: atest PerInstance/CameraAidlTest#configureInjectionStreamsAvailableOutputs/1_android_hardware_camera_provider_ICameraProvider_libcamera_0
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: device: Fix torch related return codes
When these operations are not supported, we should return
OPERATION_NOT_SUPPORTED instead of ILLEGAL_ARGUMENT.
Fix both return codes.
This is tested by VTS.
Test: atest PerInstance/CameraAidlTest#turnOnTorchWithStrengthLevel/1_android_hardware_camera_provider_ICameraProvider_libcamera_0
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: device: Return ILLEGAL_ARGUMENT on invalid output buffer
When we are importing an invalid output buffer, we should return
ILLEGAL_ARGUMENT, not INTERNAL_ERROR.
Fix this.
This is tested by VTS.
Test: atest PerInstance/CameraAidlTest#processCaptureRequestInvalidBuffer/1_android_hardware_camera_provider_ICameraProvider_libcamera_0
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
android: hal: Cleanup makefiles
.. 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%