Commit graph

652 commits

Author SHA1 Message Date
Laurent Pinchart
749dbd576f qcam: Remove double stop of the camera manager
The camera manager is stopped both in the destructor of the MainWindow
class and in the main() function. This double stop isn't needed, remove
the former and keep the latter as the manager is started in the main()
function.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-08-19 18:07:40 +03:00
Laurent Pinchart
4403a66789 libcamera: proxy: Get event dispatcher from current thread
Get the event dispatcher from the current thread instead of the camera
manager. This prepares for the removal of CameraManager::instance().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-08-19 18:07:30 +03:00
Laurent Pinchart
d0cf816569 libcamera: device_enumerator: Print media device name in error message
The device enumerator logs an error message when a media device is
removed while still in use. Add the device name to the message to help
debugging.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-08-19 18:07:29 +03:00
Laurent Pinchart
0c32433d8c android: Simplify thread RPC with Object::invokeMethod()
Replace the manual implementation of asynchronous method invocation
through a custom message with Object::invokeMethod(). This simplifies
the thread RPC implementation.

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>
2019-08-19 18:07:28 +03:00
Laurent Pinchart
1554d0b6e6 libcamera: Add parent argument to constructors of Object-derived classes
Now that the Object class implements parent-child relationships, make it
possible to create EventNotifier and Timer instances with a parent by
adding a parent argument to their constructors.

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>
2019-08-17 18:47:17 +03:00
Laurent Pinchart
2b25819ec0 libcamera: object: Create parent-child relationships
Add a parent Object to Object instances, and track the parent-children
relationships. Children are bound to the same thread as their parent,
and moving an Object to a thread automatically moves all its children.

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>
2019-08-17 18:47:17 +03:00
Laurent Pinchart
6ecf99a708 libcamera: timer: Bind timers to threads
The Timer instances are registered with the event dispatcher instance of
the CameraManager. This makes it impossible to use timers in other
threads.

Fix this by inheriting from Object, which allows binding instances to a
thread, and register them with the event dispatcher for the thread they
are bound to.

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>
2019-08-17 18:32:42 +03:00
Laurent Pinchart
0c3fd6eb14 libcamera: event_notifier: Bind event notifiers to threads
The EventNotifier instances are registered with the event dispatcher
instance of the CameraManager. This makes it impossible to use event
notifiers in other threads.

Fix this by inheriting from Object, which allows binding instances to a
thread, and register them with the event dispatcher for the thread they
are bound to.

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>
2019-08-17 18:32:38 +03:00
Laurent Pinchart
b566e97aac libcamera: camera_manager: Bind CameraManager to threads
The CameraManager class uses the event dispatcher of the current thread.
This makes the CameraManager::eventDispatcher() and
CameraManager::setEventDispatcher() methods inconsistent, as they access
different event dispatcher instances depending on the calling thread.

Fix this by inheriting from the Object class, which binds the
CameraManager to a thread, and use the event dispatcher of the bound
thread.

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>
2019-08-17 18:32:38 +03:00
Laurent Pinchart
5a954cb8b5 libcamera: object: Notify objects of thread move
Send a synchronous message to objects just before they get moved to a
new thread. This allows the object to perform any required processing.
EventNotifier and Timer objects will use this mechanism to move
themselves to the new thread's event disaptcher.

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>
2019-08-17 18:32:30 +03:00
Laurent Pinchart
d5d7b71521 libcamera: object: Add an asynchronous method invocation method
Add a helper invokeMethod() to the Object class that allows asynchrnous
invocation of any method of an Object instance. Asynchronous invocation
occurs when control returns to the event dispatcher of the target
object's thread, in the context of that thread.

To support this, generalise the SignalMessage implementation to support
automatic deletion of the associated BoundMethod, and rename the message
to InvokeMessage to reflect the more generic purpose.

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>
2019-08-17 18:32:29 +03:00
Laurent Pinchart
f83820a5d1 libcamera: bound_method: Decouple from Signal implementation
To make the BoundMethod classes more generic, replace direct access to
private member from Signal classes with accessors or helper functions.
This allows removal of friend statements from the BoundMethod classes.

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>
2019-08-17 18:32:28 +03:00
Laurent Pinchart
0e65ed8145 libcamera: signal: Split Slot implementation to reusable classes
Move the Slot* classes to bound_method.{h,cpp} and rename them to
Bound*Method*. They will be reused to implement asynchronous method
invocation similar to cross-thread signal delivery.

