1 /*
2  * Copyright (C) 2023 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 #pragma once
18 
19 #include <memory>
20 #include <optional>
21 
22 #include <aidl/android/hardware/camera/device/BnCameraDevice.h>
23 
24 #include "HwCamera.h"
25 #include "metadata_utils.h"
26 #include "utils.h"
27 
28 namespace android {
29 namespace hardware {
30 namespace camera {
31 namespace provider {
32 namespace implementation {
33 
34 using aidl::android::hardware::camera::device::BnCameraDevice;
35 using aidl::android::hardware::camera::device::CameraMetadata;
36 using aidl::android::hardware::camera::common::CameraResourceCost;
37 using aidl::android::hardware::camera::device::ICameraDeviceCallback;
38 using aidl::android::hardware::camera::device::ICameraDeviceSession;
39 using aidl::android::hardware::camera::device::ICameraInjectionSession;
40 using aidl::android::hardware::camera::device::RequestTemplate;
41 using aidl::android::hardware::camera::device::StreamConfiguration;
42 
43 using ndk::ScopedAStatus;
44 
45 struct CameraProvider;
46 
47 struct CameraDevice : public BnCameraDevice {
48     CameraDevice(hw::HwCameraFactoryProduct hwCamera);
49     ~CameraDevice() override;
50 
51     ScopedAStatus getCameraCharacteristics(CameraMetadata* metadata) override;
52     ScopedAStatus getPhysicalCameraCharacteristics(
53             const std::string& in_physicalCameraId, CameraMetadata* metadata) override;
54     ScopedAStatus getResourceCost(CameraResourceCost* cost) override;
55     ScopedAStatus isStreamCombinationSupported(
56             const StreamConfiguration& in_streams, bool* support) override;
57     ScopedAStatus open(const std::shared_ptr<ICameraDeviceCallback>& in_callback,
58                        std::shared_ptr<ICameraDeviceSession>* session) override;
59     ScopedAStatus openInjectionSession(
60             const std::shared_ptr<ICameraDeviceCallback>& in_callback,
61             std::shared_ptr<ICameraInjectionSession>* session) override;
62     ScopedAStatus setTorchMode(bool on) override;
63     ScopedAStatus turnOnTorchWithStrengthLevel(int32_t strength) override;
64     ScopedAStatus getTorchStrengthLevel(int32_t* strength) override;
65 
66     CameraMetadataMap constructDefaultRequestSettings(RequestTemplate tpl) const;
67 
68 private:
69     friend struct CameraProvider;
70 
71     hw::HwCameraFactoryProduct mHwCamera;
72     std::weak_ptr<CameraDevice> mSelf;
73 };
74 
75 }  // namespace implementation
76 }  // namespace provider
77 }  // namespace camera
78 }  // namespace hardware
79 }  // namespace android
80