Commit graph

1004 commits

Author SHA1 Message Date
Helen Koike
b3dbccd328 utils: rkisp1: sync topology with upstream driver in capture script
rkisp1 kernel driver was merged upstream with minor changes in the
topology from the original driver libcamera based it's first support to
rkisp1.

Adapt libcamera capture script to work with upstream driver.

* Remove subdevice dphy from the pipeline.
* Add resizer in the pipeline.
* Fix links.
* Update entity names.

Signed-off-by: Helen Koike <helen.koike@collabora.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-02-13 14:55:20 +01:00
Helen Koike
8f6aa56036 libcamera: pipeline: rkisp1: sync topology with upstream driver
rkisp1 kernel driver was merged upstream with minor changes in the
topology from the original driver libcamera based it's first support to
rkisp1.

Adapt libcamera pipeline to work with upstream driver.

* Remove subdevice dphy from the pipeline.
* Add resizer in the pipeline.
* Fix links.
* Update entity names.

Signed-off-by: Helen Koike <helen.koike@collabora.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-02-13 14:55:20 +01:00
Laurent Pinchart
461e7ac873 meson.build: Silence the C99 designators warning
We use array designators for array initialization, which is a C99
extension. clang-10 warns about it, causing a build failure.

As this is a useful extension, silence the warning. This needs to be
done only if the compiler supports the -Wno-c99-designator argument,
otherwise a -Wunknown-warning-option will be generated.

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-02-13 14:10:48 +02:00
Laurent Pinchart
da3f50ee9c android: Remove internal thread
Now that libcamera creates threads internally and doesn't rely on an
application-provided event loop, remove the thread from the Android
Camera HAL layer. The CameraProxy class becomes meaningless, remove it
and communicate directly from the CameraHalManager to the CameraDevice.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Jacopo Mondi <jacopo@jmondi.org>
2020-02-13 13:23:23 +02:00
Laurent Pinchart
8a8502ec0e v4l2: Remove internal thread
Now that libcamera creates threads internally and doesn't rely on an
application-provided event loop, remove the thread from the V4L2
compatibility layer. The split between the V4L2CameraProxy and
V4L2Camera classes is still kept to separate the V4L2 adaptation from
camera operation. This may be further refactored later.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-02-13 12:34:42 +02:00
Laurent Pinchart
b3b0d0a2e9 libcamera: pipeline_handler: Document the threading model
Document the threading model of the PipelineHandler class (and all its
derived classes). The model is already enforced by the Camera class, so
no change in the implementation is required. As for the Camera class,
disconnection is currently left out.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-02-13 12:34:41 +02:00
Laurent Pinchart
a8310248fc libcamera: camera: Implement the threading model
Document the threading model of the Camera class and implement it.
Selected functions become thread-safe, and require a few functions of
the PipelineHandler class to be called through cross-thread invocation
as the pipeline handlers live in the camera manager thread, while the
Camera class is mostly accessed from the application thread. The
PipelineHandler is made to inherit from the Object class to support
this.

Disconnection is currently left out as it is not implemented in pipeline
handlers, and isn't fully supported in the Camera class either. This
will be revisited when implementing proper hotplug support.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-02-13 12:34:40 +02:00
Laurent Pinchart
1aa49db823 libcamera: camera_manager: Run the camera manager in a thread
Relying on the application event loop to process all our internal events
is a bad idea for multiple reasons. In many cases the user of libcamera
can't provide an event loop, for instance when running through one of
the adaptation layers. The Android camera HAL and V4L2 compatibility
layer create a thread for this reason, and the GStreamer element would
need to do so as well. Furthermore, relying on the application event
loop pushes libcamera's realtime constraints to the application, which
isn't manageable.

For these reasons it's desirable to always run the camera manager, the
pipeline handlers and the cameras in a separate thread. Doing so isn't
too complicated, it only involves creating the thread internally when
starting the camera manager, and synchronizing a few methods of the
Camera class. Do so as a first step towards defining the threading model
of libcamera.

The event dispatcher interface is still exposed to applications, to
enable cross-thread signal delivery if desired.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-02-13 12:34:35 +02:00
Laurent Pinchart
09c45cc1fa libcamera: signal: Make connection and disconnection thread-safe
Make the signal connection and disconnection thread-safe, and document
them as such. This is required to make objects connectable from
different threads.

