Commit graph

84 commits

Author SHA1 Message Date
Laurent Pinchart
39f01e9185 py: gen-py-controls: Convert to jinja2 templates
Jinja2 templates help separate the logic related to the template from
the generation of the data. The python code becomes much clearer as a
result.

As an added bonus, we can use a single template file for both controls
and properties.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Acked-by: Paul Elder <paul.elder@ideasonboard.com>
2024-08-16 00:28:32 +03:00
Laurent Pinchart
5c1cb5e5bc py: gen-py-controls: Use Control class
Replace manual extraction of data from YAML with the Control helper
class. This centralizes YAML parsing and avoids manual mistakes.

In order to import the controls module, add the utils/codegen/ directory
to the PYTHONPATH through the Python build environment.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2024-08-16 00:28:32 +03:00
Laurent Pinchart
b8d318ebeb meson: Store controls and properties YAML files in variables
When generating control headers, the YAML files to be used are
determined dynamically based on the selected pipeline handlers. As part
of this process, the build system populates an array of meson File
objects used as an input for the control headers generation custom
target, as well as an array of file names (as strings). The file names
array is later used to generate the control source files for the
libcamera core, as well as the source code for controls support in the
Python bindings.

Both of the source code generators manually turn the array of file names
into File objects. This duplicates code and reduces readability. A third
similar implementation has also been proposed to generate control
support sources in the GStreamer element, making the issue worse.

To simplify this, store File objects instead of file names in the
controls_files array. As the meson configuration summary doesn't support
File objects, create a separate controls_files_names to store the file
names for that sole purpose.

The exact same process occurs for properties, address them the same way.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2024-08-15 04:44:09 +03:00
Tomi Valkeinen
15a51caae8 py: cam: Convert to PyQt6
Qt5 is now end of life. The libcamera 'qcam' application has removed
support for Qt5, and updated to Qt6.

Update the python 'cam' application accordingly to Qt6.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2024-08-12 20:25:20 +03:00
Laurent Pinchart
a2e27f4f2b py: libcamera: Move function declarations to common header
The init_py_*() functions are called by the top-level entry point of the
libcamera Python module to initialize different parts of the bindings.
They are declared in py_main.cpp where they are called, and defined in
separate compilation units. This results in functions being defined
without a corresponding declaration, and will generate warnings when we
enable -Wmissing-declarations.

Fix this by moving the function declarations from py_main.c to
py_main.h, and including py_main.h in the various compilation units that
need it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2024-06-26 12:07:11 +03:00
Laurent Pinchart
9ba0c3fef8 meson: Tag all installed files
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-12-07 01:43:17 +02:00
Naushir Patuck
e18a007b9d libcamera: controls: Use vendor tags for draft controls and properties
Label draft controls and properties through the "draft" vendor tag
and deprecate the existing "draft: true" mechanism. This uses the new
vendor tags mechanism to place draft controls in the same
libcamera::controls::draft namespace and provide a defined control id
range for these controls. This requires moving all draft controls from
control_ids.yaml to control_ids_draft.yaml.

One breaking change in this commit is that draft control ids also move
to the libcamera::controls::draft namespace from the existing
libcamera::controls namespace. This is desirable to avoid API breakages
when adding new libcamera controls. So, for example, the use of
controls::NOISE_REDUCTION_MODE will need to be replaced with
controls::draft::NOISE_REDUCTION_MODE.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-11-30 13:59:27 +00:00
Naushir Patuck
0455bbbf51 build: controls: Rework how controls and properties are generated
Add support for using separate YAML files for controls and properties
generation. The mapping of vendor/pipeline handler to control file is
done through the controls_map variable in include/libcamera/meson.build.

This simplifies management of vendor control definitions and avoids
possible merge conflicts when changing the control_ids.yaml file for
core and draft controls. With this change, libcamera and draft controls
and properties files are designated the 'libcamera' vendor tag.

In this change, we also rename control_ids.yaml -> control_ids_core.yaml
and property_ids.yaml -> property_ids_core.yaml to designate these as
core libcamera controls.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-11-29 09:05:38 +00:00
Naushir Patuck
bba4ec63c4 controls: Update argument handling for controls generation scripts
The template file to the gen-controls.py and gen-py-controls.py is now
passed in through the '-t' or '--template' command line argument instead
of being a positional argument.  This will allow multiple input files to
be provided to the scripts in a future commit.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-11-29 09:05:38 +00:00
Naushir Patuck
bd6658943a controls: Add vendor control/property support to generation scripts
Add support for vendor-specific controls and properties to libcamera.
The controls/properties are defined by a "vendor" tag in the YAML
control description file, for example:

