| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_DEVICE_DELEGATE_H_ |
| 6 #define MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_DEVICE_DELEGATE_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "media/capture/video/chromeos/mojo/arc_camera3.mojom.h" |
| 12 #include "media/capture/video/video_capture_device.h" |
| 13 #include "media/capture/video_capture_types.h" |
| 14 |
| 15 namespace media { |
| 16 |
| 17 class CameraHalDelegate; |
| 18 class CameraDeviceContext; |
| 19 class StreamBufferManager; |
| 20 |
| 21 // The interface to register buffer with and send capture request to the |
| 22 // camera HAL. |
| 23 class CAPTURE_EXPORT StreamCaptureInterface { |
| 24 public: |
| 25 virtual ~StreamCaptureInterface() = default; |
| 26 |
| 27 // Registers a buffer to the camera HAL. This method is called by |
| 28 // |stream_buffer_manager_| in the capture loop. |
| 29 virtual void RegisterBuffer(uint64_t buffer_id, |
| 30 arc::mojom::Camera3DeviceOps::BufferType type, |
| 31 std::vector<mojo::ScopedHandle> fds, |
| 32 uint32_t drm_format, |
| 33 arc::mojom::HalPixelFormat hal_pixel_format, |
| 34 uint32_t width, |
| 35 uint32_t height, |
| 36 std::vector<uint32_t> strides, |
| 37 std::vector<uint32_t> offsets, |
| 38 base::OnceCallback<void(int32_t)> callback); |
| 39 |
| 40 // Sends a capture request to the camera HAL. This method is called by |
| 41 // |stream_buffer_manager_| in the capture loop. |
| 42 virtual void ProcessCaptureRequest( |
| 43 arc::mojom::Camera3CaptureRequestPtr request, |
| 44 base::OnceCallback<void(int32_t)> callback); |
| 45 }; |
| 46 |
| 47 // CameraDeviceDelegate is instantiated on the capture thread where |
| 48 // AllocateAndStart of VideoCaptureDeviceArcChromeOS runs on. All the methods |
| 49 // in CameraDeviceDelegate run on |ipc_task_runner_| and hence all the |
| 50 // access to member variables is sequenced. |
| 51 // |
| 52 // CameraDeviceDelegate is refcounted because it is bound to closures that run |
| 53 // on the module thread of |hal_delegate_| and the device thread which is |
| 54 // referenced by |ipc_task_runner_|. |
| 55 class CAPTURE_EXPORT CameraDeviceDelegate final |
| 56 : public base::RefCountedThreadSafe<CameraDeviceDelegate> { |
| 57 public: |
| 58 CameraDeviceDelegate( |
| 59 VideoCaptureDeviceDescriptor device_descriptor, |
| 60 scoped_refptr<CameraHalDelegate> camera_hal_delegate, |
| 61 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner); |
| 62 |
| 63 // Delegation methods for the VideoCaptureDevice interface. |
| 64 void AllocateAndStart(const VideoCaptureParams& params, |
| 65 std::unique_ptr<VideoCaptureDevice::Client> client); |
| 66 void StopAndDeAllocate(); |
| 67 void TakePhoto(VideoCaptureDevice::TakePhotoCallback callback); |
| 68 void GetPhotoCapabilities( |
| 69 VideoCaptureDevice::GetPhotoCapabilitiesCallback callback); |
| 70 void SetPhotoOptions(mojom::PhotoSettingsPtr settings, |
| 71 VideoCaptureDevice::SetPhotoOptionsCallback callback); |
| 72 |
| 73 // Sets the frame rotation angle in |rotation_|. |rotation_| is clockwise |
| 74 // rotation in degrees, and is passed to |client_| along with the captured |
| 75 // frames. |
| 76 void SetRotation(int rotation); |
| 77 |
| 78 private: |
| 79 class StreamCaptureInterfaceImpl; |
| 80 |
| 81 friend class CameraDeviceDelegateTest; |
| 82 friend class base::RefCountedThreadSafe<CameraDeviceDelegate>; |
| 83 ~CameraDeviceDelegate(); |
| 84 |
| 85 // Mojo connection error handler. |
| 86 void OnMojoConnectionError(); |
| 87 |
| 88 // Callback method for the Close Mojo IPC call. This method resets the Mojo |
| 89 // connection and closes the camera device. |
| 90 void OnClosed(int32_t result); |
| 91 |
| 92 // Resets the Mojo interface and bindings. |
| 93 void ResetMojoInterface(); |
| 94 |
| 95 // Sets |static_metadata_| from |camera_info|. |
| 96 void OnGotCameraInfo(int32_t result, arc::mojom::CameraInfoPtr camera_info); |
| 97 |
| 98 // Creates the Mojo connection to the camera device. |
| 99 void OnOpenedDevice(int32_t result); |
| 100 |
| 101 // Initializes the camera HAL. Initialize sets up the Camera3CallbackOps with |
| 102 // the camera HAL. OnInitialized continues to ConfigureStreams if the |
| 103 // Initialize call succeeds. |
| 104 void Initialize(); |
| 105 void OnInitialized(int32_t result); |
| 106 |
| 107 // ConfigureStreams sets up stream context in |streams_| and configure the |
| 108 // streams with the camera HAL. OnConfiguredStreams updates |streams_| with |
| 109 // the stream config returned, and allocates buffers as per |updated_config| |
| 110 // indicates. If there's no error OnConfiguredStreams notifies |
| 111 // |client_| the capture has started by calling OnStarted, and proceeds to |
| 112 // ConstructDefaultRequestSettings. |
| 113 void ConfigureStreams(); |
| 114 void OnConfiguredStreams( |
| 115 int32_t result, |
| 116 arc::mojom::Camera3StreamConfigurationPtr updated_config); |
| 117 |
| 118 // ConstructDefaultRequestSettings asks the camera HAL for the default request |
| 119 // settings of the stream in |stream_context_|. |
| 120 // OnConstructedDefaultRequestSettings sets the request settings in |
| 121 // |streams_context_|. If there's no error |
| 122 // OnConstructedDefaultRequestSettings calls StartCapture to start the video |
| 123 // capture loop. |
| 124 void ConstructDefaultRequestSettings(); |
| 125 void OnConstructedDefaultRequestSettings( |
| 126 arc::mojom::CameraMetadataPtr settings); |
| 127 |
| 128 // Registers a buffer to the camera HAL. This method is called by |
| 129 // |stream_buffer_manager_| in the capture loop. |
| 130 void RegisterBuffer(uint64_t buffer_id, |
| 131 arc::mojom::Camera3DeviceOps::BufferType type, |
| 132 std::vector<mojo::ScopedHandle> fds, |
| 133 uint32_t drm_format, |
| 134 arc::mojom::HalPixelFormat hal_pixel_format, |
| 135 uint32_t width, |
| 136 uint32_t height, |
| 137 std::vector<uint32_t> strides, |
| 138 std::vector<uint32_t> offsets, |
| 139 base::OnceCallback<void(int32_t)> callback); |
| 140 |
| 141 // Sends a capture request to the camera HAL. This method is called by |
| 142 // |stream_buffer_manager_| in the capture loop. |
| 143 void ProcessCaptureRequest(arc::mojom::Camera3CaptureRequestPtr request, |
| 144 base::OnceCallback<void(int32_t)> callback); |
| 145 |
| 146 scoped_refptr<StreamBufferManager> stream_buffer_manager_; |
| 147 |
| 148 const VideoCaptureDeviceDescriptor device_descriptor_; |
| 149 const scoped_refptr<CameraHalDelegate> camera_hal_delegate_; |
| 150 |
| 151 VideoCaptureParams chrome_capture_params_; |
| 152 |
| 153 std::unique_ptr<CameraDeviceContext> device_context_; |
| 154 |
| 155 // Stores the static camera characteristics of the camera device. E.g. the |
| 156 // supported formats and resolution, various available exposure and apeture |
| 157 // settings, etc. |
| 158 arc::mojom::CameraMetadataPtr static_metadata_; |
| 159 |
| 160 arc::mojom::Camera3DeviceOpsPtr device_ops_; |
| 161 |
| 162 // Where all the Mojo IPC calls takes place. |
| 163 const scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; |
| 164 |
| 165 DISALLOW_IMPLICIT_CONSTRUCTORS(CameraDeviceDelegate); |
| 166 }; |
| 167 |
| 168 } // namespace media |
| 169 |
| 170 #endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_CAMERA_DEVICE_DELEGATE_H_ |
| OLD | NEW |