Commit graph

2839 commits

Author SHA1 Message Date
Laurent Pinchart
f7c6b1228b test: Add tests for the Flags class
Add tests that exercise the whole API of the Flags class.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2021-08-03 10:55:21 +03:00
Laurent Pinchart
87c18aab8c libcamera: flags: Add type-safe enum-based flags
Add a Flags template class that provide type-safe bitwise operators on
enum values. This allows using enum types for bit fields, without giving
away type-safety as usually done when storing combined flags in integer
variables.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-08-03 10:55:20 +03:00
David Plowman
a792512496 utils: raspberrypi: ctt: Fix namespace for sklearn NearestCentroid function
Starting in version 0.22, the NearestCentroid function is only available
in the sklearn.neighbors namespace, when it was previously available in
both the sklearn.neighbors.nearest_centroid and sklearn.neighbors
namespaces. Use sklearn.neighbors as it works on all versions of
sklearn.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.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>
2021-08-03 10:54:26 +03:00
Paul Elder
e9288e2ee5 meson: Update min clang version to 9
__builtin_FILE and __builtin_LINE are first defined in clang 9. With
clang of any version less than that we have the following compilation
errors:

../../include/libcamera/base/log.h:94:27: error: use of undeclared identifier '__builtin_FILE'
                        const char *fileName = __builtin_FILE(),
                                               ^
../../include/libcamera/base/log.h:95:24: error: use of undeclared identifier '__builtin_LINE'
                        unsigned int line = __builtin_LINE()) const;
                                            ^
../../include/libcamera/base/log.h:99:26: error: use of undeclared identifier '__builtin_FILE'
                const char *fileName = __builtin_FILE(),
                                       ^
../../include/libcamera/base/log.h💯23: error: use of undeclared identifier '__builtin_LINE'
                unsigned int line = __builtin_LINE());

Enforce clang version of at least 9 in the main meson file.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-08-03 12:07:00 +09:00
Paul Elder
f0a427d4b7 android, controls: Add and plumb MaxLatency control
Add a MaxLatency control, and plumb it into the HAL accordingly.

Bug: https://bugs.libcamera.org/show_bug.cgi?id=50
Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-08-02 18:07:38 +09:00
Paul Elder
719ac76338 android: Add skeletal still and manual request templates
Add skeletal still and manual request templates so that we can expand
them for FULL support.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-08-02 18:07:35 +09:00
Paul Elder
822d9e61fa android: capabilities: Make keys list into set and member variable
We need to be able to add additional characteristics/request/result keys
into the corresponding list in the static metadata based on libcamera
camera capabilities. We also need to be able to easily check if the
lists have specific keys, for populating templates and result metadata.

Turn the characteristics, requests, and results keys vectors into sets,
and move them to member variables to achieve this.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-08-02 18:07:33 +09:00
Paul Elder
6b444acf46 android: Add helpers for setting android metadata from libcamera controls
Add helpers for setting android metadata from libcamera controls.

There are two versions, for scalars and collections, both of which take
a default value to fill in the android control if the libcamera control
is not found. They both return the value that was set.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-08-02 18:07:30 +09:00
Paul Elder
1c8140ba02 android: Add infrastructure for determining capabilities and hardware level
Add the infrastructure for checking and reporting capabilities. Use
these capabilities to determine the hardware level as well.

Bug: https://bugs.libcamera.org/show_bug.cgi?id=55
Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-08-02 18:07:27 +09:00
Paul Elder
ad2105c2a7 android: jpeg: get ISO from SENSOR_SENSITIVITY
The data for the exif ISO tag needs to come from SENSOR_SENSITIVITY. Set
it.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-08-02 18:07:24 +09:00
Paul Elder
c9e1f75791 android: metadata: Fix addEntry template type
Since we set entries with android tags directly, which are enums and not
arithmetic types, the addEntry template fails to match. Fix this by also
allowing enum values in addEntry.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-08-02 18:07:22 +09:00
Paul Elder
24f80f14af android: metadata: Add hasEntry and entryContains
Add convenience functions for checking if an entry is present in a
CameraMetadata instance, and to check if an array entry includes a
specific value.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-08-02 18:07:19 +09:00
Paul Elder
10cdc914da controls: Add boolean constructors for ControlInfo
It would be convenient to be able to iterate over available boolean
values, for example for controls that designate if some function can be
enabled/disabled. The current min/max/def constructor is insufficient,
as .values() is empty, so the values cannot be easily iterated over, and
creating a Span of booleans does not work for the values constructor.

Add new constructors to ControlInfo that takes a set of booleans (if
both booleans are valid values) plus a default, and another that takes
only one boolean (if only one boolean is a valid value).

