libcamera: converter: Utilise shared MediaDevice pointers
With the upcoming addition of V4L2 requests support, the converters need to keep a handle to the corresponding media device. Prepare for that by changing the constructor parameter from a raw pointer to a shared pointer. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>
This commit is contained in:
@@ -46,7 +46,7 @@ public:
|
||||
Up,
|
||||
};
|
||||
|
||||
Converter(MediaDevice *media, Features features = Feature::None);
|
||||
Converter(std::shared_ptr<MediaDevice> media, Features features = Feature::None);
|
||||
virtual ~Converter();
|
||||
|
||||
virtual int loadConfiguration(const std::string &filename) = 0;
|
||||
@@ -107,7 +107,7 @@ public:
|
||||
|
||||
const std::vector<std::string> &compatibles() const { return compatibles_; }
|
||||
|
||||
static std::unique_ptr<Converter> create(MediaDevice *media);
|
||||
static std::unique_ptr<Converter> create(std::shared_ptr<MediaDevice> media);
|
||||
static std::vector<ConverterFactoryBase *> &factories();
|
||||
static std::vector<std::string> names();
|
||||
|
||||
@@ -116,7 +116,8 @@ private:
|
||||
|
||||
static void registerType(ConverterFactoryBase *factory);
|
||||
|
||||
virtual std::unique_ptr<Converter> createInstance(MediaDevice *media) const = 0;
|
||||
virtual std::unique_ptr<Converter>
|
||||
createInstance(std::shared_ptr<MediaDevice> media) const = 0;
|
||||
|
||||
std::string name_;
|
||||
std::vector<std::string> compatibles_;
|
||||
@@ -131,7 +132,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<Converter> createInstance(MediaDevice *media) const override
|
||||
std::unique_ptr<Converter> createInstance(std::shared_ptr<MediaDevice> media) const override
|
||||
{
|
||||
return std::make_unique<_Converter>(media);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ class V4L2M2MDevice;
|
||||
class V4L2M2MConverter : public Converter
|
||||
{
|
||||
public:
|
||||
V4L2M2MConverter(MediaDevice *media);
|
||||
V4L2M2MConverter(std::shared_ptr<MediaDevice> media);
|
||||
|
||||
int loadConfiguration([[maybe_unused]] const std::string &filename) override { return 0; }
|
||||
bool isValid() const override { return m2m_ != nullptr; }
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "libcamera/internal/converter.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
|
||||
#include <libcamera/base/log.h>
|
||||
|
||||
@@ -68,7 +69,7 @@ LOG_DEFINE_CATEGORY(Converter)
|
||||
* This searches for the entity implementing the data streaming function in the
|
||||
* media graph entities and use its device node as the converter device node.
|
||||
*/
|
||||
Converter::Converter(MediaDevice *media, Features features)
|
||||
Converter::Converter(std::shared_ptr<MediaDevice> media, Features features)
|
||||
{
|
||||
const std::vector<MediaEntity *> &entities = media->entities();
|
||||
auto it = std::find_if(entities.begin(), entities.end(),
|
||||
@@ -332,7 +333,7 @@ ConverterFactoryBase::ConverterFactoryBase(const std::string name, std::initiali
|
||||
* \return A new instance of the converter subclass corresponding to the media
|
||||
* device, or null if the media device driver name doesn't match anything
|
||||
*/
|
||||
std::unique_ptr<Converter> ConverterFactoryBase::create(MediaDevice *media)
|
||||
std::unique_ptr<Converter> ConverterFactoryBase::create(std::shared_ptr<MediaDevice> media)
|
||||
{
|
||||
const std::vector<ConverterFactoryBase *> &factories =
|
||||
ConverterFactoryBase::factories();
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits.h>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
#include <libcamera/base/log.h>
|
||||
@@ -261,8 +262,7 @@ void V4L2M2MConverter::V4L2M2MStream::captureBufferReady(FrameBuffer *buffer)
|
||||
* \brief Construct a V4L2M2MConverter instance
|
||||
* \param[in] media The media device implementing the converter
|
||||
*/
|
||||
|
||||
V4L2M2MConverter::V4L2M2MConverter(MediaDevice *media)
|
||||
V4L2M2MConverter::V4L2M2MConverter(std::shared_ptr<MediaDevice> media)
|
||||
: Converter(media)
|
||||
{
|
||||
if (deviceNode().empty())
|
||||
|
||||
@@ -1445,7 +1445,7 @@ bool PipelineHandlerRkISP1::match(DeviceEnumerator *enumerator)
|
||||
|
||||
std::shared_ptr<MediaDevice> dwpMediaDevice = enumerator->search(dwp);
|
||||
if (dwpMediaDevice) {
|
||||
dewarper_ = std::make_unique<V4L2M2MConverter>(dwpMediaDevice.get());
|
||||
dewarper_ = std::make_unique<V4L2M2MConverter>(dwpMediaDevice);
|
||||
if (dewarper_->isValid()) {
|
||||
dewarper_->outputBufferReady.connect(
|
||||
this, &PipelineHandlerRkISP1::dewarpBufferReady);
|
||||
|
||||
@@ -415,7 +415,7 @@ public:
|
||||
|
||||
V4L2VideoDevice *video(const MediaEntity *entity);
|
||||
V4L2Subdevice *subdev(const MediaEntity *entity);
|
||||
MediaDevice *converter() { return converter_.get(); }
|
||||
std::shared_ptr<MediaDevice> converter() { return converter_; }
|
||||
bool swIspEnabled() const { return swIspEnabled_; }
|
||||
|
||||
protected:
|
||||
@@ -588,7 +588,7 @@ int SimpleCameraData::init()
|
||||
int ret;
|
||||
|
||||
/* Open the converter, if any. */
|
||||
MediaDevice *converter = pipe->converter();
|
||||
std::shared_ptr<MediaDevice> converter = pipe->converter();
|
||||
if (converter) {
|
||||
converter_ = ConverterFactoryBase::create(converter);
|
||||
if (!converter_) {
|
||||
|
||||
Reference in New Issue
Block a user