vendor: rpi
controls:
  - MyExampleControl:
      type: string
      description: |
        Test for libcamera vendor-specific controls.

This will now generate a control id in the libcamera::controls::rpi
namespace, ensuring no id conflict between different vendors, core or
draft libcamera controls. Similarly, a ControlIdMap control is generated
in the libcamera::controls::rpi namespace.

A #define LIBCAMERA_HAS_RPI_VENDOR_CONTROLS is also generated to allow
applications to conditionally compile code if the specific vendor
controls are present. For the python bindings, the control is available
with libcamera.controls.rpi.MyExampleControl. The above controls
example applies similarly to properties.

Existing libcamera controls defined in control_ids.yaml are given the
"libcamera" vendor tag.

A new --mode flag is added to gen-controls.py to specify the mode of
operation, either 'controls' or 'properties' to allow the code generator
to correctly set the #define string.

As a drive-by, sort and redefine the output command line argument in
gen-controls.py and gen-py-controls.py to ('--output', '-o') for
consistency.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-11-29 09:05:37 +00:00
Jacopo Mondi
4814d8f1b5 py: cam: Add option to set stream orientation
Add a '--orientation|-o' option to the Python version of the cam test
application to set an orientation to the image stream.

Supported values are:
- rot0: no rotation
- rot180: rotate 180 degrees
- flip: vertical flip
- mirror: horizontal flip

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-10-23 16:06:14 +03:00
Jacopo Mondi
c65e40b848 libcamera: Use CameraConfiguration::orientation
Replace the usage of CameraConfiguration::transform with the newly
introduced CameraConfiguration::orientation.

Rework and rename the CameraSensor::validateTransform(transform) to
CameraSensor::computeTransform(orientation), that given the desired
image orientation computes the Transform that pipeline handlers should
apply to the sensor to obtain it.

Port all pipeline handlers to use the newly introduced function.

This commit breaks existing applications as it removes the public
CameraConfiguration::transform in favour of
CameraConfiguration::orientation.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-10-23 16:06:09 +03:00
Jacopo Mondi
a28f871836 py: libcamera: Define and use Orientation
Define an enumeration type for Orientation and expose the
CameraConfiguration::orientation property in place of
CameraConfiguration::transform.

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-10-23 16:06:07 +03:00
Kieran Bingham
c258302863 py: gen-py-controls: Remove SceneFlicker workaround
The python bindings layer has to parse the libcamera controls to ensure
that they are converted to suitable names for the python layer.

Part of this strips out common prefixes from control names, however the
SceneFlicker control would end up using an illegal name if processed in
the same way as the other controls.

The SceneFlicker control has now been removed as part of the
introduction of the AeFlickerMode and AeFlickerPeriod controls.

Remove the workaround in the python layer.

Fixes: 6fdbf3f38c ("libcamera: controls: Add controls for AEC/AGC flicker avoidance")
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-10-16 16:38:08 +01:00
David Plowman
d05009d34c py: Add the SensorConfiguration class
We provide access to the various fields of the new SensorConfiguration
class. The class also needs a constructor so that Python applications
can make one and put it into the CameraConfiguration.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-10-16 16:21:04 +01:00
Laurent Pinchart
ca437b4a0c meson: Fix space around colon issues
The meson style, which libcamera follows, recommends a space before
colons in function parameters. Fix the style violations through the
project.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2023-07-07 11:39:19 +03:00
Barnabás Pőcze
86fa7300fa libcamera: camera: Take span of StreamRole instead of vector
Change the parameter type of `generateConfiguration()` from `const std::vector&`
to `libcamera::Span`. A span is almost always preferable to a const vector ref
because it does not force dynamic allocation when none are needed, and it allows
any contiguous container to be used.

A new overload is added that accepts an initializer list so that

  cam->generateConfiguration({ ... })

keeps working.

