From 65f37a807e577a6cdae9e8cc11bcac64b41b50bf Mon Sep 17 00:00:00 2001 From: Jacopo Mondi Date: Tue, 8 Aug 2023 13:44:09 +0200 Subject: [HACK] libcamera: pipeline: Add usb-test pipeline 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 --- 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 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 + +#include +#include + +#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 generateConfiguration([[maybe_unused]] Camera *camera, + [[maybe_unused]] Span 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> *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 data = std::make_unique(this); + std::string id = usbDev->vid() + "/" + usbDev->pid(); + std::set streams{ &data->stream_ }; + + std::shared_ptr camera = + Camera::create(std::move(data), id, streams); + registerCamera(std::move(camera)); + + return true; +} + +REGISTER_PIPELINE_HANDLER(PipelineHandlerUSB) + +} /* namespace libcamera */ -- cgit v1.2.1