The MediaDevice class will be the entry point to hot-unplug, as it corresponds to the kernel devices that will report device removal events. The class will signal media device disconnection to pipeline handlers, which will clean up resources as a result. This can't be performed synchronously as references may exist to the related Camera objects in applications. The MediaDevice object thus needs to be reference-counted in order to support unplugging, as otherwise pipeline handlers would be required to drop all the references to the media device they have borrowed synchronously with the disconnection signal handler, which would be very error prone (if even possible at all in a sane way). Handle MedieDevice instances with std::shared_ptr<> to support this. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
74 lines
1.3 KiB
C++
74 lines
1.3 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2018, Google Inc.
|
|
*
|
|
* device_enumerator.h - API to enumerate and find media devices
|
|
*/
|
|
#ifndef __LIBCAMERA_DEVICE_ENUMERATOR_H__
|
|
#define __LIBCAMERA_DEVICE_ENUMERATOR_H__
|
|
|
|
#include <map>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <linux/media.h>
|
|
|
|
namespace libcamera {
|
|
|
|
class MediaDevice;
|
|
|
|
class DeviceMatch
|
|
{
|
|
public:
|
|
DeviceMatch(const std::string &driver);
|
|
|
|
void add(const std::string &entity);
|
|
|
|
bool match(const MediaDevice *device) const;
|
|
|
|
private:
|
|
std::string driver_;
|
|
std::vector<std::string> entities_;
|
|
};
|
|
|
|
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);
|
|
|
|
protected:
|
|
int addDevice(const std::string &deviceNode);
|
|
|
|
private:
|
|
std::vector<std::shared_ptr<MediaDevice>> devices_;
|
|
|
|
virtual std::string lookupDeviceNode(int major, int minor) = 0;
|
|
};
|
|
|
|
class DeviceEnumeratorUdev: public DeviceEnumerator
|
|
{
|
|
public:
|
|
DeviceEnumeratorUdev();
|
|
~DeviceEnumeratorUdev();
|
|
|
|
int init() final;
|
|
int enumerate() final;
|
|
|
|
private:
|
|
struct udev *udev_;
|
|
|
|
std::string lookupDeviceNode(int major, int minor) final;
|
|
};
|
|
|
|
} /* namespace libcamera */
|
|
|
|
#endif /* __LIBCAMERA_DEVICE_ENUMERATOR_H__ */
|