@@ -46,6 +46,7 @@ option('pipelines',
'rkisp1',
'rpi/vc4',
'simple',
+ 'usb-test',
'uvcvideo',
'vimc'
],
new file mode 100644
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: CC0-1.0
+
+libcamera_sources += files([
+ 'usb_test.cpp',
+])
new file mode 100644
@@ -0,0 +1,93 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2023, Ideas On Board Oy
+ *
+ * usb_test.cpp - Test USB device matching
+ */
+
+#include <libcamera/base/log.h>
+
+#include <libcamera/camera.h>
+#include <libcamera/stream.h>
+
+#include "libcamera/internal/camera.h"
+#include "libcamera/internal/device_enumerator.h"
+#include "libcamera/internal/pipeline_handler.h"
+#include "libcamera/internal/usb_device.h"
+
+namespace libcamera {
+
+LOG_DEFINE_CATEGORY(USBTest)
+
+class USBCameraData : public Camera::Private
+{
+public:
+ USBCameraData(PipelineHandler *pipe)
+ : Camera::Private(pipe)
+ {
+ }
+
+ Stream stream_;
+};
+
+class PipelineHandlerUSB : public PipelineHandler
+{
+public:
+ PipelineHandlerUSB(CameraManager *manager)
+ : PipelineHandler(manager)
+ {
+ }
+
+ std::unique_ptr<CameraConfiguration> generateConfiguration([[maybe_unused]] Camera *camera,
+ [[maybe_unused]] Span<const StreamRole> roles) override
+ {
+ return {};
+ }
+ int configure([[maybe_unused]] Camera *camera, [[maybe_unused]] CameraConfiguration *config) override
+ {
+ return 0;
+ }
+
+ int exportFrameBuffers([[maybe_unused]] Camera *camera, [[maybe_unused]] Stream *stream,
+ [[maybe_unused]] std::vector<std::unique_ptr<FrameBuffer>> *buffers) override
+ {
+ return 0;
+ }
+
+ int start([[maybe_unused]] Camera *camera, [[maybe_unused]] const ControlList *controls) override
+ {
+ return 0;
+ }
+ void stopDevice([[maybe_unused]] Camera *camera) override
+ {
+ }
+
+ int queueRequestDevice([[maybe_unused]] Camera *camera, [[maybe_unused]] Request *request) override
+ {
+ return 0;
+ }
+
+ bool match(DeviceEnumerator *enumerator) override;
+};
+
+bool PipelineHandlerUSB::match(DeviceEnumerator *enumerator)
+{
+ USBDeviceMatch dm("046d", "c52b");
+ USBDevice *usbDev = acquireUSBDevice(enumerator, dm);
+ if (!usbDev)
+ return false;
+
+ std::unique_ptr<USBCameraData> data = std::make_unique<USBCameraData>(this);
+ std::string id = usbDev->vid() + "/" + usbDev->pid();
+ std::set<Stream *> streams{ &data->stream_ };
+
+ std::shared_ptr<Camera> camera =
+ Camera::create(std::move(data), id, streams);
+ registerCamera(std::move(camera));
+
+ return true;
+}
+
+REGISTER_PIPELINE_HANDLER(PipelineHandlerUSB)
+
+} /* namespace libcamera */
Add a test pipeline to match on a USBDevice. This is a proof of concept as the pipeline handler matches on my mouse VID/PID pair. Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> --- meson_options.txt | 1 + src/libcamera/pipeline/usb-test/meson.build | 5 ++ src/libcamera/pipeline/usb-test/usb_test.cpp | 93 ++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 src/libcamera/pipeline/usb-test/meson.build create mode 100644 src/libcamera/pipeline/usb-test/usb_test.cpp