Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 1 | /* |
| 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 Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 19 | #include <unordered_set> |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 20 | #include <vector> |
Eino-Ville Talvala | b949b61 | 2020-02-06 11:08:41 -0800 | [diff] [blame] | 21 | #include <memory> |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 22 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 23 | #include <sys/types.h> |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 24 | #include <utils/Mutex.h> |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 25 | #include <utils/RefBase.h> |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 26 | #include <utils/Vector.h> |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 27 | |
| 28 | #ifdef __ANDROID_VNDK__ |
| 29 | #include <CameraMetadata.h> |
| 30 | using CameraMetadata = android::hardware::camera::common::V1_0::helper::CameraMetadata; |
| 31 | #else |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 32 | #include <camera/CameraMetadata.h> |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 33 | #endif |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 34 | |
Colin Cross | 7e8d4ba | 2017-05-04 16:17:42 -0700 | [diff] [blame] | 35 | #include <camera/NdkCameraMetadata.h> |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 36 | |
| 37 | using namespace android; |
| 38 | |
| 39 | /** |
Jiawen Chen | 9f713e8 | 2020-01-15 11:06:13 -0500 | [diff] [blame] | 40 | * ACameraMetadata is an opaque struct definition. |
| 41 | * It is intentionally left outside of the android namespace because it's NDK struct. |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 42 | */ |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 43 | struct ACameraMetadata : public RefBase { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 44 | public: |
| 45 | typedef enum { |
| 46 | ACM_CHARACTERISTICS, // Read only |
| 47 | ACM_REQUEST, // Read/Write |
| 48 | ACM_RESULT, // Read only |
| 49 | } ACAMERA_METADATA_TYPE; |
| 50 | |
Jiawen Chen | 9f713e8 | 2020-01-15 11:06:13 -0500 | [diff] [blame] | 51 | // Constructs a ACameraMetadata that takes ownership of `buffer`. |
| 52 | ACameraMetadata(camera_metadata_t* buffer, ACAMERA_METADATA_TYPE type); |
| 53 | |
Eino-Ville Talvala | b949b61 | 2020-02-06 11:08:41 -0800 | [diff] [blame] | 54 | // Constructs a ACameraMetadata that shares its data with something else, like a Java object |
| 55 | ACameraMetadata(const std::shared_ptr<CameraMetadata>& cameraMetadata, |
| 56 | ACAMERA_METADATA_TYPE type); |
Jiawen Chen | 9f713e8 | 2020-01-15 11:06:13 -0500 | [diff] [blame] | 57 | |
| 58 | // Copy constructor. |
| 59 | // |
Eino-Ville Talvala | b949b61 | 2020-02-06 11:08:41 -0800 | [diff] [blame] | 60 | // Always makes a deep copy. |
Jiawen Chen | 9f713e8 | 2020-01-15 11:06:13 -0500 | [diff] [blame] | 61 | ACameraMetadata(const ACameraMetadata& other); |
| 62 | |
| 63 | ~ACameraMetadata(); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 64 | |
| 65 | camera_status_t getConstEntry(uint32_t tag, ACameraMetadata_const_entry* entry) const; |
| 66 | |
| 67 | camera_status_t update(uint32_t tag, uint32_t count, const uint8_t* data); |
| 68 | camera_status_t update(uint32_t tag, uint32_t count, const int32_t* data); |
| 69 | camera_status_t update(uint32_t tag, uint32_t count, const float* data); |
| 70 | camera_status_t update(uint32_t tag, uint32_t count, const double* data); |
| 71 | camera_status_t update(uint32_t tag, uint32_t count, const int64_t* data); |
| 72 | camera_status_t update(uint32_t tag, uint32_t count, const ACameraMetadata_rational* data); |
| 73 | |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 74 | camera_status_t getTags(/*out*/int32_t* numTags, |
| 75 | /*out*/const uint32_t** tags) const; |
| 76 | |
Yin-Chia Yeh | e57e9a2 | 2018-08-23 15:36:41 -0700 | [diff] [blame] | 77 | const CameraMetadata& getInternalData() const; |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 78 | bool isLogicalMultiCamera(size_t* count, const char* const** physicalCameraIds) const; |
Yin-Chia Yeh | e57e9a2 | 2018-08-23 15:36:41 -0700 | [diff] [blame] | 79 | |
| 80 | private: |
| 81 | |
Jiawen Chen | 9f713e8 | 2020-01-15 11:06:13 -0500 | [diff] [blame] | 82 | // Common code called by constructors. |
| 83 | void init(); |
| 84 | |
Jayant Chowdhary | 62899df | 2019-04-02 16:53:34 -0700 | [diff] [blame] | 85 | // This function does not check whether the capability passed to it is valid. |
| 86 | // The caller must make sure that it is. |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 87 | bool isNdkSupportedCapability(const int32_t capability); |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 88 | static inline bool isVendorTag(const uint32_t tag); |
| 89 | static bool isCaptureRequestTag(const uint32_t tag); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 90 | void filterUnsupportedFeatures(); // Hide features not yet supported by NDK |
Yin-Chia Yeh | c360382 | 2016-01-18 22:11:19 -0800 | [diff] [blame] | 91 | void filterStreamConfigurations(); // Hide input streams, translate hal format to NDK formats |
Yin-Chia Yeh | e57e9a2 | 2018-08-23 15:36:41 -0700 | [diff] [blame] | 92 | void filterDurations(uint32_t tag); // translate hal format to NDK formats |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 93 | void derivePhysicalCameraIds(); // Derive array of physical ids. |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 94 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 95 | template<typename INTERNAL_T, typename NDK_T> |
| 96 | camera_status_t updateImpl(uint32_t tag, uint32_t count, const NDK_T* data) { |
| 97 | if (mType != ACM_REQUEST) { |
| 98 | ALOGE("Error: Write to metadata is only allowed for capture request!"); |
| 99 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 100 | } |
| 101 | if (!isCaptureRequestTag(tag)) { |
| 102 | ALOGE("Error: tag %d is not writable!", tag); |
| 103 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 104 | } |
| 105 | |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 106 | Mutex::Autolock _l(mLock); |
| 107 | |
Yin-Chia Yeh | 1d0955c | 2016-05-16 01:14:13 -0700 | [diff] [blame] | 108 | status_t ret = OK; |
| 109 | if (count == 0 && data == nullptr) { |
Jiawen Chen | 9f713e8 | 2020-01-15 11:06:13 -0500 | [diff] [blame] | 110 | ret = mData->erase(tag); |
Yin-Chia Yeh | 1d0955c | 2016-05-16 01:14:13 -0700 | [diff] [blame] | 111 | } else { |
| 112 | // Here we have to use reinterpret_cast because the NDK data type is |
| 113 | // exact copy of internal data type but they do not inherit from each other |
Jiawen Chen | 9f713e8 | 2020-01-15 11:06:13 -0500 | [diff] [blame] | 114 | ret = mData->update(tag, reinterpret_cast<const INTERNAL_T*>(data), count); |
Yin-Chia Yeh | 1d0955c | 2016-05-16 01:14:13 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 117 | if (ret == OK) { |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 118 | mTags.clear(); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 119 | return ACAMERA_OK; |
| 120 | } else { |
| 121 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 122 | } |
| 123 | } |
| 124 | |
Jiawen Chen | 9f713e8 | 2020-01-15 11:06:13 -0500 | [diff] [blame] | 125 | // Guard access of public APIs: get/update/getTags. |
| 126 | mutable Mutex mLock; |
| 127 | |
Eino-Ville Talvala | b949b61 | 2020-02-06 11:08:41 -0800 | [diff] [blame] | 128 | std::shared_ptr<CameraMetadata> mData; |
Jiawen Chen | 9f713e8 | 2020-01-15 11:06:13 -0500 | [diff] [blame] | 129 | |
| 130 | mutable Vector<uint32_t> mTags; // Updated by `getTags()`, cleared by `update()`. |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 131 | const ACAMERA_METADATA_TYPE mType; |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 132 | |
| 133 | static std::unordered_set<uint32_t> sSystemTags; |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 134 | |
| 135 | std::vector<const char*> mStaticPhysicalCameraIds; |
Emilian Peev | 1da379a | 2019-02-05 15:36:31 -0800 | [diff] [blame] | 136 | std::vector<String8> mStaticPhysicalCameraIdValues; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | #endif // _ACAMERA_METADATA_H |