Commit 6c05239c authored by Heng-Ruey Hsu's avatar Heng-Ruey Hsu Committed by Chromium LUCI CQ

Add video capture device chromeos delegate

Simply rename *_halv3 to *_delegate to keep git history.
Add an intermediate layer to prepare further refactor to support
multiple streams.

Bug: b:151047537
Test: Manually
Change-Id: Ic2db36b003206972aabd70a5ceafd00e9f8f1c3e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2351931
Commit-Queue: Heng-ruey Hsu <henryhsu@chromium.org>
Reviewed-by: default avatarMiguel Casas <mcasas@chromium.org>
Reviewed-by: default avatarWei Lee <wtlee@chromium.org>
Auto-Submit: Heng-ruey Hsu <henryhsu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834638}
parent 8898e9b2
...@@ -310,6 +310,8 @@ component("capture_lib") { ...@@ -310,6 +310,8 @@ component("capture_lib") {
"video/chromeos/token_manager.h", "video/chromeos/token_manager.h",
"video/chromeos/vendor_tag_ops_delegate.cc", "video/chromeos/vendor_tag_ops_delegate.cc",
"video/chromeos/vendor_tag_ops_delegate.h", "video/chromeos/vendor_tag_ops_delegate.h",
"video/chromeos/video_capture_device_chromeos_delegate.cc",
"video/chromeos/video_capture_device_chromeos_delegate.h",
"video/chromeos/video_capture_device_chromeos_halv3.cc", "video/chromeos/video_capture_device_chromeos_halv3.cc",
"video/chromeos/video_capture_device_chromeos_halv3.h", "video/chromeos/video_capture_device_chromeos_halv3.h",
"video/chromeos/video_capture_device_factory_chromeos.cc", "video/chromeos/video_capture_device_factory_chromeos.cc",
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "media/capture/video/chromeos/camera_buffer_factory.h" #include "media/capture/video/chromeos/camera_buffer_factory.h"
#include "media/capture/video/chromeos/camera_hal_dispatcher_impl.h" #include "media/capture/video/chromeos/camera_hal_dispatcher_impl.h"
#include "media/capture/video/chromeos/camera_metadata_utils.h" #include "media/capture/video/chromeos/camera_metadata_utils.h"
#include "media/capture/video/chromeos/video_capture_device_chromeos_delegate.h"
#include "media/capture/video/chromeos/video_capture_device_chromeos_halv3.h" #include "media/capture/video/chromeos/video_capture_device_chromeos_halv3.h"
namespace media { namespace media {
...@@ -205,13 +206,17 @@ std::unique_ptr<VideoCaptureDevice> CameraHalDelegate::CreateDevice( ...@@ -205,13 +206,17 @@ std::unique_ptr<VideoCaptureDevice> CameraHalDelegate::CreateDevice(
bridge->OnDeviceClosed(device_id); bridge->OnDeviceClosed(device_id);
}, },
device_descriptor.device_id, camera_app_device_bridge); device_descriptor.device_id, camera_app_device_bridge);
return std::make_unique<VideoCaptureDeviceChromeOSHalv3>( auto delegate = std::make_unique<VideoCaptureDeviceChromeOSDelegate>(
std::move(task_runner_for_screen_observer), device_descriptor, this, std::move(task_runner_for_screen_observer), device_descriptor, this,
camera_app_device, std::move(cleanup_callback)); camera_app_device, std::move(cleanup_callback));
} else {
return std::make_unique<VideoCaptureDeviceChromeOSHalv3>( return std::make_unique<VideoCaptureDeviceChromeOSHalv3>(
std::move(delegate));
} else {
auto delegate = std::make_unique<VideoCaptureDeviceChromeOSDelegate>(
std::move(task_runner_for_screen_observer), device_descriptor, this, std::move(task_runner_for_screen_observer), device_descriptor, this,
nullptr, base::DoNothing()); nullptr, base::DoNothing());
return std::make_unique<VideoCaptureDeviceChromeOSHalv3>(
std::move(delegate));
} }
} }
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_CAPTURE_VIDEO_CHROMEOS_VIDEO_CAPTURE_DEVICE_CHROMEOS_DELEGATE_H_
#define MEDIA_CAPTURE_VIDEO_CHROMEOS_VIDEO_CAPTURE_DEVICE_CHROMEOS_DELEGATE_H_
#include <memory>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "media/capture/video/chromeos/camera_device_context.h"
#include "media/capture/video/chromeos/display_rotation_observer.h"
#include "media/capture/video/video_capture_device.h"
#include "media/capture/video/video_capture_device_descriptor.h"
#include "media/capture/video_capture_types.h"
namespace display {
class Display;
} // namespace display
namespace media {
class CameraAppDeviceImpl;
class CameraHalDelegate;
class CameraDeviceDelegate;
// Implementation of VideoCaptureDevice for ChromeOS with CrOS camera HALv3.
class CAPTURE_EXPORT VideoCaptureDeviceChromeOSDelegate final
: public VideoCaptureDevice,
public DisplayRotationObserver {
public:
VideoCaptureDeviceChromeOSDelegate(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner,
const VideoCaptureDeviceDescriptor& device_descriptor,
scoped_refptr<CameraHalDelegate> camera_hal_delegate,
CameraAppDeviceImpl* camera_app_device,
base::OnceClosure cleanup_callback);
~VideoCaptureDeviceChromeOSDelegate() final;
// VideoCaptureDevice implementation.
void AllocateAndStart(const VideoCaptureParams& params,
std::unique_ptr<Client> client) final;
void StopAndDeAllocate() final;
void TakePhoto(TakePhotoCallback callback) final;
void GetPhotoState(GetPhotoStateCallback callback) final;
void SetPhotoOptions(mojom::PhotoSettingsPtr settings,
SetPhotoOptionsCallback callback) final;
private:
// Helper to interact with PowerManagerClient on DBus original thread.
class PowerManagerClientProxy;
void OpenDevice();
void CloseDevice(base::UnguessableToken unblock_suspend_token);
// DisplayRotationDelegate implementation.
void SetDisplayRotation(const display::Display& display) final;
void SetRotation(int rotation);
const VideoCaptureDeviceDescriptor device_descriptor_;
// A reference to the CameraHalDelegate instance in the VCD factory. This is
// used by AllocateAndStart to query camera info and create the camera device.
const scoped_refptr<CameraHalDelegate> camera_hal_delegate_;
// A reference to the thread that all the VideoCaptureDevice interface methods
// are expected to be called on.
const scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_;
// The thread that all the Mojo operations of |camera_device_delegate_| take
// place. Started in AllocateAndStart and stopped in StopAndDeAllocate, where
// the access to the base::Thread methods are sequenced on
// |capture_task_runner_|.
base::Thread camera_device_ipc_thread_;
VideoCaptureParams capture_params_;
// |device_context_| is created and owned by
// VideoCaptureDeviceChromeOSDelegate and is only accessed by
// |camera_device_delegate_|.
std::unique_ptr<CameraDeviceContext> device_context_;
// Internal delegate doing the actual capture setting, buffer allocation and
// circulation with the camera HAL. Created in AllocateAndStart and deleted in
// StopAndDeAllocate on |capture_task_runner_|. All methods of
// |camera_device_delegate_| operate on |camera_device_ipc_thread_|.
std::unique_ptr<CameraDeviceDelegate> camera_device_delegate_;
scoped_refptr<ScreenObserverDelegate> screen_observer_delegate_;
const VideoFacingMode lens_facing_;
// Whether the incoming frames should rotate when the device rotates.
const bool rotates_with_device_;
int rotation_;
CameraAppDeviceImpl* camera_app_device_; // Weak.
base::OnceClosure cleanup_callback_;
scoped_refptr<PowerManagerClientProxy> power_manager_client_proxy_;
// The client type in CameraDeviceContext.
ClientType client_type_;
base::WeakPtrFactory<VideoCaptureDeviceChromeOSDelegate> weak_ptr_factory_{
this};
DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceChromeOSDelegate);
};
} // namespace media
#endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_VIDEO_CAPTURE_DEVICE_CHROMEOS_DELEGATE_H_
// Copyright 2017 The Chromium Authors. All rights reserved. // Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -7,39 +7,18 @@ ...@@ -7,39 +7,18 @@
#include <memory> #include <memory>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "media/capture/video/chromeos/camera_device_context.h"
#include "media/capture/video/chromeos/display_rotation_observer.h"
#include "media/capture/video/video_capture_device.h" #include "media/capture/video/video_capture_device.h"
#include "media/capture/video/video_capture_device_descriptor.h"
#include "media/capture/video_capture_types.h"
namespace display {
class Display;
} // namespace display
namespace media { namespace media {
class CameraAppDeviceImpl; class VideoCaptureDeviceChromeOSDelegate;
class CameraHalDelegate;
class CameraDeviceDelegate;
// Implementation of VideoCaptureDevice for ChromeOS with CrOS camera HALv3. // Implementation of VideoCaptureDevice for ChromeOS with CrOS camera HALv3.
class CAPTURE_EXPORT VideoCaptureDeviceChromeOSHalv3 final class CAPTURE_EXPORT VideoCaptureDeviceChromeOSHalv3 final
: public VideoCaptureDevice, : public VideoCaptureDevice {
public DisplayRotationObserver {
public: public:
VideoCaptureDeviceChromeOSHalv3( explicit VideoCaptureDeviceChromeOSHalv3(
scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner, std::unique_ptr<VideoCaptureDeviceChromeOSDelegate> delegate);
const VideoCaptureDeviceDescriptor& device_descriptor,
scoped_refptr<CameraHalDelegate> camera_hal_delegate,
CameraAppDeviceImpl* camera_app_device,
base::OnceClosure cleanup_callback);
~VideoCaptureDeviceChromeOSHalv3() final; ~VideoCaptureDeviceChromeOSHalv3() final;
...@@ -53,59 +32,7 @@ class CAPTURE_EXPORT VideoCaptureDeviceChromeOSHalv3 final ...@@ -53,59 +32,7 @@ class CAPTURE_EXPORT VideoCaptureDeviceChromeOSHalv3 final
SetPhotoOptionsCallback callback) final; SetPhotoOptionsCallback callback) final;
private: private:
// Helper to interact with PowerManagerClient on DBus original thread. std::unique_ptr<VideoCaptureDeviceChromeOSDelegate> vcd_delegate_;
class PowerManagerClientProxy;
void OpenDevice();
void CloseDevice(base::UnguessableToken unblock_suspend_token);
// DisplayRotationDelegate implementation.
void SetDisplayRotation(const display::Display& display) final;
void SetRotation(int rotation);
const VideoCaptureDeviceDescriptor device_descriptor_;
// A reference to the CameraHalDelegate instance in the VCD factory. This is
// used by AllocateAndStart to query camera info and create the camera device.
const scoped_refptr<CameraHalDelegate> camera_hal_delegate_;
// A reference to the thread that all the VideoCaptureDevice interface methods
// are expected to be called on.
const scoped_refptr<base::SingleThreadTaskRunner> capture_task_runner_;
// The thread that all the Mojo operations of |camera_device_delegate_| take
// place. Started in AllocateAndStart and stopped in StopAndDeAllocate, where
// the access to the base::Thread methods are sequenced on
// |capture_task_runner_|.
base::Thread camera_device_ipc_thread_;
VideoCaptureParams capture_params_;
// |device_context_| is created and owned by VideoCaptureDeviceChromeOSHalv3
// and is only accessed by |camera_device_delegate_|.
std::unique_ptr<CameraDeviceContext> device_context_;
// Internal delegate doing the actual capture setting, buffer allocation and
// circulation with the camera HAL. Created in AllocateAndStart and deleted in
// StopAndDeAllocate on |capture_task_runner_|. All methods of
// |camera_device_delegate_| operate on |camera_device_ipc_thread_|.
std::unique_ptr<CameraDeviceDelegate> camera_device_delegate_;
scoped_refptr<ScreenObserverDelegate> screen_observer_delegate_;
const VideoFacingMode lens_facing_;
// Whether the incoming frames should rotate when the device rotates.
const bool rotates_with_device_;
int rotation_;
CameraAppDeviceImpl* camera_app_device_; // Weak.
base::OnceClosure cleanup_callback_;
scoped_refptr<PowerManagerClientProxy> power_manager_client_proxy_;
// The client type in CameraDeviceContext.
ClientType client_type_;
base::WeakPtrFactory<VideoCaptureDeviceChromeOSHalv3> weak_ptr_factory_{this};
DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceChromeOSHalv3); DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureDeviceChromeOSHalv3);
}; };
......
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