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 
25 namespace android {
26 namespace google_camera_hal {
27 
28 // Camera Device implements ICameraDevice. It provides methods to query static
29 // information about a camera device and create a camera device session for
30 // active use. It does not hold any states of the camera device.
31 class CameraDevice {
32  public:
33   // Create a camera device given a camera device HWL.
34   // camera_device_hwl must be valid.
35   // camera_allocator_hwl is owned by the caller and must be valid during the
36   // lifetime of CameraDevice
37   static std::unique_ptr<CameraDevice> Create(
38       std::unique_ptr<CameraDeviceHwl> camera_device_hwl,
39       CameraBufferAllocatorHwl* camera_allocator_hwl = nullptr);
40 
41   virtual ~CameraDevice() = default;
42 
43   // Get the resource cost of this camera device.
44   status_t GetResourceCost(CameraResourceCost* cost);
45 
46   // Get the characteristics of this camera device.
47   // characteristics will be filled with this camera device's characteristics.
48   status_t GetCameraCharacteristics(
49       std::unique_ptr<HalCameraMetadata>* characteristics);
50 
51   // Get the characteristics of this camera device's physical camera if the
52   // physical_camera_id belongs to this camera device.
53   // characteristics will be filled with the physical camera ID's
54   // characteristics.
55   status_t GetPhysicalCameraCharacteristics(
56       uint32_t physical_camera_id,
57       std::unique_ptr<HalCameraMetadata>* characteristics);
58 
59   // Set the torch mode of the camera device. The torch mode status remains
60   // unchanged after this CameraDevice instance is destroyed.
61   status_t SetTorchMode(TorchMode mode);
62 
63   // Create a CameraDeviceSession to handle capture requests. This method will
64   // return ALREADY_EXISTS if previous session has not been destroyed.
65   // Created CameraDeviceSession remain valid even after this CameraDevice
66   // instance is destroyed.
67   status_t CreateCameraDeviceSession(
68       std::unique_ptr<CameraDeviceSession>* session);
69 
70   // Dump the camera device states in fd, using dprintf() or write().
71   status_t DumpState(int fd);
72 
73   // Get the public camera ID for this camera device.
GetPublicCameraId()74   uint32_t GetPublicCameraId() const {
75     return public_camera_id_;
76   };
77 
78   // Query whether a particular logical and physical streams combination are
79   // supported. stream_config contains the stream configurations.
80   bool IsStreamCombinationSupported(const StreamConfiguration& stream_config);
81 
82  protected:
83   CameraDevice() = default;
84 
85  private:
86   status_t Initialize(std::unique_ptr<CameraDeviceHwl> camera_device_hwl,
87                       CameraBufferAllocatorHwl* camera_allocator_hwl);
88 
89   uint32_t public_camera_id_ = 0;
90 
91   std::unique_ptr<CameraDeviceHwl> camera_device_hwl_;
92 
93   // hwl allocator
94   CameraBufferAllocatorHwl* camera_allocator_hwl_ = nullptr;
95 };
96 
97 }  // namespace google_camera_hal
98 }  // namespace android
99 
100 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_GOOGLE_CAMERA_HAL_CAMERA_DEVICE_H_
101