summaryrefslogtreecommitdiff
path: root/src/android
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-06-15 03:11:30 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2021-06-28 07:02:44 +0300
commit7532caa2c77b966afde643d5550dff6e404e7208 (patch)
treee0b72c4573faeb6a50d0284d9a4988f2379af61a /src/android
parentc11cc6f20b4f701afaa24416be2b711e2415d79d (diff)
android: camera_device: Reset config_ if Camera::configure() fails
The config_ pointer is reset in all error paths of the CameraDevice::configureStreams() function, except when Camera::configure() fails. Fix it by using a local unique pointer to store the configuration until the end of the function, to avoid similar issues in the future. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Hirokazu Honda <hiroh@chromium.org> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Diffstat (limited to 'src/android')
-rw-r--r--src/android/camera_device.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp
index 86ea22b6..407db507 100644
--- a/src/android/camera_device.cpp
+++ b/src/android/camera_device.cpp
@@ -581,8 +581,8 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
* Generate an empty configuration, and construct a StreamConfiguration
* for each camera3_stream to add to it.
*/
- config_ = camera_->generateConfiguration();
- if (!config_) {
+ std::unique_ptr<CameraConfiguration> config = camera_->generateConfiguration();
+ if (!config) {
LOG(HAL, Error) << "Failed to generate camera configuration";
return -EINVAL;
}
@@ -720,29 +720,27 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
sortCamera3StreamConfigs(streamConfigs, jpegStream);
for (const auto &streamConfig : streamConfigs) {
- config_->addConfiguration(streamConfig.config);
+ config->addConfiguration(streamConfig.config);
for (auto &stream : streamConfig.streams) {
streams_.emplace_back(this, stream.type, stream.stream,
- config_->size() - 1);
+ config->size() - 1);
stream.stream->priv = static_cast<void *>(&streams_.back());
}
}
- switch (config_->validate()) {
+ switch (config->validate()) {
case CameraConfiguration::Valid:
break;
case CameraConfiguration::Adjusted:
LOG(HAL, Info) << "Camera configuration adjusted";
- for (const StreamConfiguration &cfg : *config_)
+ for (const StreamConfiguration &cfg : *config)
LOG(HAL, Info) << " - " << cfg.toString();
- config_.reset();
return -EINVAL;
case CameraConfiguration::Invalid:
LOG(HAL, Info) << "Camera configuration invalid";
- config_.reset();
return -EINVAL;
}
@@ -750,7 +748,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
* Once the CameraConfiguration has been adjusted/validated
* it can be applied to the camera.
*/
- int ret = camera_->configure(config_.get());
+ int ret = camera_->configure(config.get());
if (ret) {
LOG(HAL, Error) << "Failed to configure camera '"
<< camera_->id() << "'";
@@ -770,6 +768,7 @@ int CameraDevice::configureStreams(camera3_stream_configuration_t *stream_list)
}
}
+ config_ = std::move(config);
return 0;
}