1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//#define LOG_NDEBUG 0
#define LOG_TAG "NdkCaptureRequest"
#define ATRACE_TAG ATRACE_TAG_CAMERA
#include <utils/Log.h>
#include <utils/Trace.h>
#include <camera/NdkCaptureRequest.h>
#include "impl/ACameraMetadata.h"
#include "impl/ACaptureRequest.h"
EXPORT
camera_status_t ACameraOutputTarget_create(
ACameraWindowType* window, ACameraOutputTarget** out) {
ATRACE_CALL();
if (window == nullptr) {
ALOGE("%s: Error: input window is null", __FUNCTION__);
return ACAMERA_ERROR_INVALID_PARAMETER;
}
*out = new ACameraOutputTarget(window);
return ACAMERA_OK;
}
EXPORT
void ACameraOutputTarget_free(ACameraOutputTarget* target) {
ATRACE_CALL();
if (target != nullptr) {
delete target;
}
return;
}
EXPORT
camera_status_t ACaptureRequest_addTarget(
ACaptureRequest* req, const ACameraOutputTarget* target) {
ATRACE_CALL();
if (req == nullptr || req->targets == nullptr || target == nullptr) {
void* req_targets;
if (req != nullptr)
req_targets = req->targets;
else
req_targets = nullptr;
ALOGE("%s: Error: invalid input: req %p, req-targets %p, target %p",
__FUNCTION__, req, req_targets, target);
return ACAMERA_ERROR_INVALID_PARAMETER;
}
auto pair = req->targets->mOutputs.insert(*target);
if (!pair.second) {
ALOGW("%s: target %p already exists!", __FUNCTION__, target);
}
return ACAMERA_OK;
}
EXPORT
camera_status_t ACaptureRequest_removeTarget(
ACaptureRequest* req, const ACameraOutputTarget* target) {
ATRACE_CALL();
if (req == nullptr || req->targets == nullptr || target == nullptr) {
void* req_targets;
if (req != nullptr)
req_targets = req->targets;
else
req_targets = nullptr;
ALOGE("%s: Error: invalid input: req %p, req-targets %p, target %p",
__FUNCTION__, req, req_targets, target);
return ACAMERA_ERROR_INVALID_PARAMETER;
}
req->targets->mOutputs.erase(*target);
return ACAMERA_OK;
}
EXPORT
camera_status_t ACaptureRequest_getConstEntry(
const ACaptureRequest* req, uint32_t tag, ACameraMetadata_const_entry* entry) {
ATRACE_CALL();
if (req == nullptr || entry == nullptr) {
ALOGE("%s: invalid argument! req 0x%p, tag 0x%x, entry 0x%p",
__FUNCTION__, req, tag, entry);
return ACAMERA_ERROR_INVALID_PARAMETER;
}
return req->settings->getConstEntry(tag, entry);
}
EXPORT
camera_status_t ACaptureRequest_getConstEntry_physicalCamera(
const ACaptureRequest* req, const char* physicalId,
uint32_t tag, ACameraMetadata_const_entry* entry) {
ATRACE_CALL();
if (req == nullptr || entry == nullptr || physicalId == nullptr) {
ALOGE("%s: invalid argument! req %p, tag 0x%x, entry %p, physicalId %p",
__FUNCTION__, req, tag, entry, physicalId);
return ACAMERA_ERROR_INVALID_PARAMETER;
}
const auto& physicalSettings = req->physicalSettings.find(physicalId);
if (physicalSettings == req->physicalSettings.end()) {
ALOGE("%s: Failed to find metadata for physical camera id %s",
__FUNCTION__, physicalId);
return ACAMERA_ERROR_INVALID_PARAMETER;
}
return physicalSettings->second->getConstEntry(tag, entry);
}
EXPORT
camera_status_t ACaptureRequest_getAllTags(
const ACaptureRequest* req, /*out*/int32_t* numTags, /*out*/const uint32_t** tags) {
ATRACE_CALL();
if (req == nullptr || numTags == nullptr || tags == nullptr) {
ALOGE("%s: invalid argument! request %p, numTags %p, tags %p",
__FUNCTION__, req, numTags, tags);
return ACAMERA_ERROR_INVALID_PARAMETER;
}
return req->settings->getTags(numTags, tags);
}
#define SET_ENTRY(NAME,NDK_TYPE) \
EXPORT \
camera_status_t ACaptureRequest_setEntry_##NAME( \
ACaptureRequest* req, uint32_t tag, uint32_t count, const NDK_TYPE* data) { \
ATRACE_CALL(); \
if (req == nullptr || (count > 0 && data == nullptr)) { \
ALOGE("%s: invalid argument! req %p, tag 0x%x, count %d, data 0x%p", \
__FUNCTION__, req, tag, count, data); \
return ACAMERA_ERROR_INVALID_PARAMETER; \
} \
return req->settings->update(tag, count, data); \
}
SET_ENTRY(u8,uint8_t)
SET_ENTRY(i32,int32_t)
SET_ENTRY(float,float)
SET_ENTRY(double,double)
SET_ENTRY(i64,int64_t)
SET_ENTRY(rational,ACameraMetadata_rational)
#undef SET_ENTRY
#define SET_PHYSICAL_ENTRY(NAME,NDK_TYPE) \
EXPORT \
camera_status_t ACaptureRequest_setEntry_physicalCamera_##NAME( \
ACaptureRequest* req, const char* physicalId, uint32_t tag, \
uint32_t count, const NDK_TYPE* data) { \
ATRACE_CALL(); \
if (req == nullptr || (count > 0 && data == nullptr) || physicalId == nullptr) { \
ALOGE("%s: invalid argument! req %p, tag 0x%x, count %d, data 0x%p, physicalId %p", \
__FUNCTION__, req, tag, count, data, physicalId); \
return ACAMERA_ERROR_INVALID_PARAMETER; \
} \
if (req->physicalSettings.find(physicalId) == req->physicalSettings.end()) { \
ALOGE("%s: Failed to find metadata for physical camera id %s", \
__FUNCTION__, physicalId); \
return ACAMERA_ERROR_INVALID_PARAMETER; \
} \
return req->physicalSettings[physicalId]->update(tag, count, data); \
}
SET_PHYSICAL_ENTRY(u8,uint8_t)
SET_PHYSICAL_ENTRY(i32,int32_t)
SET_PHYSICAL_ENTRY(float,float)
SET_PHYSICAL_ENTRY(double,double)
SET_PHYSICAL_ENTRY(i64,int64_t)
SET_PHYSICAL_ENTRY(rational,ACameraMetadata_rational)
#undef SET_PHYSICAL_ENTRY
EXPORT
void ACaptureRequest_free(ACaptureRequest* request) {
ATRACE_CALL();
if (request == nullptr) {
return;
}
request->settings.clear();
request->physicalSettings.clear();
delete request->targets;
delete request;
return;
}
EXPORT
camera_status_t ACaptureRequest_setUserContext(
ACaptureRequest* request, void* context) {
if (request == nullptr) {
ALOGE("%s: invalid argument! request is NULL", __FUNCTION__);
return ACAMERA_ERROR_INVALID_PARAMETER;
}
return request->setContext(context);
}
EXPORT
camera_status_t ACaptureRequest_getUserContext(
const ACaptureRequest* request, /*out*/void** context) {
if (request == nullptr || context == nullptr) {
ALOGE("%s: invalid argument! request %p, context %p",
__FUNCTION__, request, context);
return ACAMERA_ERROR_INVALID_PARAMETER;
}
return request->getContext(context);
}
EXPORT
ACaptureRequest* ACaptureRequest_copy(const ACaptureRequest* src) {
ATRACE_CALL();
if (src == nullptr) {
ALOGE("%s: src is null!", __FUNCTION__);
return nullptr;
}
ACaptureRequest* pRequest = new ACaptureRequest();
pRequest->settings = new ACameraMetadata(*(src->settings));
for (const auto& entry : src->physicalSettings) {
pRequest->physicalSettings[entry.first] = new ACameraMetadata(*(entry.second));
}
pRequest->targets = new ACameraOutputTargets();
*(pRequest->targets) = *(src->targets);
pRequest->context = src->context;
return pRequest;
}
|