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_HIDL_SERVICE_HIDL_CAMERA_DEVICE_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_CAMERA_DEVICE_H_
19 
20 #include <android/hardware/camera/device/3.5/ICameraDeviceCallback.h>
21 #include <android/hardware/camera/device/3.7/ICameraDevice.h>
22 
23 #include "camera_device.h"
24 #include "hidl_profiler.h"
25 
26 namespace android {
27 namespace hardware {
28 namespace camera {
29 namespace device {
30 namespace V3_7 {
31 namespace implementation {
32 
33 using ::android::hardware::camera::common::V1_0::CameraResourceCost;
34 using ::android::hardware::camera::common::V1_0::Status;
35 using ::android::hardware::camera::common::V1_0::TorchMode;
36 using ::android::hardware::camera::device::V3_5::ICameraDeviceCallback;
37 using ::android::hardware::camera::device::V3_7::ICameraDevice;
38 using ::android::hardware::camera::implementation::HidlProfiler;
39 
40 using ::android::google_camera_hal::CameraDevice;
41 
42 // HidlCameraDevice implements the HIDL camera device interface, ICameraDevice,
43 // using Google Camera HAL to provide information about the associated camera
44 // device.
45 class HidlCameraDevice : public ICameraDevice {
46  public:
47   static const std::string kDeviceVersion;
48 
49   // Create a HidlCameraDevice.
50   // google_camera_device is a google camera device that HidlCameraDevice
51   // is going to manage. Creating a HidlCameraDevice will fail if
52   // google_camera_device is nullptr.
53   static std::unique_ptr<HidlCameraDevice> Create(
54       std::unique_ptr<CameraDevice> google_camera_device);
55   virtual ~HidlCameraDevice() = default;
56 
57   // Override functions in ICameraDevice
58   Return<void> getResourceCost(
59       ICameraDevice::getResourceCost_cb _hidl_cb) override;
60 
61   Return<void> getCameraCharacteristics(
62       ICameraDevice::getCameraCharacteristics_cb _hidl_cb) override;
63 
64   Return<Status> setTorchMode(TorchMode mode) override;
65 
66   Return<void> open(const sp<V3_2::ICameraDeviceCallback>& callback,
67                     ICameraDevice::open_cb _hidl_cb) override;
68 
69   Return<void> dumpState(const ::android::hardware::hidl_handle& handle) override;
70 
71   Return<void> getPhysicalCameraCharacteristics(
72       const hidl_string& physicalCameraId,
73       ICameraDevice::getPhysicalCameraCharacteristics_cb _hidl_cb) override;
74 
75   Return<void> isStreamCombinationSupported(
76       const V3_4::StreamConfiguration& streams,
77       ICameraDevice::isStreamCombinationSupported_cb _hidl_cb) override;
78 
79   Return<void> isStreamCombinationSupported_3_7(
80       const StreamConfiguration& streams,
81       ICameraDevice::isStreamCombinationSupported_cb _hidl_cb) override;
82 
83   // End of override functions in ICameraDevice
84 
85  protected:
86   HidlCameraDevice() = default;
87 
88  private:
89   status_t Initialize(std::unique_ptr<CameraDevice> google_camera_device);
90 
91   std::unique_ptr<CameraDevice> google_camera_device_;
92   uint32_t camera_id_ = 0;
93   std::shared_ptr<HidlProfiler> hidl_profiler_;
94 };
95 
96 }  // namespace implementation
97 }  // namespace V3_7
98 }  // namespace device
99 }  // namespace camera
100 }  // namespace hardware
101 }  // namespace android
102 
103 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_CAMERA_DEVICE_H_
104