[libcamera-devel,v5,7/9] ipa: vimc: Add Flags to parameters
diff mbox series

Message ID 20221011105859.457567-8-paul.elder@ideasonboard.com
State Accepted
Headers show
Series
  • utils: ipc: Add support for enums and Flags
Related show

Commit Message

Paul Elder Oct. 11, 2022, 10:58 a.m. UTC
For the purpose of testing serializing/deserializing Flags in function
parameters, add an enum class TestFlags and Flags<TestFlags> to some
function parameters, both for input and output and Signals.

While at it, update the ipa_interface_test.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

---
No change in v5

Changes in v4:
- make flags also passed directly (as opposed to const references)
- remove [TEST] from commit subject

Changes in v3:
- s/TestFlags/TestFlag/
- add [scopedEnum] to enum Testflag

Changes in v2:
- use new attribute-based mojom definition for Flags
---
 include/libcamera/ipa/vimc.mojom     | 14 ++++++++++++--
 src/ipa/vimc/vimc.cpp                | 20 +++++++++++++++++---
 src/libcamera/pipeline/vimc/vimc.cpp | 15 ++++++++++++---
 test/ipa/ipa_interface_test.cpp      |  6 +++++-
 4 files changed, 46 insertions(+), 9 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/ipa/vimc.mojom b/include/libcamera/ipa/vimc.mojom
index 16149787..dd991f7e 100644
--- a/include/libcamera/ipa/vimc.mojom
+++ b/include/libcamera/ipa/vimc.mojom
@@ -17,8 +17,18 @@  enum IPAOperationCode {
 	IPAOperationStop,
 };
 
