1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_CAMERA_DEVICE_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_CAMERA_DEVICE_H_
19 
20 #include "camera_buffer_allocator_hwl.h"
21 #include "camera_device_hwl.h"
22 #include "camera_device_session.h"
23 #include "hal_camera_metadata.h"
24 #include "profiler.h"
25 
26 namespace android {
27 namespace google_camera_hal {
28 
29 // Camera Device implements ICameraDevice. It provides methods to query static
30 // information about a camera device and create a camera device session for
31 // active use. It does not hold any states of the camera device.
32 class CameraDevice {
33  public:
34   // Create a camera device given a camera device HWL.
35   // camera_device_hwl must be valid.
36   // camera_allocator_hwl is owned by the caller and must be valid during the
37   // lifetime of CameraDevice
38   static std::unique_ptr<CameraDevice> Create(
39       std::unique_ptr<CameraDeviceHwl> camera_device_hwl,
40       CameraBufferAllocatorHwl* camera_allocator_hwl = nullptr,
41       const std::vector<std::string>* configure_streams_libs = nullptr);
42 
43   virtual ~CameraDevice();
44 
45   // Get the resource cost of this camera device.
46   status_t GetResourceCost(CameraResourceCost* cost);
47 
48   // Get the characteristics of this camera device.
49   // characteristics will be filled with this camera device's characteristics.
50   status_t GetCameraCharacteristics(
51       std::unique_ptr<HalCameraMetadata>* characteristics);
52 
53   // Get the characteristics of this camera device's physical camera if the
54   // physical_camera_id belongs to this camera device.
55   // characteristics will be filled with the physical camera ID's
56   // characteristics.
57   status_t GetPhysicalCameraCharacteristics(
58       uint32_t physical_camera_id,
59       std::unique_ptr<HalCameraMetadata>* characteristics);
60 
61   // Set the torch mode of the camera device. The torch mode status remains
62   // unchanged after this CameraDevice instance is destroyed.
63   status_t SetTorchMode(TorchMode mode);
64 
65   // Create a CameraDeviceSession to handle capture requests. This method will
66   // return ALREADY_EXISTS if previous session has not been destroyed.
67   // Created CameraDeviceSession remain valid even after this CameraDevice
68   // instance is destroyed.
69   status_t CreateCameraDeviceSession(
70       std::unique_ptr<CameraDeviceSession>* session);
71 
72   // Dump the camera device states in fd, using dprintf() or write().
73   status_t DumpState(int fd);
74 
75   // Get the public camera ID for this camera device.
GetPublicCameraId()76   uint32_t GetPublicCameraId() const {
77     return public_camera_id_;
78   };
79 
80   // Query whether a particular logical and physical streams combination are
81   // supported. stream_config contains the stream configurations.
82   bool IsStreamCombinationSupported(const StreamConfiguration& stream_config);
83 
84   status_t LoadExternalCaptureSession();
85 
86   std::unique_ptr<google::camera_common::Profiler> GetProfiler(uint32_t camere_id,
87                                                                int option);
88 
89  protected:
90   CameraDevice() = default;
91 
92  private:
93   status_t Initialize(std::unique_ptr<CameraDeviceHwl> camera_device_hwl,
94                       CameraBufferAllocatorHwl* camera_allocator_hwl);
95 
96   uint32_t public_camera_id_ = 0;
97 
98   std::unique_ptr<CameraDeviceHwl> camera_device_hwl_;
99 
100   // hwl allocator
101   CameraBufferAllocatorHwl* camera_allocator_hwl_ = nullptr;
102 
103   std::vector<GetCaptureSessionFactoryFunc> external_session_factory_entries_;
104   // Opened library handles that should be closed on destruction
105   std::vector<void*> external_capture_session_lib_handles_;
106 
107   const std::vector<std::string>* configure_streams_libs_ = nullptr;
108 };
109 
110 }  // namespace google_camera_hal
111 }  // namespace android
112 
113 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_CAMERA_DEVICE_H_
114