[PATCH] pipeline: simple: Use proper device for frame start events
Hans de Goede
hdegoede at redhat.com
Tue Dec 17 14:43:49 CET 2024
Hi,
On 17-Dec-24 11:52 AM, Stanislaw Gruszka wrote:
> Currently we use frame start event from video capture device to
> apply controls. But the capture device might not generate the events.
> Usually CSI-2 receiver is proper device to subscribe for start
> frame events.
>
> Without DelayedConntrols:applyControls() is possible that we can get
> call to DelayedControls::get() with frame number that exceed number
> of saved entries and get below assertion failure:
>
> ../src/libcamera/delayed_controls.cpp:227:
> libcamera::ControlList libcamera::DelayedControls::get(uint32_t):
> Assertion `info.type() != ControlTypeNone' failed
>
> Assertion failure can happen at the beginning of streaming when
> ControlRingBuffer is not yet filled and there are errors on CSI-2.
>
> To fix, loop over devices in the pipeline (starting from the last one),
> find one that emits start frame events and connect applyControls()
> to it.
>
> Bug: https://bugs.libcamera.org/show_bug.cgi?id=241
> Signed-off-by: Stanislaw Gruszka <stanislaw.gruszka at linux.intel.com>
p.s.
With this patch in place we can also introduce a custom frameStart handler,
rather then directly using delayedCtrls_->apply() as handler and also
get a timestamp from the framestart handler fixing the todo comment
around line 832 of simple.cpp.
This could/should be done in a follow-up patch to this one.
Regards,
Hans
> ---
> src/libcamera/pipeline/simple/simple.cpp | 26 ++++++++++++++++++++++--
> 1 file changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
> index 8ac24e6e..52f3d520 100644
> --- a/src/libcamera/pipeline/simple/simple.cpp
> +++ b/src/libcamera/pipeline/simple/simple.cpp
> @@ -382,6 +382,7 @@ private:
> std::map<const MediaEntity *, EntityData> entities_;
>
> MediaDevice *converter_;
> + V4L2Subdevice *eventEmitter_;
> bool swIspEnabled_;
> };
>
> @@ -1299,8 +1300,6 @@ int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c)
> data->delayedCtrls_ =
> std::make_unique<DelayedControls>(data->sensor_->device(),
> params);
> - data->video_->frameStart.connect(data->delayedCtrls_.get(),
> - &DelayedControls::applyControls);
>
> StreamConfiguration inputCfg;
> inputCfg.pixelFormat = pipeConfig->captureFormat;
> @@ -1368,6 +1367,23 @@ int SimplePipelineHandler::start(Camera *camera, [[maybe_unused]] const ControlL
>
> video->bufferReady.connect(data, &SimpleCameraData::imageBufferReady);
>
> + /*
> + * Enable frame start event on last device in the pipeline
> + * that provides the events.
> + */
> + for (auto it = data->entities_.rbegin(); it != data->entities_.rend(); ++it) {
> + V4L2Subdevice *sd = subdev(it->entity);
> + if (!sd)
> + continue;
> + if (sd->setFrameStartEnabled(true) < 0)
> + continue;
> +
> + sd->frameStart.connect(data->delayedCtrls_.get(),
> + &DelayedControls::applyControls);
> + eventEmitter_ = sd;
> + break;
> + }
> +
> ret = video->streamOn();
> if (ret < 0) {
> stop(camera);
> @@ -1400,6 +1416,12 @@ void SimplePipelineHandler::stopDevice(Camera *camera)
> SimpleCameraData *data = cameraData(camera);
> V4L2VideoDevice *video = data->video_;
>
> + if (eventEmitter_) {
> + eventEmitter_->setFrameStartEnabled(false);
> + eventEmitter_->frameStart.disconnect(data->delayedCtrls_.get(),
> + &DelayedControls::applyControls);
> + }
> +
> if (data->useConversion_) {
> if (data->converter_)
> data->converter_->stop();
More information about the libcamera-devel
mailing list