[PATCH v2 3/4] libcamera: internal: Add MediaPipeline helper
Kieran Bingham
kieran.bingham at ideasonboard.com
Wed Oct 2 23:56:55 CEST 2024
Quoting Kieran Bingham (2024-10-02 22:26:31)
> Provide a MediaPipeline class to help identifing and managing pipelines across
> a MediaDevice graph.
>
> Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
>
> ---
> v2:
>
> - use srcPads to clearly identify which pads are managed
> - Only report enabling links when a change is made
>
> - fix header includes
>
> - Fix includes
> - Remove period at end of briefs
>
> - Document function parameters
> - expand documentation throughout
> - Fix debug log capitalisation
>
> - reduce scope of single use 'ret'
>
> Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
... snippity ...
> +
> +/**
> + * \brief Configure the entities of this MediaPipeline
> + * \param[in] sensor The configured CameraSensor to propogate
How did I miss that.
Will add
* \param[inout] format The format to propogate through the pipeline
> + *
> + * Propagate formats through each of the entities of the Pipeline, validating
> + * that each one was not adjusted by the driver from the desired format.
> + *
Maybe I should add
* The format is updated with the final accepted format of the last
* entity of the pipeline.
> + * \return 0 on success or a negative errno otherwise
> + */
> +int MediaPipeline::configure(CameraSensor *sensor, V4L2SubdeviceFormat *format)
> +{
> + int ret;
> +
> + for (const Entity &e : entities_) {
> + /* The sensor is configured through the CameraSensor */
> + if (!e.sourceLink)
> + break;
> +
> + MediaLink *link = e.sourceLink;
> + MediaPad *source = link->source();
> + MediaPad *sink = link->sink();
> +
> + /* 'format' already contains the sensor configuration */
> + if (source->entity() != sensor->entity()) {
> + /* todo: Add MediaDevice cache to reduce FD pressure */
> + V4L2Subdevice subdev(source->entity());
> + ret = subdev.open();
> + if (ret)
> + return ret;
> +
> + ret = subdev.getFormat(source->index(), format);
> + if (ret < 0)
> + return ret;
> + }
> +
> + V4L2SubdeviceFormat sourceFormat = *format;
> + /* todo: Add MediaDevice cache to reduce FD pressure */
> + V4L2Subdevice subdev(sink->entity());
> + ret = subdev.open();
> + if (ret)
> + return ret;
> +
> + ret = subdev.setFormat(sink->index(), format);
> + if (ret < 0)
> + return ret;
> +
> + if (format->code != sourceFormat.code ||
> + format->size != sourceFormat.size) {
> + LOG(MediaPipeline, Debug)
> + << "Source '" << *source
> + << " produces " << sourceFormat
> + << ", sink '" << *sink
> + << " requires " << format;
> + return -EINVAL;
> + }
> +
> + LOG(MediaPipeline, Debug)
> + << "Link " << *link << " configured with format "
> + << format;
> + }
> +
> + return 0;
> +}
> +
> +} /* namespace libcamera */
> diff --git a/src/libcamera/meson.build b/src/libcamera/meson.build
> index aa9ab0291854..2c0f8603b231 100644
> --- a/src/libcamera/meson.build
> +++ b/src/libcamera/meson.build
> @@ -41,6 +41,7 @@ libcamera_internal_sources = files([
> 'mapped_framebuffer.cpp',
> 'media_device.cpp',
> 'media_object.cpp',
> + 'media_pipeline.cpp',
> 'pipeline_handler.cpp',
> 'process.cpp',
> 'pub_key.cpp',
> --
> 2.34.1
>
More information about the libcamera-devel
mailing list