Commit 4f213c25 authored by Wei Lee's avatar Wei Lee Committed by Commit Bot

camera: Only reconfigure photo stream for taking photo scenario

Currently there are two scenarios which will trigger SetPhotoOptions():
1. takePhoto() from ImageCapture API
2. applyConstraints() from MediaStreamTrack object

For (2), we don't need to reconfigure photo stream.

Bug: 1142931
Test: Manually
Change-Id: I2481d6925d2b4d8f3e99b24f9a03a9e1721c99c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2517232
Commit-Queue: Wei Lee <wtlee@chromium.org>
Reviewed-by: default avatarShik Chen <shik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823947}
parent 38b73d72
......@@ -523,33 +523,20 @@ void CameraDeviceDelegate::SetPhotoOptions(
is_set_exposure_time_ = false;
}
bool is_resolution_specified = settings->has_width && settings->has_height;
bool should_reconfigure_streams =
is_resolution_specified && (current_blob_resolution_.IsEmpty() ||
current_blob_resolution_.width() !=
static_cast<int32_t>(settings->width) ||
current_blob_resolution_.height() !=
static_cast<int32_t>(settings->height));
// If there is callback of SetPhotoOptions(), the streams might being
// reconfigured and we should notify them once the reconfiguration is done.
if (!pending_set_photo_option_callbacks_.empty()) {
pending_set_photo_option_callbacks_.push(std::move(callback));
auto on_reconfigured_callback = base::BindOnce(
[](VideoCaptureDevice::SetPhotoOptionsCallback callback) {
std::move(callback).Run(true);
},
std::move(callback));
if (!on_reconfigured_callbacks_.empty()) {
on_reconfigured_callbacks_.push(std::move(on_reconfigured_callback));
} else {
if (!request_manager_->HasStreamsConfiguredForTakePhoto() ||
should_reconfigure_streams) {
if (is_resolution_specified) {
gfx::Size new_blob_resolution(static_cast<int32_t>(settings->width),
static_cast<int32_t>(settings->height));
request_manager_->StopPreview(
base::BindOnce(&CameraDeviceDelegate::OnFlushed, GetWeakPtr(),
std::move(new_blob_resolution)));
} else {
request_manager_->StopPreview(base::BindOnce(
&CameraDeviceDelegate::OnFlushed, GetWeakPtr(), base::nullopt));
}
pending_set_photo_option_callbacks_.push(std::move(callback));
if (MaybeReconfigureForPhotoStream(std::move(settings))) {
on_reconfigured_callbacks_.push(std::move(on_reconfigured_callback));
} else {
std::move(callback).Run(true);
std::move(on_reconfigured_callback).Run();
}
}
result_metadata_frame_number_for_photo_state_ = current_request_frame_number_;
......@@ -565,6 +552,32 @@ base::WeakPtr<CameraDeviceDelegate> CameraDeviceDelegate::GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
bool CameraDeviceDelegate::MaybeReconfigureForPhotoStream(
mojom::PhotoSettingsPtr settings) {
bool is_resolution_specified = settings->has_width && settings->has_height;
bool should_reconfigure_streams =
(is_resolution_specified && (current_blob_resolution_.IsEmpty() ||
current_blob_resolution_.width() !=
static_cast<int32_t>(settings->width) ||
current_blob_resolution_.height() !=
static_cast<int32_t>(settings->height)));
if (!should_reconfigure_streams) {
return false;
}
if (is_resolution_specified) {
gfx::Size new_blob_resolution(static_cast<int32_t>(settings->width),
static_cast<int32_t>(settings->height));
request_manager_->StopPreview(
base::BindOnce(&CameraDeviceDelegate::OnFlushed, GetWeakPtr(),
std::move(new_blob_resolution)));
} else {
request_manager_->StopPreview(base::BindOnce(
&CameraDeviceDelegate::OnFlushed, GetWeakPtr(), base::nullopt));
}
return true;
}
void CameraDeviceDelegate::TakePhotoImpl() {
DCHECK(ipc_task_runner_->BelongsToCurrentThread());
......@@ -578,15 +591,18 @@ void CameraDeviceDelegate::TakePhotoImpl() {
return;
}
SetPhotoOptions(
mojom::PhotoSettings::New(),
base::BindOnce(
[](base::WeakPtr<Camera3AController> controller,
base::OnceClosure callback, bool result) {
controller->Stabilize3AForStillCapture(std::move(callback));
},
camera_3a_controller_->GetWeakPtr(),
std::move(construct_request_cb)));
// Trigger the reconfigure process if it not yet triggered.
if (on_reconfigured_callbacks_.empty()) {
request_manager_->StopPreview(base::BindOnce(
&CameraDeviceDelegate::OnFlushed, GetWeakPtr(), base::nullopt));
}
auto on_reconfigured_callback = base::BindOnce(
[](base::WeakPtr<Camera3AController> controller,
base::OnceClosure callback) {
controller->Stabilize3AForStillCapture(std::move(callback));
},
camera_3a_controller_->GetWeakPtr(), std::move(construct_request_cb));
on_reconfigured_callbacks_.push(std::move(on_reconfigured_callback));
}
void CameraDeviceDelegate::OnMojoConnectionError() {
......@@ -1087,9 +1103,9 @@ void CameraDeviceDelegate::OnGotFpsRange(
TakePhotoImpl();
}
while (!pending_set_photo_option_callbacks_.empty()) {
std::move(pending_set_photo_option_callbacks_.front()).Run(true);
pending_set_photo_option_callbacks_.pop();
while (!on_reconfigured_callbacks_.empty()) {
std::move(on_reconfigured_callbacks_.front()).Run();
on_reconfigured_callbacks_.pop();
}
}
......
......@@ -124,6 +124,10 @@ class CAPTURE_EXPORT CameraDeviceDelegate final
friend class CameraDeviceDelegateTest;
// Reconfigures the streams to include photo stream according to |settings|.
// Returns true if the reconfigure process is triggered.
bool MaybeReconfigureForPhotoStream(mojom::PhotoSettingsPtr settings);
void TakePhotoImpl();
// Mojo connection error handler.
......@@ -239,8 +243,7 @@ class CAPTURE_EXPORT CameraDeviceDelegate final
base::OnceClosure device_close_callback_;
std::queue<VideoCaptureDevice::SetPhotoOptionsCallback>
pending_set_photo_option_callbacks_;
std::queue<base::OnceClosure> on_reconfigured_callbacks_;
CameraAppDeviceImpl* camera_app_device_; // Weak.
......
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