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> |
| 20 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 21 | #include <sys/types.h> |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 22 | #include <utils/Mutex.h> |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 23 | #include <utils/RefBase.h> |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 24 | #include <utils/Vector.h> |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 25 | #include <camera/CameraMetadata.h> |
| 26 | |
| 27 | #include "NdkCameraMetadata.h" |
| 28 | |
| 29 | using namespace android; |
| 30 | |
| 31 | /** |
| 32 | * ACameraMetadata opaque struct definition |
| 33 | * Leave outside of android namespace because it's NDK struct |
| 34 | */ |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 35 | struct ACameraMetadata : public RefBase { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 36 | public: |
| 37 | typedef enum { |
| 38 | ACM_CHARACTERISTICS, // Read only |
| 39 | ACM_REQUEST, // Read/Write |
| 40 | ACM_RESULT, // Read only |
| 41 | } ACAMERA_METADATA_TYPE; |
| 42 | |
| 43 | // Takes ownership of pass-in buffer |
| 44 | ACameraMetadata(camera_metadata_t *buffer, ACAMERA_METADATA_TYPE type); |
| 45 | // Clone |
| 46 | ACameraMetadata(const ACameraMetadata& other) : |
| 47 | mData(other.mData), mType(other.mType) {}; |
| 48 | |
| 49 | camera_status_t getConstEntry(uint32_t tag, ACameraMetadata_const_entry* entry) const; |
| 50 | |
| 51 | camera_status_t update(uint32_t tag, uint32_t count, const uint8_t* data); |
| 52 | camera_status_t update(uint32_t tag, uint32_t count, const int32_t* data); |
| 53 | camera_status_t update(uint32_t tag, uint32_t count, const float* data); |
| 54 | camera_status_t update(uint32_t tag, uint32_t count, const double* data); |
| 55 | camera_status_t update(uint32_t tag, uint32_t count, const int64_t* data); |
| 56 | camera_status_t update(uint32_t tag, uint32_t count, const ACameraMetadata_rational* data); |
| 57 | |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 58 | camera_status_t getTags(/*out*/int32_t* numTags, |
| 59 | /*out*/const uint32_t** tags) const; |
| 60 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 61 | bool isNdkSupportedCapability(const int32_t capability); |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 62 | static inline bool isVendorTag(const uint32_t tag); |
| 63 | static bool isCaptureRequestTag(const uint32_t tag); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 64 | void filterUnsupportedFeatures(); // Hide features not yet supported by NDK |
Yin-Chia Yeh | c360382 | 2016-01-18 22:11:19 -0800 | [diff] [blame] | 65 | void filterStreamConfigurations(); // Hide input streams, translate hal format to NDK formats |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 66 | |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 67 | const CameraMetadata& getInternalData(); |
| 68 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 69 | template<typename INTERNAL_T, typename NDK_T> |
| 70 | camera_status_t updateImpl(uint32_t tag, uint32_t count, const NDK_T* data) { |
| 71 | if (mType != ACM_REQUEST) { |
| 72 | ALOGE("Error: Write to metadata is only allowed for capture request!"); |
| 73 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 74 | } |
| 75 | if (!isCaptureRequestTag(tag)) { |
| 76 | ALOGE("Error: tag %d is not writable!", tag); |
| 77 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 78 | } |
| 79 | |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 80 | Mutex::Autolock _l(mLock); |
| 81 | |
Yin-Chia Yeh | 1d0955c | 2016-05-16 01:14:13 -0700 | [diff] [blame^] | 82 | status_t ret = OK; |
| 83 | if (count == 0 && data == nullptr) { |
| 84 | ret = mData.erase(tag); |
| 85 | } else { |
| 86 | // Here we have to use reinterpret_cast because the NDK data type is |
| 87 | // exact copy of internal data type but they do not inherit from each other |
| 88 | ret = mData.update(tag, reinterpret_cast<const INTERNAL_T*>(data), count); |
| 89 | } |
| 90 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 91 | if (ret == OK) { |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 92 | mTags.clear(); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 93 | return ACAMERA_OK; |
| 94 | } else { |
| 95 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 96 | } |
| 97 | } |
| 98 | |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 99 | private: |
| 100 | // guard access of public APIs: get/update/getTags |
| 101 | mutable Mutex mLock; |
| 102 | CameraMetadata mData; |
| 103 | mutable Vector<uint32_t> mTags; // updated in getTags, cleared by update |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 104 | const ACAMERA_METADATA_TYPE mType; |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 105 | |
| 106 | static std::unordered_set<uint32_t> sSystemTags; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | #endif // _ACAMERA_METADATA_H |