Update the ControlInfo test accordingly.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-08-02 18:07:16 +09:00
David Plowman
fba85e6901 ipa: raspberrypi: Add support for imx378 sensor
This commit adds a tuning file for the 12MP imx378 sensor. The sensor
actually shares the same driver (and CamHelper) as the imx477 so only
a new tuning file is required. The default choice of imx477.json can
be overridden by pointing LIBCAMERA_RPI_TUNING_FILE at a version of
the new imx378.json file.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.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>
2021-08-02 03:44:31 +03:00
David Plowman
2d99cc53e2 utils: raspberrypi: ctt: Fix usage of findHomography function
The OpenCV findHomography function now raises an unhandled error if it
receives fewer than 4 points whereas previously the limit was 3. This
makes no material difference to the behaviour of the tuning tool as it
will continue to search for the Macbeth chart at different scales.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.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>
2021-08-02 03:43:53 +03:00
Naushir Patuck
b40a8d4b45 ipa: raspberrypi: Return controls::FrameDuration from the IPA
Return controls::FrameDuration through the per-frame Request metadata.
The frame duration is obtained by either the value in DelayedControls,
or (preferably) the value parsed from the embedded data buffer.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-07-28 11:26:07 +03:00
Naushir Patuck
e87fb20f8f pipeline: raspberrypi: Fix a bug when clearing out Request buffers on stop
When RPiCameraData::clearIncompleteRequests() clears out the request
queue during a stop condition, it unconditionally calls completeBuffer()
on all buffers in each request.  This is wrong, as a buffer could have
already been completed as part of the current request, but the request
itself may not yet have completed.

Fix this by checking if the buffers in the request have been completed
before cancelling them.

Fixes: d372aaa10d ("pipeline: raspberrypi: Simplify RPiCameraData::clearIncompleteRequests()")
Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Tested-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-07-28 09:55:24 +03:00
Vedant Paranjape
f573198d3e gstreamer: Store group_id in GstLibcameraSrcState
This patch adds group_id in GstLibcameraSrcState, since group_id is
something which should be same for all the pads, it can be reused
later.

Signed-off-by: Vedant Paranjape <vedantparanjape160201@gmail.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
2021-07-28 10:44:37 +09:00
Jacopo Mondi
804c52fce4 android: capabilities: Centralize RAW support check
The validation of RAW stream support is performed in two different
places:

- At initializeStreamConfigurations() time, by verifying that the
  libcamera format associated with HAL_PIXEL_FORMAT_BLOB is a Raw format
  and ensuring the Camera successfully validates it
- As initializeStaticMetadata() time by generating a CameraConfiguration
  for the Raw stream role and ensuring it is a Raw format with a 16 bit
  depth

The first check is used to build the list of supported Raw stream
resolutions. The latter is used to register the
ANDROID_REQUEST_AVAILABLE_CAPABILITIES_RAW capability.

As building the list of supported Raw streams doesn't serve any
purpose if the RAW capability is not registered, centralize the Raw
format support verification at initializeStreamConfigurations() time by
ensuring the supported format is a Raw one with a 16 bit depth.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-07-27 17:36:20 +02:00
Jacopo Mondi
18d61deb3c android: capabilties: Rationalize get[YUV|Raw]Resolution names
The getYUVResolutions() and getRawResolutions() functions are called
from the initializeStreamConfigurations() function, which is called by
initialize().

Rationalize the function naming scheme by renaming the two functions to
initializeYUVResolutions() and initializeRawResolution().

Cosmetic change only.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-07-27 12:57:34 +02:00
Jacopo Mondi
e1d43481b9 android: capabilities: Use a throw-away config for YUV stream building
When building the list of supported YUV streams in getYUVResolutions()
the CameraConfiguration provided by the caller as first parameters is used.

As the CameraConfiguration will be later actually applied to the Camera,
avoid any possible overlap of the configuration parameters by using a
throw-away CameraConfiguration generated for the Viewfinder stream role
in getYUVResolutions().

It's also nicer to avoid having two functions with a similar purpose
such as getYUVResolutions() and getRawResolutions() with different
parameter lists, as the presence of a CameraConfiguration as first
parameter might be confusing to the reader.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
2021-07-27 12:57:34 +02:00
Jacopo Mondi
9c2f6b973c ipa: core.mojom: Rework core file documentation
The comment block at the beginning of the core.mojom file is meant to
provide an overview of how to use libcamera defined types in the definition
of mojom interfaces.

As the IPA/IPC interface definition mechanism evolved, the documentation
has not been updated accordingly.

