-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rpi/v6.6/streams #200
Open
jmondi
wants to merge
46
commits into
raspberrypi:next
Choose a base branch
from
jmondi:rpi/v6.6/streams
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Rpi/v6.6/streams #200
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add a vendor control rpi::ScalerCrops that is analogous to the current core::ScalerCrop, but can apply a different crop to each configured stream. This control takes a span of Rectangle structures - the order of rectangles must match the order of streams configured by the application. Signed-off-by: Naushir Patuck <[email protected]>
Do not cache the scalerCrop_ parameter. The cached value is used to update the request metadata, but since this is not an expensive operation (and can only occur once per frame), caching it is of limited value. This will simplify logic in a future commit where we can specify a crop per-output stream. Signed-off-by: Naushir Patuck <[email protected]>
…op() This will be required when we program separate crop values to each ISP output in a future commit. Signed-off-by: Naushir Patuck <[email protected]>
In preparation for assigning separate crop windows for each stream, add a new CropParams structure that stores the existing ispCrop_ and ispMinCropSize_ as fields. Use a new std::map to store a CropParams structure where the map key is the index of the stream configuration in the CameraConfiguration vector. At preset, only a single CropParams structure will be set at key == 0 to preserve the existing crop handling logic. Signed-off-by: Naushir Patuck <[email protected]>
Add a ispIndex field to CropParams that is used to track which ISP output (0/1) will be used for a given stream during configuration. Tracking this information is required for an upcoming change where crop rectangles can be specified for each configured stream. Currently, the value is fixed to 0. Signed-off-by: Naushir Patuck <[email protected]>
At this point, the index is unused, but will be in a future commit where we can set different crops on each ISP output. Signed-off-by: Naushir Patuck <[email protected]>
Handle multiple scaler crops being set through the rpi::ScalerCrops control. We now populate the cropParams_ map in the loop where we handle the output stream configuration items. The key of this map is the index of the stream configuration structure set by the application. This will also be the same index used to specify the crop rectangles through the ScalerCrops control. CameraData::applyScalerCrop() has been adapted to look at either controls::ScalerCrop or controls::rpi::ScalerCrops. The former takes priority over the latter, and if present, will apply the same scaler crop to all output streams. Finally return all crops through the same ScalerCrops control via request metadata. The first configure stream's crop rectangle is also returned via the ScalerCrop control in the request metadata. Signed-off-by: Naushir Patuck <[email protected]>
sensorInfo_ currently gets populated in configureIPA(), but is possibly referenced in platformConfigure() which is called first. Fix this by populating sensorInfo_ straight after configuring the sensor in configure(), ensuring the fields are valid in the call to platformConfigure(). Signed-off-by: Naushir Patuck <[email protected]>
Ensure we index the CameraConfiguration incrementally when setting up the raw and output streams. Signed-off-by: Naushir Patuck <[email protected]>
Add a new subpoject wrap file for the libpisp library located at https://github.com/raspberrypi/libpisp The libpisp library is used to configure the Raspberry Pi 5 Frontend and Backend ISP components. Signed-off-by: Naushir Patuck <[email protected]> Reviewed-by: David Plowman <[email protected]>
Add the Raspberry Pi 5 ISP (PiSP) pipeline handler to libcamera. To include this pipeline handler in the build, set the following meson option: meson configure -Dpipelines=rpi/pisp Signed-off-by: Naushir Patuck <[email protected]> Reviewed-by: David Plowman <[email protected]>
Add the Raspberry Pi 5 ISP (PiSP) IPA to libcamera. To include this IPA in the build, set the following meson option: meson configure -Dipas=rpi/pisp Signed-off-by: Naushir Patuck <[email protected]> Reviewed-by: David Plowman <[email protected]>
The IMX708 sensor driver advertises its module variants (narrow/wide angle lens, IR block/pass) by modifying the media entity name string. So add duplicate entries for each variant. Signed-off-by: Nick Hollinghurst <[email protected]> Signed-off-by: Naushir Patuck <[email protected]> Reviewed-by: Naushir Patuck <[email protected]> Reviewed-by: David Plowman <[email protected]>
Look for the RAW mandatory stream flag in the pipeline handler config file. If this flag is set, it guarantees that the application will provide buffers for Unicam Image, so override the minUnicamBuffers and minTotalUnicamBuffers config parameters in the following way: - If startup drop frames are required, allocate at least 1 internal buffer. - If no startup drop frames are required, do not allocate any internal buffers. Look for the Output 0 mandatory stream flag in in the pipeline handler config file. If this flag is set, it guarantees that the application will provide buffers for the ISP, do not allocate any internal buffers for the device. Add a new rpi_apps.yaml pipeline handler config file that enables both these flags. To use the file, set the following env variable for a custom build: export LIBCAMERA_RPI_CONFIG_FILE=/usr/local/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml or for a packaged install: export LIBCAMERA_RPI_CONFIG_FILE=/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml Signed-off-by: Naushir Patuck <[email protected]>
… buffers V4L2 only allows upto VIDEO_MAX_FRAME frames to be queued at a time, so if we reach this limit, store the framebuffers in a pending queue, and try to enqueue once a buffer has been dequeued. Signed-off-by: Naushir Patuck <[email protected]>
Use an r-value reference in set() and setLocked(), allowing more efficient metadata handling with std::forward and std::move if needed. Signed-off-by: Naushir Patuck <[email protected]>
These function erases a key/value pair from the metadata object. Signed-off-by: Naushir Patuck <[email protected]>
This property (cfeDataBufferStrided) indicates if the CSI-2 hardware writes to the embedded/metadata buffer directly, or if it treats the buffer like an image buffer and strides the metadata lines. Unicam write this buffer strided, while the PiSP Frontend writes to it directly. This information will be relevant to data parsers in the helpers where the data is structured in lines. Signed-off-by: Naushir Patuck <[email protected]>
Add the follwing RPi vendor controls to handle Convolutional Neural Network processing: CnnOutputTensor CnnOutputTensorInfo CnnEnableInputTensor CnnInputTensor CnnInputTensorInfo CnnKpiInfo These controls will be used to support the new Raspberry Pi AI Camera, using an IMX500 sensor with on-board neural network processing. Signed-off-by: Naushir Patuck <[email protected]>
Add code to handle the new CNN vendor controls in the Raspberry Pi IPA. The value of CnnInputTensorInfo is cached as it is the only stateful input control. All other controls are output controls, and the values are copied into directly from the rpiMetadata object if present. The camera helpers populate the rpiMetadata object if the sensor supports on-board CNN processing, such as the IMX500. Signed-off-by: Naushir Patuck <[email protected]>
Add a CamHelper::setHwConfig() helper used by the IPA to set the hardware configuartion in use by the pipeline. This will be needed by the IMX500 camera helper in a future commit to determine if the metadata buffer is strided. Signed-off-by: Naushir Patuck <[email protected]>
Add a Sony IMX500 camera helper to the IPA. This also includes support for the on-chip CNN hardware accelerator and parsing of the neural network data stream returned in the metadata buffer. Add tuning files for both VC4 and PiSP platforms. Signed-off-by: Naushir Patuck <[email protected]>
The file imx290.json was present in the tree, but wasn't included in meson.build and so was never installed. Add it in so that imx290/327/462 all work on Pi5. Signed-off-by: Dave Stevenson <[email protected]>
Update the kernel headers with the definition of two device-specific line-based metadata formats, and with the definition of the MEDIA_PAD_FL_INTERNAL and V4L2_SUBDEV_ROUTE_FL_IMMUTABLE flags. The new definitions will allow to support handling line-based metadata streams exposed by the sensor driver through an internal sink pad. While the changes have not yet been collected in the official linux-media tree, they're available in the 'metadata' branch of https://git.linuxtv.org/sailus/media_tree.git, at revision: 8d8fdc8a8809 ("media: Documentation: Add subdev configuration models, raw sensor model"). The patches are expected to land in Linux v6.13. Signed-off-by: Jacopo Mondi <[email protected]> Acked-by: Kieran Bingham <[email protected]>
Add the definition for the generic line based pixelformats. The formats has been added in upstream Linux by commit 1d9215233958 ("media: uapi: v4l: Add generic 8-bit metadata format definitions") which got merged in Linux v6.10. The formats however are not yet available to userspace, as they have been made only available to the kernel by commit d69c8429ea80 ("media: uapi: v4l: Don't expose generic metadata formats to userspace") to let the line-based metadata support stabilize before allowing applications to use it. With the forthcoming completion of the line-based metadata upstreaming manually add the generic line based pixel format to prepare libcamera to support them. Signed-off-by: Jacopo Mondi <[email protected]>
V4L2_CID_USER_BCM2835_ISP_BASE is defined in RPi BSP as (V4L2_CID_USER_BASE + 0x10e0) However in mainline this address has been occupied by other control bases. Align V4L2_CID_USER_BCM2835_ISP_BASE to the last available identifier available in mainline. This commit requires kernel commit d1b7fb3b95c6 ("uapi: bcm2835-isp: Re-assign V4L2_CID_USER_BCM2835_ISP_BASE") Signed-off-by: Jacopo Mondi <[email protected]>
Support the newly introduced V4L2 media bus formats for metadata. This includes generic metadata formats, and two sensor-specific embedded data formats. Signed-off-by: Laurent Pinchart <[email protected]> Reviewed-by: Jacopo Mondi <[email protected]> Signed-off-by: Jacopo Mondi <[email protected]>
With support for metadata in the streams API, the v4l2_meta_format structure has been extended with width, height and bytesperline fields. Support them in the V4L2VideoDevice getFormat() and setFormat() functions is the video device is meta capture device and if the pixel format is one of the generic line-based metadata formats. Signed-off-by: Laurent Pinchart <[email protected]> Reviewed-by: Jacopo Mondi <[email protected]> Signed-off-by: Jacopo Mondi <[email protected]> --- Compared to Larent's first version, this one sets width, height and bytesperline only if the device isMetaCap() and the V4L2 pixel format is one of the generic line based ones. Signed-off-by: Jacopo Mondi <[email protected]>
Introduce a factory to create CameraSensor derived classes instances by inspecting the sensor media entity name and provide a convenience macro to register specialized sensor handlers. Signed-off-by: Jacopo Mondi <[email protected]> Signed-off-by: Laurent Pinchart <[email protected]> Reviewed-by: Stefan Klug <[email protected]>
With a camera sensor factory in place, the next step is to create an abstract base class that all camera sensors implement, providing a uniform API to pipeline handler. Turn all public functions of the CameraSensor class into pure virtual functions, and move the implementation to the CameraSensorLegacy class. Part of the code is likely worth keeping as common helpers in a base class. However, to follow the principle of not designing helpers with a single user, this commit moves the whole implementation. Common helpers will be introduced later, along with other CameraSensor subclasses. Signed-off-by: Laurent Pinchart <[email protected]> Reviewed-by: Stefan Klug <[email protected]> Reviewed-by: Jacopo Mondi <[email protected]> Signed-off-by: Jacopo Mondi <[email protected]>
In order to support a default implementation for camera sensors when no better implementation matches, libcamera needs to try "specialized" implementations first and pick the default last. Make this possible by adding a priority value for factories. Newly registered factories are inserted in the factories list sorted by descending priority, and the default factory uses a negative priority to be inserted as the last element. This mechanism may be a bit overkill in the sense that there is no expected use cases for priorities other than trying the default last, but the implementation is simple and easy to understand. Signed-off-by: Laurent Pinchart <[email protected]> Reviewed-by: Stefan Klug <[email protected]> Reviewed-by: Jacopo Mondi <[email protected]> Signed-off-by: Jacopo Mondi <[email protected]>
Add a new CameraSensorRaw implementation of the CameraSensor interface tailored to devices that implement the new V4L2 raw camera sensors API. This new class duplicates code from the CameraSensorLegacy class. The two classes will be refactored to share code. Signed-off-by: Laurent Pinchart <[email protected]> --- Changes since combined RFC: - Set factory priority explicitly - Set flipsAlterBayerOrder_ - Fix build warning due to missing default case in cfa switch - Check for read-only hblank using V4L2_CTRL_FLAG_READ_ONLY
Some sensors support producing and transmitting embedded data over a stream separate from the image stream. Add support for this feature in the CameraSensor interface, and implement it for the CameraSensorRaw class. The CameraSensorLegacy uses the default stub implementation, as the corresponding kernel drivers don't support embedded data. Signed-off-by: Laurent Pinchart <[email protected]>
Now that the CameraSensor class implements support for embedded data, use the corresponding API to enable or disable the embedded data stream. This changes requires sensor kernel drivers that implement the upstream embedded data API based on V4L2 streams. As the API is under development and not merged in the upstream kernel yet, this breaks compatibility with the downstream Raspberry Pi kernel. Signed-off-by: Laurent Pinchart <[email protected]>
Use the stream formatting operator for V4L2VideoFormat instead of calling .toString() manually. As the .toString() member function is a wrapper around the stream formatting operator, this makes the code slightly more efficient. Signed-off-by: Laurent Pinchart <[email protected]>
The Vc4CameraData::platformConfigure() function configures inicam and the ISP. The corresponding configuration steps are interleaved, making it more difficult to read the code and follow the flow. Reorganize the function to improve readability. Signed-off-by: Laurent Pinchart <[email protected]>
Now that the CameraSensor class implements support for embedded data, use the corresponding API instead of retrieving the embedded data format from the subdev manually. This changes requires sensor kernel drivers that implement the upstream embedded data API based on V4L2 streams. As the API is under development and not merged in the upstream kernel yet, this breaks compatibility with the downstream Raspberry Pi kernel. Signed-off-by: Laurent Pinchart <[email protected]>
The mainline Unicam driver unconditionally creates the embedded data video device. Create the corresponding stream unconditionally. Drop the warning in case of mismatch between Unicam and the CamHelper, as this becomes a normal situation when the sensor doesn't support emebedded data. Signed-off-by: Laurent Pinchart <[email protected]>
The mainline Unicam driver creates a V4L2 subdevice, which needs to be configured. Create and open a corresponding V4L2Subdevice instance and configure the format on its sink pad in the platformConfigure() function. Presence of the Unicam subdev is required, to avoid extra complexity. This drops support for the driver from the Raspberry Pi downstream kernel. Users are expected to update their kernel to use the mainline Unicam driver. Signed-off-by: Laurent Pinchart <[email protected]>
The Unicam embedded data video device suffers from two issues with the upstream driver: - The driver uses the generic metadata V4L2_META_FMT_GENERIC_* formats, instead of the downstream V4L2_META_FMT_SENSOR_DATA. - The driver requires the width and height of the embedded data stream to be configured. Fix them both. Signed-off-by: Laurent Pinchart <[email protected]>
The V4L2_META_FMT_SENSOR_DATA format was used by the Raspberry Pi VC4 pipeline handler and the downstream Unicam kernel driver. Now that they have both moved to an upstream API, drop the format definition from the kernel header. This brings videodev2.h closer to the mainline kernel. Signed-off-by: Laurent Pinchart <[email protected]>
Enable embedded data usage with the IMX219 for testing purpose. Signed-off-by: Laurent Pinchart <[email protected]>
Also update the entity names to match the upstream driver. Signed-off-by: Naushir Patuck <[email protected]> Signed-off-by: Jacopo Mondi <[email protected]>
naushir
force-pushed
the
next
branch
2 times, most recently
from
November 12, 2024 11:25
5da5394
to
75fe515
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Companion PR of raspberrypi/linux#6437
Tested with imx219 on pi5 and pi4. On pi4 @jailuthra reported instabilities in the embedded data reading. Maybe that's the reason why embedded data were originally disabled on that sensor.