Commit graph

756 commits

Author SHA1 Message Date
Laurent Pinchart
a8be6e94e7 qcam: Fix compilation errors with clang-10
clang-10 has introduced the same deprecated-copy warning that appeared
in gcc-9 and caused build issues with Qt header files. However, the
clang version seems more sensitive, and detects issues that are not
fixed in Qt 5.13, unlike gcc-9.

Extend the logic that disables the warning for gcc-9 and Qt < 5.13 to
cover clang-10 and all Qt versions.

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-02-19 18:49:34 +02:00
Kieran Bingham
1d80ed1feb qcam: Use standard PicturesLocation path for capture
Utilise the QStandardPaths::PicturesLocation as a starting point for
saving images from qcam.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-02-19 10:32:22 +00:00
Kieran Bingham
b0f1307fcf libcamera: media_device: Use Loggable interface
Extend MediaDevice to inherit from the Loggable interface to support a
logPrefix which presents the device node path, and the driver name.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-02-19 10:32:22 +00:00
Kieran Bingham
90240a7950 libcamera: media_device: prevent sign extension on casts
The conversion of pointers to integers is implementation defined and
differs between g++ and clang++ when utilising a uint64_t type.

	#include <iostream>

	int main(int argc, char **argv)
	{
		void *ptr = reinterpret_cast<void *>(0xf1234567);
		uint64_t u64 = reinterpret_cast<uint64_t>(ptr);
		uint64_t uint64 = reinterpret_cast<uintptr_t>(ptr);

		std::cout << "ptr " << ptr
			  << " ptr -> u64 0x" << std::hex << u64
			  << " ptr -> uintptr_t -> u64 0x" << std::hex << uint64
			  << std::endl;

		return 0;
	}

When compiled with g++ for a 32-bit platform produces the following
unexpected output:

  ptr 0xf1234567 ptr -> u64 0xfffffffff1234567 ptr -> uintptr_t -> u64 0xf1234567

The standards states:

"A pointer can be explicitly converted to any integral type large enough
to hold all values of its type. The mapping function is
implementation-defined. [Note: It is intended to be unsurprising to
those who know the addressing structure of the underlying machine. — end
note]"

And as such the g++ implementation appears to be little more surprising
than expected in this situation.

The MediaDevice passes pointers to the kernel via the struct
media_v2_topology in which pointers are cast using a uint64 type (__u64),
which is affected by the sign extension described above when BIT(32) is
set and causes an invalid address to be given to the kernel.

Ensure that we cast using uintptr_t which is not affected by the sign
extension issue.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-02-19 10:21:21 +00:00
Laurent Pinchart
b5eff18f1a libcamera: Use C++14 std::*_t type traits
C++14 introduced useful type traits helpers named std::*_t as aliases to
std::*<...>::type. Use them to simplify the code.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
2020-02-18 02:15:25 +02:00
Laurent Pinchart
68daa9302f libcamera: device_enumerator: Don't stop if one device fails
If one device fails to enumerate, which isn't supposed to happen under
normal conditions, both the sysfs and the udev enumerators stop
enumeration of further devices. This potentially prevents working
devices from being detected and handled. Fix it by skipping the faulty
device.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-02-18 02:15:21 +02:00
Jacopo Mondi
857a216fd5 android: camera_device: Use Camera properties for static Metadata
Construct two example static metadata to be reported to the Android
framework using the properties reported by the Camera.

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-02-14 16:27:42 +01:00
Jacopo Mondi
f8951ee720 libcamera: camera: Add Camera properties
Add a method to the Camera class to retrieve the Camera properties
registered by the pipeline handler.

While at it, reword the Camera::controls() operation documentation to
specify that the camera control information are constant during the
camera lifetime not their value, while the camera properties value are
the actually static information.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-02-14 16:27:42 +01:00
Jacopo Mondi
025149b050 libcamera: pipeline_handler: Add Camera properties
Associate to each Camera a ControlList which contains the Camera
properties as created by pipeline handlers in the pipeline handler's
CameraData and provide an operation to retrieve them.

Collect properties from the camera sensor in all pipeline handlers that
support one (IPU3, RKISP1 and VIMC).

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-02-14 16:27:42 +01:00
Jacopo Mondi
2523771d79 libcamera: camera_sensor: Parse camera properties
Parse and collect camera sensor properties by inspecting the associated
v4l2 controls.

Augment the CameraSensor class with an operation to retrieve the
collected properties.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-02-14 16:27:42 +01:00
Jacopo Mondi
81563b55ed libcamera: controls: Add default to ControlRange
Augment the the ControlRange class to store the control default value.

