ACameraMetadata.h revision ead9146f844ee194a4f4244ba8ae1a3aece12b63
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 <utils/RefBase.h>
21#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 */
31struct ACameraMetadata : public RefBase {
32  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
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
85