• 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 "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   // Change the brightness level of the flash unit in Torch mode.
66   // If the torch is OFF and torchStrength > 0, the torch will be turned ON.
67   status_t TurnOnTorchWithStrengthLevel(int32_t torch_strength);
68 
69   // Get the flash unit strength level of this camera device.
70   status_t GetTorchStrengthLevel(int32_t& torch_strength) const;
71 
72   // Create a CameraDeviceSession to handle capture requests. This method will
73   // return ALREADY_EXISTS if previous session has not been destroyed.
74   // Created CameraDeviceSession remain valid even after this CameraDevice
75   // instance is destroyed.
76   status_t CreateCameraDeviceSession(
77       std::unique_ptr<CameraDeviceSession>* session);
78 
79   // Dump the camera device states in fd, using dprintf() or write().
80   status_t DumpState(int fd);
81 
82   // Get the public camera ID for this camera device.
GetPublicCameraId()83   uint32_t GetPublicCameraId() const {
84     return public_camera_id_;
85   };
86 
87   // Query whether a particular logical and physical streams combination are
88   // supported. stream_config contains the stream configurations.
89   bool IsStreamCombinationSupported(const StreamConfiguration& stream_config);
90 
91   status_t LoadExternalCaptureSession();
92 
93   std::unique_ptr<google::camera_common::Profiler> GetProfiler(uint32_t camere_id,
94                                                                int option);
95 
96  protected:
97   CameraDevice() = default;
98 
99  private:
100   status_t Initialize(std::unique_ptr<CameraDeviceHwl> camera_device_hwl,
101                       CameraBufferAllocatorHwl* camera_allocator_hwl);
102 
103   uint32_t public_camera_id_ = 0;
104 
105   std::unique_ptr<CameraDeviceHwl> camera_device_hwl_;
106 
107   // hwl allocator
108   CameraBufferAllocatorHwl* camera_allocator_hwl_ = nullptr;
109 
110   std::vector<GetCaptureSessionFactoryFunc> external_session_factory_entries_;
111   // Opened library handles that should be closed on destruction
112   std::vector<void*> external_capture_session_lib_handles_;
113   // Stream use cases supported by this camera device
114   std::set<int64_t> stream_use_cases_;
115 
116   const std::vector<std::string>* configure_streams_libs_ = nullptr;
117 };
118 
119 }  // namespace google_camera_hal
120 }  // namespace android
121 
122 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_CAMERA_DEVICE_H_
123