The connect(), disconnect() and emit() methods are now all protected by
a global mutex, which may generate a high lock contention. This could be
improved with finer-grained locks or with a pool of mutexes.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-02-13 12:34:34 +02:00
Laurent Pinchart
89503199e8 libcamera: Document thread-safety attributes of core classes
Define the thread-safety attributes of the classes and methods that are
either thread-safe or thread-bound. The CameraManager, Camera and
PipelineHandler will be addressed separately.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-02-13 12:34:32 +02:00
Laurent Pinchart
fcfa11177f libcamera: Define the threading model
Document the design of libcamera's threading support, and prepare to
document thread-safety of classes and functions with a doxygen alias
command.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-02-13 12:34:28 +02:00
Naushir Patuck
8ce24bebbf qcam: Switch default stream role to viewfinder
qcam currently only displays a standard viewfinder. As such set the
StreamRole parameter to Viewfinder so that the pipeline handlers can
setup the appropriate resolutions and formats.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-02-11 11:12:23 +02:00
Laurent Pinchart
68e76b668a libcamera: ipa_module: Use ElfW() macro for native word size
Access the ELF types corresponding to the native word size using the
ElfW() macro instead of template types. This is the standard method and
simplifies the code.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-02-10 16:41:40 +02:00
Kieran Bingham
fd6f3e2a65 libcamera: framebuffer_allocator: Fix spelling
Fix two trivial issues in the documentation of the FrameBufferAllocater
class.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-02-04 16:10:19 +00:00
Madhavan Krishnan
b448bfb426 libcamera: pipeline_handler: Fix the compilation issue in musl
sys/sysmacros.h was an incorrect choice, which doesn't work with musl.

POSIX mandates dev_t to be defined by sys/types.h, so utilise that
header instead.

Fixes: effe4d6ced ("libcamera: camera_manager, pipeline_handler: allow retrieving cameras by device numbers")

Signed-off-by: Madhavan Krishnan <madhavan.krishnan@linaro.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-02-04 15:54:07 +00:00
Kieran Bingham
1a6d0f5e9a libcamera: log: Expand log level names
When the log severity names were added, there was only 4 characters
reserved for their printing. When the FATAL level was added, this
increased to 5, and thus both DBG and ERR can be expanded to their full
spelling. This also brings the levels in line with the representation
that can be used when calling logSetLevel().

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-01-31 14:56:22 +00:00
Kieran Bingham
4b44f61c53 Documentation: Add linkcheck target
Sphinx provides a run-target to verify external links specified in the
documentation. This requires an active connection to be able to validate
the links.

Add a meson target to integrate the linkcheck facility into our build
and test system.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-31 14:54:28 +00:00
Laurent Pinchart
7aeff19555 libcamera: camera: Centralize state checks in Private class
Move all accesses to the state_ and disconnected_ members to functions
of the Private class. This will make it easier to implement
synchronization, and simplifies the Camera class implementation.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-01-23 22:36:30 +02:00
Laurent Pinchart
a4be7bb5ff libcamera: camera: Move private data members to private implementation
Use the d-pointer idiom ([1], [2]) to hide the private data members from
the Camera class interface. This will ease maintaining ABI
compatibility, and prepares for the implementation of the Camera class
threading model.

The FrameBufferAllocator class accesses the Camera private data members
directly. In order to hide them, this pattern is replaced with new
private member functions in the Camera class, and the
FrameBufferAllocator is updated accordingly.

[1] https://wiki.qt.io/D-Pointer
[2] https://en.cppreference.com/w/cpp/language/pimpl

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-01-23 22:36:30 +02:00
Laurent Pinchart
a0295fdaf8 libcamera: camera_manager: Return a copy of the vector from cameras()
Making CameraManager::cameras() thread-safe requires returning a copy of
the cameras vector instead of a reference. This is also required for
hot-plugging support and is thus desirable.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-01-23 22:36:30 +02:00
Laurent Pinchart
b6467bd9c6 libcamera: camera_manager: Move private data members to private implementation
Use the d-pointer idiom ([1], [2]) to hide the private data members from
the CameraManager class interface. This will ease maintaining ABI
compatibility, and prepares for the implementation of the CameraManager
class threading model.

[1] https://wiki.qt.io/D-Pointer
[2] https://en.cppreference.com/w/cpp/language/pimpl

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-01-23 22:36:08 +02:00
Laurent Pinchart
ce2ea24fb4 libcamera: Fix documentation of buffer allocation/export functions
The V4L2VideoDevice::exportBuffers(),
PipelineHandler::exportFrameBuffers() and
FrameBufferAllocator::allocate() functions all return the number of
allocated buffers on success, but are documented as returning 0 in that
case. Fix their documentation.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-01-22 18:46:00 +02:00
Laurent Pinchart
667f53b522 libcamera: signal: Make slots list private
The slots list is touched from most of the Signal template functions. In
order to prepare for thread-safety, move handling of the list to a small
number of non-template functions in the SignalBase class.

