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

Adds comments for CameraAppDeviceImpl

Bug: 1023233
Test: None
Change-Id: I7b29be12282a78528a7cb5e17f1cf923eed9afa0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2147398
Commit-Queue: Wei Lee <wtlee@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarShik Chen <shik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759155}
parent 476c6b7c
......@@ -107,16 +107,15 @@ void CameraAppDeviceImpl::ConsumeReprocessOptions(
std::move(consumption_callback).Run(std::move(result_task_queue));
}
void CameraAppDeviceImpl::GetFpsRange(const gfx::Size& resolution,
GetFpsRangeCallback callback) {
base::Optional<gfx::Range> CameraAppDeviceImpl::GetFpsRange(
const gfx::Size& resolution) {
base::AutoLock lock(fps_ranges_lock_);
auto it = resolution_fps_range_map_.find(resolution);
if (it == resolution_fps_range_map_.end()) {
std::move(callback).Run({});
return;
return {};
}
std::move(callback).Run(it->second);
return it->second;
}
cros::mojom::CaptureIntent CameraAppDeviceImpl::GetCaptureIntent() {
......@@ -144,19 +143,6 @@ void CameraAppDeviceImpl::OnShutterDone() {
}
}
void CameraAppDeviceImpl::SetReprocessResult(
SetReprocessOptionCallback callback,
const int32_t status,
media::mojom::BlobPtr blob) {
auto callback_on_mojo_thread = base::BindOnce(
[](const int32_t status, media::mojom::BlobPtr blob,
SetReprocessOptionCallback callback) {
std::move(callback).Run(status, std::move(blob));
},
status, std::move(blob), std::move(callback));
task_runner_->PostTask(FROM_HERE, std::move(callback_on_mojo_thread));
}
void CameraAppDeviceImpl::GetCameraInfo(GetCameraInfoCallback callback) {
DCHECK(camera_info_);
std::move(callback).Run(camera_info_.Clone());
......@@ -294,4 +280,17 @@ void CameraAppDeviceImpl::DisableEeNr(ReprocessTask* task) {
task->extra_metadata.push_back(std::move(nr_entry));
}
void CameraAppDeviceImpl::SetReprocessResult(
SetReprocessOptionCallback callback,
const int32_t status,
media::mojom::BlobPtr blob) {
auto callback_on_mojo_thread = base::BindOnce(
[](const int32_t status, media::mojom::BlobPtr blob,
SetReprocessOptionCallback callback) {
std::move(callback).Run(status, std::move(blob));
},
status, std::move(blob), std::move(callback));
task_runner_->PostTask(FROM_HERE, std::move(callback_on_mojo_thread));
}
} // namespace media
......@@ -42,22 +42,26 @@ constexpr uint32_t kPortraitModeVendorKey = 0x80000000;
constexpr uint32_t kPortraitModeSegmentationResultVendorKey = 0x80000001;
constexpr int32_t kReprocessSuccess = 0;
// Implementation of CameraAppDevice that is used as the ommunication bridge
// between Chrome Camera App (CCA) and the ChromeOS Video Capture Device. By
// using this, we can do more complicated operations on cameras which is not
// supported by Chrome API.
class CAPTURE_EXPORT CameraAppDeviceImpl : public cros::mojom::CameraAppDevice {
public:
struct SizeComparator {
bool operator()(const gfx::Size& size_1, const gfx::Size& size_2) const;
};
using GetFpsRangeCallback =
base::OnceCallback<void(base::Optional<gfx::Range>)>;
using ResolutionFpsRangeMap =
base::flat_map<gfx::Size, gfx::Range, SizeComparator>;
// Retrieve the return code for reprocess |effect| from the |metadata|.
static int GetReprocessReturnCode(
cros::mojom::Effect effect,
const cros::mojom::CameraMetadataPtr* metadata);
// Construct a ReprocessTaskQueue for regular capture with
// |take_photo_callback|.
static ReprocessTaskQueue GetSingleShotReprocessOptions(
media::mojom::ImageCapture::TakePhotoCallback take_photo_callback);
......@@ -65,52 +69,52 @@ class CAPTURE_EXPORT CameraAppDeviceImpl : public cros::mojom::CameraAppDevice {
cros::mojom::CameraInfoPtr camera_info);
~CameraAppDeviceImpl() override;
// Binds the mojo receiver to this implementation.
void BindReceiver(
mojo::PendingReceiver<cros::mojom::CameraAppDevice> receiver);
// Consumes all the pending reprocess tasks if there is any and eventually
// generates a ReprocessTaskQueue which contains:
// 1. A regular capture task with |take_photo_callback|.
// 2. One or more reprocess tasks if there is any.
// And passes the generated ReprocessTaskQueue through |consumption_callback|.
void ConsumeReprocessOptions(
media::mojom::ImageCapture::TakePhotoCallback take_photo_callback,
base::OnceCallback<void(ReprocessTaskQueue)> consumption_callback);
void GetFpsRange(const gfx::Size& resolution, GetFpsRangeCallback callback);
// Retrieves the corresponding fps range given by stream |resolution|.
base::Optional<gfx::Range> GetFpsRange(const gfx::Size& resolution);
// Gets the capture intent which is specified by the app.
cros::mojom::CaptureIntent GetCaptureIntent();
// Delivers the result |metadata| with its |stream_type| to the metadata
// observers.
void OnResultMetadataAvailable(const cros::mojom::CameraMetadataPtr& metadata,
const cros::mojom::StreamType stream_type);
// Notifies the camera event observers that the shutter is finished.
void OnShutterDone();
void SetReprocessResult(SetReprocessOptionCallback callback,
const int32_t status,
media::mojom::BlobPtr blob);
// cros::mojom::CameraAppDevice implementations.
void GetCameraInfo(GetCameraInfoCallback callback) override;
void SetReprocessOption(cros::mojom::Effect effect,
SetReprocessOptionCallback callback) override;
void SetFpsRange(const gfx::Size& resolution,
const gfx::Range& fps_range,
SetFpsRangeCallback callback) override;
void SetCaptureIntent(cros::mojom::CaptureIntent capture_intent,
SetCaptureIntentCallback callback) override;
void AddResultMetadataObserver(
mojo::PendingRemote<cros::mojom::ResultMetadataObserver> observer,
cros::mojom::StreamType streamType,
AddResultMetadataObserverCallback callback) override;
void RemoveResultMetadataObserver(
uint32_t id,
RemoveResultMetadataObserverCallback callback) override;
void AddCameraEventObserver(
mojo::PendingRemote<cros::mojom::CameraEventObserver> observer,
AddCameraEventObserverCallback callback) override;
void RemoveCameraEventObserver(
uint32_t id,
RemoveCameraEventObserverCallback callback) override;
......@@ -118,6 +122,10 @@ class CAPTURE_EXPORT CameraAppDeviceImpl : public cros::mojom::CameraAppDevice {
private:
static void DisableEeNr(ReprocessTask* task);
void SetReprocessResult(SetReprocessOptionCallback callback,
const int32_t status,
media::mojom::BlobPtr blob);
std::string device_id_;
mojo::ReceiverSet<cros::mojom::CameraAppDevice> receivers_;
......@@ -126,34 +134,33 @@ class CAPTURE_EXPORT CameraAppDeviceImpl : public cros::mojom::CameraAppDevice {
const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
// The queue will be enqueued and dequeued from different threads.
base::Lock reprocess_tasks_lock_;
base::queue<ReprocessTask> reprocess_task_queue_
GUARDED_BY(reprocess_tasks_lock_);
base::queue<ReprocessTask> reprocess_task_queue_;
// The map will be inserted and read from different threads.
base::Lock fps_ranges_lock_;
ResolutionFpsRangeMap resolution_fps_range_map_ GUARDED_BY(fps_ranges_lock_);
ResolutionFpsRangeMap resolution_fps_range_map_;
// It will be modified and read from different threads.
base::Lock capture_intent_lock_;
cros::mojom::CaptureIntent capture_intent_ GUARDED_BY(capture_intent_lock_);
cros::mojom::CaptureIntent capture_intent_;
// Those maps will be changed and used from different threads.
base::Lock metadata_observers_lock_;
base::Lock camera_event_observers_lock_;
uint32_t next_metadata_observer_id_;
uint32_t next_camera_event_observer_id_;
uint32_t next_metadata_observer_id_ GUARDED_BY(metadata_observers_lock_);
base::flat_map<uint32_t, mojo::Remote<cros::mojom::ResultMetadataObserver>>
metadata_observers_;
metadata_observers_ GUARDED_BY(metadata_observers_lock_);
base::flat_map<cros::mojom::StreamType, base::flat_set<uint32_t>>
stream_metadata_observer_ids_;
stream_metadata_observer_ids_ GUARDED_BY(metadata_observers_lock_);
// Those maps will be changed and used from different threads.
base::Lock camera_event_observers_lock_;
uint32_t next_camera_event_observer_id_
GUARDED_BY(camera_event_observers_lock_);
base::flat_map<uint32_t, mojo::Remote<cros::mojom::CameraEventObserver>>
camera_event_observers_;
camera_event_observers_ GUARDED_BY(camera_event_observers_lock_);
std::unique_ptr<base::WeakPtrFactory<CameraAppDeviceImpl>> weak_ptr_factory_;
......
......@@ -875,11 +875,9 @@ void CameraDeviceDelegate::OnConstructedDefaultPreviewRequestSettings(
}
if (camera_app_device_) {
camera_app_device_->GetFpsRange(
chrome_capture_params_.requested_format.frame_size,
media::BindToCurrentLoop(
base::BindOnce(&CameraDeviceDelegate::OnGotFpsRange, GetWeakPtr(),
std::move(settings))));
OnGotFpsRange(std::move(settings),
camera_app_device_->GetFpsRange(
chrome_capture_params_.requested_format.frame_size));
} else {
OnGotFpsRange(std::move(settings), {});
}
......
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