Update the file comments to match the most recent IPA/IPC
interface definition and generation mechanism.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-27 12:56:50 +02:00
Laurent Pinchart
a8aaf56857 cam: options: Restore std::cerr adjustment field
The std::cerr adjustment is set to std::left to print the usage text.
Restore it to its original value when done, to avoid affecting the
caller.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-27 13:28:07 +03:00
Umang Jain
28990d36fe utils: ipc: Assign a new gid to proxy worker
Isolated IPAs are forked to a new process by the proxy worker, which
shares the same process group. This allows the undesired effect that
the proxy worker will receive signals such as SIGINT and will be closed
by a Ctrl-C event before the pipeline handlers have been able to fully
clean up.

Prevent this signal from being delivered to the proxy worker by moving
the process to a new process group, matching the pid of the isolated
proxy.

Bug: https://bugs.libcamera.org/show_bug.cgi?id=60
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
2021-07-27 10:07:13 +05:30
Laurent Pinchart
799a04b7e7 libcamera: CameraSensorProperties: Sort entries
Keep entries sorted by sensor name to ensure the file stays readable.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-07-26 11:49:11 +03:00
Daniel Scally
34eef24d0b libcamera: Add OV8865 sensor properties
Add camera sensor properties for the OV8865 sensor. This is the world
facing camera on most MS Surface platforms.

Signed-off-by: Daniel Scally <djrscally@gmail.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-07-25 02:43:45 +03:00
Daniel Scally
2c88a6dbc1 libipa: Add CameraSensorHelper for ov8865
Add a CameraSensorHelperOv8865 class. The gain coefficients are gleaned
from the datasheet; the lowest 7 bits are reported there as fractional
bits, so real gain is val/128.

Signed-off-by: Daniel Scally <djrscally@gmail.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-07-25 01:52:48 +03:00
Umang Jain
48a380b389 libipa: Add CameraSensorHelper for IMX258
Extend the CameraSensorHelper factory with support for the IMX258
sensor found in the Nautilus Chromebook.

The values are read by manually tweaking the IMX258 kernel driver.
The IMX258 kernel driver hints that the sensor may be compatible
with the MIPI CCS specification, as the register set matches.
The values for analog gain constants are obtained by reading the
register indexes, corresponding to the analog gain constants, as
mentioned in MIPI CCS v1.1 specification.

The values have further been confirmed by Dave Stevenson as being
those specified in the datasheet.

Signed-off-by: Umang Jain <umang.jain@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-07-23 22:48:12 +05:30
Laurent Pinchart
951df850ad cam: Initialize CamApp::loopUsers_
The CamApp loopUsers_ member variable isn't initialized, which results
in random execution of the event loop. Fix it.

Fixes: caa6ffacb2 ("cam: Reorganize run() function and merge the two event loops")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Tested-by: Umang Jain <umang.jain@ideasonboard.com>
2021-07-23 18:40:48 +03:00
Laurent Pinchart
e0704e97ea cam: Support using multiple cameras concurrently
To allow testing capture from multiple cameras concurrently, turn the
--camera option into an array option, and create one CameraSession per
specified camera. The code is adapted to iterate over the sessions
vector instead of handling a single session. Thanks to all the
refactoring previously performed, changes are minimal.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:14:05 +03:00
Laurent Pinchart
721f4b03d8 cam: Add camera index to file name of capture frames
To prepare for multi-camera support, extend the file naming scheme for
captured frames to include the camera index in addition to the stream
name and frame number.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:14:03 +03:00
Laurent Pinchart
7dab1fa58f cam: Make camera-related options sub-options of OptCamera
Use the new hierarchical options feature of the option parser to turn
camera-related option (--capture, --file, --stream, --strict-formats and
--metadata) into children of the --camera option. As an added bonus, we
don't need to check anymore if a camera has been specified when capture
is requested, as that's now enforced by the option parser.