+[scopedEnum] enum TestFlag {
+	Flag1 = 0x1,
+	Flag2 = 0x2,
+	Flag3 = 0x4,
+	Flag4 = 0x8,
+};
+
 interface IPAVimcInterface {
-	init(libcamera.IPASettings settings, IPAOperationCode code) => (int32 ret);
+	init(libcamera.IPASettings settings,
+	     IPAOperationCode code,
+	     [flags] TestFlag inFlags)
+	=> (int32 ret, [flags] TestFlag outFlags);
 
 	configure(libcamera.IPACameraSensorInfo sensorInfo,
 		  map<uint32, libcamera.IPAStream> streamConfig,
@@ -41,5 +51,5 @@  interface IPAVimcInterface {
 };
 
 interface IPAVimcEventInterface {
-	paramsBufferReady(uint32 bufferId);
+	paramsBufferReady(uint32 bufferId, [flags] TestFlag flags);
 };
diff --git a/src/ipa/vimc/vimc.cpp b/src/ipa/vimc/vimc.cpp
index 5d494b63..9256bbba 100644
--- a/src/ipa/vimc/vimc.cpp
+++ b/src/ipa/vimc/vimc.cpp
@@ -31,7 +31,10 @@  public:
 	IPAVimc();
 	~IPAVimc();
 
-	int init(const IPASettings &settings, const ipa::vimc::IPAOperationCode code) override;
+	int init(const IPASettings &settings,
+		 const ipa::vimc::IPAOperationCode code,
+		 const Flags<ipa::vimc::TestFlag> inFlags,
+		 Flags<ipa::vimc::TestFlag> *outFlags) override;
 
 	int start() override;
 	void stop() override;
@@ -66,7 +69,10 @@  IPAVimc::~IPAVimc()
 		::close(fd_);
 }
 
-int IPAVimc::init(const IPASettings &settings, const ipa::vimc::IPAOperationCode code)
+int IPAVimc::init(const IPASettings &settings,
+		  const ipa::vimc::IPAOperationCode code,
+		  const Flags<ipa::vimc::TestFlag> inFlags,
+		  Flags<ipa::vimc::TestFlag> *outFlags)
 {
 	trace(ipa::vimc::IPAOperationInit);
 
@@ -76,6 +82,13 @@  int IPAVimc::init(const IPASettings &settings, const ipa::vimc::IPAOperationCode
 
 	LOG(IPAVimc, Debug) << "Got opcode " << code;
 
+	LOG(IPAVimc, Debug)
+		<< "Flag 2 was "
+		<< (inFlags & ipa::vimc::TestFlag::Flag2 ? "" : "not ")
+		<< "set";
+
+	*outFlags |= ipa::vimc::TestFlag::Flag1;
+
 	File conf(settings.configurationFile);
 	if (!conf.open(File::OpenModeFlag::ReadOnly)) {
 		LOG(IPAVimc, Error) << "Failed to open configuration file";
@@ -144,7 +157,8 @@  void IPAVimc::fillParamsBuffer([[maybe_unused]] uint32_t frame, uint32_t bufferI
 		return;
 	}
 
-	paramsBufferReady.emit(bufferId);
+	Flags<ipa::vimc::TestFlag> flags;
+	paramsBufferReady.emit(bufferId, flags);
 }
 
 void IPAVimc::initTrace()
diff --git a/src/libcamera/pipeline/vimc/vimc.cpp b/src/libcamera/pipeline/vimc/vimc.cpp
index df749bf7..f85d05f7 100644
--- a/src/libcamera/pipeline/vimc/vimc.cpp
+++ b/src/libcamera/pipeline/vimc/vimc.cpp
@@ -54,7 +54,7 @@  public:
 	int init();
 	int allocateMockIPABuffers();
 	void bufferReady(FrameBuffer *buffer);
-	void paramsBufferReady(unsigned int id);
+	void paramsBufferReady(unsigned int id, const Flags<ipa::vimc::TestFlag> flags);
 
 	MediaDevice *media_;
 	std::unique_ptr<CameraSensor> sensor_;
@@ -471,7 +471,15 @@  bool PipelineHandlerVimc::match(DeviceEnumerator *enumerator)
 	data->ipa_->paramsBufferReady.connect(data.get(), &VimcCameraData::paramsBufferReady);
 
 	std::string conf = data->ipa_->configurationFile("vimc.conf");
-	data->ipa_->init(IPASettings{ conf, data->sensor_->model() }, ipa::vimc::IPAOperationInit);
+	Flags<ipa::vimc::TestFlag> inFlags = ipa::vimc::TestFlag::Flag2;
+	Flags<ipa::vimc::TestFlag> outFlags;
+	data->ipa_->init(IPASettings{ conf, data->sensor_->model() },
+			 ipa::vimc::IPAOperationInit, inFlags, &outFlags);
+
+	LOG(VIMC, Debug)
+		<< "Flag 1 was "
+		<< (outFlags & ipa::vimc::TestFlag::Flag1 ? "" : "not ")
+		<< "set";
 
 	/* Create and register the camera. */
 	std::set<Stream *> streams{ &data->stream_ };
@@ -608,7 +616,8 @@  int VimcCameraData::allocateMockIPABuffers()
 	return video_->exportBuffers(kBufCount, &mockIPABufs_);
 }
 
-void VimcCameraData::paramsBufferReady([[maybe_unused]] unsigned int id)
+void VimcCameraData::paramsBufferReady([[maybe_unused]] unsigned int id,
+				       [[maybe_unused]] const Flags<ipa::vimc::TestFlag> flags)
 {
 }
 
diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp
index cd20348a..051ef96e 100644
--- a/test/ipa/ipa_interface_test.cpp
+++ b/test/ipa/ipa_interface_test.cpp
@@ -106,7 +106,11 @@  protected:
 
 		/* Test initialization of IPA module. */
 		std::string conf = ipa_->configurationFile("vimc.conf");
-		int ret = ipa_->init(IPASettings{ conf, "vimc" }, ipa::vimc::IPAOperationInit);
+		Flags<ipa::vimc::TestFlag> inFlags;
+		Flags<ipa::vimc::TestFlag> outFlags;
+		int ret = ipa_->init(IPASettings{ conf, "vimc" },
+				     ipa::vimc::IPAOperationInit,
+				     inFlags, &outFlags);
 		if (ret < 0) {
 			cerr << "IPA interface init() failed" << endl;
 			return TestFail;