There is no API break since a span can be constructed from a vector
and the initializer list overload takes care of the initializer lists,
but this change causes an ABI break.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
[Kieran: Apply checkstyle fixups]
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-07-04 22:48:30 +01:00
Tomi Valkeinen
a1f0556a46 py: Fix code formatting
Fix code formatting.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-06-04 12:25:35 +03:00
Tomi Valkeinen
ad4719c10c py: Move to mainline pybind11 version
We are using pybind11 'smart_holder' branch to solve the Camera
destructor issue (see the comment in this patch, or the commit
that originally added Python bindings support).

As it would be very nice to use the mainline pybind11 (which is packaged
in distributions), this patch adds a workaround allowing us to move to
the mainline pybind11 version.

The workaround is simply creating a custom holder class
(PyCameraSmartPtr), used only for the Camera, which wraps around the
shared_ptr. This makes the compiler happy.

Moving to mainline pybind11 is achieved with:

- Change the pybind11 wrap to point to the mainline pybdind11 version

- Tell pybind11 to always use shared_ptr<> as the holder for
  PyCameraManager, as we use the singleton pattern for the
  PyCameraManager, and using shared_ptr<> to manage it is a requirement

- Tell pybind11 to always use PyCameraSmartPtr<> as the holder for Camera

- Change the meson.build file to use a system-installed pybind11

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-05-31 19:48:02 +03:00
Tomi Valkeinen
1fb31ac4f4 py: Use exceptions instead of returning error codes
We have multiple methods which return an error code, mimicking the C++
API. Using exceptions is more natural in the Python API, so change all
those methods to raise an Exception instead.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-05-30 18:29:09 +03:00
Tomi Valkeinen
5b2f1ce501 py: Move ColorSpace and Transform classes to separate files
Move ColorSpace and Transform classes to separate files from the main
py_main.cpp, for clarity.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-05-30 18:29:08 +03:00
Tomi Valkeinen
9506da142b py: Fix CameraManager.version property
The current CameraManager.version doesn't work at all (raises a
TypeError), as that's not how you use expose C++ static methods as
Python class methods.

Fix it.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-05-30 18:29:08 +03:00
Tomi Valkeinen
b3cefd4c0e py: cam: Fix demosaic overflow issue
The demosaic code first expands the buffer datatype to uint16, and then
shifts the data left so that the 8, 10 and 12 bitspp formats all become
16 bitspp.

It then, eventually, uses np.einsum to calculate averages, but this
averaging sums multiple uint16 values together, and stores them in
uint16 storage. As in the first step we shifted the values left,
possibly getting values close to the maximum of uint16 range, we, of
course, overflow when summing them together. This leads to rather bad
looking images.

Fix this by dropping the original shift. It serves no purpose, and is
probably a remnant of some early testing code. This way the largest
numbers we are summing together are 12 bit values, and as we use a 3x3
window from which we fetch values, for a single rgb plane, the max
number of 12 bit values is 5 (for green). Sum of 5 12 bit values is well
below the 16 bit maximum.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2023-03-21 23:33:43 +00:00
Daniel Oakley
20e33bc0df py: cam.py: Fix duplicate metadata output if more than one stream
Currently, if there are multiple streams, the --metadata flag will print
the metadata for each request multiple times.

Moving the metadata print logic outside the stream for loop this will no
longer occur.

Signed-off-by: Daniel Oakley <daniel.oakley@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2023-01-16 18:07:05 +02:00
Matthew Goodman
3c70cae5e5 Expose the Request Sequence Number in Python Bindings
The python bindings are missing the ability to read the sequence number
of the Request object from the public API.

Expose the objects sequence number on the pybind11 surfaces to support
applications reading this value.

Signed-off-by: Matthew Goodman <matt@exclosure.io>
[Kieran: Revised commit message]
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-12-19 15:07:30 +00:00
David Plowman
a6b1ff2e6c py: Support controls that use an array of Rectangles
The Python bindings will now accept, or return, a list or tuple of
libcamera.Rectangle objects for such controls.

