blob: c89d7ffdca1ef8af9bc494cdc1157d6a980b890c [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_AIDLUTILS_H_
18#define FRAMEWORKS_AV_SERVICES_CAMERA_LIBCAMERASERVICE_AIDL_AIDLUTILS_H_
19
20#include <aidl/android/frameworks/cameraservice/common/Status.h>
21#include <aidl/android/frameworks/cameraservice/device/CameraMetadata.h>
22#include <aidl/android/frameworks/cameraservice/device/CaptureResultExtras.h>
23#include <aidl/android/frameworks/cameraservice/device/ErrorCode.h>
24#include <aidl/android/frameworks/cameraservice/device/CaptureMetadataInfo.h>
25#include <aidl/android/frameworks/cameraservice/device/OutputConfiguration.h>
26#include <aidl/android/frameworks/cameraservice/device/PhysicalCaptureResultInfo.h>
27#include <aidl/android/frameworks/cameraservice/device/SessionConfiguration.h>
28#include <aidl/android/frameworks/cameraservice/device/StreamConfigurationMode.h>
29#include <aidl/android/frameworks/cameraservice/device/SubmitInfo.h>
30#include <aidl/android/frameworks/cameraservice/device/TemplateId.h>
31#include <aidl/android/frameworks/cameraservice/service/CameraDeviceStatus.h>
32#include <aidl/android/frameworks/cameraservice/service/CameraStatusAndId.h>
33#include <android/hardware/ICameraService.h>
34#include <android/hardware/camera2/ICameraDeviceUser.h>
35#include <android/hardware/graphics/bufferqueue/1.0/IGraphicBufferProducer.h>
36#include <camera/CameraMetadata.h>
37#include <fmq/AidlMessageQueue.h>
38#include <hardware/camera.h>
39
40namespace android::hardware::cameraservice::utils::conversion::aidl {
41
42using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;
43using ::android::AidlMessageQueue;
44using ::android::CameraMetadata;
45using CaptureResultMetadataQueue = AidlMessageQueue<int8_t, SynchronizedReadWrite>;
46
47// VNDK classes
48using SCameraDeviceStatus = ::aidl::android::frameworks::cameraservice::service::CameraDeviceStatus;
49using SCameraMetadata = ::aidl::android::frameworks::cameraservice::device::CameraMetadata;
50using SCameraStatusAndId = ::aidl::android::frameworks::cameraservice::service::CameraStatusAndId;
51using SCaptureResultExtras =
52 ::aidl::android::frameworks::cameraservice::device::CaptureResultExtras;
53using SErrorCode = ::aidl::android::frameworks::cameraservice::device::ErrorCode;
54using SCaptureMetadataInfo = ::aidl::android::frameworks::cameraservice::device::CaptureMetadataInfo;
55using SOutputConfiguration =
56 ::aidl::android::frameworks::cameraservice::device::OutputConfiguration;
57using SPhysicalCaptureResultInfo =
58 ::aidl::android::frameworks::cameraservice::device::PhysicalCaptureResultInfo;
59using SSessionConfiguration =
60 ::aidl::android::frameworks::cameraservice::device::SessionConfiguration;
61using SStatus = ::aidl::android::frameworks::cameraservice::common::Status;
62using SStreamConfigurationMode =
63 ::aidl::android::frameworks::cameraservice::device::StreamConfigurationMode;
64using SSubmitInfo = ::aidl::android::frameworks::cameraservice::device::SubmitInfo;
65using STemplateId = ::aidl::android::frameworks::cameraservice::device::TemplateId;
66// NDK classes
67using UCaptureResultExtras = ::android::hardware::camera2::impl::CaptureResultExtras;
68using UOutputConfiguration = ::android::hardware::camera2::params::OutputConfiguration;
69using UPhysicalCaptureResultInfo = ::android::hardware::camera2::impl::PhysicalCaptureResultInfo;
70using USessionConfiguration = ::android::hardware::camera2::params::SessionConfiguration;
71
72// Common macro to log errors returned from stable AIDL calls
73#define LOG_STATUS_ERROR_IF_NOT_OK(status, callName) \
74 if (!(status).isOk()) { \
75 if ((status).getExceptionCode() == EX_SERVICE_SPECIFIC) { \
76 SStatus errStatus = static_cast<SStatus>((status).getServiceSpecificError()); \
77 ALOGE("%s: %s callback failed: %s", __FUNCTION__, callName, \
78 toString(errStatus).c_str()); \
79 } else { \
80 ALOGE("%s: Transaction failed during %s: %d", __FUNCTION__, callName, \
81 (status).getExceptionCode()); \
82 } \
83 }
84
85// Note: existing data in dst will be gone. Caller still owns the memory of src
86void cloneToAidl(const camera_metadata_t *src, SCameraMetadata* dst);
87
88bool cloneFromAidl(const SCameraMetadata &src, CameraMetadata *dst);
89
90int32_t convertFromAidl(SStreamConfigurationMode streamConfigurationMode);
91
92UOutputConfiguration convertFromAidl(const SOutputConfiguration &src);
93
94USessionConfiguration convertFromAidl(const SSessionConfiguration &src);
95
96int convertFromAidl(SOutputConfiguration::Rotation rotation);
97
98int32_t convertFromAidl(STemplateId templateId);
99
100void convertToAidl(const hardware::camera2::utils::SubmitInfo &submitInfo,
101 SSubmitInfo *hSubmitInfo);
102
103SStatus convertToAidl(const binder::Status &status);
104
105SCaptureResultExtras convertToAidl(const UCaptureResultExtras &captureResultExtras);
106
107SErrorCode convertToAidl(int32_t errorCode);
108
109std::vector<SPhysicalCaptureResultInfo> convertToAidl(
110 const std::vector<UPhysicalCaptureResultInfo>& src,
111 std::shared_ptr<CaptureResultMetadataQueue>& fmq);
112
113SPhysicalCaptureResultInfo convertToAidl(const UPhysicalCaptureResultInfo& src,
114 std::shared_ptr<CaptureResultMetadataQueue>& fmq);
115
116void convertToAidl(const std::vector<hardware::CameraStatus> &src,
117 std::vector<SCameraStatusAndId>* dst);
118
119SCameraDeviceStatus convertCameraStatusToAidl(int32_t src);
120
121bool areBindersEqual(const ndk::SpAIBinder& b1, const ndk::SpAIBinder& b2);
122
123status_t filterVndkKeys(int vndkVersion, CameraMetadata &metadata, bool isStatic = true);
124
125} // namespace android::hardware::cameraservice::utils::conversion::aidl
126
127#endif // FRAMEWORKS_AV_SERVICES_CAMERA_LIBCAMERASERVICE_AIDL_AIDLUTILS_H_