• 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_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 
40 namespace android::hardware::cameraservice::utils::conversion::aidl {
41 
42 using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;
43 using ::android::AidlMessageQueue;
44 using ::android::CameraMetadata;
45 using CaptureResultMetadataQueue = AidlMessageQueue<int8_t, SynchronizedReadWrite>;
46 
47 // VNDK classes
48 using SCameraDeviceStatus = ::aidl::android::frameworks::cameraservice::service::CameraDeviceStatus;
49 using SCameraMetadata = ::aidl::android::frameworks::cameraservice::device::CameraMetadata;
50 using SCameraStatusAndId = ::aidl::android::frameworks::cameraservice::service::CameraStatusAndId;
51 using SCaptureResultExtras =
52         ::aidl::android::frameworks::cameraservice::device::CaptureResultExtras;
53 using SErrorCode = ::aidl::android::frameworks::cameraservice::device::ErrorCode;
54 using SCaptureMetadataInfo = ::aidl::android::frameworks::cameraservice::device::CaptureMetadataInfo;
55 using SOutputConfiguration =
56         ::aidl::android::frameworks::cameraservice::device::OutputConfiguration;
57 using SPhysicalCaptureResultInfo =
58         ::aidl::android::frameworks::cameraservice::device::PhysicalCaptureResultInfo;
59 using SSessionConfiguration =
60         ::aidl::android::frameworks::cameraservice::device::SessionConfiguration;
61 using SStatus = ::aidl::android::frameworks::cameraservice::common::Status;
62 using SStreamConfigurationMode =
63         ::aidl::android::frameworks::cameraservice::device::StreamConfigurationMode;
64 using SSubmitInfo = ::aidl::android::frameworks::cameraservice::device::SubmitInfo;
65 using STemplateId = ::aidl::android::frameworks::cameraservice::device::TemplateId;
66 // NDK classes
67 using UCaptureResultExtras = ::android::hardware::camera2::impl::CaptureResultExtras;
68 using UOutputConfiguration = ::android::hardware::camera2::params::OutputConfiguration;
69 using UPhysicalCaptureResultInfo = ::android::hardware::camera2::impl::PhysicalCaptureResultInfo;
70 using 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
86 void cloneToAidl(const camera_metadata_t *src, SCameraMetadata* dst);
87 
88 bool cloneFromAidl(const SCameraMetadata &src, CameraMetadata *dst);
89 
90 int32_t convertFromAidl(SStreamConfigurationMode streamConfigurationMode);
91 
92 UOutputConfiguration convertFromAidl(const SOutputConfiguration &src);
93 
94 USessionConfiguration convertFromAidl(const SSessionConfiguration &src);
95 
96 int convertFromAidl(SOutputConfiguration::Rotation rotation);
97 
98 int32_t convertFromAidl(STemplateId templateId);
99 
100 void convertToAidl(const hardware::camera2::utils::SubmitInfo &submitInfo,
101                    SSubmitInfo *hSubmitInfo);
102 
103 SStatus convertToAidl(const binder::Status &status);
104 
105 SCaptureResultExtras convertToAidl(const UCaptureResultExtras &captureResultExtras);
106 
107 SErrorCode convertToAidl(int32_t errorCode);
108 
109 std::vector<SPhysicalCaptureResultInfo> convertToAidl(
110         const std::vector<UPhysicalCaptureResultInfo>& src,
111         std::shared_ptr<CaptureResultMetadataQueue>& fmq);
112 
113 SPhysicalCaptureResultInfo convertToAidl(const UPhysicalCaptureResultInfo& src,
114                                          std::shared_ptr<CaptureResultMetadataQueue>& fmq);
115 
116 void convertToAidl(const std::vector<hardware::CameraStatus> &src,
117                    std::vector<SCameraStatusAndId>* dst);
118 
119 SCameraDeviceStatus convertCameraStatusToAidl(int32_t src);
120 
121 bool areBindersEqual(const ndk::SpAIBinder& b1, const ndk::SpAIBinder& b2);
122 
123 status_t filterVndkKeys(int vndkVersion, CameraMetadata &metadata, bool isStatic = true);
124 
125 status_t copySessionCharacteristics(const CameraMetadata& from, CameraMetadata* to,
126                                     int queryVersion);
127 
128 bool areExtensionKeysSupported(const CameraMetadata& metadata);
129 
130 status_t filterExtensionKeys(CameraMetadata* metadata /*out*/);
131 } // namespace android::hardware::cameraservice::utils::conversion::aidl
132 
133 #endif  // FRAMEWORKS_AV_SERVICES_CAMERA_LIBCAMERASERVICE_AIDL_AIDLUTILS_H_
134