blob: 41a3f43b0532b01b46676821414b2d0cc6de0d29 [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;
87 ndk::ScopedAStatus submitRequestList(const std::vector<SCaptureRequest>& in_requestList,
88 bool in_isRepeating, SSubmitInfo* _aidl_return) override;
89 ndk::ScopedAStatus updateOutputConfiguration(
90 int32_t in_streamId, const SOutputConfiguration& in_outputConfiguration) override;
91 ndk::ScopedAStatus waitUntilIdle() override;
92
93 [[nodiscard]] bool initStatus() const { return mInitSuccess; }
94
95 std::shared_ptr<CaptureResultMetadataQueue> getCaptureResultMetadataQueue() {
96 return mCaptureResultMetadataQueue;
97 }
98
99 private:
100 bool initDevice();
101
102 bool convertRequestFromAidl(const SCaptureRequest &src, UCaptureRequest *dst);
103 bool copyPhysicalCameraSettings(const std::vector<SPhysicalCameraSettings> &src,
104 std::vector<CaptureRequest::PhysicalCameraSettings> *dst);
105
106 const sp<UICameraDeviceUser> mDeviceRemote;
107 std::unique_ptr<CaptureRequestMetadataQueue> mCaptureRequestMetadataQueue = nullptr;
108 std::shared_ptr<CaptureResultMetadataQueue> mCaptureResultMetadataQueue = nullptr;
109 bool mInitSuccess = false;
110 int32_t mRequestId = REQUEST_ID_NONE;
111};
112
113} // namespace android::frameworks::cameraservice::device::implementation
114
115#endif // FRAMEWORKS_AV_SERVICES_CAMERA_LIBCAMERASERVICE_AIDL_AIDLCAMERADEVICEUSER_H_