summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJacopo Mondi <jacopo@jmondi.org>2019-09-04 16:18:23 +0200
committerJacopo Mondi <jacopo@jmondi.org>2019-09-05 23:27:36 +0200
commitfcd5a4f335530605a94eb4d3e6e807ec5e5824f9 (patch)
treecb1c9fa242cc1394310eacc2c3f09b705afffa88 /src
parent3986009cf14d94e2312a31d799c2e5d45d30a5b9 (diff)
android: camera_device: Fix handling of request template
According to the Android camera HALv3 documentation, the request template metadata pack should not be modified after it is returned to the camera stack from the HAL. Currently, the same metadata pack is used for all types of template request, without updating the capture intent there contained to match the requested template type, as correctly reported by the cros_camera_test test application. In order to avoid modifying the single request template already returned to the camera stack in order to update the capture intent it contains, create a map that associates a dedicated template to each supported capture type. Signed-off-by: Jacopo Mondi <jacopo@jmondi.org> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r--src/android/camera_device.cpp82
-rw-r--r--src/android/camera_device.h2
2 files changed, 40 insertions, 44 deletions
diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index e2bec84a..94398153 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -50,8 +50,7 @@ CameraDevice::Camera3RequestDescriptor::~Camera3RequestDescriptor()
*/
CameraDevice::CameraDevice(unsigned int id, const std::shared_ptr<Camera> &camera)
- : running_(false), camera_(camera), staticMetadata_(nullptr),
- requestTemplate_(nullptr)
+ : running_(false), camera_(camera), staticMetadata_(nullptr)
{
camera_->requestCompleted.connect(this, &CameraDevice::requestComplete);
}
@@ -61,8 +60,8 @@ CameraDevice::~CameraDevice()
if (staticMetadata_)
delete staticMetadata_;
- if (requestTemplate_)
- delete requestTemplate_;
+ for (auto &it : requestTemplates_)
+ delete it.second;
}
/*
@@ -441,10 +440,11 @@ camera_metadata_t *CameraDevice::getStaticMetadata()
*/
const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type)
{
- /*
- * \todo Inspect type and pick the right metadata pack.
- * As of now just use a single one for all templates.
- */
+ auto it = requestTemplates_.find(type);
+ if (it != requestTemplates_.end())
+ return it->second->get();
+
+ /* Use the capture intent matching the requested template type. */
uint8_t captureIntent;
switch (type) {
case CAMERA3_TEMPLATE_PREVIEW:
@@ -470,76 +470,72 @@ const camera_metadata_t *CameraDevice::constructDefaultRequestSettings(int type)
return nullptr;
}
- if (requestTemplate_)
- return requestTemplate_->get();
-
/*
* \todo Keep this in sync with the actual number of entries.
* Currently: 12 entries, 15 bytes
*/
- requestTemplate_ = new CameraMetadata(15, 20);
- if (!requestTemplate_) {
+ CameraMetadata *requestTemplate = new CameraMetadata(15, 20);
+ if (!requestTemplate->isValid()) {
LOG(HAL, Error) << "Failed to allocate template metadata";
- delete requestTemplate_;
- requestTemplate_ = nullptr;
+ delete requestTemplate;
return nullptr;
}
uint8_t aeMode = ANDROID_CONTROL_AE_MODE_ON;
- requestTemplate_->addEntry(ANDROID_CONTROL_AE_MODE,
- &aeMode, 1);
+ requestTemplate->addEntry(ANDROID_CONTROL_AE_MODE,
+ &aeMode, 1);
int32_t aeExposureCompensation = 0;
- requestTemplate_->addEntry(ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION,
- &aeExposureCompensation, 1);
+ requestTemplate->addEntry(ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION,
+ &aeExposureCompensation, 1);
uint8_t aePrecaptureTrigger = ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER_IDLE;
- requestTemplate_->addEntry(ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER,
- &aePrecaptureTrigger, 1);
+ requestTemplate->addEntry(ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER,
+ &aePrecaptureTrigger, 1);
uint8_t aeLock = ANDROID_CONTROL_AE_LOCK_OFF;
- requestTemplate_->addEntry(ANDROID_CONTROL_AE_LOCK,
- &aeLock, 1);
+ requestTemplate->addEntry(ANDROID_CONTROL_AE_LOCK,
+ &aeLock, 1);
uint8_t afTrigger = ANDROID_CONTROL_AF_TRIGGER_IDLE;
- requestTemplate_->addEntry(ANDROID_CONTROL_AF_TRIGGER,
- &afTrigger, 1);
+ requestTemplate->addEntry(ANDROID_CONTROL_AF_TRIGGER,
+ &afTrigger, 1);
uint8_t awbMode = ANDROID_CONTROL_AWB_MODE_AUTO;
- requestTemplate_->addEntry(ANDROID_CONTROL_AWB_MODE,
- &awbMode, 1);
+ requestTemplate->addEntry(ANDROID_CONTROL_AWB_MODE,
+ &awbMode, 1);
uint8_t awbLock = ANDROID_CONTROL_AWB_LOCK_OFF;
- requestTemplate_->addEntry(ANDROID_CONTROL_AWB_LOCK,
- &awbLock, 1);
+ requestTemplate->addEntry(ANDROID_CONTROL_AWB_LOCK,
+ &awbLock, 1);
uint8_t flashMode = ANDROID_FLASH_MODE_OFF;
- requestTemplate_->addEntry(ANDROID_FLASH_MODE,
- &flashMode, 1);
+ requestTemplate->addEntry(ANDROID_FLASH_MODE,
+ &flashMode, 1);
uint8_t faceDetectMode = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF;
- requestTemplate_->addEntry(ANDROID_STATISTICS_FACE_DETECT_MODE,
- &faceDetectMode, 1);
+ requestTemplate->addEntry(ANDROID_STATISTICS_FACE_DETECT_MODE,
+ &faceDetectMode, 1);
uint8_t noiseReduction = ANDROID_NOISE_REDUCTION_MODE_OFF;
- requestTemplate_->addEntry(ANDROID_NOISE_REDUCTION_MODE,
- &noiseReduction, 1);
+ requestTemplate->addEntry(ANDROID_NOISE_REDUCTION_MODE,
+ &noiseReduction, 1);
uint8_t aberrationMode = ANDROID_COLOR_CORRECTION_ABERRATION_MODE_OFF;
- requestTemplate_->addEntry(ANDROID_COLOR_CORRECTION_ABERRATION_MODE,
- &aberrationMode, 1);
+ requestTemplate->addEntry(ANDROID_COLOR_CORRECTION_ABERRATION_MODE,
+ &aberrationMode, 1);
- requestTemplate_->addEntry(ANDROID_CONTROL_CAPTURE_INTENT,
- &captureIntent, 1);
+ requestTemplate->addEntry(ANDROID_CONTROL_CAPTURE_INTENT,
+ &captureIntent, 1);
- if (!requestTemplate_->isValid()) {
+ if (!requestTemplate->isValid()) {
LOG(HAL, Error) << "Failed to construct request template";
- delete requestTemplate_;
- requestTemplate_ = nullptr;
+ delete requestTemplate;
return nullptr;
}
- return requestTemplate_->get();
+ requestTemplates_[type] = requestTemplate;
+ return requestTemplate->get();
}
/*
diff --git a/src/android/camera_device.h b/src/android/camera_device.h
index 65ba877a..d5d136a7 100644
--- a/src/android/camera_device.h
+++ b/src/android/camera_device.h
@@ -61,7 +61,7 @@ private:
std::unique_ptr<libcamera::CameraConfiguration> config_;
CameraMetadata *staticMetadata_;
- CameraMetadata *requestTemplate_;
+ std::map<unsigned int, CameraMetadata *> requestTemplates_;
const camera3_callback_ops_t *callbacks_;
};