diff options
author | Jacopo Mondi <jacopo.mondi@ideasonboard.com> | 2023-08-08 13:44:09 +0200 |
---|---|---|
committer | Jacopo Mondi <jacopo.mondi@ideasonboard.com> | 2023-08-08 14:34:28 +0200 |
commit | 65f37a807e577a6cdae9e8cc11bcac64b41b50bf (patch) | |
tree | 946c3fd0b4e30abc465dc82118f54008db532475 | |
parent | 4d1ddf954159cd0b251c81d5b92c5fdfd33cf061 (diff) |
[HACK] libcamera: pipeline: Add usb-test pipelinejmondi/device-match-generalize
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>
-rw-r--r-- | meson_options.txt | 1 | ||||
-rw-r--r-- | src/libcamera/pipeline/usb-test/meson.build | 5 | ||||
-rw-r--r-- | src/libcamera/pipeline/usb-test/usb_test.cpp | 93 |
3 files changed, 99 insertions, 0 deletions
diff --git a/meson_options.txt b/meson_options.txt index fad928af..e706484b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -46,6 +46,7 @@ option('pipelines', 'rkisp1', 'rpi/vc4', 'simple', + 'usb-test', 'uvcvideo', 'vimc' ], diff --git a/src/libcamera/pipeline/usb-test/meson.build b/src/libcamera/pipeline/usb-test/meson.build new file mode 100644 index 00000000..bafff18e --- /dev/null +++ b/src/libcamera/pipeline/usb-test/meson.build @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: CC0-1.0 + +libcamera_sources += files([ + 'usb_test.cpp', +]) diff --git a/src/libcamera/pipeline/usb-test/usb_test.cpp b/src/libcamera/pipeline/usb-test/usb_test.cpp new file mode 100644 index 00000000..5df1a137 --- /dev/null +++ b/src/libcamera/pipeline/usb-test/usb_test.cpp @@ -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 */ |