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,6 +530,11 @@ void CameraDeviceDelegate::SetPhotoOptions(
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));
} else {
if (!request_manager_->HasStreamsConfiguredForTakePhoto() ||
should_reconfigure_streams) {
if (is_resolution_specified) {
......@@ -542,11 +547,11 @@ void CameraDeviceDelegate::SetPhotoOptions(
request_manager_->StopPreview(base::BindOnce(
&CameraDeviceDelegate::OnFlushed, GetWeakPtr(), base::nullopt));
}
set_photo_option_callback_ = std::move(callback);
pending_set_photo_option_callbacks_.push(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_;
}
......@@ -1082,8 +1087,9 @@ void CameraDeviceDelegate::OnGotFpsRange(
TakePhotoImpl();
}
if (set_photo_option_callback_) {
std::move(set_photo_option_callback_).Run(true);
while (!pending_set_photo_option_callbacks_.empty()) {
std::move(pending_set_photo_option_callbacks_.front()).Run(true);
pending_set_photo_option_callbacks_.pop();
}
}
......
......@@ -6,6 +6,7 @@
#define MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_DEVICE_DELEGATE_H_
#include <memory>
#include <queue>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
......@@ -238,7 +239,8 @@ class CAPTURE_EXPORT CameraDeviceDelegate final
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.
......
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