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_HWL_INTERFACE_CAMERA_DEVICE_HWL_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_HWL_INTERFACE_CAMERA_DEVICE_HWL_H_
19 
20 #include <utils/Errors.h>
21 
22 #include "camera_buffer_allocator_hwl.h"
23 #include "camera_device_session_hwl.h"
24 #include "hal_camera_metadata.h"
25 #include "hal_types.h"
26 #include "hwl_types.h"
27 #include "physical_camera_info_hwl.h"
28 #include "profiler.h"
29 
30 namespace android {
31 namespace google_camera_hal {
32 
33 // Camera device HWL, which is associated with a certain camera ID. The camera
34 // device can be a logical camera that contains multiple physical camera, or
35 // a single physical camera. It provides methods to query static information
36 // about the associated camera devices. It does not hold any states of the
37 // camera device.
38 class CameraDeviceHwl : public PhysicalCameraInfoHwl {
39  public:
40   virtual ~CameraDeviceHwl() = default;
41 
42   // Get the camera ID of this camera device HWL.
43   virtual uint32_t GetCameraId() const = 0;
44 
45   // Get the resource cost of this camera device HWL.
46   virtual status_t GetResourceCost(CameraResourceCost* cost) const = 0;
47 
48   // Get the characteristics of this camera device HWL.
49   // characteristics will be filled by CameraDeviceHwl.
50   virtual status_t GetCameraCharacteristics(
51       std::unique_ptr<HalCameraMetadata>* characteristics) const = 0;
52 
53   // For certain feature combinations, some keys in camera characteristics
54   // have more limited support range compared with that returned by
55   // GetCameraCharacterics. This function will return the limited values of the
56   // keys listed in CameraCharacteristics#getAvailableSessionCharacteristicsKeys
57   // for the input StreamConfiguration.
58   //
59   // stream_config includes the requested streams and session settings for
60   // which we are going to fetch the characteristics.
61   //
62   // session_characteristic will be filled with the session characteristics keys
63   // with their limited ranges.
64   virtual status_t GetSessionCharacteristics(
65       const StreamConfiguration& session_config,
66       std::unique_ptr<HalCameraMetadata>& characteristics) const = 0;
67 
68   // Get the characteristics of the physical camera of this camera device.
69   // characteristics will be filled by CameraDeviceHwl.
70   virtual status_t GetPhysicalCameraCharacteristics(
71       uint32_t physical_camera_id,
72       std::unique_ptr<HalCameraMetadata>* characteristics) const = 0;
73 
74   // Get the memory config of this camera device.
75   virtual HwlMemoryConfig GetMemoryConfig() const = 0;
76 
77   // Set the torch mode of the camera device. The torch mode status remains
78   // unchanged after this CameraDevice instance is destroyed.
79   virtual status_t SetTorchMode(TorchMode mode) = 0;
80 
81   // Change the torch strength level of this camera device. If the torch is OFF
82   // and torchStrength > 0, then the torch will turn ON.
TurnOnTorchWithStrengthLevel(int32_t)83   virtual status_t TurnOnTorchWithStrengthLevel(int32_t /*torch_strength*/) {
84     return UNKNOWN_TRANSACTION;
85   }
86 
87   // Get the torch strength level of this camera device HWL.
GetTorchStrengthLevel(int32_t &)88   virtual status_t GetTorchStrengthLevel(int32_t& /*torch_strength*/) const {
89     return UNKNOWN_TRANSACTION;
90   }
91 
92   // Construct default request settings
93   virtual status_t ConstructDefaultRequestSettings(
94       RequestTemplate type,
95       std::unique_ptr<HalCameraMetadata>* request_settings) = 0;
96 
97   // Dump the camera device states in fd, using dprintf() or write().
98   virtual status_t DumpState(int fd) = 0;
99 
100   // Create a camera device session for this device. This method will not be
101   // called before previous session has been destroyed.
102   // Created CameraDeviceSession remain valid even after this CameraDevice
103   // instance is destroyed.
104   // camera_allocator_hwl will be used by the HWL session when create HW
105   // pipeline, it should be valid during the lifetime of the HWL session.
106   virtual status_t CreateCameraDeviceSessionHwl(
107       CameraBufferAllocatorHwl* camera_allocator_hwl,
108       std::unique_ptr<CameraDeviceSessionHwl>* session) = 0;
109 
110   // Query whether a particular streams configuration is supported.
111   // stream_config: It contains the stream info and session settings.
112   // check_settings: When check_settings is true, this function will check if
113   // the input session settings in stream_config is supported. The keys camera
114   // hwl has to scan for reporting support status is defined in framework by
115   // CameraCharacteristics#INFO_SESSION_CONFIGURATION_QUERY_VERSION.
116   virtual bool IsStreamCombinationSupported(
117       const StreamConfiguration& stream_config,
118       const bool check_settings) const = 0;
119 
120   // Get customized profiler
GetProfiler(uint32_t,int)121   virtual std::unique_ptr<google::camera_common::Profiler> GetProfiler(
122       uint32_t /* camera_id */, int /* option */) {
123     return nullptr;
124   }
125 };
126 
127 }  // namespace google_camera_hal
128 }  // namespace android
129 
130 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_HWL_INTERFACE_CAMERA_DEVICE_HWL_H_
131