blob: 8d050c4e3f2eb10a71ae7b358670f52e5f757bcd [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>
20
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080021#include <sys/types.h>
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -080022#include <utils/Mutex.h>
Yin-Chia Yehead91462016-01-06 16:45:08 -080023#include <utils/RefBase.h>
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -080024#include <utils/Vector.h>
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080025#include <camera/CameraMetadata.h>
26
27#include "NdkCameraMetadata.h"
28
29using namespace android;
30
31/**
32 * ACameraMetadata opaque struct definition
33 * Leave outside of android namespace because it's NDK struct
34 */
Yin-Chia Yehead91462016-01-06 16:45:08 -080035struct ACameraMetadata : public RefBase {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080036 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 Yeh8aac03f2016-03-03 15:45:23 -080058 camera_status_t getTags(/*out*/int32_t* numTags,
59 /*out*/const uint32_t** tags) const;
60
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080061 bool isNdkSupportedCapability(const int32_t capability);
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -080062 static inline bool isVendorTag(const uint32_t tag);
63 static bool isCaptureRequestTag(const uint32_t tag);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080064 void filterUnsupportedFeatures(); // Hide features not yet supported by NDK
Yin-Chia Yehc3603822016-01-18 22:11:19 -080065 void filterStreamConfigurations(); // Hide input streams, translate hal format to NDK formats
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080066
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -080067 const CameraMetadata& getInternalData();
68
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080069 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 Yeh8aac03f2016-03-03 15:45:23 -080080 Mutex::Autolock _l(mLock);
81
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -070082 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 Yeh0dea57f2015-12-09 16:46:07 -080091 if (ret == OK) {
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -080092 mTags.clear();
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080093 return ACAMERA_OK;
94 } else {
95 return ACAMERA_ERROR_INVALID_PARAMETER;
96 }
97 }
98
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -080099 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 Yeh0dea57f2015-12-09 16:46:07 -0800104 const ACAMERA_METADATA_TYPE mType;
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -0800105
106 static std::unordered_set<uint32_t> sSystemTags;
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800107};
108
109#endif // _ACAMERA_METADATA_H