This incidently fixes a bug in signal disconnection handling where the
signal wasn't removed from the object's signals list, as pointed out by
the signals unit test.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-01-22 17:26:42 +02:00
Laurent Pinchart
b6d93f9772 test: signal: Add additional disconnection tests for Object
Add two tests that exercise the Signal::disconnect(Object *) and
Signal::disconnect() methods, to verify that they correctly remove the
signal from the connected object's list of signals. This triggers an
issue that was detected through manual code inspection, and is expected
to crash or at least generate valgrind warnings.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-01-22 17:26:20 +02:00
Laurent Pinchart
0228e9c927 libcamera: Declare static local variables as const where applicable
We use static local variables to indicate errors in methods that return
a const reference. The local variables can thus be const, make them so.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-01-22 17:26:17 +02:00
Laurent Pinchart
7216c6a9bb libcamera: bound_method: Use std::index_sequence
Now that we're using C++-14, replace the manual implementation of
std::integer_sequence with std::index_sequence, a specialization of
std::integer_sequence with the integer type equal to std::size_t. The
template parameter S that denotes a sequence is replaced with I to align
with the usage examples of cppreference.com.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-01-22 17:26:05 +02:00
Laurent Pinchart
8034af7423 libcamera: bound_method: Avoid deadlock with ConnectionTypeBlocking
ConnectionTypeBlocking always invokes the method through inter-thread
message passing, which results in deadlocks if the sender and receiver
live in the same thread. The deadlock can easily be avoided by turning
the invocation into a direct call in this case. Do so to make
ConnectionTypeBlocking easier to use when some of the senders live in
the same thread as the receiver while the other senders don't.

Extend the object-invoke test to cover this usage.

While at it reformat the documentation to avoid long \brief lines.

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>
2020-01-20 19:12:14 +02:00
Laurent Pinchart
9977fc3fcb qcam: Support scaling of the viewfinder
The viewfinder is drawn using a QLabel. This could support scaling
through QLabel::setScaledContents(), but in a very inefficient way. To
maintain reasonable efficiency, turn the viewfinder into a QWidget and
draw the image directly using a QPainter.

No performance change was noticed running on a fast x86 machine, and
performance was 60% higher when scaling up to full screen compared to
QLabel.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-01-20 18:35:12 +02:00
Laurent Pinchart
026b3af8c2 libcamera: log: Print the thread ID in the log
The current thread ID is useful when debugging concurrency issues. Print
it in log messages. The syslog target is left out as the thread ID would
have little use there, and partly duplicates the process ID.

The log messages now look as follows.

[19:10:33.206560546] [22096] INFO Camera camera_manager.cpp:274 libcamera v0.0.0+993-32696686

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2020-01-20 13:35:59 +02:00
Laurent Pinchart
1d929967b7 libcamera: thread: Add a method to return the ID of the current thread
The current thread ID is useful when logging message to debug
concurrency issues. Add a method to retrieve it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2020-01-20 13:35:59 +02:00
Laurent Pinchart
a39b91d44e test: buffer_import: Propagate status code from buffer allocation
The BufferSource::allocate() return value isn't propagated correctly,
resulting in a test failure when the test should be skipped due to a
missing vivid device. Fix it.

While at it, return valid status codes from BufferSource::allocate() in
all error cases, with proper diagnostic messages.

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>
2020-01-20 13:35:55 +02:00
Nicolas Dufresne
632e0fc09f v4l2: Extend device caps with V4L2_CAP_STREAMING
This capability tells the application that mmap() is supported. GStreamer
would return an error saying there there is no input/output method supported
by this device otherwise. This was tested with:

LD_PRELOAD=$(pwd)/build/src/v4l2/v4l2-compat.so GST_DEBUG="v4l2*:7" gst-launch-1.0 v4l2src ! videoconvert ! autovideosink

