• 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() const 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         std::shared_ptr<aidl::android::hardware::camera::device::ICameraDevice>
111                 mSavedInterface = nullptr;
112 
113         AidlDeviceInfo3(const std::string& , const metadata_vendor_id_t ,
114                 const std::string &, uint16_t ,
115                 const CameraResourceCost& ,
116                 sp<ProviderInfo> ,
117                 const std::vector<std::string>& ,
118                 std::shared_ptr<aidl::android::hardware::camera::device::ICameraDevice>);
119 
~AidlDeviceInfo3AidlProviderInfo::AidlDeviceInfo3120         ~AidlDeviceInfo3() {}
121 
122         virtual status_t setTorchMode(bool enabled) override;
123         virtual status_t turnOnTorchWithStrengthLevel(int32_t torchStrength) override;
124         virtual status_t getTorchStrengthLevel(int32_t *torchStrength) override;
125 
126         virtual status_t dumpState(int fd) override;
127 
128         virtual status_t isSessionConfigurationSupported(
129                 const SessionConfiguration &/*configuration*/,
130                 bool overrideForPerfClass, camera3::metadataGetter getMetadata,
131                 bool checkSessionParams, bool *status/*status*/);
132 
133         virtual status_t createDefaultRequest(
134                     camera3::camera_request_template_t templateId,
135                     CameraMetadata* metadata) override;
136 
137         virtual status_t getSessionCharacteristics(
138                 const SessionConfiguration &/*configuration*/,
139                 bool overrideForPerfClass, camera3::metadataGetter /*getMetadata*/,
140                 CameraMetadata */*outChars*/);
141 
142         std::shared_ptr<aidl::android::hardware::camera::device::ICameraDevice>
143                 startDeviceInterface();
144         std::vector<int32_t> mAdditionalKeysForFeatureQuery;
145     };
146 
147  private:
148 
149     // Helper for initializeDeviceInfo to use the right CameraProvider get method.
150     virtual std::unique_ptr<DeviceInfo> initializeDeviceInfo(const std::string &,
151             const metadata_vendor_id_t , const std::string &,
152             uint16_t ) override;
153 
154     virtual status_t reCacheConcurrentStreamingCameraIdsLocked() override;
155 
156     //Expects to have mLock locked
157 
158     status_t getConcurrentCameraIdsInternalLocked(
159         std::shared_ptr<aidl::android::hardware::camera::provider::ICameraProvider> &interface);
160 
161     //expects to have mManager->mInterfaceMutex locked
162 
163     status_t convertToAidlHALStreamCombinationAndCameraIdsLocked(
164         const std::vector<CameraIdAndSessionConfiguration> &cameraIdsAndSessionConfigs,
165         const std::set<std::string>& perfClassPrimaryCameraIds,
166         int targetSdkVersion,
167         std::vector<aidl::android::hardware::camera::provider::CameraIdAndStreamCombination>
168                 *halCameraIdsAndStreamCombinations,
169         bool *earlyExit);
170     std::shared_ptr<AidlProviderCallbacks> mCallbacks = nullptr;
171     ndk::ScopedAIBinder_DeathRecipient mDeathRecipient;
172 
173 };
174 
175 } // namespace android
176 #endif
177