blob: e89e620385e81689977313427c594a36efe2a5d0 [file] [log] [blame]
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -08001/*
2 * Copyright (C) 2015 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#ifndef _ACAMERA_METADATA_H
17#define _ACAMERA_METADATA_H
18
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -080019#include <unordered_set>
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -080020#include <vector>
Eino-Ville Talvalab949b612020-02-06 11:08:41 -080021#include <memory>
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -080022
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080023#include <sys/types.h>
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -080024#include <utils/Mutex.h>
Yin-Chia Yehead91462016-01-06 16:45:08 -080025#include <utils/RefBase.h>
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -080026#include <utils/Vector.h>
Jayant Chowdhary6df26072018-11-06 23:55:12 -080027
28#ifdef __ANDROID_VNDK__
29#include <CameraMetadata.h>
Jayant Chowdhary6c37df02024-03-11 20:12:14 +000030#include <aidl/android/frameworks/cameraservice/common/VendorTag.h>
31#include <aidl/android/frameworks/cameraservice/common/VendorTagSection.h>
32#include <aidl/android/frameworks/cameraservice/common/ProviderIdAndVendorTagSections.h>
33#include <VendorTagDescriptor.h>
Jayant Chowdhary6df26072018-11-06 23:55:12 -080034using CameraMetadata = android::hardware::camera::common::V1_0::helper::CameraMetadata;
Jayant Chowdhary6c37df02024-03-11 20:12:14 +000035using ::aidl::android::frameworks::cameraservice::common::ProviderIdAndVendorTagSections;
36using ::android::hardware::camera::common::V1_0::helper::VendorTagDescriptor;
37using ::android::hardware::camera::common::V1_0::helper::VendorTagDescriptorCache;
Jayant Chowdhary6df26072018-11-06 23:55:12 -080038#else
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080039#include <camera/CameraMetadata.h>
Jayant Chowdhary6c37df02024-03-11 20:12:14 +000040#include <camera/VendorTagDescriptor.h>
Jayant Chowdhary6df26072018-11-06 23:55:12 -080041#endif
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080042
Colin Cross7e8d4ba2017-05-04 16:17:42 -070043#include <camera/NdkCameraMetadata.h>
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080044
45using namespace android;
46
47/**
Jiawen Chen9f713e82020-01-15 11:06:13 -050048 * ACameraMetadata is an opaque struct definition.
49 * It is intentionally left outside of the android namespace because it's NDK struct.
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080050 */
Yin-Chia Yehead91462016-01-06 16:45:08 -080051struct ACameraMetadata : public RefBase {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080052 public:
53 typedef enum {
54 ACM_CHARACTERISTICS, // Read only
55 ACM_REQUEST, // Read/Write
56 ACM_RESULT, // Read only
57 } ACAMERA_METADATA_TYPE;
58
Jiawen Chen9f713e82020-01-15 11:06:13 -050059 // Constructs a ACameraMetadata that takes ownership of `buffer`.
60 ACameraMetadata(camera_metadata_t* buffer, ACAMERA_METADATA_TYPE type);
61
Eino-Ville Talvalab949b612020-02-06 11:08:41 -080062 // Constructs a ACameraMetadata that shares its data with something else, like a Java object
63 ACameraMetadata(const std::shared_ptr<CameraMetadata>& cameraMetadata,
64 ACAMERA_METADATA_TYPE type);
Jiawen Chen9f713e82020-01-15 11:06:13 -050065
66 // Copy constructor.
67 //
Eino-Ville Talvalab949b612020-02-06 11:08:41 -080068 // Always makes a deep copy.
Jiawen Chen9f713e82020-01-15 11:06:13 -050069 ACameraMetadata(const ACameraMetadata& other);
70
71 ~ACameraMetadata();
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080072
73 camera_status_t getConstEntry(uint32_t tag, ACameraMetadata_const_entry* entry) const;
74
75 camera_status_t update(uint32_t tag, uint32_t count, const uint8_t* data);
76 camera_status_t update(uint32_t tag, uint32_t count, const int32_t* data);
77 camera_status_t update(uint32_t tag, uint32_t count, const float* data);
78 camera_status_t update(uint32_t tag, uint32_t count, const double* data);
79 camera_status_t update(uint32_t tag, uint32_t count, const int64_t* data);
80 camera_status_t update(uint32_t tag, uint32_t count, const ACameraMetadata_rational* data);
81
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -080082 camera_status_t getTags(/*out*/int32_t* numTags,
83 /*out*/const uint32_t** tags) const;
Jayant Chowdhary6c37df02024-03-11 20:12:14 +000084 camera_status_t
85 getTagFromName(const char *name, uint32_t *tag) const;
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -080086
Yin-Chia Yehe57e9a22018-08-23 15:36:41 -070087 const CameraMetadata& getInternalData() const;
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -080088 bool isLogicalMultiCamera(size_t* count, const char* const** physicalCameraIds) const;
Yin-Chia Yehe57e9a22018-08-23 15:36:41 -070089
90 private:
91
Jiawen Chen9f713e82020-01-15 11:06:13 -050092 // Common code called by constructors.
93 void init();
94
Jayant Chowdhary62899df2019-04-02 16:53:34 -070095 // This function does not check whether the capability passed to it is valid.
96 // The caller must make sure that it is.
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080097 bool isNdkSupportedCapability(const int32_t capability);
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -080098 static inline bool isVendorTag(const uint32_t tag);
99 static bool isCaptureRequestTag(const uint32_t tag);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800100 void filterUnsupportedFeatures(); // Hide features not yet supported by NDK
Yin-Chia Yehc3603822016-01-18 22:11:19 -0800101 void filterStreamConfigurations(); // Hide input streams, translate hal format to NDK formats
Yin-Chia Yehe57e9a22018-08-23 15:36:41 -0700102 void filterDurations(uint32_t tag); // translate hal format to NDK formats
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800103 void derivePhysicalCameraIds(); // Derive array of physical ids.
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -0800104
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800105 template<typename INTERNAL_T, typename NDK_T>
106 camera_status_t updateImpl(uint32_t tag, uint32_t count, const NDK_T* data) {
107 if (mType != ACM_REQUEST) {
108 ALOGE("Error: Write to metadata is only allowed for capture request!");
109 return ACAMERA_ERROR_INVALID_PARAMETER;
110 }
111 if (!isCaptureRequestTag(tag)) {
112 ALOGE("Error: tag %d is not writable!", tag);
113 return ACAMERA_ERROR_INVALID_PARAMETER;
114 }
115
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -0800116 Mutex::Autolock _l(mLock);
117
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -0700118 status_t ret = OK;
119 if (count == 0 && data == nullptr) {
Jiawen Chen9f713e82020-01-15 11:06:13 -0500120 ret = mData->erase(tag);
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -0700121 } else {
122 // Here we have to use reinterpret_cast because the NDK data type is
123 // exact copy of internal data type but they do not inherit from each other
Jiawen Chen9f713e82020-01-15 11:06:13 -0500124 ret = mData->update(tag, reinterpret_cast<const INTERNAL_T*>(data), count);
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -0700125 }
126
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800127 if (ret == OK) {
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -0800128 mTags.clear();
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800129 return ACAMERA_OK;
130 } else {
131 return ACAMERA_ERROR_INVALID_PARAMETER;
132 }
133 }
134
Jiawen Chen9f713e82020-01-15 11:06:13 -0500135 // Guard access of public APIs: get/update/getTags.
136 mutable Mutex mLock;
137
Eino-Ville Talvalab949b612020-02-06 11:08:41 -0800138 std::shared_ptr<CameraMetadata> mData;
Jiawen Chen9f713e82020-01-15 11:06:13 -0500139
140 mutable Vector<uint32_t> mTags; // Updated by `getTags()`, cleared by `update()`.
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800141 const ACAMERA_METADATA_TYPE mType;
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -0800142
143 static std::unordered_set<uint32_t> sSystemTags;
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800144
145 std::vector<const char*> mStaticPhysicalCameraIds;
Emilian Peev1da379a2019-02-05 15:36:31 -0800146 std::vector<String8> mStaticPhysicalCameraIdValues;
Jayant Chowdhary6c37df02024-03-11 20:12:14 +0000147 sp<VendorTagDescriptor> mVTags = nullptr;
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800148};
149
150#endif // _ACAMERA_METADATA_H