This change prepares for support of multiple cameras.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:13:59 +03:00
Laurent Pinchart
5082fe7b5b cam: Allow specifying directories in the --file option
The value of the --file option is the full name of the file to which
captured frames are written. To write files to a specific directory with
the default naming scheme, the "frame-#.bin" name has to appear at the
end of the file name. Simplify usage of the option by allowing --file to
specify a directory only. If the file name ends with a '/', the default
"frame-#.bin" file name is automatically appended.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:13:57 +03:00
Laurent Pinchart
caa6ffacb2 cam: Reorganize run() function and merge the two event loops
Reorganize the run() function to make it more readable, and merge the
two event loops into one as capture and hotplug monitoring don't have to
be mutually exclusive.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:13:55 +03:00
Laurent Pinchart
a2c634d449 cam: Move session_ member variable to a local variable in run() function
The session_ member of the CamApp class is only needed in the run()
function. Make it a local variable.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:13:54 +03:00
Laurent Pinchart
66c955648f cam: Move printing of camera information to CameraSession class
The three CamApp functions listControls(), listProperties() and
infoConfiguration() operate on a camera. They would thus be better
placed in the CameraSession class. Move them there. As they now have no
error to return anymore, make them void functions.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:13:53 +03:00
Laurent Pinchart
3d50939113 cam: Move camera session creation and monitoring setup to run()
Move creation of the camera session and setup of the hotplug monitoring
from the init() function to the run() function, to group all the code
that performs operations based on command line options in a single
place. The cleanup() call on session creation failure isn't required
anymore, as the cleanup() function is called unconditionally upon return
from run().

This change allows merging two different code blocks related to hotplug
monitoring.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:13:51 +03:00
Laurent Pinchart
e548e583cc cam: Make CamApp::cameraName() static
The CamApp::cameraName() doesn't need to access any member of the CamApp
class. Make it static. While at it, drop an unneeded const from the
return value.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:13:50 +03:00
Laurent Pinchart
2eeb431a93 cam: Drop unneeded error check and message
The EventLoop::exec() function returns the exit code of the event loop,
not an error status. Drop the corresponding error check and error
message.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:13:49 +03:00
Laurent Pinchart
033cac7f6d cam: Use std::unique_ptr<> to manage CameraManager
Store the CameraManager instance in a unique_ptr to simplify memory
management and avoid leaks.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:13:48 +03:00
Laurent Pinchart
8519df23a9 cam: Move camera acquire to the CameraSession class
Continue moving towards making the CameraSession class the central point
to handle a camera by moving the camera acquire operation. A new
CameraSession::camera() function is needed to allow access to the camera
from CamApp.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:13:47 +03:00
Laurent Pinchart
8e716be529 cam: Move CameraConfiguration creation to CameraSession class
Creating a configuration for a camera is an operation that logically
belongs to the CameraSession class. Move it there.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:13:46 +03:00
Laurent Pinchart
34d986d1ec cam: Store camera session pointer in CamApp class
Move the local CameraSession variable from the CamApp::run() function to
a member variable of the CamApp class, created in CamApp::init(). This
is a first step towards moving code to the CameraSession class.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:13:45 +03:00
Laurent Pinchart
24ca846a27 cam: camera_session: Use std::unique_ptr<> to manage class members
Store the BufferWriter and FrameBufferAllocator pointers in
std::unique_ptr<> instances to simplify memory management and avoid
leaks.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:13:44 +03:00
Laurent Pinchart
4cd0f586fb cam: Move event loop execution from CameraSession to CamApp
To prepare for multiple concurrent camera sessions, move the event loop
exec() call from the CameraSession class to the CamApp class.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:13:43 +03:00
Laurent Pinchart
011b3ff288 cam: Move event loop exit from CameraSession to CamApp
Make exiting the event loop the responsibility of the application, not
the camera session, to prepare for support of multiple camera sessions.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:13:42 +03:00
Laurent Pinchart
453583e189 cam: camera_session: Access event loop through global instance
Don't pass the event loop to the CameraSession constructor, as passing
this global object explicitly isn't a design that can scale.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:13:40 +03:00
Laurent Pinchart
94d828d880 cam: Rename Capture to CameraSession
Rename the Capture class to CameraSession, to prepare for multi-camera
support that will gather more camera-related operations than capture in
that class.

While at it, remove an unneeded blank line.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2021-07-22 17:13:39 +03:00
Laurent Pinchart
180e95f06a cam: options: Fail parsing when non-option arguments are found
The options parser currently ignores non-option arguments silently,
which is confusing. It's a common error to run 'cam -c1 -C 10' and
expect only 10 frames to be captured. As the -C option takes an optional
argument, the number 10 is interpreted as a non-option argument instead
of the argument to the -C option.

Fail parsing with an appropriate message and print usage information
when a non-option argument is found. The parser may be extended later to
accept non-option arguments when the application has a use for them.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-07-22 17:13:36 +03:00
Laurent Pinchart
3c63675560 cam: options: Avoid copies of OptionvValue and KeyValueParser::Options
The OptionValue toKeyValues() and toArray() functions return a copy of
the values. This is unnecessary, and can cause use-after-free issues
when taking references to the return values. Return references instead
to optimize the implementation and avoid issues.

The behaviour of the two functions is now undefined in case of an option
type mismatch. The current implementation catches this with an
assertion.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2021-07-22 17:13:32 +03:00