summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/py/libcamera/gen-py-control-enums.py95
-rw-r--r--src/py/libcamera/meson.build12
-rw-r--r--src/py/libcamera/pyenums_generated.cpp.in21
-rw-r--r--src/py/libcamera/pymain.cpp2
4 files changed, 130 insertions, 0 deletions
diff --git a/src/py/libcamera/gen-py-control-enums.py b/src/py/libcamera/gen-py-control-enums.py
new file mode 100755
index 00000000..dcc28b1a
--- /dev/null
+++ b/src/py/libcamera/gen-py-control-enums.py
@@ -0,0 +1,95 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Generate Python bindings enums for controls from YAML
+
+import argparse
+import string
+import sys
+import yaml
+
+
+def find_common_prefix(strings):
+ prefix = strings[0]
+
+ for string in strings[1:]:
+ while string[:len(prefix)] != prefix and prefix:
+ prefix = prefix[:len(prefix) - 1]
+ if not prefix:
+ break
+
+ return prefix
+
+
+def generate_py(controls):
+ out = ''
+
+ for ctrl in controls:
+ name, ctrl = ctrl.popitem()
+
+ enum = ctrl.get('enum')
+ if not enum:
+ continue
+
+ if ctrl.get('draft'):
+ ns = 'libcamera::controls::draft::'
+ else:
+ ns = 'libcamera::controls::'
+
+ cpp_enum = name + 'Enum'
+
+ out += '\tpy::enum_<{}{}>(m, \"{}\")\n'.format(ns, cpp_enum, name)
+
+ if name == 'LensShadingMapMode':
+ prefix = 'LensShadingMapMode'
+ else:
+ prefix = find_common_prefix([e['name'] for e in enum])
+
+ for entry in enum:
+ cpp_enum = entry['name']
+ py_enum = entry['name'][len(prefix):]
+
+ out += '\t\t.value(\"{}\", {}{})\n'.format(py_enum, ns, cpp_enum)
+
+ out += '\t;\n'
+
+ return {'enums': out}
+
+
+def fill_template(template, data):
+ template = open(template, 'rb').read()
+ template = template.decode('utf-8')
+ template = string.Template(template)
+ return template.substitute(data)
+
+
+def main(argv):
+ # Parse command line arguments
+ parser = argparse.ArgumentParser()
+ parser.add_argument('-o', dest='output', metavar='file', type=str,
+ help='Output file name. Defaults to standard output if not specified.')
+ parser.add_argument('input', type=str,
+ help='Input file name.')
+ parser.add_argument('template', type=str,
+ help='Template file name.')
+ args = parser.parse_args(argv[1:])
+
+ data = open(args.input, 'rb').read()
+ controls = yaml.safe_load(data)['controls']
+
+ data = generate_py(controls)
+
+ data = fill_template(args.template, data)
+
+ if args.output:
+ output = open(args.output, 'wb')
+ output.write(data.encode('utf-8'))
+ output.close()
+ else:
+ sys.stdout.write(data)
+
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
diff --git a/src/py/libcamera/meson.build b/src/py/libcamera/meson.build
index edf4a629..842db1ed 100644
--- a/src/py/libcamera/meson.build
+++ b/s * guarantees that before actually applying the Request to the hardware, all the * valid fences of the frame buffers in a Request are correctly signalled. Once * a Fence has completed, the library will release the FrameBuffer fence so that * application won't be allowed to access it. * * An optional timeout can be started while waiting for a fence to complete. If * waiting on a Fence fails for whatever reason, the FrameBuffer's fence is not * reset and is made available to application for them to handle it, by * releasing the Fence to correctly close the underlying UniqueFD. * * A failure in waiting for a Fence to complete will result in the Request to * complete in failed state. * * \sa Request::prepare() * \sa PipelineHandler::doQueueRequests() */ /** * \brief Create a Fence * \param[in] fd The fence file descriptor * * The file descriptor ownership is moved to the Fence. */ Fence::Fence(UniqueFD fd) : fd_(std::move(fd)) { } /** * \fn Fence::isValid() * \brief Check if a Fence is valid * * A Fence is valid if the file descriptor it wraps is valid. * * \return True if the Fence is valid, false otherwise */ /** * \fn Fence::fd() * \brief Retrieve a constant reference to the file descriptor * \return A const reference to the fence file descriptor */ /** * \fn Fence::release() * \brief Release the ownership of the file descriptor * * Release the ownership of the wrapped file descriptor by returning it to the * caller. * * \return The wrapper UniqueFD */ } /* namespace libcamera */
.1 (git 2.18.0) at 2024-12-25 06:55:35 +0000