• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "NdkCameraDevice"
19 #define ATRACE_TAG ATRACE_TAG_CAMERA
20 
21 #include <utils/Log.h>
22 #include <utils/Trace.h>
23 
24 #include <camera/NdkCameraDevice.h>
25 
26 #include "impl/ACameraCaptureSession.h"
27 
28 using namespace android::acam;
29 
30 EXPORT
ACameraDevice_close(ACameraDevice * device)31 camera_status_t ACameraDevice_close(ACameraDevice* device) {
32     ATRACE_CALL();
33     if (device == nullptr) {
34         ALOGE("%s: invalid argument! device is null", __FUNCTION__);
35         return ACAMERA_ERROR_INVALID_PARAMETER;
36     }
37     delete device;
38     return ACAMERA_OK;
39 }
40 
41 EXPORT
ACameraDevice_getId(const ACameraDevice * device)42 const char* ACameraDevice_getId(const ACameraDevice* device) {
43     ATRACE_CALL();
44     if (device == nullptr) {
45         ALOGE("%s: invalid argument! device is null", __FUNCTION__);
46         return nullptr;
47     }
48     return device->getId();
49 }
50 
51 EXPORT
ACameraDevice_createCaptureRequest(const ACameraDevice * device,ACameraDevice_request_template templateId,ACaptureRequest ** request)52 camera_status_t ACameraDevice_createCaptureRequest(
53         const ACameraDevice* device,
54         ACameraDevice_request_template templateId,
55         ACaptureRequest** request) {
56     ATRACE_CALL();
57     if (device == nullptr || request == nullptr) {
58         ALOGE("%s: invalid argument! device %p request %p",
59                 __FUNCTION__, device, request);
60         return ACAMERA_ERROR_INVALID_PARAMETER;
61     }
62     switch (templateId) {
63         case TEMPLATE_PREVIEW:
64         case TEMPLATE_STILL_CAPTURE:
65         case TEMPLATE_RECORD:
66         case TEMPLATE_VIDEO_SNAPSHOT:
67         case TEMPLATE_ZERO_SHUTTER_LAG:
68         case TEMPLATE_MANUAL:
69             break;
70         default:
71             ALOGE("%s: unknown template ID %d", __FUNCTION__, templateId);
72             return ACAMERA_ERROR_INVALID_PARAMETER;
73     }
74     return device->createCaptureRequest(templateId, nullptr /*physicalIdList*/, request);
75 }
76 
77 EXPORT
ACameraDevice_createCaptureRequest_withPhysicalIds(const ACameraDevice * device,ACameraDevice_request_template templateId,const ACameraIdList * physicalCameraIdList,ACaptureRequest ** request)78 camera_status_t ACameraDevice_createCaptureRequest_withPhysicalIds(
79         const ACameraDevice* device,
80         ACameraDevice_request_template templateId,
81         const ACameraIdList* physicalCameraIdList,
82         ACaptureRequest** request) {
83     ATRACE_CALL();
84     if (device == nullptr || request == nullptr || physicalCameraIdList == nullptr) {
85         ALOGE("%s: invalid argument! device %p request %p, physicalCameraIdList %p",
86                 __FUNCTION__, device, request, physicalCameraIdList);
87         return ACAMERA_ERROR_INVALID_PARAMETER;
88     }
89     switch (templateId) {
90         case TEMPLATE_PREVIEW:
91         case TEMPLATE_STILL_CAPTURE:
92         case TEMPLATE_RECORD:
93         case TEMPLATE_VIDEO_SNAPSHOT:
94         case TEMPLATE_ZERO_SHUTTER_LAG:
95         case TEMPLATE_MANUAL:
96             break;
97         default:
98             ALOGE("%s: unknown template ID %d", __FUNCTION__, templateId);
99             return ACAMERA_ERROR_INVALID_PARAMETER;
100     }
101     return device->createCaptureRequest(templateId, physicalCameraIdList, request);
102 }
103 
104 EXPORT
ACaptureSessionOutputContainer_create(ACaptureSessionOutputContainer ** out)105 camera_status_t ACaptureSessionOutputContainer_create(
106         /*out*/ACaptureSessionOutputContainer** out) {
107     ATRACE_CALL();
108     if (out == nullptr) {
109         ALOGE("%s: Error: out null", __FUNCTION__);
110         return ACAMERA_ERROR_INVALID_PARAMETER;
111     }
112     *out = new ACaptureSessionOutputContainer();
113     return ACAMERA_OK;
114 }
115 
116 EXPORT
ACaptureSessionOutputContainer_free(ACaptureSessionOutputContainer * container)117 void ACaptureSessionOutputContainer_free(ACaptureSessionOutputContainer* container) {
118     ATRACE_CALL();
119     if (container != nullptr) {
120         delete container;
121     }
122     return;
123 }
124 
125 EXPORT
ACaptureSessionOutput_create(ANativeWindow * window,ACaptureSessionOutput ** out)126 camera_status_t ACaptureSessionOutput_create(
127         ANativeWindow* window, /*out*/ACaptureSessionOutput** out) {
128     ATRACE_CALL();
129     if (window == nullptr || out == nullptr) {
130         ALOGE("%s: Error: bad argument. window %p, out %p",
131                 __FUNCTION__, window, out);
132         return ACAMERA_ERROR_INVALID_PARAMETER;
133     }
134     *out = new ACaptureSessionOutput(window, false);
135     return ACAMERA_OK;
136 }
137 
138 EXPORT
ACaptureSessionSharedOutput_create(ANativeWindow * window,ACaptureSessionOutput ** out)139 camera_status_t ACaptureSessionSharedOutput_create(
140         ANativeWindow* window, /*out*/ACaptureSessionOutput** out) {
141     ATRACE_CALL();
142     if (window == nullptr || out == nullptr) {
143         ALOGE("%s: Error: bad argument. window %p, out %p",
144                 __FUNCTION__, window, out);
145         return ACAMERA_ERROR_INVALID_PARAMETER;
146     }
147     *out = new ACaptureSessionOutput(window, true);
148     return ACAMERA_OK;
149 }
150 
151 EXPORT
ACaptureSessionPhysicalOutput_create(ANativeWindow * window,const char * physicalId,ACaptureSessionOutput ** out)152 camera_status_t ACaptureSessionPhysicalOutput_create(
153         ANativeWindow* window, const char* physicalId,
154         /*out*/ACaptureSessionOutput** out) {
155     ATRACE_CALL();
156     if (window == nullptr || physicalId == nullptr || out == nullptr) {
157         ALOGE("%s: Error: bad argument. window %p, physicalId %p, out %p",
158                 __FUNCTION__, window, physicalId, out);
159         return ACAMERA_ERROR_INVALID_PARAMETER;
160     }
161     *out = new ACaptureSessionOutput(window, false, physicalId);
162     return ACAMERA_OK;
163 }
164 
165 EXPORT
ACaptureSessionSharedOutput_add(ACaptureSessionOutput * out,ANativeWindow * window)166 camera_status_t ACaptureSessionSharedOutput_add(ACaptureSessionOutput *out,
167         ANativeWindow* window) {
168     ATRACE_CALL();
169     if ((window == nullptr) || (out == nullptr)) {
170         ALOGE("%s: Error: bad argument. window %p, out %p",
171                 __FUNCTION__, window, out);
172         return ACAMERA_ERROR_INVALID_PARAMETER;
173     }
174     if (!out->mIsShared) {
175         ALOGE("%s: Error trying to insert a new window in non-shared output configuration",
176                 __FUNCTION__);
177         return ACAMERA_ERROR_INVALID_OPERATION;
178     }
179     if (out->isWindowEqual(window)) {
180         ALOGE("%s: Error trying to add the same window associated with the output configuration",
181                 __FUNCTION__);
182         return ACAMERA_ERROR_INVALID_PARAMETER;
183     }
184 
185 
186     bool insert = out->addSharedWindow(window);
187     camera_status_t ret = (insert) ? ACAMERA_OK : ACAMERA_ERROR_INVALID_PARAMETER;
188     return ret;
189 }
190 
191 EXPORT
ACaptureSessionSharedOutput_remove(ACaptureSessionOutput * out,ANativeWindow * window)192 camera_status_t ACaptureSessionSharedOutput_remove(ACaptureSessionOutput *out,
193         ANativeWindow* window) {
194     ATRACE_CALL();
195     if ((window == nullptr) || (out == nullptr)) {
196         ALOGE("%s: Error: bad argument. window %p, out %p",
197                 __FUNCTION__, window, out);
198         return ACAMERA_ERROR_INVALID_PARAMETER;
199     }
200     if (!out->mIsShared) {
201         ALOGE("%s: Error trying to remove a  window in non-shared output configuration",
202                 __FUNCTION__);
203         return ACAMERA_ERROR_INVALID_OPERATION;
204     }
205     if (out->isWindowEqual(window)) {
206         ALOGE("%s: Error trying to remove the same window associated with the output configuration",
207                 __FUNCTION__);
208         return ACAMERA_ERROR_INVALID_PARAMETER;
209     }
210 
211     auto remove = out->removeSharedWindow(window);
212     camera_status_t ret = (remove) ? ACAMERA_OK : ACAMERA_ERROR_INVALID_PARAMETER;
213     return ret;
214 }
215 
216 EXPORT
ACaptureSessionOutput_free(ACaptureSessionOutput * output)217 void ACaptureSessionOutput_free(ACaptureSessionOutput* output) {
218     ATRACE_CALL();
219     if (output != nullptr) {
220         delete output;
221     }
222     return;
223 }
224 
225 EXPORT
ACaptureSessionOutputContainer_add(ACaptureSessionOutputContainer * container,const ACaptureSessionOutput * output)226 camera_status_t ACaptureSessionOutputContainer_add(
227         ACaptureSessionOutputContainer* container, const ACaptureSessionOutput* output) {
228     ATRACE_CALL();
229     if (container == nullptr || output == nullptr) {
230         ALOGE("%s: Error: invalid input: container %p, output %p",
231                 __FUNCTION__, container, output);
232         return ACAMERA_ERROR_INVALID_PARAMETER;
233     }
234     auto pair = container->mOutputs.insert(*output);
235     if (!pair.second) {
236         ALOGW("%s: output %p already exists!", __FUNCTION__, output);
237     }
238     return ACAMERA_OK;
239 }
240 
241 EXPORT
ACaptureSessionOutputContainer_remove(ACaptureSessionOutputContainer * container,const ACaptureSessionOutput * output)242 camera_status_t ACaptureSessionOutputContainer_remove(
243         ACaptureSessionOutputContainer* container, const ACaptureSessionOutput* output) {
244     ATRACE_CALL();
245     if (container == nullptr || output == nullptr) {
246         ALOGE("%s: Error: invalid input: container %p, output %p",
247                 __FUNCTION__, container, output);
248         return ACAMERA_ERROR_INVALID_PARAMETER;
249     }
250     container->mOutputs.erase(*output);
251     return ACAMERA_OK;
252 }
253 
254 EXPORT
ACameraDevice_createCaptureSession(ACameraDevice * device,const ACaptureSessionOutputContainer * outputs,const ACameraCaptureSession_stateCallbacks * callbacks,ACameraCaptureSession ** session)255 camera_status_t ACameraDevice_createCaptureSession(
256         ACameraDevice* device,
257         const ACaptureSessionOutputContainer*       outputs,
258         const ACameraCaptureSession_stateCallbacks* callbacks,
259         /*out*/ACameraCaptureSession** session) {
260     ATRACE_CALL();
261     if (device == nullptr || outputs == nullptr || callbacks == nullptr || session == nullptr) {
262         ALOGE("%s: Error: invalid input: device %p, outputs %p, callbacks %p, session %p",
263                 __FUNCTION__, device, outputs, callbacks, session);
264         return ACAMERA_ERROR_INVALID_PARAMETER;
265     }
266     return device->createCaptureSession(outputs, nullptr, callbacks, session);
267 }
268 
269 EXPORT
ACameraDevice_createCaptureSessionWithSessionParameters(ACameraDevice * device,const ACaptureSessionOutputContainer * outputs,const ACaptureRequest * sessionParameters,const ACameraCaptureSession_stateCallbacks * callbacks,ACameraCaptureSession ** session)270 camera_status_t ACameraDevice_createCaptureSessionWithSessionParameters(
271         ACameraDevice* device,
272         const ACaptureSessionOutputContainer*       outputs,
273         const ACaptureRequest* sessionParameters,
274         const ACameraCaptureSession_stateCallbacks* callbacks,
275         /*out*/ACameraCaptureSession** session) {
276     ATRACE_CALL();
277     if (device == nullptr || outputs == nullptr || callbacks == nullptr || session == nullptr) {
278         ALOGE("%s: Error: invalid input: device %p, outputs %p, callbacks %p, session %p",
279                 __FUNCTION__, device, outputs, callbacks, session);
280         return ACAMERA_ERROR_INVALID_PARAMETER;
281     }
282     return device->createCaptureSession(outputs, sessionParameters, callbacks, session);
283 }
284 
285 EXPORT
ACameraDevice_isSessionConfigurationSupported(const ACameraDevice * device,const ACaptureSessionOutputContainer * sessionOutputContainer)286 camera_status_t ACameraDevice_isSessionConfigurationSupported(
287         const ACameraDevice* device,
288         const ACaptureSessionOutputContainer* sessionOutputContainer) {
289     ATRACE_CALL();
290     if (device == nullptr || sessionOutputContainer == nullptr) {
291         ALOGE("%s: Error: invalid input: device %p, sessionOutputContainer %p",
292                 __FUNCTION__, device, sessionOutputContainer);
293         return ACAMERA_ERROR_INVALID_PARAMETER;
294     }
295     return device->isSessionConfigurationSupported(sessionOutputContainer);
296 }
297