summaryrefslogtreecommitdiff
path: root/src/ipa/rpi/controller/stitch_status.h
diff options
context:
space:
mode:
authorNaushir Patuck <naush@raspberrypi.com>2023-11-08 13:44:20 +0000
committerNaushir Patuck <naush@raspberrypi.com>2023-11-29 09:05:38 +0000
commit0455bbbf518cc834bd72ac65e13c9ed40bf21f3c (patch)
tree97fec38bd5b40cf14e411f425fd31261b4124351 /src/ipa/rpi/controller/stitch_status.h
parentbba4ec63c4b0699b7f7ffb20e4f37af2b996d355 (diff)
build: controls: Rework how controls and properties are generated
Add support for using separate YAML files for controls and properties generation. The mapping of vendor/pipeline handler to control file is done through the controls_map variable in include/libcamera/meson.build. This simplifies management of vendor control definitions and avoids possible merge conflicts when changing the control_ids.yaml file for core and draft controls. With this change, libcamera and draft controls and properties files are designated the 'libcamera' vendor tag. In this change, we also rename control_ids.yaml -> control_ids_core.yaml and property_ids.yaml -> property_ids_core.yaml to designate these as core libcamera controls. Signed-off-by: Naushir Patuck <naush@raspberrypi.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/ipa/rpi/controller/stitch_status.h')
0 files changed, 0 insertions, 0 deletions
n143'>143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2020, Google Inc.
 *
 * ipa_proxy_thread.cpp - Proxy running an Image Processing Algorithm in a thread
 */

#include <memory>

#include <libcamera/ipa/ipa_interface.h>
#include <libcamera/ipa/ipa_module_info.h>

#include "libcamera/internal/ipa_context_wrapper.h"
#include "libcamera/internal/ipa_module.h"
#include "libcamera/internal/ipa_proxy.h"
#include "libcamera/internal/log.h"
#include "libcamera/internal/thread.h"

namespace libcamera {

LOG_DECLARE_CATEGORY(IPAProxy)

class IPAProxyThread : public IPAProxy, public Object
{
public:
	IPAProxyThread(IPAModule *ipam);

	int init(const IPASettings &settings) override;
	int start() override;
	void stop() override;

	void configure(const CameraSensorInfo &sensorInfo,
		       const std::map<unsigned int, IPAStream> &streamConfig,
		       const std::map<unsigned int, const ControlInfoMap &> &entityControls,
		       const IPAOperationData &ipaConfig,
		       IPAOperationData *result) override;
	void mapBuffers(const std::vector<IPABuffer> &buffers) override;
	void unmapBuffers(const std::vector<unsigned int> &ids) override;
	void processEvent(const IPAOperationData &event) override;

private:
	void queueFrameAction(unsigned int frame, const IPAOperationData &data);

	/* Helper class to invoke processEvent() in another thread. */
	class ThreadProxy : public Object
	{
	public:
		void setIPA(IPAInterface *ipa)
		{
			ipa_ = ipa;
		}

		int start()
		{
			return ipa_->start();
		}

		void stop()
		{
			ipa_->stop();
		}

		void processEvent(const IPAOperationData &event)
		{
			ipa_->processEvent(event);
		}

	private:
		IPAInterface *ipa_;
	};

	bool running_;
	Thread thread_;
	ThreadProxy proxy_;
	std::unique_ptr<IPAInterface> ipa_;
};

IPAProxyThread::IPAProxyThread(IPAModule *ipam)
	: IPAProxy(ipam), running_(false)
{
	if (!ipam->load())
		return;

	struct ipa_context *ctx = ipam->createContext();
	if (!ctx) {
		LOG(IPAProxy, Error)
			<< "Failed to create IPA context for " << ipam->path();
		return;
	}

	ipa_ = std::make_unique<IPAContextWrapper>(ctx);
	proxy_.setIPA(ipa_.get());

	/*
	 * Proxy the queueFrameAction signal to dispatch it in the caller's
	 * thread.
	 */
	ipa_->queueFrameAction.connect(this, &IPAProxyThread::queueFrameAction);

	valid_ = true;
}

int IPAProxyThread::init(const IPASettings &settings)
{
	int ret = ipa_->init(settings);
	if (ret)
		return ret;

	proxy_.moveToThread(&thread_);

	return 0;
}

int IPAProxyThread::start()
{
	running_ = true;
	thread_.start();

	return proxy_.invokeMethod(&ThreadProxy::start, ConnectionTypeBlocking);
}

void IPAProxyThread::stop()
{
	if (!running_)
		return;

	running_ = false;

	proxy_.invokeMethod(&ThreadProxy::stop, ConnectionTypeBlocking);

	thread_.exit();
	thread_.wait();
}

void IPAProxyThread::configure(const CameraSensorInfo &sensorInfo,
			       const std::map<unsigned int, IPAStream> &streamConfig,
			       const std::map<unsigned int, const ControlInfoMap &> &entityControls,
			       const IPAOperationData &ipaConfig,
			       IPAOperationData *result)
{
	ipa_->configure(sensorInfo, streamConfig, entityControls, ipaConfig,
			result);
}

void IPAProxyThread::mapBuffers(const std::vector<IPABuffer> &buffers)
{
	ipa_->mapBuffers(buffers);
}

void IPAProxyThread::unmapBuffers(const std::vector<unsigned int> &ids)
{
	ipa_->unmapBuffers(ids);
}

void IPAProxyThread::processEvent(const IPAOperationData &event)
{
	if (!running_)
		return;

	/* Dispatch the processEvent() call to the thread. */
	proxy_.invokeMethod(&ThreadProxy::processEvent, ConnectionTypeQueued,
			    event);
}

void IPAProxyThread::queueFrameAction(unsigned int frame, const IPAOperationData &data)
{
	IPAInterface::queueFrameAction.emit(frame, data);
}

REGISTER_IPA_PROXY(IPAProxyThread)

} /* namespace libcamera */