This is particularly relevant for v4l2 controls used to create
Camera properties, which are constructed using immutable video device
properties, whose value won't change at runtime.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-02-14 16:27:42 +01:00
Jacopo Mondi
e5ff2c9894 libcamera: properties: Add rotation property
The rotation property describes the rotation of the camera sensor.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-02-14 16:27:42 +01:00
Jacopo Mondi
f870591a9b libcamera: properties: Add location property
Re-use the Control generation infrastructure to generate libcamera properties
and define the first 'Location' property.

Introduce three additional files:

- include/libcamera/property_ids.h
  Defines the properties ids

- src/libcamera/property_ids.cpp
  Defines the properties Control<> instances

- src/libcamera/property_ids.yaml
  Provide the first 'Location' property definition.

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-02-14 16:27:42 +01:00
Jacopo Mondi
c9104548af libcamera: controls: Parse 'enum' in gen-controls.py
In preparation to add libcamera Camera properties definitions by re-using
the control generation framework, augment the gen_controls.py script to
support parsing the 'enum' yaml tag and generate documentation and
definition of possible values associated with a Control or a Property
and defined through an enumeration of supported values.

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-02-14 16:27:42 +01:00
Laurent Pinchart
3f207e0b33 libcamera: thread: Support timeout in wait() function
Add a parameter to the Thread::wait() function to wait with a timeout.
The delay value utils::duration::max() waits forever.

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-14 15:06:42 +02:00
Kieran Bingham
0f292e7821 qcam: Provide save image functionality
Implement a save image button on the toolbar which will take a current
viewfinder image and present the user with a QFileDialog to allow them
to choose where to save the image.

Utilise the QImageWriter to perform the output task.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-02-14 12:34:36 +00:00
Kieran Bingham
2dc85eabe1 qcam: Provide initial icon buttons "Play/Stop"
Provide Quit, Play, Stop icons.

Create a Qt resource to compile icons into the binary and present them
on the toolbar.

Update the Quit button with a 'cross', and implement Play/Stop buttons.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-02-14 12:34:33 +00:00
Kieran Bingham
fc9fe45580 qcam: assets: Provide initial icon set
Provide simple clean icons from https://feathericons.com/
(https://github.com/feathericons/feather)

These are provided under the MIT license.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-02-14 12:34:31 +00:00
Kieran Bingham
fb497899e2 qcam: Introduce a toolbar and camera switching
Implement a quit button, and a list of cameras.

Selecting a different camera from the Toolbar will stop the current
stream, and start streaming the chosen camera device if it can be
acquired.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-02-14 12:34:27 +00:00
Kieran Bingham
871879eb73 qcam: Store CameraManager as class member
Intialise a local copy of the CameraManager instance to ease
access to the CameraManager which is frequently utilised.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-02-14 12:34:25 +00:00
Kieran Bingham
de584a58f7 qcam: Move requestCompleted signal mapping
The MainWindow connects a handler to the Camera requestCompleted signal
when the camera is opened, but never disconnects it.

Move the connection to the startCapture() function, and ensure that it
is disconnected again when the stream is stopped.

This ensures that we can successfully tear down the stream, and restart
with a new camera.

Introducing the error_disconnect cleanup path in start_capture
identified that we left the camera in the start state, thus we also add
a call to camera->stop() when disconnecting the signal connection.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-02-14 12:34:23 +00:00
Kieran Bingham
1bf5173076 qcam: Tie FrameBufferAllocator to stream life
The FrameBufferAllocator must be deleted and reconstructed before performing
any reconfiguration of the stream.

Construct the allocator at startCapture, and destroy it during stopCapture so
that we can successfully stop and restart the stream.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-02-14 12:34:17 +00:00
Naushir Patuck
ea3a00bc33 libcamera: v4l2_videodevice: Add crop/selection control
Add control for cropping/selection on a V4L2 video device through
the VIDIOC_S_SELECTION ioctl. This is similar to the existing cropping
control available on V4L2 sub-devices.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
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>
2020-02-13 22:19:07 +02:00
Kieran Bingham
5dc5fb2ac5 libcamera: Standardize on doxygen \return
Two occasions in the source utilise the Doxygen '\returns' alias for \return.
We use \return everywhere else in the code. Update the two occurences to match.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-02-13 16:47:56 +00:00
Laurent Pinchart
52774fff56 libcamera: ipa_manager: Use utils::split()
Replace the custom string splitting implementation with utils::split().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
[Kieran: Re-fit to master branch]
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-02-13 16:47:56 +00:00
Laurent Pinchart
31a05b70aa libcamera: utils: Add string splitter utility function
Add a utils::split() function that splits a string for the purpose of
iterating over substrings. It returns an object of unspecified type that
can be used in range-based for loops.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-02-13 16:47:56 +00: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
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
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
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
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