Commit graph

1111 commits

Author SHA1 Message Date
Laurent Pinchart
00804512c6 include: libcamera: Improve automation of libcamera.h generation
The gen-header.sh script that generates libcamera.h takes all .h files
in the include/libcamera/ directory, and manually adds the generated
control_ids.h and version.h. This is fragile, as shown by the failure to
add property_ids.h to the list in commit f870591a9b ("libcamera:
properties: Add location property").

To avoid future omissions, take all the .h.in files into account to
generate libcamera.h. This also fixes the missing property_ids.h.

Fixes: f870591a9b ("libcamera: properties: Add location property")
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-03-08 19:33:59 +02:00
Laurent Pinchart
34396936f7 gst: Fix GLib detection
Commit 17cccc68a8 ("Add GStreamer plugin and element skeleton") has
gained a last minute fix for a clang compilation error with GLib prior
to v2.63.0. The fix wasn't properly tested, and failed to check the GLib
dependency correctly. This resulted in compilation of the GStreamer
element to always be disabled.

Fix this by changing the GLib package name from 'glib' to 'glib-2.0'.

Fixes: 17cccc68a8 ("Add GStreamer plugin and element skeleton")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
2020-03-07 21:54:06 +02:00
Laurent Pinchart
f36ecf9824 gst: Turn the top-level plugin file gstlibcamera.c into a C++ file
The top-level plugin file gstlibcamera.c is the only C source file in
the whole libcamera GStreamer element. To avoid specifying both C and
C++ compiler arguments in the future, turn it into a C++ file.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
2020-03-07 21:53:59 +02:00
Nicolas Dufresne
6f344f8942 gst: Document dependencies and quick usage
This is a quick startup guide allowing to build and use the GStreamer element
from the libcamera source tree.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:58:08 +02:00
Jakub Adam
170def84c6 gst: libcamerasrc: Prevent src task deadlock on exhausted buffer pool
Allow GstLibcameraPool to notify the source when a new buffer has become
available in a previously exhausted buffer pool. This can be used to
resume a src task that got paused because it couldn't acquire a buffer.

Without this change the src task will never resume from pause once the
pool gets exhausted.

To trigger the deadlock (it doesn't happen every time), run:

  gst-launch-1.0 libcamerasrc ! queue ! glimagesink

Signed-off-by: Jakub Adam <jakub.adam@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:58:08 +02:00
Jakub Adam
9dab15bed6 gst: utils: Factor-out the task resume helper
Task resume will be added in the core GStreamer API in the future and
we will need to call this in another location in the following patches.

Signed-off-by: Jakub Adam <jakub.adam@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:58:08 +02:00
Nicolas Dufresne
a9ce14b0e0 gst: libcamerasrc: Add a TODO comment
This is to guide upcoming contributors toward what is left to do to get
toward a production ready element.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:58:08 +02:00
Nicolas Dufresne
0c4147c3b6 gst: libcamerasrc: Implement timestamp support
This is an experimental patch adding timestamp support to the libcamerasrc
element. This patch currently assume that the driver timestamp are relative to
the system monotonic clock. Without a reference clock source, the timestamp are
otherwise unusable, and without timestamp only minor use case can be achieved.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:58:08 +02:00
Nicolas Dufresne
d1d1348228 gst: libcamerasrc: Implement initial streaming
With this patch, the element is now able to push buffers to the next
element in the graph. The buffers are currently missing any metadata
like timestamp, sequence number. This will be added in the next commit.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:58:08 +02:00
Nicolas Dufresne
5d6db0936f gst: pad: Add method to store retrieve pending buffers
These will be useful for streaming. The requestComplete callback will
store the buffers on each pads so that the _run() can pick them up
and push them through the pads from a streaming thread.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:58:08 +02:00
Nicolas Dufresne
db50b1072a gst: Add getters for Stream and FrameBuffer
This adds getters on pad/pool/allocator so that we can retrieve the
Stream or FrameBuffer.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:58:08 +02:00
Nicolas Dufresne
6d0cf98bb1 gst: libcamerasrc: Allocate and release buffers
Setup the allocation and the release of buffers in the
element. We have one pooling GstAllocator that wraps the
FrameBufferAllocator and tracks the lifetime of FrameBuffer
objects. Then, for each pad we have a GstBufferPool object
which is only used to avoid re-allocating the GstBuffer
structure every time we push a buffer.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:58:08 +02:00
Nicolas Dufresne
a801f5e4f6 gst: libcamerapad: Allow storing a pool
This adds get/set helper to store a pool on the pad.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:58:08 +02:00
Nicolas Dufresne
bde275408c gst: Add a pool and an allocator implementation
This is needed to track the lifetime of the FrameBufferAllocator in relation to
the GstBuffer/GstMemory objects travelling inside GStreamer.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:58:07 +02:00
Nicolas Dufresne
d343326d28 gst: libcamerasrc: Push segment event
Now that we have stream-start and caps, we can now push a segment event to
announce what time will our buffer correlate to. For live sources this is just
an open segment in time format.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:57:45 +02:00
Nicolas Dufresne
2575b49160 gst: libcamerasrc: Implement minimal caps negotiation
This is not expected to work in every possible cases, but should be sufficient as
an initial implementation. What it does is that it turns the StreamFormats into
caps and queries downstream caps with that as a filter.

The result is the subset of caps that can be used. We then keep the first
structure in that result and fixate using the default values found in
StreamConfiguration as a default in case a range is available.

We then validate this configuration and turn the potentially modified
configuration into caps that we push downstream. Note that we trust the order
in StreamFormats as being sorted best first, but this is not currently in
libcamera. A todo has been added in the head of this file as a reminder to fix
that in the core.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:57:45 +02:00
Nicolas Dufresne
bd0c2df110 gst: utils: Add StreamConfiguration helpers
This adds helpers to deal with the conversion from StreamConfiguration
to caps and vice-versa. This is needed to implement caps negotiation.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:57:45 +02:00
Nicolas Dufresne
e5f4398c19 gst: libcamerasrc: Send stream start event
Prior to sending caps, we need to send a stream-start event. This requires
generating a stream and a group id. The stream id is random for live sources and
the group id is shared across all pads.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:57:45 +02:00
Nicolas Dufresne
6d69661c24 gst: libcamerasrc: Store the srcpad in a vector
This will allow implementing generic algorithm even if we cannot
request pads yet.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:57:45 +02:00
Nicolas Dufresne
d41b356564 gst: libcamerapad: Add a method to access the role
Each pad can have a different roles. Users will have to request and configure
their pads role before moving to a higher state.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:57:45 +02:00
Nicolas Dufresne
1d8cbaf214 gst: libcamerasrc: Add a task for the streaming thread
Use a GstTask as our internal streaming thread. Unlike GstBaseSrc, we
will be running a streaming thread at the element level rather than
per pad. This is needed to combine buffer request for multiple pads.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:57:45 +02:00
Nicolas Dufresne
58feb69f85 gst: libcamerasrc: Implement selection and acquisition
This adds code to select and acquire a camera. With this, it is now
possible to run a pipeline like:

   gst-launch-1.0 libcamerasrc ! fakesink

Though no buffer will be streamed yet. In this function, we implement the
change_state() virtual method to trigger actions on specific state transitions.
Note that we also return GST_STATE_CHANGE_NO_PREROLL in
GST_STATE_CHANGE_READY_TO_PAUSED and GST_STATE_CHANGE_PLAYING_TO_PAUSED
transitions as this is required for all live sources.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:57:45 +02:00
Nicolas Dufresne
cfa61225a4 gst: libcamerasrc: Add a debug category
This will allow selecting libcamerasrc traces with the following
environment:

  GST_DEBUG=libcamerasrc:7

Or all libcamera GStreamer element traces using

  GST_DEBUG="libcamera*:7"

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:57:45 +02:00
Nicolas Dufresne
2c93810ec1 gst: libcamerasrc: Add camera-name property
This property will be used to select by name the camera to use.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:57:45 +02:00
Nicolas Dufresne
26c923a27c gst: libcamerasrc: Allocate and add static pad
This pad will always be present and will allow simple pipeline to be used to
stream from the camera.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:57:45 +02:00
Nicolas Dufresne
71a28f9593 gst: Add pads to the source
This simply adds the boiler plate for pads on the source element. The
design is that we have one pad, called "src", that will always be
present, and then more pads can be requested prior in READY or less
state. Initially pads have one property "stream-role" that let you
decide which role this pad will have.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:57:45 +02:00
Nicolas Dufresne
7e82d3c2a1 gst: utils: Add simple scoped lockers for GMutex and GRectMutex
While GLib has locker implementation already using g_autoptr(), recursive mutex
locker was only introduced in recent GLib. Implement a simple locker for GMutex
and GRectMutex in order to allow making locking simpler and safer.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:57:45 +02:00
Nicolas Dufresne
0e0cc2149e gst: Add initial device provider
This feature is used with GstDeviceMonitor in order to enumerate
and monitor devices to be used with the source element. The resulting
GstDevice implementation is also used by application to abstract the
configuration of the source element.

Implementation notes:
  - libcamera does not support polling yet
  - The device ID isn't unique in libcamera yet
  - The "name" property does not yet exist in libcamerasrc yet

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:57:45 +02:00
Nicolas Dufresne
eee8f56f0a gst: Add utility to convert StreamFormats to GstCaps
This transforms the basic information found in StreamFormats to GstCaps.
This can be handy to reply to early caps query or inside a device
provider. Note that we ignored generated range as they are harmful to
caps negotiation. We also don't simplify the caps for readability
reasons, so some of the discrete value may be included in a range.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:57:45 +02:00
Nicolas Dufresne
17cccc68a8 Add GStreamer plugin and element skeleton
This implements the GStreamer plugin interface and adds libcamerasrc
element feature to it. This is just enough to allow plugin
introspection.

gst-inspect-1.0 build/src/gstreamer/libgstlibcamera.so
Plugin Details:
  Name                     libcamera
  Description              libcamera capture plugin
  Filename                 build/src/gstreamer/libgstlibcamera.so
  Version                  0.0.0+1042-6c9f16d3-dirty
  License                  LGPL
  Source module            libcamera
  Binary package           libcamera
  Origin URL               https://libcamera.org

  libcamerasrc: libcamera Source

  1 features:

GST_PLUGIN_PATH=$(pwd)/build/src/gstreamer gst-inspect-1.0 libcamerasrc
Factory Details:
  Rank                     primary (256)
  Long-name                libcamera Source
  Klass                    Source/Video
  Description              Linux Camera source using libcamera
  Author                   Nicolas Dufresne <nicolas.dufresne@collabora.com

Plugin Details:
  Name                     libcamera
  Description              libcamera capture plugin
  Filename                 /home/nicolas/Sources/libcamera/build/src/gstreamer/libgstlibcamera.so
  Version                  0.0.0+1042-6c9f16d3-dirty
  License                  LGPL
  Source module            libcamera
  Binary package           libcamera
  Origin URL               https://libcamera.org

GObject
 +----GInitiallyUnowned
       +----GstObject
             +----GstElement
                   +----GstLibcameraSrc

Pad Templates:
  none

Element has no clocking capabilities.
Element has no URI handling capabilities.

Pads:
  none

Element Properties:
  name                : The name of the object
                        flags: accès en lecture, accès en écriture, 0x2000
                        String. Default: "libcamerasrc0"
  parent              : The parent of the object
                        flags: accès en lecture, accès en écriture, 0x2000
                        Object of type "GstObject"

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
[Silence -Wunused-function warning for older GLib versions]
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-07 01:57:42 +02:00
Laurent Pinchart
2cc90af8c7 libcamera: v4l2_videodevice: Don't use std::atomic specialization
The std::atomic_uint64_t specialization was missing from C++14, and only
added to C++17 (see LWG 2441). It was treated as a Defect Report and
backported to earlier C++ standards by gcc and clang, but is missing
from libstdc++ shipped with gcc 5 and gcc 6. Fix the compilation error
by using std::atomic<uint64_t> instead.

Fixes: 4e0d1eca10 ("libcamera: V4L2BufferCache: Improve cache eviction strategy")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-03-07 01:15:43 +02:00
Niklas Söderlund
4e0d1eca10 libcamera: V4L2BufferCache: Improve cache eviction strategy
The strategy used to find a free cache entry in the first implementation
was not the smartest, it picked the first free entry. This lead to
unwanted performance issues as the cache was not used as good as it
could for imported buffers.

Improve this by adding a last usage sequence number to the cache entries
and change the eviction strategy to use the oldest free entry instead of
the first one it finds.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-06 17:45:48 +01:00
Niklas Söderlund
69d1e24ac7 test: v4l2_videodevice: Add test for V4L2BufferCache
Add test to test the different modes and situations the V4L2BufferCache
can be put in. The tests verify that a FrameBuffer used with the cache
results in a V4L2 video device index, and that the cache implementation
is capable of keeping buffers in a hot state.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-06 17:45:48 +01:00
Niklas Söderlund
b167158395 libcamera: V4L2BufferCache: Check for hot hit first
Check for a hot cache hit before updating which buffer is best to evict
in case no hot hit is found. This doesn't change the behaviour, but
follows a more logical flow.

Suggested-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-06 17:45:48 +01:00
Niklas Söderlund
bab5749227 libcamera: V4L2BufferCache: Use the entry reference
Instead of looking up the index in the storage vector use the reference
to it created at the beginning of the loop.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-06 17:45:48 +01:00
Niklas Söderlund
353851b773 libcamera: V4L2BufferCache: Mark Entry::operator==() as const
The comparison operator does not change any state, mark it as const.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-06 17:45:48 +01:00
Niklas Söderlund
257df552a4 test: Extract BufferSource class out of camera tests to libtest
The BufferSource class can be used by other tests other then the camera
buffer importer test, move it to libtest. The only changes to
BufferSource is for it to be allowed to be split in a header and source
file.

This change makes it necessary for libtest to have access to internal
libcamera headers. As the internal headers already are accessible to all
test cases this does not increase the exposure of libcamera internals to
the test cases.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-06 17:45:48 +01:00
Niklas Söderlund
42a00cb617 test: camera: buffer_import: Fix error messages
The error message for when a device name can't be resolved to a video
device is wrong and applies to the next operation below it. Move it to
its correct location and add a new error message to highlight the
resolution failure.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-03-06 17:45:48 +01:00
Jacopo Mondi
a14b6baca9 cam: Add option to list camera properties
Add the '-p'|'--list-properties' option to the cam application to list
the properties of a camera.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-03-06 18:35:36 +02:00
Laurent Pinchart
50478550e5 test: controls: control_value: Expand test to cover array controls
Add tests to ControlValueTest to cover array controls of all supported
types.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-03-06 18:35:34 +02:00
Laurent Pinchart
38d6e5b9ca test: controls: control_value: Expand test to cover all control types
The ControlValueTest hasn't been updated for a long time and is
outdated. Improve it to support all control types, and test the type(),
isArray() and toString() methods.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-03-06 18:10:51 +02:00
Jacopo Mondi
fa252b710a libcamera: control_serializer: Add support for array controls
Add support for serializing and deserializing control values that store
arrays of values. The serialized format is extended to explicitly handle
arrays.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-03-06 18:10:50 +02:00
Laurent Pinchart
7c6f59217e libcamera: control_serializer: Use zero-copy ByteStreamBuffer::read()
Use the zero-copy variant of ByteStreamBuffer::read() to read packet
headers and control entries. This enhances the performance of
ControlList and ControlInfoMap deserialization.

Deserialization of the actual ControlValue is untouched for now and will
be optimized later.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.binghm@ideasonboard.com>
2020-03-06 18:10:49 +02:00
Laurent Pinchart
5467d61925 libcamera: control_serializer: Simplify serialization of ControlValue
Use the ControlValue::data() function to access raw data stored in the
control value and simplify serialization.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.binghm@ideasonboard.com>
2020-03-06 18:10:48 +02:00
Laurent Pinchart
44ff5a18e4 libcamera: control_serializer: Use explicit ControlTypeNone case
Replace the default case with an explicit ControlTypeNone case in
ControlSerializer::load() to catch omissions when adding new control
types.

A return statement needs to be added to the end of the function to avoid
gcc incorrectly reporting that some exit paths don't contain a return
statement. The compiler will still warn that not all cases are handled
when adding a new control type.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-03-06 18:10:45 +02:00
Laurent Pinchart
7f2da874cd libcamera: byte_stream_buffer: Add zero-copy read() variant
Add a read() function to ByteStreamBuffer that returns a pointer to the
data instead of copying it. Overflow check is still handled by the
class, but the caller must check the returned pointer explicitly.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-03-06 18:10:44 +02:00
Jacopo Mondi
8a1f0321dc libcamera: byte_stream_buffer: Add Span<> support
Add support to write and read a Span<> to and from the ByteStreamBuffer
class.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-03-06 18:10:43 +02:00
Jacopo Mondi
34fc1f38bd libcamera: byte_stream_buffer: Fix documentation of read() and write()
The documentation of the read() and write() functions refer to non
existent 'size' and 'data' parameters in their brief. Fix them.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-03-06 18:10:42 +02:00
Laurent Pinchart
427c37f671 libcamera: ipa: Support array controls in ipa_control_value_entry
Report in a new field of the ipa_control_value_entry structure if the
value contains an array. Reorganize the other fields of the structure to
avoid increasing its size.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-03-06 18:10:41 +02:00
Laurent Pinchart
1716d4e86f libcamera: controls: Convert bool ControlValue to lowercase strings
The C++ boolean types are lower case, and std::ostream::operator<<(bool)
produces a lowercase string (when std::boolalpha is in effect, otherwise
it produces 0 or 1).  Switch ControlValue::toString() to produce
lowercase "true" and "false" strings too for consistency.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-03-06 18:10:40 +02:00