• 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 FRAMEWORKS_AV_SERVICES_CAMERA_LIBCAMERASERVICE_AIDL_AIDLCAMERADEVICEUSER_H_
18 #define FRAMEWORKS_AV_SERVICES_CAMERA_LIBCAMERASERVICE_AIDL_AIDLCAMERADEVICEUSER_H_
19 
20 #include <CameraService.h>
21 #include <aidl/android/frameworks/cameraservice/common/Status.h>
22 #include <aidl/android/frameworks/cameraservice/device/BnCameraDeviceUser.h>
23 #include <aidl/android/frameworks/cameraservice/device/CameraMetadata.h>
24 #include <aidl/android/frameworks/cameraservice/device/OutputConfiguration.h>
25 #include <aidl/android/frameworks/cameraservice/device/PhysicalCameraSettings.h>
26 #include <aidl/android/frameworks/cameraservice/device/SessionConfiguration.h>
27 #include <aidl/android/frameworks/cameraservice/device/StreamConfigurationMode.h>
28 #include <aidl/android/frameworks/cameraservice/device/SubmitInfo.h>
29 #include <aidl/android/frameworks/cameraservice/device/TemplateId.h>
30 #include <aidl/android/hardware/common/fmq/MQDescriptor.h>
31 #include <android/hardware/camera2/ICameraDeviceCallbacks.h>
32 #include <fmq/AidlMessageQueue.h>
33 #include <memory>
34 
35 namespace android::frameworks::cameraservice::device::implementation {
36 
37 using ::aidl::android::hardware::common::fmq::MQDescriptor;
38 using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;
39 using ::android::AidlMessageQueue;
40 using CaptureRequestMetadataQueue = AidlMessageQueue<int8_t, SynchronizedReadWrite>;
41 using CaptureResultMetadataQueue = AidlMessageQueue<int8_t, SynchronizedReadWrite>;
42 
43 // Stable NDK classes
44 using SBnCameraDeviceUser = ::aidl::android::frameworks::cameraservice::device::BnCameraDeviceUser;
45 using SCameraMetadata = ::aidl::android::frameworks::cameraservice::device::CameraMetadata;
46 using SCaptureRequest = ::aidl::android::frameworks::cameraservice::device::CaptureRequest;
47 using SOutputConfiguration =
48         ::aidl::android::frameworks::cameraservice::device::OutputConfiguration;
49 using SPhysicalCameraSettings =
50         ::aidl::android::frameworks::cameraservice::device::PhysicalCameraSettings;
51 using SSessionConfiguration =
52         ::aidl::android::frameworks::cameraservice::device::SessionConfiguration;
53 using SStatus = ::aidl::android::frameworks::cameraservice::common::Status;
54 using SStreamConfigurationMode =
55         ::aidl::android::frameworks::cameraservice::device::StreamConfigurationMode;
56 using SSubmitInfo = ::aidl::android::frameworks::cameraservice::device::SubmitInfo;
57 using STemplateId = ::aidl::android::frameworks::cameraservice::device::TemplateId;
58 // Unstable NDK classes
59 using UCaptureRequest= ::android::hardware::camera2::CaptureRequest;
60 using UICameraDeviceUser = ::android::hardware::camera2::ICameraDeviceUser;
61 
62 static constexpr int32_t REQUEST_ID_NONE = -1;
63 
64 class AidlCameraDeviceUser final : public SBnCameraDeviceUser {
65   public:
66     explicit AidlCameraDeviceUser(const sp<UICameraDeviceUser> &deviceRemote);
67     ~AidlCameraDeviceUser() override = default;
68 
69     ndk::ScopedAStatus beginConfigure() override;
70     ndk::ScopedAStatus cancelRepeatingRequest(int64_t* _aidl_return) override;
71     ndk::ScopedAStatus createDefaultRequest(STemplateId in_templateId,
72                                             SCameraMetadata* _aidl_return) override;
73     ndk::ScopedAStatus createStream(const SOutputConfiguration& in_outputConfiguration,
74                                     int32_t* _aidl_return) override;
75     ndk::ScopedAStatus deleteStream(int32_t in_streamId) override;
76     ndk::ScopedAStatus disconnect() override;
77     ndk::ScopedAStatus endConfigure(SStreamConfigurationMode in_operatingMode,
78                                     const SCameraMetadata& in_sessionParams,
79                                     int64_t in_startTimeNs) override;
80     ndk::ScopedAStatus flush(int64_t* _aidl_return) override;
81     ndk::ScopedAStatus getCaptureRequestMetadataQueue(
82             MQDescriptor<int8_t, SynchronizedReadWrite>* _aidl_return) override;
83     ndk::ScopedAStatus getCaptureResultMetadataQueue(
84             MQDescriptor<int8_t, SynchronizedReadWrite>* _aidl_return) override;
85     ndk::ScopedAStatus isSessionConfigurationSupported(
86             const SSessionConfiguration& in_sessionConfiguration, bool* _aidl_return) override;
87     ndk::ScopedAStatus prepare(int32_t in_streamId) override;
88     ndk::ScopedAStatus submitRequestList(const std::vector<SCaptureRequest>& in_requestList,
89                                          bool in_isRepeating, SSubmitInfo* _aidl_return) override;
90     ndk::ScopedAStatus updateOutputConfiguration(
91             int32_t in_streamId, const SOutputConfiguration& in_outputConfiguration) override;
92     ndk::ScopedAStatus waitUntilIdle() override;
93 
initStatus()94     [[nodiscard]] bool initStatus() const { return mInitSuccess; }
95 
getCaptureResultMetadataQueue()96     std::shared_ptr<CaptureResultMetadataQueue> getCaptureResultMetadataQueue() {
97         return mCaptureResultMetadataQueue;
98     }
99 
100   private:
101     bool initDevice();
102 
103     bool convertRequestFromAidl(const SCaptureRequest &src, UCaptureRequest *dst);
104     bool copyPhysicalCameraSettings(const std::vector<SPhysicalCameraSettings> &src,
105                                     std::vector<CaptureRequest::PhysicalCameraSettings> *dst);
106 
107     const sp<UICameraDeviceUser> mDeviceRemote;
108     std::unique_ptr<CaptureRequestMetadataQueue> mCaptureRequestMetadataQueue = nullptr;
109     std::shared_ptr<CaptureResultMetadataQueue> mCaptureResultMetadataQueue = nullptr;
110     bool mInitSuccess = false;
111     int32_t mRequestId = REQUEST_ID_NONE;
112     int mVndkVersion = -1;
113 };
114 
115 } // namespace android::frameworks::cameraservice::device::implementation
116 
117 #endif  // FRAMEWORKS_AV_SERVICES_CAMERA_LIBCAMERASERVICE_AIDL_AIDLCAMERADEVICEUSER_H_
118