Some entities in a media graph have names that might differ from
implementation to implementation; for example the Camera Receiver
Unit and CSI-2 receiver on the RZ/V2H(P) SoC have entities with names
that include their address, in the form "csi-16000400.csi2". Passing
that entity name to DeviceMatch is too inflexible given it would only
work if that specific CSI-2 receiver were the one being used.
Add an overload for DeviceMatch::add() such that users can pass in a
std::regex instead of a string. Update DeviceMatch::match() to check
for entities that are matched by the regular expressions added with
the new overload after checking for any exact matches from the vector
of strings. This allows us to use regex to match on patterns like
"csi-[0-9a-f]{8}.csi2".
Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
61 lines
1.1 KiB
C++
61 lines
1.1 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2018, Google Inc.
|
|
*
|
|
* API to enumerate and find media devices
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <libcamera/base/regex.h>
|
|
#include <libcamera/base/signal.h>
|
|
|
|
namespace libcamera {
|
|
|
|
class MediaDevice;
|
|
|
|
class DeviceMatch
|
|
{
|
|
public:
|
|
DeviceMatch(const std::string &driver);
|
|
|
|
void add(const std::string &entity);
|
|
void add(std::regex entity);
|
|
|
|
bool match(const MediaDevice *device) const;
|
|
|
|
private:
|
|
std::string driver_;
|
|
std::vector<std::string> entities_;
|
|
std::vector<std::regex> entityRegexs_;
|
|
};
|
|
|
|
class DeviceEnumerator
|
|
{
|
|
public:
|
|
static std::unique_ptr<DeviceEnumerator> create();
|
|
|
|
virtual ~DeviceEnumerator();
|
|
|
|
virtual int init() = 0;
|
|
virtual int enumerate() = 0;
|
|
|
|
std::shared_ptr<MediaDevice> search(const DeviceMatch &dm);
|
|
|
|
Signal<> devicesAdded;
|
|
|
|
protected:
|
|
std::unique_ptr<MediaDevice> createDevice(const std::string &deviceNode);
|
|
void addDevice(std::unique_ptr<MediaDevice> media);
|
|
void removeDevice(const std::string &deviceNode);
|
|
|
|
private:
|
|
std::vector<std::shared_ptr<MediaDevice>> devices_;
|
|
};
|
|
|
|
} /* namespace libcamera */
|