Chromium Code Reviews| Index: media/capture/video/chromeos/camera_device_delegate.h |
| diff --git a/media/capture/video/chromeos/camera_device_delegate.h b/media/capture/video/chromeos/camera_device_delegate.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e8e31121b7a9c1d2e38f18c75cec685cce924dac |
| --- /dev/null |
| +++ b/media/capture/video/chromeos/camera_device_delegate.h |
| @@ -0,0 +1,168 @@ |
| +// 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_CAMERA_DEVICE_DELEGATE_H_ |
| +#define MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_DEVICE_DELEGATE_H_ |
| + |
| +#include <memory> |
| + |
| +#include "base/macros.h" |
| +#include "media/capture/video/chromeos/mojo/arc_camera3.mojom.h" |
| +#include "media/capture/video/video_capture_device.h" |
| +#include "media/capture/video_capture_types.h" |
| + |
| +namespace media { |
| + |
| +class CameraHalDelegate; |
| +class CameraDeviceContext; |
| +class StreamBufferManager; |
| + |
| +// The interface to register buffer with and send capture request to the |
| +// camera HAL. |
| +class CAPTURE_EXPORT StreamCaptureInterface { |
| + public: |
| + virtual ~StreamCaptureInterface() {} |
|
Pawel Osciak
2017/06/13 08:40:16
= default ?
jcliang
2017/06/14 04:46:05
I'm hitting style checker errors in the trybots wi
|
| + |
| + // Registers a buffer to the camera HAL. |
| + virtual void RegisterBuffer(uint64_t buffer_id, |
| + arc::mojom::Camera3DeviceOps::BufferType type, |
| + std::vector<mojo::ScopedHandle> fds, |
| + uint32_t drm_format, |
| + arc::mojom::HalPixelFormat hal_pixel_format, |
| + uint32_t width, |
| + uint32_t height, |
| + std::vector<uint32_t> strides, |
|
Pawel Osciak
2017/06/13 08:40:16
Perhaps a struct Plane {uint32_t stride; uint32_t
jcliang
2017/06/14 04:46:06
Done.
|
| + std::vector<uint32_t> offsets, |
| + base::OnceCallback<void(int32_t)> callback); |
| + |
| + // Sends a capture request to the camera HAL. |
| + virtual void ProcessCaptureRequest( |
| + arc::mojom::Camera3CaptureRequestPtr request, |
| + base::OnceCallback<void(int32_t)> callback); |
| +}; |
| + |
| +// CameraDeviceDelegate is instantiated on the capture thread where |
| +// AllocateAndStart of VideoCaptureDeviceArcChromeOS runs on. All the methods |
| +// in CameraDeviceDelegate run on |ipc_task_runner_| and hence all the |
| +// access to member variables is sequenced. |
| +// |
| +// CameraDeviceDelegate is refcounted because it is bound to closures that run |
| +// on the module ipc thread of |hal_delegate_| and the device ipc thread which |
| +// is referenced by |ipc_task_runner_|. |
| +class CAPTURE_EXPORT CameraDeviceDelegate final |
| + : public base::RefCountedThreadSafe<CameraDeviceDelegate> { |
| + public: |
| + CameraDeviceDelegate( |
| + VideoCaptureDeviceDescriptor device_descriptor, |
| + scoped_refptr<CameraHalDelegate> camera_hal_delegate, |
| + scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner); |
| + |
| + // Delegation methods for the VideoCaptureDevice interface. |
| + void AllocateAndStart(const VideoCaptureParams& params, |
| + std::unique_ptr<VideoCaptureDevice::Client> client); |
| + void StopAndDeAllocate(); |
| + void TakePhoto(VideoCaptureDevice::TakePhotoCallback callback); |
| + void GetPhotoCapabilities( |
| + VideoCaptureDevice::GetPhotoCapabilitiesCallback callback); |
| + void SetPhotoOptions(mojom::PhotoSettingsPtr settings, |
| + VideoCaptureDevice::SetPhotoOptionsCallback callback); |
| + |
| + // Sets the frame rotation angle in |rotation_|. |rotation_| is clockwise |
| + // rotation in degrees, and is passed to |client_| along with the captured |
| + // frames. |
| + void SetRotation(int rotation); |
| + |
| + private: |
| + class StreamCaptureInterfaceImpl; |
| + |
| + friend class CameraDeviceDelegateTest; |
| + friend class base::RefCountedThreadSafe<CameraDeviceDelegate>; |
| + ~CameraDeviceDelegate(); |
|
Pawel Osciak
2017/06/13 08:40:16
= default?
jcliang
2017/06/14 04:46:06
Same here. Default destructor is not favored by th
|
| + |
| + // Mojo connection error handler. |
| + void OnMojoConnectionError(); |
| + |
| + // Callback method for the Close Mojo IPC call. This method resets the Mojo |
| + // connection and closes the camera device. |
| + void OnClosed(int32_t result); |
| + |
| + // Resets the Mojo interface and bindings. |
| + void ResetMojoInterface(); |
| + |
| + // Sets |static_metadata_| from |camera_info|. |
| + void OnGotCameraInfo(int32_t result, arc::mojom::CameraInfoPtr camera_info); |
| + |
| + // Creates the Mojo connection to the camera device. |
| + void OnOpenedDevice(int32_t result); |
| + |
| + // Initializes the camera HAL. Initialize sets up the Camera3CallbackOps with |
| + // the camera HAL. OnInitialized continues to ConfigureStreams if the |
| + // Initialize call succeeds. |
| + void Initialize(); |
| + void OnInitialized(int32_t result); |
| + |
| + // ConfigureStreams sets up stream context in |streams_| and configure the |
| + // streams with the camera HAL. OnConfiguredStreams updates |streams_| with |
| + // the stream config returned, and allocates buffers as per |updated_config| |
| + // indicates. If there's no error OnConfiguredStreams notifies |
| + // |client_| the capture has started by calling OnStarted, and proceeds to |
| + // ConstructDefaultRequestSettings. |
| + void ConfigureStreams(); |
| + void OnConfiguredStreams( |
| + int32_t result, |
| + arc::mojom::Camera3StreamConfigurationPtr updated_config); |
| + |
| + // ConstructDefaultRequestSettings asks the camera HAL for the default request |
| + // settings of the stream in |stream_context_|. |
| + // OnConstructedDefaultRequestSettings sets the request settings in |
| + // |streams_context_|. If there's no error |
| + // OnConstructedDefaultRequestSettings calls StartCapture to start the video |
| + // capture loop. |
| + void ConstructDefaultRequestSettings(); |
| + void OnConstructedDefaultRequestSettings( |
| + arc::mojom::CameraMetadataPtr settings); |
| + |
| + // StreamCaptureInterface implementations. These methods are called by |
| + // |stream_buffer_manager_|. |
| + void RegisterBuffer(uint64_t buffer_id, |
| + arc::mojom::Camera3DeviceOps::BufferType type, |
| + std::vector<mojo::ScopedHandle> fds, |
| + uint32_t drm_format, |
| + arc::mojom::HalPixelFormat hal_pixel_format, |
| + uint32_t width, |
| + uint32_t height, |
| + std::vector<uint32_t> strides, |
| + std::vector<uint32_t> offsets, |
| + base::OnceCallback<void(int32_t)> callback); |
| + void ProcessCaptureRequest(arc::mojom::Camera3CaptureRequestPtr request, |
| + base::OnceCallback<void(int32_t)> callback); |
| + |
| + const VideoCaptureDeviceDescriptor device_descriptor_; |
| + |
| + int32_t camera_id_; |
| + |
| + const scoped_refptr<CameraHalDelegate> camera_hal_delegate_; |
| + |
| + VideoCaptureParams chrome_capture_params_; |
| + |
| + std::unique_ptr<CameraDeviceContext> device_context_; |
| + |
| + scoped_refptr<StreamBufferManager> stream_buffer_manager_; |
| + |
| + // Stores the static camera characteristics of the camera device. E.g. the |
| + // supported formats and resolution, various available exposure and apeture |
| + // settings, etc. |
| + arc::mojom::CameraMetadataPtr static_metadata_; |
| + |
| + arc::mojom::Camera3DeviceOpsPtr device_ops_; |
| + |
| + // Where all the Mojo IPC calls takes place. |
| + const scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; |
| + |
| + DISALLOW_IMPLICIT_CONSTRUCTORS(CameraDeviceDelegate); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_DEVICE_DELEGATE_H_ |