An attempt at getting image data back
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,919 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// FIXME: add well-defined names for cameras
|
||||
|
||||
#ifndef ANDROID_INCLUDE_CAMERA_COMMON_H
|
||||
#define ANDROID_INCLUDE_CAMERA_COMMON_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
#include <cutils/native_handle.h>
|
||||
#include <system/camera.h>
|
||||
#include <system/camera_vendor_tags.h>
|
||||
#include <hardware/hardware.h>
|
||||
#include <hardware/gralloc.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* The id of this module
|
||||
*/
|
||||
#define CAMERA_HARDWARE_MODULE_ID "camera"
|
||||
|
||||
/**
|
||||
* Module versioning information for the Camera hardware module, based on
|
||||
* camera_module_t.common.module_api_version. The two most significant hex
|
||||
* digits represent the major version, and the two least significant represent
|
||||
* the minor version.
|
||||
*
|
||||
*******************************************************************************
|
||||
* Versions: 0.X - 1.X [CAMERA_MODULE_API_VERSION_1_0]
|
||||
*
|
||||
* Camera modules that report these version numbers implement the initial
|
||||
* camera module HAL interface. All camera devices openable through this
|
||||
* module support only version 1 of the camera device HAL. The device_version
|
||||
* and static_camera_characteristics fields of camera_info are not valid. Only
|
||||
* the android.hardware.Camera API can be supported by this module and its
|
||||
* devices.
|
||||
*
|
||||
*******************************************************************************
|
||||
* Version: 2.0 [CAMERA_MODULE_API_VERSION_2_0]
|
||||
*
|
||||
* Camera modules that report this version number implement the second version
|
||||
* of the camera module HAL interface. Camera devices openable through this
|
||||
* module may support either version 1.0 or version 2.0 of the camera device
|
||||
* HAL interface. The device_version field of camera_info is always valid; the
|
||||
* static_camera_characteristics field of camera_info is valid if the
|
||||
* device_version field is 2.0 or higher.
|
||||
*
|
||||
*******************************************************************************
|
||||
* Version: 2.1 [CAMERA_MODULE_API_VERSION_2_1]
|
||||
*
|
||||
* This camera module version adds support for asynchronous callbacks to the
|
||||
* framework from the camera HAL module, which is used to notify the framework
|
||||
* about changes to the camera module state. Modules that provide a valid
|
||||
* set_callbacks() method must report at least this version number.
|
||||
*
|
||||
*******************************************************************************
|
||||
* Version: 2.2 [CAMERA_MODULE_API_VERSION_2_2]
|
||||
*
|
||||
* This camera module version adds vendor tag support from the module, and
|
||||
* deprecates the old vendor_tag_query_ops that were previously only
|
||||
* accessible with a device open.
|
||||
*
|
||||
*******************************************************************************
|
||||
* Version: 2.3 [CAMERA_MODULE_API_VERSION_2_3]
|
||||
*
|
||||
* This camera module version adds open legacy camera HAL device support.
|
||||
* Framework can use it to open the camera device as lower device HAL version
|
||||
* HAL device if the same device can support multiple device API versions.
|
||||
* The standard hardware module open call (common.methods->open) continues
|
||||
* to open the camera device with the latest supported version, which is
|
||||
* also the version listed in camera_info_t.device_version.
|
||||
*
|
||||
*******************************************************************************
|
||||
* Version: 2.4 [CAMERA_MODULE_API_VERSION_2_4]
|
||||
*
|
||||
* This camera module version adds below API changes:
|
||||
*
|
||||
* 1. Torch mode support. The framework can use it to turn on torch mode for
|
||||
* any camera device that has a flash unit, without opening a camera device. The
|
||||
* camera device has a higher priority accessing the flash unit than the camera
|
||||
* module; opening a camera device will turn off the torch if it had been enabled
|
||||
* through the module interface. When there are any resource conflicts, such as
|
||||
* open() is called to open a camera device, the camera HAL module must notify the
|
||||
* framework through the torch mode status callback that the torch mode has been
|
||||
* turned off.
|
||||
*
|
||||
* 2. External camera (e.g. USB hot-plug camera) support. The API updates specify that
|
||||
* the camera static info is only available when camera is connected and ready to
|
||||
* use for external hot-plug cameras. Calls to get static info will be invalid
|
||||
* calls when camera status is not CAMERA_DEVICE_STATUS_PRESENT. The frameworks
|
||||
* will only count on device status change callbacks to manage the available external
|
||||
* camera list.
|
||||
*
|
||||
* 3. Camera arbitration hints. This module version adds support for explicitly
|
||||
* indicating the number of camera devices that can be simultaneously opened and used.
|
||||
* To specify valid combinations of devices, the resource_cost and conflicting_devices
|
||||
* fields should always be set in the camera_info structure returned by the
|
||||
* get_camera_info call.
|
||||
*
|
||||
* 4. Module initialization method. This will be called by the camera service
|
||||
* right after the HAL module is loaded, to allow for one-time initialization
|
||||
* of the HAL. It is called before any other module methods are invoked.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Predefined macros for currently-defined version numbers
|
||||
*/
|
||||
|
||||
/**
|
||||
* All module versions <= HARDWARE_MODULE_API_VERSION(1, 0xFF) must be treated
|
||||
* as CAMERA_MODULE_API_VERSION_1_0
|
||||
*/
|
||||
#define CAMERA_MODULE_API_VERSION_1_0 HARDWARE_MODULE_API_VERSION(1, 0)
|
||||
#define CAMERA_MODULE_API_VERSION_2_0 HARDWARE_MODULE_API_VERSION(2, 0)
|
||||
#define CAMERA_MODULE_API_VERSION_2_1 HARDWARE_MODULE_API_VERSION(2, 1)
|
||||
#define CAMERA_MODULE_API_VERSION_2_2 HARDWARE_MODULE_API_VERSION(2, 2)
|
||||
#define CAMERA_MODULE_API_VERSION_2_3 HARDWARE_MODULE_API_VERSION(2, 3)
|
||||
#define CAMERA_MODULE_API_VERSION_2_4 HARDWARE_MODULE_API_VERSION(2, 4)
|
||||
|
||||
#define CAMERA_MODULE_API_VERSION_CURRENT CAMERA_MODULE_API_VERSION_2_4
|
||||
|
||||
/**
|
||||
* All device versions <= HARDWARE_DEVICE_API_VERSION(1, 0xFF) must be treated
|
||||
* as CAMERA_DEVICE_API_VERSION_1_0
|
||||
*/
|
||||
#define CAMERA_DEVICE_API_VERSION_1_0 HARDWARE_DEVICE_API_VERSION(1, 0) // DEPRECATED
|
||||
#define CAMERA_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0) // NO LONGER SUPPORTED
|
||||
#define CAMERA_DEVICE_API_VERSION_2_1 HARDWARE_DEVICE_API_VERSION(2, 1) // NO LONGER SUPPORTED
|
||||
#define CAMERA_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0) // NO LONGER SUPPORTED
|
||||
#define CAMERA_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1) // NO LONGER SUPPORTED
|
||||
#define CAMERA_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
|
||||
#define CAMERA_DEVICE_API_VERSION_3_3 HARDWARE_DEVICE_API_VERSION(3, 3)
|
||||
#define CAMERA_DEVICE_API_VERSION_3_4 HARDWARE_DEVICE_API_VERSION(3, 4)
|
||||
#define CAMERA_DEVICE_API_VERSION_3_5 HARDWARE_DEVICE_API_VERSION(3, 5)
|
||||
|
||||
// Device version 3.5 is current, older HAL camera device versions are not
|
||||
// recommended for new devices.
|
||||
#define CAMERA_DEVICE_API_VERSION_CURRENT CAMERA_DEVICE_API_VERSION_3_5
|
||||
|
||||
/**
|
||||
* Defined in /system/media/camera/include/system/camera_metadata.h
|
||||
*/
|
||||
typedef struct camera_metadata camera_metadata_t;
|
||||
|
||||
typedef struct camera_info {
|
||||
/**
|
||||
* The direction that the camera faces to. See system/core/include/system/camera.h
|
||||
* for camera facing definitions.
|
||||
*
|
||||
* Version information (based on camera_module_t.common.module_api_version):
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_3 or lower:
|
||||
*
|
||||
* It should be CAMERA_FACING_BACK or CAMERA_FACING_FRONT.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_4 or higher:
|
||||
*
|
||||
* It should be CAMERA_FACING_BACK, CAMERA_FACING_FRONT or
|
||||
* CAMERA_FACING_EXTERNAL.
|
||||
*/
|
||||
int facing;
|
||||
|
||||
/**
|
||||
* The orientation of the camera image. The value is the angle that the
|
||||
* camera image needs to be rotated clockwise so it shows correctly on the
|
||||
* display in its natural orientation. It should be 0, 90, 180, or 270.
|
||||
*
|
||||
* For example, suppose a device has a naturally tall screen. The
|
||||
* back-facing camera sensor is mounted in landscape. You are looking at the
|
||||
* screen. If the top side of the camera sensor is aligned with the right
|
||||
* edge of the screen in natural orientation, the value should be 90. If the
|
||||
* top side of a front-facing camera sensor is aligned with the right of the
|
||||
* screen, the value should be 270.
|
||||
*
|
||||
* Version information (based on camera_module_t.common.module_api_version):
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_3 or lower:
|
||||
*
|
||||
* Valid in all camera_module versions.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_4 or higher:
|
||||
*
|
||||
* Valid if camera facing is CAMERA_FACING_BACK or CAMERA_FACING_FRONT,
|
||||
* not valid if camera facing is CAMERA_FACING_EXTERNAL.
|
||||
*/
|
||||
int orientation;
|
||||
|
||||
/**
|
||||
* The value of camera_device_t.common.version.
|
||||
*
|
||||
* Version information (based on camera_module_t.common.module_api_version):
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_1_0:
|
||||
*
|
||||
* Not valid. Can be assumed to be CAMERA_DEVICE_API_VERSION_1_0. Do
|
||||
* not read this field.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_0 or higher:
|
||||
*
|
||||
* Always valid
|
||||
*
|
||||
*/
|
||||
uint32_t device_version;
|
||||
|
||||
/**
|
||||
* The camera's fixed characteristics, which include all static camera metadata
|
||||
* specified in system/media/camera/docs/docs.html. This should be a sorted metadata
|
||||
* buffer, and may not be modified or freed by the caller. The pointer should remain
|
||||
* valid for the lifetime of the camera module, and values in it may not
|
||||
* change after it is returned by get_camera_info().
|
||||
*
|
||||
* Version information (based on camera_module_t.common.module_api_version):
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_1_0:
|
||||
*
|
||||
* Not valid. Extra characteristics are not available. Do not read this
|
||||
* field.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_0 or higher:
|
||||
*
|
||||
* Valid if device_version >= CAMERA_DEVICE_API_VERSION_2_0. Do not read
|
||||
* otherwise.
|
||||
*
|
||||
*/
|
||||
const camera_metadata_t *static_camera_characteristics;
|
||||
|
||||
/**
|
||||
* The total resource "cost" of using this camera, represented as an integer
|
||||
* value in the range [0, 100] where 100 represents total usage of the shared
|
||||
* resource that is the limiting bottleneck of the camera subsystem. This may
|
||||
* be a very rough estimate, and is used as a hint to the camera service to
|
||||
* determine when to disallow multiple applications from simultaneously
|
||||
* opening different cameras advertised by the camera service.
|
||||
*
|
||||
* The camera service must be able to simultaneously open and use any
|
||||
* combination of camera devices exposed by the HAL where the sum of
|
||||
* the resource costs of these cameras is <= 100. For determining cost,
|
||||
* each camera device must be assumed to be configured and operating at
|
||||
* the maximally resource-consuming framerate and stream size settings
|
||||
* available in the configuration settings exposed for that device through
|
||||
* the camera metadata.
|
||||
*
|
||||
* The camera service may still attempt to simultaneously open combinations
|
||||
* of camera devices with a total resource cost > 100. This may succeed or
|
||||
* fail. If this succeeds, combinations of configurations that are not
|
||||
* supported due to resource constraints from having multiple open devices
|
||||
* should fail during the configure calls. If the total resource cost is
|
||||
* <= 100, open and configure should never fail for any stream configuration
|
||||
* settings or other device capabilities that would normally succeed for a
|
||||
* device when it is the only open camera device.
|
||||
*
|
||||
* This field will be used to determine whether background applications are
|
||||
* allowed to use this camera device while other applications are using other
|
||||
* camera devices. Note: multiple applications will never be allowed by the
|
||||
* camera service to simultaneously open the same camera device.
|
||||
*
|
||||
* Example use cases:
|
||||
*
|
||||
* Ex. 1: Camera Device 0 = Back Camera
|
||||
* Camera Device 1 = Front Camera
|
||||
* - Using both camera devices causes a large framerate slowdown due to
|
||||
* limited ISP bandwidth.
|
||||
*
|
||||
* Configuration:
|
||||
*
|
||||
* Camera Device 0 - resource_cost = 51
|
||||
* conflicting_devices = null
|
||||
* Camera Device 1 - resource_cost = 51
|
||||
* conflicting_devices = null
|
||||
*
|
||||
* Result:
|
||||
*
|
||||
* Since the sum of the resource costs is > 100, if a higher-priority
|
||||
* application has either device open, no lower-priority applications will be
|
||||
* allowed by the camera service to open either device. If a lower-priority
|
||||
* application is using a device that a higher-priority subsequently attempts
|
||||
* to open, the lower-priority application will be forced to disconnect the
|
||||
* the device.
|
||||
*
|
||||
* If the highest-priority application chooses, it may still attempt to open
|
||||
* both devices (since these devices are not listed as conflicting in the
|
||||
* conflicting_devices fields), but usage of these devices may fail in the
|
||||
* open or configure calls.
|
||||
*
|
||||
* Ex. 2: Camera Device 0 = Left Back Camera
|
||||
* Camera Device 1 = Right Back Camera
|
||||
* Camera Device 2 = Combined stereo camera using both right and left
|
||||
* back camera sensors used by devices 0, and 1
|
||||
* Camera Device 3 = Front Camera
|
||||
* - Due to do hardware constraints, up to two cameras may be open at once. The
|
||||
* combined stereo camera may never be used at the same time as either of the
|
||||
* two back camera devices (device 0, 1), and typically requires too much
|
||||
* bandwidth to use at the same time as the front camera (device 3).
|
||||
*
|
||||
* Configuration:
|
||||
*
|
||||
* Camera Device 0 - resource_cost = 50
|
||||
* conflicting_devices = { 2 }
|
||||
* Camera Device 1 - resource_cost = 50
|
||||
* conflicting_devices = { 2 }
|
||||
* Camera Device 2 - resource_cost = 100
|
||||
* conflicting_devices = { 0, 1 }
|
||||
* Camera Device 3 - resource_cost = 50
|
||||
* conflicting_devices = null
|
||||
*
|
||||
* Result:
|
||||
*
|
||||
* Based on the conflicting_devices fields, the camera service guarantees that
|
||||
* the following sets of open devices will never be allowed: { 1, 2 }, { 0, 2 }.
|
||||
*
|
||||
* Based on the resource_cost fields, if a high-priority foreground application
|
||||
* is using camera device 0, a background application would be allowed to open
|
||||
* camera device 1 or 3 (but would be forced to disconnect it again if the
|
||||
* foreground application opened another device).
|
||||
*
|
||||
* The highest priority application may still attempt to simultaneously open
|
||||
* devices 0, 2, and 3, but the HAL may fail in open or configure calls for
|
||||
* this combination.
|
||||
*
|
||||
* Ex. 3: Camera Device 0 = Back Camera
|
||||
* Camera Device 1 = Front Camera
|
||||
* Camera Device 2 = Low-power Front Camera that uses the same
|
||||
* sensor as device 1, but only exposes image stream
|
||||
* resolutions that can be used in low-power mode
|
||||
* - Using both front cameras (device 1, 2) at the same time is impossible due
|
||||
* a shared physical sensor. Using the back and "high-power" front camera
|
||||
* (device 1) may be impossible for some stream configurations due to hardware
|
||||
* limitations, but the "low-power" front camera option may always be used as
|
||||
* it has special dedicated hardware.
|
||||
*
|
||||
* Configuration:
|
||||
*
|
||||
* Camera Device 0 - resource_cost = 100
|
||||
* conflicting_devices = null
|
||||
* Camera Device 1 - resource_cost = 100
|
||||
* conflicting_devices = { 2 }
|
||||
* Camera Device 2 - resource_cost = 0
|
||||
* conflicting_devices = { 1 }
|
||||
* Result:
|
||||
*
|
||||
* Based on the conflicting_devices fields, the camera service guarantees that
|
||||
* the following sets of open devices will never be allowed: { 1, 2 }.
|
||||
*
|
||||
* Based on the resource_cost fields, only the highest priority application
|
||||
* may attempt to open both device 0 and 1 at the same time. If a higher-priority
|
||||
* application is not using device 1 or 2, a low-priority background application
|
||||
* may open device 2 (but will be forced to disconnect it if a higher-priority
|
||||
* application subsequently opens device 1 or 2).
|
||||
*
|
||||
* Version information (based on camera_module_t.common.module_api_version):
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_3 or lower:
|
||||
*
|
||||
* Not valid. Can be assumed to be 100. Do not read this field.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_4 or higher:
|
||||
*
|
||||
* Always valid.
|
||||
*/
|
||||
int resource_cost;
|
||||
|
||||
/**
|
||||
* An array of camera device IDs represented as NULL-terminated strings
|
||||
* indicating other devices that cannot be simultaneously opened while this
|
||||
* camera device is in use.
|
||||
*
|
||||
* This field is intended to be used to indicate that this camera device
|
||||
* is a composite of several other camera devices, or otherwise has
|
||||
* hardware dependencies that prohibit simultaneous usage. If there are no
|
||||
* dependencies, a NULL may be returned in this field to indicate this.
|
||||
*
|
||||
* The camera service will never simultaneously open any of the devices
|
||||
* in this list while this camera device is open.
|
||||
*
|
||||
* The strings pointed to in this field will not be cleaned up by the camera
|
||||
* service, and must remain while this device is plugged in.
|
||||
*
|
||||
* Version information (based on camera_module_t.common.module_api_version):
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_3 or lower:
|
||||
*
|
||||
* Not valid. Can be assumed to be NULL. Do not read this field.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_4 or higher:
|
||||
*
|
||||
* Always valid.
|
||||
*/
|
||||
char** conflicting_devices;
|
||||
|
||||
/**
|
||||
* The length of the array given in the conflicting_devices field.
|
||||
*
|
||||
* Version information (based on camera_module_t.common.module_api_version):
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_3 or lower:
|
||||
*
|
||||
* Not valid. Can be assumed to be 0. Do not read this field.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_4 or higher:
|
||||
*
|
||||
* Always valid.
|
||||
*/
|
||||
size_t conflicting_devices_length;
|
||||
|
||||
} camera_info_t;
|
||||
|
||||
/**
|
||||
* camera_device_status_t:
|
||||
*
|
||||
* The current status of the camera device, as provided by the HAL through the
|
||||
* camera_module_callbacks.camera_device_status_change() call.
|
||||
*
|
||||
* At module load time, the framework will assume all camera devices are in the
|
||||
* CAMERA_DEVICE_STATUS_PRESENT state. The HAL should invoke
|
||||
* camera_module_callbacks::camera_device_status_change to inform the framework
|
||||
* of any initially NOT_PRESENT devices.
|
||||
*
|
||||
* Allowed transitions:
|
||||
* PRESENT -> NOT_PRESENT
|
||||
* NOT_PRESENT -> ENUMERATING
|
||||
* NOT_PRESENT -> PRESENT
|
||||
* ENUMERATING -> PRESENT
|
||||
* ENUMERATING -> NOT_PRESENT
|
||||
*/
|
||||
typedef enum camera_device_status {
|
||||
/**
|
||||
* The camera device is not currently connected, and opening it will return
|
||||
* failure.
|
||||
*
|
||||
* Version information (based on camera_module_t.common.module_api_version):
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_3 or lower:
|
||||
*
|
||||
* Calls to get_camera_info must still succeed, and provide the same information
|
||||
* it would if the camera were connected.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_4:
|
||||
*
|
||||
* The camera device at this status must return -EINVAL for get_camera_info call,
|
||||
* as the device is not connected.
|
||||
*/
|
||||
CAMERA_DEVICE_STATUS_NOT_PRESENT = 0,
|
||||
|
||||
/**
|
||||
* The camera device is connected, and opening it will succeed.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_3 or lower:
|
||||
*
|
||||
* The information returned by get_camera_info cannot change due to this status
|
||||
* change. By default, the framework will assume all devices are in this state.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_4:
|
||||
*
|
||||
* The information returned by get_camera_info will become valid after a device's
|
||||
* status changes to this. By default, the framework will assume all devices are in
|
||||
* this state.
|
||||
*/
|
||||
CAMERA_DEVICE_STATUS_PRESENT = 1,
|
||||
|
||||
/**
|
||||
* The camera device is connected, but it is undergoing an enumeration and
|
||||
* so opening the device will return -EBUSY.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_3 or lower:
|
||||
*
|
||||
* Calls to get_camera_info must still succeed, as if the camera was in the
|
||||
* PRESENT status.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_4:
|
||||
*
|
||||
* The camera device at this status must return -EINVAL for get_camera_info for call,
|
||||
* as the device is not ready.
|
||||
*/
|
||||
CAMERA_DEVICE_STATUS_ENUMERATING = 2,
|
||||
|
||||
} camera_device_status_t;
|
||||
|
||||
/**
|
||||
* torch_mode_status_t:
|
||||
*
|
||||
* The current status of the torch mode, as provided by the HAL through the
|
||||
* camera_module_callbacks.torch_mode_status_change() call.
|
||||
*
|
||||
* The torch mode status of a camera device is applicable only when the camera
|
||||
* device is present. The framework will not call set_torch_mode() to turn on
|
||||
* torch mode of a camera device if the camera device is not present. At module
|
||||
* load time, the framework will assume torch modes are in the
|
||||
* TORCH_MODE_STATUS_AVAILABLE_OFF state if the camera device is present and
|
||||
* android.flash.info.available is reported as true via get_camera_info() call.
|
||||
*
|
||||
* The behaviors of the camera HAL module that the framework expects in the
|
||||
* following situations when a camera device's status changes:
|
||||
* 1. A previously-disconnected camera device becomes connected.
|
||||
* After camera_module_callbacks::camera_device_status_change() is invoked
|
||||
* to inform the framework that the camera device is present, the framework
|
||||
* will assume the camera device's torch mode is in
|
||||
* TORCH_MODE_STATUS_AVAILABLE_OFF state. The camera HAL module does not need
|
||||
* to invoke camera_module_callbacks::torch_mode_status_change() unless the
|
||||
* flash unit is unavailable to use by set_torch_mode().
|
||||
*
|
||||
* 2. A previously-connected camera becomes disconnected.
|
||||
* After camera_module_callbacks::camera_device_status_change() is invoked
|
||||
* to inform the framework that the camera device is not present, the
|
||||
* framework will not call set_torch_mode() for the disconnected camera
|
||||
* device until its flash unit becomes available again. The camera HAL
|
||||
* module does not need to invoke
|
||||
* camera_module_callbacks::torch_mode_status_change() separately to inform
|
||||
* that the flash unit has become unavailable.
|
||||
*
|
||||
* 3. open() is called to open a camera device.
|
||||
* The camera HAL module must invoke
|
||||
* camera_module_callbacks::torch_mode_status_change() for all flash units
|
||||
* that have entered TORCH_MODE_STATUS_NOT_AVAILABLE state and can not be
|
||||
* turned on by calling set_torch_mode() anymore due to this open() call.
|
||||
* open() must not trigger TORCH_MODE_STATUS_AVAILABLE_OFF before
|
||||
* TORCH_MODE_STATUS_NOT_AVAILABLE for all flash units that have become
|
||||
* unavailable.
|
||||
*
|
||||
* 4. close() is called to close a camera device.
|
||||
* The camera HAL module must invoke
|
||||
* camera_module_callbacks::torch_mode_status_change() for all flash units
|
||||
* that have entered TORCH_MODE_STATUS_AVAILABLE_OFF state and can be turned
|
||||
* on by calling set_torch_mode() again because of enough resources freed
|
||||
* up by this close() call.
|
||||
*
|
||||
* Note that the framework calling set_torch_mode() successfully must trigger
|
||||
* TORCH_MODE_STATUS_AVAILABLE_OFF or TORCH_MODE_STATUS_AVAILABLE_ON callback
|
||||
* for the given camera device. Additionally it must trigger
|
||||
* TORCH_MODE_STATUS_AVAILABLE_OFF callbacks for other previously-on torch
|
||||
* modes if HAL cannot keep multiple torch modes on simultaneously.
|
||||
*/
|
||||
typedef enum torch_mode_status {
|
||||
|
||||
/**
|
||||
* The flash unit is no longer available and the torch mode can not be
|
||||
* turned on by calling set_torch_mode(). If the torch mode is on, it
|
||||
* will be turned off by HAL before HAL calls torch_mode_status_change().
|
||||
*/
|
||||
TORCH_MODE_STATUS_NOT_AVAILABLE = 0,
|
||||
|
||||
/**
|
||||
* A torch mode has become off and available to be turned on via
|
||||
* set_torch_mode(). This may happen in the following
|
||||
* cases:
|
||||
* 1. After the resources to turn on the torch mode have become available.
|
||||
* 2. After set_torch_mode() is called to turn off the torch mode.
|
||||
* 3. After the framework turned on the torch mode of some other camera
|
||||
* device and HAL had to turn off the torch modes of any camera devices
|
||||
* that were previously on.
|
||||
*/
|
||||
TORCH_MODE_STATUS_AVAILABLE_OFF = 1,
|
||||
|
||||
/**
|
||||
* A torch mode has become on and available to be turned off via
|
||||
* set_torch_mode(). This can happen only after set_torch_mode() is called
|
||||
* to turn on the torch mode.
|
||||
*/
|
||||
TORCH_MODE_STATUS_AVAILABLE_ON = 2,
|
||||
|
||||
} torch_mode_status_t;
|
||||
|
||||
/**
|
||||
* Callback functions for the camera HAL module to use to inform the framework
|
||||
* of changes to the camera subsystem.
|
||||
*
|
||||
* Version information (based on camera_module_t.common.module_api_version):
|
||||
*
|
||||
* Each callback is called only by HAL modules implementing the indicated
|
||||
* version or higher of the HAL module API interface.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_1:
|
||||
* camera_device_status_change()
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_4:
|
||||
* torch_mode_status_change()
|
||||
|
||||
*/
|
||||
typedef struct camera_module_callbacks {
|
||||
|
||||
/**
|
||||
* camera_device_status_change:
|
||||
*
|
||||
* Callback to the framework to indicate that the state of a specific camera
|
||||
* device has changed. At module load time, the framework will assume all
|
||||
* camera devices are in the CAMERA_DEVICE_STATUS_PRESENT state. The HAL
|
||||
* must call this method to inform the framework of any initially
|
||||
* NOT_PRESENT devices.
|
||||
*
|
||||
* This callback is added for CAMERA_MODULE_API_VERSION_2_1.
|
||||
*
|
||||
* camera_module_callbacks: The instance of camera_module_callbacks_t passed
|
||||
* to the module with set_callbacks.
|
||||
*
|
||||
* camera_id: The ID of the camera device that has a new status.
|
||||
*
|
||||
* new_status: The new status code, one of the camera_device_status_t enums,
|
||||
* or a platform-specific status.
|
||||
*
|
||||
*/
|
||||
void (*camera_device_status_change)(const struct camera_module_callbacks*,
|
||||
int camera_id,
|
||||
int new_status);
|
||||
|
||||
/**
|
||||
* torch_mode_status_change:
|
||||
*
|
||||
* Callback to the framework to indicate that the state of the torch mode
|
||||
* of the flash unit associated with a specific camera device has changed.
|
||||
* At module load time, the framework will assume the torch modes are in
|
||||
* the TORCH_MODE_STATUS_AVAILABLE_OFF state if android.flash.info.available
|
||||
* is reported as true via get_camera_info() call.
|
||||
*
|
||||
* This callback is added for CAMERA_MODULE_API_VERSION_2_4.
|
||||
*
|
||||
* camera_module_callbacks: The instance of camera_module_callbacks_t
|
||||
* passed to the module with set_callbacks.
|
||||
*
|
||||
* camera_id: The ID of camera device whose flash unit has a new torch mode
|
||||
* status.
|
||||
*
|
||||
* new_status: The new status code, one of the torch_mode_status_t enums.
|
||||
*/
|
||||
void (*torch_mode_status_change)(const struct camera_module_callbacks*,
|
||||
const char* camera_id,
|
||||
int new_status);
|
||||
|
||||
|
||||
} camera_module_callbacks_t;
|
||||
|
||||
typedef struct camera_module {
|
||||
/**
|
||||
* Common methods of the camera module. This *must* be the first member of
|
||||
* camera_module as users of this structure will cast a hw_module_t to
|
||||
* camera_module pointer in contexts where it's known the hw_module_t
|
||||
* references a camera_module.
|
||||
*
|
||||
* The return values for common.methods->open for camera_module are:
|
||||
*
|
||||
* 0: On a successful open of the camera device.
|
||||
*
|
||||
* -ENODEV: The camera device cannot be opened due to an internal
|
||||
* error.
|
||||
*
|
||||
* -EINVAL: The input arguments are invalid, i.e. the id is invalid,
|
||||
* and/or the module is invalid.
|
||||
*
|
||||
* -EBUSY: The camera device was already opened for this camera id
|
||||
* (by using this method or open_legacy),
|
||||
* regardless of the device HAL version it was opened as.
|
||||
*
|
||||
* -EUSERS: The maximal number of camera devices that can be
|
||||
* opened concurrently were opened already, either by
|
||||
* this method or the open_legacy method.
|
||||
*
|
||||
* All other return values from common.methods->open will be treated as
|
||||
* -ENODEV.
|
||||
*/
|
||||
hw_module_t common;
|
||||
|
||||
/**
|
||||
* get_number_of_cameras:
|
||||
*
|
||||
* Returns the number of camera devices accessible through the camera
|
||||
* module. The camera devices are numbered 0 through N-1, where N is the
|
||||
* value returned by this call. The name of the camera device for open() is
|
||||
* simply the number converted to a string. That is, "0" for camera ID 0,
|
||||
* "1" for camera ID 1.
|
||||
*
|
||||
* Version information (based on camera_module_t.common.module_api_version):
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_3 or lower:
|
||||
*
|
||||
* The value here must be static, and cannot change after the first call
|
||||
* to this method.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_4 or higher:
|
||||
*
|
||||
* The value here must be static, and must count only built-in cameras,
|
||||
* which have CAMERA_FACING_BACK or CAMERA_FACING_FRONT camera facing values
|
||||
* (camera_info.facing). The HAL must not include the external cameras
|
||||
* (camera_info.facing == CAMERA_FACING_EXTERNAL) into the return value
|
||||
* of this call. Frameworks will use camera_device_status_change callback
|
||||
* to manage number of external cameras.
|
||||
*/
|
||||
int (*get_number_of_cameras)(void);
|
||||
|
||||
/**
|
||||
* get_camera_info:
|
||||
*
|
||||
* Return the static camera information for a given camera device. This
|
||||
* information may not change for a camera device.
|
||||
*
|
||||
* Return values:
|
||||
*
|
||||
* 0: On a successful operation
|
||||
*
|
||||
* -ENODEV: The information cannot be provided due to an internal
|
||||
* error.
|
||||
*
|
||||
* -EINVAL: The input arguments are invalid, i.e. the id is invalid,
|
||||
* and/or the module is invalid.
|
||||
*
|
||||
* Version information (based on camera_module_t.common.module_api_version):
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_4 or higher:
|
||||
*
|
||||
* When a camera is disconnected, its camera id becomes invalid. Calling this
|
||||
* this method with this invalid camera id will get -EINVAL and NULL camera
|
||||
* static metadata (camera_info.static_camera_characteristics).
|
||||
*/
|
||||
int (*get_camera_info)(int camera_id, struct camera_info *info);
|
||||
|
||||
/**
|
||||
* set_callbacks:
|
||||
*
|
||||
* Provide callback function pointers to the HAL module to inform framework
|
||||
* of asynchronous camera module events. The framework will call this
|
||||
* function once after initial camera HAL module load, after the
|
||||
* get_number_of_cameras() method is called for the first time, and before
|
||||
* any other calls to the module.
|
||||
*
|
||||
* Version information (based on camera_module_t.common.module_api_version):
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_1_0, CAMERA_MODULE_API_VERSION_2_0:
|
||||
*
|
||||
* Not provided by HAL module. Framework may not call this function.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_1:
|
||||
*
|
||||
* Valid to be called by the framework.
|
||||
*
|
||||
* Return values:
|
||||
*
|
||||
* 0: On a successful operation
|
||||
*
|
||||
* -ENODEV: The operation cannot be completed due to an internal
|
||||
* error.
|
||||
*
|
||||
* -EINVAL: The input arguments are invalid, i.e. the callbacks are
|
||||
* null
|
||||
*/
|
||||
int (*set_callbacks)(const camera_module_callbacks_t *callbacks);
|
||||
|
||||
/**
|
||||
* get_vendor_tag_ops:
|
||||
*
|
||||
* Get methods to query for vendor extension metadata tag information. The
|
||||
* HAL should fill in all the vendor tag operation methods, or leave ops
|
||||
* unchanged if no vendor tags are defined.
|
||||
*
|
||||
* The vendor_tag_ops structure used here is defined in:
|
||||
* system/media/camera/include/system/vendor_tags.h
|
||||
*
|
||||
* Version information (based on camera_module_t.common.module_api_version):
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_1_x/2_0/2_1:
|
||||
* Not provided by HAL module. Framework may not call this function.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_2:
|
||||
* Valid to be called by the framework.
|
||||
*/
|
||||
void (*get_vendor_tag_ops)(vendor_tag_ops_t* ops);
|
||||
|
||||
/**
|
||||
* open_legacy:
|
||||
*
|
||||
* Open a specific legacy camera HAL device if multiple device HAL API
|
||||
* versions are supported by this camera HAL module. For example, if the
|
||||
* camera module supports both CAMERA_DEVICE_API_VERSION_1_0 and
|
||||
* CAMERA_DEVICE_API_VERSION_3_2 device API for the same camera id,
|
||||
* framework can call this function to open the camera device as
|
||||
* CAMERA_DEVICE_API_VERSION_1_0 device.
|
||||
*
|
||||
* This is an optional method. A Camera HAL module does not need to support
|
||||
* more than one device HAL version per device, and such modules may return
|
||||
* -ENOSYS for all calls to this method. For all older HAL device API
|
||||
* versions that are not supported, it may return -EOPNOTSUPP. When above
|
||||
* cases occur, The normal open() method (common.methods->open) will be
|
||||
* used by the framework instead.
|
||||
*
|
||||
* Version information (based on camera_module_t.common.module_api_version):
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2:
|
||||
* Not provided by HAL module. Framework will not call this function.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_3:
|
||||
* Valid to be called by the framework.
|
||||
*
|
||||
* Return values:
|
||||
*
|
||||
* 0: On a successful open of the camera device.
|
||||
*
|
||||
* -ENOSYS This method is not supported.
|
||||
*
|
||||
* -EOPNOTSUPP: The requested HAL version is not supported by this method.
|
||||
*
|
||||
* -EINVAL: The input arguments are invalid, i.e. the id is invalid,
|
||||
* and/or the module is invalid.
|
||||
*
|
||||
* -EBUSY: The camera device was already opened for this camera id
|
||||
* (by using this method or common.methods->open method),
|
||||
* regardless of the device HAL version it was opened as.
|
||||
*
|
||||
* -EUSERS: The maximal number of camera devices that can be
|
||||
* opened concurrently were opened already, either by
|
||||
* this method or common.methods->open method.
|
||||
*/
|
||||
int (*open_legacy)(const struct hw_module_t* module, const char* id,
|
||||
uint32_t halVersion, struct hw_device_t** device);
|
||||
|
||||
/**
|
||||
* set_torch_mode:
|
||||
*
|
||||
* Turn on or off the torch mode of the flash unit associated with a given
|
||||
* camera ID. If the operation is successful, HAL must notify the framework
|
||||
* torch state by invoking
|
||||
* camera_module_callbacks.torch_mode_status_change() with the new state.
|
||||
*
|
||||
* The camera device has a higher priority accessing the flash unit. When
|
||||
* there are any resource conflicts, such as open() is called to open a
|
||||
* camera device, HAL module must notify the framework through
|
||||
* camera_module_callbacks.torch_mode_status_change() that the
|
||||
* torch mode has been turned off and the torch mode state has become
|
||||
* TORCH_MODE_STATUS_NOT_AVAILABLE. When resources to turn on torch mode
|
||||
* become available again, HAL module must notify the framework through
|
||||
* camera_module_callbacks.torch_mode_status_change() that the torch mode
|
||||
* state has become TORCH_MODE_STATUS_AVAILABLE_OFF for set_torch_mode() to
|
||||
* be called.
|
||||
*
|
||||
* When the framework calls set_torch_mode() to turn on the torch mode of a
|
||||
* flash unit, if HAL cannot keep multiple torch modes on simultaneously,
|
||||
* HAL should turn off the torch mode that was turned on by
|
||||
* a previous set_torch_mode() call and notify the framework that the torch
|
||||
* mode state of that flash unit has become TORCH_MODE_STATUS_AVAILABLE_OFF.
|
||||
*
|
||||
* Version information (based on camera_module_t.common.module_api_version):
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2/2_3:
|
||||
* Not provided by HAL module. Framework will not call this function.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_4:
|
||||
* Valid to be called by the framework.
|
||||
*
|
||||
* Return values:
|
||||
*
|
||||
* 0: On a successful operation.
|
||||
*
|
||||
* -ENOSYS: The camera device does not support this operation. It is
|
||||
* returned if and only if android.flash.info.available is
|
||||
* false.
|
||||
*
|
||||
* -EBUSY: The camera device is already in use.
|
||||
*
|
||||
* -EUSERS: The resources needed to turn on the torch mode are not
|
||||
* available, typically because other camera devices are
|
||||
* holding the resources to make using the flash unit not
|
||||
* possible.
|
||||
*
|
||||
* -EINVAL: camera_id is invalid.
|
||||
*
|
||||
*/
|
||||
int (*set_torch_mode)(const char* camera_id, bool enabled);
|
||||
|
||||
/**
|
||||
* init:
|
||||
*
|
||||
* This method is called by the camera service before any other methods
|
||||
* are invoked, right after the camera HAL library has been successfully
|
||||
* loaded. It may be left as NULL by the HAL module, if no initialization
|
||||
* in needed.
|
||||
*
|
||||
* It can be used by HAL implementations to perform initialization and
|
||||
* other one-time operations.
|
||||
*
|
||||
* Version information (based on camera_module_t.common.module_api_version):
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_1_x/2_0/2_1/2_2/2_3:
|
||||
* Not provided by HAL module. Framework will not call this function.
|
||||
*
|
||||
* CAMERA_MODULE_API_VERSION_2_4:
|
||||
* If not NULL, will always be called by the framework once after the HAL
|
||||
* module is loaded, before any other HAL module method is called.
|
||||
*
|
||||
* Return values:
|
||||
*
|
||||
* 0: On a successful operation.
|
||||
*
|
||||
* -ENODEV: Initialization cannot be completed due to an internal
|
||||
* error. The HAL must be assumed to be in a nonfunctional
|
||||
* state.
|
||||
*
|
||||
*/
|
||||
int (*init)();
|
||||
|
||||
/* reserved for future use */
|
||||
void* reserved[5];
|
||||
} camera_module_t;
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* ANDROID_INCLUDE_CAMERA_COMMON_H */
|
||||
@@ -0,0 +1,174 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ANDROID_FB_INTERFACE_H
|
||||
#define ANDROID_FB_INTERFACE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <cutils/native_handle.h>
|
||||
|
||||
#include <hardware/hardware.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define GRALLOC_HARDWARE_FB0 "fb0"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct framebuffer_device_t {
|
||||
/**
|
||||
* Common methods of the framebuffer device. This *must* be the first member of
|
||||
* framebuffer_device_t as users of this structure will cast a hw_device_t to
|
||||
* framebuffer_device_t pointer in contexts where it's known the hw_device_t references a
|
||||
* framebuffer_device_t.
|
||||
*/
|
||||
struct hw_device_t common;
|
||||
|
||||
/* flags describing some attributes of the framebuffer */
|
||||
const uint32_t flags;
|
||||
|
||||
/* dimensions of the framebuffer in pixels */
|
||||
const uint32_t width;
|
||||
const uint32_t height;
|
||||
|
||||
/* frambuffer stride in pixels */
|
||||
const int stride;
|
||||
|
||||
/* framebuffer pixel format */
|
||||
const int format;
|
||||
|
||||
/* resolution of the framebuffer's display panel in pixel per inch*/
|
||||
const float xdpi;
|
||||
const float ydpi;
|
||||
|
||||
/* framebuffer's display panel refresh rate in frames per second */
|
||||
const float fps;
|
||||
|
||||
/* min swap interval supported by this framebuffer */
|
||||
const int minSwapInterval;
|
||||
|
||||
/* max swap interval supported by this framebuffer */
|
||||
const int maxSwapInterval;
|
||||
|
||||
/* Number of framebuffers supported*/
|
||||
const int numFramebuffers;
|
||||
|
||||
int reserved[7];
|
||||
|
||||
/*
|
||||
* requests a specific swap-interval (same definition than EGL)
|
||||
*
|
||||
* Returns 0 on success or -errno on error.
|
||||
*/
|
||||
int (*setSwapInterval)(struct framebuffer_device_t* window,
|
||||
int interval);
|
||||
|
||||
/*
|
||||
* This hook is OPTIONAL.
|
||||
*
|
||||
* It is non NULL If the framebuffer driver supports "update-on-demand"
|
||||
* and the given rectangle is the area of the screen that gets
|
||||
* updated during (*post)().
|
||||
*
|
||||
* This is useful on devices that are able to DMA only a portion of
|
||||
* the screen to the display panel, upon demand -- as opposed to
|
||||
* constantly refreshing the panel 60 times per second, for instance.
|
||||
*
|
||||
* Only the area defined by this rectangle is guaranteed to be valid, that
|
||||
* is, the driver is not allowed to post anything outside of this
|
||||
* rectangle.
|
||||
*
|
||||
* The rectangle evaluated during (*post)() and specifies which area
|
||||
* of the buffer passed in (*post)() shall to be posted.
|
||||
*
|
||||
* return -EINVAL if width or height <=0, or if left or top < 0
|
||||
*/
|
||||
int (*setUpdateRect)(struct framebuffer_device_t* window,
|
||||
int left, int top, int width, int height);
|
||||
|
||||
/*
|
||||
* Post <buffer> to the display (display it on the screen)
|
||||
* The buffer must have been allocated with the
|
||||
* GRALLOC_USAGE_HW_FB usage flag.
|
||||
* buffer must be the same width and height as the display and must NOT
|
||||
* be locked.
|
||||
*
|
||||
* The buffer is shown during the next VSYNC.
|
||||
*
|
||||
* If the same buffer is posted again (possibly after some other buffer),
|
||||
* post() will block until the the first post is completed.
|
||||
*
|
||||
* Internally, post() is expected to lock the buffer so that a
|
||||
* subsequent call to gralloc_module_t::(*lock)() with USAGE_RENDER or
|
||||
* USAGE_*_WRITE will block until it is safe; that is typically once this
|
||||
* buffer is shown and another buffer has been posted.
|
||||
*
|
||||
* Returns 0 on success or -errno on error.
|
||||
*/
|
||||
int (*post)(struct framebuffer_device_t* dev, buffer_handle_t buffer);
|
||||
|
||||
|
||||
/*
|
||||
* The (*compositionComplete)() method must be called after the
|
||||
* compositor has finished issuing GL commands for client buffers.
|
||||
*/
|
||||
|
||||
int (*compositionComplete)(struct framebuffer_device_t* dev);
|
||||
|
||||
/*
|
||||
* This hook is OPTIONAL.
|
||||
*
|
||||
* If non NULL it will be caused by SurfaceFlinger on dumpsys
|
||||
*/
|
||||
void (*dump)(struct framebuffer_device_t* dev, char *buff, int buff_len);
|
||||
|
||||
/*
|
||||
* (*enableScreen)() is used to either blank (enable=0) or
|
||||
* unblank (enable=1) the screen this framebuffer is attached to.
|
||||
*
|
||||
* Returns 0 on success or -errno on error.
|
||||
*/
|
||||
int (*enableScreen)(struct framebuffer_device_t* dev, int enable);
|
||||
|
||||
void* reserved_proc[6];
|
||||
|
||||
} framebuffer_device_t;
|
||||
|
||||
|
||||
/** convenience API for opening and closing a supported device */
|
||||
|
||||
static inline int framebuffer_open(const struct hw_module_t* module,
|
||||
struct framebuffer_device_t** device) {
|
||||
return module->methods->open(module,
|
||||
GRALLOC_HARDWARE_FB0, TO_HW_DEVICE_T_OPEN(device));
|
||||
}
|
||||
|
||||
static inline int framebuffer_close(struct framebuffer_device_t* device) {
|
||||
return device->common.close(&device->common);
|
||||
}
|
||||
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // ANDROID_FB_INTERFACE_H
|
||||
@@ -0,0 +1,416 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef ANDROID_GRALLOC_INTERFACE_H
|
||||
#define ANDROID_GRALLOC_INTERFACE_H
|
||||
|
||||
#include <hardware/hardware.h>
|
||||
#include <system/graphics.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <cutils/native_handle.h>
|
||||
|
||||
#include <hardware/fb.h>
|
||||
#include <hardware/hardware.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* Module versioning information for the Gralloc hardware module, based on
|
||||
* gralloc_module_t.common.module_api_version.
|
||||
*
|
||||
* Version History:
|
||||
*
|
||||
* GRALLOC_MODULE_API_VERSION_0_1:
|
||||
* Initial Gralloc hardware module API.
|
||||
*
|
||||
* GRALLOC_MODULE_API_VERSION_0_2:
|
||||
* Add support for flexible YCbCr format with (*lock_ycbcr)() method.
|
||||
*
|
||||
* GRALLOC_MODULE_API_VERSION_0_3:
|
||||
* Add support for fence passing to/from lock/unlock.
|
||||
*/
|
||||
|
||||
#define GRALLOC_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
|
||||
#define GRALLOC_MODULE_API_VERSION_0_2 HARDWARE_MODULE_API_VERSION(0, 2)
|
||||
#define GRALLOC_MODULE_API_VERSION_0_3 HARDWARE_MODULE_API_VERSION(0, 3)
|
||||
|
||||
#define GRALLOC_DEVICE_API_VERSION_0_1 HARDWARE_DEVICE_API_VERSION(0, 1)
|
||||
|
||||
/**
|
||||
* The id of this module
|
||||
*/
|
||||
#define GRALLOC_HARDWARE_MODULE_ID "gralloc"
|
||||
|
||||
/**
|
||||
* Name of the graphics device to open
|
||||
*/
|
||||
|
||||
#define GRALLOC_HARDWARE_GPU0 "gpu0"
|
||||
|
||||
enum {
|
||||
/* buffer is never read in software */
|
||||
GRALLOC_USAGE_SW_READ_NEVER = 0x00000000U,
|
||||
/* buffer is rarely read in software */
|
||||
GRALLOC_USAGE_SW_READ_RARELY = 0x00000002U,
|
||||
/* buffer is often read in software */
|
||||
GRALLOC_USAGE_SW_READ_OFTEN = 0x00000003U,
|
||||
/* mask for the software read values */
|
||||
GRALLOC_USAGE_SW_READ_MASK = 0x0000000FU,
|
||||
|
||||
/* buffer is never written in software */
|
||||
GRALLOC_USAGE_SW_WRITE_NEVER = 0x00000000U,
|
||||
/* buffer is rarely written in software */
|
||||
GRALLOC_USAGE_SW_WRITE_RARELY = 0x00000020U,
|
||||
/* buffer is often written in software */
|
||||
GRALLOC_USAGE_SW_WRITE_OFTEN = 0x00000030U,
|
||||
/* mask for the software write values */
|
||||
GRALLOC_USAGE_SW_WRITE_MASK = 0x000000F0U,
|
||||
|
||||
/* buffer will be used as an OpenGL ES texture */
|
||||
GRALLOC_USAGE_HW_TEXTURE = 0x00000100U,
|
||||
/* buffer will be used as an OpenGL ES render target */
|
||||
GRALLOC_USAGE_HW_RENDER = 0x00000200U,
|
||||
/* buffer will be used by the 2D hardware blitter */
|
||||
GRALLOC_USAGE_HW_2D = 0x00000400U,
|
||||
/* buffer will be used by the HWComposer HAL module */
|
||||
GRALLOC_USAGE_HW_COMPOSER = 0x00000800U,
|
||||
/* buffer will be used with the framebuffer device */
|
||||
GRALLOC_USAGE_HW_FB = 0x00001000U,
|
||||
|
||||
/* buffer should be displayed full-screen on an external display when
|
||||
* possible */
|
||||
GRALLOC_USAGE_EXTERNAL_DISP = 0x00002000U,
|
||||
|
||||
/* Must have a hardware-protected path to external display sink for
|
||||
* this buffer. If a hardware-protected path is not available, then
|
||||
* either don't composite only this buffer (preferred) to the
|
||||
* external sink, or (less desirable) do not route the entire
|
||||
* composition to the external sink. */
|
||||
GRALLOC_USAGE_PROTECTED = 0x00004000U,
|
||||
|
||||
/* buffer may be used as a cursor */
|
||||
GRALLOC_USAGE_CURSOR = 0x00008000U,
|
||||
|
||||
/* buffer will be used with the HW video encoder */
|
||||
GRALLOC_USAGE_HW_VIDEO_ENCODER = 0x00010000U,
|
||||
/* buffer will be written by the HW camera pipeline */
|
||||
GRALLOC_USAGE_HW_CAMERA_WRITE = 0x00020000U,
|
||||
/* buffer will be read by the HW camera pipeline */
|
||||
GRALLOC_USAGE_HW_CAMERA_READ = 0x00040000U,
|
||||
/* buffer will be used as part of zero-shutter-lag queue */
|
||||
GRALLOC_USAGE_HW_CAMERA_ZSL = 0x00060000U,
|
||||
/* mask for the camera access values */
|
||||
GRALLOC_USAGE_HW_CAMERA_MASK = 0x00060000U,
|
||||
/* mask for the software usage bit-mask */
|
||||
GRALLOC_USAGE_HW_MASK = 0x00071F00U,
|
||||
|
||||
/* buffer will be used as a RenderScript Allocation */
|
||||
GRALLOC_USAGE_RENDERSCRIPT = 0x00100000U,
|
||||
|
||||
/* Set by the consumer to indicate to the producer that they may attach a
|
||||
* buffer that they did not detach from the BufferQueue. Will be filtered
|
||||
* out by GRALLOC_USAGE_ALLOC_MASK, so gralloc modules will not need to
|
||||
* handle this flag. */
|
||||
GRALLOC_USAGE_FOREIGN_BUFFERS = 0x00200000U,
|
||||
|
||||
/* Mask of all flags which could be passed to a gralloc module for buffer
|
||||
* allocation. Any flags not in this mask do not need to be handled by
|
||||
* gralloc modules. */
|
||||
GRALLOC_USAGE_ALLOC_MASK = ~(GRALLOC_USAGE_FOREIGN_BUFFERS),
|
||||
|
||||
/* implementation-specific private usage flags */
|
||||
GRALLOC_USAGE_PRIVATE_0 = 0x10000000U,
|
||||
GRALLOC_USAGE_PRIVATE_1 = 0x20000000U,
|
||||
GRALLOC_USAGE_PRIVATE_2 = 0x40000000U,
|
||||
GRALLOC_USAGE_PRIVATE_3 = 0x80000000U,
|
||||
GRALLOC_USAGE_PRIVATE_MASK = 0xF0000000U,
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
|
||||
* and the fields of this data structure must begin with hw_module_t
|
||||
* followed by module specific information.
|
||||
*/
|
||||
typedef struct gralloc_module_t {
|
||||
struct hw_module_t common;
|
||||
|
||||
/*
|
||||
* (*registerBuffer)() must be called before a buffer_handle_t that has not
|
||||
* been created with (*alloc_device_t::alloc)() can be used.
|
||||
*
|
||||
* This is intended to be used with buffer_handle_t's that have been
|
||||
* received in this process through IPC.
|
||||
*
|
||||
* This function checks that the handle is indeed a valid one and prepares
|
||||
* it for use with (*lock)() and (*unlock)().
|
||||
*
|
||||
* It is not necessary to call (*registerBuffer)() on a handle created
|
||||
* with (*alloc_device_t::alloc)().
|
||||
*
|
||||
* returns an error if this buffer_handle_t is not valid.
|
||||
*/
|
||||
int (*registerBuffer)(struct gralloc_module_t const* module,
|
||||
buffer_handle_t handle);
|
||||
|
||||
/*
|
||||
* (*unregisterBuffer)() is called once this handle is no longer needed in
|
||||
* this process. After this call, it is an error to call (*lock)(),
|
||||
* (*unlock)(), or (*registerBuffer)().
|
||||
*
|
||||
* This function doesn't close or free the handle itself; this is done
|
||||
* by other means, usually through libcutils's native_handle_close() and
|
||||
* native_handle_free().
|
||||
*
|
||||
* It is an error to call (*unregisterBuffer)() on a buffer that wasn't
|
||||
* explicitly registered first.
|
||||
*/
|
||||
int (*unregisterBuffer)(struct gralloc_module_t const* module,
|
||||
buffer_handle_t handle);
|
||||
|
||||
/*
|
||||
* The (*lock)() method is called before a buffer is accessed for the
|
||||
* specified usage. This call may block, for instance if the h/w needs
|
||||
* to finish rendering or if CPU caches need to be synchronized.
|
||||
*
|
||||
* The caller promises to modify only pixels in the area specified
|
||||
* by (l,t,w,h).
|
||||
*
|
||||
* The content of the buffer outside of the specified area is NOT modified
|
||||
* by this call.
|
||||
*
|
||||
* If usage specifies GRALLOC_USAGE_SW_*, vaddr is filled with the address
|
||||
* of the buffer in virtual memory.
|
||||
*
|
||||
* Note calling (*lock)() on HAL_PIXEL_FORMAT_YCbCr_*_888 buffers will fail
|
||||
* and return -EINVAL. These buffers must be locked with (*lock_ycbcr)()
|
||||
* instead.
|
||||
*
|
||||
* THREADING CONSIDERATIONS:
|
||||
*
|
||||
* It is legal for several different threads to lock a buffer from
|
||||
* read access, none of the threads are blocked.
|
||||
*
|
||||
* However, locking a buffer simultaneously for write or read/write is
|
||||
* undefined, but:
|
||||
* - shall not result in termination of the process
|
||||
* - shall not block the caller
|
||||
* It is acceptable to return an error or to leave the buffer's content
|
||||
* into an indeterminate state.
|
||||
*
|
||||
* If the buffer was created with a usage mask incompatible with the
|
||||
* requested usage flags here, -EINVAL is returned.
|
||||
*
|
||||
*/
|
||||
|
||||
int (*lock)(struct gralloc_module_t const* module,
|
||||
buffer_handle_t handle, int usage,
|
||||
int l, int t, int w, int h,
|
||||
void** vaddr);
|
||||
|
||||
|
||||
/*
|
||||
* The (*unlock)() method must be called after all changes to the buffer
|
||||
* are completed.
|
||||
*/
|
||||
|
||||
int (*unlock)(struct gralloc_module_t const* module,
|
||||
buffer_handle_t handle);
|
||||
|
||||
|
||||
/* reserved for future use */
|
||||
int (*perform)(struct gralloc_module_t const* module,
|
||||
int operation, ... );
|
||||
|
||||
/*
|
||||
* The (*lock_ycbcr)() method is like the (*lock)() method, with the
|
||||
* difference that it fills a struct ycbcr with a description of the buffer
|
||||
* layout, and zeroes out the reserved fields.
|
||||
*
|
||||
* If the buffer format is not compatible with a flexible YUV format (e.g.
|
||||
* the buffer layout cannot be represented with the ycbcr struct), it
|
||||
* will return -EINVAL.
|
||||
*
|
||||
* This method must work on buffers with HAL_PIXEL_FORMAT_YCbCr_*_888
|
||||
* if supported by the device, as well as with any other format that is
|
||||
* requested by the multimedia codecs when they are configured with a
|
||||
* flexible-YUV-compatible color-format with android native buffers.
|
||||
*
|
||||
* Note that this method may also be called on buffers of other formats,
|
||||
* including non-YUV formats.
|
||||
*
|
||||
* Added in GRALLOC_MODULE_API_VERSION_0_2.
|
||||
*/
|
||||
|
||||
int (*lock_ycbcr)(struct gralloc_module_t const* module,
|
||||
buffer_handle_t handle, int usage,
|
||||
int l, int t, int w, int h,
|
||||
struct android_ycbcr *ycbcr);
|
||||
|
||||
/*
|
||||
* The (*lockAsync)() method is like the (*lock)() method except
|
||||
* that the buffer's sync fence object is passed into the lock
|
||||
* call instead of requiring the caller to wait for completion.
|
||||
*
|
||||
* The gralloc implementation takes ownership of the fenceFd and
|
||||
* is responsible for closing it when no longer needed.
|
||||
*
|
||||
* Added in GRALLOC_MODULE_API_VERSION_0_3.
|
||||
*/
|
||||
int (*lockAsync)(struct gralloc_module_t const* module,
|
||||
buffer_handle_t handle, int usage,
|
||||
int l, int t, int w, int h,
|
||||
void** vaddr, int fenceFd);
|
||||
|
||||
/*
|
||||
* The (*unlockAsync)() method is like the (*unlock)() method
|
||||
* except that a buffer sync fence object is returned from the
|
||||
* lock call, representing the completion of any pending work
|
||||
* performed by the gralloc implementation.
|
||||
*
|
||||
* The caller takes ownership of the fenceFd and is responsible
|
||||
* for closing it when no longer needed.
|
||||
*
|
||||
* Added in GRALLOC_MODULE_API_VERSION_0_3.
|
||||
*/
|
||||
int (*unlockAsync)(struct gralloc_module_t const* module,
|
||||
buffer_handle_t handle, int* fenceFd);
|
||||
|
||||
/*
|
||||
* The (*lockAsync_ycbcr)() method is like the (*lock_ycbcr)()
|
||||
* method except that the buffer's sync fence object is passed
|
||||
* into the lock call instead of requiring the caller to wait for
|
||||
* completion.
|
||||
*
|
||||
* The gralloc implementation takes ownership of the fenceFd and
|
||||
* is responsible for closing it when no longer needed.
|
||||
*
|
||||
* Added in GRALLOC_MODULE_API_VERSION_0_3.
|
||||
*/
|
||||
int (*lockAsync_ycbcr)(struct gralloc_module_t const* module,
|
||||
buffer_handle_t handle, int usage,
|
||||
int l, int t, int w, int h,
|
||||
struct android_ycbcr *ycbcr, int fenceFd);
|
||||
|
||||
/* reserved for future use */
|
||||
void* reserved_proc[3];
|
||||
} gralloc_module_t;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* Every device data structure must begin with hw_device_t
|
||||
* followed by module specific public methods and attributes.
|
||||
*/
|
||||
|
||||
typedef struct alloc_device_t {
|
||||
struct hw_device_t common;
|
||||
|
||||
/*
|
||||
* (*alloc)() Allocates a buffer in graphic memory with the requested
|
||||
* parameters and returns a buffer_handle_t and the stride in pixels to
|
||||
* allow the implementation to satisfy hardware constraints on the width
|
||||
* of a pixmap (eg: it may have to be multiple of 8 pixels).
|
||||
* The CALLER TAKES OWNERSHIP of the buffer_handle_t.
|
||||
*
|
||||
* If format is HAL_PIXEL_FORMAT_YCbCr_420_888, the returned stride must be
|
||||
* 0, since the actual strides are available from the android_ycbcr
|
||||
* structure.
|
||||
*
|
||||
* Returns 0 on success or -errno on error.
|
||||
*/
|
||||
|
||||
int (*alloc)(struct alloc_device_t* dev,
|
||||
int w, int h, int format, int usage,
|
||||
buffer_handle_t* handle, int* stride);
|
||||
|
||||
/*
|
||||
* (*free)() Frees a previously allocated buffer.
|
||||
* Behavior is undefined if the buffer is still mapped in any process,
|
||||
* but shall not result in termination of the program or security breaches
|
||||
* (allowing a process to get access to another process' buffers).
|
||||
* THIS FUNCTION TAKES OWNERSHIP of the buffer_handle_t which becomes
|
||||
* invalid after the call.
|
||||
*
|
||||
* Returns 0 on success or -errno on error.
|
||||
*/
|
||||
int (*free)(struct alloc_device_t* dev,
|
||||
buffer_handle_t handle);
|
||||
|
||||
/* This hook is OPTIONAL.
|
||||
*
|
||||
* If non NULL it will be caused by SurfaceFlinger on dumpsys
|
||||
*/
|
||||
void (*dump)(struct alloc_device_t *dev, char *buff, int buff_len);
|
||||
|
||||
void* reserved_proc[7];
|
||||
} alloc_device_t;
|
||||
|
||||
|
||||
/** convenience API for opening and closing a supported device */
|
||||
|
||||
static inline int gralloc_open(const struct hw_module_t* module,
|
||||
struct alloc_device_t** device) {
|
||||
return module->methods->open(module,
|
||||
GRALLOC_HARDWARE_GPU0, TO_HW_DEVICE_T_OPEN(device));
|
||||
}
|
||||
|
||||
static inline int gralloc_close(struct alloc_device_t* device) {
|
||||
return device->common.close(&device->common);
|
||||
}
|
||||
|
||||
/**
|
||||
* map_usage_to_memtrack should be called after allocating a gralloc buffer.
|
||||
*
|
||||
* @param usage - it is the flag used when alloc function is called.
|
||||
*
|
||||
* This function maps the gralloc usage flags to appropriate memtrack bucket.
|
||||
* GrallocHAL implementers and users should make an additional ION_IOCTL_TAG
|
||||
* call using the memtrack tag returned by this function. This will help the
|
||||
* in-kernel memtack to categorize the memory allocated by different processes
|
||||
* according to their usage.
|
||||
*
|
||||
*/
|
||||
static inline const char* map_usage_to_memtrack(uint32_t usage) {
|
||||
usage &= GRALLOC_USAGE_ALLOC_MASK;
|
||||
|
||||
if ((usage & GRALLOC_USAGE_HW_CAMERA_WRITE) != 0) {
|
||||
return "camera";
|
||||
} else if ((usage & GRALLOC_USAGE_HW_VIDEO_ENCODER) != 0 ||
|
||||
(usage & GRALLOC_USAGE_EXTERNAL_DISP) != 0) {
|
||||
return "video";
|
||||
} else if ((usage & GRALLOC_USAGE_HW_RENDER) != 0 ||
|
||||
(usage & GRALLOC_USAGE_HW_TEXTURE) != 0) {
|
||||
return "gl";
|
||||
} else if ((usage & GRALLOC_USAGE_HW_CAMERA_READ) != 0) {
|
||||
return "camera";
|
||||
} else if ((usage & GRALLOC_USAGE_SW_READ_MASK) != 0 ||
|
||||
(usage & GRALLOC_USAGE_SW_WRITE_MASK) != 0) {
|
||||
return "cpu";
|
||||
}
|
||||
return "graphics";
|
||||
}
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // ANDROID_GRALLOC_INTERFACE_H
|
||||
@@ -0,0 +1,245 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
/*
|
||||
* Copyright (C) 2008 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_INCLUDE_HARDWARE_HARDWARE_H
|
||||
#define ANDROID_INCLUDE_HARDWARE_HARDWARE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <cutils/native_handle.h>
|
||||
#include <system/graphics.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/*
|
||||
* Value for the hw_module_t.tag field
|
||||
*/
|
||||
|
||||
#define MAKE_TAG_CONSTANT(A,B,C,D) (((A) << 24) | ((B) << 16) | ((C) << 8) | (D))
|
||||
|
||||
#define HARDWARE_MODULE_TAG MAKE_TAG_CONSTANT('H', 'W', 'M', 'T')
|
||||
#define HARDWARE_DEVICE_TAG MAKE_TAG_CONSTANT('H', 'W', 'D', 'T')
|
||||
|
||||
#define HARDWARE_MAKE_API_VERSION(maj,min) \
|
||||
((((maj) & 0xff) << 8) | ((min) & 0xff))
|
||||
|
||||
#define HARDWARE_MAKE_API_VERSION_2(maj,min,hdr) \
|
||||
((((maj) & 0xff) << 24) | (((min) & 0xff) << 16) | ((hdr) & 0xffff))
|
||||
#define HARDWARE_API_VERSION_2_MAJ_MIN_MASK 0xffff0000
|
||||
#define HARDWARE_API_VERSION_2_HEADER_MASK 0x0000ffff
|
||||
|
||||
|
||||
/*
|
||||
* The current HAL API version.
|
||||
*
|
||||
* All module implementations must set the hw_module_t.hal_api_version field
|
||||
* to this value when declaring the module with HAL_MODULE_INFO_SYM.
|
||||
*
|
||||
* Note that previous implementations have always set this field to 0.
|
||||
* Therefore, libhardware HAL API will always consider versions 0.0 and 1.0
|
||||
* to be 100% binary compatible.
|
||||
*
|
||||
*/
|
||||
#define HARDWARE_HAL_API_VERSION HARDWARE_MAKE_API_VERSION(1, 0)
|
||||
|
||||
/*
|
||||
* Helper macros for module implementors.
|
||||
*
|
||||
* The derived modules should provide convenience macros for supported
|
||||
* versions so that implementations can explicitly specify module/device
|
||||
* versions at definition time.
|
||||
*
|
||||
* Use this macro to set the hw_module_t.module_api_version field.
|
||||
*/
|
||||
#define HARDWARE_MODULE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
|
||||
#define HARDWARE_MODULE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr)
|
||||
|
||||
/*
|
||||
* Use this macro to set the hw_device_t.version field
|
||||
*/
|
||||
#define HARDWARE_DEVICE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
|
||||
#define HARDWARE_DEVICE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr)
|
||||
|
||||
struct hw_module_t;
|
||||
struct hw_module_methods_t;
|
||||
struct hw_device_t;
|
||||
|
||||
/**
|
||||
* Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
|
||||
* and the fields of this data structure must begin with hw_module_t
|
||||
* followed by module specific information.
|
||||
*/
|
||||
typedef struct hw_module_t {
|
||||
/** tag must be initialized to HARDWARE_MODULE_TAG */
|
||||
uint32_t tag;
|
||||
|
||||
/**
|
||||
* The API version of the implemented module. The module owner is
|
||||
* responsible for updating the version when a module interface has
|
||||
* changed.
|
||||
*
|
||||
* The derived modules such as gralloc and audio own and manage this field.
|
||||
* The module user must interpret the version field to decide whether or
|
||||
* not to inter-operate with the supplied module implementation.
|
||||
* For example, SurfaceFlinger is responsible for making sure that
|
||||
* it knows how to manage different versions of the gralloc-module API,
|
||||
* and AudioFlinger must know how to do the same for audio-module API.
|
||||
*
|
||||
* The module API version should include a major and a minor component.
|
||||
* For example, version 1.0 could be represented as 0x0100. This format
|
||||
* implies that versions 0x0100-0x01ff are all API-compatible.
|
||||
*
|
||||
* In the future, libhardware will expose a hw_get_module_version()
|
||||
* (or equivalent) function that will take minimum/maximum supported
|
||||
* versions as arguments and would be able to reject modules with
|
||||
* versions outside of the supplied range.
|
||||
*/
|
||||
uint16_t module_api_version;
|
||||
#define version_major module_api_version
|
||||
/**
|
||||
* version_major/version_minor defines are supplied here for temporary
|
||||
* source code compatibility. They will be removed in the next version.
|
||||
* ALL clients must convert to the new version format.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The API version of the HAL module interface. This is meant to
|
||||
* version the hw_module_t, hw_module_methods_t, and hw_device_t
|
||||
* structures and definitions.
|
||||
*
|
||||
* The HAL interface owns this field. Module users/implementations
|
||||
* must NOT rely on this value for version information.
|
||||
*
|
||||
* Presently, 0 is the only valid value.
|
||||
*/
|
||||
uint16_t hal_api_version;
|
||||
#define version_minor hal_api_version
|
||||
|
||||
/** Identifier of module */
|
||||
const char *id;
|
||||
|
||||
/** Name of this module */
|
||||
const char *name;
|
||||
|
||||
/** Author/owner/implementor of the module */
|
||||
const char *author;
|
||||
|
||||
/** Modules methods */
|
||||
struct hw_module_methods_t* methods;
|
||||
|
||||
/** module's dso */
|
||||
void* dso;
|
||||
|
||||
#ifdef __LP64__
|
||||
uint64_t reserved[32-7];
|
||||
#else
|
||||
/** padding to 128 bytes, reserved for future use */
|
||||
uint32_t reserved[32-7];
|
||||
#endif
|
||||
|
||||
} hw_module_t;
|
||||
|
||||
typedef struct hw_module_methods_t {
|
||||
/** Open a specific device */
|
||||
int (*open)(const struct hw_module_t* module, const char* id,
|
||||
struct hw_device_t** device);
|
||||
|
||||
} hw_module_methods_t;
|
||||
|
||||
/**
|
||||
* Every device data structure must begin with hw_device_t
|
||||
* followed by module specific public methods and attributes.
|
||||
*/
|
||||
typedef struct hw_device_t {
|
||||
/** tag must be initialized to HARDWARE_DEVICE_TAG */
|
||||
uint32_t tag;
|
||||
|
||||
/**
|
||||
* Version of the module-specific device API. This value is used by
|
||||
* the derived-module user to manage different device implementations.
|
||||
*
|
||||
* The module user is responsible for checking the module_api_version
|
||||
* and device version fields to ensure that the user is capable of
|
||||
* communicating with the specific module implementation.
|
||||
*
|
||||
* One module can support multiple devices with different versions. This
|
||||
* can be useful when a device interface changes in an incompatible way
|
||||
* but it is still necessary to support older implementations at the same
|
||||
* time. One such example is the Camera 2.0 API.
|
||||
*
|
||||
* This field is interpreted by the module user and is ignored by the
|
||||
* HAL interface itself.
|
||||
*/
|
||||
uint32_t version;
|
||||
|
||||
/** reference to the module this device belongs to */
|
||||
struct hw_module_t* module;
|
||||
|
||||
/** padding reserved for future use */
|
||||
#ifdef __LP64__
|
||||
uint64_t reserved[12];
|
||||
#else
|
||||
uint32_t reserved[12];
|
||||
#endif
|
||||
|
||||
/** Close this device */
|
||||
int (*close)(struct hw_device_t* device);
|
||||
|
||||
} hw_device_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define TO_HW_DEVICE_T_OPEN(x) reinterpret_cast<struct hw_device_t**>(x)
|
||||
#else
|
||||
#define TO_HW_DEVICE_T_OPEN(x) (struct hw_device_t**)(x)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Name of the hal_module_info
|
||||
*/
|
||||
#define HAL_MODULE_INFO_SYM HMI
|
||||
|
||||
/**
|
||||
* Name of the hal_module_info as a string
|
||||
*/
|
||||
#define HAL_MODULE_INFO_SYM_AS_STR "HMI"
|
||||
|
||||
/**
|
||||
* Get the module info associated with a module by id.
|
||||
*
|
||||
* @return: 0 == success, <0 == error and *module == NULL
|
||||
*/
|
||||
int hw_get_module(const char *id, const struct hw_module_t **module);
|
||||
|
||||
/**
|
||||
* Get the module info associated with a module instance by class 'class_id'
|
||||
* and instance 'inst'.
|
||||
*
|
||||
* Some modules types necessitate multiple instances. For example audio supports
|
||||
* multiple concurrent interfaces and thus 'audio' is the module class
|
||||
* and 'primary' or 'a2dp' are module interfaces. This implies that the files
|
||||
* providing these modules would be named audio.primary.<variant>.so and
|
||||
* audio.a2dp.<variant>.so
|
||||
*
|
||||
* @return: 0 == success, <0 == error and *module == NULL
|
||||
*/
|
||||
int hw_get_module_by_class(const char *class_id, const char *inst,
|
||||
const struct hw_module_t **module);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* ANDROID_INCLUDE_HARDWARE_HARDWARE_H */
|
||||
7
spider-cam/libcamera/include/android/meson.build
Normal file
7
spider-cam/libcamera/include/android/meson.build
Normal file
@@ -0,0 +1,7 @@
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
android_includes = ([
|
||||
include_directories('hardware/libhardware/include/'),
|
||||
include_directories('metadata/'),
|
||||
include_directories('system/core/include'),
|
||||
])
|
||||
@@ -0,0 +1,101 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
/*
|
||||
* Copyright 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SYSTEM_MEDIA_PRIVATE_INCLUDE_CAMERA_METADATA_HIDDEN_H
|
||||
#define SYSTEM_MEDIA_PRIVATE_INCLUDE_CAMERA_METADATA_HIDDEN_H
|
||||
|
||||
#include <system/camera_vendor_tags.h>
|
||||
|
||||
/**
|
||||
* Error codes returned by vendor tags ops operations. These are intended
|
||||
* to be used by all framework code that uses the return values from the
|
||||
* vendor operations object.
|
||||
*/
|
||||
#define VENDOR_SECTION_NAME_ERR NULL
|
||||
#define VENDOR_TAG_NAME_ERR NULL
|
||||
#define VENDOR_TAG_COUNT_ERR (-1)
|
||||
#define VENDOR_TAG_TYPE_ERR (-1)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/** **These are private functions for use only by the camera framework.** **/
|
||||
|
||||
/**
|
||||
* Set the global vendor tag operations object used to define vendor tag
|
||||
* structure when parsing camera metadata with functions defined in
|
||||
* system/media/camera/include/camera_metadata.h.
|
||||
*/
|
||||
ANDROID_API
|
||||
int set_camera_metadata_vendor_ops(const vendor_tag_ops_t *query_ops);
|
||||
|
||||
/**
|
||||
* Set the global vendor tag cache operations object used to define vendor tag
|
||||
* structure when parsing camera metadata with functions defined in
|
||||
* system/media/camera/include/camera_metadata.h.
|
||||
*/
|
||||
ANDROID_API
|
||||
int set_camera_metadata_vendor_cache_ops(
|
||||
const struct vendor_tag_cache_ops *query_cache_ops);
|
||||
|
||||
/**
|
||||
* Set the vendor id for a particular metadata buffer.
|
||||
*/
|
||||
ANDROID_API
|
||||
void set_camera_metadata_vendor_id(camera_metadata_t *meta,
|
||||
metadata_vendor_id_t id);
|
||||
|
||||
/**
|
||||
* Retrieve the vendor id for a particular metadata buffer.
|
||||
*/
|
||||
ANDROID_API
|
||||
metadata_vendor_id_t get_camera_metadata_vendor_id(
|
||||
const camera_metadata_t *meta);
|
||||
|
||||
/**
|
||||
* Retrieve the type of a tag. Returns -1 if no such tag is defined.
|
||||
*/
|
||||
ANDROID_API
|
||||
int get_local_camera_metadata_tag_type_vendor_id(uint32_t tag,
|
||||
metadata_vendor_id_t id);
|
||||
|
||||
/**
|
||||
* Retrieve the name of a tag. Returns NULL if no such tag is defined.
|
||||
*/
|
||||
ANDROID_API
|
||||
const char *get_local_camera_metadata_tag_name_vendor_id(uint32_t tag,
|
||||
metadata_vendor_id_t id);
|
||||
|
||||
/**
|
||||
* Retrieve the name of a tag section. Returns NULL if no such tag is defined.
|
||||
*/
|
||||
ANDROID_API
|
||||
const char *get_local_camera_metadata_section_name_vendor_id(uint32_t tag,
|
||||
metadata_vendor_id_t id);
|
||||
|
||||
/**
|
||||
* Retrieve the type of a tag. Returns -1 if no such tag is defined.
|
||||
*/
|
||||
ANDROID_API
|
||||
int get_local_camera_metadata_tag_type_vendor_id(uint32_t tag,
|
||||
metadata_vendor_id_t id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* SYSTEM_MEDIA_PRIVATE_INCLUDE_CAMERA_METADATA_HIDDEN_H */
|
||||
@@ -0,0 +1,581 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
/*
|
||||
* Copyright (C) 2012 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SYSTEM_MEDIA_INCLUDE_ANDROID_CAMERA_METADATA_H
|
||||
#define SYSTEM_MEDIA_INCLUDE_ANDROID_CAMERA_METADATA_H
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <cutils/compiler.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Tag hierarchy and enum definitions for camera_metadata_entry
|
||||
* =============================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* Main enum definitions are in a separate file to make it easy to
|
||||
* maintain
|
||||
*/
|
||||
#include "camera_metadata_tags.h"
|
||||
|
||||
/**
|
||||
* Enum range for each top-level category
|
||||
*/
|
||||
ANDROID_API
|
||||
extern unsigned int camera_metadata_section_bounds[ANDROID_SECTION_COUNT][2];
|
||||
ANDROID_API
|
||||
extern const char *camera_metadata_section_names[ANDROID_SECTION_COUNT];
|
||||
|
||||
/**
|
||||
* Type definitions for camera_metadata_entry
|
||||
* =============================================================================
|
||||
*/
|
||||
enum {
|
||||
// Unsigned 8-bit integer (uint8_t)
|
||||
TYPE_BYTE = 0,
|
||||
// Signed 32-bit integer (int32_t)
|
||||
TYPE_INT32 = 1,
|
||||
// 32-bit float (float)
|
||||
TYPE_FLOAT = 2,
|
||||
// Signed 64-bit integer (int64_t)
|
||||
TYPE_INT64 = 3,
|
||||
// 64-bit float (double)
|
||||
TYPE_DOUBLE = 4,
|
||||
// A 64-bit fraction (camera_metadata_rational_t)
|
||||
TYPE_RATIONAL = 5,
|
||||
// Number of type fields
|
||||
NUM_TYPES
|
||||
};
|
||||
|
||||
typedef struct camera_metadata_rational {
|
||||
int32_t numerator;
|
||||
int32_t denominator;
|
||||
} camera_metadata_rational_t;
|
||||
|
||||
/**
|
||||
* A reference to a metadata entry in a buffer.
|
||||
*
|
||||
* The data union pointers point to the real data in the buffer, and can be
|
||||
* modified in-place if the count does not need to change. The count is the
|
||||
* number of entries in data of the entry's type, not a count of bytes.
|
||||
*/
|
||||
typedef struct camera_metadata_entry {
|
||||
size_t index;
|
||||
uint32_t tag;
|
||||
uint8_t type;
|
||||
size_t count;
|
||||
union {
|
||||
uint8_t *u8;
|
||||
int32_t *i32;
|
||||
float *f;
|
||||
int64_t *i64;
|
||||
double *d;
|
||||
camera_metadata_rational_t *r;
|
||||
} data;
|
||||
} camera_metadata_entry_t;
|
||||
|
||||
/**
|
||||
* A read-only reference to a metadata entry in a buffer. Identical to
|
||||
* camera_metadata_entry in layout
|
||||
*/
|
||||
typedef struct camera_metadata_ro_entry {
|
||||
size_t index;
|
||||
uint32_t tag;
|
||||
uint8_t type;
|
||||
size_t count;
|
||||
union {
|
||||
const uint8_t *u8;
|
||||
const int32_t *i32;
|
||||
const float *f;
|
||||
const int64_t *i64;
|
||||
const double *d;
|
||||
const camera_metadata_rational_t *r;
|
||||
} data;
|
||||
} camera_metadata_ro_entry_t;
|
||||
|
||||
/**
|
||||
* Size in bytes of each entry type
|
||||
*/
|
||||
ANDROID_API
|
||||
extern const size_t camera_metadata_type_size[NUM_TYPES];
|
||||
|
||||
/**
|
||||
* Human-readable name of each entry type
|
||||
*/
|
||||
ANDROID_API
|
||||
extern const char* camera_metadata_type_names[NUM_TYPES];
|
||||
|
||||
/**
|
||||
* Main definitions for the metadata entry and array structures
|
||||
* =============================================================================
|
||||
*/
|
||||
|
||||
/**
|
||||
* A packet of metadata. This is a list of metadata entries, each of which has
|
||||
* an integer tag to identify its meaning, 'type' and 'count' field, and the
|
||||
* data, which contains a 'count' number of entries of type 'type'. The packet
|
||||
* has a fixed capacity for entries and for extra data. A new entry uses up one
|
||||
* entry slot, and possibly some amount of data capacity; the function
|
||||
* calculate_camera_metadata_entry_data_size() provides the amount of data
|
||||
* capacity that would be used up by an entry.
|
||||
*
|
||||
* Entries are not sorted by default, and are not forced to be unique - multiple
|
||||
* entries with the same tag are allowed. The packet will not dynamically resize
|
||||
* when full.
|
||||
*
|
||||
* The packet is contiguous in memory, with size in bytes given by
|
||||
* get_camera_metadata_size(). Therefore, it can be copied safely with memcpy()
|
||||
* to a buffer of sufficient size. The copy_camera_metadata() function is
|
||||
* intended for eliminating unused capacity in the destination packet.
|
||||
*/
|
||||
struct camera_metadata;
|
||||
typedef struct camera_metadata camera_metadata_t;
|
||||
|
||||
/**
|
||||
* Functions for manipulating camera metadata
|
||||
* =============================================================================
|
||||
*
|
||||
* NOTE: Unless otherwise specified, functions that return type "int"
|
||||
* return 0 on success, and non-0 value on error.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allocate a new camera_metadata structure, with some initial space for entries
|
||||
* and extra data. The entry_capacity is measured in entry counts, and
|
||||
* data_capacity in bytes. The resulting structure is all contiguous in memory,
|
||||
* and can be freed with free_camera_metadata().
|
||||
*/
|
||||
ANDROID_API
|
||||
camera_metadata_t *allocate_camera_metadata(size_t entry_capacity,
|
||||
size_t data_capacity);
|
||||
|
||||
/**
|
||||
* Get the required alignment of a packet of camera metadata, which is the
|
||||
* maximal alignment of the embedded camera_metadata, camera_metadata_buffer_entry,
|
||||
* and camera_metadata_data.
|
||||
*/
|
||||
ANDROID_API
|
||||
size_t get_camera_metadata_alignment();
|
||||
|
||||
/**
|
||||
* Allocate a new camera_metadata structure of size src_size. Copy the data,
|
||||
* ignoring alignment, and then attempt validation. If validation
|
||||
* fails, free the memory and return NULL. Otherwise return the pointer.
|
||||
*
|
||||
* The resulting pointer can be freed with free_camera_metadata().
|
||||
*/
|
||||
ANDROID_API
|
||||
camera_metadata_t *allocate_copy_camera_metadata_checked(
|
||||
const camera_metadata_t *src,
|
||||
size_t src_size);
|
||||
|
||||
/**
|
||||
* Place a camera metadata structure into an existing buffer. Returns NULL if
|
||||
* the buffer is too small for the requested number of reserved entries and
|
||||
* bytes of data. The entry_capacity is measured in entry counts, and
|
||||
* data_capacity in bytes. If the buffer is larger than the required space,
|
||||
* unused space will be left at the end. If successful, returns a pointer to the
|
||||
* metadata header placed at the start of the buffer. It is the caller's
|
||||
* responsibility to free the original buffer; do not call
|
||||
* free_camera_metadata() with the returned pointer.
|
||||
*/
|
||||
ANDROID_API
|
||||
camera_metadata_t *place_camera_metadata(void *dst, size_t dst_size,
|
||||
size_t entry_capacity,
|
||||
size_t data_capacity);
|
||||
|
||||
/**
|
||||
* Free a camera_metadata structure. Should only be used with structures
|
||||
* allocated with allocate_camera_metadata().
|
||||
*/
|
||||
ANDROID_API
|
||||
void free_camera_metadata(camera_metadata_t *metadata);
|
||||
|
||||
/**
|
||||
* Calculate the buffer size needed for a metadata structure of entry_count
|
||||
* metadata entries, needing a total of data_count bytes of extra data storage.
|
||||
*/
|
||||
ANDROID_API
|
||||
size_t calculate_camera_metadata_size(size_t entry_count,
|
||||
size_t data_count);
|
||||
|
||||
/**
|
||||
* Get current size of entire metadata structure in bytes, including reserved
|
||||
* but unused space.
|
||||
*/
|
||||
ANDROID_API
|
||||
size_t get_camera_metadata_size(const camera_metadata_t *metadata);
|
||||
|
||||
/**
|
||||
* Get size of entire metadata buffer in bytes, not including reserved but
|
||||
* unused space. This is the amount of space needed by copy_camera_metadata for
|
||||
* its dst buffer.
|
||||
*/
|
||||
ANDROID_API
|
||||
size_t get_camera_metadata_compact_size(const camera_metadata_t *metadata);
|
||||
|
||||
/**
|
||||
* Get the current number of entries in the metadata packet.
|
||||
*
|
||||
* metadata packet must be valid, which can be checked before the call with
|
||||
* validate_camera_metadata_structure().
|
||||
*/
|
||||
ANDROID_API
|
||||
size_t get_camera_metadata_entry_count(const camera_metadata_t *metadata);
|
||||
|
||||
/**
|
||||
* Get the maximum number of entries that could fit in the metadata packet.
|
||||
*/
|
||||
ANDROID_API
|
||||
size_t get_camera_metadata_entry_capacity(const camera_metadata_t *metadata);
|
||||
|
||||
/**
|
||||
* Get the current count of bytes used for value storage in the metadata packet.
|
||||
*/
|
||||
ANDROID_API
|
||||
size_t get_camera_metadata_data_count(const camera_metadata_t *metadata);
|
||||
|
||||
/**
|
||||
* Get the maximum count of bytes that could be used for value storage in the
|
||||
* metadata packet.
|
||||
*/
|
||||
ANDROID_API
|
||||
size_t get_camera_metadata_data_capacity(const camera_metadata_t *metadata);
|
||||
|
||||
/**
|
||||
* Copy a metadata structure to a memory buffer, compacting it along the
|
||||
* way. That is, in the copied structure, entry_count == entry_capacity, and
|
||||
* data_count == data_capacity.
|
||||
*
|
||||
* If dst_size > get_camera_metadata_compact_size(), the unused bytes are at the
|
||||
* end of the buffer. If dst_size < get_camera_metadata_compact_size(), returns
|
||||
* NULL. Otherwise returns a pointer to the metadata structure header placed at
|
||||
* the start of dst.
|
||||
*
|
||||
* Since the buffer was not allocated by allocate_camera_metadata, the caller is
|
||||
* responsible for freeing the underlying buffer when needed; do not call
|
||||
* free_camera_metadata.
|
||||
*/
|
||||
ANDROID_API
|
||||
camera_metadata_t *copy_camera_metadata(void *dst, size_t dst_size,
|
||||
const camera_metadata_t *src);
|
||||
|
||||
|
||||
// Non-zero return values for validate_camera_metadata_structure
|
||||
enum {
|
||||
CAMERA_METADATA_VALIDATION_ERROR = 1,
|
||||
CAMERA_METADATA_VALIDATION_SHIFTED = 2,
|
||||
};
|
||||
|
||||
/**
|
||||
* Validate that a metadata is structurally sane. That is, its internal
|
||||
* state is such that we won't get buffer overflows or run into other
|
||||
* 'impossible' issues when calling the other API functions.
|
||||
*
|
||||
* This is useful in particular after copying the binary metadata blob
|
||||
* from an untrusted source, since passing this check means the data is at least
|
||||
* consistent.
|
||||
*
|
||||
* The expected_size argument is optional.
|
||||
*
|
||||
* Returns 0: on success
|
||||
* CAMERA_METADATA_VALIDATION_ERROR: on error
|
||||
* CAMERA_METADATA_VALIDATION_SHIFTED: when the data is not properly aligned, but can be
|
||||
* used as input of clone_camera_metadata and the returned metadata will be valid.
|
||||
*
|
||||
*/
|
||||
ANDROID_API
|
||||
int validate_camera_metadata_structure(const camera_metadata_t *metadata,
|
||||
const size_t *expected_size);
|
||||
|
||||
/**
|
||||
* Append camera metadata in src to an existing metadata structure in dst. This
|
||||
* does not resize the destination structure, so if it is too small, a non-zero
|
||||
* value is returned. On success, 0 is returned. Appending onto a sorted
|
||||
* structure results in a non-sorted combined structure.
|
||||
*/
|
||||
ANDROID_API
|
||||
int append_camera_metadata(camera_metadata_t *dst, const camera_metadata_t *src);
|
||||
|
||||
/**
|
||||
* Clone an existing metadata buffer, compacting along the way. This is
|
||||
* equivalent to allocating a new buffer of the minimum needed size, then
|
||||
* appending the buffer to be cloned into the new buffer. The resulting buffer
|
||||
* can be freed with free_camera_metadata(). Returns NULL if cloning failed.
|
||||
*/
|
||||
ANDROID_API
|
||||
camera_metadata_t *clone_camera_metadata(const camera_metadata_t *src);
|
||||
|
||||
/**
|
||||
* Calculate the number of bytes of extra data a given metadata entry will take
|
||||
* up. That is, if entry of 'type' with a payload of 'data_count' values is
|
||||
* added, how much will the value returned by get_camera_metadata_data_count()
|
||||
* be increased? This value may be zero, if no extra data storage is needed.
|
||||
*/
|
||||
ANDROID_API
|
||||
size_t calculate_camera_metadata_entry_data_size(uint8_t type,
|
||||
size_t data_count);
|
||||
|
||||
/**
|
||||
* Add a metadata entry to a metadata structure. Returns 0 if the addition
|
||||
* succeeded. Returns a non-zero value if there is insufficient reserved space
|
||||
* left to add the entry, or if the tag is unknown. data_count is the number of
|
||||
* entries in the data array of the tag's type, not a count of
|
||||
* bytes. Vendor-defined tags can not be added using this method, unless
|
||||
* set_vendor_tag_query_ops() has been called first. Entries are always added to
|
||||
* the end of the structure (highest index), so after addition, a
|
||||
* previously-sorted array will be marked as unsorted.
|
||||
*
|
||||
* Returns 0 on success. A non-0 value is returned on error.
|
||||
*/
|
||||
ANDROID_API
|
||||
int add_camera_metadata_entry(camera_metadata_t *dst,
|
||||
uint32_t tag,
|
||||
const void *data,
|
||||
size_t data_count);
|
||||
|
||||
/**
|
||||
* Sort the metadata buffer for fast searching. If already marked as sorted,
|
||||
* does nothing. Adding or appending entries to the buffer will place the buffer
|
||||
* back into an unsorted state.
|
||||
*
|
||||
* Returns 0 on success. A non-0 value is returned on error.
|
||||
*/
|
||||
ANDROID_API
|
||||
int sort_camera_metadata(camera_metadata_t *dst);
|
||||
|
||||
/**
|
||||
* Get metadata entry at position index in the metadata buffer.
|
||||
* Index must be less than entry count, which is returned by
|
||||
* get_camera_metadata_entry_count().
|
||||
*
|
||||
* src and index are inputs; the passed-in entry is updated with the details of
|
||||
* the entry. The data pointer points to the real data in the buffer, and can be
|
||||
* updated as long as the data count does not change.
|
||||
*
|
||||
* Returns 0 on success. A non-0 value is returned on error.
|
||||
*/
|
||||
ANDROID_API
|
||||
int get_camera_metadata_entry(camera_metadata_t *src,
|
||||
size_t index,
|
||||
camera_metadata_entry_t *entry);
|
||||
|
||||
/**
|
||||
* Get metadata entry at position index, but disallow editing the data.
|
||||
*/
|
||||
ANDROID_API
|
||||
int get_camera_metadata_ro_entry(const camera_metadata_t *src,
|
||||
size_t index,
|
||||
camera_metadata_ro_entry_t *entry);
|
||||
|
||||
/**
|
||||
* Find an entry with given tag value. If not found, returns -ENOENT. Otherwise,
|
||||
* returns entry contents like get_camera_metadata_entry.
|
||||
*
|
||||
* If multiple entries with the same tag exist, does not have any guarantees on
|
||||
* which is returned. To speed up searching for tags, sort the metadata
|
||||
* structure first by calling sort_camera_metadata().
|
||||
*/
|
||||
ANDROID_API
|
||||
int find_camera_metadata_entry(camera_metadata_t *src,
|
||||
uint32_t tag,
|
||||
camera_metadata_entry_t *entry);
|
||||
|
||||
/**
|
||||
* Find an entry with given tag value, but disallow editing the data
|
||||
*/
|
||||
ANDROID_API
|
||||
int find_camera_metadata_ro_entry(const camera_metadata_t *src,
|
||||
uint32_t tag,
|
||||
camera_metadata_ro_entry_t *entry);
|
||||
|
||||
/**
|
||||
* Delete an entry at given index. This is an expensive operation, since it
|
||||
* requires repacking entries and possibly entry data. This also invalidates any
|
||||
* existing camera_metadata_entry.data pointers to this buffer. Sorting is
|
||||
* maintained.
|
||||
*/
|
||||
ANDROID_API
|
||||
int delete_camera_metadata_entry(camera_metadata_t *dst,
|
||||
size_t index);
|
||||
|
||||
/**
|
||||
* Updates a metadata entry with new data. If the data size is changing, may
|
||||
* need to adjust the data array, making this an O(N) operation. If the data
|
||||
* size is the same or still fits in the entry space, this is O(1). Maintains
|
||||
* sorting, but invalidates camera_metadata_entry instances that point to the
|
||||
* updated entry. If a non-NULL value is passed in to entry, the entry structure
|
||||
* is updated to match the new buffer state. Returns a non-zero value if there
|
||||
* is no room for the new data in the buffer.
|
||||
*/
|
||||
ANDROID_API
|
||||
int update_camera_metadata_entry(camera_metadata_t *dst,
|
||||
size_t index,
|
||||
const void *data,
|
||||
size_t data_count,
|
||||
camera_metadata_entry_t *updated_entry);
|
||||
|
||||
/**
|
||||
* Retrieve human-readable name of section the tag is in. Returns NULL if
|
||||
* no such tag is defined. Returns NULL for tags in the vendor section, unless
|
||||
* set_vendor_tag_query_ops() has been used.
|
||||
*/
|
||||
ANDROID_API
|
||||
const char *get_camera_metadata_section_name(uint32_t tag);
|
||||
|
||||
/**
|
||||
* Retrieve human-readable name of tag (not including section). Returns NULL if
|
||||
* no such tag is defined. Returns NULL for tags in the vendor section, unless
|
||||
* set_vendor_tag_query_ops() has been used.
|
||||
*/
|
||||
ANDROID_API
|
||||
const char *get_camera_metadata_tag_name(uint32_t tag);
|
||||
|
||||
/**
|
||||
* Retrieve the type of a tag. Returns -1 if no such tag is defined. Returns -1
|
||||
* for tags in the vendor section, unless set_vendor_tag_query_ops() has been
|
||||
* used.
|
||||
*/
|
||||
ANDROID_API
|
||||
int get_camera_metadata_tag_type(uint32_t tag);
|
||||
|
||||
/**
|
||||
* Retrieve human-readable name of section the tag is in. Returns NULL if
|
||||
* no such tag is defined.
|
||||
*/
|
||||
ANDROID_API
|
||||
const char *get_local_camera_metadata_section_name(uint32_t tag,
|
||||
const camera_metadata_t *meta);
|
||||
|
||||
/**
|
||||
* Retrieve human-readable name of tag (not including section). Returns NULL if
|
||||
* no such tag is defined.
|
||||
*/
|
||||
ANDROID_API
|
||||
const char *get_local_camera_metadata_tag_name(uint32_t tag,
|
||||
const camera_metadata_t *meta);
|
||||
|
||||
/**
|
||||
* Retrieve the type of a tag. Returns -1 if no such tag is defined.
|
||||
*/
|
||||
ANDROID_API
|
||||
int get_local_camera_metadata_tag_type(uint32_t tag,
|
||||
const camera_metadata_t *meta);
|
||||
|
||||
/**
|
||||
* Set up vendor-specific tag query methods. These are needed to properly add
|
||||
* entries with vendor-specified tags and to use the
|
||||
* get_camera_metadata_section_name, _tag_name, and _tag_type methods with
|
||||
* vendor tags. Returns 0 on success.
|
||||
*
|
||||
* **DEPRECATED** - Please use vendor_tag_ops defined in camera_vendor_tags.h
|
||||
* instead.
|
||||
*/
|
||||
typedef struct vendor_tag_query_ops vendor_tag_query_ops_t;
|
||||
struct vendor_tag_query_ops {
|
||||
/**
|
||||
* Get vendor section name for a vendor-specified entry tag. Only called for
|
||||
* tags >= 0x80000000. The section name must start with the name of the
|
||||
* vendor in the Java package style. For example, CameraZoom inc must prefix
|
||||
* their sections with "com.camerazoom." Must return NULL if the tag is
|
||||
* outside the bounds of vendor-defined sections.
|
||||
*/
|
||||
const char *(*get_camera_vendor_section_name)(
|
||||
const vendor_tag_query_ops_t *v,
|
||||
uint32_t tag);
|
||||
/**
|
||||
* Get tag name for a vendor-specified entry tag. Only called for tags >=
|
||||
* 0x80000000. Must return NULL if the tag is outside the bounds of
|
||||
* vendor-defined sections.
|
||||
*/
|
||||
const char *(*get_camera_vendor_tag_name)(
|
||||
const vendor_tag_query_ops_t *v,
|
||||
uint32_t tag);
|
||||
/**
|
||||
* Get tag type for a vendor-specified entry tag. Only called for tags >=
|
||||
* 0x80000000. Must return -1 if the tag is outside the bounds of
|
||||
* vendor-defined sections.
|
||||
*/
|
||||
int (*get_camera_vendor_tag_type)(
|
||||
const vendor_tag_query_ops_t *v,
|
||||
uint32_t tag);
|
||||
/**
|
||||
* Get the number of vendor tags supported on this platform. Used to
|
||||
* calculate the size of buffer needed for holding the array of all tags
|
||||
* returned by get_camera_vendor_tags().
|
||||
*/
|
||||
int (*get_camera_vendor_tag_count)(
|
||||
const vendor_tag_query_ops_t *v);
|
||||
/**
|
||||
* Fill an array with all the supported vendor tags on this platform.
|
||||
* get_camera_vendor_tag_count() returns the number of tags supported, and
|
||||
* tag_array should be allocated with enough space to hold all of the tags.
|
||||
*/
|
||||
void (*get_camera_vendor_tags)(
|
||||
const vendor_tag_query_ops_t *v,
|
||||
uint32_t *tag_array);
|
||||
};
|
||||
|
||||
/**
|
||||
* **DEPRECATED** - This should only be used by the camera framework. Camera
|
||||
* metadata will transition to using vendor_tag_ops defined in
|
||||
* camera_vendor_tags.h instead.
|
||||
*/
|
||||
ANDROID_API
|
||||
int set_camera_metadata_vendor_tag_ops(const vendor_tag_query_ops_t *query_ops);
|
||||
|
||||
/**
|
||||
* Print fields in the metadata to the log.
|
||||
* verbosity = 0: Only tag entry information
|
||||
* verbosity = 1: Tag entry information plus at most 16 data values
|
||||
* verbosity = 2: All information
|
||||
*/
|
||||
ANDROID_API
|
||||
void dump_camera_metadata(const camera_metadata_t *metadata,
|
||||
int fd,
|
||||
int verbosity);
|
||||
|
||||
/**
|
||||
* Print fields in the metadata to the log; adds indentation parameter, which
|
||||
* specifies the number of spaces to insert before each line of the dump
|
||||
*/
|
||||
ANDROID_API
|
||||
void dump_indented_camera_metadata(const camera_metadata_t *metadata,
|
||||
int fd,
|
||||
int verbosity,
|
||||
int indentation);
|
||||
|
||||
/**
|
||||
* Prints the specified tag value as a string. Only works for enum tags.
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
ANDROID_API
|
||||
int camera_metadata_enum_snprint(uint32_t tag,
|
||||
uint32_t value,
|
||||
char *dst,
|
||||
size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,159 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
/*
|
||||
* Copyright 2014 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SYSTEM_MEDIA_INCLUDE_ANDROID_CAMERA_VENDOR_TAGS_H
|
||||
#define SYSTEM_MEDIA_INCLUDE_ANDROID_CAMERA_VENDOR_TAGS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CAMERA_METADATA_VENDOR_TAG_BOUNDARY 0x80000000u
|
||||
#define CAMERA_METADATA_INVALID_VENDOR_ID UINT64_MAX
|
||||
|
||||
typedef uint64_t metadata_vendor_id_t;
|
||||
|
||||
/**
|
||||
* Vendor tags:
|
||||
*
|
||||
* This structure contains basic functions for enumerating an immutable set of
|
||||
* vendor-defined camera metadata tags, and querying static information about
|
||||
* their structure/type. The intended use of this information is to validate
|
||||
* the structure of metadata returned by the camera HAL, and to allow vendor-
|
||||
* defined metadata tags to be visible in application facing camera API.
|
||||
*/
|
||||
typedef struct vendor_tag_ops vendor_tag_ops_t;
|
||||
struct vendor_tag_ops {
|
||||
/**
|
||||
* Get the number of vendor tags supported on this platform. Used to
|
||||
* calculate the size of buffer needed for holding the array of all tags
|
||||
* returned by get_all_tags(). This must return -1 on error.
|
||||
*/
|
||||
int (*get_tag_count)(const vendor_tag_ops_t *v);
|
||||
|
||||
/**
|
||||
* Fill an array with all of the supported vendor tags on this platform.
|
||||
* get_tag_count() must return the number of tags supported, and
|
||||
* tag_array will be allocated with enough space to hold the number of tags
|
||||
* returned by get_tag_count().
|
||||
*/
|
||||
void (*get_all_tags)(const vendor_tag_ops_t *v, uint32_t *tag_array);
|
||||
|
||||
/**
|
||||
* Get the vendor section name for a vendor-specified entry tag. This will
|
||||
* only be called for vendor-defined tags.
|
||||
*
|
||||
* The naming convention for the vendor-specific section names should
|
||||
* follow a style similar to the Java package style. For example,
|
||||
* CameraZoom Inc. must prefix their sections with "com.camerazoom."
|
||||
* This must return NULL if the tag is outside the bounds of
|
||||
* vendor-defined sections.
|
||||
*
|
||||
* There may be different vendor-defined tag sections, for example the
|
||||
* phone maker, the chipset maker, and the camera module maker may each
|
||||
* have their own "com.vendor."-prefixed section.
|
||||
*
|
||||
* The memory pointed to by the return value must remain valid for the
|
||||
* lifetime of the module, and is owned by the module.
|
||||
*/
|
||||
const char *(*get_section_name)(const vendor_tag_ops_t *v, uint32_t tag);
|
||||
|
||||
/**
|
||||
* Get the tag name for a vendor-specified entry tag. This is only called
|
||||
* for vendor-defined tags, and must return NULL if it is not a
|
||||
* vendor-defined tag.
|
||||
*
|
||||
* The memory pointed to by the return value must remain valid for the
|
||||
* lifetime of the module, and is owned by the module.
|
||||
*/
|
||||
const char *(*get_tag_name)(const vendor_tag_ops_t *v, uint32_t tag);
|
||||
|
||||
/**
|
||||
* Get tag type for a vendor-specified entry tag. The type returned must be
|
||||
* a valid type defined in camera_metadata.h. This method is only called
|
||||
* for tags >= CAMERA_METADATA_VENDOR_TAG_BOUNDARY, and must return
|
||||
* -1 if the tag is outside the bounds of the vendor-defined sections.
|
||||
*/
|
||||
int (*get_tag_type)(const vendor_tag_ops_t *v, uint32_t tag);
|
||||
|
||||
/* Reserved for future use. These must be initialized to NULL. */
|
||||
void* reserved[8];
|
||||
};
|
||||
|
||||
struct vendor_tag_cache_ops {
|
||||
/**
|
||||
* Get the number of vendor tags supported on this platform. Used to
|
||||
* calculate the size of buffer needed for holding the array of all tags
|
||||
* returned by get_all_tags(). This must return -1 on error.
|
||||
*/
|
||||
int (*get_tag_count)(metadata_vendor_id_t id);
|
||||
|
||||
/**
|
||||
* Fill an array with all of the supported vendor tags on this platform.
|
||||
* get_tag_count() must return the number of tags supported, and
|
||||
* tag_array will be allocated with enough space to hold the number of tags
|
||||
* returned by get_tag_count().
|
||||
*/
|
||||
void (*get_all_tags)(uint32_t *tag_array, metadata_vendor_id_t id);
|
||||
|
||||
/**
|
||||
* Get the vendor section name for a vendor-specified entry tag. This will
|
||||
* only be called for vendor-defined tags.
|
||||
*
|
||||
* The naming convention for the vendor-specific section names should
|
||||
* follow a style similar to the Java package style. For example,
|
||||
* CameraZoom Inc. must prefix their sections with "com.camerazoom."
|
||||
* This must return NULL if the tag is outside the bounds of
|
||||
* vendor-defined sections.
|
||||
*
|
||||
* There may be different vendor-defined tag sections, for example the
|
||||
* phone maker, the chipset maker, and the camera module maker may each
|
||||
* have their own "com.vendor."-prefixed section.
|
||||
*
|
||||
* The memory pointed to by the return value must remain valid for the
|
||||
* lifetime of the module, and is owned by the module.
|
||||
*/
|
||||
const char *(*get_section_name)(uint32_t tag, metadata_vendor_id_t id);
|
||||
|
||||
/**
|
||||
* Get the tag name for a vendor-specified entry tag. This is only called
|
||||
* for vendor-defined tags, and must return NULL if it is not a
|
||||
* vendor-defined tag.
|
||||
*
|
||||
* The memory pointed to by the return value must remain valid for the
|
||||
* lifetime of the module, and is owned by the module.
|
||||
*/
|
||||
const char *(*get_tag_name)(uint32_t tag, metadata_vendor_id_t id);
|
||||
|
||||
/**
|
||||
* Get tag type for a vendor-specified entry tag. The type returned must be
|
||||
* a valid type defined in camera_metadata.h. This method is only called
|
||||
* for tags >= CAMERA_METADATA_VENDOR_TAG_BOUNDARY, and must return
|
||||
* -1 if the tag is outside the bounds of the vendor-defined sections.
|
||||
*/
|
||||
int (*get_tag_type)(uint32_t tag, metadata_vendor_id_t id);
|
||||
|
||||
/* Reserved for future use. These must be initialized to NULL. */
|
||||
void* reserved[8];
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* SYSTEM_MEDIA_INCLUDE_ANDROID_CAMERA_VENDOR_TAGS_H */
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _ANDROID_LOG_H
|
||||
#define _ANDROID_LOG_H
|
||||
|
||||
/******************************************************************
|
||||
*
|
||||
* IMPORTANT NOTICE:
|
||||
*
|
||||
* This file is part of Android's set of stable system headers
|
||||
* exposed by the Android NDK (Native Development Kit) since
|
||||
* platform release 1.5
|
||||
*
|
||||
* Third-party source AND binary code relies on the definitions
|
||||
* here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES.
|
||||
*
|
||||
* - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES)
|
||||
* - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS
|
||||
* - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY
|
||||
* - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES
|
||||
*/
|
||||
|
||||
/*
|
||||
* Support routines to send messages to the Android in-kernel log buffer,
|
||||
* which can later be accessed through the 'logcat' utility.
|
||||
*
|
||||
* Each log message must have
|
||||
* - a priority
|
||||
* - a log tag
|
||||
* - some text
|
||||
*
|
||||
* The tag normally corresponds to the component that emits the log message,
|
||||
* and should be reasonably small.
|
||||
*
|
||||
* Log message text may be truncated to less than an implementation-specific
|
||||
* limit (e.g. 1023 characters max).
|
||||
*
|
||||
* Note that a newline character ("\n") will be appended automatically to your
|
||||
* log message, if not already there. It is not possible to send several messages
|
||||
* and have them appear on a single line in logcat.
|
||||
*
|
||||
* PLEASE USE LOGS WITH MODERATION:
|
||||
*
|
||||
* - Sending log messages eats CPU and slow down your application and the
|
||||
* system.
|
||||
*
|
||||
* - The circular log buffer is pretty small (<64KB), sending many messages
|
||||
* might push off other important log messages from the rest of the system.
|
||||
*
|
||||
* - In release builds, only send log messages to account for exceptional
|
||||
* conditions.
|
||||
*
|
||||
* NOTE: These functions MUST be implemented by /system/lib/liblog.so
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Android log priority values, in ascending priority order.
|
||||
*/
|
||||
typedef enum android_LogPriority {
|
||||
ANDROID_LOG_UNKNOWN = 0,
|
||||
ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */
|
||||
ANDROID_LOG_VERBOSE,
|
||||
ANDROID_LOG_DEBUG,
|
||||
ANDROID_LOG_INFO,
|
||||
ANDROID_LOG_WARN,
|
||||
ANDROID_LOG_ERROR,
|
||||
ANDROID_LOG_FATAL,
|
||||
ANDROID_LOG_SILENT, /* only for SetMinPriority(); must be last */
|
||||
} android_LogPriority;
|
||||
|
||||
/*
|
||||
* Send a simple string to the log.
|
||||
*/
|
||||
int __android_log_write(int prio, const char *tag, const char *text);
|
||||
|
||||
/*
|
||||
* Send a formatted string to the log, used like printf(fmt,...)
|
||||
*/
|
||||
int __android_log_print(int prio, const char *tag, const char *fmt, ...)
|
||||
#if defined(__GNUC__)
|
||||
#ifdef __USE_MINGW_ANSI_STDIO
|
||||
#if __USE_MINGW_ANSI_STDIO
|
||||
__attribute__ ((format(gnu_printf, 3, 4)))
|
||||
#else
|
||||
__attribute__ ((format(printf, 3, 4)))
|
||||
#endif
|
||||
#else
|
||||
__attribute__ ((format(printf, 3, 4)))
|
||||
#endif
|
||||
#endif
|
||||
;
|
||||
|
||||
/*
|
||||
* A variant of __android_log_print() that takes a va_list to list
|
||||
* additional parameters.
|
||||
*/
|
||||
int __android_log_vprint(int prio, const char *tag,
|
||||
const char *fmt, va_list ap);
|
||||
|
||||
/*
|
||||
* Log an assertion failure and abort the process to have a chance
|
||||
* to inspect it if a debugger is attached. This uses the FATAL priority.
|
||||
*/
|
||||
void __android_log_assert(const char *cond, const char *tag,
|
||||
const char *fmt, ...)
|
||||
#if defined(__GNUC__)
|
||||
__attribute__ ((noreturn))
|
||||
#ifdef __USE_MINGW_ANSI_STDIO
|
||||
#if __USE_MINGW_ANSI_STDIO
|
||||
__attribute__ ((format(gnu_printf, 3, 4)))
|
||||
#else
|
||||
__attribute__ ((format(printf, 3, 4)))
|
||||
#endif
|
||||
#else
|
||||
__attribute__ ((format(printf, 3, 4)))
|
||||
#endif
|
||||
#endif
|
||||
;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ANDROID_LOG_H */
|
||||
@@ -0,0 +1,45 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_CUTILS_COMPILER_H
|
||||
#define ANDROID_CUTILS_COMPILER_H
|
||||
|
||||
/*
|
||||
* helps the compiler's optimizer predicting branches
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
# define CC_LIKELY( exp ) (__builtin_expect( !!(exp), true ))
|
||||
# define CC_UNLIKELY( exp ) (__builtin_expect( !!(exp), false ))
|
||||
#else
|
||||
# define CC_LIKELY( exp ) (__builtin_expect( !!(exp), 1 ))
|
||||
# define CC_UNLIKELY( exp ) (__builtin_expect( !!(exp), 0 ))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* exports marked symbols
|
||||
*
|
||||
* if used on a C++ class declaration, this macro must be inserted
|
||||
* after the "class" keyword. For instance:
|
||||
*
|
||||
* template <typename TYPE>
|
||||
* class ANDROID_API Singleton { }
|
||||
*/
|
||||
|
||||
#define ANDROID_API __attribute__((visibility("default")))
|
||||
|
||||
#endif // ANDROID_CUTILS_COMPILER_H
|
||||
@@ -0,0 +1,106 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef NATIVE_HANDLE_H_
|
||||
#define NATIVE_HANDLE_H_
|
||||
|
||||
#include <stdalign.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define NATIVE_HANDLE_MAX_FDS 1024
|
||||
#define NATIVE_HANDLE_MAX_INTS 1024
|
||||
|
||||
/* Declare a char array for use with native_handle_init */
|
||||
#define NATIVE_HANDLE_DECLARE_STORAGE(name, maxFds, maxInts) \
|
||||
alignas(native_handle_t) char (name)[ \
|
||||
sizeof(native_handle_t) + sizeof(int) * ((maxFds) + (maxInts))]
|
||||
|
||||
typedef struct native_handle
|
||||
{
|
||||
int version; /* sizeof(native_handle_t) */
|
||||
int numFds; /* number of file-descriptors at &data[0] */
|
||||
int numInts; /* number of ints at &data[numFds] */
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wzero-length-array"
|
||||
#endif
|
||||
int data[0]; /* numFds + numInts ints */
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
} native_handle_t;
|
||||
|
||||
typedef const native_handle_t* buffer_handle_t;
|
||||
|
||||
/*
|
||||
* native_handle_close
|
||||
*
|
||||
* closes the file descriptors contained in this native_handle_t
|
||||
*
|
||||
* return 0 on success, or a negative error code on failure
|
||||
*
|
||||
*/
|
||||
int native_handle_close(const native_handle_t* h);
|
||||
|
||||
/*
|
||||
* native_handle_init
|
||||
*
|
||||
* Initializes a native_handle_t from storage. storage must be declared with
|
||||
* NATIVE_HANDLE_DECLARE_STORAGE. numFds and numInts must not respectively
|
||||
* exceed maxFds and maxInts used to declare the storage.
|
||||
*/
|
||||
native_handle_t* native_handle_init(char* storage, int numFds, int numInts);
|
||||
|
||||
/*
|
||||
* native_handle_create
|
||||
*
|
||||
* creates a native_handle_t and initializes it. must be destroyed with
|
||||
* native_handle_delete().
|
||||
*
|
||||
*/
|
||||
native_handle_t* native_handle_create(int numFds, int numInts);
|
||||
|
||||
/*
|
||||
* native_handle_clone
|
||||
*
|
||||
* creates a native_handle_t and initializes it from another native_handle_t.
|
||||
* Must be destroyed with native_handle_delete().
|
||||
*
|
||||
*/
|
||||
native_handle_t* native_handle_clone(const native_handle_t* handle);
|
||||
|
||||
/*
|
||||
* native_handle_delete
|
||||
*
|
||||
* frees a native_handle_t allocated with native_handle_create().
|
||||
* This ONLY frees the memory allocated for the native_handle_t, but doesn't
|
||||
* close the file descriptors; which can be achieved with native_handle_close().
|
||||
*
|
||||
* return 0 on success, or a negative error code on failure
|
||||
*
|
||||
*/
|
||||
int native_handle_delete(native_handle_t* h);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* NATIVE_HANDLE_H_ */
|
||||
@@ -0,0 +1,308 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SYSTEM_CORE_INCLUDE_ANDROID_CAMERA_H
|
||||
#define SYSTEM_CORE_INCLUDE_ANDROID_CAMERA_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
#include <cutils/native_handle.h>
|
||||
#include <hardware/hardware.h>
|
||||
#include <hardware/gralloc.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* A set of bit masks for specifying how the received preview frames are
|
||||
* handled before the previewCallback() call.
|
||||
*
|
||||
* The least significant 3 bits of an "int" value are used for this purpose:
|
||||
*
|
||||
* ..... 0 0 0
|
||||
* ^ ^ ^
|
||||
* | | |---------> determine whether the callback is enabled or not
|
||||
* | |-----------> determine whether the callback is one-shot or not
|
||||
* |-------------> determine whether the frame is copied out or not
|
||||
*
|
||||
* WARNING: When a frame is sent directly without copying, it is the frame
|
||||
* receiver's responsiblity to make sure that the frame data won't get
|
||||
* corrupted by subsequent preview frames filled by the camera. This flag is
|
||||
* recommended only when copying out data brings significant performance price
|
||||
* and the handling/processing of the received frame data is always faster than
|
||||
* the preview frame rate so that data corruption won't occur.
|
||||
*
|
||||
* For instance,
|
||||
* 1. 0x00 disables the callback. In this case, copy out and one shot bits
|
||||
* are ignored.
|
||||
* 2. 0x01 enables a callback without copying out the received frames. A
|
||||
* typical use case is the Camcorder application to avoid making costly
|
||||
* frame copies.
|
||||
* 3. 0x05 is enabling a callback with frame copied out repeatedly. A typical
|
||||
* use case is the Camera application.
|
||||
* 4. 0x07 is enabling a callback with frame copied out only once. A typical
|
||||
* use case is the Barcode scanner application.
|
||||
*/
|
||||
|
||||
enum {
|
||||
CAMERA_FRAME_CALLBACK_FLAG_ENABLE_MASK = 0x01,
|
||||
CAMERA_FRAME_CALLBACK_FLAG_ONE_SHOT_MASK = 0x02,
|
||||
CAMERA_FRAME_CALLBACK_FLAG_COPY_OUT_MASK = 0x04,
|
||||
/** Typical use cases */
|
||||
CAMERA_FRAME_CALLBACK_FLAG_NOOP = 0x00,
|
||||
CAMERA_FRAME_CALLBACK_FLAG_CAMCORDER = 0x01,
|
||||
CAMERA_FRAME_CALLBACK_FLAG_CAMERA = 0x05,
|
||||
CAMERA_FRAME_CALLBACK_FLAG_BARCODE_SCANNER = 0x07
|
||||
};
|
||||
|
||||
/** msgType in notifyCallback and dataCallback functions */
|
||||
enum {
|
||||
CAMERA_MSG_ERROR = 0x0001, // notifyCallback
|
||||
CAMERA_MSG_SHUTTER = 0x0002, // notifyCallback
|
||||
CAMERA_MSG_FOCUS = 0x0004, // notifyCallback
|
||||
CAMERA_MSG_ZOOM = 0x0008, // notifyCallback
|
||||
CAMERA_MSG_PREVIEW_FRAME = 0x0010, // dataCallback
|
||||
CAMERA_MSG_VIDEO_FRAME = 0x0020, // data_timestamp_callback
|
||||
CAMERA_MSG_POSTVIEW_FRAME = 0x0040, // dataCallback
|
||||
CAMERA_MSG_RAW_IMAGE = 0x0080, // dataCallback
|
||||
CAMERA_MSG_COMPRESSED_IMAGE = 0x0100, // dataCallback
|
||||
CAMERA_MSG_RAW_IMAGE_NOTIFY = 0x0200, // dataCallback
|
||||
// Preview frame metadata. This can be combined with
|
||||
// CAMERA_MSG_PREVIEW_FRAME in dataCallback. For example, the apps can
|
||||
// request FRAME and METADATA. Or the apps can request only FRAME or only
|
||||
// METADATA.
|
||||
CAMERA_MSG_PREVIEW_METADATA = 0x0400, // dataCallback
|
||||
// Notify on autofocus start and stop. This is useful in continuous
|
||||
// autofocus - FOCUS_MODE_CONTINUOUS_VIDEO and FOCUS_MODE_CONTINUOUS_PICTURE.
|
||||
CAMERA_MSG_FOCUS_MOVE = 0x0800, // notifyCallback
|
||||
CAMERA_MSG_ALL_MSGS = 0xFFFF
|
||||
};
|
||||
|
||||
/** cmdType in sendCommand functions */
|
||||
enum {
|
||||
CAMERA_CMD_START_SMOOTH_ZOOM = 1,
|
||||
CAMERA_CMD_STOP_SMOOTH_ZOOM = 2,
|
||||
|
||||
/**
|
||||
* Set the clockwise rotation of preview display (setPreviewDisplay) in
|
||||
* degrees. This affects the preview frames and the picture displayed after
|
||||
* snapshot. This method is useful for portrait mode applications. Note
|
||||
* that preview display of front-facing cameras is flipped horizontally
|
||||
* before the rotation, that is, the image is reflected along the central
|
||||
* vertical axis of the camera sensor. So the users can see themselves as
|
||||
* looking into a mirror.
|
||||
*
|
||||
* This does not affect the order of byte array of
|
||||
* CAMERA_MSG_PREVIEW_FRAME, CAMERA_MSG_VIDEO_FRAME,
|
||||
* CAMERA_MSG_POSTVIEW_FRAME, CAMERA_MSG_RAW_IMAGE, or
|
||||
* CAMERA_MSG_COMPRESSED_IMAGE. This is allowed to be set during preview
|
||||
* since API level 14.
|
||||
*/
|
||||
CAMERA_CMD_SET_DISPLAY_ORIENTATION = 3,
|
||||
|
||||
/**
|
||||
* cmdType to disable/enable shutter sound. In sendCommand passing arg1 =
|
||||
* 0 will disable, while passing arg1 = 1 will enable the shutter sound.
|
||||
*/
|
||||
CAMERA_CMD_ENABLE_SHUTTER_SOUND = 4,
|
||||
|
||||
/* cmdType to play recording sound */
|
||||
CAMERA_CMD_PLAY_RECORDING_SOUND = 5,
|
||||
|
||||
/**
|
||||
* Start the face detection. This should be called after preview is started.
|
||||
* The camera will notify the listener of CAMERA_MSG_FACE and the detected
|
||||
* faces in the preview frame. The detected faces may be the same as the
|
||||
* previous ones. Apps should call CAMERA_CMD_STOP_FACE_DETECTION to stop
|
||||
* the face detection. This method is supported if CameraParameters
|
||||
* KEY_MAX_NUM_HW_DETECTED_FACES or KEY_MAX_NUM_SW_DETECTED_FACES is
|
||||
* bigger than 0. Hardware and software face detection should not be running
|
||||
* at the same time. If the face detection has started, apps should not send
|
||||
* this again.
|
||||
*
|
||||
* In hardware face detection mode, CameraParameters KEY_WHITE_BALANCE,
|
||||
* KEY_FOCUS_AREAS and KEY_METERING_AREAS have no effect.
|
||||
*
|
||||
* arg1 is the face detection type. It can be CAMERA_FACE_DETECTION_HW or
|
||||
* CAMERA_FACE_DETECTION_SW. If the type of face detection requested is not
|
||||
* supported, the HAL must return BAD_VALUE.
|
||||
*/
|
||||
CAMERA_CMD_START_FACE_DETECTION = 6,
|
||||
|
||||
/**
|
||||
* Stop the face detection.
|
||||
*/
|
||||
CAMERA_CMD_STOP_FACE_DETECTION = 7,
|
||||
|
||||
/**
|
||||
* Enable/disable focus move callback (CAMERA_MSG_FOCUS_MOVE). Passing
|
||||
* arg1 = 0 will disable, while passing arg1 = 1 will enable the callback.
|
||||
*/
|
||||
CAMERA_CMD_ENABLE_FOCUS_MOVE_MSG = 8,
|
||||
|
||||
/**
|
||||
* Ping camera service to see if camera hardware is released.
|
||||
*
|
||||
* When any camera method returns error, the client can use ping command
|
||||
* to see if the camera has been taken away by other clients. If the result
|
||||
* is NO_ERROR, it means the camera hardware is not released. If the result
|
||||
* is not NO_ERROR, the camera has been released and the existing client
|
||||
* can silently finish itself or show a dialog.
|
||||
*/
|
||||
CAMERA_CMD_PING = 9,
|
||||
|
||||
/**
|
||||
* Configure the number of video buffers used for recording. The intended
|
||||
* video buffer count for recording is passed as arg1, which must be
|
||||
* greater than 0. This command must be sent before recording is started.
|
||||
* This command returns INVALID_OPERATION error if it is sent after video
|
||||
* recording is started, or the command is not supported at all. This
|
||||
* command also returns a BAD_VALUE error if the intended video buffer
|
||||
* count is non-positive or too big to be realized.
|
||||
*/
|
||||
CAMERA_CMD_SET_VIDEO_BUFFER_COUNT = 10,
|
||||
|
||||
/**
|
||||
* Configure an explicit format to use for video recording metadata mode.
|
||||
* This can be used to switch the format from the
|
||||
* default IMPLEMENTATION_DEFINED gralloc format to some other
|
||||
* device-supported format, and the default dataspace from the BT_709 color
|
||||
* space to some other device-supported dataspace. arg1 is the HAL pixel
|
||||
* format, and arg2 is the HAL dataSpace. This command returns
|
||||
* INVALID_OPERATION error if it is sent after video recording is started,
|
||||
* or the command is not supported at all.
|
||||
*
|
||||
* If the gralloc format is set to a format other than
|
||||
* IMPLEMENTATION_DEFINED, then HALv3 devices will use gralloc usage flags
|
||||
* of SW_READ_OFTEN.
|
||||
*/
|
||||
CAMERA_CMD_SET_VIDEO_FORMAT = 11
|
||||
};
|
||||
|
||||
/** camera fatal errors */
|
||||
enum {
|
||||
CAMERA_ERROR_UNKNOWN = 1,
|
||||
/**
|
||||
* Camera was released because another client has connected to the camera.
|
||||
* The original client should call Camera::disconnect immediately after
|
||||
* getting this notification. Otherwise, the camera will be released by
|
||||
* camera service in a short time. The client should not call any method
|
||||
* (except disconnect and sending CAMERA_CMD_PING) after getting this.
|
||||
*/
|
||||
CAMERA_ERROR_RELEASED = 2,
|
||||
|
||||
/**
|
||||
* Camera was released because device policy change or the client application
|
||||
* is going to background. The client should call Camera::disconnect
|
||||
* immediately after getting this notification. Otherwise, the camera will be
|
||||
* released by camera service in a short time. The client should not call any
|
||||
* method (except disconnect and sending CAMERA_CMD_PING) after getting this.
|
||||
*/
|
||||
CAMERA_ERROR_DISABLED = 3,
|
||||
CAMERA_ERROR_SERVER_DIED = 100
|
||||
};
|
||||
|
||||
enum {
|
||||
/** The facing of the camera is opposite to that of the screen. */
|
||||
CAMERA_FACING_BACK = 0,
|
||||
/** The facing of the camera is the same as that of the screen. */
|
||||
CAMERA_FACING_FRONT = 1,
|
||||
/**
|
||||
* The facing of the camera is not fixed relative to the screen.
|
||||
* The cameras with this facing are external cameras, e.g. USB cameras.
|
||||
*/
|
||||
CAMERA_FACING_EXTERNAL = 2
|
||||
};
|
||||
|
||||
enum {
|
||||
/** Hardware face detection. It does not use much CPU. */
|
||||
CAMERA_FACE_DETECTION_HW = 0,
|
||||
/**
|
||||
* Software face detection. It uses some CPU. Applications must use
|
||||
* Camera.setPreviewTexture for preview in this mode.
|
||||
*/
|
||||
CAMERA_FACE_DETECTION_SW = 1
|
||||
};
|
||||
|
||||
/**
|
||||
* The information of a face from camera face detection.
|
||||
*/
|
||||
typedef struct camera_face {
|
||||
/**
|
||||
* Bounds of the face [left, top, right, bottom]. (-1000, -1000) represents
|
||||
* the top-left of the camera field of view, and (1000, 1000) represents the
|
||||
* bottom-right of the field of view. The width and height cannot be 0 or
|
||||
* negative. This is supported by both hardware and software face detection.
|
||||
*
|
||||
* The direction is relative to the sensor orientation, that is, what the
|
||||
* sensor sees. The direction is not affected by the rotation or mirroring
|
||||
* of CAMERA_CMD_SET_DISPLAY_ORIENTATION.
|
||||
*/
|
||||
int32_t rect[4];
|
||||
|
||||
/**
|
||||
* The confidence level of the face. The range is 1 to 100. 100 is the
|
||||
* highest confidence. This is supported by both hardware and software
|
||||
* face detection.
|
||||
*/
|
||||
int32_t score;
|
||||
|
||||
/**
|
||||
* An unique id per face while the face is visible to the tracker. If
|
||||
* the face leaves the field-of-view and comes back, it will get a new
|
||||
* id. If the value is 0, id is not supported.
|
||||
*/
|
||||
int32_t id;
|
||||
|
||||
/**
|
||||
* The coordinates of the center of the left eye. The range is -1000 to
|
||||
* 1000. -2000, -2000 if this is not supported.
|
||||
*/
|
||||
int32_t left_eye[2];
|
||||
|
||||
/**
|
||||
* The coordinates of the center of the right eye. The range is -1000 to
|
||||
* 1000. -2000, -2000 if this is not supported.
|
||||
*/
|
||||
int32_t right_eye[2];
|
||||
|
||||
/**
|
||||
* The coordinates of the center of the mouth. The range is -1000 to 1000.
|
||||
* -2000, -2000 if this is not supported.
|
||||
*/
|
||||
int32_t mouth[2];
|
||||
|
||||
} camera_face_t;
|
||||
|
||||
/**
|
||||
* The metadata of the frame data.
|
||||
*/
|
||||
typedef struct camera_frame_metadata {
|
||||
/**
|
||||
* The number of detected faces in the frame.
|
||||
*/
|
||||
int32_t number_of_faces;
|
||||
|
||||
/**
|
||||
* An array of the detected faces. The length is number_of_faces.
|
||||
*/
|
||||
camera_face_t *faces;
|
||||
} camera_frame_metadata_t;
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* SYSTEM_CORE_INCLUDE_ANDROID_CAMERA_H */
|
||||
@@ -0,0 +1,141 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
// This file is autogenerated by hidl-gen. Do not edit manually.
|
||||
// Source: android.hardware.graphics.common@1.0
|
||||
// Location: hardware/interfaces/graphics/common/1.0/
|
||||
|
||||
#ifndef HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_COMMON_V1_0_EXPORTED_CONSTANTS_H_
|
||||
#define HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_COMMON_V1_0_EXPORTED_CONSTANTS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
HAL_PIXEL_FORMAT_RGBA_8888 = 1,
|
||||
HAL_PIXEL_FORMAT_RGBX_8888 = 2,
|
||||
HAL_PIXEL_FORMAT_RGB_888 = 3,
|
||||
HAL_PIXEL_FORMAT_RGB_565 = 4,
|
||||
HAL_PIXEL_FORMAT_BGRA_8888 = 5,
|
||||
HAL_PIXEL_FORMAT_YCBCR_422_SP = 16,
|
||||
HAL_PIXEL_FORMAT_YCRCB_420_SP = 17,
|
||||
HAL_PIXEL_FORMAT_YCBCR_422_I = 20,
|
||||
HAL_PIXEL_FORMAT_RGBA_FP16 = 22,
|
||||
HAL_PIXEL_FORMAT_RAW16 = 32,
|
||||
HAL_PIXEL_FORMAT_BLOB = 33,
|
||||
HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED = 34,
|
||||
HAL_PIXEL_FORMAT_YCBCR_420_888 = 35,
|
||||
HAL_PIXEL_FORMAT_RAW_OPAQUE = 36,
|
||||
HAL_PIXEL_FORMAT_RAW10 = 37,
|
||||
HAL_PIXEL_FORMAT_RAW12 = 38,
|
||||
HAL_PIXEL_FORMAT_RGBA_1010102 = 43,
|
||||
HAL_PIXEL_FORMAT_Y8 = 538982489,
|
||||
HAL_PIXEL_FORMAT_Y16 = 540422489,
|
||||
HAL_PIXEL_FORMAT_YV12 = 842094169,
|
||||
} android_pixel_format_t;
|
||||
|
||||
typedef enum {
|
||||
HAL_TRANSFORM_FLIP_H = 1, // (1 << 0)
|
||||
HAL_TRANSFORM_FLIP_V = 2, // (1 << 1)
|
||||
HAL_TRANSFORM_ROT_90 = 4, // (1 << 2)
|
||||
HAL_TRANSFORM_ROT_180 = 3, // (FLIP_H | FLIP_V)
|
||||
HAL_TRANSFORM_ROT_270 = 7, // ((FLIP_H | FLIP_V) | ROT_90)
|
||||
} android_transform_t;
|
||||
|
||||
typedef enum {
|
||||
HAL_DATASPACE_UNKNOWN = 0,
|
||||
HAL_DATASPACE_ARBITRARY = 1,
|
||||
HAL_DATASPACE_STANDARD_SHIFT = 16,
|
||||
HAL_DATASPACE_STANDARD_MASK = 4128768, // (63 << STANDARD_SHIFT)
|
||||
HAL_DATASPACE_STANDARD_UNSPECIFIED = 0, // (0 << STANDARD_SHIFT)
|
||||
HAL_DATASPACE_STANDARD_BT709 = 65536, // (1 << STANDARD_SHIFT)
|
||||
HAL_DATASPACE_STANDARD_BT601_625 = 131072, // (2 << STANDARD_SHIFT)
|
||||
HAL_DATASPACE_STANDARD_BT601_625_UNADJUSTED = 196608, // (3 << STANDARD_SHIFT)
|
||||
HAL_DATASPACE_STANDARD_BT601_525 = 262144, // (4 << STANDARD_SHIFT)
|
||||
HAL_DATASPACE_STANDARD_BT601_525_UNADJUSTED = 327680, // (5 << STANDARD_SHIFT)
|
||||
HAL_DATASPACE_STANDARD_BT2020 = 393216, // (6 << STANDARD_SHIFT)
|
||||
HAL_DATASPACE_STANDARD_BT2020_CONSTANT_LUMINANCE = 458752, // (7 << STANDARD_SHIFT)
|
||||
HAL_DATASPACE_STANDARD_BT470M = 524288, // (8 << STANDARD_SHIFT)
|
||||
HAL_DATASPACE_STANDARD_FILM = 589824, // (9 << STANDARD_SHIFT)
|
||||
HAL_DATASPACE_STANDARD_DCI_P3 = 655360, // (10 << STANDARD_SHIFT)
|
||||
HAL_DATASPACE_STANDARD_ADOBE_RGB = 720896, // (11 << STANDARD_SHIFT)
|
||||
HAL_DATASPACE_TRANSFER_SHIFT = 22,
|
||||
HAL_DATASPACE_TRANSFER_MASK = 130023424, // (31 << TRANSFER_SHIFT)
|
||||
HAL_DATASPACE_TRANSFER_UNSPECIFIED = 0, // (0 << TRANSFER_SHIFT)
|
||||
HAL_DATASPACE_TRANSFER_LINEAR = 4194304, // (1 << TRANSFER_SHIFT)
|
||||
HAL_DATASPACE_TRANSFER_SRGB = 8388608, // (2 << TRANSFER_SHIFT)
|
||||
HAL_DATASPACE_TRANSFER_SMPTE_170M = 12582912, // (3 << TRANSFER_SHIFT)
|
||||
HAL_DATASPACE_TRANSFER_GAMMA2_2 = 16777216, // (4 << TRANSFER_SHIFT)
|
||||
HAL_DATASPACE_TRANSFER_GAMMA2_6 = 20971520, // (5 << TRANSFER_SHIFT)
|
||||
HAL_DATASPACE_TRANSFER_GAMMA2_8 = 25165824, // (6 << TRANSFER_SHIFT)
|
||||
HAL_DATASPACE_TRANSFER_ST2084 = 29360128, // (7 << TRANSFER_SHIFT)
|
||||
HAL_DATASPACE_TRANSFER_HLG = 33554432, // (8 << TRANSFER_SHIFT)
|
||||
HAL_DATASPACE_RANGE_SHIFT = 27,
|
||||
HAL_DATASPACE_RANGE_MASK = 939524096, // (7 << RANGE_SHIFT)
|
||||
HAL_DATASPACE_RANGE_UNSPECIFIED = 0, // (0 << RANGE_SHIFT)
|
||||
HAL_DATASPACE_RANGE_FULL = 134217728, // (1 << RANGE_SHIFT)
|
||||
HAL_DATASPACE_RANGE_LIMITED = 268435456, // (2 << RANGE_SHIFT)
|
||||
HAL_DATASPACE_RANGE_EXTENDED = 402653184, // (3 << RANGE_SHIFT)
|
||||
HAL_DATASPACE_SRGB_LINEAR = 512,
|
||||
HAL_DATASPACE_V0_SRGB_LINEAR = 138477568, // ((STANDARD_BT709 | TRANSFER_LINEAR) | RANGE_FULL)
|
||||
HAL_DATASPACE_V0_SCRGB_LINEAR =
|
||||
406913024, // ((STANDARD_BT709 | TRANSFER_LINEAR) | RANGE_EXTENDED)
|
||||
HAL_DATASPACE_SRGB = 513,
|
||||
HAL_DATASPACE_V0_SRGB = 142671872, // ((STANDARD_BT709 | TRANSFER_SRGB) | RANGE_FULL)
|
||||
HAL_DATASPACE_V0_SCRGB = 411107328, // ((STANDARD_BT709 | TRANSFER_SRGB) | RANGE_EXTENDED)
|
||||
HAL_DATASPACE_JFIF = 257,
|
||||
HAL_DATASPACE_V0_JFIF = 146931712, // ((STANDARD_BT601_625 | TRANSFER_SMPTE_170M) | RANGE_FULL)
|
||||
HAL_DATASPACE_BT601_625 = 258,
|
||||
HAL_DATASPACE_V0_BT601_625 =
|
||||
281149440, // ((STANDARD_BT601_625 | TRANSFER_SMPTE_170M) | RANGE_LIMITED)
|
||||
HAL_DATASPACE_BT601_525 = 259,
|
||||
HAL_DATASPACE_V0_BT601_525 =
|
||||
281280512, // ((STANDARD_BT601_525 | TRANSFER_SMPTE_170M) | RANGE_LIMITED)
|
||||
HAL_DATASPACE_BT709 = 260,
|
||||
HAL_DATASPACE_V0_BT709 = 281083904, // ((STANDARD_BT709 | TRANSFER_SMPTE_170M) | RANGE_LIMITED)
|
||||
HAL_DATASPACE_DCI_P3_LINEAR = 139067392, // ((STANDARD_DCI_P3 | TRANSFER_LINEAR) | RANGE_FULL)
|
||||
HAL_DATASPACE_DCI_P3 = 155844608, // ((STANDARD_DCI_P3 | TRANSFER_GAMMA2_6) | RANGE_FULL)
|
||||
HAL_DATASPACE_DISPLAY_P3_LINEAR =
|
||||
139067392, // ((STANDARD_DCI_P3 | TRANSFER_LINEAR) | RANGE_FULL)
|
||||
HAL_DATASPACE_DISPLAY_P3 = 143261696, // ((STANDARD_DCI_P3 | TRANSFER_SRGB) | RANGE_FULL)
|
||||
HAL_DATASPACE_ADOBE_RGB = 151715840, // ((STANDARD_ADOBE_RGB | TRANSFER_GAMMA2_2) | RANGE_FULL)
|
||||
HAL_DATASPACE_BT2020_LINEAR = 138805248, // ((STANDARD_BT2020 | TRANSFER_LINEAR) | RANGE_FULL)
|
||||
HAL_DATASPACE_BT2020 = 147193856, // ((STANDARD_BT2020 | TRANSFER_SMPTE_170M) | RANGE_FULL)
|
||||
HAL_DATASPACE_BT2020_PQ = 163971072, // ((STANDARD_BT2020 | TRANSFER_ST2084) | RANGE_FULL)
|
||||
HAL_DATASPACE_DEPTH = 4096,
|
||||
HAL_DATASPACE_SENSOR = 4097,
|
||||
} android_dataspace_t;
|
||||
|
||||
typedef enum {
|
||||
HAL_COLOR_MODE_NATIVE = 0,
|
||||
HAL_COLOR_MODE_STANDARD_BT601_625 = 1,
|
||||
HAL_COLOR_MODE_STANDARD_BT601_625_UNADJUSTED = 2,
|
||||
HAL_COLOR_MODE_STANDARD_BT601_525 = 3,
|
||||
HAL_COLOR_MODE_STANDARD_BT601_525_UNADJUSTED = 4,
|
||||
HAL_COLOR_MODE_STANDARD_BT709 = 5,
|
||||
HAL_COLOR_MODE_DCI_P3 = 6,
|
||||
HAL_COLOR_MODE_SRGB = 7,
|
||||
HAL_COLOR_MODE_ADOBE_RGB = 8,
|
||||
HAL_COLOR_MODE_DISPLAY_P3 = 9,
|
||||
} android_color_mode_t;
|
||||
|
||||
typedef enum {
|
||||
HAL_COLOR_TRANSFORM_IDENTITY = 0,
|
||||
HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX = 1,
|
||||
HAL_COLOR_TRANSFORM_VALUE_INVERSE = 2,
|
||||
HAL_COLOR_TRANSFORM_GRAYSCALE = 3,
|
||||
HAL_COLOR_TRANSFORM_CORRECT_PROTANOPIA = 4,
|
||||
HAL_COLOR_TRANSFORM_CORRECT_DEUTERANOPIA = 5,
|
||||
HAL_COLOR_TRANSFORM_CORRECT_TRITANOPIA = 6,
|
||||
} android_color_transform_t;
|
||||
|
||||
typedef enum {
|
||||
HAL_HDR_DOLBY_VISION = 1,
|
||||
HAL_HDR_HDR10 = 2,
|
||||
HAL_HDR_HLG = 3,
|
||||
} android_hdr_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_COMMON_V1_0_EXPORTED_CONSTANTS_H_
|
||||
@@ -0,0 +1,49 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
// This file is autogenerated by hidl-gen. Do not edit manually.
|
||||
// Source: android.hardware.graphics.common@1.1
|
||||
// Location: hardware/interfaces/graphics/common/1.1/
|
||||
|
||||
#ifndef HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_COMMON_V1_1_EXPORTED_CONSTANTS_H_
|
||||
#define HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_COMMON_V1_1_EXPORTED_CONSTANTS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
HAL_PIXEL_FORMAT_DEPTH_16 = 48,
|
||||
HAL_PIXEL_FORMAT_DEPTH_24 = 49,
|
||||
HAL_PIXEL_FORMAT_DEPTH_24_STENCIL_8 = 50,
|
||||
HAL_PIXEL_FORMAT_DEPTH_32F = 51,
|
||||
HAL_PIXEL_FORMAT_DEPTH_32F_STENCIL_8 = 52,
|
||||
HAL_PIXEL_FORMAT_STENCIL_8 = 53,
|
||||
HAL_PIXEL_FORMAT_YCBCR_P010 = 54,
|
||||
} android_pixel_format_v1_1_t;
|
||||
|
||||
typedef enum {
|
||||
HAL_DATASPACE_BT2020_ITU =
|
||||
281411584, // ((STANDARD_BT2020 | TRANSFER_SMPTE_170M) | RANGE_LIMITED)
|
||||
HAL_DATASPACE_BT2020_ITU_PQ =
|
||||
298188800, // ((STANDARD_BT2020 | TRANSFER_ST2084) | RANGE_LIMITED)
|
||||
HAL_DATASPACE_BT2020_ITU_HLG = 302383104, // ((STANDARD_BT2020 | TRANSFER_HLG) | RANGE_LIMITED)
|
||||
HAL_DATASPACE_BT2020_HLG = 168165376, // ((STANDARD_BT2020 | TRANSFER_HLG) | RANGE_FULL)
|
||||
} android_dataspace_v1_1_t;
|
||||
|
||||
typedef enum {
|
||||
HAL_COLOR_MODE_BT2020 = 10,
|
||||
HAL_COLOR_MODE_BT2100_PQ = 11,
|
||||
HAL_COLOR_MODE_BT2100_HLG = 12,
|
||||
} android_color_mode_v1_1_t;
|
||||
|
||||
typedef enum {
|
||||
HAL_RENDER_INTENT_COLORIMETRIC = 0,
|
||||
HAL_RENDER_INTENT_ENHANCE = 1,
|
||||
HAL_RENDER_INTENT_TONE_MAP_COLORIMETRIC = 2,
|
||||
HAL_RENDER_INTENT_TONE_MAP_ENHANCE = 3,
|
||||
} android_render_intent_v1_1_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // HIDL_GENERATED_ANDROID_HARDWARE_GRAPHICS_COMMON_V1_1_EXPORTED_CONSTANTS_H_
|
||||
@@ -0,0 +1,8 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
#ifndef SYSTEM_CORE_GRAPHICS_BASE_H_
|
||||
#define SYSTEM_CORE_GRAPHICS_BASE_H_
|
||||
|
||||
#include "graphics-base-v1.0.h"
|
||||
#include "graphics-base-v1.1.h"
|
||||
|
||||
#endif // SYSTEM_CORE_GRAPHICS_BASE_H_
|
||||
@@ -0,0 +1,17 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
#ifndef SYSTEM_CORE_GRAPHICS_SW_H_
|
||||
#define SYSTEM_CORE_GRAPHICS_SW_H_
|
||||
|
||||
/* Software formats not in the HAL definitions. */
|
||||
typedef enum {
|
||||
HAL_PIXEL_FORMAT_YCBCR_422_888 = 39, // 0x27
|
||||
HAL_PIXEL_FORMAT_YCBCR_444_888 = 40, // 0x28
|
||||
HAL_PIXEL_FORMAT_FLEX_RGB_888 = 41, // 0x29
|
||||
HAL_PIXEL_FORMAT_FLEX_RGBA_8888 = 42, // 0x2A
|
||||
} android_pixel_format_sw_t;
|
||||
|
||||
/* for compatibility */
|
||||
#define HAL_PIXEL_FORMAT_YCbCr_422_888 HAL_PIXEL_FORMAT_YCBCR_422_888
|
||||
#define HAL_PIXEL_FORMAT_YCbCr_444_888 HAL_PIXEL_FORMAT_YCBCR_444_888
|
||||
|
||||
#endif // SYSTEM_CORE_GRAPHICS_SW_H_
|
||||
@@ -0,0 +1,269 @@
|
||||
/* SPDX-License-Identifier: Apache-2.0 */
|
||||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H
|
||||
#define SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* Some of the enums are now defined in HIDL in hardware/interfaces and are
|
||||
* generated.
|
||||
*/
|
||||
#include "graphics-base.h"
|
||||
#include "graphics-sw.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* for compatibility */
|
||||
#define HAL_PIXEL_FORMAT_YCbCr_420_888 HAL_PIXEL_FORMAT_YCBCR_420_888
|
||||
#define HAL_PIXEL_FORMAT_YCbCr_422_SP HAL_PIXEL_FORMAT_YCBCR_422_SP
|
||||
#define HAL_PIXEL_FORMAT_YCrCb_420_SP HAL_PIXEL_FORMAT_YCRCB_420_SP
|
||||
#define HAL_PIXEL_FORMAT_YCbCr_422_I HAL_PIXEL_FORMAT_YCBCR_422_I
|
||||
typedef android_pixel_format_t android_pixel_format;
|
||||
typedef android_transform_t android_transform;
|
||||
typedef android_dataspace_t android_dataspace;
|
||||
typedef android_color_mode_t android_color_mode;
|
||||
typedef android_color_transform_t android_color_transform;
|
||||
typedef android_hdr_t android_hdr;
|
||||
|
||||
/*
|
||||
* If the HAL needs to create service threads to handle graphics related
|
||||
* tasks, these threads need to run at HAL_PRIORITY_URGENT_DISPLAY priority
|
||||
* if they can block the main rendering thread in any way.
|
||||
*
|
||||
* the priority of the current thread can be set with:
|
||||
*
|
||||
* #include <sys/resource.h>
|
||||
* setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY);
|
||||
*
|
||||
*/
|
||||
|
||||
#define HAL_PRIORITY_URGENT_DISPLAY (-8)
|
||||
|
||||
/*
|
||||
* Structure for describing YCbCr formats for consumption by applications.
|
||||
* This is used with HAL_PIXEL_FORMAT_YCbCr_*_888.
|
||||
*
|
||||
* Buffer chroma subsampling is defined in the format.
|
||||
* e.g. HAL_PIXEL_FORMAT_YCbCr_420_888 has subsampling 4:2:0.
|
||||
*
|
||||
* Buffers must have a 8 bit depth.
|
||||
*
|
||||
* y, cb, and cr point to the first byte of their respective planes.
|
||||
*
|
||||
* Stride describes the distance in bytes from the first value of one row of
|
||||
* the image to the first value of the next row. It includes the width of the
|
||||
* image plus padding.
|
||||
* ystride is the stride of the luma plane.
|
||||
* cstride is the stride of the chroma planes.
|
||||
*
|
||||
* chroma_step is the distance in bytes from one chroma pixel value to the
|
||||
* next. This is 2 bytes for semiplanar (because chroma values are interleaved
|
||||
* and each chroma value is one byte) and 1 for planar.
|
||||
*/
|
||||
|
||||
struct android_ycbcr {
|
||||
void *y;
|
||||
void *cb;
|
||||
void *cr;
|
||||
size_t ystride;
|
||||
size_t cstride;
|
||||
size_t chroma_step;
|
||||
|
||||
/** reserved for future use, set to 0 by gralloc's (*lock_ycbcr)() */
|
||||
uint32_t reserved[8];
|
||||
};
|
||||
|
||||
/*
|
||||
* Structures for describing flexible YUVA/RGBA formats for consumption by
|
||||
* applications. Such flexible formats contain a plane for each component (e.g.
|
||||
* red, green, blue), where each plane is laid out in a grid-like pattern
|
||||
* occupying unique byte addresses and with consistent byte offsets between
|
||||
* neighboring pixels.
|
||||
*
|
||||
* The android_flex_layout structure is used with any pixel format that can be
|
||||
* represented by it, such as:
|
||||
* - HAL_PIXEL_FORMAT_YCbCr_*_888
|
||||
* - HAL_PIXEL_FORMAT_FLEX_RGB*_888
|
||||
* - HAL_PIXEL_FORMAT_RGB[AX]_888[8],BGRA_8888,RGB_888
|
||||
* - HAL_PIXEL_FORMAT_YV12,Y8,Y16,YCbCr_422_SP/I,YCrCb_420_SP
|
||||
* - even implementation defined formats that can be represented by
|
||||
* the structures
|
||||
*
|
||||
* Vertical increment (aka. row increment or stride) describes the distance in
|
||||
* bytes from the first pixel of one row to the first pixel of the next row
|
||||
* (below) for the component plane. This can be negative.
|
||||
*
|
||||
* Horizontal increment (aka. column or pixel increment) describes the distance
|
||||
* in bytes from one pixel to the next pixel (to the right) on the same row for
|
||||
* the component plane. This can be negative.
|
||||
*
|
||||
* Each plane can be subsampled either vertically or horizontally by
|
||||
* a power-of-two factor.
|
||||
*
|
||||
* The bit-depth of each component can be arbitrary, as long as the pixels are
|
||||
* laid out on whole bytes, in native byte-order, using the most significant
|
||||
* bits of each unit.
|
||||
*/
|
||||
|
||||
typedef enum android_flex_component {
|
||||
/* luma */
|
||||
FLEX_COMPONENT_Y = 1 << 0,
|
||||
/* chroma blue */
|
||||
FLEX_COMPONENT_Cb = 1 << 1,
|
||||
/* chroma red */
|
||||
FLEX_COMPONENT_Cr = 1 << 2,
|
||||
|
||||
/* red */
|
||||
FLEX_COMPONENT_R = 1 << 10,
|
||||
/* green */
|
||||
FLEX_COMPONENT_G = 1 << 11,
|
||||
/* blue */
|
||||
FLEX_COMPONENT_B = 1 << 12,
|
||||
|
||||
/* alpha */
|
||||
FLEX_COMPONENT_A = 1 << 30,
|
||||
} android_flex_component_t;
|
||||
|
||||
typedef struct android_flex_plane {
|
||||
/* pointer to the first byte of the top-left pixel of the plane. */
|
||||
uint8_t *top_left;
|
||||
|
||||
android_flex_component_t component;
|
||||
|
||||
/* bits allocated for the component in each pixel. Must be a positive
|
||||
multiple of 8. */
|
||||
int32_t bits_per_component;
|
||||
/* number of the most significant bits used in the format for this
|
||||
component. Must be between 1 and bits_per_component, inclusive. */
|
||||
int32_t bits_used;
|
||||
|
||||
/* horizontal increment */
|
||||
int32_t h_increment;
|
||||
/* vertical increment */
|
||||
int32_t v_increment;
|
||||
/* horizontal subsampling. Must be a positive power of 2. */
|
||||
int32_t h_subsampling;
|
||||
/* vertical subsampling. Must be a positive power of 2. */
|
||||
int32_t v_subsampling;
|
||||
} android_flex_plane_t;
|
||||
|
||||
typedef enum android_flex_format {
|
||||
/* not a flexible format */
|
||||
FLEX_FORMAT_INVALID = 0x0,
|
||||
FLEX_FORMAT_Y = FLEX_COMPONENT_Y,
|
||||
FLEX_FORMAT_YCbCr = FLEX_COMPONENT_Y | FLEX_COMPONENT_Cb | FLEX_COMPONENT_Cr,
|
||||
FLEX_FORMAT_YCbCrA = FLEX_FORMAT_YCbCr | FLEX_COMPONENT_A,
|
||||
FLEX_FORMAT_RGB = FLEX_COMPONENT_R | FLEX_COMPONENT_G | FLEX_COMPONENT_B,
|
||||
FLEX_FORMAT_RGBA = FLEX_FORMAT_RGB | FLEX_COMPONENT_A,
|
||||
} android_flex_format_t;
|
||||
|
||||
typedef struct android_flex_layout {
|
||||
/* the kind of flexible format */
|
||||
android_flex_format_t format;
|
||||
|
||||
/* number of planes; 0 for FLEX_FORMAT_INVALID */
|
||||
uint32_t num_planes;
|
||||
/* a plane for each component; ordered in increasing component value order.
|
||||
E.g. FLEX_FORMAT_RGBA maps 0 -> R, 1 -> G, etc.
|
||||
Can be NULL for FLEX_FORMAT_INVALID */
|
||||
android_flex_plane_t *planes;
|
||||
} android_flex_layout_t;
|
||||
|
||||
/**
|
||||
* Structure used to define depth point clouds for format HAL_PIXEL_FORMAT_BLOB
|
||||
* with dataSpace value of HAL_DATASPACE_DEPTH.
|
||||
* When locking a native buffer of the above format and dataSpace value,
|
||||
* the vaddr pointer can be cast to this structure.
|
||||
*
|
||||
* A variable-length list of (x,y,z, confidence) 3D points, as floats. (x, y,
|
||||
* z) represents a measured point's position, with the coordinate system defined
|
||||
* by the data source. Confidence represents the estimated likelihood that this
|
||||
* measurement is correct. It is between 0.f and 1.f, inclusive, with 1.f ==
|
||||
* 100% confidence.
|
||||
*
|
||||
* num_points is the number of points in the list
|
||||
*
|
||||
* xyz_points is the flexible array of floating-point values.
|
||||
* It contains (num_points) * 4 floats.
|
||||
*
|
||||
* For example:
|
||||
* android_depth_points d = get_depth_buffer();
|
||||
* struct {
|
||||
* float x; float y; float z; float confidence;
|
||||
* } firstPoint, lastPoint;
|
||||
*
|
||||
* firstPoint.x = d.xyzc_points[0];
|
||||
* firstPoint.y = d.xyzc_points[1];
|
||||
* firstPoint.z = d.xyzc_points[2];
|
||||
* firstPoint.confidence = d.xyzc_points[3];
|
||||
* lastPoint.x = d.xyzc_points[(d.num_points - 1) * 4 + 0];
|
||||
* lastPoint.y = d.xyzc_points[(d.num_points - 1) * 4 + 1];
|
||||
* lastPoint.z = d.xyzc_points[(d.num_points - 1) * 4 + 2];
|
||||
* lastPoint.confidence = d.xyzc_points[(d.num_points - 1) * 4 + 3];
|
||||
*/
|
||||
|
||||
struct android_depth_points {
|
||||
uint32_t num_points;
|
||||
|
||||
/** reserved for future use, set to 0 by gralloc's (*lock)() */
|
||||
uint32_t reserved[8];
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wc99-extensions"
|
||||
#endif
|
||||
float xyzc_points[];
|
||||
#if defined(__clang__)
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* These structures are used to define the reference display's
|
||||
* capabilities for HDR content. Display engine can use this
|
||||
* to better tone map content to user's display.
|
||||
* Color is defined in CIE XYZ coordinates
|
||||
*/
|
||||
struct android_xy_color {
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
|
||||
struct android_smpte2086_metadata {
|
||||
struct android_xy_color displayPrimaryRed;
|
||||
struct android_xy_color displayPrimaryGreen;
|
||||
struct android_xy_color displayPrimaryBlue;
|
||||
struct android_xy_color whitePoint;
|
||||
float maxLuminance;
|
||||
float minLuminance;
|
||||
};
|
||||
|
||||
struct android_cta861_3_metadata {
|
||||
float maxContentLightLevel;
|
||||
float maxFrameAverageLightLevel;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H */
|
||||
36
spider-cam/libcamera/include/libcamera/base/backtrace.h
Normal file
36
spider-cam/libcamera/include/libcamera/base/backtrace.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2021, Ideas on Board Oy
|
||||
*
|
||||
* Call stack backtraces
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/private.h>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Backtrace
|
||||
{
|
||||
public:
|
||||
Backtrace();
|
||||
|
||||
std::string toString(unsigned int skipLevels = 0) const;
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY(Backtrace)
|
||||
|
||||
bool backtraceTrace();
|
||||
bool unwindTrace();
|
||||
|
||||
std::vector<void *> backtrace_;
|
||||
std::vector<std::string> backtraceText_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
224
spider-cam/libcamera/include/libcamera/base/bound_method.h
Normal file
224
spider-cam/libcamera/include/libcamera/base/bound_method.h
Normal file
@@ -0,0 +1,224 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Method bind and invocation
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Object;
|
||||
|
||||
enum ConnectionType {
|
||||
ConnectionTypeAuto,
|
||||
ConnectionTypeDirect,
|
||||
ConnectionTypeQueued,
|
||||
ConnectionTypeBlocking,
|
||||
};
|
||||
|
||||
class BoundMethodPackBase
|
||||
{
|
||||
public:
|
||||
virtual ~BoundMethodPackBase() = default;
|
||||
};
|
||||
|
||||
template<typename R, typename... Args>
|
||||
class BoundMethodPack : public BoundMethodPackBase
|
||||
{
|
||||
public:
|
||||
BoundMethodPack(const Args &... args)
|
||||
: args_(args...)
|
||||
{
|
||||
}
|
||||
|
||||
R returnValue()
|
||||
{
|
||||
return ret_;
|
||||
}
|
||||
|
||||
std::tuple<typename std::remove_reference_t<Args>...> args_;
|
||||
R ret_;
|
||||
};
|
||||
|
||||
template<typename... Args>
|
||||
class BoundMethodPack<void, Args...> : public BoundMethodPackBase
|
||||
{
|
||||
public:
|
||||
BoundMethodPack(const Args &... args)
|
||||
: args_(args...)
|
||||
{
|
||||
}
|
||||
|
||||
void returnValue()
|
||||
{
|
||||
}
|
||||
|
||||
std::tuple<typename std::remove_reference_t<Args>...> args_;
|
||||
};
|
||||
|
||||
class BoundMethodBase
|
||||
{
|
||||
public:
|
||||
BoundMethodBase(void *obj, Object *object, ConnectionType type)
|
||||
: obj_(obj), object_(object), connectionType_(type)
|
||||
{
|
||||
}
|
||||
virtual ~BoundMethodBase() = default;
|
||||
|
||||
template<typename T, std::enable_if_t<!std::is_same<Object, T>::value> * = nullptr>
|
||||
bool match(T *obj) { return obj == obj_; }
|
||||
bool match(Object *object) { return object == object_; }
|
||||
|
||||
Object *object() const { return object_; }
|
||||
|
||||
virtual void invokePack(BoundMethodPackBase *pack) = 0;
|
||||
|
||||
protected:
|
||||
bool activatePack(std::shared_ptr<BoundMethodPackBase> pack,
|
||||
bool deleteMethod);
|
||||
|
||||
void *obj_;
|
||||
Object *object_;
|
||||
|
||||
private:
|
||||
ConnectionType connectionType_;
|
||||
};
|
||||
|
||||
template<typename R, typename... Args>
|
||||
class BoundMethodArgs : public BoundMethodBase
|
||||
{
|
||||
public:
|
||||
using PackType = BoundMethodPack<R, Args...>;
|
||||
|
||||
private:
|
||||
template<std::size_t... I, typename T = R>
|
||||
std::enable_if_t<!std::is_void<T>::value, void>
|
||||
invokePack(BoundMethodPackBase *pack, std::index_sequence<I...>)
|
||||
{
|
||||
PackType *args = static_cast<PackType *>(pack);
|
||||
args->ret_ = invoke(std::get<I>(args->args_)...);
|
||||
}
|
||||
|
||||
template<std::size_t... I, typename T = R>
|
||||
std::enable_if_t<std::is_void<T>::value, void>
|
||||
invokePack(BoundMethodPackBase *pack, std::index_sequence<I...>)
|
||||
{
|
||||
/* args is effectively unused when the sequence I is empty. */
|
||||
PackType *args [[gnu::unused]] = static_cast<PackType *>(pack);
|
||||
invoke(std::get<I>(args->args_)...);
|
||||
}
|
||||
|
||||
public:
|
||||
BoundMethodArgs(void *obj, Object *object, ConnectionType type)
|
||||
: BoundMethodBase(obj, object, type) {}
|
||||
|
||||
void invokePack(BoundMethodPackBase *pack) override
|
||||
{
|
||||
invokePack(pack, std::make_index_sequence<sizeof...(Args)>{});
|
||||
}
|
||||
|
||||
virtual R activate(Args... args, bool deleteMethod = false) = 0;
|
||||
virtual R invoke(Args... args) = 0;
|
||||
};
|
||||
|
||||
template<typename T, typename R, typename Func, typename... Args>
|
||||
class BoundMethodFunctor : public BoundMethodArgs<R, Args...>
|
||||
{
|
||||
public:
|
||||
using PackType = typename BoundMethodArgs<R, Args...>::PackType;
|
||||
|
||||
BoundMethodFunctor(T *obj, Object *object, Func func,
|
||||
ConnectionType type = ConnectionTypeAuto)
|
||||
: BoundMethodArgs<R, Args...>(obj, object, type), func_(func)
|
||||
{
|
||||
}
|
||||
|
||||
R activate(Args... args, bool deleteMethod = false) override
|
||||
{
|
||||
if (!this->object_)
|
||||
return func_(args...);
|
||||
|
||||
auto pack = std::make_shared<PackType>(args...);
|
||||
bool sync = BoundMethodBase::activatePack(pack, deleteMethod);
|
||||
return sync ? pack->returnValue() : R();
|
||||
}
|
||||
|
||||
R invoke(Args... args) override
|
||||
{
|
||||
return func_(args...);
|
||||
}
|
||||
|
||||
private:
|
||||
Func func_;
|
||||
};
|
||||
|
||||
template<typename T, typename R, typename... Args>
|
||||
class BoundMethodMember : public BoundMethodArgs<R, Args...>
|
||||
{
|
||||
public:
|
||||
using PackType = typename BoundMethodArgs<R, Args...>::PackType;
|
||||
|
||||
BoundMethodMember(T *obj, Object *object, R (T::*func)(Args...),
|
||||
ConnectionType type = ConnectionTypeAuto)
|
||||
: BoundMethodArgs<R, Args...>(obj, object, type), func_(func)
|
||||
{
|
||||
}
|
||||
|
||||
bool match(R (T::*func)(Args...)) const { return func == func_; }
|
||||
|
||||
R activate(Args... args, bool deleteMethod = false) override
|
||||
{
|
||||
if (!this->object_) {
|
||||
T *obj = static_cast<T *>(this->obj_);
|
||||
return (obj->*func_)(args...);
|
||||
}
|
||||
|
||||
auto pack = std::make_shared<PackType>(args...);
|
||||
bool sync = BoundMethodBase::activatePack(pack, deleteMethod);
|
||||
return sync ? pack->returnValue() : R();
|
||||
}
|
||||
|
||||
R invoke(Args... args) override
|
||||
{
|
||||
T *obj = static_cast<T *>(this->obj_);
|
||||
return (obj->*func_)(args...);
|
||||
}
|
||||
|
||||
private:
|
||||
R (T::*func_)(Args...);
|
||||
};
|
||||
|
||||
template<typename R, typename... Args>
|
||||
class BoundMethodStatic : public BoundMethodArgs<R, Args...>
|
||||
{
|
||||
public:
|
||||
BoundMethodStatic(R (*func)(Args...))
|
||||
: BoundMethodArgs<R, Args...>(nullptr, nullptr, ConnectionTypeAuto),
|
||||
func_(func)
|
||||
{
|
||||
}
|
||||
|
||||
bool match(R (*func)(Args...)) const { return func == func_; }
|
||||
|
||||
R activate(Args... args, [[maybe_unused]] bool deleteMethod = false) override
|
||||
{
|
||||
return (*func_)(args...);
|
||||
}
|
||||
|
||||
R invoke(Args...) override
|
||||
{
|
||||
return R();
|
||||
}
|
||||
|
||||
private:
|
||||
R (*func_)(Args...);
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
109
spider-cam/libcamera/include/libcamera/base/class.h
Normal file
109
spider-cam/libcamera/include/libcamera/base/class.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Google Inc.
|
||||
*
|
||||
* Utilities and helpers for classes
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
#define LIBCAMERA_DISABLE_COPY(klass) \
|
||||
klass(const klass &) = delete; \
|
||||
klass &operator=(const klass &) = delete;
|
||||
|
||||
#define LIBCAMERA_DISABLE_MOVE(klass) \
|
||||
klass(klass &&) = delete; \
|
||||
klass &operator=(klass &&) = delete;
|
||||
|
||||
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass) \
|
||||
LIBCAMERA_DISABLE_COPY(klass) \
|
||||
LIBCAMERA_DISABLE_MOVE(klass)
|
||||
#else
|
||||
#define LIBCAMERA_DISABLE_COPY(klass)
|
||||
#define LIBCAMERA_DISABLE_MOVE(klass)
|
||||
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
|
||||
#endif
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
#define LIBCAMERA_DECLARE_PRIVATE() \
|
||||
public: \
|
||||
class Private; \
|
||||
friend class Private; \
|
||||
template <bool B = true> \
|
||||
const Private *_d() const \
|
||||
{ \
|
||||
return Extensible::_d<Private>(); \
|
||||
} \
|
||||
template <bool B = true> \
|
||||
Private *_d() \
|
||||
{ \
|
||||
return Extensible::_d<Private>(); \
|
||||
}
|
||||
|
||||
#define LIBCAMERA_DECLARE_PUBLIC(klass) \
|
||||
friend class klass; \
|
||||
using Public = klass;
|
||||
|
||||
#define LIBCAMERA_O_PTR() \
|
||||
_o<Public>()
|
||||
|
||||
#else
|
||||
#define LIBCAMERA_DECLARE_PRIVATE()
|
||||
#define LIBCAMERA_DECLARE_PUBLIC(klass)
|
||||
#define LIBCAMERA_O_PTR()
|
||||
#endif
|
||||
|
||||
class Extensible
|
||||
{
|
||||
public:
|
||||
class Private
|
||||
{
|
||||
public:
|
||||
Private();
|
||||
virtual ~Private();
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
template<typename T>
|
||||
const T *_o() const
|
||||
{
|
||||
return static_cast<const T *>(o_);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T *_o()
|
||||
{
|
||||
return static_cast<T *>(o_);
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
/* To initialize o_ from Extensible. */
|
||||
friend class Extensible;
|
||||
Extensible *const o_;
|
||||
};
|
||||
|
||||
Extensible(std::unique_ptr<Private> d);
|
||||
|
||||
protected:
|
||||
template<typename T>
|
||||
const T *_d() const
|
||||
{
|
||||
return static_cast<const T *>(d_.get());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T *_d()
|
||||
{
|
||||
return static_cast<T *>(d_.get());
|
||||
}
|
||||
|
||||
private:
|
||||
const std::unique_ptr<Private> d_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
14
spider-cam/libcamera/include/libcamera/base/compiler.h
Normal file
14
spider-cam/libcamera/include/libcamera/base/compiler.h
Normal file
@@ -0,0 +1,14 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2021, Google Inc.
|
||||
*
|
||||
* Compiler support
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
#define __nodiscard [[nodiscard]]
|
||||
#else
|
||||
#define __nodiscard
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Event dispatcher
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/private.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class EventNotifier;
|
||||
class Timer;
|
||||
|
||||
class EventDispatcher
|
||||
{
|
||||
public:
|
||||
virtual ~EventDispatcher();
|
||||
|
||||
virtual void registerEventNotifier(EventNotifier *notifier) = 0;
|
||||
virtual void unregisterEventNotifier(EventNotifier *notifier) = 0;
|
||||
|
||||
virtual void registerTimer(Timer *timer) = 0;
|
||||
virtual void unregisterTimer(Timer *timer) = 0;
|
||||
|
||||
virtual void processEvents() = 0;
|
||||
|
||||
virtual void interrupt() = 0;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,59 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Poll-based event dispatcher
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/private.h>
|
||||
|
||||
#include <libcamera/base/event_dispatcher.h>
|
||||
#include <libcamera/base/unique_fd.h>
|
||||
|
||||
struct pollfd;
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class EventNotifier;
|
||||
class Timer;
|
||||
|
||||
class EventDispatcherPoll final : public EventDispatcher
|
||||
{
|
||||
public:
|
||||
EventDispatcherPoll();
|
||||
~EventDispatcherPoll();
|
||||
|
||||
void registerEventNotifier(EventNotifier *notifier);
|
||||
void unregisterEventNotifier(EventNotifier *notifier);
|
||||
|
||||
void registerTimer(Timer *timer);
|
||||
void unregisterTimer(Timer *timer);
|
||||
|
||||
void processEvents();
|
||||
void interrupt();
|
||||
|
||||
private:
|
||||
struct EventNotifierSetPoll {
|
||||
short events() const;
|
||||
EventNotifier *notifiers[3];
|
||||
};
|
||||
|
||||
int poll(std::vector<struct pollfd> *pollfds);
|
||||
void processInterrupt(const struct pollfd &pfd);
|
||||
void processNotifiers(const std::vector<struct pollfd> &pollfds);
|
||||
void processTimers();
|
||||
|
||||
std::map<int, EventNotifierSetPoll> notifiers_;
|
||||
std::list<Timer *> timers_;
|
||||
UniqueFD eventfd_;
|
||||
|
||||
bool processingEvents_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
48
spider-cam/libcamera/include/libcamera/base/event_notifier.h
Normal file
48
spider-cam/libcamera/include/libcamera/base/event_notifier.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* File descriptor event notifier
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libcamera/base/private.h>
|
||||
|
||||
#include <libcamera/base/object.h>
|
||||
#include <libcamera/base/signal.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Message;
|
||||
|
||||
class EventNotifier : public Object
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
Read,
|
||||
Write,
|
||||
Exception,
|
||||
};
|
||||
|
||||
EventNotifier(int fd, Type type, Object *parent = nullptr);
|
||||
virtual ~EventNotifier();
|
||||
|
||||
Type type() const { return type_; }
|
||||
int fd() const { return fd_; }
|
||||
|
||||
bool enabled() const { return enabled_; }
|
||||
void setEnabled(bool enable);
|
||||
|
||||
Signal<> activated;
|
||||
|
||||
protected:
|
||||
void message(Message *msg) override;
|
||||
|
||||
private:
|
||||
int fd_;
|
||||
Type type_;
|
||||
bool enabled_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
87
spider-cam/libcamera/include/libcamera/base/file.h
Normal file
87
spider-cam/libcamera/include/libcamera/base/file.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Google Inc.
|
||||
*
|
||||
* File I/O operations
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <libcamera/base/private.h>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
#include <libcamera/base/flags.h>
|
||||
#include <libcamera/base/span.h>
|
||||
#include <libcamera/base/unique_fd.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class File
|
||||
{
|
||||
public:
|
||||
enum class MapFlag {
|
||||
NoOption = 0,
|
||||
Private = (1 << 0),
|
||||
};
|
||||
|
||||
using MapFlags = Flags<MapFlag>;
|
||||
|
||||
enum class OpenModeFlag {
|
||||
NotOpen = 0,
|
||||
ReadOnly = (1 << 0),
|
||||
WriteOnly = (1 << 1),
|
||||
ReadWrite = ReadOnly | WriteOnly,
|
||||
};
|
||||
|
||||
using OpenMode = Flags<OpenModeFlag>;
|
||||
|
||||
File(const std::string &name);
|
||||
File();
|
||||
~File();
|
||||
|
||||
const std::string &fileName() const { return name_; }
|
||||
void setFileName(const std::string &name);
|
||||
bool exists() const;
|
||||
|
||||
bool open(OpenMode mode);
|
||||
bool isOpen() const { return fd_.isValid(); }
|
||||
OpenMode openMode() const { return mode_; }
|
||||
void close();
|
||||
|
||||
int error() const { return error_; }
|
||||
ssize_t size() const;
|
||||
|
||||
off_t pos() const;
|
||||
off_t seek(off_t pos);
|
||||
|
||||
ssize_t read(const Span<uint8_t> &data);
|
||||
ssize_t write(const Span<const uint8_t> &data);
|
||||
|
||||
Span<uint8_t> map(off_t offset = 0, ssize_t size = -1,
|
||||
MapFlags flags = MapFlag::NoOption);
|
||||
bool unmap(uint8_t *addr);
|
||||
|
||||
static bool exists(const std::string &name);
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY(File)
|
||||
|
||||
void unmapAll();
|
||||
|
||||
std::string name_;
|
||||
UniqueFD fd_;
|
||||
OpenMode mode_;
|
||||
|
||||
int error_;
|
||||
std::map<void *, size_t> maps_;
|
||||
};
|
||||
|
||||
LIBCAMERA_FLAGS_ENABLE_OPERATORS(File::MapFlag)
|
||||
LIBCAMERA_FLAGS_ENABLE_OPERATORS(File::OpenModeFlag)
|
||||
|
||||
} /* namespace libcamera */
|
||||
193
spider-cam/libcamera/include/libcamera/base/flags.h
Normal file
193
spider-cam/libcamera/include/libcamera/base/flags.h
Normal file
@@ -0,0 +1,193 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Google Inc.
|
||||
*
|
||||
* Type-safe enum-based bitfields
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
template<typename E>
|
||||
class Flags
|
||||
{
|
||||
public:
|
||||
static_assert(std::is_enum<E>::value,
|
||||
"Flags<> template parameter must be an enum");
|
||||
|
||||
using Type = std::underlying_type_t<E>;
|
||||
|
||||
constexpr Flags()
|
||||
: value_(0)
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Flags(E flag)
|
||||
: value_(static_cast<Type>(flag))
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Flags &operator&=(E flag)
|
||||
{
|
||||
value_ &= static_cast<Type>(flag);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Flags &operator&=(Flags other)
|
||||
{
|
||||
value_ &= other.value_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Flags &operator|=(E flag)
|
||||
{
|
||||
value_ |= static_cast<Type>(flag);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Flags &operator|=(Flags other)
|
||||
{
|
||||
value_ |= other.value_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Flags &operator^=(E flag)
|
||||
{
|
||||
value_ ^= static_cast<Type>(flag);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr Flags &operator^=(Flags other)
|
||||
{
|
||||
value_ ^= other.value_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr bool operator==(E flag)
|
||||
{
|
||||
return value_ == static_cast<Type>(flag);
|
||||
}
|
||||
|
||||
constexpr bool operator==(Flags other)
|
||||
{
|
||||
return value_ == static_cast<Type>(other);
|
||||
}
|
||||
|
||||
constexpr bool operator!=(E flag)
|
||||
{
|
||||
return value_ != static_cast<Type>(flag);
|
||||
}
|
||||
|
||||
constexpr bool operator!=(Flags other)
|
||||
{
|
||||
return value_ != static_cast<Type>(other);
|
||||
}
|
||||
|
||||
constexpr explicit operator Type() const
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
|
||||
constexpr explicit operator bool() const
|
||||
{
|
||||
return !!value_;
|
||||
}
|
||||
|
||||
constexpr Flags operator&(E flag) const
|
||||
{
|
||||
return Flags(static_cast<E>(value_ & static_cast<Type>(flag)));
|
||||
}
|
||||
|
||||
constexpr Flags operator&(Flags other) const
|
||||
{
|
||||
return Flags(static_cast<E>(value_ & other.value_));
|
||||
}
|
||||
|
||||
constexpr Flags operator|(E flag) const
|
||||
{
|
||||
return Flags(static_cast<E>(value_ | static_cast<Type>(flag)));
|
||||
}
|
||||
|
||||
constexpr Flags operator|(Flags other) const
|
||||
{
|
||||
return Flags(static_cast<E>(value_ | other.value_));
|
||||
}
|
||||
|
||||
constexpr Flags operator^(E flag) const
|
||||
{
|
||||
return Flags(static_cast<E>(value_ ^ static_cast<Type>(flag)));
|
||||
}
|
||||
|
||||
constexpr Flags operator^(Flags other) const
|
||||
{
|
||||
return Flags(static_cast<E>(value_ ^ other.value_));
|
||||
}
|
||||
|
||||
constexpr Flags operator~() const
|
||||
{
|
||||
return Flags(static_cast<E>(~value_));
|
||||
}
|
||||
|
||||
constexpr bool operator!() const
|
||||
{
|
||||
return !value_;
|
||||
}
|
||||
|
||||
private:
|
||||
Type value_;
|
||||
};
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
template<typename E>
|
||||
struct flags_enable_operators {
|
||||
static const bool enable = false;
|
||||
};
|
||||
|
||||
template<typename E>
|
||||
std::enable_if_t<flags_enable_operators<E>::enable, Flags<E>>
|
||||
operator|(E lhs, E rhs)
|
||||
{
|
||||
using type = std::underlying_type_t<E>;
|
||||
return Flags<E>(static_cast<E>(static_cast<type>(lhs) | static_cast<type>(rhs)));
|
||||
}
|
||||
|
||||
template<typename E>
|
||||
std::enable_if_t<flags_enable_operators<E>::enable, Flags<E>>
|
||||
operator&(E lhs, E rhs)
|
||||
{
|
||||
using type = std::underlying_type_t<E>;
|
||||
return Flags<E>(static_cast<E>(static_cast<type>(lhs) & static_cast<type>(rhs)));
|
||||
}
|
||||
|
||||
template<typename E>
|
||||
std::enable_if_t<flags_enable_operators<E>::enable, Flags<E>>
|
||||
operator^(E lhs, E rhs)
|
||||
{
|
||||
using type = std::underlying_type_t<E>;
|
||||
return Flags<E>(static_cast<E>(static_cast<type>(lhs) ^ static_cast<type>(rhs)));
|
||||
}
|
||||
|
||||
template<typename E>
|
||||
std::enable_if_t<flags_enable_operators<E>::enable, Flags<E>>
|
||||
operator~(E rhs)
|
||||
{
|
||||
using type = std::underlying_type_t<E>;
|
||||
return Flags<E>(static_cast<E>(~static_cast<type>(rhs)));
|
||||
}
|
||||
|
||||
#define LIBCAMERA_FLAGS_ENABLE_OPERATORS(_enum) \
|
||||
template<> \
|
||||
struct flags_enable_operators<_enum> { \
|
||||
static const bool enable = true; \
|
||||
};
|
||||
|
||||
#else /* __DOXYGEN__ */
|
||||
|
||||
#define LIBCAMERA_FLAGS_ENABLE_OPERATORS(_enum)
|
||||
|
||||
#endif /* __DOXYGEN__ */
|
||||
|
||||
} /* namespace libcamera */
|
||||
136
spider-cam/libcamera/include/libcamera/base/log.h
Normal file
136
spider-cam/libcamera/include/libcamera/base/log.h
Normal file
@@ -0,0 +1,136 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018, Google Inc.
|
||||
*
|
||||
* Logging infrastructure
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <sstream>
|
||||
|
||||
#include <libcamera/base/private.h>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
#include <libcamera/base/utils.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
enum LogSeverity {
|
||||
LogInvalid = -1,
|
||||
LogDebug = 0,
|
||||
LogInfo,
|
||||
LogWarning,
|
||||
LogError,
|
||||
LogFatal,
|
||||
};
|
||||
|
||||
class LogCategory
|
||||
{
|
||||
public:
|
||||
static LogCategory *create(const char *name);
|
||||
|
||||
const std::string &name() const { return name_; }
|
||||
LogSeverity severity() const { return severity_; }
|
||||
void setSeverity(LogSeverity severity);
|
||||
|
||||
static const LogCategory &defaultCategory();
|
||||
|
||||
private:
|
||||
explicit LogCategory(const char *name);
|
||||
|
||||
const std::string name_;
|
||||
LogSeverity severity_;
|
||||
};
|
||||
|
||||
#define LOG_DECLARE_CATEGORY(name) \
|
||||
extern const LogCategory &_LOG_CATEGORY(name)();
|
||||
|
||||
#define LOG_DEFINE_CATEGORY(name) \
|
||||
LOG_DECLARE_CATEGORY(name) \
|
||||
const LogCategory &_LOG_CATEGORY(name)() \
|
||||
{ \
|
||||
/* The instance will be deleted by the Logger destructor. */ \
|
||||
static LogCategory *category = LogCategory::create(#name); \
|
||||
return *category; \
|
||||
}
|
||||
|
||||
class LogMessage
|
||||
{
|
||||
public:
|
||||
LogMessage(const char *fileName, unsigned int line,
|
||||
const LogCategory &category, LogSeverity severity,
|
||||
const std::string &prefix = std::string());
|
||||
|
||||
LogMessage(LogMessage &&);
|
||||
~LogMessage();
|
||||
|
||||
std::ostream &stream() { return msgStream_; }
|
||||
|
||||
const utils::time_point ×tamp() const { return timestamp_; }
|
||||
LogSeverity severity() const { return severity_; }
|
||||
const LogCategory &category() const { return category_; }
|
||||
const std::string &fileInfo() const { return fileInfo_; }
|
||||
const std::string &prefix() const { return prefix_; }
|
||||
const std::string msg() const { return msgStream_.str(); }
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY(LogMessage)
|
||||
|
||||
void init(const char *fileName, unsigned int line);
|
||||
|
||||
std::ostringstream msgStream_;
|
||||
const LogCategory &category_;
|
||||
LogSeverity severity_;
|
||||
utils::time_point timestamp_;
|
||||
std::string fileInfo_;
|
||||
std::string prefix_;
|
||||
};
|
||||
|
||||
class Loggable
|
||||
{
|
||||
public:
|
||||
virtual ~Loggable();
|
||||
|
||||
protected:
|
||||
virtual std::string logPrefix() const = 0;
|
||||
|
||||
LogMessage _log(const LogCategory *category, LogSeverity severity,
|
||||
const char *fileName = __builtin_FILE(),
|
||||
unsigned int line = __builtin_LINE()) const;
|
||||
};
|
||||
|
||||
LogMessage _log(const LogCategory *category, LogSeverity severity,
|
||||
const char *fileName = __builtin_FILE(),
|
||||
unsigned int line = __builtin_LINE());
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
#define _LOG_CATEGORY(name) logCategory##name
|
||||
|
||||
#define _LOG1(severity) \
|
||||
_log(nullptr, Log##severity).stream()
|
||||
#define _LOG2(category, severity) \
|
||||
_log(&_LOG_CATEGORY(category)(), Log##severity).stream()
|
||||
|
||||
/*
|
||||
* Expand the LOG() macro to _LOG1() or _LOG2() based on the number of
|
||||
* arguments.
|
||||
*/
|
||||
#define _LOG_MACRO(_1, _2, NAME, ...) NAME
|
||||
#define LOG(...) _LOG_MACRO(__VA_ARGS__, _LOG2, _LOG1)(__VA_ARGS__)
|
||||
#else /* __DOXYGEN___ */
|
||||
#define LOG(category, severity)
|
||||
#endif /* __DOXYGEN__ */
|
||||
|
||||
#ifndef NDEBUG
|
||||
#define ASSERT(condition) static_cast<void>(({ \
|
||||
if (!(condition)) \
|
||||
LOG(Fatal) << "assertion \"" #condition "\" failed in " \
|
||||
<< __func__ << "()"; \
|
||||
}))
|
||||
#else
|
||||
#define ASSERT(condition) static_cast<void>(false && (condition))
|
||||
#endif
|
||||
|
||||
} /* namespace libcamera */
|
||||
40
spider-cam/libcamera/include/libcamera/base/meson.build
Normal file
40
spider-cam/libcamera/include/libcamera/base/meson.build
Normal file
@@ -0,0 +1,40 @@
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
libcamera_base_include_dir = libcamera_include_dir / 'base'
|
||||
|
||||
libcamera_base_public_headers = files([
|
||||
'bound_method.h',
|
||||
'class.h',
|
||||
'compiler.h',
|
||||
'flags.h',
|
||||
'object.h',
|
||||
'shared_fd.h',
|
||||
'signal.h',
|
||||
'span.h',
|
||||
'unique_fd.h',
|
||||
])
|
||||
|
||||
libcamera_base_private_headers = files([
|
||||
'backtrace.h',
|
||||
'event_dispatcher.h',
|
||||
'event_dispatcher_poll.h',
|
||||
'event_notifier.h',
|
||||
'file.h',
|
||||
'log.h',
|
||||
'message.h',
|
||||
'mutex.h',
|
||||
'private.h',
|
||||
'semaphore.h',
|
||||
'thread.h',
|
||||
'thread_annotations.h',
|
||||
'timer.h',
|
||||
'utils.h',
|
||||
])
|
||||
|
||||
libcamera_base_headers = [
|
||||
libcamera_base_public_headers,
|
||||
libcamera_base_private_headers,
|
||||
]
|
||||
|
||||
install_headers(libcamera_base_public_headers,
|
||||
subdir : libcamera_base_include_dir)
|
||||
71
spider-cam/libcamera/include/libcamera/base/message.h
Normal file
71
spider-cam/libcamera/include/libcamera/base/message.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Message queue support
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include <libcamera/base/private.h>
|
||||
|
||||
#include <libcamera/base/bound_method.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class BoundMethodBase;
|
||||
class Object;
|
||||
class Semaphore;
|
||||
class Thread;
|
||||
|
||||
class Message
|
||||
{
|
||||
public:
|
||||
enum Type {
|
||||
None = 0,
|
||||
InvokeMessage = 1,
|
||||
ThreadMoveMessage = 2,
|
||||
DeferredDelete = 3,
|
||||
UserMessage = 1000,
|
||||
};
|
||||
|
||||
Message(Type type);
|
||||
virtual ~Message();
|
||||
|
||||
Type type() const { return type_; }
|
||||
Object *receiver() const { return receiver_; }
|
||||
|
||||
static Type registerMessageType();
|
||||
|
||||
private:
|
||||
friend class Thread;
|
||||
|
||||
Type type_;
|
||||
Object *receiver_;
|
||||
|
||||
static std::atomic_uint nextUserType_;
|
||||
};
|
||||
|
||||
class InvokeMessage : public Message
|
||||
{
|
||||
public:
|
||||
InvokeMessage(BoundMethodBase *method,
|
||||
std::shared_ptr<BoundMethodPackBase> pack,
|
||||
Semaphore *semaphore = nullptr,
|
||||
bool deleteMethod = false);
|
||||
~InvokeMessage();
|
||||
|
||||
Semaphore *semaphore() const { return semaphore_; }
|
||||
|
||||
void invoke();
|
||||
|
||||
private:
|
||||
BoundMethodBase *method_;
|
||||
std::shared_ptr<BoundMethodPackBase> pack_;
|
||||
Semaphore *semaphore_;
|
||||
bool deleteMethod_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
134
spider-cam/libcamera/include/libcamera/base/mutex.h
Normal file
134
spider-cam/libcamera/include/libcamera/base/mutex.h
Normal file
@@ -0,0 +1,134 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2021, Google Inc.
|
||||
*
|
||||
* Mutex classes with clang thread safety annotation
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
|
||||
#include <libcamera/base/private.h>
|
||||
|
||||
#include <libcamera/base/thread_annotations.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
/* \todo using Mutex = std::mutex if libc++ is used. */
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
|
||||
class LIBCAMERA_TSA_CAPABILITY("mutex") Mutex final
|
||||
{
|
||||
public:
|
||||
constexpr Mutex()
|
||||
{
|
||||
}
|
||||
|
||||
void lock() LIBCAMERA_TSA_ACQUIRE()
|
||||
{
|
||||
mutex_.lock();
|
||||
}
|
||||
|
||||
void unlock() LIBCAMERA_TSA_RELEASE()
|
||||
{
|
||||
mutex_.unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
friend class MutexLocker;
|
||||
|
||||
std::mutex mutex_;
|
||||
};
|
||||
|
||||
class LIBCAMERA_TSA_SCOPED_CAPABILITY MutexLocker final
|
||||
{
|
||||
public:
|
||||
explicit MutexLocker(Mutex &mutex) LIBCAMERA_TSA_ACQUIRE(mutex)
|
||||
: lock_(mutex.mutex_)
|
||||
{
|
||||
}
|
||||
|
||||
MutexLocker(Mutex &mutex, std::defer_lock_t t) noexcept LIBCAMERA_TSA_EXCLUDES(mutex)
|
||||
: lock_(mutex.mutex_, t)
|
||||
{
|
||||
}
|
||||
|
||||
~MutexLocker() LIBCAMERA_TSA_RELEASE()
|
||||
{
|
||||
}
|
||||
|
||||
void lock() LIBCAMERA_TSA_ACQUIRE()
|
||||
{
|
||||
lock_.lock();
|
||||
}
|
||||
|
||||
bool try_lock() LIBCAMERA_TSA_TRY_ACQUIRE(true)
|
||||
{
|
||||
return lock_.try_lock();
|
||||
}
|
||||
|
||||
void unlock() LIBCAMERA_TSA_RELEASE()
|
||||
{
|
||||
lock_.unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
friend class ConditionVariable;
|
||||
|
||||
std::unique_lock<std::mutex> lock_;
|
||||
};
|
||||
|
||||
class ConditionVariable final
|
||||
{
|
||||
public:
|
||||
ConditionVariable()
|
||||
{
|
||||
}
|
||||
|
||||
void notify_one() noexcept
|
||||
{
|
||||
cv_.notify_one();
|
||||
}
|
||||
|
||||
void notify_all() noexcept
|
||||
{
|
||||
cv_.notify_all();
|
||||
}
|
||||
|
||||
template<class Predicate>
|
||||
void wait(MutexLocker &locker, Predicate stopWaiting)
|
||||
{
|
||||
cv_.wait(locker.lock_, stopWaiting);
|
||||
}
|
||||
|
||||
template<class Rep, class Period, class Predicate>
|
||||
bool wait_for(MutexLocker &locker,
|
||||
const std::chrono::duration<Rep, Period> &relTime,
|
||||
Predicate stopWaiting)
|
||||
{
|
||||
return cv_.wait_for(locker.lock_, relTime, stopWaiting);
|
||||
}
|
||||
|
||||
private:
|
||||
std::condition_variable cv_;
|
||||
};
|
||||
|
||||
#else /* __DOXYGEN__ */
|
||||
|
||||
class Mutex final
|
||||
{
|
||||
};
|
||||
|
||||
class MutexLocker final
|
||||
{
|
||||
};
|
||||
|
||||
class ConditionVariable final
|
||||
{
|
||||
};
|
||||
|
||||
#endif /* __DOXYGEN__ */
|
||||
} /* namespace libcamera */
|
||||
71
spider-cam/libcamera/include/libcamera/base/object.h
Normal file
71
spider-cam/libcamera/include/libcamera/base/object.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Base object
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/bound_method.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Message;
|
||||
template<typename... Args>
|
||||
class Signal;
|
||||
class SignalBase;
|
||||
class Thread;
|
||||
|
||||
class Object
|
||||
{
|
||||
public:
|
||||
Object(Object *parent = nullptr);
|
||||
virtual ~Object();
|
||||
|
||||
void deleteLater();
|
||||
|
||||
void postMessage(std::unique_ptr<Message> msg);
|
||||
|
||||
template<typename T, typename R, typename... FuncArgs, typename... Args,
|
||||
std::enable_if_t<std::is_base_of<Object, T>::value> * = nullptr>
|
||||
R invokeMethod(R (T::*func)(FuncArgs...), ConnectionType type,
|
||||
Args&&... args)
|
||||
{
|
||||
T *obj = static_cast<T *>(this);
|
||||
auto *method = new BoundMethodMember<T, R, FuncArgs...>(obj, this, func, type);
|
||||
return method->activate(args..., true);
|
||||
}
|
||||
|
||||
Thread *thread() const { return thread_; }
|
||||
void moveToThread(Thread *thread);
|
||||
|
||||
Object *parent() const { return parent_; }
|
||||
|
||||
protected:
|
||||
virtual void message(Message *msg);
|
||||
|
||||
bool assertThreadBound(const char *message);
|
||||
|
||||
private:
|
||||
friend class SignalBase;
|
||||
friend class Thread;
|
||||
|
||||
void notifyThreadMove();
|
||||
|
||||
void connect(SignalBase *signal);
|
||||
void disconnect(SignalBase *signal);
|
||||
|
||||
Object *parent_;
|
||||
std::vector<Object *> children_;
|
||||
|
||||
Thread *thread_;
|
||||
std::list<SignalBase *> signals_;
|
||||
unsigned int pendingMessages_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
22
spider-cam/libcamera/include/libcamera/base/private.h
Normal file
22
spider-cam/libcamera/include/libcamera/base/private.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2021, Google Inc.
|
||||
*
|
||||
* Private Header Validation
|
||||
*
|
||||
* A selection of internal libcamera headers are installed as part
|
||||
* of the libcamera package to allow sharing of a select subset of
|
||||
* internal functionality with IPA module only.
|
||||
*
|
||||
* This functionality is not considered part of the public libcamera
|
||||
* API, and can therefore potentially face ABI instabilities which
|
||||
* should not be exposed to applications. IPA modules however should be
|
||||
* versioned and more closely matched to the libcamera installation.
|
||||
*
|
||||
* Components which include this file can not be included in any file
|
||||
* which forms part of the libcamera API.
|
||||
*/
|
||||
|
||||
#ifndef LIBCAMERA_BASE_PRIVATE
|
||||
#error "Private headers must not be included in the libcamera API"
|
||||
#endif
|
||||
32
spider-cam/libcamera/include/libcamera/base/semaphore.h
Normal file
32
spider-cam/libcamera/include/libcamera/base/semaphore.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* General-purpose counting semaphore
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libcamera/base/private.h>
|
||||
|
||||
#include <libcamera/base/mutex.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Semaphore
|
||||
{
|
||||
public:
|
||||
Semaphore(unsigned int n = 0);
|
||||
|
||||
unsigned int available() LIBCAMERA_TSA_EXCLUDES(mutex_);
|
||||
void acquire(unsigned int n = 1) LIBCAMERA_TSA_EXCLUDES(mutex_);
|
||||
bool tryAcquire(unsigned int n = 1) LIBCAMERA_TSA_EXCLUDES(mutex_);
|
||||
void release(unsigned int n = 1) LIBCAMERA_TSA_EXCLUDES(mutex_);
|
||||
|
||||
private:
|
||||
Mutex mutex_;
|
||||
ConditionVariable cv_;
|
||||
unsigned int available_ LIBCAMERA_TSA_GUARDED_BY(mutex_);
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
59
spider-cam/libcamera/include/libcamera/base/shared_fd.h
Normal file
59
spider-cam/libcamera/include/libcamera/base/shared_fd.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* File descriptor wrapper with shared ownership
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class UniqueFD;
|
||||
|
||||
class SharedFD final
|
||||
{
|
||||
public:
|
||||
explicit SharedFD(const int &fd = -1);
|
||||
explicit SharedFD(int &&fd);
|
||||
explicit SharedFD(UniqueFD fd);
|
||||
SharedFD(const SharedFD &other);
|
||||
SharedFD(SharedFD &&other);
|
||||
~SharedFD();
|
||||
|
||||
SharedFD &operator=(const SharedFD &other);
|
||||
SharedFD &operator=(SharedFD &&other);
|
||||
|
||||
bool isValid() const { return fd_ != nullptr; }
|
||||
int get() const { return fd_ ? fd_->fd() : -1; }
|
||||
UniqueFD dup() const;
|
||||
|
||||
private:
|
||||
class Descriptor
|
||||
{
|
||||
public:
|
||||
Descriptor(int fd, bool duplicate);
|
||||
~Descriptor();
|
||||
|
||||
int fd() const { return fd_; }
|
||||
|
||||
private:
|
||||
int fd_;
|
||||
};
|
||||
|
||||
std::shared_ptr<Descriptor> fd_;
|
||||
};
|
||||
|
||||
static inline bool operator==(const SharedFD &lhs, const SharedFD &rhs)
|
||||
{
|
||||
return lhs.get() == rhs.get();
|
||||
}
|
||||
|
||||
static inline bool operator!=(const SharedFD &lhs, const SharedFD &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
} /* namespace libcamera */
|
||||
158
spider-cam/libcamera/include/libcamera/base/signal.h
Normal file
158
spider-cam/libcamera/include/libcamera/base/signal.h
Normal file
@@ -0,0 +1,158 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Signal & slot implementation
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/bound_method.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Object;
|
||||
|
||||
class SignalBase
|
||||
{
|
||||
public:
|
||||
void disconnect(Object *object);
|
||||
|
||||
protected:
|
||||
using SlotList = std::list<BoundMethodBase *>;
|
||||
|
||||
void connect(BoundMethodBase *slot);
|
||||
void disconnect(std::function<bool(SlotList::iterator &)> match);
|
||||
|
||||
SlotList slots();
|
||||
|
||||
private:
|
||||
SlotList slots_;
|
||||
};
|
||||
|
||||
template<typename... Args>
|
||||
class Signal : public SignalBase
|
||||
{
|
||||
public:
|
||||
~Signal()
|
||||
{
|
||||
disconnect();
|
||||
}
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
template<typename T, typename R, std::enable_if_t<std::is_base_of<Object, T>::value> * = nullptr>
|
||||
void connect(T *obj, R (T::*func)(Args...),
|
||||
ConnectionType type = ConnectionTypeAuto)
|
||||
{
|
||||
Object *object = static_cast<Object *>(obj);
|
||||
SignalBase::connect(new BoundMethodMember<T, R, Args...>(obj, object, func, type));
|
||||
}
|
||||
|
||||
template<typename T, typename R, std::enable_if_t<!std::is_base_of<Object, T>::value> * = nullptr>
|
||||
#else
|
||||
template<typename T, typename R>
|
||||
#endif
|
||||
void connect(T *obj, R (T::*func)(Args...))
|
||||
{
|
||||
SignalBase::connect(new BoundMethodMember<T, R, Args...>(obj, nullptr, func));
|
||||
}
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
template<typename T, typename Func,
|
||||
std::enable_if_t<std::is_base_of<Object, T>::value
|
||||
#if __cplusplus >= 201703L
|
||||
&& std::is_invocable_v<Func, Args...>
|
||||
#endif
|
||||
> * = nullptr>
|
||||
void connect(T *obj, Func func, ConnectionType type = ConnectionTypeAuto)
|
||||
{
|
||||
Object *object = static_cast<Object *>(obj);
|
||||
SignalBase::connect(new BoundMethodFunctor<T, void, Func, Args...>(obj, object, func, type));
|
||||
}
|
||||
|
||||
template<typename T, typename Func,
|
||||
std::enable_if_t<!std::is_base_of<Object, T>::value
|
||||
#if __cplusplus >= 201703L
|
||||
&& std::is_invocable_v<Func, Args...>
|
||||
#endif
|
||||
> * = nullptr>
|
||||
#else
|
||||
template<typename T, typename Func>
|
||||
#endif
|
||||
void connect(T *obj, Func func)
|
||||
{
|
||||
SignalBase::connect(new BoundMethodFunctor<T, void, Func, Args...>(obj, nullptr, func));
|
||||
}
|
||||
|
||||
template<typename R>
|
||||
void connect(R (*func)(Args...))
|
||||
{
|
||||
SignalBase::connect(new BoundMethodStatic<R, Args...>(func));
|
||||
}
|
||||
|
||||
void disconnect()
|
||||
{
|
||||
SignalBase::disconnect([]([[maybe_unused]] SlotList::iterator &iter) {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void disconnect(T *obj)
|
||||
{
|
||||
SignalBase::disconnect([obj](SlotList::iterator &iter) {
|
||||
return (*iter)->match(obj);
|
||||
});
|
||||
}
|
||||
|
||||
template<typename T, typename R>
|
||||
void disconnect(T *obj, R (T::*func)(Args...))
|
||||
{
|
||||
SignalBase::disconnect([obj, func](SlotList::iterator &iter) {
|
||||
BoundMethodArgs<R, Args...> *slot =
|
||||
static_cast<BoundMethodArgs<R, Args...> *>(*iter);
|
||||
|
||||
if (!slot->match(obj))
|
||||
return false;
|
||||
|
||||
/*
|
||||
* If the object matches the slot, the slot is
|
||||
* guaranteed to be a member slot, so we can safely
|
||||
* cast it to BoundMethodMember<T, Args...> to match
|
||||
* func.
|
||||
*/
|
||||
return static_cast<BoundMethodMember<T, R, Args...> *>(slot)->match(func);
|
||||
});
|
||||
}
|
||||
|
||||
template<typename R>
|
||||
void disconnect(R (*func)(Args...))
|
||||
{
|
||||
SignalBase::disconnect([func](SlotList::iterator &iter) {
|
||||
BoundMethodArgs<R, Args...> *slot =
|
||||
static_cast<BoundMethodArgs<R, Args...> *>(*iter);
|
||||
|
||||
if (!slot->match(nullptr))
|
||||
return false;
|
||||
|
||||
return static_cast<BoundMethodStatic<R, Args...> *>(slot)->match(func);
|
||||
});
|
||||
}
|
||||
|
||||
void emit(Args... args)
|
||||
{
|
||||
/*
|
||||
* Make a copy of the slots list as the slot could call the
|
||||
* disconnect operation, invalidating the iterator.
|
||||
*/
|
||||
for (BoundMethodBase *slot : slots())
|
||||
static_cast<BoundMethodArgs<void, Args...> *>(slot)->activate(args...);
|
||||
}
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
421
spider-cam/libcamera/include/libcamera/base/span.h
Normal file
421
spider-cam/libcamera/include/libcamera/base/span.h
Normal file
@@ -0,0 +1,421 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Google Inc.
|
||||
*
|
||||
* C++20 std::span<> implementation for C++11
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <stddef.h>
|
||||
#include <type_traits>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
static constexpr std::size_t dynamic_extent = std::numeric_limits<std::size_t>::max();
|
||||
|
||||
template<typename T, std::size_t Extent = dynamic_extent>
|
||||
class Span;
|
||||
|
||||
namespace details {
|
||||
|
||||
template<typename U>
|
||||
struct is_array : public std::false_type {
|
||||
};
|
||||
|
||||
template<typename U, std::size_t N>
|
||||
struct is_array<std::array<U, N>> : public std::true_type {
|
||||
};
|
||||
|
||||
template<typename U>
|
||||
struct is_span : public std::false_type {
|
||||
};
|
||||
|
||||
template<typename U, std::size_t Extent>
|
||||
struct is_span<Span<U, Extent>> : public std::true_type {
|
||||
};
|
||||
|
||||
} /* namespace details */
|
||||
|
||||
namespace utils {
|
||||
|
||||
template<typename C>
|
||||
constexpr auto size(const C &c) -> decltype(c.size())
|
||||
{
|
||||
return c.size();
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
constexpr auto data(const C &c) -> decltype(c.data())
|
||||
{
|
||||
return c.data();
|
||||
}
|
||||
|
||||
template<typename C>
|
||||
constexpr auto data(C &c) -> decltype(c.data())
|
||||
{
|
||||
return c.data();
|
||||
}
|
||||
|
||||
template<class T, std::size_t N>
|
||||
constexpr T *data(T (&array)[N]) noexcept
|
||||
{
|
||||
return array;
|
||||
}
|
||||
|
||||
template<std::size_t I, typename T>
|
||||
struct tuple_element;
|
||||
|
||||
template<std::size_t I, typename T, std::size_t N>
|
||||
struct tuple_element<I, Span<T, N>> {
|
||||
using type = T;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct tuple_size;
|
||||
|
||||
template<typename T, std::size_t N>
|
||||
struct tuple_size<Span<T, N>> : public std::integral_constant<std::size_t, N> {
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct tuple_size<Span<T, dynamic_extent>>;
|
||||
|
||||
} /* namespace utils */
|
||||
|
||||
template<typename T, std::size_t Extent>
|
||||
class Span
|
||||
{
|
||||
public:
|
||||
using element_type = T;
|
||||
using value_type = typename std::remove_cv_t<T>;
|
||||
using size_type = std::size_t;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = T *;
|
||||
using const_pointer = const T *;
|
||||
using reference = T &;
|
||||
using const_reference = const T &;
|
||||
using iterator = pointer;
|
||||
using const_iterator = const_pointer;
|
||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||
|
||||
static constexpr std::size_t extent = Extent;
|
||||
|
||||
template<bool Dependent = false,
|
||||
typename = std::enable_if_t<Dependent || Extent == 0>>
|
||||
constexpr Span() noexcept
|
||||
: data_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
explicit constexpr Span(pointer ptr, [[maybe_unused]] size_type count)
|
||||
: data_(ptr)
|
||||
{
|
||||
}
|
||||
|
||||
explicit constexpr Span(pointer first, [[maybe_unused]] pointer last)
|
||||
: data_(first)
|
||||
{
|
||||
}
|
||||
|
||||
template<std::size_t N>
|
||||
constexpr Span(element_type (&arr)[N],
|
||||
std::enable_if_t<std::is_convertible<std::remove_pointer_t<decltype(utils::data(arr))> (*)[],
|
||||
element_type (*)[]>::value &&
|
||||
N == Extent,
|
||||
std::nullptr_t> = nullptr) noexcept
|
||||
: data_(arr)
|
||||
{
|
||||
}
|
||||
|
||||
template<std::size_t N>
|
||||
constexpr Span(std::array<value_type, N> &arr,
|
||||
std::enable_if_t<std::is_convertible<std::remove_pointer_t<decltype(utils::data(arr))> (*)[],
|
||||
element_type (*)[]>::value &&
|
||||
N == Extent,
|
||||
std::nullptr_t> = nullptr) noexcept
|
||||
: data_(arr.data())
|
||||
{
|
||||
}
|
||||
|
||||
template<std::size_t N>
|
||||
constexpr Span(const std::array<value_type, N> &arr,
|
||||
std::enable_if_t<std::is_convertible<std::remove_pointer_t<decltype(utils::data(arr))> (*)[],
|
||||
element_type (*)[]>::value &&
|
||||
N == Extent,
|
||||
std::nullptr_t> = nullptr) noexcept
|
||||
: data_(arr.data())
|
||||
{
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
explicit constexpr Span(Container &cont,
|
||||
std::enable_if_t<!details::is_span<Container>::value &&
|
||||
!details::is_array<Container>::value &&
|
||||
!std::is_array<Container>::value &&
|
||||
std::is_convertible<std::remove_pointer_t<decltype(utils::data(cont))> (*)[],
|
||||
element_type (*)[]>::value,
|
||||
std::nullptr_t> = nullptr)
|
||||
: data_(utils::data(cont))
|
||||
{
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
explicit constexpr Span(const Container &cont,
|
||||
std::enable_if_t<!details::is_span<Container>::value &&
|
||||
!details::is_array<Container>::value &&
|
||||
!std::is_array<Container>::value &&
|
||||
std::is_convertible<std::remove_pointer_t<decltype(utils::data(cont))> (*)[],
|
||||
element_type (*)[]>::value,
|
||||
std::nullptr_t> = nullptr)
|
||||
: data_(utils::data(cont))
|
||||
{
|
||||
static_assert(utils::size(cont) == Extent, "Size mismatch");
|
||||
}
|
||||
|
||||
template<class U, std::size_t N>
|
||||
explicit constexpr Span(const Span<U, N> &s,
|
||||
std::enable_if_t<std::is_convertible<U (*)[], element_type (*)[]>::value &&
|
||||
N == Extent,
|
||||
std::nullptr_t> = nullptr) noexcept
|
||||
: data_(s.data())
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Span(const Span &other) noexcept = default;
|
||||
constexpr Span &operator=(const Span &other) noexcept = default;
|
||||
|
||||
constexpr iterator begin() const { return data(); }
|
||||
constexpr const_iterator cbegin() const { return begin(); }
|
||||
constexpr iterator end() const { return data() + size(); }
|
||||
constexpr const_iterator cend() const { return end(); }
|
||||
constexpr reverse_iterator rbegin() const { return reverse_iterator(end()); }
|
||||
constexpr const_reverse_iterator crbegin() const { return rbegin(); }
|
||||
constexpr reverse_iterator rend() const { return reverse_iterator(begin()); }
|
||||
constexpr const_reverse_iterator crend() const { return rend(); }
|
||||
|
||||
constexpr reference front() const { return *data(); }
|
||||
constexpr reference back() const { return *(data() + size() - 1); }
|
||||
constexpr reference operator[](size_type idx) const { return data()[idx]; }
|
||||
constexpr pointer data() const noexcept { return data_; }
|
||||
|
||||
constexpr size_type size() const noexcept { return Extent; }
|
||||
constexpr size_type size_bytes() const noexcept { return size() * sizeof(element_type); }
|
||||
constexpr bool empty() const noexcept { return size() == 0; }
|
||||
|
||||
template<std::size_t Count>
|
||||
constexpr Span<element_type, Count> first() const
|
||||
{
|
||||
static_assert(Count <= Extent, "Count larger than size");
|
||||
return Span<element_type, Count>{ data(), Count };
|
||||
}
|
||||
|
||||
constexpr Span<element_type, dynamic_extent> first(std::size_t Count) const
|
||||
{
|
||||
return Span<element_type, dynamic_extent>{ data(), Count };
|
||||
}
|
||||
|
||||
template<std::size_t Count>
|
||||
constexpr Span<element_type, Count> last() const
|
||||
{
|
||||
static_assert(Count <= Extent, "Count larger than size");
|
||||
return Span<element_type, Count>{ data() + size() - Count, Count };
|
||||
}
|
||||
|
||||
constexpr Span<element_type, dynamic_extent> last(std::size_t Count) const
|
||||
{
|
||||
return Span<element_type, dynamic_extent>{ data() + size() - Count, Count };
|
||||
}
|
||||
|
||||
template<std::size_t Offset, std::size_t Count = dynamic_extent>
|
||||
constexpr Span<element_type, Count != dynamic_extent ? Count : Extent - Offset> subspan() const
|
||||
{
|
||||
static_assert(Offset <= Extent, "Offset larger than size");
|
||||
static_assert(Count == dynamic_extent || Count + Offset <= Extent,
|
||||
"Offset + Count larger than size");
|
||||
return Span<element_type, Count != dynamic_extent ? Count : Extent - Offset>{
|
||||
data() + Offset,
|
||||
Count == dynamic_extent ? size() - Offset : Count
|
||||
};
|
||||
}
|
||||
|
||||
constexpr Span<element_type, dynamic_extent>
|
||||
subspan(std::size_t Offset, std::size_t Count = dynamic_extent) const
|
||||
{
|
||||
return Span<element_type, dynamic_extent>{
|
||||
data() + Offset,
|
||||
Count == dynamic_extent ? size() - Offset : Count
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
pointer data_;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class Span<T, dynamic_extent>
|
||||
{
|
||||
public:
|
||||
using element_type = T;
|
||||
using value_type = typename std::remove_cv_t<T>;
|
||||
using size_type = std::size_t;
|
||||
using difference_type = std::ptrdiff_t;
|
||||
using pointer = T *;
|
||||
using const_pointer = const T *;
|
||||
using reference = T &;
|
||||
using const_reference = const T &;
|
||||
using iterator = T *;
|
||||
using const_iterator = const T *;
|
||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||
|
||||
static constexpr std::size_t extent = dynamic_extent;
|
||||
|
||||
constexpr Span() noexcept
|
||||
: data_(nullptr), size_(0)
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Span(pointer ptr, size_type count)
|
||||
: data_(ptr), size_(count)
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Span(pointer first, pointer last)
|
||||
: data_(first), size_(last - first)
|
||||
{
|
||||
}
|
||||
|
||||
template<std::size_t N>
|
||||
constexpr Span(element_type (&arr)[N],
|
||||
std::enable_if_t<std::is_convertible<std::remove_pointer_t<decltype(utils::data(arr))> (*)[],
|
||||
element_type (*)[]>::value,
|
||||
std::nullptr_t> = nullptr) noexcept
|
||||
: data_(arr), size_(N)
|
||||
{
|
||||
}
|
||||
|
||||
template<std::size_t N>
|
||||
constexpr Span(std::array<value_type, N> &arr,
|
||||
std::enable_if_t<std::is_convertible<std::remove_pointer_t<decltype(utils::data(arr))> (*)[],
|
||||
element_type (*)[]>::value,
|
||||
std::nullptr_t> = nullptr) noexcept
|
||||
: data_(utils::data(arr)), size_(N)
|
||||
{
|
||||
}
|
||||
|
||||
template<std::size_t N>
|
||||
constexpr Span(const std::array<value_type, N> &arr) noexcept
|
||||
: data_(utils::data(arr)), size_(N)
|
||||
{
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
constexpr Span(Container &cont,
|
||||
std::enable_if_t<!details::is_span<Container>::value &&
|
||||
!details::is_array<Container>::value &&
|
||||
!std::is_array<Container>::value &&
|
||||
std::is_convertible<std::remove_pointer_t<decltype(utils::data(cont))> (*)[],
|
||||
element_type (*)[]>::value,
|
||||
std::nullptr_t> = nullptr)
|
||||
: data_(utils::data(cont)), size_(utils::size(cont))
|
||||
{
|
||||
}
|
||||
|
||||
template<class Container>
|
||||
constexpr Span(const Container &cont,
|
||||
std::enable_if_t<!details::is_span<Container>::value &&
|
||||
!details::is_array<Container>::value &&
|
||||
!std::is_array<Container>::value &&
|
||||
std::is_convertible<std::remove_pointer_t<decltype(utils::data(cont))> (*)[],
|
||||
element_type (*)[]>::value,
|
||||
std::nullptr_t> = nullptr)
|
||||
: data_(utils::data(cont)), size_(utils::size(cont))
|
||||
{
|
||||
}
|
||||
|
||||
template<class U, std::size_t N>
|
||||
constexpr Span(const Span<U, N> &s,
|
||||
std::enable_if_t<std::is_convertible<U (*)[], element_type (*)[]>::value,
|
||||
std::nullptr_t> = nullptr) noexcept
|
||||
: data_(s.data()), size_(s.size())
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Span(const Span &other) noexcept = default;
|
||||
|
||||
constexpr Span &operator=(const Span &other) noexcept
|
||||
{
|
||||
data_ = other.data_;
|
||||
size_ = other.size_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr iterator begin() const { return data(); }
|
||||
constexpr const_iterator cbegin() const { return begin(); }
|
||||
constexpr iterator end() const { return data() + size(); }
|
||||
constexpr const_iterator cend() const { return end(); }
|
||||
constexpr reverse_iterator rbegin() const { return reverse_iterator(end()); }
|
||||
constexpr const_reverse_iterator crbegin() const { return rbegin(); }
|
||||
constexpr reverse_iterator rend() const { return reverse_iterator(begin()); }
|
||||
constexpr const_reverse_iterator crend() const { return rend(); }
|
||||
|
||||
constexpr reference front() const { return *data(); }
|
||||
constexpr reference back() const { return *(data() + size() - 1); }
|
||||
constexpr reference operator[](size_type idx) const { return data()[idx]; }
|
||||
constexpr pointer data() const noexcept { return data_; }
|
||||
|
||||
constexpr size_type size() const noexcept { return size_; }
|
||||
constexpr size_type size_bytes() const noexcept { return size() * sizeof(element_type); }
|
||||
constexpr bool empty() const noexcept { return size() == 0; }
|
||||
|
||||
template<std::size_t Count>
|
||||
constexpr Span<element_type, Count> first() const
|
||||
{
|
||||
return Span<element_type, Count>{ data(), Count };
|
||||
}
|
||||
|
||||
constexpr Span<element_type, dynamic_extent> first(std::size_t Count) const
|
||||
{
|
||||
return { data(), Count };
|
||||
}
|
||||
|
||||
template<std::size_t Count>
|
||||
constexpr Span<element_type, Count> last() const
|
||||
{
|
||||
return Span<element_type, Count>{ data() + size() - Count, Count };
|
||||
}
|
||||
|
||||
constexpr Span<element_type, dynamic_extent> last(std::size_t Count) const
|
||||
{
|
||||
return Span<element_type, dynamic_extent>{ data() + size() - Count, Count };
|
||||
}
|
||||
|
||||
template<std::size_t Offset, std::size_t Count = dynamic_extent>
|
||||
constexpr Span<element_type, Count> subspan() const
|
||||
{
|
||||
return Span<element_type, Count>{
|
||||
data() + Offset,
|
||||
Count == dynamic_extent ? size() - Offset : Count
|
||||
};
|
||||
}
|
||||
|
||||
constexpr Span<element_type, dynamic_extent>
|
||||
subspan(std::size_t Offset, std::size_t Count = dynamic_extent) const
|
||||
{
|
||||
return Span<element_type, dynamic_extent>{
|
||||
data() + Offset,
|
||||
Count == dynamic_extent ? size() - Offset : Count
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
pointer data_;
|
||||
size_type size_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
72
spider-cam/libcamera/include/libcamera/base/thread.h
Normal file
72
spider-cam/libcamera/include/libcamera/base/thread.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Thread support
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <sys/types.h>
|
||||
#include <thread>
|
||||
|
||||
#include <libcamera/base/private.h>
|
||||
|
||||
#include <libcamera/base/message.h>
|
||||
#include <libcamera/base/signal.h>
|
||||
#include <libcamera/base/utils.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class EventDispatcher;
|
||||
class Message;
|
||||
class Object;
|
||||
class ThreadData;
|
||||
class ThreadMain;
|
||||
|
||||
class Thread
|
||||
{
|
||||
public:
|
||||
Thread();
|
||||
virtual ~Thread();
|
||||
|
||||
void start();
|
||||
void exit(int code = 0);
|
||||
bool wait(utils::duration duration = utils::duration::max());
|
||||
|
||||
bool isRunning();
|
||||
|
||||
Signal<> finished;
|
||||
|
||||
static Thread *current();
|
||||
static pid_t currentId();
|
||||
|
||||
EventDispatcher *eventDispatcher();
|
||||
|
||||
void dispatchMessages(Message::Type type = Message::Type::None);
|
||||
|
||||
protected:
|
||||
int exec();
|
||||
virtual void run();
|
||||
|
||||
private:
|
||||
void startThread();
|
||||
void finishThread();
|
||||
|
||||
void postMessage(std::unique_ptr<Message> msg, Object *receiver);
|
||||
void removeMessages(Object *receiver);
|
||||
|
||||
friend class Object;
|
||||
friend class ThreadData;
|
||||
friend class ThreadMain;
|
||||
|
||||
void moveObject(Object *object);
|
||||
void moveObject(Object *object, ThreadData *currentData,
|
||||
ThreadData *targetData);
|
||||
|
||||
std::thread thread_;
|
||||
ThreadData *data_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,82 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2021, Google Inc.
|
||||
*
|
||||
* Macro of Clang thread safety analysis
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libcamera/base/private.h>
|
||||
|
||||
/*
|
||||
* Enable thread safety attributes only with clang.
|
||||
* The attributes can be safely erased when compiling with other compilers.
|
||||
*/
|
||||
#if defined(__clang__) && !defined(SWIG)
|
||||
#define LIBCAMERA_TSA_ATTRIBUTE__(x) __attribute__((x))
|
||||
#else
|
||||
#define LIBCAMERA_TSA_ATTRIBUTE__(x) /* no-op */
|
||||
#endif
|
||||
|
||||
/* See https://clang.llvm.org/docs/ThreadSafetyAnalysis.html for these usages. */
|
||||
|
||||
#define LIBCAMERA_TSA_CAPABILITY(x) \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(capability(x))
|
||||
|
||||
#define LIBCAMERA_TSA_SCOPED_CAPABILITY \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(scoped_lockable)
|
||||
|
||||
#define LIBCAMERA_TSA_GUARDED_BY(x) \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(guarded_by(x))
|
||||
|
||||
#define LIBCAMERA_TSA_PT_GUARDED_BY(x) \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(pt_guarded_by(x))
|
||||
|
||||
#define LIBCAMERA_TSA_ACQUIRED_BEFORE(...) \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(acquired_before(__VA_ARGS__))
|
||||
|
||||
#define LIBCAMERA_TSA_ACQUIRED_AFTER(...) \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(acquired_after(__VA_ARGS__))
|
||||
|
||||
#define LIBCAMERA_TSA_REQUIRES(...) \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(requires_capability(__VA_ARGS__))
|
||||
|
||||
#define LIBCAMERA_TSA_REQUIRES_SHARED(...) \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(requires_shared_capability(__VA_ARGS__))
|
||||
|
||||
#define LIBCAMERA_TSA_ACQUIRE(...) \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(acquire_capability(__VA_ARGS__))
|
||||
|
||||
#define LIBCAMERA_TSA_ACQUIRE_SHARED(...) \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(acquire_shared_capability(__VA_ARGS__))
|
||||
|
||||
#define LIBCAMERA_TSA_RELEASE(...) \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(release_capability(__VA_ARGS__))
|
||||
|
||||
#define LIBCAMERA_TSA_RELEASE_SHARED(...) \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(release_shared_capability(__VA_ARGS__))
|
||||
|
||||
#define LIBCAMERA_TSA_RELEASE_GENERIC(...) \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(release_generic_capability(__VA_ARGS__))
|
||||
|
||||
#define LIBCAMERA_TSA_TRY_ACQUIRE(...) \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(try_acquire_capability(__VA_ARGS__))
|
||||
|
||||
#define LIBCAMERA_TSA_TRY_ACQUIRE_SHARED(...) \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(try_acquire_shared_capability(__VA_ARGS__))
|
||||
|
||||
#define LIBCAMERA_TSA_EXCLUDES(...) \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(locks_excluded(__VA_ARGS__))
|
||||
|
||||
#define LIBCAMERA_TSA_ASSERT_CAPABILITY(x) \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(assert_capability(x))
|
||||
|
||||
#define LIBCAMERA_TSA_ASSERT_SHARED_CAPABILITY(x) \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(assert_shared_capability(x))
|
||||
|
||||
#define LIBCAMERA_TSA_RETURN_CAPABILITY(x) \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(lock_returned(x))
|
||||
|
||||
#define LIBCAMERA_TSA_NO_THREAD_SAFETY_ANALYSIS \
|
||||
LIBCAMERA_TSA_ATTRIBUTE__(no_thread_safety_analysis)
|
||||
48
spider-cam/libcamera/include/libcamera/base/timer.h
Normal file
48
spider-cam/libcamera/include/libcamera/base/timer.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Generic timer
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <libcamera/base/private.h>
|
||||
|
||||
#include <libcamera/base/object.h>
|
||||
#include <libcamera/base/signal.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Message;
|
||||
|
||||
class Timer : public Object
|
||||
{
|
||||
public:
|
||||
Timer(Object *parent = nullptr);
|
||||
~Timer();
|
||||
|
||||
void start(std::chrono::milliseconds duration);
|
||||
void start(std::chrono::steady_clock::time_point deadline);
|
||||
void stop();
|
||||
bool isRunning() const;
|
||||
|
||||
std::chrono::steady_clock::time_point deadline() const { return deadline_; }
|
||||
|
||||
Signal<> timeout;
|
||||
|
||||
protected:
|
||||
void message(Message *msg) override;
|
||||
|
||||
private:
|
||||
void registerTimer();
|
||||
void unregisterTimer();
|
||||
|
||||
bool running_;
|
||||
std::chrono::steady_clock::time_point deadline_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
69
spider-cam/libcamera/include/libcamera/base/unique_fd.h
Normal file
69
spider-cam/libcamera/include/libcamera/base/unique_fd.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2021, Google Inc.
|
||||
*
|
||||
* File descriptor wrapper that owns a file descriptor.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
#include <libcamera/base/compiler.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class UniqueFD final
|
||||
{
|
||||
public:
|
||||
UniqueFD()
|
||||
: fd_(-1)
|
||||
{
|
||||
}
|
||||
|
||||
explicit UniqueFD(int fd)
|
||||
: fd_(fd)
|
||||
{
|
||||
}
|
||||
|
||||
UniqueFD(UniqueFD &&other)
|
||||
: fd_(other.release())
|
||||
{
|
||||
}
|
||||
|
||||
~UniqueFD()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
UniqueFD &operator=(UniqueFD &&other)
|
||||
{
|
||||
reset(other.release());
|
||||
return *this;
|
||||
}
|
||||
|
||||
__nodiscard int release()
|
||||
{
|
||||
int fd = fd_;
|
||||
fd_ = -1;
|
||||
return fd;
|
||||
}
|
||||
|
||||
void reset(int fd = -1);
|
||||
|
||||
void swap(UniqueFD &other)
|
||||
{
|
||||
std::swap(fd_, other.fd_);
|
||||
}
|
||||
|
||||
int get() const { return fd_; }
|
||||
bool isValid() const { return fd_ >= 0; }
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY(UniqueFD)
|
||||
|
||||
int fd_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
410
spider-cam/libcamera/include/libcamera/base/utils.h
Normal file
410
spider-cam/libcamera/include/libcamera/base/utils.h
Normal file
@@ -0,0 +1,410 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018, Google Inc.
|
||||
*
|
||||
* Miscellaneous utility functions
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/private.h>
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
|
||||
/* uClibc and uClibc-ng don't provide O_TMPFILE */
|
||||
#ifndef O_TMPFILE
|
||||
#define O_TMPFILE (020000000 | O_DIRECTORY)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
namespace utils {
|
||||
|
||||
const char *basename(const char *path);
|
||||
|
||||
char *secure_getenv(const char *name);
|
||||
std::string dirname(const std::string &path);
|
||||
|
||||
template<typename T>
|
||||
std::vector<typename T::key_type> map_keys(const T &map)
|
||||
{
|
||||
std::vector<typename T::key_type> keys;
|
||||
std::transform(map.begin(), map.end(), std::back_inserter(keys),
|
||||
[](const auto &value) { return value.first; });
|
||||
return keys;
|
||||
}
|
||||
|
||||
template<class InputIt1, class InputIt2>
|
||||
unsigned int set_overlap(InputIt1 first1, InputIt1 last1,
|
||||
InputIt2 first2, InputIt2 last2)
|
||||
{
|
||||
unsigned int count = 0;
|
||||
|
||||
while (first1 != last1 && first2 != last2) {
|
||||
if (*first1 < *first2) {
|
||||
++first1;
|
||||
} else {
|
||||
if (!(*first2 < *first1))
|
||||
count++;
|
||||
++first2;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
using clock = std::chrono::steady_clock;
|
||||
using duration = std::chrono::steady_clock::duration;
|
||||
using time_point = std::chrono::steady_clock::time_point;
|
||||
|
||||
struct timespec duration_to_timespec(const duration &value);
|
||||
std::string time_point_to_string(const time_point &time);
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
struct _hex {
|
||||
uint64_t v;
|
||||
unsigned int w;
|
||||
};
|
||||
|
||||
std::basic_ostream<char, std::char_traits<char>> &
|
||||
operator<<(std::basic_ostream<char, std::char_traits<char>> &stream, const _hex &h);
|
||||
#endif
|
||||
|
||||
template<typename T,
|
||||
std::enable_if_t<std::is_integral<T>::value> * = nullptr>
|
||||
_hex hex(T value, unsigned int width = 0);
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
template<>
|
||||
inline _hex hex<int8_t>(int8_t value, unsigned int width)
|
||||
{
|
||||
return { static_cast<uint64_t>(value), width ? width : 2 };
|
||||
}
|
||||
|
||||
template<>
|
||||
inline _hex hex<uint8_t>(uint8_t value, unsigned int width)
|
||||
{
|
||||
return { static_cast<uint64_t>(value), width ? width : 2 };
|
||||
}
|
||||
|
||||
template<>
|
||||
inline _hex hex<int16_t>(int16_t value, unsigned int width)
|
||||
{
|
||||
return { static_cast<uint64_t>(value), width ? width : 4 };
|
||||
}
|
||||
|
||||
template<>
|
||||
inline _hex hex<uint16_t>(uint16_t value, unsigned int width)
|
||||
{
|
||||
return { static_cast<uint64_t>(value), width ? width : 4 };
|
||||
}
|
||||
|
||||
template<>
|
||||
inline _hex hex<int32_t>(int32_t value, unsigned int width)
|
||||
{
|
||||
return { static_cast<uint64_t>(value), width ? width : 8 };
|
||||
}
|
||||
|
||||
template<>
|
||||
inline _hex hex<uint32_t>(uint32_t value, unsigned int width)
|
||||
{
|
||||
return { static_cast<uint64_t>(value), width ? width : 8 };
|
||||
}
|
||||
|
||||
template<>
|
||||
inline _hex hex<int64_t>(int64_t value, unsigned int width)
|
||||
{
|
||||
return { static_cast<uint64_t>(value), width ? width : 16 };
|
||||
}
|
||||
|
||||
template<>
|
||||
inline _hex hex<uint64_t>(uint64_t value, unsigned int width)
|
||||
{
|
||||
return { static_cast<uint64_t>(value), width ? width : 16 };
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t strlcpy(char *dst, const char *src, size_t size);
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
template<typename Container, typename UnaryOp>
|
||||
std::string join(const Container &items, const std::string &sep, UnaryOp op)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
bool first = true;
|
||||
|
||||
for (typename Container::const_iterator it = std::begin(items);
|
||||
it != std::end(items); ++it) {
|
||||
if (!first)
|
||||
ss << sep;
|
||||
else
|
||||
first = false;
|
||||
|
||||
ss << op(*it);
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template<typename Container>
|
||||
std::string join(const Container &items, const std::string &sep)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
bool first = true;
|
||||
|
||||
for (typename Container::const_iterator it = std::begin(items);
|
||||
it != std::end(items); ++it) {
|
||||
if (!first)
|
||||
ss << sep;
|
||||
else
|
||||
first = false;
|
||||
|
||||
ss << *it;
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
#else
|
||||
template<typename Container, typename UnaryOp>
|
||||
std::string join(const Container &items, const std::string &sep, UnaryOp op = nullptr);
|
||||
#endif
|
||||
|
||||
namespace details {
|
||||
|
||||
class StringSplitter
|
||||
{
|
||||
public:
|
||||
StringSplitter(const std::string &str, const std::string &delim);
|
||||
|
||||
class iterator
|
||||
{
|
||||
public:
|
||||
using difference_type = std::size_t;
|
||||
using value_type = std::string;
|
||||
using pointer = value_type *;
|
||||
using reference = value_type &;
|
||||
using iterator_category = std::input_iterator_tag;
|
||||
|
||||
iterator(const StringSplitter *ss, std::string::size_type pos);
|
||||
|
||||
iterator &operator++();
|
||||
std::string operator*() const;
|
||||
bool operator!=(const iterator &other) const;
|
||||
|
||||
private:
|
||||
const StringSplitter *ss_;
|
||||
std::string::size_type pos_;
|
||||
std::string::size_type next_;
|
||||
};
|
||||
|
||||
iterator begin() const;
|
||||
iterator end() const;
|
||||
|
||||
private:
|
||||
std::string str_;
|
||||
std::string delim_;
|
||||
};
|
||||
|
||||
} /* namespace details */
|
||||
|
||||
details::StringSplitter split(const std::string &str, const std::string &delim);
|
||||
|
||||
std::string toAscii(const std::string &str);
|
||||
|
||||
std::string libcameraBuildPath();
|
||||
std::string libcameraSourcePath();
|
||||
|
||||
constexpr unsigned int alignDown(unsigned int value, unsigned int alignment)
|
||||
{
|
||||
return value / alignment * alignment;
|
||||
}
|
||||
|
||||
constexpr unsigned int alignUp(unsigned int value, unsigned int alignment)
|
||||
{
|
||||
return (value + alignment - 1) / alignment * alignment;
|
||||
}
|
||||
|
||||
namespace details {
|
||||
|
||||
template<typename T>
|
||||
struct reverse_adapter {
|
||||
T &iterable;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
auto begin(reverse_adapter<T> r)
|
||||
{
|
||||
return std::rbegin(r.iterable);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
auto end(reverse_adapter<T> r)
|
||||
{
|
||||
return std::rend(r.iterable);
|
||||
}
|
||||
|
||||
} /* namespace details */
|
||||
|
||||
template<typename T>
|
||||
details::reverse_adapter<T> reverse(T &&iterable)
|
||||
{
|
||||
return { iterable };
|
||||
}
|
||||
|
||||
namespace details {
|
||||
|
||||
template<typename Base>
|
||||
class enumerate_iterator
|
||||
{
|
||||
private:
|
||||
using base_reference = typename std::iterator_traits<Base>::reference;
|
||||
|
||||
public:
|
||||
using difference_type = typename std::iterator_traits<Base>::difference_type;
|
||||
using value_type = std::pair<const std::size_t, base_reference>;
|
||||
using pointer = value_type *;
|
||||
using reference = value_type &;
|
||||
using iterator_category = std::input_iterator_tag;
|
||||
|
||||
explicit enumerate_iterator(Base iter)
|
||||
: current_(iter), pos_(0)
|
||||
{
|
||||
}
|
||||
|
||||
enumerate_iterator &operator++()
|
||||
{
|
||||
++current_;
|
||||
++pos_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator!=(const enumerate_iterator &other) const
|
||||
{
|
||||
return current_ != other.current_;
|
||||
}
|
||||
|
||||
value_type operator*() const
|
||||
{
|
||||
return { pos_, *current_ };
|
||||
}
|
||||
|
||||
private:
|
||||
Base current_;
|
||||
std::size_t pos_;
|
||||
};
|
||||
|
||||
template<typename Base>
|
||||
class enumerate_adapter
|
||||
{
|
||||
public:
|
||||
using iterator = enumerate_iterator<Base>;
|
||||
|
||||
enumerate_adapter(Base begin, Base end)
|
||||
: begin_(begin), end_(end)
|
||||
{
|
||||
}
|
||||
|
||||
iterator begin() const
|
||||
{
|
||||
return iterator{ begin_ };
|
||||
}
|
||||
|
||||
iterator end() const
|
||||
{
|
||||
return iterator{ end_ };
|
||||
}
|
||||
|
||||
private:
|
||||
const Base begin_;
|
||||
const Base end_;
|
||||
};
|
||||
|
||||
} /* namespace details */
|
||||
|
||||
template<typename T>
|
||||
auto enumerate(T &iterable) -> details::enumerate_adapter<decltype(iterable.begin())>
|
||||
{
|
||||
return { std::begin(iterable), std::end(iterable) };
|
||||
}
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
template<typename T, size_t N>
|
||||
auto enumerate(T (&iterable)[N]) -> details::enumerate_adapter<T *>
|
||||
{
|
||||
return { std::begin(iterable), std::end(iterable) };
|
||||
}
|
||||
#endif
|
||||
|
||||
class Duration : public std::chrono::duration<double, std::nano>
|
||||
{
|
||||
using BaseDuration = std::chrono::duration<double, std::nano>;
|
||||
|
||||
public:
|
||||
Duration() = default;
|
||||
|
||||
template<typename Rep>
|
||||
constexpr explicit Duration(const Rep &r)
|
||||
: BaseDuration(r)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Rep, typename Period>
|
||||
constexpr Duration(const std::chrono::duration<Rep, Period> &d)
|
||||
: BaseDuration(d)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Period>
|
||||
double get() const
|
||||
{
|
||||
auto const c = std::chrono::duration_cast<std::chrono::duration<double, Period>>(*this);
|
||||
return c.count();
|
||||
}
|
||||
|
||||
explicit constexpr operator bool() const
|
||||
{
|
||||
return *this != BaseDuration::zero();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
decltype(auto) abs_diff(const T &a, const T &b)
|
||||
{
|
||||
if (a < b)
|
||||
return b - a;
|
||||
else
|
||||
return a - b;
|
||||
}
|
||||
|
||||
double strtod(const char *__restrict nptr, char **__restrict endptr);
|
||||
|
||||
template<class Enum>
|
||||
constexpr std::underlying_type_t<Enum> to_underlying(Enum e) noexcept
|
||||
{
|
||||
return static_cast<std::underlying_type_t<Enum>>(e);
|
||||
}
|
||||
|
||||
} /* namespace utils */
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
template<class CharT, class Traits>
|
||||
std::basic_ostream<CharT, Traits> &operator<<(std::basic_ostream<CharT, Traits> &os,
|
||||
const utils::Duration &d);
|
||||
#endif
|
||||
|
||||
} /* namespace libcamera */
|
||||
170
spider-cam/libcamera/include/libcamera/camera.h
Normal file
170
spider-cam/libcamera/include/libcamera/camera.h
Normal file
@@ -0,0 +1,170 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018, Google Inc.
|
||||
*
|
||||
* Camera object interface
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
#include <libcamera/base/flags.h>
|
||||
#include <libcamera/base/object.h>
|
||||
#include <libcamera/base/signal.h>
|
||||
|
||||
#include <libcamera/controls.h>
|
||||
#include <libcamera/geometry.h>
|
||||
#include <libcamera/orientation.h>
|
||||
#include <libcamera/request.h>
|
||||
#include <libcamera/stream.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class FrameBuffer;
|
||||
class FrameBufferAllocator;
|
||||
class PipelineHandler;
|
||||
class Request;
|
||||
|
||||
class SensorConfiguration
|
||||
{
|
||||
public:
|
||||
unsigned int bitDepth = 0;
|
||||
|
||||
Rectangle analogCrop;
|
||||
|
||||
struct {
|
||||
unsigned int binX = 1;
|
||||
unsigned int binY = 1;
|
||||
} binning;
|
||||
|
||||
struct {
|
||||
unsigned int xOddInc = 1;
|
||||
unsigned int xEvenInc = 1;
|
||||
unsigned int yOddInc = 1;
|
||||
unsigned int yEvenInc = 1;
|
||||
} skipping;
|
||||
|
||||
Size outputSize;
|
||||
|
||||
bool isValid() const;
|
||||
};
|
||||
|
||||
class CameraConfiguration
|
||||
{
|
||||
public:
|
||||
enum Status {
|
||||
Valid,
|
||||
Adjusted,
|
||||
Invalid,
|
||||
};
|
||||
|
||||
using iterator = std::vector<StreamConfiguration>::iterator;
|
||||
using const_iterator = std::vector<StreamConfiguration>::const_iterator;
|
||||
|
||||
virtual ~CameraConfiguration();
|
||||
|
||||
void addConfiguration(const StreamConfiguration &cfg);
|
||||
virtual Status validate() = 0;
|
||||
|
||||
StreamConfiguration &at(unsigned int index);
|
||||
const StreamConfiguration &at(unsigned int index) const;
|
||||
StreamConfiguration &operator[](unsigned int index)
|
||||
{
|
||||
return at(index);
|
||||
}
|
||||
const StreamConfiguration &operator[](unsigned int index) const
|
||||
{
|
||||
return at(index);
|
||||
}
|
||||
|
||||
iterator begin();
|
||||
const_iterator begin() const;
|
||||
iterator end();
|
||||
const_iterator end() const;
|
||||
|
||||
bool empty() const;
|
||||
std::size_t size() const;
|
||||
|
||||
std::optional<SensorConfiguration> sensorConfig;
|
||||
Orientation orientation;
|
||||
|
||||
protected:
|
||||
CameraConfiguration();
|
||||
|
||||
enum class ColorSpaceFlag {
|
||||
None,
|
||||
StreamsShareColorSpace,
|
||||
};
|
||||
|
||||
using ColorSpaceFlags = Flags<ColorSpaceFlag>;
|
||||
|
||||
Status validateColorSpaces(ColorSpaceFlags flags = ColorSpaceFlag::None);
|
||||
|
||||
std::vector<StreamConfiguration> config_;
|
||||
};
|
||||
|
||||
class Camera final : public Object, public std::enable_shared_from_this<Camera>,
|
||||
public Extensible
|
||||
{
|
||||
LIBCAMERA_DECLARE_PRIVATE()
|
||||
|
||||
public:
|
||||
static std::shared_ptr<Camera> create(std::unique_ptr<Private> d,
|
||||
const std::string &id,
|
||||
const std::set<Stream *> &streams);
|
||||
|
||||
const std::string &id() const;
|
||||
|
||||
Signal<Request *, FrameBuffer *> bufferCompleted;
|
||||
Signal<Request *> requestCompleted;
|
||||
Signal<> disconnected;
|
||||
|
||||
int acquire();
|
||||
int release();
|
||||
|
||||
const ControlInfoMap &controls() const;
|
||||
const ControlList &properties() const;
|
||||
|
||||
const std::set<Stream *> &streams() const;
|
||||
|
||||
std::unique_ptr<CameraConfiguration>
|
||||
generateConfiguration(Span<const StreamRole> roles = {});
|
||||
|
||||
std::unique_ptr<CameraConfiguration>
|
||||
generateConfiguration(std::initializer_list<StreamRole> roles)
|
||||
{
|
||||
return generateConfiguration(Span(roles.begin(), roles.end()));
|
||||
}
|
||||
|
||||
int configure(CameraConfiguration *config);
|
||||
|
||||
std::unique_ptr<Request> createRequest(uint64_t cookie = 0);
|
||||
int queueRequest(Request *request);
|
||||
|
||||
int start(const ControlList *controls = nullptr);
|
||||
int stop();
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY(Camera)
|
||||
|
||||
Camera(std::unique_ptr<Private> d, const std::string &id,
|
||||
const std::set<Stream *> &streams);
|
||||
~Camera();
|
||||
|
||||
friend class PipelineHandler;
|
||||
void disconnect();
|
||||
void requestComplete(Request *request);
|
||||
|
||||
friend class FrameBufferAllocator;
|
||||
int exportFrameBuffers(Stream *stream,
|
||||
std::vector<std::unique_ptr<FrameBuffer>> *buffers);
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
48
spider-cam/libcamera/include/libcamera/camera_manager.h
Normal file
48
spider-cam/libcamera/include/libcamera/camera_manager.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018, Google Inc.
|
||||
*
|
||||
* Camera management
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <sys/types.h>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
#include <libcamera/base/object.h>
|
||||
#include <libcamera/base/signal.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Camera;
|
||||
|
||||
class CameraManager : public Object, public Extensible
|
||||
{
|
||||
LIBCAMERA_DECLARE_PRIVATE()
|
||||
public:
|
||||
CameraManager();
|
||||
~CameraManager();
|
||||
|
||||
int start();
|
||||
void stop();
|
||||
|
||||
std::vector<std::shared_ptr<Camera>> cameras() const;
|
||||
std::shared_ptr<Camera> get(const std::string &id);
|
||||
|
||||
static const std::string &version() { return version_; }
|
||||
|
||||
Signal<std::shared_ptr<Camera>> cameraAdded;
|
||||
Signal<std::shared_ptr<Camera>> cameraRemoved;
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY(CameraManager)
|
||||
|
||||
static const std::string version_;
|
||||
static CameraManager *self_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
76
spider-cam/libcamera/include/libcamera/color_space.h
Normal file
76
spider-cam/libcamera/include/libcamera/color_space.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2021, Raspberry Pi Ltd
|
||||
*
|
||||
* color space definitions
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class PixelFormat;
|
||||
|
||||
class ColorSpace
|
||||
{
|
||||
public:
|
||||
enum class Primaries {
|
||||
Raw,
|
||||
Smpte170m,
|
||||
Rec709,
|
||||
Rec2020,
|
||||
};
|
||||
|
||||
enum class TransferFunction {
|
||||
Linear,
|
||||
Srgb,
|
||||
Rec709,
|
||||
};
|
||||
|
||||
enum class YcbcrEncoding {
|
||||
None,
|
||||
Rec601,
|
||||
Rec709,
|
||||
Rec2020,
|
||||
};
|
||||
|
||||
enum class Range {
|
||||
Full,
|
||||
Limited,
|
||||
};
|
||||
|
||||
constexpr ColorSpace(Primaries p, TransferFunction t, YcbcrEncoding e, Range r)
|
||||
: primaries(p), transferFunction(t), ycbcrEncoding(e), range(r)
|
||||
{
|
||||
}
|
||||
|
||||
static const ColorSpace Raw;
|
||||
static const ColorSpace Srgb;
|
||||
static const ColorSpace Sycc;
|
||||
static const ColorSpace Smpte170m;
|
||||
static const ColorSpace Rec709;
|
||||
static const ColorSpace Rec2020;
|
||||
|
||||
Primaries primaries;
|
||||
TransferFunction transferFunction;
|
||||
YcbcrEncoding ycbcrEncoding;
|
||||
Range range;
|
||||
|
||||
std::string toString() const;
|
||||
static std::string toString(const std::optional<ColorSpace> &colorSpace);
|
||||
|
||||
static std::optional<ColorSpace> fromString(const std::string &str);
|
||||
|
||||
bool adjust(PixelFormat format);
|
||||
};
|
||||
|
||||
bool operator==(const ColorSpace &lhs, const ColorSpace &rhs);
|
||||
static inline bool operator!=(const ColorSpace &lhs, const ColorSpace &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
} /* namespace libcamera */
|
||||
35
spider-cam/libcamera/include/libcamera/control_ids.h.in
Normal file
35
spider-cam/libcamera/include/libcamera/control_ids.h.in
Normal file
@@ -0,0 +1,35 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Control ID list
|
||||
*
|
||||
* This file is auto-generated. Do not edit.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
#include <libcamera/controls.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
namespace controls {
|
||||
|
||||
enum {
|
||||
${ids}
|
||||
};
|
||||
|
||||
${controls}
|
||||
|
||||
extern const ControlIdMap controls;
|
||||
|
||||
${vendor_controls}
|
||||
|
||||
} /* namespace controls */
|
||||
|
||||
} /* namespace libcamera */
|
||||
428
spider-cam/libcamera/include/libcamera/controls.h
Normal file
428
spider-cam/libcamera/include/libcamera/controls.h
Normal file
@@ -0,0 +1,428 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Control handling
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
#include <libcamera/base/span.h>
|
||||
|
||||
#include <libcamera/geometry.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class ControlValidator;
|
||||
|
||||
enum ControlType {
|
||||
ControlTypeNone,
|
||||
ControlTypeBool,
|
||||
ControlTypeByte,
|
||||
ControlTypeInteger32,
|
||||
ControlTypeInteger64,
|
||||
ControlTypeFloat,
|
||||
ControlTypeString,
|
||||
ControlTypeRectangle,
|
||||
ControlTypeSize,
|
||||
};
|
||||
|
||||
namespace details {
|
||||
|
||||
template<typename T>
|
||||
struct control_type {
|
||||
};
|
||||
|
||||
template<>
|
||||
struct control_type<void> {
|
||||
static constexpr ControlType value = ControlTypeNone;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct control_type<bool> {
|
||||
static constexpr ControlType value = ControlTypeBool;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct control_type<uint8_t> {
|
||||
static constexpr ControlType value = ControlTypeByte;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct control_type<int32_t> {
|
||||
static constexpr ControlType value = ControlTypeInteger32;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct control_type<int64_t> {
|
||||
static constexpr ControlType value = ControlTypeInteger64;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct control_type<float> {
|
||||
static constexpr ControlType value = ControlTypeFloat;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct control_type<std::string> {
|
||||
static constexpr ControlType value = ControlTypeString;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct control_type<Rectangle> {
|
||||
static constexpr ControlType value = ControlTypeRectangle;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct control_type<Size> {
|
||||
static constexpr ControlType value = ControlTypeSize;
|
||||
};
|
||||
|
||||
template<typename T, std::size_t N>
|
||||
struct control_type<Span<T, N>> : public control_type<std::remove_cv_t<T>> {
|
||||
};
|
||||
|
||||
} /* namespace details */
|
||||
|
||||
class ControlValue
|
||||
{
|
||||
public:
|
||||
ControlValue();
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
template<typename T, std::enable_if_t<!details::is_span<T>::value &&
|
||||
details::control_type<T>::value &&
|
||||
!std::is_same<std::string, std::remove_cv_t<T>>::value,
|
||||
std::nullptr_t> = nullptr>
|
||||
ControlValue(const T &value)
|
||||
: type_(ControlTypeNone), numElements_(0)
|
||||
{
|
||||
set(details::control_type<std::remove_cv_t<T>>::value, false,
|
||||
&value, 1, sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T, std::enable_if_t<details::is_span<T>::value ||
|
||||
std::is_same<std::string, std::remove_cv_t<T>>::value,
|
||||
std::nullptr_t> = nullptr>
|
||||
#else
|
||||
template<typename T>
|
||||
#endif
|
||||
ControlValue(const T &value)
|
||||
: type_(ControlTypeNone), numElements_(0)
|
||||
{
|
||||
set(details::control_type<std::remove_cv_t<T>>::value, true,
|
||||
value.data(), value.size(), sizeof(typename T::value_type));
|
||||
}
|
||||
|
||||
~ControlValue();
|
||||
|
||||
ControlValue(const ControlValue &other);
|
||||
ControlValue &operator=(const ControlValue &other);
|
||||
|
||||
ControlType type() const { return type_; }
|
||||
bool isNone() const { return type_ == ControlTypeNone; }
|
||||
bool isArray() const { return isArray_; }
|
||||
std::size_t numElements() const { return numElements_; }
|
||||
Span<const uint8_t> data() const;
|
||||
Span<uint8_t> data();
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
bool operator==(const ControlValue &other) const;
|
||||
bool operator!=(const ControlValue &other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
template<typename T, std::enable_if_t<!details::is_span<T>::value &&
|
||||
!std::is_same<std::string, std::remove_cv_t<T>>::value,
|
||||
std::nullptr_t> = nullptr>
|
||||
T get() const
|
||||
{
|
||||
assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
|
||||
assert(!isArray_);
|
||||
|
||||
return *reinterpret_cast<const T *>(data().data());
|
||||
}
|
||||
|
||||
template<typename T, std::enable_if_t<details::is_span<T>::value ||
|
||||
std::is_same<std::string, std::remove_cv_t<T>>::value,
|
||||
std::nullptr_t> = nullptr>
|
||||
#else
|
||||
template<typename T>
|
||||
#endif
|
||||
T get() const
|
||||
{
|
||||
assert(type_ == details::control_type<std::remove_cv_t<T>>::value);
|
||||
assert(isArray_);
|
||||
|
||||
using V = typename T::value_type;
|
||||
const V *value = reinterpret_cast<const V *>(data().data());
|
||||
return T{ value, numElements_ };
|
||||
}
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
template<typename T, std::enable_if_t<!details::is_span<T>::value &&
|
||||
!std::is_same<std::string, std::remove_cv_t<T>>::value,
|
||||
std::nullptr_t> = nullptr>
|
||||
void set(const T &value)
|
||||
{
|
||||
set(details::control_type<std::remove_cv_t<T>>::value, false,
|
||||
reinterpret_cast<const void *>(&value), 1, sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T, std::enable_if_t<details::is_span<T>::value ||
|
||||
std::is_same<std::string, std::remove_cv_t<T>>::value,
|
||||
std::nullptr_t> = nullptr>
|
||||
#else
|
||||
template<typename T>
|
||||
#endif
|
||||
void set(const T &value)
|
||||
{
|
||||
set(details::control_type<std::remove_cv_t<T>>::value, true,
|
||||
value.data(), value.size(), sizeof(typename T::value_type));
|
||||
}
|
||||
|
||||
void reserve(ControlType type, bool isArray = false,
|
||||
std::size_t numElements = 1);
|
||||
|
||||
private:
|
||||
ControlType type_ : 8;
|
||||
bool isArray_;
|
||||
std::size_t numElements_ : 32;
|
||||
union {
|
||||
uint64_t value_;
|
||||
void *storage_;
|
||||
};
|
||||
|
||||
void release();
|
||||
void set(ControlType type, bool isArray, const void *data,
|
||||
std::size_t numElements, std::size_t elementSize);
|
||||
};
|
||||
|
||||
class ControlId
|
||||
{
|
||||
public:
|
||||
ControlId(unsigned int id, const std::string &name, ControlType type)
|
||||
: id_(id), name_(name), type_(type)
|
||||
{
|
||||
}
|
||||
|
||||
unsigned int id() const { return id_; }
|
||||
const std::string &name() const { return name_; }
|
||||
ControlType type() const { return type_; }
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY_AND_MOVE(ControlId)
|
||||
|
||||
unsigned int id_;
|
||||
std::string name_;
|
||||
ControlType type_;
|
||||
};
|
||||
|
||||
static inline bool operator==(unsigned int lhs, const ControlId &rhs)
|
||||
{
|
||||
return lhs == rhs.id();
|
||||
}
|
||||
|
||||
static inline bool operator!=(unsigned int lhs, const ControlId &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
static inline bool operator==(const ControlId &lhs, unsigned int rhs)
|
||||
{
|
||||
return lhs.id() == rhs;
|
||||
}
|
||||
|
||||
static inline bool operator!=(const ControlId &lhs, unsigned int rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class Control : public ControlId
|
||||
{
|
||||
public:
|
||||
using type = T;
|
||||
|
||||
Control(unsigned int id, const char *name)
|
||||
: ControlId(id, name, details::control_type<std::remove_cv_t<T>>::value)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY_AND_MOVE(Control)
|
||||
};
|
||||
|
||||
class ControlInfo
|
||||
{
|
||||
public:
|
||||
explicit ControlInfo(const ControlValue &min = {},
|
||||
const ControlValue &max = {},
|
||||
const ControlValue &def = {});
|
||||
explicit ControlInfo(Span<const ControlValue> values,
|
||||
const ControlValue &def = {});
|
||||
explicit ControlInfo(std::set<bool> values, bool def);
|
||||
explicit ControlInfo(bool value);
|
||||
|
||||
const ControlValue &min() const { return min_; }
|
||||
const ControlValue &max() const { return max_; }
|
||||
const ControlValue &def() const { return def_; }
|
||||
const std::vector<ControlValue> &values() const { return values_; }
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
bool operator==(const ControlInfo &other) const
|
||||
{
|
||||
return min_ == other.min_ && max_ == other.max_;
|
||||
}
|
||||
|
||||
bool operator!=(const ControlInfo &other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
private:
|
||||
ControlValue min_;
|
||||
ControlValue max_;
|
||||
ControlValue def_;
|
||||
std::vector<ControlValue> values_;
|
||||
};
|
||||
|
||||
using ControlIdMap = std::unordered_map<unsigned int, const ControlId *>;
|
||||
|
||||
class ControlInfoMap : private std::unordered_map<const ControlId *, ControlInfo>
|
||||
{
|
||||
public:
|
||||
using Map = std::unordered_map<const ControlId *, ControlInfo>;
|
||||
|
||||
ControlInfoMap() = default;
|
||||
ControlInfoMap(const ControlInfoMap &other) = default;
|
||||
ControlInfoMap(std::initializer_list<Map::value_type> init,
|
||||
const ControlIdMap &idmap);
|
||||
ControlInfoMap(Map &&info, const ControlIdMap &idmap);
|
||||
|
||||
ControlInfoMap &operator=(const ControlInfoMap &other) = default;
|
||||
|
||||
using Map::key_type;
|
||||
using Map::mapped_type;
|
||||
using Map::value_type;
|
||||
using Map::size_type;
|
||||
using Map::iterator;
|
||||
using Map::const_iterator;
|
||||
|
||||
using Map::begin;
|
||||
using Map::cbegin;
|
||||
using Map::end;
|
||||
using Map::cend;
|
||||
using Map::at;
|
||||
using Map::empty;
|
||||
using Map::size;
|
||||
using Map::count;
|
||||
using Map::find;
|
||||
|
||||
mapped_type &at(unsigned int key);
|
||||
const mapped_type &at(unsigned int key) const;
|
||||
size_type count(unsigned int key) const;
|
||||
iterator find(unsigned int key);
|
||||
const_iterator find(unsigned int key) const;
|
||||
|
||||
const ControlIdMap &idmap() const { return *idmap_; }
|
||||
|
||||
private:
|
||||
bool validate();
|
||||
|
||||
const ControlIdMap *idmap_ = nullptr;
|
||||
};
|
||||
|
||||
class ControlList
|
||||
{
|
||||
private:
|
||||
using ControlListMap = std::unordered_map<unsigned int, ControlValue>;
|
||||
|
||||
public:
|
||||
enum class MergePolicy {
|
||||
KeepExisting = 0,
|
||||
OverwriteExisting,
|
||||
};
|
||||
|
||||
ControlList();
|
||||
ControlList(const ControlIdMap &idmap, const ControlValidator *validator = nullptr);
|
||||
ControlList(const ControlInfoMap &infoMap, const ControlValidator *validator = nullptr);
|
||||
|
||||
using iterator = ControlListMap::iterator;
|
||||
using const_iterator = ControlListMap::const_iterator;
|
||||
|
||||
iterator begin() { return controls_.begin(); }
|
||||
iterator end() { return controls_.end(); }
|
||||
const_iterator begin() const { return controls_.begin(); }
|
||||
const_iterator end() const { return controls_.end(); }
|
||||
|
||||
bool empty() const { return controls_.empty(); }
|
||||
std::size_t size() const { return controls_.size(); }
|
||||
|
||||
void clear() { controls_.clear(); }
|
||||
void merge(const ControlList &source, MergePolicy policy = MergePolicy::KeepExisting);
|
||||
|
||||
bool contains(unsigned int id) const;
|
||||
|
||||
template<typename T>
|
||||
std::optional<T> get(const Control<T> &ctrl) const
|
||||
{
|
||||
const auto entry = controls_.find(ctrl.id());
|
||||
if (entry == controls_.end())
|
||||
return std::nullopt;
|
||||
|
||||
const ControlValue &val = entry->second;
|
||||
return val.get<T>();
|
||||
}
|
||||
|
||||
template<typename T, typename V>
|
||||
void set(const Control<T> &ctrl, const V &value)
|
||||
{
|
||||
ControlValue *val = find(ctrl.id());
|
||||
if (!val)
|
||||
return;
|
||||
|
||||
val->set<T>(value);
|
||||
}
|
||||
|
||||
template<typename T, typename V, size_t Size>
|
||||
void set(const Control<Span<T, Size>> &ctrl, const std::initializer_list<V> &value)
|
||||
{
|
||||
ControlValue *val = find(ctrl.id());
|
||||
if (!val)
|
||||
return;
|
||||
|
||||
val->set(Span<const typename std::remove_cv_t<V>, Size>{ value.begin(), value.size() });
|
||||
}
|
||||
|
||||
const ControlValue &get(unsigned int id) const;
|
||||
void set(unsigned int id, const ControlValue &value);
|
||||
|
||||
const ControlInfoMap *infoMap() const { return infoMap_; }
|
||||
const ControlIdMap *idMap() const { return idmap_; }
|
||||
|
||||
private:
|
||||
const ControlValue *find(unsigned int id) const;
|
||||
ControlValue *find(unsigned int id);
|
||||
|
||||
const ControlValidator *validator_;
|
||||
const ControlIdMap *idmap_;
|
||||
const ControlInfoMap *infoMap_;
|
||||
|
||||
ControlListMap controls_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
31
spider-cam/libcamera/include/libcamera/fence.h
Normal file
31
spider-cam/libcamera/include/libcamera/fence.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2021, Google Inc.
|
||||
*
|
||||
* Synchronization fence
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
#include <libcamera/base/unique_fd.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Fence
|
||||
{
|
||||
public:
|
||||
Fence(UniqueFD fd);
|
||||
|
||||
bool isValid() const { return fd_.isValid(); }
|
||||
const UniqueFD &fd() const { return fd_; }
|
||||
|
||||
UniqueFD release() { return std::move(fd_); }
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY_AND_MOVE(Fence)
|
||||
|
||||
UniqueFD fd_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
42
spider-cam/libcamera/include/libcamera/formats.h.in
Normal file
42
spider-cam/libcamera/include/libcamera/formats.h.in
Normal file
@@ -0,0 +1,42 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Google Inc.
|
||||
*
|
||||
* Formats
|
||||
*
|
||||
* This file is auto-generated. Do not edit.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <libcamera/pixel_format.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
namespace formats {
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr uint32_t __fourcc(char a, char b, char c, char d)
|
||||
{
|
||||
return (static_cast<uint32_t>(a) << 0) |
|
||||
(static_cast<uint32_t>(b) << 8) |
|
||||
(static_cast<uint32_t>(c) << 16) |
|
||||
(static_cast<uint32_t>(d) << 24);
|
||||
}
|
||||
|
||||
constexpr uint64_t __mod(unsigned int vendor, unsigned int mod)
|
||||
{
|
||||
return (static_cast<uint64_t>(vendor) << 56) |
|
||||
(static_cast<uint64_t>(mod) << 0);
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
${formats}
|
||||
|
||||
} /* namespace formats */
|
||||
|
||||
} /* namespace libcamera */
|
||||
78
spider-cam/libcamera/include/libcamera/framebuffer.h
Normal file
78
spider-cam/libcamera/include/libcamera/framebuffer.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Frame buffer handling
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
#include <libcamera/base/shared_fd.h>
|
||||
#include <libcamera/base/span.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Fence;
|
||||
class Request;
|
||||
|
||||
struct FrameMetadata {
|
||||
enum Status {
|
||||
FrameSuccess,
|
||||
FrameError,
|
||||
FrameCancelled,
|
||||
};
|
||||
|
||||
struct Plane {
|
||||
unsigned int bytesused;
|
||||
};
|
||||
|
||||
Status status;
|
||||
unsigned int sequence;
|
||||
uint64_t timestamp;
|
||||
|
||||
Span<Plane> planes() { return planes_; }
|
||||
Span<const Plane> planes() const { return planes_; }
|
||||
|
||||
private:
|
||||
friend class FrameBuffer;
|
||||
|
||||
std::vector<Plane> planes_;
|
||||
};
|
||||
|
||||
class FrameBuffer : public Extensible
|
||||
{
|
||||
LIBCAMERA_DECLARE_PRIVATE()
|
||||
|
||||
public:
|
||||
struct Plane {
|
||||
static constexpr unsigned int kInvalidOffset = std::numeric_limits<unsigned int>::max();
|
||||
SharedFD fd;
|
||||
unsigned int offset = kInvalidOffset;
|
||||
unsigned int length;
|
||||
};
|
||||
|
||||
FrameBuffer(const std::vector<Plane> &planes, unsigned int cookie = 0);
|
||||
FrameBuffer(std::unique_ptr<Private> d);
|
||||
virtual ~FrameBuffer() {}
|
||||
|
||||
const std::vector<Plane> &planes() const;
|
||||
Request *request() const;
|
||||
const FrameMetadata &metadata() const;
|
||||
|
||||
uint64_t cookie() const;
|
||||
void setCookie(uint64_t cookie);
|
||||
|
||||
std::unique_ptr<Fence> releaseFence();
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY_AND_MOVE(FrameBuffer)
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,41 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* FrameBuffer allocator
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Camera;
|
||||
class FrameBuffer;
|
||||
class Stream;
|
||||
|
||||
class FrameBufferAllocator
|
||||
{
|
||||
public:
|
||||
FrameBufferAllocator(std::shared_ptr<Camera> camera);
|
||||
~FrameBufferAllocator();
|
||||
|
||||
int allocate(Stream *stream);
|
||||
int free(Stream *stream);
|
||||
|
||||
bool allocated() const { return !buffers_.empty(); }
|
||||
const std::vector<std::unique_ptr<FrameBuffer>> &buffers(Stream *stream) const;
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY(FrameBufferAllocator)
|
||||
|
||||
std::shared_ptr<Camera> camera_;
|
||||
std::map<Stream *, std::vector<std::unique_ptr<FrameBuffer>>> buffers_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
303
spider-cam/libcamera/include/libcamera/geometry.h
Normal file
303
spider-cam/libcamera/include/libcamera/geometry.h
Normal file
@@ -0,0 +1,303 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Geometry-related classes
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include <libcamera/base/compiler.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Rectangle;
|
||||
|
||||
class Point
|
||||
{
|
||||
public:
|
||||
constexpr Point()
|
||||
: x(0), y(0)
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Point(int xpos, int ypos)
|
||||
: x(xpos), y(ypos)
|
||||
{
|
||||
}
|
||||
|
||||
int x;
|
||||
int y;
|
||||
|
||||
const std::string toString() const;
|
||||
|
||||
constexpr Point operator-() const
|
||||
{
|
||||
return { -x, -y };
|
||||
}
|
||||
};
|
||||
|
||||
bool operator==(const Point &lhs, const Point &rhs);
|
||||
static inline bool operator!=(const Point &lhs, const Point &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const Point &p);
|
||||
|
||||
class Size
|
||||
{
|
||||
public:
|
||||
constexpr Size()
|
||||
: Size(0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Size(unsigned int w, unsigned int h)
|
||||
: width(w), height(h)
|
||||
{
|
||||
}
|
||||
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
|
||||
bool isNull() const { return !width && !height; }
|
||||
const std::string toString() const;
|
||||
|
||||
Size &alignDownTo(unsigned int hAlignment, unsigned int vAlignment)
|
||||
{
|
||||
width = width / hAlignment * hAlignment;
|
||||
height = height / vAlignment * vAlignment;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Size &alignUpTo(unsigned int hAlignment, unsigned int vAlignment)
|
||||
{
|
||||
width = (width + hAlignment - 1) / hAlignment * hAlignment;
|
||||
height = (height + vAlignment - 1) / vAlignment * vAlignment;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Size &boundTo(const Size &bound)
|
||||
{
|
||||
width = std::min(width, bound.width);
|
||||
height = std::min(height, bound.height);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Size &expandTo(const Size &expand)
|
||||
{
|
||||
width = std::max(width, expand.width);
|
||||
height = std::max(height, expand.height);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Size &growBy(const Size &margins)
|
||||
{
|
||||
width += margins.width;
|
||||
height += margins.height;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Size &shrinkBy(const Size &margins)
|
||||
{
|
||||
width = width > margins.width ? width - margins.width : 0;
|
||||
height = height > margins.height ? height - margins.height : 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
__nodiscard constexpr Size alignedDownTo(unsigned int hAlignment,
|
||||
unsigned int vAlignment) const
|
||||
{
|
||||
return {
|
||||
width / hAlignment * hAlignment,
|
||||
height / vAlignment * vAlignment
|
||||
};
|
||||
}
|
||||
|
||||
__nodiscard constexpr Size alignedUpTo(unsigned int hAlignment,
|
||||
unsigned int vAlignment) const
|
||||
{
|
||||
return {
|
||||
(width + hAlignment - 1) / hAlignment * hAlignment,
|
||||
(height + vAlignment - 1) / vAlignment * vAlignment
|
||||
};
|
||||
}
|
||||
|
||||
__nodiscard constexpr Size boundedTo(const Size &bound) const
|
||||
{
|
||||
return {
|
||||
std::min(width, bound.width),
|
||||
std::min(height, bound.height)
|
||||
};
|
||||
}
|
||||
|
||||
__nodiscard constexpr Size expandedTo(const Size &expand) const
|
||||
{
|
||||
return {
|
||||
std::max(width, expand.width),
|
||||
std::max(height, expand.height)
|
||||
};
|
||||
}
|
||||
|
||||
__nodiscard constexpr Size grownBy(const Size &margins) const
|
||||
{
|
||||
return {
|
||||
width + margins.width,
|
||||
height + margins.height
|
||||
};
|
||||
}
|
||||
|
||||
__nodiscard constexpr Size shrunkBy(const Size &margins) const
|
||||
{
|
||||
return {
|
||||
width > margins.width ? width - margins.width : 0,
|
||||
height > margins.height ? height - margins.height : 0
|
||||
};
|
||||
}
|
||||
|
||||
__nodiscard Size boundedToAspectRatio(const Size &ratio) const;
|
||||
__nodiscard Size expandedToAspectRatio(const Size &ratio) const;
|
||||
|
||||
__nodiscard Rectangle centeredTo(const Point ¢er) const;
|
||||
|
||||
Size operator*(float factor) const;
|
||||
Size operator/(float factor) const;
|
||||
|
||||
Size &operator*=(float factor);
|
||||
Size &operator/=(float factor);
|
||||
};
|
||||
|
||||
bool operator==(const Size &lhs, const Size &rhs);
|
||||
bool operator<(const Size &lhs, const Size &rhs);
|
||||
|
||||
static inline bool operator!=(const Size &lhs, const Size &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
static inline bool operator<=(const Size &lhs, const Size &rhs)
|
||||
{
|
||||
return lhs < rhs || lhs == rhs;
|
||||
}
|
||||
|
||||
static inline bool operator>(const Size &lhs, const Size &rhs)
|
||||
{
|
||||
return !(lhs <= rhs);
|
||||
}
|
||||
|
||||
static inline bool operator>=(const Size &lhs, const Size &rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const Size &s);
|
||||
|
||||
class SizeRange
|
||||
{
|
||||
public:
|
||||
SizeRange()
|
||||
: hStep(0), vStep(0)
|
||||
{
|
||||
}
|
||||
|
||||
SizeRange(const Size &size)
|
||||
: min(size), max(size), hStep(1), vStep(1)
|
||||
{
|
||||
}
|
||||
|
||||
SizeRange(const Size &minSize, const Size &maxSize)
|
||||
: min(minSize), max(maxSize), hStep(1), vStep(1)
|
||||
{
|
||||
}
|
||||
|
||||
SizeRange(const Size &minSize, const Size &maxSize,
|
||||
unsigned int hstep, unsigned int vstep)
|
||||
: min(minSize), max(maxSize), hStep(hstep), vStep(vstep)
|
||||
{
|
||||
}
|
||||
|
||||
bool contains(const Size &size) const;
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
Size min;
|
||||
Size max;
|
||||
unsigned int hStep;
|
||||
unsigned int vStep;
|
||||
};
|
||||
|
||||
bool operator==(const SizeRange &lhs, const SizeRange &rhs);
|
||||
static inline bool operator!=(const SizeRange &lhs, const SizeRange &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const SizeRange &sr);
|
||||
|
||||
class Rectangle
|
||||
{
|
||||
public:
|
||||
constexpr Rectangle()
|
||||
: Rectangle(0, 0, 0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Rectangle(int xpos, int ypos, const Size &size)
|
||||
: x(xpos), y(ypos), width(size.width), height(size.height)
|
||||
{
|
||||
}
|
||||
|
||||
constexpr Rectangle(int xpos, int ypos, unsigned int w, unsigned int h)
|
||||
: x(xpos), y(ypos), width(w), height(h)
|
||||
{
|
||||
}
|
||||
|
||||
constexpr explicit Rectangle(const Size &size)
|
||||
: x(0), y(0), width(size.width), height(size.height)
|
||||
{
|
||||
}
|
||||
|
||||
int x;
|
||||
int y;
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
|
||||
bool isNull() const { return !width && !height; }
|
||||
const std::string toString() const;
|
||||
|
||||
Point center() const;
|
||||
|
||||
Size size() const
|
||||
{
|
||||
return { width, height };
|
||||
}
|
||||
|
||||
Point topLeft() const
|
||||
{
|
||||
return { x, y };
|
||||
}
|
||||
|
||||
Rectangle &scaleBy(const Size &numerator, const Size &denominator);
|
||||
Rectangle &translateBy(const Point &point);
|
||||
|
||||
__nodiscard Rectangle boundedTo(const Rectangle &bound) const;
|
||||
__nodiscard Rectangle enclosedIn(const Rectangle &boundary) const;
|
||||
__nodiscard Rectangle scaledBy(const Size &numerator,
|
||||
const Size &denominator) const;
|
||||
__nodiscard Rectangle translatedBy(const Point &point) const;
|
||||
};
|
||||
|
||||
bool operator==(const Rectangle &lhs, const Rectangle &rhs);
|
||||
static inline bool operator!=(const Rectangle &lhs, const Rectangle &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const Rectangle &r);
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,76 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Raspberry Pi Ltd
|
||||
*
|
||||
* Bayer Pixel Format
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ostream>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
#include <libcamera/pixel_format.h>
|
||||
|
||||
#include "libcamera/internal/v4l2_pixelformat.h"
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
enum class Transform;
|
||||
|
||||
class BayerFormat
|
||||
{
|
||||
public:
|
||||
enum Order : uint8_t {
|
||||
BGGR = 0,
|
||||
GBRG = 1,
|
||||
GRBG = 2,
|
||||
RGGB = 3,
|
||||
MONO = 4
|
||||
};
|
||||
|
||||
enum class Packing : uint16_t {
|
||||
None = 0,
|
||||
CSI2 = 1,
|
||||
IPU3 = 2,
|
||||
PISP1 = 3,
|
||||
PISP2 = 4,
|
||||
};
|
||||
|
||||
constexpr BayerFormat()
|
||||
: order(Order::BGGR), bitDepth(0), packing(Packing::None)
|
||||
{
|
||||
}
|
||||
|
||||
constexpr BayerFormat(Order o, uint8_t b, Packing p)
|
||||
: order(o), bitDepth(b), packing(p)
|
||||
{
|
||||
}
|
||||
|
||||
static const BayerFormat &fromMbusCode(unsigned int mbusCode);
|
||||
bool isValid() const { return bitDepth != 0; }
|
||||
|
||||
std::string toString() const;
|
||||
|
||||
V4L2PixelFormat toV4L2PixelFormat() const;
|
||||
static BayerFormat fromV4L2PixelFormat(V4L2PixelFormat v4l2Format);
|
||||
PixelFormat toPixelFormat() const;
|
||||
static BayerFormat fromPixelFormat(PixelFormat format);
|
||||
BayerFormat transform(Transform t) const;
|
||||
|
||||
Order order;
|
||||
uint8_t bitDepth;
|
||||
|
||||
Packing packing;
|
||||
};
|
||||
|
||||
bool operator==(const BayerFormat &lhs, const BayerFormat &rhs);
|
||||
static inline bool operator!=(const BayerFormat &lhs, const BayerFormat &rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const BayerFormat &f);
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,87 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Byte stream buffer
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <type_traits>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
#include <libcamera/base/span.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class ByteStreamBuffer
|
||||
{
|
||||
public:
|
||||
ByteStreamBuffer(const uint8_t *base, size_t size);
|
||||
ByteStreamBuffer(uint8_t *base, size_t size);
|
||||
ByteStreamBuffer(ByteStreamBuffer &&other);
|
||||
ByteStreamBuffer &operator=(ByteStreamBuffer &&other);
|
||||
|
||||
const uint8_t *base() const { return base_; }
|
||||
uint32_t offset() const { return (write_ ? write_ : read_) - base_; }
|
||||
size_t size() const { return size_; }
|
||||
bool overflow() const { return overflow_; }
|
||||
|
||||
ByteStreamBuffer carveOut(size_t size);
|
||||
int skip(size_t size);
|
||||
|
||||
template<typename T>
|
||||
int read(T *t)
|
||||
{
|
||||
return read(reinterpret_cast<uint8_t *>(t), sizeof(*t));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int read(const Span<T> &data)
|
||||
{
|
||||
return read(reinterpret_cast<uint8_t *>(data.data()),
|
||||
data.size_bytes());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const std::remove_reference_t<T> *read(size_t count = 1)
|
||||
{
|
||||
using return_type = const std::remove_reference_t<T> *;
|
||||
return reinterpret_cast<return_type>(read(sizeof(T), count));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int write(const T *t)
|
||||
{
|
||||
return write(reinterpret_cast<const uint8_t *>(t), sizeof(*t));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
int write(const Span<T> &data)
|
||||
{
|
||||
return write(reinterpret_cast<const uint8_t *>(data.data()),
|
||||
data.size_bytes());
|
||||
}
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY(ByteStreamBuffer)
|
||||
|
||||
void setOverflow();
|
||||
|
||||
int read(uint8_t *data, size_t size);
|
||||
const uint8_t *read(size_t size, size_t count);
|
||||
int write(const uint8_t *data, size_t size);
|
||||
|
||||
ByteStreamBuffer *parent_;
|
||||
|
||||
const uint8_t *base_;
|
||||
size_t size_;
|
||||
bool overflow_;
|
||||
|
||||
const uint8_t *read_;
|
||||
uint8_t *write_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
75
spider-cam/libcamera/include/libcamera/internal/camera.h
Normal file
75
spider-cam/libcamera/include/libcamera/internal/camera.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2021, Google Inc.
|
||||
*
|
||||
* Camera private data
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
|
||||
#include <libcamera/camera.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class CameraControlValidator;
|
||||
class PipelineHandler;
|
||||
class Stream;
|
||||
|
||||
class Camera::Private : public Extensible::Private
|
||||
{
|
||||
LIBCAMERA_DECLARE_PUBLIC(Camera)
|
||||
|
||||
public:
|
||||
Private(PipelineHandler *pipe);
|
||||
~Private();
|
||||
|
||||
PipelineHandler *pipe() { return pipe_.get(); }
|
||||
|
||||
std::list<Request *> queuedRequests_;
|
||||
ControlInfoMap controlInfo_;
|
||||
ControlList properties_;
|
||||
|
||||
uint32_t requestSequence_;
|
||||
|
||||
const CameraControlValidator *validator() const { return validator_.get(); }
|
||||
|
||||
private:
|
||||
enum State {
|
||||
CameraAvailable,
|
||||
CameraAcquired,
|
||||
CameraConfigured,
|
||||
CameraStopping,
|
||||
CameraRunning,
|
||||
};
|
||||
|
||||
bool isAcquired() const;
|
||||
bool isRunning() const;
|
||||
int isAccessAllowed(State state, bool allowDisconnected = false,
|
||||
const char *from = __builtin_FUNCTION()) const;
|
||||
int isAccessAllowed(State low, State high,
|
||||
bool allowDisconnected = false,
|
||||
const char *from = __builtin_FUNCTION()) const;
|
||||
|
||||
void disconnect();
|
||||
void setState(State state);
|
||||
|
||||
std::shared_ptr<PipelineHandler> pipe_;
|
||||
std::string id_;
|
||||
std::set<Stream *> streams_;
|
||||
std::set<const Stream *> activeStreams_;
|
||||
|
||||
bool disconnected_;
|
||||
std::atomic<State> state_;
|
||||
|
||||
std::unique_ptr<CameraControlValidator> validator_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,28 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Camera controls
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "libcamera/internal/control_validator.h"
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Camera;
|
||||
|
||||
class CameraControlValidator final : public ControlValidator
|
||||
{
|
||||
public:
|
||||
CameraControlValidator(Camera *camera);
|
||||
|
||||
const std::string &name() const override;
|
||||
bool validate(unsigned int id) const override;
|
||||
|
||||
private:
|
||||
Camera *camera_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,49 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2021, Google Inc.
|
||||
*
|
||||
* A camera lens controller
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
#include <libcamera/base/log.h>
|
||||
|
||||
#include <libcamera/controls.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class MediaEntity;
|
||||
class V4L2Subdevice;
|
||||
|
||||
class CameraLens : protected Loggable
|
||||
{
|
||||
public:
|
||||
explicit CameraLens(const MediaEntity *entity);
|
||||
~CameraLens();
|
||||
|
||||
int init();
|
||||
int setFocusPosition(int32_t position);
|
||||
|
||||
const std::string &model() const { return model_; }
|
||||
|
||||
const ControlInfoMap &controls() const;
|
||||
|
||||
protected:
|
||||
std::string logPrefix() const override;
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY_AND_MOVE(CameraLens)
|
||||
|
||||
int validateLensDriver();
|
||||
|
||||
const MediaEntity *entity_;
|
||||
std::unique_ptr<V4L2Subdevice> subdev_;
|
||||
|
||||
std::string model_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,69 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2023, Ideas on Board Oy.
|
||||
*
|
||||
* Camera manager private data
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libcamera/camera_manager.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <sys/types.h>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
#include <libcamera/base/mutex.h>
|
||||
#include <libcamera/base/thread.h>
|
||||
#include <libcamera/base/thread_annotations.h>
|
||||
|
||||
#include "libcamera/internal/ipa_manager.h"
|
||||
#include "libcamera/internal/process.h"
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Camera;
|
||||
class DeviceEnumerator;
|
||||
|
||||
class CameraManager::Private : public Extensible::Private, public Thread
|
||||
{
|
||||
LIBCAMERA_DECLARE_PUBLIC(CameraManager)
|
||||
|
||||
public:
|
||||
Private();
|
||||
|
||||
int start();
|
||||
void addCamera(std::shared_ptr<Camera> camera) LIBCAMERA_TSA_EXCLUDES(mutex_);
|
||||
void removeCamera(std::shared_ptr<Camera> camera) LIBCAMERA_TSA_EXCLUDES(mutex_);
|
||||
|
||||
protected:
|
||||
void run() override;
|
||||
|
||||
private:
|
||||
int init();
|
||||
void createPipelineHandlers();
|
||||
void pipelineFactoryMatch(const PipelineHandlerFactoryBase *factory);
|
||||
void cleanup() LIBCAMERA_TSA_EXCLUDES(mutex_);
|
||||
|
||||
/*
|
||||
* This mutex protects
|
||||
*
|
||||
* - initialized_ and status_ during initialization
|
||||
* - cameras_ after initialization
|
||||
*/
|
||||
mutable Mutex mutex_;
|
||||
std::vector<std::shared_ptr<Camera>> cameras_ LIBCAMERA_TSA_GUARDED_BY(mutex_);
|
||||
|
||||
ConditionVariable cv_;
|
||||
bool initialized_ LIBCAMERA_TSA_GUARDED_BY(mutex_);
|
||||
int status_ LIBCAMERA_TSA_GUARDED_BY(mutex_);
|
||||
|
||||
std::unique_ptr<DeviceEnumerator> enumerator_;
|
||||
|
||||
IPAManager ipaManager_;
|
||||
ProcessManager processManager_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
126
spider-cam/libcamera/include/libcamera/internal/camera_sensor.h
Normal file
126
spider-cam/libcamera/include/libcamera/internal/camera_sensor.h
Normal file
@@ -0,0 +1,126 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* A camera sensor
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
#include <libcamera/base/log.h>
|
||||
|
||||
#include <libcamera/control_ids.h>
|
||||
#include <libcamera/controls.h>
|
||||
#include <libcamera/geometry.h>
|
||||
#include <libcamera/orientation.h>
|
||||
#include <libcamera/transform.h>
|
||||
|
||||
#include <libcamera/ipa/core_ipa_interface.h>
|
||||
|
||||
#include "libcamera/internal/bayer_format.h"
|
||||
#include "libcamera/internal/formats.h"
|
||||
#include "libcamera/internal/v4l2_subdevice.h"
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class CameraLens;
|
||||
class MediaEntity;
|
||||
class SensorConfiguration;
|
||||
|
||||
struct CameraSensorProperties;
|
||||
|
||||
enum class Orientation;
|
||||
|
||||
class CameraSensor : protected Loggable
|
||||
{
|
||||
public:
|
||||
explicit CameraSensor(const MediaEntity *entity);
|
||||
~CameraSensor();
|
||||
|
||||
int init();
|
||||
|
||||
const std::string &model() const { return model_; }
|
||||
const std::string &id() const { return id_; }
|
||||
|
||||
const MediaEntity *entity() const { return entity_; }
|
||||
V4L2Subdevice *device() { return subdev_.get(); }
|
||||
|
||||
CameraLens *focusLens() { return focusLens_.get(); }
|
||||
|
||||
const std::vector<unsigned int> &mbusCodes() const { return mbusCodes_; }
|
||||
std::vector<Size> sizes(unsigned int mbusCode) const;
|
||||
Size resolution() const;
|
||||
|
||||
V4L2SubdeviceFormat getFormat(const std::vector<unsigned int> &mbusCodes,
|
||||
const Size &size) const;
|
||||
int setFormat(V4L2SubdeviceFormat *format,
|
||||
Transform transform = Transform::Identity);
|
||||
int tryFormat(V4L2SubdeviceFormat *format) const;
|
||||
|
||||
int applyConfiguration(const SensorConfiguration &config,
|
||||
Transform transform = Transform::Identity,
|
||||
V4L2SubdeviceFormat *sensorFormat = nullptr);
|
||||
|
||||
const ControlList &properties() const { return properties_; }
|
||||
int sensorInfo(IPACameraSensorInfo *info) const;
|
||||
Transform computeTransform(Orientation *orientation) const;
|
||||
BayerFormat::Order bayerOrder(Transform t) const;
|
||||
|
||||
const ControlInfoMap &controls() const;
|
||||
ControlList getControls(const std::vector<uint32_t> &ids);
|
||||
int setControls(ControlList *ctrls);
|
||||
|
||||
const std::vector<controls::draft::TestPatternModeEnum> &testPatternModes() const
|
||||
{
|
||||
return testPatternModes_;
|
||||
}
|
||||
int setTestPatternMode(controls::draft::TestPatternModeEnum mode);
|
||||
|
||||
protected:
|
||||
std::string logPrefix() const override;
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY(CameraSensor)
|
||||
|
||||
int generateId();
|
||||
int validateSensorDriver();
|
||||
void initVimcDefaultProperties();
|
||||
void initStaticProperties();
|
||||
void initTestPatternModes();
|
||||
int initProperties();
|
||||
int discoverAncillaryDevices();
|
||||
int applyTestPatternMode(controls::draft::TestPatternModeEnum mode);
|
||||
|
||||
const MediaEntity *entity_;
|
||||
std::unique_ptr<V4L2Subdevice> subdev_;
|
||||
unsigned int pad_;
|
||||
|
||||
const CameraSensorProperties *staticProps_;
|
||||
|
||||
std::string model_;
|
||||
std::string id_;
|
||||
|
||||
V4L2Subdevice::Formats formats_;
|
||||
std::vector<unsigned int> mbusCodes_;
|
||||
std::vector<Size> sizes_;
|
||||
std::vector<controls::draft::TestPatternModeEnum> testPatternModes_;
|
||||
controls::draft::TestPatternModeEnum testPatternMode_;
|
||||
|
||||
Size pixelArraySize_;
|
||||
Rectangle activeArea_;
|
||||
const BayerFormat *bayerFormat_;
|
||||
bool supportFlips_;
|
||||
bool flipsAlterBayerOrder_;
|
||||
Orientation mountingOrientation_;
|
||||
|
||||
ControlList properties_;
|
||||
|
||||
std::unique_ptr<CameraLens> focusLens_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,25 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2021, Google Inc.
|
||||
*
|
||||
* Database of camera sensor properties
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <libcamera/control_ids.h>
|
||||
#include <libcamera/geometry.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
struct CameraSensorProperties {
|
||||
static const CameraSensorProperties *get(const std::string &sensor);
|
||||
|
||||
Size unitCellSize;
|
||||
std::map<controls::draft::TestPatternModeEnum, int32_t> testPatternModes;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,62 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Control (de)serializer
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/controls.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class ByteStreamBuffer;
|
||||
|
||||
class ControlSerializer
|
||||
{
|
||||
public:
|
||||
enum class Role {
|
||||
Proxy,
|
||||
Worker
|
||||
};
|
||||
|
||||
ControlSerializer(Role role);
|
||||
|
||||
void reset();
|
||||
|
||||
static size_t binarySize(const ControlInfoMap &infoMap);
|
||||
static size_t binarySize(const ControlList &list);
|
||||
|
||||
int serialize(const ControlInfoMap &infoMap, ByteStreamBuffer &buffer);
|
||||
int serialize(const ControlList &list, ByteStreamBuffer &buffer);
|
||||
|
||||
template<typename T>
|
||||
T deserialize(ByteStreamBuffer &buffer);
|
||||
|
||||
bool isCached(const ControlInfoMap &infoMap);
|
||||
|
||||
private:
|
||||
static size_t binarySize(const ControlValue &value);
|
||||
static size_t binarySize(const ControlInfo &info);
|
||||
|
||||
static void store(const ControlValue &value, ByteStreamBuffer &buffer);
|
||||
static void store(const ControlInfo &info, ByteStreamBuffer &buffer);
|
||||
|
||||
ControlValue loadControlValue(ByteStreamBuffer &buffer,
|
||||
bool isArray = false, unsigned int count = 1);
|
||||
ControlInfo loadControlInfo(ByteStreamBuffer &buffer);
|
||||
|
||||
unsigned int serial_;
|
||||
unsigned int serialSeed_;
|
||||
std::vector<std::unique_ptr<ControlId>> controlIds_;
|
||||
std::vector<std::unique_ptr<ControlIdMap>> controlIdMaps_;
|
||||
std::map<unsigned int, ControlInfoMap> infoMaps_;
|
||||
std::map<const ControlInfoMap *, unsigned int> infoMapHandles_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,25 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Control validator
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class ControlId;
|
||||
|
||||
class ControlValidator
|
||||
{
|
||||
public:
|
||||
virtual ~ControlValidator() = default;
|
||||
|
||||
virtual const std::string &name() const = 0;
|
||||
virtual bool validate(unsigned int id) const = 0;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
109
spider-cam/libcamera/include/libcamera/internal/converter.h
Normal file
109
spider-cam/libcamera/include/libcamera/internal/converter.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Laurent Pinchart
|
||||
* Copyright 2022 NXP
|
||||
*
|
||||
* Generic format converter interface
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
#include <libcamera/base/signal.h>
|
||||
|
||||
#include <libcamera/geometry.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class FrameBuffer;
|
||||
class MediaDevice;
|
||||
class PixelFormat;
|
||||
class Stream;
|
||||
struct StreamConfiguration;
|
||||
|
||||
class Converter
|
||||
{
|
||||
public:
|
||||
Converter(MediaDevice *media);
|
||||
virtual ~Converter();
|
||||
|
||||
virtual int loadConfiguration(const std::string &filename) = 0;
|
||||
|
||||
virtual bool isValid() const = 0;
|
||||
|
||||
virtual std::vector<PixelFormat> formats(PixelFormat input) = 0;
|
||||
virtual SizeRange sizes(const Size &input) = 0;
|
||||
|
||||
virtual std::tuple<unsigned int, unsigned int>
|
||||
strideAndFrameSize(const PixelFormat &pixelFormat, const Size &size) = 0;
|
||||
|
||||
virtual int configure(const StreamConfiguration &inputCfg,
|
||||
const std::vector<std::reference_wrapper<StreamConfiguration>> &outputCfgs) = 0;
|
||||
virtual int exportBuffers(const Stream *stream, unsigned int count,
|
||||
std::vector<std::unique_ptr<FrameBuffer>> *buffers) = 0;
|
||||
|
||||
virtual int start() = 0;
|
||||
virtual void stop() = 0;
|
||||
|
||||
virtual int queueBuffers(FrameBuffer *input,
|
||||
const std::map<const Stream *, FrameBuffer *> &outputs) = 0;
|
||||
|
||||
Signal<FrameBuffer *> inputBufferReady;
|
||||
Signal<FrameBuffer *> outputBufferReady;
|
||||
|
||||
const std::string &deviceNode() const { return deviceNode_; }
|
||||
|
||||
private:
|
||||
std::string deviceNode_;
|
||||
};
|
||||
|
||||
class ConverterFactoryBase
|
||||
{
|
||||
public:
|
||||
ConverterFactoryBase(const std::string name, std::initializer_list<std::string> compatibles);
|
||||
virtual ~ConverterFactoryBase() = default;
|
||||
|
||||
const std::vector<std::string> &compatibles() const { return compatibles_; }
|
||||
|
||||
static std::unique_ptr<Converter> create(MediaDevice *media);
|
||||
static std::vector<ConverterFactoryBase *> &factories();
|
||||
static std::vector<std::string> names();
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY_AND_MOVE(ConverterFactoryBase)
|
||||
|
||||
static void registerType(ConverterFactoryBase *factory);
|
||||
|
||||
virtual std::unique_ptr<Converter> createInstance(MediaDevice *media) const = 0;
|
||||
|
||||
std::string name_;
|
||||
std::vector<std::string> compatibles_;
|
||||
};
|
||||
|
||||
template<typename _Converter>
|
||||
class ConverterFactory : public ConverterFactoryBase
|
||||
{
|
||||
public:
|
||||
ConverterFactory(const char *name, std::initializer_list<std::string> compatibles)
|
||||
: ConverterFactoryBase(name, compatibles)
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<Converter> createInstance(MediaDevice *media) const override
|
||||
{
|
||||
return std::make_unique<_Converter>(media);
|
||||
}
|
||||
};
|
||||
|
||||
#define REGISTER_CONVERTER(name, converter, compatibles) \
|
||||
static ConverterFactory<converter> global_##converter##Factory(name, compatibles);
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,99 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Laurent Pinchart
|
||||
* Copyright 2022 NXP
|
||||
*
|
||||
* V4l2 M2M Format converter interface
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/log.h>
|
||||
#include <libcamera/base/signal.h>
|
||||
|
||||
#include <libcamera/pixel_format.h>
|
||||
|
||||
#include "libcamera/internal/converter.h"
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class FrameBuffer;
|
||||
class MediaDevice;
|
||||
class Size;
|
||||
class SizeRange;
|
||||
class Stream;
|
||||
struct StreamConfiguration;
|
||||
class V4L2M2MDevice;
|
||||
|
||||
class V4L2M2MConverter : public Converter
|
||||
{
|
||||
public:
|
||||
V4L2M2MConverter(MediaDevice *media);
|
||||
|
||||
int loadConfiguration([[maybe_unused]] const std::string &filename) { return 0; }
|
||||
bool isValid() const { return m2m_ != nullptr; }
|
||||
|
||||
std::vector<PixelFormat> formats(PixelFormat input);
|
||||
SizeRange sizes(const Size &input);
|
||||
|
||||
std::tuple<unsigned int, unsigned int>
|
||||
strideAndFrameSize(const PixelFormat &pixelFormat, const Size &size);
|
||||
|
||||
int configure(const StreamConfiguration &inputCfg,
|
||||
const std::vector<std::reference_wrapper<StreamConfiguration>> &outputCfg);
|
||||
int exportBuffers(const Stream *stream, unsigned int count,
|
||||
std::vector<std::unique_ptr<FrameBuffer>> *buffers);
|
||||
|
||||
int start();
|
||||
void stop();
|
||||
|
||||
int queueBuffers(FrameBuffer *input,
|
||||
const std::map<const Stream *, FrameBuffer *> &outputs);
|
||||
|
||||
private:
|
||||
class V4L2M2MStream : protected Loggable
|
||||
{
|
||||
public:
|
||||
V4L2M2MStream(V4L2M2MConverter *converter, const Stream *stream);
|
||||
|
||||
bool isValid() const { return m2m_ != nullptr; }
|
||||
|
||||
int configure(const StreamConfiguration &inputCfg,
|
||||
const StreamConfiguration &outputCfg);
|
||||
int exportBuffers(unsigned int count,
|
||||
std::vector<std::unique_ptr<FrameBuffer>> *buffers);
|
||||
|
||||
int start();
|
||||
void stop();
|
||||
|
||||
int queueBuffers(FrameBuffer *input, FrameBuffer *output);
|
||||
|
||||
protected:
|
||||
std::string logPrefix() const override;
|
||||
|
||||
private:
|
||||
void captureBufferReady(FrameBuffer *buffer);
|
||||
void outputBufferReady(FrameBuffer *buffer);
|
||||
|
||||
V4L2M2MConverter *converter_;
|
||||
const Stream *stream_;
|
||||
std::unique_ptr<V4L2M2MDevice> m2m_;
|
||||
|
||||
unsigned int inputBufferCount_;
|
||||
unsigned int outputBufferCount_;
|
||||
};
|
||||
|
||||
std::unique_ptr<V4L2M2MDevice> m2m_;
|
||||
|
||||
std::map<const Stream *, std::unique_ptr<V4L2M2MStream>> streams_;
|
||||
std::map<FrameBuffer *, unsigned int> queue_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,5 @@
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
libcamera_internal_headers += files([
|
||||
'converter_v4l2_m2m.h',
|
||||
])
|
||||
@@ -0,0 +1,81 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Raspberry Pi Ltd
|
||||
*
|
||||
* Helper to deal with controls that take effect with a delay
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <libcamera/controls.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class V4L2Device;
|
||||
|
||||
class DelayedControls
|
||||
{
|
||||
public:
|
||||
struct ControlParams {
|
||||
unsigned int delay;
|
||||
bool priorityWrite;
|
||||
};
|
||||
|
||||
DelayedControls(V4L2Device *device,
|
||||
const std::unordered_map<uint32_t, ControlParams> &controlParams);
|
||||
|
||||
void reset();
|
||||
|
||||
bool push(const ControlList &controls);
|
||||
ControlList get(uint32_t sequence);
|
||||
|
||||
void applyControls(uint32_t sequence);
|
||||
|
||||
private:
|
||||
class Info : public ControlValue
|
||||
{
|
||||
public:
|
||||
Info()
|
||||
: updated(false)
|
||||
{
|
||||
}
|
||||
|
||||
Info(const ControlValue &v, bool updated_ = true)
|
||||
: ControlValue(v), updated(updated_)
|
||||
{
|
||||
}
|
||||
|
||||
bool updated;
|
||||
};
|
||||
|
||||
/* \todo Make the listSize configurable at instance creation time. */
|
||||
static constexpr int listSize = 16;
|
||||
class ControlRingBuffer : public std::array<Info, listSize>
|
||||
{
|
||||
public:
|
||||
Info &operator[](unsigned int index)
|
||||
{
|
||||
return std::array<Info, listSize>::operator[](index % listSize);
|
||||
}
|
||||
|
||||
const Info &operator[](unsigned int index) const
|
||||
{
|
||||
return std::array<Info, listSize>::operator[](index % listSize);
|
||||
}
|
||||
};
|
||||
|
||||
V4L2Device *device_;
|
||||
/* \todo Evaluate if we should index on ControlId * or unsigned int */
|
||||
std::unordered_map<const ControlId *, ControlParams> controlParams_;
|
||||
unsigned int maxDelay_;
|
||||
|
||||
uint32_t queueCount_;
|
||||
uint32_t writeCount_;
|
||||
/* \todo Evaluate if we should index on ControlId * or unsigned int */
|
||||
std::unordered_map<const ControlId *, ControlRingBuffer> values_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,57 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018, Google Inc.
|
||||
*
|
||||
* API to enumerate and find media devices
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/signal.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class MediaDevice;
|
||||
|
||||
class DeviceMatch
|
||||
{
|
||||
public:
|
||||
DeviceMatch(const std::string &driver);
|
||||
|
||||
void add(const std::string &entity);
|
||||
|
||||
bool match(const MediaDevice *device) const;
|
||||
|
||||
private:
|
||||
std::string driver_;
|
||||
std::vector<std::string> entities_;
|
||||
};
|
||||
|
||||
class DeviceEnumerator
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr<DeviceEnumerator> create();
|
||||
|
||||
virtual ~DeviceEnumerator();
|
||||
|
||||
virtual int init() = 0;
|
||||
virtual int enumerate() = 0;
|
||||
|
||||
std::shared_ptr<MediaDevice> search(const DeviceMatch &dm);
|
||||
|
||||
Signal<> devicesAdded;
|
||||
|
||||
protected:
|
||||
std::unique_ptr<MediaDevice> createDevice(const std::string &deviceNode);
|
||||
void addDevice(std::unique_ptr<MediaDevice> media);
|
||||
void removeDevice(const std::string &deviceNode);
|
||||
|
||||
private:
|
||||
std::vector<std::shared_ptr<MediaDevice>> devices_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,30 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* sysfs-based device enumerator
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "libcamera/internal/device_enumerator.h"
|
||||
|
||||
class MediaDevice;
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class DeviceEnumeratorSysfs final : public DeviceEnumerator
|
||||
{
|
||||
public:
|
||||
int init();
|
||||
int enumerate();
|
||||
|
||||
private:
|
||||
int populateMediaDevice(MediaDevice *media);
|
||||
std::string lookupDeviceNode(int major, int minor);
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,73 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018-2019, Google Inc.
|
||||
*
|
||||
* udev-based device enumerator
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "libcamera/internal/device_enumerator.h"
|
||||
|
||||
struct udev;
|
||||
struct udev_device;
|
||||
struct udev_monitor;
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class EventNotifier;
|
||||
class MediaDevice;
|
||||
class MediaEntity;
|
||||
|
||||
class DeviceEnumeratorUdev final : public DeviceEnumerator
|
||||
{
|
||||
public:
|
||||
DeviceEnumeratorUdev();
|
||||
~DeviceEnumeratorUdev();
|
||||
|
||||
int init();
|
||||
int enumerate();
|
||||
|
||||
private:
|
||||
using DependencyMap = std::map<dev_t, std::list<MediaEntity *>>;
|
||||
|
||||
struct MediaDeviceDeps {
|
||||
MediaDeviceDeps(std::unique_ptr<MediaDevice> media,
|
||||
DependencyMap deps)
|
||||
: media_(std::move(media)), deps_(std::move(deps))
|
||||
{
|
||||
}
|
||||
|
||||
bool operator==(const MediaDeviceDeps &other) const
|
||||
{
|
||||
return media_ == other.media_;
|
||||
}
|
||||
|
||||
std::unique_ptr<MediaDevice> media_;
|
||||
DependencyMap deps_;
|
||||
};
|
||||
|
||||
int addUdevDevice(struct udev_device *dev);
|
||||
int populateMediaDevice(MediaDevice *media, DependencyMap *deps);
|
||||
std::string lookupDeviceNode(dev_t devnum);
|
||||
|
||||
int addV4L2Device(dev_t devnum);
|
||||
void udevNotify();
|
||||
|
||||
struct udev *udev_;
|
||||
struct udev_monitor *monitor_;
|
||||
EventNotifier *notifier_;
|
||||
|
||||
std::set<dev_t> orphans_;
|
||||
std::list<MediaDeviceDeps> pending_;
|
||||
std::map<dev_t, MediaDeviceDeps *> devMap_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,42 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Raspberry Pi Ltd
|
||||
*
|
||||
* Helper class for dma-buf allocations.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <libcamera/base/flags.h>
|
||||
#include <libcamera/base/unique_fd.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class DmaBufAllocator
|
||||
{
|
||||
public:
|
||||
enum class DmaBufAllocatorFlag {
|
||||
CmaHeap = 1 << 0,
|
||||
SystemHeap = 1 << 1,
|
||||
UDmaBuf = 1 << 2,
|
||||
};
|
||||
|
||||
using DmaBufAllocatorFlags = Flags<DmaBufAllocatorFlag>;
|
||||
|
||||
DmaBufAllocator(DmaBufAllocatorFlags flags = DmaBufAllocatorFlag::CmaHeap);
|
||||
~DmaBufAllocator();
|
||||
bool isValid() const { return providerHandle_.isValid(); }
|
||||
UniqueFD alloc(const char *name, std::size_t size);
|
||||
|
||||
private:
|
||||
UniqueFD allocFromHeap(const char *name, std::size_t size);
|
||||
UniqueFD allocFromUDmaBuf(const char *name, std::size_t size);
|
||||
UniqueFD providerHandle_;
|
||||
DmaBufAllocatorFlag type_;
|
||||
};
|
||||
|
||||
LIBCAMERA_FLAGS_ENABLE_OPERATORS(DmaBufAllocator::DmaBufAllocatorFlag)
|
||||
|
||||
} /* namespace libcamera */
|
||||
66
spider-cam/libcamera/include/libcamera/internal/formats.h
Normal file
66
spider-cam/libcamera/include/libcamera/internal/formats.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* libcamera image formats
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/geometry.h>
|
||||
#include <libcamera/pixel_format.h>
|
||||
|
||||
#include "libcamera/internal/v4l2_pixelformat.h"
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class PixelFormatInfo
|
||||
{
|
||||
public:
|
||||
enum ColourEncoding {
|
||||
ColourEncodingRGB,
|
||||
ColourEncodingYUV,
|
||||
ColourEncodingRAW,
|
||||
};
|
||||
|
||||
struct Plane {
|
||||
unsigned int bytesPerGroup;
|
||||
unsigned int verticalSubSampling;
|
||||
};
|
||||
|
||||
bool isValid() const { return format.isValid(); }
|
||||
|
||||
static const PixelFormatInfo &info(const PixelFormat &format);
|
||||
static const PixelFormatInfo &info(const V4L2PixelFormat &format);
|
||||
static const PixelFormatInfo &info(const std::string &name);
|
||||
|
||||
unsigned int stride(unsigned int width, unsigned int plane,
|
||||
unsigned int align = 1) const;
|
||||
unsigned int planeSize(const Size &size, unsigned int plane,
|
||||
unsigned int align = 1) const;
|
||||
unsigned int planeSize(unsigned int height, unsigned int plane,
|
||||
unsigned int stride) const;
|
||||
unsigned int frameSize(const Size &size, unsigned int align = 1) const;
|
||||
unsigned int frameSize(const Size &size,
|
||||
const std::array<unsigned int, 3> &strides) const;
|
||||
|
||||
unsigned int numPlanes() const;
|
||||
|
||||
/* \todo Add support for non-contiguous memory planes */
|
||||
const char *name;
|
||||
PixelFormat format;
|
||||
std::vector<V4L2PixelFormat> v4l2Formats;
|
||||
unsigned int bitsPerPixel;
|
||||
enum ColourEncoding colourEncoding;
|
||||
bool packed;
|
||||
|
||||
unsigned int pixelsPerGroup;
|
||||
|
||||
std::array<Plane, 3> planes;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,48 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Google Inc.
|
||||
*
|
||||
* Internal frame buffer handling
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
|
||||
#include <libcamera/fence.h>
|
||||
#include <libcamera/framebuffer.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class FrameBuffer::Private : public Extensible::Private
|
||||
{
|
||||
LIBCAMERA_DECLARE_PUBLIC(FrameBuffer)
|
||||
|
||||
public:
|
||||
Private(const std::vector<Plane> &planes, uint64_t cookie = 0);
|
||||
virtual ~Private();
|
||||
|
||||
void setRequest(Request *request) { request_ = request; }
|
||||
bool isContiguous() const { return isContiguous_; }
|
||||
|
||||
Fence *fence() const { return fence_.get(); }
|
||||
void setFence(std::unique_ptr<Fence> fence) { fence_ = std::move(fence); }
|
||||
|
||||
void cancel() { metadata_.status = FrameMetadata::FrameCancelled; }
|
||||
|
||||
FrameMetadata &metadata() { return metadata_; }
|
||||
|
||||
private:
|
||||
std::vector<Plane> planes_;
|
||||
FrameMetadata metadata_;
|
||||
uint64_t cookie_;
|
||||
|
||||
std::unique_ptr<Fence> fence_;
|
||||
Request *request_;
|
||||
bool isContiguous_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,352 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Google Inc.
|
||||
*
|
||||
* Image Processing Algorithm data serializer
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <deque>
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/flags.h>
|
||||
#include <libcamera/base/log.h>
|
||||
|
||||
#include <libcamera/control_ids.h>
|
||||
#include <libcamera/framebuffer.h>
|
||||
#include <libcamera/geometry.h>
|
||||
#include <libcamera/ipa/ipa_interface.h>
|
||||
|
||||
#include "libcamera/internal/byte_stream_buffer.h"
|
||||
#include "libcamera/internal/camera_sensor.h"
|
||||
#include "libcamera/internal/control_serializer.h"
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
LOG_DECLARE_CATEGORY(IPADataSerializer)
|
||||
|
||||
namespace {
|
||||
|
||||
template<typename T,
|
||||
std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr>
|
||||
void appendPOD(std::vector<uint8_t> &vec, T val)
|
||||
{
|
||||
constexpr size_t byteWidth = sizeof(val);
|
||||
vec.resize(vec.size() + byteWidth);
|
||||
memcpy(&*(vec.end() - byteWidth), &val, byteWidth);
|
||||
}
|
||||
|
||||
template<typename T,
|
||||
std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr>
|
||||
T readPOD(std::vector<uint8_t>::const_iterator it, size_t pos,
|
||||
std::vector<uint8_t>::const_iterator end)
|
||||
{
|
||||
ASSERT(pos + it < end);
|
||||
|
||||
T ret = 0;
|
||||
memcpy(&ret, &(*(it + pos)), sizeof(ret));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename T,
|
||||
std::enable_if_t<std::is_arithmetic_v<T>> * = nullptr>
|
||||
T readPOD(std::vector<uint8_t> &vec, size_t pos)
|
||||
{
|
||||
return readPOD<T>(vec.cbegin(), pos, vec.end());
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
template<typename T>
|
||||
class IPADataSerializer
|
||||
{
|
||||
public:
|
||||
static std::tuple<std::vector<uint8_t>, std::vector<SharedFD>>
|
||||
serialize(const T &data, ControlSerializer *cs = nullptr);
|
||||
|
||||
static T deserialize(const std::vector<uint8_t> &data,
|
||||
ControlSerializer *cs = nullptr);
|
||||
static T deserialize(std::vector<uint8_t>::const_iterator dataBegin,
|
||||
std::vector<uint8_t>::const_iterator dataEnd,
|
||||
ControlSerializer *cs = nullptr);
|
||||
|
||||
static T deserialize(const std::vector<uint8_t> &data,
|
||||
const std::vector<SharedFD> &fds,
|
||||
ControlSerializer *cs = nullptr);
|
||||
static T deserialize(std::vector<uint8_t>::const_iterator dataBegin,
|
||||
std::vector<uint8_t>::const_iterator dataEnd,
|
||||
std::vector<SharedFD>::const_iterator fdsBegin,
|
||||
std::vector<SharedFD>::const_iterator fdsEnd,
|
||||
ControlSerializer *cs = nullptr);
|
||||
};
|
||||
|
||||
#ifndef __DOXYGEN__
|
||||
|
||||
/*
|
||||
* Serialization format for vector of type V:
|
||||
*
|
||||
* 4 bytes - uint32_t Length of vector, in number of elements
|
||||
*
|
||||
* For every element in the vector:
|
||||
*
|
||||
* 4 bytes - uint32_t Size of element, in bytes
|
||||
* 4 bytes - uint32_t Number of fds for the element
|
||||
* X bytes - Serialized element
|
||||
*
|
||||
* \todo Support elements that are references
|
||||
*/
|
||||
template<typename V>
|
||||
class IPADataSerializer<std::vector<V>>
|
||||
{
|
||||
public:
|
||||
static std::tuple<std::vector<uint8_t>, std::vector<SharedFD>>
|
||||
serialize(const std::vector<V> &data, ControlSerializer *cs = nullptr)
|
||||
{
|
||||
std::vector<uint8_t> dataVec;
|
||||
std::vector<SharedFD> fdsVec;
|
||||
|
||||
/* Serialize the length. */
|
||||
uint32_t vecLen = data.size();
|
||||
appendPOD<uint32_t>(dataVec, vecLen);
|
||||
|
||||
/* Serialize the members. */
|
||||
for (auto const &it : data) {
|
||||
std::vector<uint8_t> dvec;
|
||||
std::vector<SharedFD> fvec;
|
||||
|
||||
std::tie(dvec, fvec) =
|
||||
IPADataSerializer<V>::serialize(it, cs);
|
||||
|
||||
appendPOD<uint32_t>(dataVec, dvec.size());
|
||||
appendPOD<uint32_t>(dataVec, fvec.size());
|
||||
|
||||
dataVec.insert(dataVec.end(), dvec.begin(), dvec.end());
|
||||
fdsVec.insert(fdsVec.end(), fvec.begin(), fvec.end());
|
||||
}
|
||||
|
||||
return { dataVec, fdsVec };
|
||||
}
|
||||
|
||||
static std::vector<V> deserialize(std::vector<uint8_t> &data, ControlSerializer *cs = nullptr)
|
||||
{
|
||||
return deserialize(data.cbegin(), data.cend(), cs);
|
||||
}
|
||||
|
||||
static std::vector<V> deserialize(std::vector<uint8_t>::const_iterator dataBegin,
|
||||
std::vector<uint8_t>::const_iterator dataEnd,
|
||||
ControlSerializer *cs = nullptr)
|
||||
{
|
||||
std::vector<SharedFD> fds;
|
||||
return deserialize(dataBegin, dataEnd, fds.cbegin(), fds.cend(), cs);
|
||||
}
|
||||
|
||||
static std::vector<V> deserialize(std::vector<uint8_t> &data, std::vector<SharedFD> &fds,
|
||||
ControlSerializer *cs = nullptr)
|
||||
{
|
||||
return deserialize(data.cbegin(), data.cend(), fds.cbegin(), fds.cend(), cs);
|
||||
}
|
||||
|
||||
static std::vector<V> deserialize(std::vector<uint8_t>::const_iterator dataBegin,
|
||||
std::vector<uint8_t>::const_iterator dataEnd,
|
||||
std::vector<SharedFD>::const_iterator fdsBegin,
|
||||
[[maybe_unused]] std::vector<SharedFD>::const_iterator fdsEnd,
|
||||
ControlSerializer *cs = nullptr)
|
||||
{
|
||||
uint32_t vecLen = readPOD<uint32_t>(dataBegin, 0, dataEnd);
|
||||
std::vector<V> ret(vecLen);
|
||||
|
||||
std::vector<uint8_t>::const_iterator dataIter = dataBegin + 4;
|
||||
std::vector<SharedFD>::const_iterator fdIter = fdsBegin;
|
||||
for (uint32_t i = 0; i < vecLen; i++) {
|
||||
uint32_t sizeofData = readPOD<uint32_t>(dataIter, 0, dataEnd);
|
||||
uint32_t sizeofFds = readPOD<uint32_t>(dataIter, 4, dataEnd);
|
||||
dataIter += 8;
|
||||
|
||||
ret[i] = IPADataSerializer<V>::deserialize(dataIter,
|
||||
dataIter + sizeofData,
|
||||
fdIter,
|
||||
fdIter + sizeofFds,
|
||||
cs);
|
||||
|
||||
dataIter += sizeofData;
|
||||
fdIter += sizeofFds;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Serialization format for map of key type K and value type V:
|
||||
*
|
||||
* 4 bytes - uint32_t Length of map, in number of pairs
|
||||
*
|
||||
* For every pair in the map:
|
||||
*
|
||||
* 4 bytes - uint32_t Size of key, in bytes
|
||||
* 4 bytes - uint32_t Number of fds for the key
|
||||
* X bytes - Serialized key
|
||||
* 4 bytes - uint32_t Size of value, in bytes
|
||||
* 4 bytes - uint32_t Number of fds for the value
|
||||
* X bytes - Serialized value
|
||||
*
|
||||
* \todo Support keys or values that are references
|
||||
*/
|
||||
template<typename K, typename V>
|
||||
class IPADataSerializer<std::map<K, V>>
|
||||
{
|
||||
public:
|
||||
static std::tuple<std::vector<uint8_t>, std::vector<SharedFD>>
|
||||
serialize(const std::map<K, V> &data, ControlSerializer *cs = nullptr)
|
||||
{
|
||||
std::vector<uint8_t> dataVec;
|
||||
std::vector<SharedFD> fdsVec;
|
||||
|
||||
/* Serialize the length. */
|
||||
uint32_t mapLen = data.size();
|
||||
appendPOD<uint32_t>(dataVec, mapLen);
|
||||
|
||||
/* Serialize the members. */
|
||||
for (auto const &it : data) {
|
||||
std::vector<uint8_t> dvec;
|
||||
std::vector<SharedFD> fvec;
|
||||
|
||||
std::tie(dvec, fvec) =
|
||||
IPADataSerializer<K>::serialize(it.first, cs);
|
||||
|
||||
appendPOD<uint32_t>(dataVec, dvec.size());
|
||||
appendPOD<uint32_t>(dataVec, fvec.size());
|
||||
|
||||
dataVec.insert(dataVec.end(), dvec.begin(), dvec.end());
|
||||
fdsVec.insert(fdsVec.end(), fvec.begin(), fvec.end());
|
||||
|
||||
std::tie(dvec, fvec) =
|
||||
IPADataSerializer<V>::serialize(it.second, cs);
|
||||
|
||||
appendPOD<uint32_t>(dataVec, dvec.size());
|
||||
appendPOD<uint32_t>(dataVec, fvec.size());
|
||||
|
||||
dataVec.insert(dataVec.end(), dvec.begin(), dvec.end());
|
||||
fdsVec.insert(fdsVec.end(), fvec.begin(), fvec.end());
|
||||
}
|
||||
|
||||
return { dataVec, fdsVec };
|
||||
}
|
||||
|
||||
static std::map<K, V> deserialize(std::vector<uint8_t> &data, ControlSerializer *cs = nullptr)
|
||||
{
|
||||
return deserialize(data.cbegin(), data.cend(), cs);
|
||||
}
|
||||
|
||||
static std::map<K, V> deserialize(std::vector<uint8_t>::const_iterator dataBegin,
|
||||
std::vector<uint8_t>::const_iterator dataEnd,
|
||||
ControlSerializer *cs = nullptr)
|
||||
{
|
||||
std::vector<SharedFD> fds;
|
||||
return deserialize(dataBegin, dataEnd, fds.cbegin(), fds.cend(), cs);
|
||||
}
|
||||
|
||||
static std::map<K, V> deserialize(std::vector<uint8_t> &data, std::vector<SharedFD> &fds,
|
||||
ControlSerializer *cs = nullptr)
|
||||
{
|
||||
return deserialize(data.cbegin(), data.cend(), fds.cbegin(), fds.cend(), cs);
|
||||
}
|
||||
|
||||
static std::map<K, V> deserialize(std::vector<uint8_t>::const_iterator dataBegin,
|
||||
std::vector<uint8_t>::const_iterator dataEnd,
|
||||
std::vector<SharedFD>::const_iterator fdsBegin,
|
||||
[[maybe_unused]] std::vector<SharedFD>::const_iterator fdsEnd,
|
||||
ControlSerializer *cs = nullptr)
|
||||
{
|
||||
std::map<K, V> ret;
|
||||
|
||||
uint32_t mapLen = readPOD<uint32_t>(dataBegin, 0, dataEnd);
|
||||
|
||||
std::vector<uint8_t>::const_iterator dataIter = dataBegin + 4;
|
||||
std::vector<SharedFD>::const_iterator fdIter = fdsBegin;
|
||||
for (uint32_t i = 0; i < mapLen; i++) {
|
||||
uint32_t sizeofData = readPOD<uint32_t>(dataIter, 0, dataEnd);
|
||||
uint32_t sizeofFds = readPOD<uint32_t>(dataIter, 4, dataEnd);
|
||||
dataIter += 8;
|
||||
|
||||
K key = IPADataSerializer<K>::deserialize(dataIter,
|
||||
dataIter + sizeofData,
|
||||
fdIter,
|
||||
fdIter + sizeofFds,
|
||||
cs);
|
||||
|
||||
dataIter += sizeofData;
|
||||
fdIter += sizeofFds;
|
||||
sizeofData = readPOD<uint32_t>(dataIter, 0, dataEnd);
|
||||
sizeofFds = readPOD<uint32_t>(dataIter, 4, dataEnd);
|
||||
dataIter += 8;
|
||||
|
||||
const V value = IPADataSerializer<V>::deserialize(dataIter,
|
||||
dataIter + sizeofData,
|
||||
fdIter,
|
||||
fdIter + sizeofFds,
|
||||
cs);
|
||||
ret.insert({ key, value });
|
||||
|
||||
dataIter += sizeofData;
|
||||
fdIter += sizeofFds;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
/* Serialization format for Flags is same as for PODs */
|
||||
template<typename E>
|
||||
class IPADataSerializer<Flags<E>>
|
||||
{
|
||||
public:
|
||||
static std::tuple<std::vector<uint8_t>, std::vector<SharedFD>>
|
||||
serialize(const Flags<E> &data, [[maybe_unused]] ControlSerializer *cs = nullptr)
|
||||
{
|
||||
std::vector<uint8_t> dataVec;
|
||||
dataVec.reserve(sizeof(Flags<E>));
|
||||
appendPOD<uint32_t>(dataVec, static_cast<typename Flags<E>::Type>(data));
|
||||
|
||||
return { dataVec, {} };
|
||||
}
|
||||
|
||||
static Flags<E> deserialize(std::vector<uint8_t> &data,
|
||||
[[maybe_unused]] ControlSerializer *cs = nullptr)
|
||||
{
|
||||
return deserialize(data.cbegin(), data.cend());
|
||||
}
|
||||
|
||||
static Flags<E> deserialize(std::vector<uint8_t>::const_iterator dataBegin,
|
||||
std::vector<uint8_t>::const_iterator dataEnd,
|
||||
[[maybe_unused]] ControlSerializer *cs = nullptr)
|
||||
{
|
||||
return Flags<E>{ static_cast<E>(readPOD<uint32_t>(dataBegin, 0, dataEnd)) };
|
||||
}
|
||||
|
||||
static Flags<E> deserialize(std::vector<uint8_t> &data,
|
||||
[[maybe_unused]] std::vector<SharedFD> &fds,
|
||||
[[maybe_unused]] ControlSerializer *cs = nullptr)
|
||||
{
|
||||
return deserialize(data.cbegin(), data.cend());
|
||||
}
|
||||
|
||||
static Flags<E> deserialize(std::vector<uint8_t>::const_iterator dataBegin,
|
||||
std::vector<uint8_t>::const_iterator dataEnd,
|
||||
[[maybe_unused]] std::vector<SharedFD>::const_iterator fdsBegin,
|
||||
[[maybe_unused]] std::vector<SharedFD>::const_iterator fdsEnd,
|
||||
[[maybe_unused]] ControlSerializer *cs = nullptr)
|
||||
{
|
||||
return deserialize(dataBegin, dataEnd);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* __DOXYGEN__ */
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,77 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Image Processing Algorithm module manager
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/log.h>
|
||||
|
||||
#include <libcamera/ipa/ipa_interface.h>
|
||||
#include <libcamera/ipa/ipa_module_info.h>
|
||||
|
||||
#include "libcamera/internal/ipa_module.h"
|
||||
#include "libcamera/internal/pipeline_handler.h"
|
||||
#include "libcamera/internal/pub_key.h"
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
LOG_DECLARE_CATEGORY(IPAManager)
|
||||
|
||||
class IPAManager
|
||||
{
|
||||
public:
|
||||
IPAManager();
|
||||
~IPAManager();
|
||||
|
||||
template<typename T>
|
||||
static std::unique_ptr<T> createIPA(PipelineHandler *pipe,
|
||||
uint32_t minVersion,
|
||||
uint32_t maxVersion)
|
||||
{
|
||||
IPAModule *m = self_->module(pipe, minVersion, maxVersion);
|
||||
if (!m)
|
||||
return nullptr;
|
||||
|
||||
std::unique_ptr<T> proxy = std::make_unique<T>(m, !self_->isSignatureValid(m));
|
||||
if (!proxy->isValid()) {
|
||||
LOG(IPAManager, Error) << "Failed to load proxy";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return proxy;
|
||||
}
|
||||
|
||||
#if HAVE_IPA_PUBKEY
|
||||
static const PubKey &pubKey()
|
||||
{
|
||||
return pubKey_;
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
static IPAManager *self_;
|
||||
|
||||
void parseDir(const char *libDir, unsigned int maxDepth,
|
||||
std::vector<std::string> &files);
|
||||
unsigned int addDir(const char *libDir, unsigned int maxDepth = 0);
|
||||
|
||||
IPAModule *module(PipelineHandler *pipe, uint32_t minVersion,
|
||||
uint32_t maxVersion);
|
||||
|
||||
bool isSignatureValid(IPAModule *ipa) const;
|
||||
|
||||
std::vector<IPAModule *> modules_;
|
||||
|
||||
#if HAVE_IPA_PUBKEY
|
||||
static const uint8_t publicKeyData_[];
|
||||
static const PubKey pubKey_;
|
||||
#endif
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
60
spider-cam/libcamera/include/libcamera/internal/ipa_module.h
Normal file
60
spider-cam/libcamera/include/libcamera/internal/ipa_module.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Image Processing Algorithm module
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/log.h>
|
||||
|
||||
#include <libcamera/ipa/ipa_interface.h>
|
||||
#include <libcamera/ipa/ipa_module_info.h>
|
||||
|
||||
#include "libcamera/internal/pipeline_handler.h"
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class IPAModule : public Loggable
|
||||
{
|
||||
public:
|
||||
explicit IPAModule(const std::string &libPath);
|
||||
~IPAModule();
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
const struct IPAModuleInfo &info() const;
|
||||
const std::vector<uint8_t> signature() const;
|
||||
const std::string &path() const;
|
||||
|
||||
bool load();
|
||||
|
||||
IPAInterface *createInterface();
|
||||
|
||||
bool match(PipelineHandler *pipe,
|
||||
uint32_t minVersion, uint32_t maxVersion) const;
|
||||
|
||||
protected:
|
||||
std::string logPrefix() const override;
|
||||
|
||||
private:
|
||||
int loadIPAModuleInfo();
|
||||
|
||||
struct IPAModuleInfo info_;
|
||||
std::vector<uint8_t> signature_;
|
||||
|
||||
std::string libPath_;
|
||||
bool valid_;
|
||||
bool loaded_;
|
||||
|
||||
void *dlHandle_;
|
||||
typedef IPAInterface *(*IPAIntfFactory)(void);
|
||||
IPAIntfFactory ipaCreate_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
46
spider-cam/libcamera/include/libcamera/internal/ipa_proxy.h
Normal file
46
spider-cam/libcamera/include/libcamera/internal/ipa_proxy.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Image Processing Algorithm proxy
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/ipa/ipa_interface.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class IPAModule;
|
||||
|
||||
class IPAProxy : public IPAInterface
|
||||
{
|
||||
public:
|
||||
enum ProxyState {
|
||||
ProxyStopped,
|
||||
ProxyStopping,
|
||||
ProxyRunning,
|
||||
};
|
||||
|
||||
IPAProxy(IPAModule *ipam);
|
||||
~IPAProxy();
|
||||
|
||||
bool isValid() const { return valid_; }
|
||||
|
||||
std::string configurationFile(const std::string &file) const;
|
||||
|
||||
protected:
|
||||
std::string resolvePath(const std::string &file) const;
|
||||
|
||||
bool valid_;
|
||||
ProxyState state_;
|
||||
|
||||
private:
|
||||
IPAModule *ipam_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
68
spider-cam/libcamera/include/libcamera/internal/ipc_pipe.h
Normal file
68
spider-cam/libcamera/include/libcamera/internal/ipc_pipe.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Google Inc.
|
||||
*
|
||||
* Image Processing Algorithm IPC module for IPA proxies
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/shared_fd.h>
|
||||
#include <libcamera/base/signal.h>
|
||||
|
||||
#include "libcamera/internal/ipc_unixsocket.h"
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class IPCMessage
|
||||
{
|
||||
public:
|
||||
struct Header {
|
||||
uint32_t cmd;
|
||||
uint32_t cookie;
|
||||
};
|
||||
|
||||
IPCMessage();
|
||||
IPCMessage(uint32_t cmd);
|
||||
IPCMessage(const Header &header);
|
||||
IPCMessage(IPCUnixSocket::Payload &payload);
|
||||
|
||||
IPCUnixSocket::Payload payload() const;
|
||||
|
||||
Header &header() { return header_; }
|
||||
std::vector<uint8_t> &data() { return data_; }
|
||||
std::vector<SharedFD> &fds() { return fds_; }
|
||||
|
||||
const Header &header() const { return header_; }
|
||||
const std::vector<uint8_t> &data() const { return data_; }
|
||||
const std::vector<SharedFD> &fds() const { return fds_; }
|
||||
|
||||
private:
|
||||
Header header_;
|
||||
|
||||
std::vector<uint8_t> data_;
|
||||
std::vector<SharedFD> fds_;
|
||||
};
|
||||
|
||||
class IPCPipe
|
||||
{
|
||||
public:
|
||||
IPCPipe();
|
||||
virtual ~IPCPipe();
|
||||
|
||||
bool isConnected() const { return connected_; }
|
||||
|
||||
virtual int sendSync(const IPCMessage &in,
|
||||
IPCMessage *out) = 0;
|
||||
|
||||
virtual int sendAsync(const IPCMessage &data) = 0;
|
||||
|
||||
Signal<const IPCMessage &> recv;
|
||||
|
||||
protected:
|
||||
bool connected_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,47 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Google Inc.
|
||||
*
|
||||
* Image Processing Algorithm IPC module using unix socket
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "libcamera/internal/ipc_pipe.h"
|
||||
#include "libcamera/internal/ipc_unixsocket.h"
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Process;
|
||||
|
||||
class IPCPipeUnixSocket : public IPCPipe
|
||||
{
|
||||
public:
|
||||
IPCPipeUnixSocket(const char *ipaModulePath, const char *ipaProxyWorkerPath);
|
||||
~IPCPipeUnixSocket();
|
||||
|
||||
int sendSync(const IPCMessage &in,
|
||||
IPCMessage *out = nullptr) override;
|
||||
|
||||
int sendAsync(const IPCMessage &data) override;
|
||||
|
||||
private:
|
||||
struct CallData {
|
||||
IPCUnixSocket::Payload *response;
|
||||
bool done;
|
||||
};
|
||||
|
||||
void readyRead();
|
||||
int call(const IPCUnixSocket::Payload &message,
|
||||
IPCUnixSocket::Payload *response, uint32_t seq);
|
||||
|
||||
std::unique_ptr<Process> proc_;
|
||||
std::unique_ptr<IPCUnixSocket> socket_;
|
||||
std::map<uint32_t, CallData> callData_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,59 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* IPC mechanism based on Unix sockets
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/signal.h>
|
||||
#include <libcamera/base/unique_fd.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class EventNotifier;
|
||||
|
||||
class IPCUnixSocket
|
||||
{
|
||||
public:
|
||||
struct Payload {
|
||||
std::vector<uint8_t> data;
|
||||
std::vector<int32_t> fds;
|
||||
};
|
||||
|
||||
IPCUnixSocket();
|
||||
~IPCUnixSocket();
|
||||
|
||||
UniqueFD create();
|
||||
int bind(UniqueFD fd);
|
||||
void close();
|
||||
bool isBound() const;
|
||||
|
||||
int send(const Payload &payload);
|
||||
int receive(Payload *payload);
|
||||
|
||||
Signal<> readyRead;
|
||||
|
||||
private:
|
||||
struct Header {
|
||||
uint32_t data;
|
||||
uint8_t fds;
|
||||
};
|
||||
|
||||
int sendData(const void *buffer, size_t length, const int32_t *fds, unsigned int num);
|
||||
int recvData(void *buffer, size_t length, int32_t *fds, unsigned int num);
|
||||
|
||||
void dataNotifier();
|
||||
|
||||
UniqueFD fd_;
|
||||
bool headerReceived_;
|
||||
struct Header header_;
|
||||
EventNotifier *notifier_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,62 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2021, Google Inc.
|
||||
*
|
||||
* Frame buffer memory mapping support
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
#include <libcamera/base/flags.h>
|
||||
#include <libcamera/base/span.h>
|
||||
|
||||
#include <libcamera/framebuffer.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class MappedBuffer
|
||||
{
|
||||
public:
|
||||
using Plane = Span<uint8_t>;
|
||||
|
||||
~MappedBuffer();
|
||||
|
||||
MappedBuffer(MappedBuffer &&other);
|
||||
MappedBuffer &operator=(MappedBuffer &&other);
|
||||
|
||||
bool isValid() const { return error_ == 0; }
|
||||
int error() const { return error_; }
|
||||
const std::vector<Plane> &planes() const { return planes_; }
|
||||
|
||||
protected:
|
||||
MappedBuffer();
|
||||
|
||||
int error_;
|
||||
std::vector<Plane> planes_;
|
||||
std::vector<Plane> maps_;
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY(MappedBuffer)
|
||||
};
|
||||
|
||||
class MappedFrameBuffer : public MappedBuffer
|
||||
{
|
||||
public:
|
||||
enum class MapFlag {
|
||||
Read = 1 << 0,
|
||||
Write = 1 << 1,
|
||||
ReadWrite = Read | Write,
|
||||
};
|
||||
|
||||
using MapFlags = Flags<MapFlag>;
|
||||
|
||||
MappedFrameBuffer(const FrameBuffer *buffer, MapFlags flags);
|
||||
};
|
||||
|
||||
LIBCAMERA_FLAGS_ENABLE_OPERATORS(MappedFrameBuffer::MapFlag)
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,94 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018, Google Inc.
|
||||
*
|
||||
* Media device handler
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <linux/media.h>
|
||||
|
||||
#include <libcamera/base/log.h>
|
||||
#include <libcamera/base/signal.h>
|
||||
#include <libcamera/base/unique_fd.h>
|
||||
|
||||
#include "libcamera/internal/media_object.h"
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class MediaDevice : protected Loggable
|
||||
{
|
||||
public:
|
||||
MediaDevice(const std::string &deviceNode);
|
||||
~MediaDevice();
|
||||
|
||||
bool acquire();
|
||||
void release();
|
||||
bool busy() const { return acquired_; }
|
||||
|
||||
bool lock();
|
||||
void unlock();
|
||||
|
||||
int populate();
|
||||
bool isValid() const { return valid_; }
|
||||
|
||||
const std::string &driver() const { return driver_; }
|
||||
const std::string &deviceNode() const { return deviceNode_; }
|
||||
const std::string &model() const { return model_; }
|
||||
unsigned int version() const { return version_; }
|
||||
unsigned int hwRevision() const { return hwRevision_; }
|
||||
|
||||
const std::vector<MediaEntity *> &entities() const { return entities_; }
|
||||
MediaEntity *getEntityByName(const std::string &name) const;
|
||||
|
||||
MediaLink *link(const std::string &sourceName, unsigned int sourceIdx,
|
||||
const std::string &sinkName, unsigned int sinkIdx);
|
||||
MediaLink *link(const MediaEntity *source, unsigned int sourceIdx,
|
||||
const MediaEntity *sink, unsigned int sinkIdx);
|
||||
MediaLink *link(const MediaPad *source, const MediaPad *sink);
|
||||
int disableLinks();
|
||||
|
||||
Signal<> disconnected;
|
||||
|
||||
protected:
|
||||
std::string logPrefix() const override;
|
||||
|
||||
private:
|
||||
int open();
|
||||
void close();
|
||||
|
||||
MediaObject *object(unsigned int id);
|
||||
bool addObject(MediaObject *object);
|
||||
void clear();
|
||||
|
||||
struct media_v2_interface *findInterface(const struct media_v2_topology &topology,
|
||||
unsigned int entityId);
|
||||
bool populateEntities(const struct media_v2_topology &topology);
|
||||
bool populatePads(const struct media_v2_topology &topology);
|
||||
bool populateLinks(const struct media_v2_topology &topology);
|
||||
void fixupEntityFlags(struct media_v2_entity *entity);
|
||||
|
||||
friend int MediaLink::setEnabled(bool enable);
|
||||
int setupLink(const MediaLink *link, unsigned int flags);
|
||||
|
||||
std::string driver_;
|
||||
std::string deviceNode_;
|
||||
std::string model_;
|
||||
unsigned int version_;
|
||||
unsigned int hwRevision_;
|
||||
|
||||
UniqueFD fd_;
|
||||
bool valid_;
|
||||
bool acquired_;
|
||||
|
||||
std::map<unsigned int, MediaObject *> objects_;
|
||||
std::vector<MediaEntity *> entities_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
138
spider-cam/libcamera/include/libcamera/internal/media_object.h
Normal file
138
spider-cam/libcamera/include/libcamera/internal/media_object.h
Normal file
@@ -0,0 +1,138 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018, Google Inc.
|
||||
*
|
||||
* Media Device objects: entities, pads and links.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <linux/media.h>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class MediaDevice;
|
||||
class MediaEntity;
|
||||
class MediaPad;
|
||||
|
||||
class MediaObject
|
||||
{
|
||||
public:
|
||||
MediaDevice *device() { return dev_; }
|
||||
const MediaDevice *device() const { return dev_; }
|
||||
unsigned int id() const { return id_; }
|
||||
|
||||
protected:
|
||||
friend class MediaDevice;
|
||||
|
||||
MediaObject(MediaDevice *dev, unsigned int id)
|
||||
: dev_(dev), id_(id)
|
||||
{
|
||||
}
|
||||
virtual ~MediaObject() = default;
|
||||
|
||||
MediaDevice *dev_;
|
||||
unsigned int id_;
|
||||
};
|
||||
|
||||
class MediaLink : public MediaObject
|
||||
{
|
||||
public:
|
||||
MediaPad *source() const { return source_; }
|
||||
MediaPad *sink() const { return sink_; }
|
||||
unsigned int flags() const { return flags_; }
|
||||
int setEnabled(bool enable);
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY_AND_MOVE(MediaLink)
|
||||
|
||||
friend class MediaDevice;
|
||||
|
||||
MediaLink(const struct media_v2_link *link,
|
||||
MediaPad *source, MediaPad *sink);
|
||||
|
||||
MediaPad *source_;
|
||||
MediaPad *sink_;
|
||||
unsigned int flags_;
|
||||
};
|
||||
|
||||
class MediaPad : public MediaObject
|
||||
{
|
||||
public:
|
||||
unsigned int index() const { return index_; }
|
||||
MediaEntity *entity() const { return entity_; }
|
||||
unsigned int flags() const { return flags_; }
|
||||
const std::vector<MediaLink *> &links() const { return links_; }
|
||||
|
||||
void addLink(MediaLink *link);
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY_AND_MOVE(MediaPad)
|
||||
|
||||
friend class MediaDevice;
|
||||
|
||||
MediaPad(const struct media_v2_pad *pad, MediaEntity *entity);
|
||||
|
||||
unsigned int index_;
|
||||
MediaEntity *entity_;
|
||||
unsigned int flags_;
|
||||
|
||||
std::vector<MediaLink *> links_;
|
||||
};
|
||||
|
||||
class MediaEntity : public MediaObject
|
||||
{
|
||||
public:
|
||||
enum class Type {
|
||||
Invalid,
|
||||
MediaEntity,
|
||||
V4L2Subdevice,
|
||||
V4L2VideoDevice,
|
||||
};
|
||||
|
||||
const std::string &name() const { return name_; }
|
||||
unsigned int function() const { return function_; }
|
||||
unsigned int flags() const { return flags_; }
|
||||
Type type() const { return type_; }
|
||||
const std::string &deviceNode() const { return deviceNode_; }
|
||||
unsigned int deviceMajor() const { return major_; }
|
||||
unsigned int deviceMinor() const { return minor_; }
|
||||
|
||||
const std::vector<MediaPad *> &pads() const { return pads_; }
|
||||
const std::vector<MediaEntity *> ancillaryEntities() const { return ancillaryEntities_; }
|
||||
|
||||
const MediaPad *getPadByIndex(unsigned int index) const;
|
||||
const MediaPad *getPadById(unsigned int id) const;
|
||||
|
||||
int setDeviceNode(const std::string &deviceNode);
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY_AND_MOVE(MediaEntity)
|
||||
|
||||
friend class MediaDevice;
|
||||
|
||||
MediaEntity(MediaDevice *dev, const struct media_v2_entity *entity,
|
||||
const struct media_v2_interface *iface);
|
||||
|
||||
void addPad(MediaPad *pad);
|
||||
|
||||
void addAncillaryEntity(MediaEntity *ancillaryEntity);
|
||||
|
||||
std::string name_;
|
||||
unsigned int function_;
|
||||
unsigned int flags_;
|
||||
Type type_;
|
||||
std::string deviceNode_;
|
||||
unsigned int major_;
|
||||
unsigned int minor_;
|
||||
|
||||
std::vector<MediaPad *> pads_;
|
||||
std::vector<MediaEntity *> ancillaryEntities_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
53
spider-cam/libcamera/include/libcamera/internal/meson.build
Normal file
53
spider-cam/libcamera/include/libcamera/internal/meson.build
Normal file
@@ -0,0 +1,53 @@
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
subdir('tracepoints')
|
||||
|
||||
libcamera_tracepoint_header = custom_target(
|
||||
'tp_header',
|
||||
input : ['tracepoints.h.in', tracepoint_files],
|
||||
output : 'tracepoints.h',
|
||||
command : [gen_tracepoints_header, include_build_dir, '@OUTPUT@', '@INPUT@'],
|
||||
)
|
||||
|
||||
libcamera_internal_headers = files([
|
||||
'bayer_format.h',
|
||||
'byte_stream_buffer.h',
|
||||
'camera.h',
|
||||
'camera_controls.h',
|
||||
'camera_lens.h',
|
||||
'camera_manager.h',
|
||||
'camera_sensor.h',
|
||||
'camera_sensor_properties.h',
|
||||
'control_serializer.h',
|
||||
'control_validator.h',
|
||||
'converter.h',
|
||||
'delayed_controls.h',
|
||||
'device_enumerator.h',
|
||||
'device_enumerator_sysfs.h',
|
||||
'device_enumerator_udev.h',
|
||||
'dma_buf_allocator.h',
|
||||
'formats.h',
|
||||
'framebuffer.h',
|
||||
'ipa_manager.h',
|
||||
'ipa_module.h',
|
||||
'ipa_proxy.h',
|
||||
'ipc_unixsocket.h',
|
||||
'mapped_framebuffer.h',
|
||||
'media_device.h',
|
||||
'media_object.h',
|
||||
'pipeline_handler.h',
|
||||
'process.h',
|
||||
'pub_key.h',
|
||||
'request.h',
|
||||
'shared_mem_object.h',
|
||||
'source_paths.h',
|
||||
'sysfs.h',
|
||||
'v4l2_device.h',
|
||||
'v4l2_pixelformat.h',
|
||||
'v4l2_subdevice.h',
|
||||
'v4l2_videodevice.h',
|
||||
'yaml_parser.h',
|
||||
])
|
||||
|
||||
subdir('converter')
|
||||
subdir('software_isp')
|
||||
@@ -0,0 +1,147 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018, Google Inc.
|
||||
*
|
||||
* Pipeline handler infrastructure
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <sys/types.h>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/mutex.h>
|
||||
#include <libcamera/base/object.h>
|
||||
|
||||
#include <libcamera/controls.h>
|
||||
#include <libcamera/stream.h>
|
||||
|
||||
#include "libcamera/internal/ipa_proxy.h"
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Camera;
|
||||
class CameraConfiguration;
|
||||
class CameraManager;
|
||||
class DeviceEnumerator;
|
||||
class DeviceMatch;
|
||||
class FrameBuffer;
|
||||
class MediaDevice;
|
||||
class PipelineHandler;
|
||||
class Request;
|
||||
|
||||
class PipelineHandler : public std::enable_shared_from_this<PipelineHandler>,
|
||||
public Object
|
||||
{
|
||||
public:
|
||||
PipelineHandler(CameraManager *manager);
|
||||
virtual ~PipelineHandler();
|
||||
|
||||
virtual bool match(DeviceEnumerator *enumerator) = 0;
|
||||
MediaDevice *acquireMediaDevice(DeviceEnumerator *enumerator,
|
||||
const DeviceMatch &dm);
|
||||
|
||||
bool acquire();
|
||||
void release(Camera *camera);
|
||||
|
||||
virtual std::unique_ptr<CameraConfiguration> generateConfiguration(Camera *camera,
|
||||
Span<const StreamRole> roles) = 0;
|
||||
virtual int configure(Camera *camera, CameraConfiguration *config) = 0;
|
||||
|
||||
virtual int exportFrameBuffers(Camera *camera, Stream *stream,
|
||||
std::vector<std::unique_ptr<FrameBuffer>> *buffers) = 0;
|
||||
|
||||
virtual int start(Camera *camera, const ControlList *controls) = 0;
|
||||
void stop(Camera *camera);
|
||||
bool hasPendingRequests(const Camera *camera) const;
|
||||
|
||||
void registerRequest(Request *request);
|
||||
void queueRequest(Request *request);
|
||||
|
||||
bool completeBuffer(Request *request, FrameBuffer *buffer);
|
||||
void completeRequest(Request *request);
|
||||
|
||||
std::string configurationFile(const std::string &subdir,
|
||||
const std::string &name) const;
|
||||
|
||||
const char *name() const { return name_; }
|
||||
|
||||
protected:
|
||||
void registerCamera(std::shared_ptr<Camera> camera);
|
||||
void hotplugMediaDevice(MediaDevice *media);
|
||||
|
||||
virtual int queueRequestDevice(Camera *camera, Request *request) = 0;
|
||||
virtual void stopDevice(Camera *camera) = 0;
|
||||
|
||||
virtual void releaseDevice(Camera *camera);
|
||||
|
||||
CameraManager *manager_;
|
||||
|
||||
private:
|
||||
void unlockMediaDevices();
|
||||
|
||||
void mediaDeviceDisconnected(MediaDevice *media);
|
||||
virtual void disconnect();
|
||||
|
||||
void doQueueRequest(Request *request);
|
||||
void doQueueRequests();
|
||||
|
||||
std::vector<std::shared_ptr<MediaDevice>> mediaDevices_;
|
||||
std::vector<std::weak_ptr<Camera>> cameras_;
|
||||
|
||||
std::queue<Request *> waitingRequests_;
|
||||
|
||||
const char *name_;
|
||||
|
||||
Mutex lock_;
|
||||
unsigned int useCount_ LIBCAMERA_TSA_GUARDED_BY(lock_);
|
||||
|
||||
friend class PipelineHandlerFactoryBase;
|
||||
};
|
||||
|
||||
class PipelineHandlerFactoryBase
|
||||
{
|
||||
public:
|
||||
PipelineHandlerFactoryBase(const char *name);
|
||||
virtual ~PipelineHandlerFactoryBase() = default;
|
||||
|
||||
std::shared_ptr<PipelineHandler> create(CameraManager *manager) const;
|
||||
|
||||
const std::string &name() const { return name_; }
|
||||
|
||||
static std::vector<PipelineHandlerFactoryBase *> &factories();
|
||||
static const PipelineHandlerFactoryBase *getFactoryByName(const std::string &name);
|
||||
|
||||
private:
|
||||
static void registerType(PipelineHandlerFactoryBase *factory);
|
||||
|
||||
virtual std::unique_ptr<PipelineHandler>
|
||||
createInstance(CameraManager *manager) const = 0;
|
||||
|
||||
std::string name_;
|
||||
};
|
||||
|
||||
template<typename _PipelineHandler>
|
||||
class PipelineHandlerFactory final : public PipelineHandlerFactoryBase
|
||||
{
|
||||
public:
|
||||
PipelineHandlerFactory(const char *name)
|
||||
: PipelineHandlerFactoryBase(name)
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<PipelineHandler>
|
||||
createInstance(CameraManager *manager) const override
|
||||
{
|
||||
return std::make_unique<_PipelineHandler>(manager);
|
||||
}
|
||||
};
|
||||
|
||||
#define REGISTER_PIPELINE_HANDLER(handler, name) \
|
||||
static PipelineHandlerFactory<handler> global_##handler##Factory(name);
|
||||
|
||||
} /* namespace libcamera */
|
||||
84
spider-cam/libcamera/include/libcamera/internal/process.h
Normal file
84
spider-cam/libcamera/include/libcamera/internal/process.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Process object
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <signal.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/signal.h>
|
||||
#include <libcamera/base/unique_fd.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class EventNotifier;
|
||||
|
||||
class Process final
|
||||
{
|
||||
public:
|
||||
enum ExitStatus {
|
||||
NotExited,
|
||||
NormalExit,
|
||||
SignalExit,
|
||||
};
|
||||
|
||||
Process();
|
||||
~Process();
|
||||
|
||||
int start(const std::string &path,
|
||||
const std::vector<std::string> &args = std::vector<std::string>(),
|
||||
const std::vector<int> &fds = std::vector<int>());
|
||||
|
||||
ExitStatus exitStatus() const { return exitStatus_; }
|
||||
int exitCode() const { return exitCode_; }
|
||||
|
||||
void kill();
|
||||
|
||||
Signal<enum ExitStatus, int> finished;
|
||||
|
||||
private:
|
||||
void closeAllFdsExcept(const std::vector<int> &fds);
|
||||
int isolate();
|
||||
void died(int wstatus);
|
||||
|
||||
pid_t pid_;
|
||||
bool running_;
|
||||
enum ExitStatus exitStatus_;
|
||||
int exitCode_;
|
||||
|
||||
friend class ProcessManager;
|
||||
};
|
||||
|
||||
class ProcessManager
|
||||
{
|
||||
public:
|
||||
ProcessManager();
|
||||
~ProcessManager();
|
||||
|
||||
void registerProcess(Process *proc);
|
||||
|
||||
static ProcessManager *instance();
|
||||
|
||||
int writePipe() const;
|
||||
|
||||
const struct sigaction &oldsa() const;
|
||||
|
||||
private:
|
||||
static ProcessManager *self_;
|
||||
|
||||
void sighandler();
|
||||
|
||||
std::list<Process *> processes_;
|
||||
|
||||
struct sigaction oldsa_;
|
||||
|
||||
EventNotifier *sigEvent_;
|
||||
UniqueFD pipe_[2];
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
40
spider-cam/libcamera/include/libcamera/internal/pub_key.h
Normal file
40
spider-cam/libcamera/include/libcamera/internal/pub_key.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Google Inc.
|
||||
*
|
||||
* Public key signature verification
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <libcamera/base/span.h>
|
||||
|
||||
#if HAVE_CRYPTO
|
||||
struct evp_pkey_st;
|
||||
#elif HAVE_GNUTLS
|
||||
struct gnutls_pubkey_st;
|
||||
#endif
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class PubKey
|
||||
{
|
||||
public:
|
||||
PubKey(Span<const uint8_t> key);
|
||||
~PubKey();
|
||||
|
||||
bool isValid() const { return valid_; }
|
||||
bool verify(Span<const uint8_t> data, Span<const uint8_t> sig) const;
|
||||
|
||||
private:
|
||||
bool valid_;
|
||||
#if HAVE_CRYPTO
|
||||
struct evp_pkey_st *pubkey_;
|
||||
#elif HAVE_GNUTLS
|
||||
struct gnutls_pubkey_st *pubkey_;
|
||||
#endif
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
64
spider-cam/libcamera/include/libcamera/internal/request.h
Normal file
64
spider-cam/libcamera/include/libcamera/internal/request.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2019, Google Inc.
|
||||
*
|
||||
* Request class private data
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
#include <libcamera/base/event_notifier.h>
|
||||
#include <libcamera/base/timer.h>
|
||||
|
||||
#include <libcamera/request.h>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class Camera;
|
||||
class FrameBuffer;
|
||||
|
||||
class Request::Private : public Extensible::Private
|
||||
{
|
||||
LIBCAMERA_DECLARE_PUBLIC(Request)
|
||||
|
||||
public:
|
||||
Private(Camera *camera);
|
||||
~Private();
|
||||
|
||||
Camera *camera() const { return camera_; }
|
||||
bool hasPendingBuffers() const;
|
||||
|
||||
bool completeBuffer(FrameBuffer *buffer);
|
||||
void complete();
|
||||
void cancel();
|
||||
void reset();
|
||||
|
||||
void prepare(std::chrono::milliseconds timeout = 0ms);
|
||||
Signal<> prepared;
|
||||
|
||||
private:
|
||||
friend class PipelineHandler;
|
||||
friend std::ostream &operator<<(std::ostream &out, const Request &r);
|
||||
|
||||
void doCancelRequest();
|
||||
void emitPrepareCompleted();
|
||||
void notifierActivated(FrameBuffer *buffer);
|
||||
void timeout();
|
||||
|
||||
Camera *camera_;
|
||||
bool cancelled_;
|
||||
uint32_t sequence_ = 0;
|
||||
bool prepared_ = false;
|
||||
|
||||
std::unordered_set<FrameBuffer *> pending_;
|
||||
std::map<FrameBuffer *, std::unique_ptr<EventNotifier>> notifiers_;
|
||||
std::unique_ptr<Timer> timer_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,127 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2023 Raspberry Pi Ltd
|
||||
* Copyright (C) 2024 Andrei Konovalov
|
||||
* Copyright (C) 2024 Dennis Bonke
|
||||
*
|
||||
* Helpers for shared memory allocations
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <sys/mman.h>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
#include <libcamera/base/shared_fd.h>
|
||||
#include <libcamera/base/span.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class SharedMem
|
||||
{
|
||||
public:
|
||||
SharedMem();
|
||||
|
||||
SharedMem(const std::string &name, std::size_t size);
|
||||
SharedMem(SharedMem &&rhs);
|
||||
|
||||
virtual ~SharedMem();
|
||||
|
||||
SharedMem &operator=(SharedMem &&rhs);
|
||||
|
||||
const SharedFD &fd() const
|
||||
{
|
||||
return fd_;
|
||||
}
|
||||
|
||||
Span<uint8_t> mem() const
|
||||
{
|
||||
return mem_;
|
||||
}
|
||||
|
||||
explicit operator bool() const
|
||||
{
|
||||
return !mem_.empty();
|
||||
}
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY(SharedMem)
|
||||
|
||||
SharedFD fd_;
|
||||
|
||||
Span<uint8_t> mem_;
|
||||
};
|
||||
|
||||
template<class T, typename = std::enable_if_t<std::is_standard_layout<T>::value>>
|
||||
class SharedMemObject : public SharedMem
|
||||
{
|
||||
public:
|
||||
static constexpr std::size_t kSize = sizeof(T);
|
||||
|
||||
SharedMemObject()
|
||||
: SharedMem(), obj_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
template<class... Args>
|
||||
SharedMemObject(const std::string &name, Args &&...args)
|
||||
: SharedMem(name, kSize), obj_(nullptr)
|
||||
{
|
||||
if (mem().empty())
|
||||
return;
|
||||
|
||||
obj_ = new (mem().data()) T(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
SharedMemObject(SharedMemObject<T> &&rhs)
|
||||
: SharedMem(std::move(rhs))
|
||||
{
|
||||
this->obj_ = rhs.obj_;
|
||||
rhs.obj_ = nullptr;
|
||||
}
|
||||
|
||||
~SharedMemObject()
|
||||
{
|
||||
if (obj_)
|
||||
obj_->~T();
|
||||
}
|
||||
|
||||
SharedMemObject<T> &operator=(SharedMemObject<T> &&rhs)
|
||||
{
|
||||
SharedMem::operator=(std::move(rhs));
|
||||
this->obj_ = rhs.obj_;
|
||||
rhs.obj_ = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
T *operator->()
|
||||
{
|
||||
return obj_;
|
||||
}
|
||||
|
||||
const T *operator->() const
|
||||
{
|
||||
return obj_;
|
||||
}
|
||||
|
||||
T &operator*()
|
||||
{
|
||||
return *obj_;
|
||||
}
|
||||
|
||||
const T &operator*() const
|
||||
{
|
||||
return *obj_;
|
||||
}
|
||||
|
||||
private:
|
||||
LIBCAMERA_DISABLE_COPY(SharedMemObject)
|
||||
|
||||
T *obj_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,28 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2023, 2024 Red Hat Inc.
|
||||
*
|
||||
* Authors:
|
||||
* Hans de Goede <hdegoede@redhat.com>
|
||||
*
|
||||
* DebayerParams header
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
struct DebayerParams {
|
||||
static constexpr unsigned int kRGBLookupSize = 256;
|
||||
|
||||
using ColorLookupTable = std::array<uint8_t, kRGBLookupSize>;
|
||||
|
||||
ColorLookupTable red;
|
||||
ColorLookupTable green;
|
||||
ColorLookupTable blue;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,7 @@
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
libcamera_internal_headers += files([
|
||||
'debayer_params.h',
|
||||
'software_isp.h',
|
||||
'swisp_stats.h',
|
||||
])
|
||||
@@ -0,0 +1,100 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2023, Linaro Ltd
|
||||
*
|
||||
* Simple software ISP implementation
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include <libcamera/base/class.h>
|
||||
#include <libcamera/base/log.h>
|
||||
#include <libcamera/base/signal.h>
|
||||
#include <libcamera/base/thread.h>
|
||||
|
||||
#include <libcamera/geometry.h>
|
||||
#include <libcamera/pixel_format.h>
|
||||
|
||||
#include <libcamera/ipa/soft_ipa_interface.h>
|
||||
#include <libcamera/ipa/soft_ipa_proxy.h>
|
||||
|
||||
#include "libcamera/internal/camera_sensor.h"
|
||||
#include "libcamera/internal/dma_buf_allocator.h"
|
||||
#include "libcamera/internal/pipeline_handler.h"
|
||||
#include "libcamera/internal/shared_mem_object.h"
|
||||
#include "libcamera/internal/software_isp/debayer_params.h"
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
class DebayerCpu;
|
||||
class FrameBuffer;
|
||||
class PixelFormat;
|
||||
class Stream;
|
||||
struct StreamConfiguration;
|
||||
|
||||
LOG_DECLARE_CATEGORY(SoftwareIsp)
|
||||
|
||||
class SoftwareIsp
|
||||
{
|
||||
public:
|
||||
SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor);
|
||||
~SoftwareIsp();
|
||||
|
||||
int loadConfiguration([[maybe_unused]] const std::string &filename) { return 0; }
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
std::vector<PixelFormat> formats(PixelFormat input);
|
||||
|
||||
SizeRange sizes(PixelFormat inputFormat, const Size &inputSize);
|
||||
|
||||
std::tuple<unsigned int, unsigned int>
|
||||
strideAndFrameSize(const PixelFormat &outputFormat, const Size &size);
|
||||
|
||||
int configure(const StreamConfiguration &inputCfg,
|
||||
const std::vector<std::reference_wrapper<StreamConfiguration>> &outputCfgs,
|
||||
const ControlInfoMap &sensorControls);
|
||||
|
||||
int exportBuffers(const Stream *stream, unsigned int count,
|
||||
std::vector<std::unique_ptr<FrameBuffer>> *buffers);
|
||||
|
||||
void processStats(const ControlList &sensorControls);
|
||||
|
||||
int start();
|
||||
void stop();
|
||||
|
||||
int queueBuffers(FrameBuffer *input,
|
||||
const std::map<const Stream *, FrameBuffer *> &outputs);
|
||||
|
||||
void process(FrameBuffer *input, FrameBuffer *output);
|
||||
|
||||
Signal<FrameBuffer *> inputBufferReady;
|
||||
Signal<FrameBuffer *> outputBufferReady;
|
||||
Signal<> ispStatsReady;
|
||||
Signal<const ControlList &> setSensorControls;
|
||||
|
||||
private:
|
||||
void saveIspParams();
|
||||
void setSensorCtrls(const ControlList &sensorControls);
|
||||
void statsReady();
|
||||
void inputReady(FrameBuffer *input);
|
||||
void outputReady(FrameBuffer *output);
|
||||
|
||||
std::unique_ptr<DebayerCpu> debayer_;
|
||||
Thread ispWorkerThread_;
|
||||
SharedMemObject<DebayerParams> sharedParams_;
|
||||
DebayerParams debayerParams_;
|
||||
DmaBufAllocator dmaHeap_;
|
||||
|
||||
std::unique_ptr<ipa::soft::IPAProxySoft> ipa_;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,49 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2023, Linaro Ltd
|
||||
*
|
||||
* Statistics data format used by the software ISP and software IPA
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
/**
|
||||
* \brief Struct that holds the statistics for the Software ISP
|
||||
*
|
||||
* The struct value types are large enough to not overflow.
|
||||
* Should they still overflow for some reason, no check is performed and they
|
||||
* wrap around.
|
||||
*/
|
||||
struct SwIspStats {
|
||||
/**
|
||||
* \brief Holds the sum of all sampled red pixels
|
||||
*/
|
||||
uint64_t sumR_;
|
||||
/**
|
||||
* \brief Holds the sum of all sampled green pixels
|
||||
*/
|
||||
uint64_t sumG_;
|
||||
/**
|
||||
* \brief Holds the sum of all sampled blue pixels
|
||||
*/
|
||||
uint64_t sumB_;
|
||||
/**
|
||||
* \brief Number of bins in the yHistogram
|
||||
*/
|
||||
static constexpr unsigned int kYHistogramSize = 64;
|
||||
/**
|
||||
* \brief Type of the histogram.
|
||||
*/
|
||||
using Histogram = std::array<uint32_t, kYHistogramSize>;
|
||||
/**
|
||||
* \brief A histogram of luminance values
|
||||
*/
|
||||
Histogram yHistogram;
|
||||
};
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,17 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2021, Google Inc.
|
||||
*
|
||||
* Identify libcamera source and build paths
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace libcamera::utils {
|
||||
|
||||
std::string libcameraBuildPath();
|
||||
std::string libcameraSourcePath();
|
||||
|
||||
} /* namespace libcamera::utils */
|
||||
22
spider-cam/libcamera/include/libcamera/internal/sysfs.h
Normal file
22
spider-cam/libcamera/include/libcamera/internal/sysfs.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Google Inc.
|
||||
*
|
||||
* Miscellaneous utility functions to access sysfs
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace libcamera {
|
||||
|
||||
namespace sysfs {
|
||||
|
||||
std::string charDevPath(const std::string &deviceNode);
|
||||
|
||||
std::string firmwareNodePath(const std::string &device);
|
||||
|
||||
} /* namespace sysfs */
|
||||
|
||||
} /* namespace libcamera */
|
||||
@@ -0,0 +1,61 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) {{year}}, Google Inc.
|
||||
*
|
||||
* Tracepoints with lttng
|
||||
*
|
||||
* This file is auto-generated. Do not edit.
|
||||
*/
|
||||
#ifndef __LIBCAMERA_INTERNAL_TRACEPOINTS_H__
|
||||
#define __LIBCAMERA_INTERNAL_TRACEPOINTS_H__
|
||||
|
||||
#if HAVE_TRACING
|
||||
#define LIBCAMERA_TRACEPOINT(...) tracepoint(libcamera, __VA_ARGS__)
|
||||
|
||||
#define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func) \
|
||||
tracepoint(libcamera, ipa_call_begin, #pipe, #func)
|
||||
|
||||
#define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func) \
|
||||
tracepoint(libcamera, ipa_call_end, #pipe, #func)
|
||||
|
||||
#else
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename ...Args>
|
||||
inline void unused([[maybe_unused]] Args&& ...args)
|
||||
{
|
||||
}
|
||||
|
||||
} /* namespace */
|
||||
|
||||
#define LIBCAMERA_TRACEPOINT(category, ...) unused(__VA_ARGS__)
|
||||
|
||||
#define LIBCAMERA_TRACEPOINT_IPA_BEGIN(pipe, func)
|
||||
#define LIBCAMERA_TRACEPOINT_IPA_END(pipe, func)
|
||||
|
||||
#endif /* HAVE_TRACING */
|
||||
|
||||
#endif /* __LIBCAMERA_INTERNAL_TRACEPOINTS_H__ */
|
||||
|
||||
|
||||
#if HAVE_TRACING
|
||||
|
||||
#undef TRACEPOINT_PROVIDER
|
||||
#define TRACEPOINT_PROVIDER libcamera
|
||||
|
||||
#undef TRACEPOINT_INCLUDE
|
||||
#define TRACEPOINT_INCLUDE "{{path}}"
|
||||
|
||||
#if !defined(INCLUDE_LIBCAMERA_INTERNAL_TRACEPOINTS_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
|
||||
#define INCLUDE_LIBCAMERA_INTERNAL_TRACEPOINTS_TP_H
|
||||
|
||||
#include <lttng/tracepoint.h>
|
||||
|
||||
{{source}}
|
||||
|
||||
#endif /* INCLUDE_LIBCAMERA_INTERNAL_TRACEPOINTS_TP_H */
|
||||
|
||||
#include <lttng/tracepoint-event.h>
|
||||
|
||||
#endif /* HAVE_TRACING */
|
||||
@@ -0,0 +1,16 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Google Inc.
|
||||
*
|
||||
* buffer_enums.tp - Tracepoint definition for enums in the buffer class
|
||||
*/
|
||||
|
||||
TRACEPOINT_ENUM(
|
||||
libcamera,
|
||||
buffer_status,
|
||||
TP_ENUM_VALUES(
|
||||
ctf_enum_value("FrameSuccess", 0)
|
||||
ctf_enum_value("FrameError", 1)
|
||||
ctf_enum_value("FrameCancelled", 2)
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
# enum files must go first
|
||||
tracepoint_files = files([
|
||||
'buffer_enums.tp',
|
||||
'request_enums.tp',
|
||||
])
|
||||
|
||||
tracepoint_files += files([
|
||||
'pipeline.tp',
|
||||
'request.tp',
|
||||
])
|
||||
@@ -0,0 +1,32 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Google Inc.
|
||||
*
|
||||
* pipeline.tp - Tracepoints for pipelines
|
||||
*/
|
||||
|
||||
TRACEPOINT_EVENT(
|
||||
libcamera,
|
||||
ipa_call_begin,
|
||||
TP_ARGS(
|
||||
const char *, pipe,
|
||||
const char *, func
|
||||
),
|
||||
TP_FIELDS(
|
||||
ctf_string(pipeline_name, pipe)
|
||||
ctf_string(function_name, func)
|
||||
)
|
||||
)
|
||||
|
||||
TRACEPOINT_EVENT(
|
||||
libcamera,
|
||||
ipa_call_end,
|
||||
TP_ARGS(
|
||||
const char *, pipe,
|
||||
const char *, func
|
||||
),
|
||||
TP_FIELDS(
|
||||
ctf_string(pipeline_name, pipe)
|
||||
ctf_string(function_name, func)
|
||||
)
|
||||
)
|
||||
@@ -0,0 +1,102 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
/*
|
||||
* Copyright (C) 2020, Google Inc.
|
||||
*
|
||||
* request.tp - Tracepoints for the request object
|
||||
*/
|
||||
|
||||
#include <libcamera/framebuffer.h>
|
||||
|
||||
#include "libcamera/internal/request.h"
|
||||
|
||||
TRACEPOINT_EVENT_CLASS(
|
||||
libcamera,
|
||||
request,
|
||||
TP_ARGS(
|
||||
libcamera::Request *, req
|
||||
),
|
||||
TP_FIELDS(
|
||||
ctf_integer_hex(uintptr_t, request, reinterpret_cast<uintptr_t>(req))
|
||||
ctf_integer(uint64_t, cookie, req->cookie())
|
||||
ctf_enum(libcamera, request_status, uint32_t, status, req->status())
|
||||
)
|
||||
)
|
||||
|
||||
TRACEPOINT_EVENT_INSTANCE(
|
||||
libcamera,
|
||||
request,
|
||||
request_construct,
|
||||
TP_ARGS(
|
||||
libcamera::Request *, req
|
||||
)
|
||||
)
|
||||
|
||||
TRACEPOINT_EVENT_INSTANCE(
|
||||
libcamera,
|
||||
request,
|
||||
request_destroy,
|
||||
TP_ARGS(
|
||||
libcamera::Request *, req
|
||||
)
|
||||
)
|
||||
|
||||
TRACEPOINT_EVENT_INSTANCE(
|
||||
libcamera,
|
||||
request,
|
||||
request_reuse,
|
||||
TP_ARGS(
|
||||
libcamera::Request *, req
|
||||
)
|
||||
)
|
||||
|
||||
TRACEPOINT_EVENT_INSTANCE(
|
||||
libcamera,
|
||||
request,
|
||||
request_queue,
|
||||
TP_ARGS(
|
||||
libcamera::Request *, req
|
||||
)
|
||||
)
|
||||
|
||||
TRACEPOINT_EVENT_INSTANCE(
|
||||
libcamera,
|
||||
request,
|
||||
request_device_queue,
|
||||
TP_ARGS(
|
||||
libcamera::Request *, req
|
||||
)
|
||||
)
|
||||
|
||||
TRACEPOINT_EVENT_INSTANCE(
|
||||
libcamera,
|
||||
request,
|
||||
request_complete,
|
||||
TP_ARGS(
|
||||
libcamera::Request::Private *, req
|
||||
)
|
||||
)
|
||||
|
||||
TRACEPOINT_EVENT_INSTANCE(
|
||||
libcamera,
|
||||
request,
|
||||
request_cancel,
|
||||
TP_ARGS(
|
||||
libcamera::Request::Private *, req
|
||||
)
|
||||
)
|
||||
|
||||
TRACEPOINT_EVENT(
|
||||
libcamera,
|
||||
request_complete_buffer,
|
||||
TP_ARGS(
|
||||
libcamera::Request::Private *, req,
|
||||
libcamera::FrameBuffer *, buf
|
||||
),
|
||||
TP_FIELDS(
|
||||
ctf_integer_hex(uintptr_t, request, reinterpret_cast<uintptr_t>(req))
|
||||
ctf_integer(uint64_t, cookie, req->_o<libcamera::Request>()->cookie())
|
||||
ctf_integer(int, status, req->_o<libcamera::Request>()->status())
|
||||
ctf_integer_hex(uintptr_t, buffer, reinterpret_cast<uintptr_t>(buf))
|
||||
ctf_enum(libcamera, buffer_status, uint32_t, buf_status, buf->metadata().status)
|
||||
)
|
||||
)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user