• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 ANDROID_SERVERS_CAMERA_CAMERAPROVIDER_AIDLPROVIDERINFOH
18 #define ANDROID_SERVERS_CAMERA_CAMERAPROVIDER_AIDLPROVIDERINFOH
19 
20 #include "common/CameraProviderManager.h"
21 
22 #include <aidl/android/hardware/camera/common/Status.h>
23 #include <aidl/android/hardware/camera/provider/BnCameraProviderCallback.h>
24 #include <aidl/android/hardware/camera/device/ICameraDevice.h>
25 
26 namespace android {
27 
28 struct AidlProviderInfo : public CameraProviderManager::ProviderInfo {
29     // Current overall Android device physical status
30     int64_t mDeviceState;
31 
32     // This pointer is used to keep a reference to the ICameraProvider that was last accessed.
33     std::weak_ptr<aidl::android::hardware::camera::provider::ICameraProvider> mActiveInterface;
34 
35     std::shared_ptr<aidl::android::hardware::camera::provider::ICameraProvider> mSavedInterface;
36 
37     AidlProviderInfo(
38             const std::string &providerName,
39             const std::string &providerInstance,
40             CameraProviderManager *manager);
41 
42     static status_t mapToStatusT(const ndk::ScopedAStatus& s);
43 
44     // Start camera device interface, start the camera provider process for lazy
45     // hals, if needed
46     status_t initializeAidlProvider(
47         std::shared_ptr<aidl::android::hardware::camera::provider::ICameraProvider>& interface,
48         int64_t currentDeviceState);
49 
50     static void binderDied(void *cookie);
51 
getIPCTransportAidlProviderInfo52     virtual IPCTransport getIPCTransport() override {return IPCTransport::AIDL;}
53 
54     const std::shared_ptr<aidl::android::hardware::camera::provider::ICameraProvider>
55     startProviderInterface();
56 
57     virtual status_t setUpVendorTags() override;
58     virtual status_t notifyDeviceStateChange(int64_t newDeviceState) override;
59 
60     virtual bool successfullyStartedProviderInterface() override;
61 
getDeviceStateAidlProviderInfo62     virtual int64_t getDeviceState() override { return mDeviceState; };
63 
64     /**
65      * Query the camera provider for concurrent stream configuration support
66      */
67     virtual status_t isConcurrentSessionConfigurationSupported(
68         const std::vector<CameraIdAndSessionConfiguration> &cameraIdsAndSessionConfigs,
69         const std::set<std::string>& perfClassPrimaryCameraIds,
70         int targetSdkVersion, bool *isSupported) override;
71 
72     std::shared_ptr<aidl::android::hardware::camera::device::ICameraDevice>
73             startDeviceInterface(const std::string &deviceName);
74 
75     // AIDL ICameraProviderCallback interface - these lock the parent
76     // mInterfaceMutex
77 
78     ::ndk::ScopedAStatus cameraDeviceStatusChange(const std::string& cameraDeviceName,
79             ::aidl::android::hardware::camera::common::CameraDeviceStatus newStatus);
80 
81     ::ndk::ScopedAStatus torchModeStatusChange(const std::string& cameraDeviceName,
82             ::aidl::android::hardware::camera::common::TorchModeStatus newStatus);
83 
84     ::ndk::ScopedAStatus physicalCameraDeviceStatusChange(
85             const std::string& cameraDeviceName,
86             const std::string& physicalCameraDeviceName,
87             ::aidl::android::hardware::camera::common::CameraDeviceStatus newStatus);
88 
89     struct AidlProviderCallbacks :
90             public aidl::android::hardware::camera::provider::BnCameraProviderCallback {
AidlProviderCallbacksAidlProviderInfo::AidlProviderCallbacks91         AidlProviderCallbacks(wp<AidlProviderInfo> parent) : mParent(parent) { }
92         virtual ::ndk::ScopedAStatus cameraDeviceStatusChange(const std::string& cameraDeviceName,
93                 ::aidl::android::hardware::camera::common::CameraDeviceStatus newStatus) override;
94 
95         virtual ::ndk::ScopedAStatus torchModeStatusChange(const std::string& cameraDeviceName,
96                 ::aidl::android::hardware::camera::common::TorchModeStatus newStatus) override;
97 
98         virtual ::ndk::ScopedAStatus physicalCameraDeviceStatusChange(
99                 const std::string& cameraDeviceName,
100                 const std::string& physicalCameraDeviceName,
101                 ::aidl::android::hardware::camera::common::CameraDeviceStatus newStatus) override;
102 
103        private:
104         wp<AidlProviderInfo> mParent = nullptr;
105 
106     };
107 
108     struct AidlDeviceInfo3 : public CameraProviderManager::ProviderInfo::DeviceInfo3 {
109 
110         //TODO: fix init
111         const hardware::hidl_version mVersion = hardware::hidl_version{3, 2};
112         std::shared_ptr<aidl::android::hardware::camera::device::ICameraDevice>
113                 mSavedInterface = nullptr;
114 
115         AidlDeviceInfo3(const std::string& , const metadata_vendor_id_t ,
116                 const std::string &, uint16_t ,
117                 const CameraResourceCost& ,
118                 sp<ProviderInfo> ,
119                 const std::vector<std::string>& ,
120                 std::shared_ptr<aidl::android::hardware::camera::device::ICameraDevice>);
121 
~AidlDeviceInfo3AidlProviderInfo::AidlDeviceInfo3122         ~AidlDeviceInfo3() {}
123 
124         virtual status_t setTorchMode(bool enabled) override;
125         virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) override;
126         virtual status_t getTorchStrengthLevel(int32_t *torchStrength) override;
127 
128         virtual status_t dumpState(int fd) override;
129 
130         virtual status_t isSessionConfigurationSupported(
131                 const SessionConfiguration &/*configuration*/,
132                 bool overrideForPerfClass, camera3::metadataGetter /*getMetadata*/,
133                 bool *status/*status*/);
134 
135         std::shared_ptr<aidl::android::hardware::camera::device::ICameraDevice>
136                 startDeviceInterface();
137     };
138 
139  private:
140 
141     // Helper for initializeDeviceInfo to use the right CameraProvider get method.
142     virtual std::unique_ptr<DeviceInfo> initializeDeviceInfo(const std::string &,
143             const metadata_vendor_id_t , const std::string &,
144             uint16_t ) override;
145 
146     virtual status_t reCacheConcurrentStreamingCameraIdsLocked() override;
147 
148     //Expects to have mLock locked
149 
150     status_t getConcurrentCameraIdsInternalLocked(
151         std::shared_ptr<aidl::android::hardware::camera::provider::ICameraProvider> &interface);
152 
153     //expects to have mManager->mInterfaceMutex locked
154 
155     status_t convertToAidlHALStreamCombinationAndCameraIdsLocked(
156         const std::vector<CameraIdAndSessionConfiguration> &cameraIdsAndSessionConfigs,
157         const std::set<std::string>& perfClassPrimaryCameraIds,
158         int targetSdkVersion,
159         std::vector<aidl::android::hardware::camera::provider::CameraIdAndStreamCombination>
160                 *halCameraIdsAndStreamCombinations,
161         bool *earlyExit);
162     std::shared_ptr<AidlProviderCallbacks> mCallbacks = nullptr;
163     ndk::ScopedAIBinder_DeathRecipient mDeathRecipient;
164 
165 };
166 
167 } // namespace android
168 #endif
169