cam: camera_session: Use std::unique_ptr<> to manage class members
Store the BufferWriter and FrameBufferAllocator pointers in std::unique_ptr<> instances to simplify memory management and avoid leaks. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
parent
4cd0f586fb
commit
24ca846a27
2 changed files with 9 additions and 11 deletions
|
@ -20,9 +20,8 @@ using namespace libcamera;
|
||||||
|
|
||||||
CameraSession::CameraSession(std::shared_ptr<Camera> camera,
|
CameraSession::CameraSession(std::shared_ptr<Camera> camera,
|
||||||
CameraConfiguration *config)
|
CameraConfiguration *config)
|
||||||
: camera_(camera), config_(config), writer_(nullptr), last_(0),
|
: camera_(camera), config_(config), last_(0), queueCount_(0),
|
||||||
queueCount_(0), captureCount_(0), captureLimit_(0),
|
captureCount_(0), captureLimit_(0), printMetadata_(false)
|
||||||
printMetadata_(false), allocator_(nullptr)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,12 +55,12 @@ int CameraSession::start(const OptionsParser::Options &options)
|
||||||
|
|
||||||
if (options.isSet(OptFile)) {
|
if (options.isSet(OptFile)) {
|
||||||
if (!options[OptFile].toString().empty())
|
if (!options[OptFile].toString().empty())
|
||||||
writer_ = new BufferWriter(options[OptFile]);
|
writer_ = std::make_unique<BufferWriter>(options[OptFile]);
|
||||||
else
|
else
|
||||||
writer_ = new BufferWriter();
|
writer_ = std::make_unique<BufferWriter>();
|
||||||
}
|
}
|
||||||
|
|
||||||
allocator_ = new FrameBufferAllocator(camera_);
|
allocator_ = std::make_unique<FrameBufferAllocator>(camera_);
|
||||||
|
|
||||||
return startCapture();
|
return startCapture();
|
||||||
}
|
}
|
||||||
|
@ -72,12 +71,11 @@ void CameraSession::stop()
|
||||||
if (ret)
|
if (ret)
|
||||||
std::cout << "Failed to stop capture" << std::endl;
|
std::cout << "Failed to stop capture" << std::endl;
|
||||||
|
|
||||||
delete writer_;
|
writer_.reset();
|
||||||
writer_ = nullptr;
|
|
||||||
|
|
||||||
requests_.clear();
|
requests_.clear();
|
||||||
|
|
||||||
delete allocator_;
|
allocator_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CameraSession::startCapture()
|
int CameraSession::startCapture()
|
||||||
|
|
|
@ -44,7 +44,7 @@ private:
|
||||||
libcamera::CameraConfiguration *config_;
|
libcamera::CameraConfiguration *config_;
|
||||||
|
|
||||||
std::map<const libcamera::Stream *, std::string> streamName_;
|
std::map<const libcamera::Stream *, std::string> streamName_;
|
||||||
BufferWriter *writer_;
|
std::unique_ptr<BufferWriter> writer_;
|
||||||
uint64_t last_;
|
uint64_t last_;
|
||||||
|
|
||||||
unsigned int queueCount_;
|
unsigned int queueCount_;
|
||||||
|
@ -52,7 +52,7 @@ private:
|
||||||
unsigned int captureLimit_;
|
unsigned int captureLimit_;
|
||||||
bool printMetadata_;
|
bool printMetadata_;
|
||||||
|
|
||||||
libcamera::FrameBufferAllocator *allocator_;
|
std::unique_ptr<libcamera::FrameBufferAllocator> allocator_;
|
||||||
std::vector<std::unique_ptr<libcamera::Request>> requests_;
|
std::vector<std::unique_ptr<libcamera::Request>> requests_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue