Commit graph

118 commits

Author SHA1 Message Date
Jacopo Mondi
753d7536b7 android: camera_device: Register EXPOSURE_TIME_RANGE
Register the EXPOSURE_TIME_RANGE static metadata inspecting the
ExposureTime control limits as reported by the camera.

If such information is not available, do not register the property.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2021-01-25 14:55:45 +01:00
Jacopo Mondi
9e6eece622 android: camera_device: Clone settings in request descriptor
When a Camera3RequestDescriptor instance is created to wrap a
camera3_capture_request_t the settings associated with the request
are cloned for later re-use.

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2021-01-22 10:37:33 +01:00
Jacopo Mondi
4b18b82c4f android: camera_device: Copy camera3 buffers in descriptor
The camera3_stream_buffer_t instances part of a capture request contain
information on the stream for which capture has been requested (size,
format and fences) and a handle to the stream's memory buffers.

This information is copied in the descriptor one piece at the time while
processing the camera3 streams to be re-used at request completion time.

Simplify the code by copying the stream information in the descriptor
at construction time.

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2021-01-22 10:36:09 +01:00
Jacopo Mondi
dd1cd532ca android: camera_device: Pass camera3 request to descriptor
The Camera3RequestDescriptor class can access the number of buffers
and the frame number from the camera3_capture_request_t instead of
having the caller passing them to the constructor.

This change allows to access other fields of the capture request, such
as the capture settings.

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2021-01-22 10:35:53 +01:00
Jacopo Mondi
cda41ff754 android: camera_device: Do not default pixel array properties
Now that the pixel array properties have been defaulted in the
CameraSensor class (or in the pipeline handler, for the UVC use case),
they will always be reported by the libcamera::Camera and there's no
need to default them in the Camera HAL.

Remove defaults and assume properties are always there.

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2021-01-18 10:39:14 +01:00
Niklas Söderlund
35de31e027 android: camera_device: Only advertise RAW support if RAW16 is available
The Android camera2 API defines a RAW capture capability ([1]) for
devices that support "outputting RAW buffers and metadata for
interpreting them". This capability requires the camera device to
support RAW_SENSOR ([2]) as an output format. Despite what its name may
sound like, the RAW_SENSOR format is defined as a 16 bits RAW format,
not an opaque implementation-dependent format (which is instead called
RAW_PRIVATE). Devices may additionally support the RAW10 and RAW12
formats, but that isn't enough to claim RAW capture capability.

To comply with the API requirements, only report the
ANDROID_REQUEST_AVAILABLE_CAPABILITIES_RAW capability when 16-bit RAW is
supported.

[1] https://developer.android.com/reference/android/hardware/camera2/CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_RAW
[2] https://developer.android.com/reference/android/graphics/ImageFormat#RAW_SENSOR

Suggested-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Tested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2021-01-04 13:35:05 +01:00
Jacopo Mondi
0ed0532457 android: camera_device: Simplify properties.get()
When accessing the value of a property by reading the properties
ControlList content with ControlList::get<>() it is not necessary to
specify the template type as it is already conveyed by the Control
instance provided as first argument.

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-12-30 11:22:53 +01:00
Jacopo Mondi
cb35ed23f3 android: camera_device: Report ColorFilterArrangement
Conditionally report the ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT
property inspecting the draft property reported by the libcamera Camera.

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-12-30 11:22:52 +01:00
Jacopo Mondi
eec6c54134 android: camera_device: Report number of out streams
Report the number of supported output streams through the
ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS static metadata.

The camera HAL currently supports:
- 1 optional RAW stream
- 2 YUV streams
- 1 JPEG stream

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-12-18 17:48:49 +01:00
Jacopo Mondi
3535e0c104 android: camera_device: Report pipeline depth
Report the pipeline depth in the capture results if the pipeline
reports it.

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-12-18 17:48:31 +01:00
Laurent Pinchart
bd4894d259 android: camera_device: Replace auto with explicit type
The auto keyword facilitates writing code. It avoids typing out very
long types, which can make the code more readable, but it can also have
a negative impact on readability as it requires the reader (including
reviewers) to look up the type of the variable.