This had previously been omitted, but now we have, for example, the
AfWindows control which requires this feature.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2022-12-09 16:02:40 +00:00
David Plowman
c97cf467ea py: Support controls that are ControlTypeNone
Such controls can now be created when a control doesn't have a
reasonable or obvious default value. We support them using Python's
"None" value, rather than generating a runtime error.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Christian Rauch <Rauch.Christian@gmx.de>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-09-30 23:12:05 +03:00
Laurent Pinchart
1d54f8d0a2 libcamera: Add missing SPDX headers for miscellaneous CC0-1.0 contents
Miscellaneous files that are not considered copyrightable are missing an
SPDX-License-Identifier header. Fix this by adding a header listing the
CC0-1.0 license.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2022-09-30 21:51:23 +03:00
Laurent Pinchart
a17f0eddc6 libcamera: color_space: Rename Jpeg to Sycc
The JPEG color space is badly name, as the JPEG specification (ITU-T
T.81) doesn't define any particular color space:

    The interchange format does not specify a complete coded image
    representation. Application-dependent information, e.g. colour
    space, is outside the scope of this Specification.

The JFIF specification (ITU-T T.871) is clearer as it requires ITU-R
BT.601 YCbCr encoding and a full quantization range:

  The interpretations of Y, CB, and CR are derived from the E'Y, E'Cb,
  and E'Cr signals defined in the 625-line specification of Rec. ITU-R
  BT.601, but these signals are normalized so as to permit the usage of
  the full range of 256 levels of the 8-bit binary encoding of the Y
  component.

It however doesn't specify color primaries or a transfer function
explicitly. It only mentions the latter when describing the conversion
from YCbCr to RGB:

  The inverse relationship for computing full scale 8-bit per colour
  channel gamma pre-corrected RGB values (following Rec. ITU-R BT.601
  gamma pre-correction and colour primary specifications) from YCbCr
  colours (with 256 levels per component) can be computed as follows:
  [...]

Given that ITU-R BT.601-5 (1995) didn't specify color primaries or a
transfer function, and that the later ITU-R BT.601-7 (2011) version
specifies color primaries for the 625-line variant that do not match
sRGB, the JPEG color space in libcamera is badly named. This is
confirmed by ITU-T T.871:

  As this Recommendation | International Standard is based on the prior
  informally-circulated JFIF version 1.02 specification that was
  produced in 1992, which referenced Rec. ITU-R BT.601 (formerly CCIR
  601), it references that specification for definition of the E'Y,
  E'Cb, and E'Cr signals that correspond to the YCBCR values specified
  herein. However, since the development of the prior JFIF version 1.02
  specification, additional industry specifications have been developed,
  Rec. ITU-R BT.601 has been updated, and common industry practice has
  emerged which often follows the sYCC specification in IEC
  61966-2-1/Amd.1. The difference between the use of the colour
  interpretation specification in this Recommendation | International
  Standard and that of the sYCC specification may be considered
  negligible in practice.

Rename the color space to sYCC, as its definition matches the sYCC
standard, and indicate that it is typically used to encode JPEG images.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2022-08-25 20:12:54 +03:00
Tomi Valkeinen
bf3dbaece9 py: Switch to non-blocking eventfd
Blocking wait can be easily implemented on top in Python, so rather than
supporting only blocking reads, or supporting both non-blocking and
blocking reads, let's support only non-blocking reads.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-19 15:44:28 +03:00
Tomi Valkeinen
de7f1aa591 py: Use libcamera's Mutex classes
Use libcamera's Mutex and MutexLocker instead of the std versions to get
thread safety annotations.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-19 15:44:26 +03:00
Tomi Valkeinen
dfa86000a6 py: Set EFD_CLOEXEC on eventfd to avoid fd leaking
Set EFD_CLOEXEC on eventfd to avoid fd leaking.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-19 15:44:24 +03:00
Tomi Valkeinen
f4933ee77f py: Use UniqueFD
Use UniqueFD to automate the eventfd lifetime management.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-19 15:44:21 +03:00
Tomi Valkeinen
f814b1b6a9 py: Create PyCameraManager
Wrap the CameraManager with a PyCameraManager class and move the related
code inside the new class.

This helps understanding the life times of the used-to-be global
variables, gets rid of static handleRequestCompleted function, and
allows us to simplify the binding code as the more complex pieces are
inside the class.