This is only a move and rename, no functional changes are included.

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>
2019-08-17 18:32:28 +03:00
Laurent Pinchart
a66e5ca8c6 libcamera: thread: Support dispatching messages to main thread
Threads contain message queues and dispatch queued messages in their
event loop, in Thread::exec(). This mechanism prevents the main thread
from dispatching messages as it doesn't run Thread::exec().

Fix this by moving message dispatching from Thread::exec() to
EventDispatcher::processEvents().

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>
2019-08-17 18:32:27 +03:00
Laurent Pinchart
391b184fc5 libcamera: thread: Wake up target thread when moving objects
When moving an object to a different thread, messages posted for the
object are moved to the message queue of the new thread. Wake up the new
thread to ensure it processes the moved messages.

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>
2019-08-17 18:32:26 +03:00
Laurent Pinchart
a8b472598e hal: Fix comparison of unsigned integer < 0
The CameraHalManager::getCameraInfo() validates the camera id it
receives from the camera service, and in doing so generates a compiler
error with gcc as the id is an unsigned integer and can never be
negative:

../src/android/camera_hal_manager.cpp: In member function ‘CameraProxy* CameraHalManager::open(unsigned int, const hw_module_t*)’:
../src/android/camera_hal_manager.cpp:89:9: error: comparison of unsigned expression < 0 is always false [-Werror=type-limits]
  if (id < 0 || id >= numCameras()) {

Fix it by removing the unneeded comparison.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-08-15 15:40:14 +03:00
Kieran Bingham
4f7625cca7 libcamera: v4l2_videodevice: Support M2M devices
V4L2 M2M devices represent a V4L2Device with two queues: One output, and
one capture on a single device node.

Represent this by instantiating a V4L2VideoDevice for each queue type,
and preparing each device for its queue.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-08-13 15:36:04 +01:00
Kieran Bingham
3a278eb460 libcamera: v4l2_videodevice: Fix ordering of debug statement
The "Opened device" statement occurs before the buffertype_ is set.

This causes all devices to report that they are [out] devices at open()
regardless of their type.

As the message operates in the past-tense, move the statement to the end
of the function when all work has been completed.

Fixes: 04d5be7f76 ("libcamera: v4l2_device: Inherit from Loggable to print device node name")
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-08-13 10:23:21 +01:00
Kieran Bingham
e0f35d6f57 libcamera: v4l2_device: Add setFd()
Provide a means for V4L2 device instances to set the fd_ explicitly.
This allows for V4L2Devices to operate when they must use an external
open() call.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-08-13 10:23:21 +01:00
Laurent Pinchart
a6799dc5b9 hal: Fix comparison of integers of different signs
The CameraHalManager::getCameraInfo() validates the camera id it
receives from the camera service, and in doing so compares it with an
unsigned integer, generating a compiler error:

src/android/camera_hal_manager.cpp:121:9: error: comparison of integers of different signs: 'int' and 'unsigned int' [-Werror,-Wsign-compare]
        if (id >= numCameras() || id < 0) {
            ~~ ^  ~~~~~~~~~~~~

Fix this by turning the id into an unsigned int, as camera ids can't be
negative. If a negative id is received from the camera service it will
be converted to a large unsigned integer that will fail the comparison
with numCameras().

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>
2019-08-12 15:01:30 +03:00
Jacopo Mondi
667d8ea8fd android: hal: Add Camera3 HAL
Add libcamera Android Camera HALv3 implementation.

The initial camera HAL implementation supports the LIMITED hardware
level and uses statically defined metadata and camera characteristics.

Add a build option named 'android' and adjust the build system to
selectively compile the Android camera HAL and link it against the
required Android libraries.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-08-12 11:55:46 +02:00
Jacopo Mondi
6bed34da16 android: metadata: Add SPDX tag
Add SPDX tag to the android metadata library files licensed under
Apache-2.0.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-08-12 10:34:13 +02:00
Jacopo Mondi
552b5d16d7 android: Add camera metadata library
Import the Android camera metadata library from the ChromiumOS build
system.

The camera metadata library has been copied from
https://chromium.googlesource.com/chromiumos/platform2
at revision 9e65ddd2c496e712f005ada9715decd2ff8e4a03

The original path in the Cros platform2/ repository is:
camera/android/libcamera_metadata/src

Create a new build target for the camera metadata library to
create a static library to link against libcamera.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-08-12 10:34:13 +02:00
Niklas Söderlund
4debc71ffa libcamera: pipeline: vimc: Switch to using the RGB/YUV Capture video node
Linux commit 85ab1aa1fac17bcd ("media: vimc: deb: fix default sink bayer
format") which is part of v5.2 changes the default media bus format for
the debayer subdevices. This leads to a -EPIPE error when trying to use
the raw capture video device nodes.

Fix this by moving the vimc pipeline to use the RGB/YUV Capture capture
video node. As a consequence of this change the scaler in the vimc
pipeline is used and a hard coded upscale of 3 is present in the video
pipeline. This limits the sizes exposed and accepted by libcamera to
multiples of 3.

Update the buffer import test case to match this  new format constraint
by setting the resolution to 1920x1080, a resolution which works with
both vimc and vivid. With this new resolution the buffer import test
takes a bit more time to complete 60 buffers and it's runtime also needs
to be increased.

The raw capture video node still needs to be handled by the pipeline as
its format needs to be updated to allow the pipeline format validation
to pass.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-08-11 02:16:21 +02:00
Niklas Söderlund
f5d3a956cc libcamera: pipeline: vimc: Initialize device pointers
As the device pointers are deleted in the pipelines destructor it's not
a good idea to have them uninitialized.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-08-11 02:16:21 +02:00
Helen Koike
c91d7bb980 libcamera: pipeline: RKISP1 configure isp output pad
ISP output pad should be set to YUYV8_2X8 for non-bayer output format.
Bayer formats are not listed in RkISP1CameraConfiguration::validate(),
only non-bayer are listed, so we can set YUYV8_2X8 directly.
This will need to be changed if we add support for bayer output with
libcamera.

Signed-off-by: Helen Koike <helen.koike@collabora.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-08-09 01:02:57 +03:00
Kieran Bingham
9ecc60e10c libcamera: ipa_module: prevent uninitialised access
The IPAModule::loadIPAModuleInfo() function includes a *data pointer
which is used as a null-pointer comparison in the error path with a
conditional statement of "if (ret || !data)".

The data variable is not initialised, and a single error path evaluates
this as "if (true || uninitialised)".

Whilst this error path does not incorrectly utilise the uninitialised
data, as the ret evaluates to true already, it does leave a statement
which includes an uninitialised variable.

Help the static analysers by initialising the data variable when it is
defined.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-08-01 16:20:27 +01:00
Jacopo Mondi
119428fa1c libcamera: process: Fail loudly on isolate
Add an error debug message when disassociating part of a process
execution context using unshare fails.

As this is currently used to isolate a child process which is
immediately terminated silently if unshare fails, add a debug printout
and propagate up the error code to make the failure more visible.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-07-31 15:29:56 +02:00
Laurent Pinchart
9e6147d303 libcamera: pipeline: ipu3: Fix argument name mismatch
Fix an argument name mismatch between method declaration and
definition.

Reported-by: Paul Elder <paul.elder@ideasonboard.com>
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>
2019-07-30 06:59:11 +03:00
Paul Elder
b9f7e269b6 libcamera: logging: add syslog, stream, and nowhere logging targets
Allow logging to syslog, or any given ostream, or to nowhere. The
logging API is updated to accomodate these new logging destinations.
LogMessage is modified to allow this.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-17 14:36:35 +09:00
Jacopo Mondi
8f0984f2cc libcamera: ipu3: Do not re-queue cancelled buffers
When a video device is stopped all the buffers there queued are released
and their state is set to BufferCancelled.

Currently, on buffer completion, cancelled buffers are blindly re-queued
to the ImgU input or CIO2 output devices, preventing them to be
re-started succesfully in future capture sessions.

Fix that by inspecting the buffers status and skip re-queueing if
they're reported as cancelled. For the ImgU output buffer this is not
required, as cancelled request should be reported to applications in
order to report them failure of the capture operations.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-07-17 04:51:33 +02:00
Jacopo Mondi
01c0ad98c4 libcamera: ipu3: Disable links at configure() time
With the current IPU3 kernel driver implementation, a linked pipe shall be
used (buffers should be queued on it) in order not to block all other pipes.

Currently all links on the ImgU device are only disabled at match() time,
implying that once an ImgU pipe gets linked, it should be used until the
whole pipeline is not re-matched and links disabled again. This is a severe
limitation for applications that wants to switch between cameras using
different pipes going through a full library tear-down and reload.

Perform link disabling at configure() time as well, so that a camera
configuration operation always unlock the usage of the assigned pipe,
regardless of the previously linked ones.

Unfortunately this requires a camera start/stop sequence to always go
through a configure step, a requirement that is not enforced by the
Camera state machine.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2019-07-17 04:51:26 +02:00
Jacopo Mondi
a5ebcea8c0 libcamera: qcam: Allow specifying sizes on command line
Add a '-s|--size' option to qcam to allow selecting the stream
resolution using a command line option.

If the sizes are not supported by the camera, they get automatically
adjusted and the user notified via an output message.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-17 04:49:38 +02:00
Jacopo Mondi
fae053307d libcamera: message: Add user message types
Reserve identifiers for user-defined message types and add an operation
to the Message class to register the type identifiers.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-07-16 10:55:27 +03:00
Laurent Pinchart
3e29a2d520 libcamera: message: Document Message::SignalMessage
The SignalMessage type is undocumented. Fix it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2019-07-16 10:55:26 +03:00
Laurent Pinchart
a68cec65c1 libcamera: stream: Initialise pixelFormat in StreamConfiguration()
To avoid depending on unitialised values, set the pixelFormat field of
the StreamConfiguration class to 0 in the constructor.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-16 09:18:42 +03:00
Laurent Pinchart
124336329c libcamera: pipeline: ipu3: Free internal buffers after stopping streaming
The internal buffers between the CIO2 and ImgU are freed by the
CIO2Device::stop() method, which is called first when stopping
streaming. The ImgUDevice::stop() method is then called, and attempts to
report completion for all queued buffers, which we have just freed. The
use-after-free corrupts memory, leading to crashes.

Fix this by moving the vector of internal buffers to the IPU3CameraData
where it belongs, and free the buffers after stopping both devices.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-16 08:51:09 +03:00
Laurent Pinchart
d55c8018cd libcamera: pipeline: ipu3: Initialise pixel format to NV12 in new config
To avoid printing debugging messages related to stream configuration
adjustement when generating a new configuration, set the pixel format
explicitly instead of relying on the internal validate() call to do so.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-16 08:51:04 +03:00
Kieran Bingham
ef98f90a4f libcamera: Fix spellings and grammar
Fix a number of spelling errors and word duplications throughout the comments
within libcamera.

These were picked up with spellintian.

Also one capitalisation of the first word of a \return statement picked
up by checkstyle.py while creating this patch.

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2019-07-15 09:35:10 +01:00
Jacopo Mondi
b5010e4cee libcamera: pipeline: Support importing buffers
Add support for importing external buffers in all pipeline handlers.

Use the stream memory type in the pipeline handlers during buffer
allocation to import buffers to or export buffers from the video device.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-14 16:01:10 +03:00
Jacopo Mondi
9ed9d9b3c1 libcamera: stream: Map external buffers to indexes
Add and use an operation to assign to Buffer representing external
memory locations an index at queueRequest() time. The index is used to
identify the memory buffer to be queued to the video device once the
buffer will be queued in a Request.

In order to minimize relocations in the V4L2 backend, this method
provides a best-effort caching mechanisms that attempts to reuse
BufferMemory previously mapped to the buffer's dmabuf file descriptors,
if any.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-14 16:01:09 +03:00
Laurent Pinchart
689e8916ca libcamera: buffer: Add an accessor to the BufferMemory
Buffer instances reference memory, which is modelled internally by a
BufferMemory instance. Store a pointer to the BufferMemory in the Buffer
class, and populate it when the buffer is queued to the camera through a
request. This is useful for applications to access the buffer memory in
the buffer or request completion handler.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-14 16:01:07 +03:00
Jacopo Mondi
f1199a1011 libcamera: buffer: Add dmabuf file descriptors
In addition to referencing buffer memory by index, add support to
referencing it using dmabuf file descriptors. This will be used to
reference buffer memory allocated outside of libcamera and import it.

The dmabuf file descriptors are stored in an array in the Buffer class,
and a new Stream::createBuffer() overload is added to construct a buffer
from dmabuf file descriptor.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-14 16:01:03 +03:00
Jacopo Mondi
99e1e786b4 libcamera: stream: Add Stream memory type
Define the memory type a Stream uses and allow application to set it
through the associated StreamConfiguration.

A Stream can use either internal or external memory allocation methods,
depending on where the data produced by the stream is actually saved.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2019-07-14 16:01:02 +03:00
Jacopo Mondi
be3e3ebc92 libcamera: stream: Shorten access to the bufferPool
All interactions with the Stream's buffers currently go through the
BufferPool. In order to shorten accessing the buffers array, and eventually
restrict access to the Stream's internal buffer pool, provide operations to
access, create and destroy buffers.

It is still possible to access the pool for pipeline handlers to
populate it by exporting buffers from a video device to Stream's pool.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-14 16:00:58 +03:00
Laurent Pinchart
5085bc03bc libcamera: Stop using Stream::bufferPool to get the number of buffers
The cam and qcam applications, as well as the camera capture test case,
access the Stream::bufferPool in order to know how many requests to
initially queue. As part of an effort to remove access to the buffer
pool from applications, use the buffer count from the stream
configuration instead.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-14 16:00:58 +03:00
Laurent Pinchart
4cb78e712c libcamera: pipeline: ipu3: Use stream configuration to get buffers count
Access the number of allocated buffer for the streams through the stream
configuration instead of the stream's buffers pool.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-14 16:00:57 +03:00
Laurent Pinchart
4e79b2ef31 libcamera: v4l2_videodevice: Signal buffer completion at streamoff time
When stopping the stream buffers have been queued, in which case their
completion is never be notified to the user. This can lead to memory
leaks. Fix it by notifying completion of all queued buffers with the
status set to error.

As a result the base PipelineHandler implementation can be simplified,
as all requests complete as the result of stopping the stream. The
stop() method that manually completes all queued requests isn't needed
anymore.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-14 16:00:56 +03:00
Laurent Pinchart
a2bcf6feee libcamera: buffer: Split memory information to BufferMemory
The Buffer class is a large beast the stores information about the
buffer memory, dynamic metadata related to the frame stored in the
buffer, and buffer reference data (in the index). In order to implement
buffer import we will need to extend this with dmabuf file descriptors,
making usage of the class even more complex.

Refactor the Buffer class by splitting the buffer memory information to
a BufferMemory class, and repurposing the Buffer class to reference a
buffer and to store dynamic metadata. The BufferMemory class becomes a
long term storage, valid and stable from the time buffer memory is
allocated to the time it is freed. The Buffer class, on the other hand,
becomes transient, is created on demand when an application requires a
buffer, is given to a request, and is deleted when the request
completes.

Buffer and BufferMemory don't need to be copied, so their copy
constructor and assignment operators are deleted.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-14 16:00:54 +03:00
Laurent Pinchart
9bb36ec274 libcamera: v4l2_videodevice: Add helper to queue all buffers
When starting the stream on a capture video device it is often needed to
queue all the allocated buffers. Add a helper method to do so, and
refactor the existing queueBuffer() method to make it clearer.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2019-07-14 16:00:51 +03:00