ipa: raspberrypi: Use a unique_ptr for the metadata parser

The derived CamHelper class now allocates a metadata parser object through a
unique_ptr that is passed to the base class constructor. This automates the
lifetime management of the parser object.

Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Naushir Patuck 2021-06-29 11:44:59 +01:00 committed by Laurent Pinchart
parent 9d44551404
commit d3ea8e7885
7 changed files with 11 additions and 11 deletions

View file

@ -40,15 +40,14 @@ CamHelper *CamHelper::Create(std::string const &cam_name)
return nullptr; return nullptr;
} }
CamHelper::CamHelper(MdParser *parser, unsigned int frameIntegrationDiff) CamHelper::CamHelper(std::unique_ptr<MdParser> parser, unsigned int frameIntegrationDiff)
: parser_(parser), initialized_(false), : parser_(std::move(parser)), initialized_(false),
frameIntegrationDiff_(frameIntegrationDiff) frameIntegrationDiff_(frameIntegrationDiff)
{ {
} }
CamHelper::~CamHelper() CamHelper::~CamHelper()
{ {
delete parser_;
} }
void CamHelper::Prepare(Span<const uint8_t> buffer, void CamHelper::Prepare(Span<const uint8_t> buffer,

View file

@ -6,6 +6,7 @@
*/ */
#pragma once #pragma once
#include <memory>
#include <string> #include <string>
#include <libcamera/base/span.h> #include <libcamera/base/span.h>
@ -67,7 +68,7 @@ class CamHelper
{ {
public: public:
static CamHelper *Create(std::string const &cam_name); static CamHelper *Create(std::string const &cam_name);
CamHelper(MdParser *parser, unsigned int frameIntegrationDiff); CamHelper(std::unique_ptr<MdParser> parser, unsigned int frameIntegrationDiff);
virtual ~CamHelper(); virtual ~CamHelper();
void SetCameraMode(const CameraMode &mode); void SetCameraMode(const CameraMode &mode);
virtual void Prepare(libcamera::Span<const uint8_t> buffer, virtual void Prepare(libcamera::Span<const uint8_t> buffer,
@ -92,7 +93,7 @@ protected:
void parseEmbeddedData(libcamera::Span<const uint8_t> buffer, void parseEmbeddedData(libcamera::Span<const uint8_t> buffer,
Metadata &metadata); Metadata &metadata);
MdParser *parser_; std::unique_ptr<MdParser> parser_;
CameraMode mode_; CameraMode mode_;
private: private:

View file

@ -58,9 +58,9 @@ private:
CamHelperImx219::CamHelperImx219() CamHelperImx219::CamHelperImx219()
#if ENABLE_EMBEDDED_DATA #if ENABLE_EMBEDDED_DATA
: CamHelper(new MdParserImx219(), frameIntegrationDiff) : CamHelper(std::make_unique<MdParserImx219>(), frameIntegrationDiff)
#else #else
: CamHelper(nullptr, frameIntegrationDiff) : CamHelper({}, frameIntegrationDiff)
#endif #endif
{ {
} }

View file

@ -30,7 +30,7 @@ private:
}; };
CamHelperImx290::CamHelperImx290() CamHelperImx290::CamHelperImx290()
: CamHelper(nullptr, frameIntegrationDiff) : CamHelper({}, frameIntegrationDiff)
{ {
} }

View file

@ -50,7 +50,7 @@ private:
}; };
CamHelperImx477::CamHelperImx477() CamHelperImx477::CamHelperImx477()
: CamHelper(new MdParserImx477(), frameIntegrationDiff) : CamHelper(std::make_unique<MdParserImx477>(), frameIntegrationDiff)
{ {
} }

View file

@ -38,7 +38,7 @@ private:
*/ */
CamHelperOv5647::CamHelperOv5647() CamHelperOv5647::CamHelperOv5647()
: CamHelper(nullptr, frameIntegrationDiff) : CamHelper({}, frameIntegrationDiff)
{ {
} }

View file

@ -34,7 +34,7 @@ private:
*/ */
CamHelperOv9281::CamHelperOv9281() CamHelperOv9281::CamHelperOv9281()
: CamHelper(nullptr, frameIntegrationDiff) : CamHelper({}, frameIntegrationDiff)
{ {
} }