With this patch, GStreamer will reach playing state. It then blocks waiting on
poll() which is not implemented yet on our side.

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>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-01-20 12:21:58 +02:00
Nicolas Dufresne
3628fb704b checkstyle: Add a pre-commit hook script
This adds support for pre-commit hook workflow. In pre-commit hook we
check the style on the changes currently staged or the combination
of the index and the last commit if "git commit --amend" is being used.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-18 22:41:00 +02:00
Nicolas Dufresne
17b3c79409 checkstyle: Add support for checking style on amendments
This introduces a new argument "--amend" and a new special type of
commit "Amendment". It will check the style of changes that are in
the index combined with the changes of the last commit. So this is
the changes that would be applied by "git commit --amend" hence the
name of the argument.

This is needed to implement pre-commit hook.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-18 22:40:55 +02:00
Nicolas Dufresne
8bf8442565 checkstyle: Add support for checking style on staged changes
This introduces a new command line "--staged" and a new special type of
commit "StagedChanges". It will check the style of changes that are in
the index, so the changes that would be committed by "git commit".

"--staged" was chosen to match with "git diff --staged" command line.
Other valid name could have been "--index" or "--cached". This was
my personal preference, aliases can be added later. Note that we must
not confuse this with working tree changes, as these changes are not
picked by "git commit".

This feature is needed to implement pre-commit hook.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-18 22:05:03 +02:00
Nicolas Dufresne
fef2f02324 checkstyle: Introduce a Commit class
This introduces a Commit class used in the final revlist list. All the
git commands are moved into that class. This class will be used to
introduce new types of commit (StagedChanges and Amendment) needed to implement
pre-commit hook support.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-18 22:05:03 +02:00
Nicolas Dufresne
0b86152a57 checkstyle: Exit with 1 status if issues are found
Makes the tool return 1 if there is any potential issues. This is
needed when using this tool for pre-commit hook in order to abort
the commit process.

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-18 22:05:03 +02:00
Nicolas Dufresne
3e0c32f992 checkstyle: Move from pep8 to pycodestyle
The tool has been renamed in 2016 to make it more obvious what it
is doing. There is no other changes needed on our side.

See https://github.com/PyCQA/pycodestyle/issues/466

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-18 22:05:03 +02:00
Laurent Pinchart
30f9624f89 README: Remove duplicated line
The commit 2de78434ca ("meson: Bump required version to 0.47")
included an extra duplicated line (my bad, the issue happened when
applying). Fix it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-01-17 01:34:51 +02:00
Nicolas Dufresne
2de78434ca meson: Bump required version to 0.47
This is needed to use option type 'feature'. This is a tri-state
(auto/enabled/disabled) which comes with utility to enable them all, or
disabled them all to avoid any dynamic selection happening. It can also
be used as value to any "required" field.

This will be used in GStreamer support. If you don't have a recent enough
meson in your distribution, you can always install or upgrade your version
using pip3.

  pip3 install --user meson
  pip3 install --user --upgrade meson

Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-17 01:17:18 +02:00
Laurent Pinchart
38dd90307a libcamera: Remove std::piecewise_construct where not necessary
When inserting an element with emplace(), the element is constructed
in-place with the parameters to the emplace() method being forwarded to
the constructor of the element. For std::map containers, the element is
an std::pair<const Key, T>. The constructors of std::pair<T1, T2> fall
into three categories:

(1) Default, copy and move constructors (and related versions)
(2) Constructors that take lvalue or rvalue references to T1 and T2
(3) A forwarding constructor that forwards parameters to the
    constructors of T1 and T2

The first category isn't useful in most cases for std::map::emplace(),
as the caller usually doesn't have an existing std::pair<const Key, T>
for the element to be inserted.

The constructor from the third category is useful to avoid constructing
intermediate Key or T instances when the caller doesn't have them
available. This constructor takes two std::tuple arguments that contain
the arguments for the Key and T constructors, respectively. Due to
template deduction rules, usage of such a constructor couldn't be
deduced by the compiler automatically in all cases, so the constructor
takes a first argument of type std::piecewise_construct_t that lets the
caller force the usage ot the forwarding constructor (also known for
this reason as the piecewise constructor). The caller uses a construct
such as

        map.emplace(std::piecewise_construct,
                    std::forward_as_tuple(args_for_Key, ...),
                    std::forward_as_tuple(args_for_T, ...));

This syntax is a bit heavy, but is required to construct Key and T
in-place from arguments to their non-default constructor (it is also the
only std::pair non-default constructor that can be used for non-copyable
non-movable types).

When the caller of std::map::emplace() already has references to a Key
and a T, they can be passed to the std::pair piecewise constructor, and
this will create std::tuple instance to wrap the Key and T references
arguments to ultimately pass them to the Key and T copy constructors.

        map.emplace(std::piecewise_construct,
                    std::forward_as_tuple(Key_value),
                    std::forward_as_tuple(T_value));