There should be no user visible functional changes.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-19 15:44:18 +03:00
Tomi Valkeinen
418cbde04b py: meson: Use libcamera_private dependency
We define -DLIBCAMERA_BASE_PRIVATE to get access to libcamera private
headers, but the correct way to do this is to have a meson dependency to
libcamera_private.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-19 15:44:09 +03:00
Tomi Valkeinen
36ea10a564 py: cam.py: Remove todo comment
The comment is no longer valid.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-08-18 22:02:07 +03:00
Tomi Valkeinen
4bd2d5191c py: Move ControlValue helpers to py_helpers.cpp
Clean up the py_main.cpp a bit by moving the ControlValue helpers to a
separate file.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.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>
2022-08-18 22:00:46 +03:00
Tomi Valkeinen
a7f73dd096 py: Add Python logging category
Add Python logging category, and use it in handleRequestCompleted().

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.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>
2022-08-18 22:00:43 +03:00
Tomi Valkeinen
93629989a9 py: cam.py: Fix multi camera capture without -C
-C flag is supposed to affect only the camera that was previously
defined in the arguments. That's not the case, and, e.g.:

cam.py -c2 -C -c3

causes camera 3 to start capturing, but it stops after the initial
Requests have been completed.

Fix the issue by filtering out camera contexts that do not have -C
defined.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.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>
2022-08-18 22:00:39 +03:00
Tomi Valkeinen
b4d4b78c82 py: examples: Add simple-cam.py
Add a Python version of simple-cam from:

https://git.libcamera.org/libcamera/simple-cam.git

Let's keep this in the libcamera repository until the Python API has
stabilized a bit more, and then we could move this to the simple-cam
repo.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-06-08 20:16:25 +03:00
Tomi Valkeinen
d6cfb08060 py: examples: Add simple-continuous-capture.py
Add a slightly more complex, and I think a more realistic, example,
where the script reacts to events and re-queues the buffers.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-06-08 20:16:21 +03:00
Tomi Valkeinen
ab21acb9c0 py: examples: Add simple-capture.py
Add an example to showcase the more-or-less minimal capture case.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-06-08 20:16:19 +03:00
Tomi Valkeinen
7ef83e0228 py: Merge read_event() and get_ready_requests()
We always call CameraManager.read_event() and
CameraManager.get_ready_requests(), so to simplify the use merge the
read_event() into the get_ready_requests().

This has the side effect that get_ready_requests() will now block if
there is no event ready. If we ever need to call get_ready_requests() in
a polling manner we will need a new function which behaves differently.

However, afaics the only sensible way to manage the event loop is to use
select/poll on the eventfd and then call get_ready_requests() once,
which is the use case what the current merged function supports.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-06-04 02:21:05 +03:00
Tomi Valkeinen
dfcf638a0a py: cam: cam_qt: mmap the fbs only once
Instead of doing an mmap and munmap every time a Request is complete,
mmap all the buffers once at the start of the program.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-06-01 12:09:10 +03:00
Tomi Valkeinen
958d9187aa py: MappedFrameBuffer: Add 'fb' property
Add 'fb' property to expose the underlying FrameBuffer.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-06-01 12:09:07 +03:00
Tomi Valkeinen
43192f4321 py: MappedFrameBuffer: Support non-contextmanager use
Implement non-contextmanager use to MappedFrameBuffer so that we can
either:

with MappedFrameBuffer(fb) as mfb:
	...

or

mfb = MappedFrameBuffer(fb)
mfb.mmap()
...
mfb.munmap()

While at it, improve the error handling a bit.

Note that the mmap() returns self. In other words, one can do this:

mfb = MappedFrameBuffer(fb).mmap()
...
mfb.munmap()

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-06-01 12:09:06 +03:00
Tomi Valkeinen
fbd6c4d1c8 py: Implement FrameBufferPlane
Implement FrameBufferPlane class and adjust the methods and uses
accordingly.

Note that we don't expose the fd as a SharedFD, but as an int.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-06-01 12:09:02 +03:00
Tomi Valkeinen
e8317de05c py: Add FrameMetadataPlane
Add FrameMetadataPlane class and adjust the methods and uses
accordingly.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-06-01 12:08:58 +03:00
Tomi Valkeinen
80e0ff355e py: Add Request.__str__()
Add Request.__str__() which maps directly to Request::toString().

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-06-01 12:08:56 +03:00
Tomi Valkeinen
7330474762 py: cam: Drop PIL dependency
We can use Qt directly to accomplish the same as we do with PIL.

A minor downside is that loading MJPEG frame with Qt produces a "Corrupt
JPEG data" warning. The resulting picture looks fine, though. So add a
message handler to ignore that warning.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2022-06-01 12:08:54 +03:00