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