Commit 9afc45a6 authored by Moja Hsu's avatar Moja Hsu Committed by Chromium LUCI CQ

camera: Support exposure compensation control

This CL adds exposureCompensation MediaTrackCapabilities.

Bug: b:151048287
Test: Tested on kukui.
Change-Id: I3e80d4d953d32f2fe123d02df1383206c964a1e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2392190
Commit-Queue: Hsu Wei-Cheng <mojahsu@chromium.org>
Reviewed-by: default avatarWei Lee <wtlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839094}
parent 02eb7e26
...@@ -292,6 +292,7 @@ void CameraDeviceDelegate::AllocateAndStart( ...@@ -292,6 +292,7 @@ void CameraDeviceDelegate::AllocateAndStart(
is_set_awb_mode_ = false; is_set_awb_mode_ = false;
is_set_brightness_ = false; is_set_brightness_ = false;
is_set_contrast_ = false; is_set_contrast_ = false;
is_set_exposure_compensation_ = false;
is_set_exposure_time_ = false; is_set_exposure_time_ = false;
is_set_focus_distance_ = false; is_set_focus_distance_ = false;
is_set_iso_ = false; is_set_iso_ = false;
...@@ -557,6 +558,22 @@ void CameraDeviceDelegate::SetPhotoOptions( ...@@ -557,6 +558,22 @@ void CameraDeviceDelegate::SetPhotoOptions(
is_set_iso_ = false; is_set_iso_ = false;
} }
if (settings->has_exposure_compensation) {
int metadata_exposure_compensation =
std::round(settings->exposure_compensation / ae_compensation_step_);
request_manager_->SetRepeatingCaptureMetadata(
cros::mojom::CameraMetadataTag::
ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION,
cros::mojom::EntryType::TYPE_INT32, 1,
to_uint8_vector(metadata_exposure_compensation));
is_set_exposure_compensation_ = true;
} else if (is_set_exposure_compensation_) {
request_manager_->UnsetRepeatingCaptureMetadata(
cros::mojom::CameraMetadataTag::
ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION);
is_set_exposure_compensation_ = false;
}
// If there is callback of SetPhotoOptions(), the streams might being // If there is callback of SetPhotoOptions(), the streams might being
// reconfigured and we should notify them once the reconfiguration is done. // reconfigured and we should notify them once the reconfiguration is done.
auto on_reconfigured_callback = base::BindOnce( auto on_reconfigured_callback = base::BindOnce(
...@@ -1354,6 +1371,13 @@ void CameraDeviceDelegate::OnResultMetadataAvailable( ...@@ -1354,6 +1371,13 @@ void CameraDeviceDelegate::OnResultMetadataAvailable(
if (sensitivity.size() == 1) if (sensitivity.size() == 1)
result_metadata_.sensitivity = sensitivity[0]; result_metadata_.sensitivity = sensitivity[0];
result_metadata_.ae_compensation.reset();
auto ae_compensation = GetMetadataEntryAsSpan<int32_t>(
result_metadata,
cros::mojom::CameraMetadataTag::ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION);
if (ae_compensation.size() == 1)
result_metadata_.ae_compensation = ae_compensation[0];
result_metadata_frame_number_ = frame_number; result_metadata_frame_number_ = frame_number;
// We need to wait the new result metadata for new settings. // We need to wait the new result metadata for new settings.
if (result_metadata_frame_number_ > if (result_metadata_frame_number_ >
...@@ -1580,6 +1604,38 @@ void CameraDeviceDelegate::DoGetPhotoState( ...@@ -1580,6 +1604,38 @@ void CameraDeviceDelegate::DoGetPhotoState(
photo_state->iso->current = result_metadata_.sensitivity.value(); photo_state->iso->current = result_metadata_.sensitivity.value();
} }
auto ae_compensation_step = GetMetadataEntryAsSpan<Rational>(
static_metadata_,
cros::mojom::CameraMetadataTag::ANDROID_CONTROL_AE_COMPENSATION_STEP);
ae_compensation_step_ = 0.0;
if (ae_compensation_step.size() == 1) {
if (ae_compensation_step[0].numerator == 0 ||
ae_compensation_step[0].denominator == 0) {
LOG(WARNING) << "AE_COMPENSATION_STEP: numerator:"
<< ae_compensation_step[0].numerator
<< "denominator:" << ae_compensation_step[0].denominator;
} else {
ae_compensation_step_ =
static_cast<float>(ae_compensation_step[0].numerator) /
static_cast<float>(ae_compensation_step[0].denominator);
}
}
auto ae_compensation_range = GetMetadataEntryAsSpan<int32_t>(
static_metadata_,
cros::mojom::CameraMetadataTag::ANDROID_CONTROL_AE_COMPENSATION_RANGE);
if (ae_compensation_step_ != 0.0 && ae_compensation_range.size() == 2) {
photo_state->exposure_compensation->min =
ae_compensation_range[0] * ae_compensation_step_;
photo_state->exposure_compensation->max =
ae_compensation_range[1] * ae_compensation_step_;
photo_state->exposure_compensation->step = ae_compensation_step_;
if (result_metadata_.ae_compensation)
photo_state->exposure_compensation->current =
result_metadata_.ae_compensation.value() * ae_compensation_step_;
else
photo_state->exposure_compensation->current = 0;
}
std::move(callback).Run(std::move(photo_state)); std::move(callback).Run(std::move(photo_state));
} }
......
...@@ -44,6 +44,7 @@ struct ResultMetadata { ...@@ -44,6 +44,7 @@ struct ResultMetadata {
~ResultMetadata(); ~ResultMetadata();
base::Optional<uint8_t> ae_mode; base::Optional<uint8_t> ae_mode;
base::Optional<int32_t> ae_compensation;
base::Optional<uint8_t> af_mode; base::Optional<uint8_t> af_mode;
base::Optional<uint8_t> awb_mode; base::Optional<uint8_t> awb_mode;
base::Optional<int32_t> brightness; base::Optional<int32_t> brightness;
...@@ -255,6 +256,7 @@ class CAPTURE_EXPORT CameraDeviceDelegate final ...@@ -255,6 +256,7 @@ class CAPTURE_EXPORT CameraDeviceDelegate final
bool is_set_awb_mode_; bool is_set_awb_mode_;
bool is_set_brightness_; bool is_set_brightness_;
bool is_set_contrast_; bool is_set_contrast_;
bool is_set_exposure_compensation_;
bool is_set_exposure_time_; bool is_set_exposure_time_;
bool is_set_focus_distance_; bool is_set_focus_distance_;
bool is_set_iso_; bool is_set_iso_;
...@@ -266,6 +268,8 @@ class CAPTURE_EXPORT CameraDeviceDelegate final ...@@ -266,6 +268,8 @@ class CAPTURE_EXPORT CameraDeviceDelegate final
std::vector<base::OnceClosure> get_photo_state_queue_; std::vector<base::OnceClosure> get_photo_state_queue_;
bool use_digital_zoom_; bool use_digital_zoom_;
float ae_compensation_step_;
// We reply GetPhotoState when |result_metadata_frame_number_| > // We reply GetPhotoState when |result_metadata_frame_number_| >
// |result_metadata_frame_number_for_photo_state_|. Otherwise javascript API // |result_metadata_frame_number_for_photo_state_|. Otherwise javascript API
// getSettings() will get non-updated settings. // getSettings() will get non-updated settings.
......
...@@ -35,6 +35,10 @@ template <> ...@@ -35,6 +35,10 @@ template <>
const cros::mojom::EntryType entry_type_of<double>::value = const cros::mojom::EntryType entry_type_of<double>::value =
cros::mojom::EntryType::TYPE_DOUBLE; cros::mojom::EntryType::TYPE_DOUBLE;
template <>
const cros::mojom::EntryType entry_type_of<Rational>::value =
cros::mojom::EntryType::TYPE_RATIONAL;
// TODO(shik): support TYPE_RATIONAL // TODO(shik): support TYPE_RATIONAL
cros::mojom::CameraMetadataEntryPtr* GetMetadataEntry( cros::mojom::CameraMetadataEntryPtr* GetMetadataEntry(
......
...@@ -12,6 +12,11 @@ ...@@ -12,6 +12,11 @@
namespace media { namespace media {
struct Rational {
int32_t numerator;
int32_t denominator;
};
// Helper traits for converting native types to cros::mojom::EntryType. // Helper traits for converting native types to cros::mojom::EntryType.
template <typename T, typename Enable = void> template <typename T, typename Enable = void>
struct entry_type_of { struct entry_type_of {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment