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 | |
| 19 | #include <sys/types.h> |
| 20 | #include <camera/CameraMetadata.h> |
| 21 | |
| 22 | #include "NdkCameraMetadata.h" |
| 23 | |
| 24 | using namespace android; |
| 25 | |
| 26 | /** |
| 27 | * ACameraMetadata opaque struct definition |
| 28 | * Leave outside of android namespace because it's NDK struct |
| 29 | */ |
| 30 | struct ACameraMetadata { |
| 31 | public: |
| 32 | typedef enum { |
| 33 | ACM_CHARACTERISTICS, // Read only |
| 34 | ACM_REQUEST, // Read/Write |
| 35 | ACM_RESULT, // Read only |
| 36 | } ACAMERA_METADATA_TYPE; |
| 37 | |
| 38 | // Takes ownership of pass-in buffer |
| 39 | ACameraMetadata(camera_metadata_t *buffer, ACAMERA_METADATA_TYPE type); |
| 40 | // Clone |
| 41 | ACameraMetadata(const ACameraMetadata& other) : |
| 42 | mData(other.mData), mType(other.mType) {}; |
| 43 | |
| 44 | camera_status_t getConstEntry(uint32_t tag, ACameraMetadata_const_entry* entry) const; |
| 45 | |
| 46 | camera_status_t update(uint32_t tag, uint32_t count, const uint8_t* data); |
| 47 | camera_status_t update(uint32_t tag, uint32_t count, const int32_t* data); |
| 48 | camera_status_t update(uint32_t tag, uint32_t count, const float* data); |
| 49 | camera_status_t update(uint32_t tag, uint32_t count, const double* data); |
| 50 | camera_status_t update(uint32_t tag, uint32_t count, const int64_t* data); |
| 51 | camera_status_t update(uint32_t tag, uint32_t count, const ACameraMetadata_rational* data); |
| 52 | |
| 53 | private: |
| 54 | bool isNdkSupportedCapability(const int32_t capability); |
| 55 | inline bool isVendorTag(const uint32_t tag); |
| 56 | bool isCaptureRequestTag(const uint32_t tag); |
| 57 | void filterUnsupportedFeatures(); // Hide features not yet supported by NDK |
| 58 | |
| 59 | template<typename INTERNAL_T, typename NDK_T> |
| 60 | camera_status_t updateImpl(uint32_t tag, uint32_t count, const NDK_T* data) { |
| 61 | if (mType != ACM_REQUEST) { |
| 62 | ALOGE("Error: Write to metadata is only allowed for capture request!"); |
| 63 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 64 | } |
| 65 | if (!isCaptureRequestTag(tag)) { |
| 66 | ALOGE("Error: tag %d is not writable!", tag); |
| 67 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 68 | } |
| 69 | |
| 70 | // Here we have to use reinterpret_cast because the NDK data type is |
| 71 | // exact copy of internal data type but they do not inherit from each other |
| 72 | status_t ret = mData.update(tag, reinterpret_cast<const INTERNAL_T*>(data), count); |
| 73 | if (ret == OK) { |
| 74 | return ACAMERA_OK; |
| 75 | } else { |
| 76 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | CameraMetadata mData; |
| 81 | const ACAMERA_METADATA_TYPE mType; |
| 82 | }; |
| 83 | |
| 84 | #endif // _ACAMERA_METADATA_H |