blob: 442e1dd990a984967d2958728774b47775638907 [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
19#include <sys/types.h>
Yin-Chia Yehead91462016-01-06 16:45:08 -080020#include <utils/RefBase.h>
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080021#include <camera/CameraMetadata.h>
22
23#include "NdkCameraMetadata.h"
24
25using namespace android;
26
27/**
28 * ACameraMetadata opaque struct definition
29 * Leave outside of android namespace because it's NDK struct
30 */
Yin-Chia Yehead91462016-01-06 16:45:08 -080031struct ACameraMetadata : public RefBase {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080032 public:
33 typedef enum {
34 ACM_CHARACTERISTICS, // Read only
35 ACM_REQUEST, // Read/Write
36 ACM_RESULT, // Read only
37 } ACAMERA_METADATA_TYPE;
38
39 // Takes ownership of pass-in buffer
40 ACameraMetadata(camera_metadata_t *buffer, ACAMERA_METADATA_TYPE type);
41 // Clone
42 ACameraMetadata(const ACameraMetadata& other) :
43 mData(other.mData), mType(other.mType) {};
44
45 camera_status_t getConstEntry(uint32_t tag, ACameraMetadata_const_entry* entry) const;
46
47 camera_status_t update(uint32_t tag, uint32_t count, const uint8_t* data);
48 camera_status_t update(uint32_t tag, uint32_t count, const int32_t* data);
49 camera_status_t update(uint32_t tag, uint32_t count, const float* data);
50 camera_status_t update(uint32_t tag, uint32_t count, const double* data);
51 camera_status_t update(uint32_t tag, uint32_t count, const int64_t* data);
52 camera_status_t update(uint32_t tag, uint32_t count, const ACameraMetadata_rational* data);
53
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080054 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
Yin-Chia Yehc3603822016-01-18 22:11:19 -080058 void filterStreamConfigurations(); // Hide input streams, translate hal format to NDK formats
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080059
60 template<typename INTERNAL_T, typename NDK_T>
61 camera_status_t updateImpl(uint32_t tag, uint32_t count, const NDK_T* data) {
62 if (mType != ACM_REQUEST) {
63 ALOGE("Error: Write to metadata is only allowed for capture request!");
64 return ACAMERA_ERROR_INVALID_PARAMETER;
65 }
66 if (!isCaptureRequestTag(tag)) {
67 ALOGE("Error: tag %d is not writable!", tag);
68 return ACAMERA_ERROR_INVALID_PARAMETER;
69 }
70
71 // Here we have to use reinterpret_cast because the NDK data type is
72 // exact copy of internal data type but they do not inherit from each other
73 status_t ret = mData.update(tag, reinterpret_cast<const INTERNAL_T*>(data), count);
74 if (ret == OK) {
75 return ACAMERA_OK;
76 } else {
77 return ACAMERA_ERROR_INVALID_PARAMETER;
78 }
79 }
80
81 CameraMetadata mData;
82 const ACAMERA_METADATA_TYPE mType;
83};
84
85#endif // _ACAMERA_METADATA_H