blob: 98608da774fbbc95d163e26fb55f02c6c45873e0 [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
17//#define LOG_NDEBUG 0
18#define LOG_TAG "NdkCameraDevice"
19#define ATRACE_TAG ATRACE_TAG_CAMERA
20
21#include <utils/Log.h>
22#include <utils/Trace.h>
23
Colin Cross7e8d4ba2017-05-04 16:17:42 -070024#include <camera/NdkCameraDevice.h>
Yin-Chia Yehead91462016-01-06 16:45:08 -080025#include "impl/ACameraCaptureSession.h"
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080026
Jayant Chowdhary6df26072018-11-06 23:55:12 -080027using namespace android::acam;
28
29bool areWindowTypesEqual(ACameraWindowType *a, ACameraWindowType *b) {
30#ifdef __ANDROID_VNDK__
31 return utils::isWindowNativeHandleEqual(a, b);
32#else
33 return a == b;
34#endif
35}
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080036
37EXPORT
38camera_status_t ACameraDevice_close(ACameraDevice* device) {
39 ATRACE_CALL();
40 if (device == nullptr) {
41 ALOGE("%s: invalid argument! device is null", __FUNCTION__);
42 return ACAMERA_ERROR_INVALID_PARAMETER;
43 }
44 delete device;
45 return ACAMERA_OK;
46}
47
48EXPORT
49const char* ACameraDevice_getId(const ACameraDevice* device) {
50 ATRACE_CALL();
51 if (device == nullptr) {
52 ALOGE("%s: invalid argument! device is null", __FUNCTION__);
53 return nullptr;
54 }
55 return device->getId();
56}
57
58EXPORT
59camera_status_t ACameraDevice_createCaptureRequest(
60 const ACameraDevice* device,
61 ACameraDevice_request_template templateId,
62 ACaptureRequest** request) {
63 ATRACE_CALL();
64 if (device == nullptr || request == nullptr) {
Yin-Chia Yehead91462016-01-06 16:45:08 -080065 ALOGE("%s: invalid argument! device %p request %p",
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080066 __FUNCTION__, device, request);
67 return ACAMERA_ERROR_INVALID_PARAMETER;
68 }
69 switch (templateId) {
70 case TEMPLATE_PREVIEW:
71 case TEMPLATE_STILL_CAPTURE:
72 case TEMPLATE_RECORD:
73 case TEMPLATE_VIDEO_SNAPSHOT:
74 case TEMPLATE_ZERO_SHUTTER_LAG:
75 case TEMPLATE_MANUAL:
76 break;
77 default:
78 ALOGE("%s: unknown template ID %d", __FUNCTION__, templateId);
79 return ACAMERA_ERROR_INVALID_PARAMETER;
80 }
81 return device->createCaptureRequest(templateId, request);
82}
83
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080084EXPORT
Yin-Chia Yehead91462016-01-06 16:45:08 -080085camera_status_t ACaptureSessionOutputContainer_create(
86 /*out*/ACaptureSessionOutputContainer** out) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080087 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -080088 if (out == nullptr) {
89 ALOGE("%s: Error: out null", __FUNCTION__);
90 return ACAMERA_ERROR_INVALID_PARAMETER;
91 }
92 *out = new ACaptureSessionOutputContainer();
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080093 return ACAMERA_OK;
94}
95
96EXPORT
Yin-Chia Yehead91462016-01-06 16:45:08 -080097void ACaptureSessionOutputContainer_free(ACaptureSessionOutputContainer* container) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080098 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -080099 if (container != nullptr) {
100 delete container;
101 }
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800102 return;
103}
104
105EXPORT
Yin-Chia Yehead91462016-01-06 16:45:08 -0800106camera_status_t ACaptureSessionOutput_create(
Jayant Chowdhary6df26072018-11-06 23:55:12 -0800107 ACameraWindowType* window, /*out*/ACaptureSessionOutput** out) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800108 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -0800109 if (window == nullptr || out == nullptr) {
110 ALOGE("%s: Error: bad argument. window %p, out %p",
111 __FUNCTION__, window, out);
112 return ACAMERA_ERROR_INVALID_PARAMETER;
113 }
Emilian Peev40ead602017-09-26 15:46:36 +0100114 *out = new ACaptureSessionOutput(window, false);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800115 return ACAMERA_OK;
116}
117
118EXPORT
Emilian Peev40ead602017-09-26 15:46:36 +0100119camera_status_t ACaptureSessionSharedOutput_create(
Jayant Chowdhary6df26072018-11-06 23:55:12 -0800120 ACameraWindowType* window, /*out*/ACaptureSessionOutput** out) {
Emilian Peev40ead602017-09-26 15:46:36 +0100121 ATRACE_CALL();
122 if (window == nullptr || out == nullptr) {
123 ALOGE("%s: Error: bad argument. window %p, out %p",
124 __FUNCTION__, window, out);
125 return ACAMERA_ERROR_INVALID_PARAMETER;
126 }
127 *out = new ACaptureSessionOutput(window, true);
128 return ACAMERA_OK;
129}
130
131EXPORT
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800132camera_status_t ACaptureSessionPhysicalOutput_create(
133 ACameraWindowType* window, const char* physicalId,
134 /*out*/ACaptureSessionOutput** out) {
135 ATRACE_CALL();
136 if (window == nullptr || physicalId == nullptr || out == nullptr) {
137 ALOGE("%s: Error: bad argument. window %p, physicalId %p, out %p",
138 __FUNCTION__, window, physicalId, out);
139 return ACAMERA_ERROR_INVALID_PARAMETER;
140 }
141 *out = new ACaptureSessionOutput(window, false, physicalId);
142 return ACAMERA_OK;
143}
144
145EXPORT
Emilian Peev40ead602017-09-26 15:46:36 +0100146camera_status_t ACaptureSessionSharedOutput_add(ACaptureSessionOutput *out,
Jayant Chowdhary6df26072018-11-06 23:55:12 -0800147 ACameraWindowType* window) {
Emilian Peev40ead602017-09-26 15:46:36 +0100148 ATRACE_CALL();
149 if ((window == nullptr) || (out == nullptr)) {
150 ALOGE("%s: Error: bad argument. window %p, out %p",
151 __FUNCTION__, window, out);
152 return ACAMERA_ERROR_INVALID_PARAMETER;
153 }
154 if (!out->mIsShared) {
155 ALOGE("%s: Error trying to insert a new window in non-shared output configuration",
156 __FUNCTION__);
157 return ACAMERA_ERROR_INVALID_OPERATION;
158 }
Jayant Chowdhary6df26072018-11-06 23:55:12 -0800159 if (areWindowTypesEqual(out->mWindow, window)) {
Emilian Peev40ead602017-09-26 15:46:36 +0100160 ALOGE("%s: Error trying to add the same window associated with the output configuration",
161 __FUNCTION__);
162 return ACAMERA_ERROR_INVALID_PARAMETER;
163 }
164
165 auto insert = out->mSharedWindows.insert(window);
166 camera_status_t ret = (insert.second) ? ACAMERA_OK : ACAMERA_ERROR_INVALID_PARAMETER;
167 return ret;
168}
169
170EXPORT
171camera_status_t ACaptureSessionSharedOutput_remove(ACaptureSessionOutput *out,
Jayant Chowdhary6df26072018-11-06 23:55:12 -0800172 ACameraWindowType* window) {
Emilian Peev40ead602017-09-26 15:46:36 +0100173 ATRACE_CALL();
174 if ((window == nullptr) || (out == nullptr)) {
175 ALOGE("%s: Error: bad argument. window %p, out %p",
176 __FUNCTION__, window, out);
177 return ACAMERA_ERROR_INVALID_PARAMETER;
178 }
179 if (!out->mIsShared) {
180 ALOGE("%s: Error trying to remove a window in non-shared output configuration",
181 __FUNCTION__);
182 return ACAMERA_ERROR_INVALID_OPERATION;
183 }
Jayant Chowdhary6df26072018-11-06 23:55:12 -0800184 if (areWindowTypesEqual(out->mWindow, window)) {
Emilian Peev40ead602017-09-26 15:46:36 +0100185 ALOGE("%s: Error trying to remove the same window associated with the output configuration",
186 __FUNCTION__);
187 return ACAMERA_ERROR_INVALID_PARAMETER;
188 }
189
190 auto remove = out->mSharedWindows.erase(window);
191 camera_status_t ret = (remove) ? ACAMERA_OK : ACAMERA_ERROR_INVALID_PARAMETER;
192 return ret;
193}
194
195EXPORT
Yin-Chia Yehead91462016-01-06 16:45:08 -0800196void ACaptureSessionOutput_free(ACaptureSessionOutput* output) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800197 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -0800198 if (output != nullptr) {
199 delete output;
200 }
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800201 return;
202}
203
204EXPORT
205camera_status_t ACaptureSessionOutputContainer_add(
Yin-Chia Yehead91462016-01-06 16:45:08 -0800206 ACaptureSessionOutputContainer* container, const ACaptureSessionOutput* output) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800207 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -0800208 if (container == nullptr || output == nullptr) {
209 ALOGE("%s: Error: invalid input: container %p, output %p",
210 __FUNCTION__, container, output);
211 return ACAMERA_ERROR_INVALID_PARAMETER;
212 }
213 auto pair = container->mOutputs.insert(*output);
214 if (!pair.second) {
215 ALOGW("%s: output %p already exists!", __FUNCTION__, output);
216 }
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800217 return ACAMERA_OK;
218}
219
220EXPORT
221camera_status_t ACaptureSessionOutputContainer_remove(
Yin-Chia Yehead91462016-01-06 16:45:08 -0800222 ACaptureSessionOutputContainer* container, const ACaptureSessionOutput* output) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800223 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -0800224 if (container == nullptr || output == nullptr) {
225 ALOGE("%s: Error: invalid input: container %p, output %p",
226 __FUNCTION__, container, output);
227 return ACAMERA_ERROR_INVALID_PARAMETER;
228 }
229 container->mOutputs.erase(*output);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800230 return ACAMERA_OK;
231}
232
233EXPORT
234camera_status_t ACameraDevice_createCaptureSession(
Yin-Chia Yehead91462016-01-06 16:45:08 -0800235 ACameraDevice* device,
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800236 const ACaptureSessionOutputContainer* outputs,
Yin-Chia Yehead91462016-01-06 16:45:08 -0800237 const ACameraCaptureSession_stateCallbacks* callbacks,
238 /*out*/ACameraCaptureSession** session) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800239 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -0800240 if (device == nullptr || outputs == nullptr || callbacks == nullptr || session == nullptr) {
241 ALOGE("%s: Error: invalid input: device %p, outputs %p, callbacks %p, session %p",
242 __FUNCTION__, device, outputs, callbacks, session);
243 return ACAMERA_ERROR_INVALID_PARAMETER;
244 }
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100245 return device->createCaptureSession(outputs, nullptr, callbacks, session);
246}
247
248EXPORT
249camera_status_t ACameraDevice_createCaptureSessionWithSessionParameters(
250 ACameraDevice* device,
251 const ACaptureSessionOutputContainer* outputs,
252 const ACaptureRequest* sessionParameters,
253 const ACameraCaptureSession_stateCallbacks* callbacks,
254 /*out*/ACameraCaptureSession** session) {
255 ATRACE_CALL();
256 if (device == nullptr || outputs == nullptr || callbacks == nullptr || session == nullptr) {
257 ALOGE("%s: Error: invalid input: device %p, outputs %p, callbacks %p, session %p",
258 __FUNCTION__, device, outputs, callbacks, session);
259 return ACAMERA_ERROR_INVALID_PARAMETER;
260 }
261 return device->createCaptureSession(outputs, sessionParameters, callbacks, session);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800262}