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 | |
| 17 | //#define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "NdkCaptureRequest" |
| 19 | #define ATRACE_TAG ATRACE_TAG_CAMERA |
| 20 | |
| 21 | #include <utils/Log.h> |
| 22 | #include <utils/Trace.h> |
| 23 | |
Colin Cross | 7e8d4ba | 2017-05-04 16:17:42 -0700 | [diff] [blame] | 24 | #include <camera/NdkCaptureRequest.h> |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 25 | #include "impl/ACameraMetadata.h" |
| 26 | #include "impl/ACaptureRequest.h" |
| 27 | |
| 28 | EXPORT |
| 29 | camera_status_t ACameraOutputTarget_create( |
Jayant Chowdhary | 6df2607 | 2018-11-06 23:55:12 -0800 | [diff] [blame] | 30 | ACameraWindowType* window, ACameraOutputTarget** out) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 31 | ATRACE_CALL(); |
| 32 | if (window == nullptr) { |
| 33 | ALOGE("%s: Error: input window is null", __FUNCTION__); |
| 34 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 35 | } |
| 36 | *out = new ACameraOutputTarget(window); |
| 37 | return ACAMERA_OK; |
| 38 | } |
| 39 | |
| 40 | EXPORT |
| 41 | void ACameraOutputTarget_free(ACameraOutputTarget* target) { |
| 42 | ATRACE_CALL(); |
| 43 | if (target != nullptr) { |
| 44 | delete target; |
| 45 | } |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | EXPORT |
| 50 | camera_status_t ACaptureRequest_addTarget( |
| 51 | ACaptureRequest* req, const ACameraOutputTarget* target) { |
| 52 | ATRACE_CALL(); |
| 53 | if (req == nullptr || req->targets == nullptr || target == nullptr) { |
Yunlian Jiang | 2169303 | 2016-11-15 17:52:15 -0800 | [diff] [blame] | 54 | void* req_targets; |
| 55 | if (req != nullptr) |
| 56 | req_targets = req->targets; |
| 57 | else |
| 58 | req_targets = nullptr; |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 59 | ALOGE("%s: Error: invalid input: req %p, req-targets %p, target %p", |
Yunlian Jiang | 2169303 | 2016-11-15 17:52:15 -0800 | [diff] [blame] | 60 | __FUNCTION__, req, req_targets, target); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 61 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 62 | } |
| 63 | auto pair = req->targets->mOutputs.insert(*target); |
| 64 | if (!pair.second) { |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 65 | ALOGW("%s: target %p already exists!", __FUNCTION__, target); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 66 | } |
| 67 | return ACAMERA_OK; |
| 68 | } |
| 69 | |
| 70 | EXPORT |
| 71 | camera_status_t ACaptureRequest_removeTarget( |
| 72 | ACaptureRequest* req, const ACameraOutputTarget* target) { |
| 73 | ATRACE_CALL(); |
| 74 | if (req == nullptr || req->targets == nullptr || target == nullptr) { |
Yunlian Jiang | 2169303 | 2016-11-15 17:52:15 -0800 | [diff] [blame] | 75 | void* req_targets; |
| 76 | if (req != nullptr) |
| 77 | req_targets = req->targets; |
| 78 | else |
| 79 | req_targets = nullptr; |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 80 | ALOGE("%s: Error: invalid input: req %p, req-targets %p, target %p", |
Yunlian Jiang | 2169303 | 2016-11-15 17:52:15 -0800 | [diff] [blame] | 81 | __FUNCTION__, req, req_targets, target); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 82 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 83 | } |
| 84 | req->targets->mOutputs.erase(*target); |
| 85 | return ACAMERA_OK; |
| 86 | } |
| 87 | |
| 88 | EXPORT |
| 89 | camera_status_t ACaptureRequest_getConstEntry( |
| 90 | const ACaptureRequest* req, uint32_t tag, ACameraMetadata_const_entry* entry) { |
| 91 | ATRACE_CALL(); |
| 92 | if (req == nullptr || entry == nullptr) { |
| 93 | ALOGE("%s: invalid argument! req 0x%p, tag 0x%x, entry 0x%p", |
| 94 | __FUNCTION__, req, tag, entry); |
| 95 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 96 | } |
| 97 | return req->settings->getConstEntry(tag, entry); |
| 98 | } |
| 99 | |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 100 | EXPORT |
Shuzhen Wang | 6c17e21 | 2019-02-19 14:51:47 -0800 | [diff] [blame] | 101 | camera_status_t ACaptureRequest_getConstEntry_physicalCamera( |
| 102 | const ACaptureRequest* req, const char* physicalId, |
| 103 | uint32_t tag, ACameraMetadata_const_entry* entry) { |
| 104 | ATRACE_CALL(); |
| 105 | if (req == nullptr || entry == nullptr || physicalId == nullptr) { |
| 106 | ALOGE("%s: invalid argument! req %p, tag 0x%x, entry %p, physicalId %p", |
| 107 | __FUNCTION__, req, tag, entry, physicalId); |
| 108 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 109 | } |
| 110 | |
| 111 | const auto& physicalSettings = req->physicalSettings.find(physicalId); |
| 112 | if (physicalSettings == req->physicalSettings.end()) { |
| 113 | ALOGE("%s: Failed to find metadata for physical camera id %s", |
| 114 | __FUNCTION__, physicalId); |
| 115 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 116 | } |
| 117 | |
| 118 | return physicalSettings->second->getConstEntry(tag, entry); |
| 119 | } |
| 120 | |
| 121 | EXPORT |
Yin-Chia Yeh | 8aac03f | 2016-03-03 15:45:23 -0800 | [diff] [blame] | 122 | camera_status_t ACaptureRequest_getAllTags( |
| 123 | const ACaptureRequest* req, /*out*/int32_t* numTags, /*out*/const uint32_t** tags) { |
| 124 | ATRACE_CALL(); |
| 125 | if (req == nullptr || numTags == nullptr || tags == nullptr) { |
| 126 | ALOGE("%s: invalid argument! request %p, numTags %p, tags %p", |
| 127 | __FUNCTION__, req, numTags, tags); |
| 128 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 129 | } |
| 130 | return req->settings->getTags(numTags, tags); |
| 131 | } |
| 132 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 133 | #define SET_ENTRY(NAME,NDK_TYPE) \ |
| 134 | EXPORT \ |
| 135 | camera_status_t ACaptureRequest_setEntry_##NAME( \ |
| 136 | ACaptureRequest* req, uint32_t tag, uint32_t count, const NDK_TYPE* data) { \ |
| 137 | ATRACE_CALL(); \ |
| 138 | if (req == nullptr || (count > 0 && data == nullptr)) { \ |
| 139 | ALOGE("%s: invalid argument! req %p, tag 0x%x, count %d, data 0x%p", \ |
| 140 | __FUNCTION__, req, tag, count, data); \ |
| 141 | return ACAMERA_ERROR_INVALID_PARAMETER; \ |
| 142 | } \ |
| 143 | return req->settings->update(tag, count, data); \ |
| 144 | } |
| 145 | |
| 146 | SET_ENTRY(u8,uint8_t) |
| 147 | SET_ENTRY(i32,int32_t) |
| 148 | SET_ENTRY(float,float) |
| 149 | SET_ENTRY(double,double) |
| 150 | SET_ENTRY(i64,int64_t) |
| 151 | SET_ENTRY(rational,ACameraMetadata_rational) |
| 152 | |
| 153 | #undef SET_ENTRY |
| 154 | |
Shuzhen Wang | 6c17e21 | 2019-02-19 14:51:47 -0800 | [diff] [blame] | 155 | #define SET_PHYSICAL_ENTRY(NAME,NDK_TYPE) \ |
| 156 | EXPORT \ |
| 157 | camera_status_t ACaptureRequest_setEntry_physicalCamera_##NAME( \ |
| 158 | ACaptureRequest* req, const char* physicalId, uint32_t tag, \ |
| 159 | uint32_t count, const NDK_TYPE* data) { \ |
| 160 | ATRACE_CALL(); \ |
| 161 | if (req == nullptr || (count > 0 && data == nullptr) || physicalId == nullptr) { \ |
| 162 | ALOGE("%s: invalid argument! req %p, tag 0x%x, count %d, data 0x%p, physicalId %p", \ |
| 163 | __FUNCTION__, req, tag, count, data, physicalId); \ |
| 164 | return ACAMERA_ERROR_INVALID_PARAMETER; \ |
| 165 | } \ |
| 166 | if (req->physicalSettings.find(physicalId) == req->physicalSettings.end()) { \ |
| 167 | ALOGE("%s: Failed to find metadata for physical camera id %s", \ |
| 168 | __FUNCTION__, physicalId); \ |
| 169 | return ACAMERA_ERROR_INVALID_PARAMETER; \ |
| 170 | } \ |
| 171 | return req->physicalSettings[physicalId]->update(tag, count, data); \ |
| 172 | } |
| 173 | |
| 174 | SET_PHYSICAL_ENTRY(u8,uint8_t) |
| 175 | SET_PHYSICAL_ENTRY(i32,int32_t) |
| 176 | SET_PHYSICAL_ENTRY(float,float) |
| 177 | SET_PHYSICAL_ENTRY(double,double) |
| 178 | SET_PHYSICAL_ENTRY(i64,int64_t) |
| 179 | SET_PHYSICAL_ENTRY(rational,ACameraMetadata_rational) |
| 180 | |
| 181 | #undef SET_PHYSICAL_ENTRY |
| 182 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 183 | EXPORT |
| 184 | void ACaptureRequest_free(ACaptureRequest* request) { |
| 185 | ATRACE_CALL(); |
| 186 | if (request == nullptr) { |
| 187 | return; |
| 188 | } |
Yin-Chia Yeh | dd045bf | 2018-08-20 12:39:19 -0700 | [diff] [blame] | 189 | request->settings.clear(); |
Shuzhen Wang | 6c17e21 | 2019-02-19 14:51:47 -0800 | [diff] [blame] | 190 | request->physicalSettings.clear(); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 191 | delete request->targets; |
| 192 | delete request; |
| 193 | return; |
| 194 | } |
Yin-Chia Yeh | d39b9e3 | 2017-10-30 17:39:23 -0700 | [diff] [blame] | 195 | |
| 196 | EXPORT |
| 197 | camera_status_t ACaptureRequest_setUserContext( |
| 198 | ACaptureRequest* request, void* context) { |
| 199 | if (request == nullptr) { |
| 200 | ALOGE("%s: invalid argument! request is NULL", __FUNCTION__); |
| 201 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 202 | } |
| 203 | return request->setContext(context); |
| 204 | } |
| 205 | |
| 206 | EXPORT |
| 207 | camera_status_t ACaptureRequest_getUserContext( |
| 208 | const ACaptureRequest* request, /*out*/void** context) { |
| 209 | if (request == nullptr || context == nullptr) { |
| 210 | ALOGE("%s: invalid argument! request %p, context %p", |
| 211 | __FUNCTION__, request, context); |
| 212 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 213 | } |
| 214 | return request->getContext(context); |
| 215 | } |
| 216 | |
| 217 | EXPORT |
| 218 | ACaptureRequest* ACaptureRequest_copy(const ACaptureRequest* src) { |
| 219 | ATRACE_CALL(); |
| 220 | if (src == nullptr) { |
| 221 | ALOGE("%s: src is null!", __FUNCTION__); |
| 222 | return nullptr; |
| 223 | } |
| 224 | |
| 225 | ACaptureRequest* pRequest = new ACaptureRequest(); |
| 226 | pRequest->settings = new ACameraMetadata(*(src->settings)); |
Shuzhen Wang | 6c17e21 | 2019-02-19 14:51:47 -0800 | [diff] [blame] | 227 | for (const auto& entry : src->physicalSettings) { |
| 228 | pRequest->physicalSettings[entry.first] = new ACameraMetadata(*(entry.second)); |
| 229 | } |
Yin-Chia Yeh | d39b9e3 | 2017-10-30 17:39:23 -0700 | [diff] [blame] | 230 | pRequest->targets = new ACameraOutputTargets(); |
| 231 | *(pRequest->targets) = *(src->targets); |
| 232 | pRequest->context = src->context; |
| 233 | return pRequest; |
| 234 | } |