blob: 8fa33f731df749e42b7e4356481dc869bad04f31 [file] [log] [blame]
Avichal Rakeshfcb78cb2022-10-27 15:45:54 -07001/*
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
35namespace android::frameworks::cameraservice::device::implementation {
36
37using ::aidl::android::hardware::common::fmq::MQDescriptor;
38using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;
39using ::android::AidlMessageQueue;
40using CaptureRequestMetadataQueue = AidlMessageQueue<int8_t, SynchronizedReadWrite>;
41using CaptureResultMetadataQueue = AidlMessageQueue<int8_t, SynchronizedReadWrite>;
42
43// Stable NDK classes
44using SBnCameraDeviceUser = ::aidl::android::frameworks::cameraservice::device::BnCameraDeviceUser;
45using SCameraMetadata = ::aidl::android::frameworks::cameraservice::device::CameraMetadata;
46using SCaptureRequest = ::aidl::android::frameworks::cameraservice::device::CaptureRequest;
47using SOutputConfiguration =
48 ::aidl::android::frameworks::cameraservice::device::OutputConfiguration;
49using SPhysicalCameraSettings =
50 ::aidl::android::frameworks::cameraservice::device::PhysicalCameraSettings;
51using SSessionConfiguration =
52 ::aidl::android::frameworks::cameraservice::device::SessionConfiguration;
53using SStatus = ::aidl::android::frameworks::cameraservice::common::Status;
54using SStreamConfigurationMode =
55 ::aidl::android::frameworks::cameraservice::device::StreamConfigurationMode;
56using SSubmitInfo = ::aidl::android::frameworks::cameraservice::device::SubmitInfo;
57using STemplateId = ::aidl::android::frameworks::cameraservice::device::TemplateId;
58// Unstable NDK classes
59using UCaptureRequest= ::android::hardware::camera2::CaptureRequest;
60using UICameraDeviceUser = ::android::hardware::camera2::ICameraDeviceUser;
61
62static constexpr int32_t REQUEST_ID_NONE = -1;
63
64class 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;
Jayant Chowdhary09b368b2023-02-13 06:53:05 +000087 ndk::ScopedAStatus prepare(int32_t in_streamId) override;
Avichal Rakeshfcb78cb2022-10-27 15:45:54 -070088 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
94 [[nodiscard]] bool initStatus() const { return mInitSuccess; }
95
96 std::shared_ptr<CaptureResultMetadataQueue> getCaptureResultMetadataQueue() {
97 return mCaptureResultMetadataQueue;
98 }
99
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -0700100 ndk::ScopedAStatus isPrimaryClient(bool* _aidl_return) override;
101
Avichal Rakeshfcb78cb2022-10-27 15:45:54 -0700102 private:
103 bool initDevice();
104
105 bool convertRequestFromAidl(const SCaptureRequest &src, UCaptureRequest *dst);
106 bool copyPhysicalCameraSettings(const std::vector<SPhysicalCameraSettings> &src,
107 std::vector<CaptureRequest::PhysicalCameraSettings> *dst);
108
109 const sp<UICameraDeviceUser> mDeviceRemote;
110 std::unique_ptr<CaptureRequestMetadataQueue> mCaptureRequestMetadataQueue = nullptr;
111 std::shared_ptr<CaptureResultMetadataQueue> mCaptureResultMetadataQueue = nullptr;
112 bool mInitSuccess = false;
113 int32_t mRequestId = REQUEST_ID_NONE;
Euisang Lim0dabcbb2023-04-04 17:38:32 +0900114 int mVndkVersion = -1;
Avichal Rakeshfcb78cb2022-10-27 15:45:54 -0700115};
116
117} // namespace android::frameworks::cameraservice::device::implementation
118
119#endif // FRAMEWORKS_AV_SERVICES_CAMERA_LIBCAMERASERVICE_AIDL_AIDLCAMERADEVICEUSER_H_