summaryrefslogtreecommitdiff
path: root/src/android/camera_device.cpp
diff options
context:
space:
mode:
authorHirokazu Honda <hiroh@chromium.org>2021-03-24 16:07:57 +0900
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-03-25 00:45:27 +0200
commitf101cc6878112d6587692913078f5656372c2e25 (patch)
tree10e4bcc675fcd20de534dbbdbbe83312f88064c6 /src/android/camera_device.cpp
parentdca709c44aeb0d6532edf3000f701f5d988c5116 (diff)
android: CameraDevice: Manage requestTemplates_ with std::unique_ptr
CameraMetadata stored in requestTemplates_ in CameraDevice is not necessary to be a raw pointer. This reduces the manual new/delete code by changing the type to std::unique_ptr. Signed-off-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src/android/camera_device.cpp')
-rw-r--r--src/android/camera_device.cpp22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 8fdcb85a..5fbf6f82 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -338,11 +338,7 @@ CameraDevice::CameraDevice(unsigned int id, std::shared_ptr<Camera> camera)
}
}
-CameraDevice::~CameraDevice()
-{
- for (auto &it : requestTemplates_)
- delete it.second;
-}
+CameraDevice::~CameraDevice() = default;
std::unique_ptr<CameraDevice> CameraDevice::create(unsigned int id,
std::shared_ptr<Camera> cam)
@@ -1358,15 +1354,14 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()
return staticMetadata_->get();
}
-CameraMetadata *CameraDevice::requestTemplatePreview()
+std::unique_ptr<CameraMetadata> CameraDevice::requestTemplatePreview()
{
/*
* \todo Keep this in sync with the actual number of entries.
* Currently: 20 entries, 35 bytes
*/
- CameraMetadata *requestTemplate = new CameraMetadata(21, 36);
+ auto requestTemplate = std::make_unique<CameraMetadata>(21, 36);
if (!requestTemplate->isValid()) {
- delete requestTemplate;
return nullptr;
}
@@ -1454,9 +1449,9 @@ CameraMetadata *CameraDevice::requestTemplatePreview()
return requestTemplate;
}
-CameraMetadata *CameraDevice::requestTemplateVideo()
+std::unique_ptr<CameraMetadata> CameraDevice::requestTemplateVideo()
{
- CameraMetadata *previewTemplate = requestTemplatePreview();
+ std::unique_ptr<CameraMetadata> previewTemplate = requestTemplatePreview();
if (!previewTemplate)
return nullptr;
@@ -1488,7 +1483,7 @@ const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type)
return it->second->get();
/* Use the capture intent matching the requested template type. */
- CameraMetadata *requestTemplate;
+ std::unique_ptr<CameraMetadata> requestTemplate;
uint8_t captureIntent;
switch (type) {
case CAMERA3_TEMPLATE_PREVIEW:
@@ -1521,15 +1516,14 @@ const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type)
if (!requestTemplate || !requestTemplate->isValid()) {
LOG(HAL, Error) << "Failed to construct request template";
- delete requestTemplate;
return nullptr;
}
requestTemplate->updateEntry(ANDROID_CONTROL_CAPTURE_INTENT,
&captureIntent, 1);
- requestTemplates_[type] = requestTemplate;
- return requestTemplate->get();
+ requestTemplates_[type] = std::move(requestTemplate);
+ return requestTemplates_[type]->get();
}
PixelFormat CameraDevice::toPixelFormat(int format) const