While this mechanism works, it's unnecessary complex. A constructor of
std::pair that takes references to Key and T can be used without any
performance penalty, as it will also call the copy constructor of Key
and T. In this case we can use a simpler constructor of std::pair, and
thus a simpler call of std::map::emplace.

        map.emplace(Key_value, T_value);

We have a couple occurrences of this above misuse of piecewise
construction. Simplify them, which simplifies the code and reduces the
generated code size.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-01-16 19:29:16 +02:00
Laurent Pinchart
acf18e4265 libcamera: Switch from utils::make_unique to std::make_unique
Now that we're using C++-14, drop utils::make_unique for
std::make_unique.

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-01-14 19:06:40 +02:00
Laurent Pinchart
9a61a13466 meson.build: Switch to C++14
C++14 is a minor release that doesn't introduce major new concepts or
paradigms compared to C++11, but brings two useful changes for us:

- std::make_unique allows dropping our custom implementation in utils.
- Functions returning constexpr are not assumed to be const anymore,
  which is needed to create a standard-conformant span implementation.

All the g++ and clang++ versions we support and test (g++-5 onwards and
clang++6 onwards) support C++14. However, due to a defect in the
original C++14 specification, solved in N4387 ([1]), compilation would
fail on g++-5 due to the use of std::map::emplace() with a non-copyable
value type. It turns out we can easily fix it by switching to the
explicit piecewise emplace() overload.

There is thus really nothing holding back the switch. Let's do it, and
update the coding style accordingly.

[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4387

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-01-14 19:06:40 +02:00
Laurent Pinchart
055335bf49 libcamera: gen-controls.py: Don't hardcode path to python interpreter
The gen-controls.py script hardcodes the path to the python interpreter
to /usr/bin/python3 in the first line of the script. This hardcodes
usage of the host python3, even when building in cross-compilation
environments that may ship their own version of python. Fix it by
setting the interpreter to '/usr/bin/env python3'.

Reported-by: Madhavan Krishnan <madhavan.krishnan@linaro.org>
Suggested-by: Nicolas Dufresne <nicolas@ndufresne.ca>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-01-14 15:33:43 +02:00
Laurent Pinchart
744fabcbb9 libcamera: ipa_interface: Fix doxygen warning
Doxygen generates the following warning:

src/libcamera/ipa_interface.cpp:262: warning: explicit link request to 'dup()' could not be resolved

Fix it by disabling link generation by prefixing the function name with
a %.

Fixes: 4b9bd6c3ad ("libcamera: ipa_interface: Document the ownership of dmabufs passed to map_buffers()")
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-01-14 02:14:54 +02:00
Show Liu
a84742e36a rkisp1: add pipeline test for rkisp1
Add an initial simple test tool for the rkisp1 pipeline based upon the
IPU3 pipeline test.

Signed-off-by: Show Liu <show.liu@linaro.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-01-13 22:45:46 +00:00
Niklas Söderlund
4b9bd6c3ad libcamera: ipa_interface: Document the ownership of dmabufs passed to map_buffers()
The ownership of the dmabuf file handles passed to map_buffers() is not
clear. Explicitly document that they are borrowed from the caller and
only guaranteed to be valid for the duration of the map_buffers() call.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-12 19:13:34 +01:00
Niklas Söderlund
a1c5450be5 libcamera: camera: Remove the prepared state
With the FrameBuffer rework completed there is no reason to keep the
camera prepared state around as buffer allocations are now decoupled
from the camera state. Remove the camera state simplifying the API.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-12 16:10:38 +01:00
Niklas Söderlund
6cd505ac89 libcamera: pipeline: Remove explicit buffer handling
With the FrameBuffer interface in place there is no need for the Camera
to call into the specific pipelines allocation and freeing of buffers as
it no longer needs to be synchronized with buffer allocation by the
application.

Remove the function prototypes in the pipeline handler base class and
fold the functionality in the pipelines start() and stop() functions
where needed. A follow up patch will remove the now no-op
Camera::allocateBuffers() and Camera::freeBuffers().

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-12 16:10:38 +01:00
Niklas Söderlund
07156a2713 qcam: Cache buffer memory mapping
With the buffer allocator in use it's possible to cache the dmabuf
memory mappings when starting the camera instead of mapping and
unmapping them each time.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-01-12 16:10:38 +01:00