Replace one occurrence of auto with the explicit type where doing so
doesn't require a long type name.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2020-12-14 15:35:03 +02:00
Jacopo Mondi
008f2a55d1 android: camera_device: Temporary fix sensor properties
The ChromeOS camera service, which is the current main user of the
Android Camera HAL, fails to start if the pixel array properties are
not registered.

As the sensor driver for the Soraka test device have not yet been
updated to report their pixel array properties through the V4L2
selection API, temporary fix the gap by re-establishing the default
properties values removed by commit 1889cdc2e9 ("android: camera_device:
Initialize pixel array properties")

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-12-14 08:39:03 +01:00
Hirokazu Honda
26d90af082 android: camera_device: Reorder configurations before requesting
This reorders Camera3Configs before executing
CameraConfiguration::validate() to make it easier for the Camera
to satisfy the Android framework request.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Umang Jain <email@uajain.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Add blank line and fix compilation on gcc 7.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-12-11 15:10:49 +02:00
Hirokazu Honda
2bc6ba2e1f android: camera_device: Use Camera3StreamConfig in configureStreams()
Use the newly introduced Camera3StreamConfig to associate the
Android requested streams with the associated StreamConfiguration
in a vector of configurations.

This change prepares to sort the vector of configuration before using
it to configure the Camera and populate the streams_ vector.

No functional changes intended.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Umang Jain <email@uajain.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-12-11 14:13:38 +02:00
Hirokazu Honda
c2df74364f android: camera_device: Introduce Camera3StreamConfig
Camera3StreamConfig is a new class to store camera3_stream and
types with associated StreamConfiguration.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Umang Jain <email@uajain.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-12-11 14:12:35 +02:00
Jacopo Mondi
8fed613562 android: camera_device: Stop camera when re-configuring it
The Android camera device HAL3 specification does not require a
camera to go through any explicit close() call between configurations.
It is legitimate for a camera to be configured, a number of requests
processed and then re-configured again without any explicit stop.

The libcamera Android camera HAL starts the Camera at the first handled
request, and only stops it at camera close time. This means that two
camera configuration attempts in the same streaming session are only
interleaved by capture requests handling.

The libcamera::Camera state machine requires the Camera to be stopped
before any configuration take place, and this currently doesn't happen.

Fix this by stopping the camera and the associated worker thread if
a configuration attempt is performed while the Camera is in running
state.

This patch fixes cros_camera_test:
Camera3PreviewTest/Camera3SinglePreviewTest.Camera3BasicPreviewTest/0

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: Jacopo Mondi <jacopo@jmondi.org>
2020-12-07 14:26:42 +01:00
Jacopo Mondi
1889cdc2e9 android: camera_device: Initialize pixel array properties
Initialize pixel array properties in the Android camera HAL
inspecting the camera properties.

If the camera does not provide any suitable property, not static
metadata is registered to the Android framework.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-12-07 14:26:33 +01:00
Jacopo Mondi
c5b732b2ca android: camera_device: Check capture_request validity
Make sure the 'camera3_capture_request_t *' provided to
CameraDevice::processCaptureRequest() is valid before attempting to
access it.

This patch fixes cros_camera_test:
Camera3FrameTest/Camera3InvalidRequestTest.NullOrUnconfiguredRequest/*

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-12-02 11:23:20 +01:00
Jacopo Mondi
c268e4f2e8 android: camera_mode: Reserve 'data' vectors
The CameraDevice::getStaticMetadata() function populates the
entries for Android's static metadata by walking the ControlInfo
supported values reported by the libcamera pipeline.

The number of entries to be passed to Android is computed using the
vector's size which is initialized at vector creation time to the
maximum number of available entries.

In order to report the correct number of metadata do not create the
vector with the largest possible number of elements but only reserve
space for them using std::vector::reserve() which does not modify the
vector's size.

This patch fixes cros_camera_test:
Camera3DeviceTest/Camera3DeviceDefaultSettings.ConstructDefaultSettings/1

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-12-02 11:23:18 +01:00
Hirokazu Honda
c1ae9055f9 android: camera_device: Mark toPixelFormat() a const function
CameraDevice::toPixelFormat() doesn't change the state of the
CameraDevice. Marks it a const function so that it can be called
in const functions.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-10-28 15:52:51 +00:00
Hirokazu Honda
3a777d8cc1 android: camera_device: Fix crash of accessing a missing map element
std::map::at() searches std::map by the given key. The commit
e1f9fdb8a5 ("android: camera_device: Remove shadowing FrameBuffer
usage") uses it with 0 to intend to accessing the first element of the
map, but actually access the element whose key is nullptr. This causes
the crash because the map doesn't have the element with nullptr. This
fixes the issue by replacing the std::map::at() operation by
std::map::begin().

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
[Kieran: Updated commit message]
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2020-10-28 15:52:51 +00:00
Jacopo Mondi
2c61850e12 android: camera_device: Handle LENS_SHADING_MAP_MODES
Register the ANDROID_STATISTICS_INFO_AVAILABLE_LENS_SHADING_MAP_MODES
static metadata property inspecting the values retuned by the pipeline
handler.

Add one entry and reserve in static metadata pack enough space to
support all the 2 available lens shading map modes Android defines.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-26 17:51:56 +01:00
Jacopo Mondi
63336863c9 android: camera_device: Handle COLOR_CORRECTION_ABERRATION_MODE
Register the ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES
static metadata property inspecting the values retuned by the pipeline
handler.

Reserve in the static metadata pack enough space to support all the 3
available color correction aberration modes Android defines.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-26 17:51:56 +01:00
Jacopo Mondi
0b5fecc746 android: camera_device: Handle NOISE_REDUCTION_MODES
Register the ANDROID_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES
static metadata property inspecting the values retuned by the pipeline
handler.

Reserve in the static metadata pack enough space to support all the 5
available noise reduction modes Android defines.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-26 17:51:56 +01:00
Jacopo Mondi
5d91c8da5c android: camera_device: Report PIPELINE_MAX_DEPTH
Register the ANDROID_REQUEST_PIPELINE_MAX_DEPTH static property
inspecting the value reported by the pipeline handler.

If the Camera does not report any suitable value, default the
static property to 2.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-26 17:51:55 +01:00
Kieran Bingham
e1f9fdb8a5 android: camera_device: Remove shadowing FrameBuffer usage
A FrameBuffer *buffer is used to obtain the 'first' buffer from a
request which is used purely to identify the timestamp from the
metadata in two locations.

Rather than keep the FrameBuffer instance around, which then causes
further usages of FrameBuffers to be shadowed, store the timestamp
locally.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-10-21 17:18:36 +01:00
Kieran Bingham
37c18c2eec android: camera_device: use member style on Camera3RequestDescriptor
Use the postfixed '_' member variable naming style for the
Camera3RequestDescriptor structure, which in turn ensures that variable
shadowing does not occur in the member initializer list of the
constructor.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-10-21 17:01:40 +01:00
Kieran Bingham
c7bcae02a0 android: camera_device: Use existing variable definitions
Prevent variable shadowing by removing the redeclaration of variables
with the same name (and type) where the existing variable can be reused.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-10-21 17:01:28 +01:00
Hirokazu Honda
6c5792f7a8 android: Omit extra semicolons
The end semicolons with LOG_DECLARE_CATEGORY and
LOG_DEFINE_CATEGORY are unnecessary.

Signed-off-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2020-10-20 13:15:49 +03:00
Umang Jain
b2b8c4dc94 android: jpeg: Port to PostProcessor interface
Port the CameraStream's JPEG-encoding bits to PostProcessorJpeg.
This encapsulates the encoder and EXIF generation code into the
PostProcessorJpeg layer and removes these specifics related to JPEG,
from the CameraStream itself.

Signed-off-by: Umang Jain <email@uajain.com>
Tested-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Change-Id: Id9e6e9b2bec83493a90e5e126298a2bb2ed2232a
2020-10-16 10:23:10 +01:00
Jacopo Mondi
4b1aa21db0 android: camera_device: Queue request using Worker
Add a CameraWorker class member to the CameraDevice class and
queue capture requests to it to delegate its handling. Start and
stop the CameraWorker when the libcamera::Camera is started or
stopped.

Tie the CaptureRequest lifetime to the Camera3RequestDescriptor's one
by storing it as unique_ptr<> in the descriptor to simplify handling
of request creation and deletion.

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-14 20:11:26 +02:00
Paul Elder
c753223ad6 libcamera, android, cam, gstreamer, qcam, v4l2: Reuse Request
Allow reuse of the Request object by implementing reuse(). This means
the applications now have the responsibility of freeing the Request
objects, so make all libcamera users (cam, qcam, v4l2-compat, gstreamer,
android) do so.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-12 11:32:40 +09:00
Jacopo Mondi
6c4999e6a4 android: camera_device: Clear streams_ at stop time
When the CameraDevice is stopped, we need to clear the vector
of CameraStream instances to make sure they get deleted and all the
resources they have acquired get released.

Reviewed-by: Umang Jain <email@uajain.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-07 16:09:22 +02:00
Jacopo Mondi
35f726d4da android: camera_device: Add stream mapping log
To ease following how Android streams get mapped to libcamera ones
add a (quite verbose) printout before queueing a request to libcamera.

The output looks like:
 0 -  (320x240)[0x00000022] -> (320x240)[NV12] (direct)
 1 -  (640x480)[0x00000021] -> (640x480)[NV12] (internal)

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-07 16:09:22 +02:00
Jacopo Mondi
de8304b116 android: camera_device: Use CameraStream buffers
Now that CameraStream that require internal memory allocation
have been instrumented with a FrameBuffer pool, use them to create
intermediate buffers in the CameraDevice.

Reviewed-by: Umang Jain <email@uajain.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-07 16:09:22 +02:00
Jacopo Mondi
b84e35dc97 android: camera_stream: Create buffer pool
Add a FrameBufferAllocator class member to the CameraStream class.
The allocator is constructed for CameraStream instances that needs
internal allocation and automatically deleted.

Allocate FrameBuffers using the allocator_ class member in the
CameraStream class at CameraStream::configure() time and add two
methods to the CameraStream class to get and put FrameBuffer pointers
from the pool of allocated buffers. As buffer allocation can take place
only after the Camera has been configured, move the CameraStream
configuration loop in the CameraDevice class after camera_->configure()
call.

The newly created pool will be used to provide buffers to CameraStream
that need to provide memory to libcamera where to deliver frames.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-07 16:09:20 +02:00
Jacopo Mondi
6c8837da5e android: camera_device: Make CameraStream configuration nicer
Loop over the CameraStream instances and use their interface to perform
CameraStream configuration.

Modify CameraStream::configure() to configure the android stream buffer
count and to retrieve the StreamConfiguration by index instead of
receiving it as a parameter.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-07 16:07:45 +02:00
Jacopo Mondi
e3393f147e android: camera_stream: Fetch format and size from configuration
Fetch the format and size of the libcamera::StreamConfiguration
associated with a CameraStream by accessing the configuration by
index.

This removes the need to store the libcamera stream format and sizes
as class members and avoid duplicating information that might get out
of sync.

It also allows to remove the StreamConfiguration from the constructor
parameters list, as it can be identified by its index. While at it,
re-order the constructor parameters order.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-07 16:07:44 +02:00
Jacopo Mondi
216030aa9d android: camera_stream: Retrieve Stream and Configuration
It's a common pattern to access the libcamera::Stream and
libcamera::StreamConfiguration using the CameraStream instance's
index.

Add two methods to the CameraStream to shorten access to the
two fields. This allows removing the index() method from the class
interface.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-07 16:07:44 +02:00
Jacopo Mondi
9e95d5e453 android: camera_device: Move processing to CameraStream
Move the JPEG processing procedure to the individual CameraStream
by augmenting the class with a CameraStream::process() method.

This allows removing the CameraStream::encoder() method.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-07 16:07:44 +02:00
Jacopo Mondi
160bb0998b android: camera_stream: Construct with Android stream
Pass the android camera3_stream_t, and a libcamera::StreamConfiguration
to identify the source and destination parameters of this stream.

Pass a CameraDevice pointer to the CameraStream constructor to allow
retrieval of the StreamConfiguration associated with the CameraStream.

Also change the format on which the CameraDevice performs checks to
decide if post-processing is required, as the libcamera facing format is
not meaningful anymore, but the Android requested format should be used
instead.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-07 16:07:44 +02:00
Jacopo Mondi
3c84d88193 android: camera_stream: Delegate Encoder construction
Delegate the construction of the encoder to the CameraStream class
for streams that need post-processing.

Reviewed-by: Umang Jain <email@uajain.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-07 16:07:44 +02:00
Jacopo Mondi
94c4d49ebe android: camera_stream: Add CameraStream::Type
Define the CameraStream::Type enumeration and assign it to
each CameraStream instance at construction time.

The CameraStream type will be used to decide if memory needs to be
allocated on its behalf or if the stream is backed by memory externally
allocated by the Android framework.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-07 16:07:44 +02:00
Jacopo Mondi
5cf64b26a2 android: camera_stream: Break out CameraStream
Break CameraStream out of the CameraDevice class.

No functional changes, only the code is moved.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-10-07 16:07:43 +02:00
Niklas Söderlund
dbe8d271e7 libcamera: stream: Rename StillCaptureRaw to Raw
With the buffer copy removed from all pipelines for raw capture
rename StillCaptureRaw to Raw to better describe the role.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
2020-09-30 14:01:01 +02:00
Jacopo Mondi
45fe8e99c8 android: camera_device: Make CameraStream a class
Complete the transformation of CameraStream into a class and provide
a read-only interface that allows to access its parameters but not
modify them at run-time.

No functional changes intended but this change aims to make the code
more robust by enforcing a stricter interface in the CameraStream class.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-09-18 11:31:56 +02:00
Jacopo Mondi
facadb188e android: camera_device: Set Encoder at construction
Make the CameraStream encoder a private unique pointer and require its
initialization at construction time. This ties the encoder lifetime to
the CameraStream it has been created with, allowing to remove the
CameraStream destructor.

This change dis-allow creating a CameraStream and set the Encoder later,
which shall not happen now that we create CameraStream once we have all
the required information in place.

No functional changes intended but this change aims to make the code
more robust enforcing a stricter CameraStream interface.

Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-09-18 11:31:56 +02:00
Jacopo Mondi
c82f944399 android: camera_device: Rework CameraStream handling
The CameraDevice::streams_ vector of CameraStream instances is
currently mostly accessed by index. The current implementation
creates all the CameraStream during the first loop that inspects the
camera3_stream instances and then update the index of the
StreamConfiguration associated with the CameraStream during a second
loop that inspects MJPEG streams. A third loop creates the JPEG encoder
associated with camera streams that produce MJPEG format.

As the index-based association is hard to follow and rather fragile,
rework the creation and handling of CameraStream:

1) Make the StreamConfiguration index a constructor parameter and a
   private struct member. This disallows the creation of CameraStream
   without a StreamConfiguration index assigned.

2) Create CameraStream only after the associated StreamConfiguration
   has been identified. The first loop creates CameraStream for non-JPEG
   streams, the second for the JPEG ones after having identified the
   associated StreamConfiguration. Since we have just created the
   CameraStream, create the JPEG encoder at the same time instead of
   deferring it.

This change removes all accesses by index to the CameraDevice::streams_
vector.

No functional changes intended, but this change aims to make the code
easier to follow and more robust.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-09-18 11:31:56 +02:00
Jacopo Mondi
f868f08c21 android: camera_device: Use Android format
When iterating the camera3_stream_t received from the Android camera
framework to identify the MJPEG streams, the format check was performed
on the CameraStream created when iterating the non-MJPEG streams and not
on the format actually requested by Android. As the next patches will
remove the creation of CameraStream instances for MJPEG streams, use the
camera3_stream format to prepare for that.

Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-09-18 11:31:56 +02:00
Jacopo Mondi
5b64f64745 android: camera_device: Get rid of stream counter
Use the size() method of the CameraConfiguration class to retrieve the
index of the StreamConfiguration associated with a CameraStream and get
rid of the custom counter.

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
Reviewed-by: Hirokazu Honda <hiroh@chromium.org>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
2020-09-18 11:31:56 +02:00