Commit c5c1d077 authored by Wei Lee's avatar Wei Lee Committed by Commit Bot

camera: Use queue for pending photo options callbacks

When there are multiple requests for setting photo options callbacks,
pushing the callbacks into a queue instead of storing the latest one only.

Bug: 1142931
Test: https://1142931.glitch.me/?timeout=100
Change-Id: Ia4feac88de5600b696cf05f31fd0cea7c2612223
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2513809Reviewed-by: default avatarShik Chen <shik@chromium.org>
Commit-Queue: Wei Lee <wtlee@chromium.org>
Auto-Submit: Wei Lee <wtlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823937}
parent 984d91ec
...@@ -530,22 +530,27 @@ void CameraDeviceDelegate::SetPhotoOptions( ...@@ -530,22 +530,27 @@ void CameraDeviceDelegate::SetPhotoOptions(
static_cast<int32_t>(settings->width) || static_cast<int32_t>(settings->width) ||
current_blob_resolution_.height() != current_blob_resolution_.height() !=
static_cast<int32_t>(settings->height)); static_cast<int32_t>(settings->height));
if (!request_manager_->HasStreamsConfiguredForTakePhoto() || // If there is callback of SetPhotoOptions(), the streams might being
should_reconfigure_streams) { // reconfigured and we should notify them once the reconfiguration is done.
if (is_resolution_specified) { if (!pending_set_photo_option_callbacks_.empty()) {
gfx::Size new_blob_resolution(static_cast<int32_t>(settings->width), pending_set_photo_option_callbacks_.push(std::move(callback));
static_cast<int32_t>(settings->height)); } else {
request_manager_->StopPreview( if (!request_manager_->HasStreamsConfiguredForTakePhoto() ||
base::BindOnce(&CameraDeviceDelegate::OnFlushed, GetWeakPtr(), should_reconfigure_streams) {
std::move(new_blob_resolution))); 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));
} else { } else {
request_manager_->StopPreview(base::BindOnce( std::move(callback).Run(true);
&CameraDeviceDelegate::OnFlushed, GetWeakPtr(), base::nullopt));
} }
set_photo_option_callback_ = std::move(callback);
} else {
set_photo_option_callback_.Reset();
std::move(callback).Run(true);
} }
result_metadata_frame_number_for_photo_state_ = current_request_frame_number_; result_metadata_frame_number_for_photo_state_ = current_request_frame_number_;
} }
...@@ -1082,8 +1087,9 @@ void CameraDeviceDelegate::OnGotFpsRange( ...@@ -1082,8 +1087,9 @@ void CameraDeviceDelegate::OnGotFpsRange(
TakePhotoImpl(); TakePhotoImpl();
} }
if (set_photo_option_callback_) { while (!pending_set_photo_option_callbacks_.empty()) {
std::move(set_photo_option_callback_).Run(true); std::move(pending_set_photo_option_callbacks_.front()).Run(true);
pending_set_photo_option_callbacks_.pop();
} }
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_DEVICE_DELEGATE_H_ #define MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_DEVICE_DELEGATE_H_
#include <memory> #include <memory>
#include <queue>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
...@@ -238,7 +239,8 @@ class CAPTURE_EXPORT CameraDeviceDelegate final ...@@ -238,7 +239,8 @@ class CAPTURE_EXPORT CameraDeviceDelegate final
base::OnceClosure device_close_callback_; base::OnceClosure device_close_callback_;
VideoCaptureDevice::SetPhotoOptionsCallback set_photo_option_callback_; std::queue<VideoCaptureDevice::SetPhotoOptionsCallback>
pending_set_photo_option_callbacks_;
CameraAppDeviceImpl* camera_app_device_; // Weak. 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