blob: f21dbaf1ba94dc54602d911bcee7b9ca2303e33f [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>
Jayant Chowdhary6df26072018-11-06 23:55:12 -080025
26#ifdef __ANDROID_VNDK__
27#include <CameraMetadata.h>
28using CameraMetadata = android::hardware::camera::common::V1_0::helper::CameraMetadata;
29#else
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080030#include <camera/CameraMetadata.h>
Jayant Chowdhary6df26072018-11-06 23:55:12 -080031#endif
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080032
Colin Cross7e8d4ba2017-05-04 16:17:42 -070033#include <camera/NdkCameraMetadata.h>
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080034
35using namespace android;
36
37/**
38 * ACameraMetadata opaque struct definition
39 * Leave outside of android namespace because it's NDK struct
40 */
Yin-Chia Yehead91462016-01-06 16:45:08 -080041struct ACameraMetadata : public RefBase {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080042 public:
43 typedef enum {
44 ACM_CHARACTERISTICS, // Read only
45 ACM_REQUEST, // Read/Write
46 ACM_RESULT, // Read only
47 } ACAMERA_METADATA_TYPE;
48
49 // Takes ownership of pass-in buffer
50 ACameraMetadata(camera_metadata_t *buffer, ACAMERA_METADATA_TYPE type);
51 // Clone
52 ACameraMetadata(const ACameraMetadata& other) :
53 mData(other.mData), mType(other.mType) {};
54
55 camera_status_t getConstEntry(uint32_t tag, ACameraMetadata_const_entry* entry) const;
56
57 camera_status_t update(uint32_t tag, uint32_t count, const uint8_t* data);
58 camera_status_t update(uint32_t tag, uint32_t count, const int32_t* data);
59 camera_status_t update(uint32_t tag, uint32_t count, const float* data);
60 camera_status_t update(uint32_t tag, uint32_t count, const double* data);
61 camera_status_t update(uint32_t tag, uint32_t count, const int64_t* data);
62 camera_status_t update(uint32_t tag, uint32_t count, const ACameraMetadata_rational* data);
63
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -080064 camera_status_t getTags(/*out*/int32_t* numTags,
65 /*out*/const uint32_t** tags) const;
66
Yin-Chia Yehe57e9a22018-08-23 15:36:41 -070067 const CameraMetadata& getInternalData() const;
68
69 private:
70
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080071 bool isNdkSupportedCapability(const int32_t capability);
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -080072 static inline bool isVendorTag(const uint32_t tag);
73 static bool isCaptureRequestTag(const uint32_t tag);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080074 void filterUnsupportedFeatures(); // Hide features not yet supported by NDK
Yin-Chia Yehc3603822016-01-18 22:11:19 -080075 void filterStreamConfigurations(); // Hide input streams, translate hal format to NDK formats
Yin-Chia Yehe57e9a22018-08-23 15:36:41 -070076 void filterDurations(uint32_t tag); // translate hal format to NDK formats
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -080077
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080078 template<typename INTERNAL_T, typename NDK_T>
79 camera_status_t updateImpl(uint32_t tag, uint32_t count, const NDK_T* data) {
80 if (mType != ACM_REQUEST) {
81 ALOGE("Error: Write to metadata is only allowed for capture request!");
82 return ACAMERA_ERROR_INVALID_PARAMETER;
83 }
84 if (!isCaptureRequestTag(tag)) {
85 ALOGE("Error: tag %d is not writable!", tag);
86 return ACAMERA_ERROR_INVALID_PARAMETER;
87 }
88
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -080089 Mutex::Autolock _l(mLock);
90
Yin-Chia Yeh1d0955c2016-05-16 01:14:13 -070091 status_t ret = OK;
92 if (count == 0 && data == nullptr) {
93 ret = mData.erase(tag);
94 } else {
95 // Here we have to use reinterpret_cast because the NDK data type is
96 // exact copy of internal data type but they do not inherit from each other
97 ret = mData.update(tag, reinterpret_cast<const INTERNAL_T*>(data), count);
98 }
99
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800100 if (ret == OK) {
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -0800101 mTags.clear();
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800102 return ACAMERA_OK;
103 } else {
104 return ACAMERA_ERROR_INVALID_PARAMETER;
105 }
106 }
107
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -0800108 // guard access of public APIs: get/update/getTags
109 mutable Mutex mLock;
110 CameraMetadata mData;
111 mutable Vector<uint32_t> mTags; // updated in getTags, cleared by update
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800112 const ACAMERA_METADATA_TYPE mType;
Yin-Chia Yeh8aac03f2016-03-03 15:45:23 -0800113
114 static std::unordered_set<uint32_t> sSystemTags;
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800115};
116
117#endif // _ACAMERA_METADATA_H