• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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_AIDL_SERVICE_AIDL_CAMERA_DEVICE_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_CAMERA_DEVICE_H_
19 
20 #include <aidl/android/hardware/camera/device/BnCameraDevice.h>
21 #include <aidl/android/hardware/camera/device/ICameraDeviceCallback.h>
22 
23 #include "aidl_profiler.h"
24 #include "camera_device.h"
25 
26 namespace android {
27 namespace hardware {
28 namespace camera {
29 namespace device {
30 namespace implementation {
31 
32 using aidl::android::hardware::camera::common::CameraResourceCost;
33 using aidl::android::hardware::camera::device::BnCameraDevice;
34 using aidl::android::hardware::camera::device::CameraMetadata;
35 using aidl::android::hardware::camera::device::ICameraDevice;
36 using aidl::android::hardware::camera::device::ICameraDeviceCallback;
37 using aidl::android::hardware::camera::device::ICameraDeviceSession;
38 using aidl::android::hardware::camera::device::ICameraInjectionSession;
39 using aidl::android::hardware::camera::device::StreamConfiguration;
40 using ::android::hardware::camera::implementation::AidlProfiler;
41 using ndk::ScopedAStatus;
42 using ndk::ScopedFileDescriptor;
43 
44 using ::android::google_camera_hal::CameraDevice;
45 
46 // AidlCameraDevice implements the AIDL camera device interface, ICameraDevice,
47 // using Google Camera HAL to provide information about the associated camera
48 // device.
49 class AidlCameraDevice : public BnCameraDevice {
50  public:
51   static const std::string kDeviceVersion;
52 
53   // Create a AidlCameraDevice.
54   // google_camera_device is a google camera device that AidlCameraDevice
55   // is going to manage. Creating a AidlCameraDevice will fail if
56   // google_camera_device is nullptr.
57   static std::shared_ptr<AidlCameraDevice> Create(
58       std::unique_ptr<CameraDevice> google_camera_device);
59   virtual ~AidlCameraDevice() = default;
60 
61   binder_status_t dump(int fd, const char**, uint32_t) override;
62 
63   // Override functions in ICameraDevice
64   ScopedAStatus getCameraCharacteristics(
65       CameraMetadata* characteristics) override;
66 
67   ScopedAStatus getPhysicalCameraCharacteristics(
68       const std::string& in_physicalCameraId,
69       CameraMetadata* characteristics) override;
70 
71   ScopedAStatus getResourceCost(CameraResourceCost* resource_cost) override;
72 
73   ScopedAStatus isStreamCombinationSupported(
74       const StreamConfiguration& in_streams, bool* supported) override;
75 
76   ScopedAStatus open(const std::shared_ptr<ICameraDeviceCallback>& in_callback,
77                      std::shared_ptr<ICameraDeviceSession>* session) override;
78 
79   ScopedAStatus openInjectionSession(
80       const std::shared_ptr<ICameraDeviceCallback>& in_callback,
81       std::shared_ptr<ICameraInjectionSession>* session) override;
82 
83   ScopedAStatus setTorchMode(bool on) override;
84 
85   ScopedAStatus turnOnTorchWithStrengthLevel(int32_t torchStrength) override;
86 
87   ScopedAStatus getTorchStrengthLevel(int32_t* strength_level) override;
88 
89   // End of override functions in ICameraDevice
90   AidlCameraDevice() = default;
91 
92  private:
93   status_t Initialize(std::unique_ptr<CameraDevice> google_camera_device);
94 
95   std::unique_ptr<CameraDevice> google_camera_device_;
96   uint32_t camera_id_ = 0;
97   std::shared_ptr<AidlProfiler> aidl_profiler_;
98 };
99 
100 }  // namespace implementation
101 }  // namespace device
102 }  // namespace camera
103 }  // namespace hardware
104 }  // namespace android
105 
106 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_AIDL_SERVICE_AIDL_CAMERA_DEVICE_H_
107