• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <map>
21 
22 #include "camera_buffer_allocator_hwl.h"
23 #include "camera_device_hwl.h"
24 #include "camera_device_session.h"
25 #include "hal_camera_metadata.h"
26 #include "profiler.h"
27 
28 namespace android {
29 namespace google_camera_hal {
30 
31 // Camera Device implements ICameraDevice. It provides methods to query static
32 // information about a camera device and create a camera device session for
33 // active use. It does not hold any states of the camera device.
34 class CameraDevice {
35  public:
36   // Create a camera device given a camera device HWL.
37   // camera_device_hwl must be valid.
38   // camera_allocator_hwl is owned by the caller and must be valid during the
39   // lifetime of CameraDevice
40   static std::unique_ptr<CameraDevice> Create(
41       std::unique_ptr<CameraDeviceHwl> camera_device_hwl,
42       CameraBufferAllocatorHwl* camera_allocator_hwl = nullptr,
43       const std::vector<std::string>* configure_streams_libs = nullptr);
44 
45   virtual ~CameraDevice();
46 
47   // Get the resource cost of this camera device.
48   status_t GetResourceCost(CameraResourceCost* cost);
49 
50   // Get the characteristics of this camera device.
51   // characteristics will be filled with this camera device's characteristics.
52   status_t GetCameraCharacteristics(
53       std::unique_ptr<HalCameraMetadata>* characteristics);
54 
55   // For certain feature combinations, some keys in camera characteristics
56   // have more limited support range compared with that returned by
57   // GetCameraCharacterics. This function will return the limited values of the
58   // keys listed in CameraCharacteristics#getAvailableSessionCharacteristicsKeys
59   // for the input StreamConfiguration.
60   //
61   // stream_config includes the requested streams and session settings for
62   // which we are going to fetch the characteristics.
63   //
64   // session_characteristic will be filled with the session characteristics keys
65   // with their limited ranges.
66   status_t GetSessionCharacteristics(
67       const StreamConfiguration& stream_config,
68       std::unique_ptr<HalCameraMetadata>& session_characteristics);
69 
70   // Get the characteristics of this camera device's physical camera if the
71   // physical_camera_id belongs to this camera device.
72   // characteristics will be filled with the physical camera ID's
73   // characteristics.
74   status_t GetPhysicalCameraCharacteristics(
75       uint32_t physical_camera_id,
76       std::unique_ptr<HalCameraMetadata>* characteristics);
77 
78   // Set the torch mode of the camera device. The torch mode status remains
79   // unchanged after this CameraDevice instance is destroyed.
80   status_t SetTorchMode(TorchMode mode);
81 
82   // Change the brightness level of the flash unit in Torch mode.
83   // If the torch is OFF and torchStrength > 0, the torch will be turned ON.
84   status_t TurnOnTorchWithStrengthLevel(int32_t torch_strength);
85 
86   // Get the flash unit strength level of this camera device.
87   status_t GetTorchStrengthLevel(int32_t& torch_strength) const;
88 
89   // Construct default request settings
90   status_t ConstructDefaultRequestSettings(
91       RequestTemplate type,
92       std::unique_ptr<HalCameraMetadata>* request_settings);
93 
94   // Create a CameraDeviceSession to handle capture requests. This method will
95   // return ALREADY_EXISTS if previous session has not been destroyed.
96   // Created CameraDeviceSession remain valid even after this CameraDevice
97   // instance is destroyed.
98   status_t CreateCameraDeviceSession(
99       std::unique_ptr<CameraDeviceSession>* session);
100 
101   // Dump the camera device states in fd, using dprintf() or write().
102   status_t DumpState(int fd);
103 
104   // Get the public camera ID for this camera device.
GetPublicCameraId()105   uint32_t GetPublicCameraId() const {
106     return public_camera_id_;
107   };
108 
109   // Query whether a particular streams configuration is supported.
110   // stream_config: It contains the stream info and a set of features, which are
111   // described in the form of session settings.
112   // check_settings: When check_settings is true, this function will check if
113   // the input features combination in stream_config is supported. The feature
114   // set camera hwl has to scan for reporting support status is defined in
115   // framework by CameraCharacteristics#INFO_SESSION_CONFIGURATION_QUERY_VERSION.
116   bool IsStreamCombinationSupported(const StreamConfiguration& stream_config,
117                                     bool check_settings);
118 
119   status_t LoadExternalCaptureSession();
120 
121   std::unique_ptr<google::camera_common::Profiler> GetProfiler(uint32_t camere_id,
122                                                                int option);
123 
124  protected:
125   CameraDevice() = default;
126 
127  private:
128   status_t Initialize(std::unique_ptr<CameraDeviceHwl> camera_device_hwl,
129                       CameraBufferAllocatorHwl* camera_allocator_hwl);
130 
131   uint32_t public_camera_id_ = 0;
132 
133   std::unique_ptr<CameraDeviceHwl> camera_device_hwl_;
134 
135   // hwl allocator
136   CameraBufferAllocatorHwl* camera_allocator_hwl_ = nullptr;
137 
138   std::vector<GetCaptureSessionFactoryFunc> external_session_factory_entries_;
139   // Opened library handles that should be closed on destruction
140   std::vector<void*> external_capture_session_lib_handles_;
141   // Stream use cases supported by this camera device
142   std::map<uint32_t, std::set<int64_t>> camera_id_to_stream_use_cases_;
143 
144   const std::vector<std::string>* configure_streams_libs_ = nullptr;
145 };
146 
147 }  // namespace google_camera_hal
148 }  // namespace android
149 
150 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_CAMERA_DEVICE_H_
151