summaryrefslogtreecommitdiff
path: root/chromium/media/capture/video/chromeos/request_manager.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2021-05-20 09:47:09 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2021-06-07 11:15:42 +0000
commit189d4fd8fad9e3c776873be51938cd31a42b6177 (patch)
tree6497caeff5e383937996768766ab3bb2081a40b2 /chromium/media/capture/video/chromeos/request_manager.cc
parent8bc75099d364490b22f43a7ce366b366c08f4164 (diff)
downloadqtwebengine-chromium-189d4fd8fad9e3c776873be51938cd31a42b6177.tar.gz
BASELINE: Update Chromium to 90.0.4430.221
Change-Id: Iff4d9d18d2fcf1a576f3b1f453010f744a232920 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/media/capture/video/chromeos/request_manager.cc')
-rw-r--r--chromium/media/capture/video/chromeos/request_manager.cc133
1 files changed, 91 insertions, 42 deletions
diff --git a/chromium/media/capture/video/chromeos/request_manager.cc b/chromium/media/capture/video/chromeos/request_manager.cc
index 7dedadf09b3..8944ef12a3a 100644
--- a/chromium/media/capture/video/chromeos/request_manager.cc
+++ b/chromium/media/capture/video/chromeos/request_manager.cc
@@ -17,6 +17,7 @@
#include "base/posix/safe_strerror.h"
#include "base/strings/string_number_conversions.h"
#include "base/trace_event/trace_event.h"
+#include "media/capture/video/chromeos/camera_app_device_bridge_impl.h"
#include "media/capture/video/chromeos/camera_buffer_factory.h"
#include "media/capture/video/chromeos/camera_metadata_utils.h"
#include "media/capture/video/chromeos/video_capture_features_chromeos.h"
@@ -34,6 +35,7 @@ constexpr std::initializer_list<StreamType> kYUVReprocessStreams = {
} // namespace
RequestManager::RequestManager(
+ const std::string& device_id,
mojo::PendingReceiver<cros::mojom::Camera3CallbackOps>
callback_ops_receiver,
std::unique_ptr<StreamCaptureInterface> capture_interface,
@@ -41,10 +43,9 @@ RequestManager::RequestManager(
VideoCaptureBufferType buffer_type,
std::unique_ptr<CameraBufferFactory> camera_buffer_factory,
BlobifyCallback blobify_callback,
- scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner,
- CameraAppDeviceImpl* camera_app_device,
- ClientType client_type)
- : callback_ops_(this, std::move(callback_ops_receiver)),
+ scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner)
+ : device_id_(device_id),
+ callback_ops_(this, std::move(callback_ops_receiver)),
capture_interface_(std::move(capture_interface)),
device_context_(device_context),
video_capture_use_gmb_(buffer_type ==
@@ -52,15 +53,12 @@ RequestManager::RequestManager(
stream_buffer_manager_(
new StreamBufferManager(device_context_,
video_capture_use_gmb_,
- std::move(camera_buffer_factory),
- client_type)),
+ std::move(camera_buffer_factory))),
blobify_callback_(std::move(blobify_callback)),
ipc_task_runner_(std::move(ipc_task_runner)),
capturing_(false),
partial_result_count_(1),
- first_frame_shutter_time_(base::TimeTicks()),
- camera_app_device_(std::move(camera_app_device)),
- client_type_(client_type) {
+ first_frame_shutter_time_(base::TimeTicks()) {
DCHECK(ipc_task_runner_->BelongsToCurrentThread());
DCHECK(callback_ops_.is_bound());
DCHECK(device_context_);
@@ -80,9 +78,19 @@ RequestManager::RequestManager(
RequestManager::~RequestManager() = default;
void RequestManager::SetUpStreamsAndBuffers(
- VideoCaptureFormat capture_format,
+ base::flat_map<ClientType, VideoCaptureParams> capture_params,
const cros::mojom::CameraMetadataPtr& static_metadata,
std::vector<cros::mojom::Camera3StreamPtr> streams) {
+ auto request_keys = GetMetadataEntryAsSpan<int32_t>(
+ static_metadata,
+ cros::mojom::CameraMetadataTag::ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS);
+ zero_shutter_lag_supported_ = base::Contains(
+ request_keys,
+ static_cast<int32_t>(
+ cros::mojom::CameraMetadataTag::ANDROID_CONTROL_ENABLE_ZSL));
+ VLOG(1) << "Zero-shutter lag is "
+ << (zero_shutter_lag_supported_ ? "" : "not ") << "supported";
+
// The partial result count metadata is optional; defaults to 1 in case it
// is not set in the static metadata.
const cros::mojom::CameraMetadataEntryPtr* partial_count = GetMetadataEntry(
@@ -107,7 +115,7 @@ void RequestManager::SetUpStreamsAndBuffers(
}
stream_buffer_manager_->SetUpStreamsAndBuffers(
- capture_format, static_metadata, std::move(streams));
+ capture_params, static_metadata, std::move(streams));
}
cros::mojom::Camera3StreamPtr RequestManager::GetStreamConfiguration(
@@ -269,11 +277,13 @@ void RequestManager::PrepareCaptureRequest() {
// 2. Capture (YuvOutput)
// 3. Preview + Capture (YuvOutput)
// 4. Reprocess (YuvInput + BlobOutput)
+ // 5. Preview + Recording (YuvOutput)
//
// For device without reprocess capability:
// 1. Preview
// 2. Capture (BlobOutput)
// 3. Preview + Capture (BlobOutput)
+ // 4. Preview + Recording (YuvOutput)
std::set<StreamType> stream_types;
cros::mojom::CameraMetadataPtr settings;
TakePhotoCallback callback = base::NullCallback();
@@ -283,6 +293,7 @@ void RequestManager::PrepareCaptureRequest() {
bool is_reprocess_request = false;
bool is_preview_request = false;
bool is_oneshot_request = false;
+ bool is_recording_request = false;
// First, check if there are pending reprocess tasks.
is_reprocess_request = TryPrepareReprocessRequest(
@@ -291,16 +302,32 @@ void RequestManager::PrepareCaptureRequest() {
// If there is no pending reprocess task, then check if there are pending
// one-shot requests. And also try to put preview in the request.
if (!is_reprocess_request) {
- is_preview_request = TryPreparePreviewRequest(&stream_types, &settings);
+ if (!zero_shutter_lag_supported_) {
+ is_preview_request = TryPreparePreviewRequest(&stream_types, &settings);
+
+ // Order matters here. If the preview request and oneshot request are both
+ // added in single capture request, the settings will be overridden by the
+ // later.
+ is_oneshot_request =
+ TryPrepareOneShotRequest(&stream_types, &settings, &callback);
+ } else {
+ // Zero-shutter lag could potentially give a frame from the past. Don't
+ // prepare a preview request when a one shot request has been prepared.
+ is_oneshot_request =
+ TryPrepareOneShotRequest(&stream_types, &settings, &callback);
+
+ if (!is_oneshot_request) {
+ is_preview_request = TryPreparePreviewRequest(&stream_types, &settings);
+ }
+ }
+ }
- // Order matters here. If the preview request and oneshot request are both
- // added in single capture request, the settings will be overridden by the
- // later.
- is_oneshot_request =
- TryPrepareOneShotRequest(&stream_types, &settings, &callback);
+ if (is_preview_request) {
+ is_recording_request = TryPrepareRecordingRequest(&stream_types);
}
- if (!is_reprocess_request && !is_oneshot_request && !is_preview_request) {
+ if (!is_reprocess_request && !is_oneshot_request && !is_preview_request &&
+ !is_recording_request) {
// We have to keep the pipeline full.
if (preview_buffers_queued_ < pipeline_depth_) {
ipc_task_runner_->PostTask(
@@ -450,6 +477,17 @@ bool RequestManager::TryPrepareOneShotRequest(
return true;
}
+bool RequestManager::TryPrepareRecordingRequest(
+ std::set<StreamType>* stream_types) {
+ if (!stream_buffer_manager_->IsRecordingSupported() ||
+ !stream_buffer_manager_->HasFreeBuffers({StreamType::kRecordingOutput})) {
+ return false;
+ }
+
+ stream_types->insert({StreamType::kRecordingOutput});
+ return true;
+}
+
void RequestManager::OnProcessedCaptureRequest(int32_t result) {
DCHECK(ipc_task_runner_->BelongsToCurrentThread());
@@ -664,8 +702,12 @@ void RequestManager::Notify(cros::mojom::Camera3NotifyMsgPtr message) {
first_frame_shutter_time_ = reference_time;
}
pending_result.timestamp = reference_time - first_frame_shutter_time_;
- if (camera_app_device_ && pending_result.still_capture_callback) {
- camera_app_device_->OnShutterDone();
+
+ auto camera_app_device =
+ CameraAppDeviceBridgeImpl::GetInstance()->GetWeakCameraAppDevice(
+ device_id_);
+ if (camera_app_device && pending_result.still_capture_callback) {
+ camera_app_device->OnShutterDone();
}
TrySubmitPendingBuffers(frame_number);
@@ -759,8 +801,11 @@ void RequestManager::SubmitCaptureResult(
observer->OnResultMetadataAvailable(frame_number, pending_result.metadata);
}
- if (camera_app_device_) {
- camera_app_device_->OnResultMetadataAvailable(
+ auto camera_app_device =
+ CameraAppDeviceBridgeImpl::GetInstance()->GetWeakCameraAppDevice(
+ device_id_);
+ if (camera_app_device) {
+ camera_app_device->OnResultMetadataAvailable(
pending_result.metadata,
static_cast<cros::mojom::StreamType>(stream_type));
}
@@ -790,8 +835,10 @@ void RequestManager::SubmitCaptureResult(
// Deliver the captured data to client.
if (stream_buffer->status ==
cros::mojom::Camera3BufferStatus::CAMERA3_BUFFER_STATUS_OK) {
- if (stream_type == StreamType::kPreviewOutput) {
- SubmitCapturedPreviewBuffer(frame_number, buffer_ipc_id);
+ if (stream_type == StreamType::kPreviewOutput ||
+ stream_type == StreamType::kRecordingOutput) {
+ SubmitCapturedPreviewRecordingBuffer(frame_number, buffer_ipc_id,
+ stream_type);
} else if (stream_type == StreamType::kJpegOutput) {
SubmitCapturedJpegBuffer(frame_number, buffer_ipc_id);
} else if (stream_type == StreamType::kYUVOutput) {
@@ -827,14 +874,17 @@ void RequestManager::SubmitCaptureResult(
PrepareCaptureRequest();
}
-void RequestManager::SubmitCapturedPreviewBuffer(uint32_t frame_number,
- uint64_t buffer_ipc_id) {
+void RequestManager::SubmitCapturedPreviewRecordingBuffer(
+ uint32_t frame_number,
+ uint64_t buffer_ipc_id,
+ StreamType stream_type) {
const CaptureResult& pending_result = pending_results_[frame_number];
+ auto client_type = kStreamClientTypeMap[static_cast<int>(stream_type)];
if (video_capture_use_gmb_) {
VideoCaptureFormat format;
base::Optional<VideoCaptureDevice::Client::Buffer> buffer =
stream_buffer_manager_->AcquireBufferForClientById(
- StreamType::kPreviewOutput, buffer_ipc_id, &format);
+ stream_type, buffer_ipc_id, &format);
CHECK(buffer);
// TODO: Figure out the right color space for the camera frame. We may need
@@ -849,39 +899,38 @@ void RequestManager::SubmitCapturedPreviewBuffer(uint32_t frame_number,
auto translate_rotation = [](const int rotation) -> VideoRotation {
switch (rotation) {
case 0:
- return VideoRotation::VIDEO_ROTATION_0;
+ return VIDEO_ROTATION_0;
case 90:
- return VideoRotation::VIDEO_ROTATION_90;
+ return VIDEO_ROTATION_90;
case 180:
- return VideoRotation::VIDEO_ROTATION_180;
+ return VIDEO_ROTATION_180;
case 270:
- return VideoRotation::VIDEO_ROTATION_270;
+ return VIDEO_ROTATION_270;
}
- return VideoRotation::VIDEO_ROTATION_0;
+ return VIDEO_ROTATION_0;
};
- metadata.rotation =
+ metadata.transformation =
translate_rotation(device_context_->GetRotationForDisplay());
} else {
// All frames are pre-rotated to the display orientation.
- metadata.rotation = VideoRotation::VIDEO_ROTATION_0;
+ metadata.transformation = VIDEO_ROTATION_0;
}
device_context_->SubmitCapturedVideoCaptureBuffer(
- client_type_, std::move(*buffer), format, pending_result.reference_time,
+ client_type, std::move(*buffer), format, pending_result.reference_time,
pending_result.timestamp, metadata);
// |buffer| ownership is transferred to client, so we need to reserve a
// new video buffer.
- stream_buffer_manager_->ReserveBuffer(StreamType::kPreviewOutput);
+ stream_buffer_manager_->ReserveBuffer(stream_type);
} else {
gfx::GpuMemoryBuffer* gmb = stream_buffer_manager_->GetGpuMemoryBufferById(
- StreamType::kPreviewOutput, buffer_ipc_id);
+ stream_type, buffer_ipc_id);
CHECK(gmb);
device_context_->SubmitCapturedGpuMemoryBuffer(
- client_type_, gmb,
- stream_buffer_manager_->GetStreamCaptureFormat(
- StreamType::kPreviewOutput),
+ client_type, gmb,
+ stream_buffer_manager_->GetStreamCaptureFormat(stream_type),
pending_result.reference_time, pending_result.timestamp);
- stream_buffer_manager_->ReleaseBufferFromCaptureResult(
- StreamType::kPreviewOutput, buffer_ipc_id);
+ stream_buffer_manager_->ReleaseBufferFromCaptureResult(stream_type,
+ buffer_ipc_id);
}
}