• 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 "NdkCameraCaptureSession"
19 #define ATRACE_TAG ATRACE_TAG_CAMERA
20 
21 #include <utils/Log.h>
22 #include <utils/Mutex.h>
23 #include <utils/StrongPointer.h>
24 #include <utils/Trace.h>
25 
26 #include <camera/NdkCameraDevice.h>
27 #include <camera/NdkCaptureRequest.h>
28 #include <camera/NdkCameraCaptureSession.h>
29 #include "impl/ACameraCaptureSession.h"
30 
31 #include "impl/ACameraCaptureSession.inc"
32 
33 #include "NdkCameraCaptureSession.inc"
34 
35 using namespace android;
36 
37 EXPORT
ACameraCaptureSession_close(ACameraCaptureSession * session)38 void ACameraCaptureSession_close(ACameraCaptureSession* session) {
39     ATRACE_CALL();
40     if (session != nullptr) {
41         session->closeByApp();
42     }
43     return;
44 }
45 
46 EXPORT
ACameraCaptureSession_getDevice(ACameraCaptureSession * session,ACameraDevice ** device)47 camera_status_t ACameraCaptureSession_getDevice(
48         ACameraCaptureSession* session, ACameraDevice **device) {
49     ATRACE_CALL();
50     if (session == nullptr || device == nullptr) {
51         ALOGE("%s: Error: invalid input: session %p, device %p",
52                 __FUNCTION__, session, device);
53         return ACAMERA_ERROR_INVALID_PARAMETER;
54     }
55 
56     if (session->isClosed()) {
57         ALOGE("%s: session %p is already closed", __FUNCTION__, session);
58         *device = nullptr;
59         return ACAMERA_ERROR_SESSION_CLOSED;
60     }
61 
62     *device = session->getDevice();
63     if (*device == nullptr) {
64         // Should not reach here
65         ALOGE("%s: unknown failure: device is null", __FUNCTION__);
66         return ACAMERA_ERROR_UNKNOWN;
67     }
68     return ACAMERA_OK;
69 }
70 
71 EXPORT
ACameraCaptureSession_capture(ACameraCaptureSession * session,ACameraCaptureSession_captureCallbacks * cbs,int numRequests,ACaptureRequest ** requests,int * captureSequenceId)72 camera_status_t ACameraCaptureSession_capture(
73         ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs,
74         int numRequests, ACaptureRequest** requests,
75         /*optional*/int* captureSequenceId) {
76     ATRACE_CALL();
77     return captureTemplate(session, cbs, numRequests, requests, captureSequenceId);
78 }
79 
80 EXPORT
ACameraCaptureSession_captureV2(ACameraCaptureSession * session,ACameraCaptureSession_captureCallbacksV2 * cbs,int numRequests,ACaptureRequest ** requests,int * captureSequenceId)81 camera_status_t ACameraCaptureSession_captureV2(
82         ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacksV2* cbs,
83         int numRequests, ACaptureRequest** requests,
84         /*optional*/int* captureSequenceId) {
85     ATRACE_CALL();
86     return captureTemplate(session, cbs, numRequests, requests, captureSequenceId);
87 }
88 
89 EXPORT
ACameraCaptureSession_logicalCamera_capture(ACameraCaptureSession * session,ACameraCaptureSession_logicalCamera_captureCallbacks * lcbs,int numRequests,ACaptureRequest ** requests,int * captureSequenceId)90 camera_status_t ACameraCaptureSession_logicalCamera_capture(
91         ACameraCaptureSession* session,
92         /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacks* lcbs,
93         int numRequests, ACaptureRequest** requests,
94         /*optional*/int* captureSequenceId) {
95     ATRACE_CALL();
96     return captureTemplate(session, lcbs, numRequests, requests, captureSequenceId);
97 }
98 
99 EXPORT
ACameraCaptureSession_logicalCamera_captureV2(ACameraCaptureSession * session,ACameraCaptureSession_logicalCamera_captureCallbacksV2 * lcbs,int numRequests,ACaptureRequest ** requests,int * captureSequenceId)100 camera_status_t ACameraCaptureSession_logicalCamera_captureV2(
101         ACameraCaptureSession* session,
102         /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacksV2* lcbs,
103         int numRequests, ACaptureRequest** requests,
104         /*optional*/int* captureSequenceId) {
105     ATRACE_CALL();
106     return captureTemplate(session, lcbs, numRequests, requests, captureSequenceId);
107 }
108 
109 EXPORT
ACameraCaptureSession_setRepeatingRequestV2(ACameraCaptureSession * session,ACameraCaptureSession_captureCallbacksV2 * cbs,int numRequests,ACaptureRequest ** requests,int * captureSequenceId)110 camera_status_t ACameraCaptureSession_setRepeatingRequestV2(
111         ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacksV2* cbs,
112         int numRequests, ACaptureRequest** requests,
113         /*optional*/int* captureSequenceId) {
114     ATRACE_CALL();
115     return setRepeatingRequestTemplate(session, cbs, numRequests, requests, captureSequenceId);
116 }
117 
118 EXPORT
ACameraCaptureSession_setRepeatingRequest(ACameraCaptureSession * session,ACameraCaptureSession_captureCallbacks * cbs,int numRequests,ACaptureRequest ** requests,int * captureSequenceId)119 camera_status_t ACameraCaptureSession_setRepeatingRequest(
120         ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs,
121         int numRequests, ACaptureRequest** requests,
122         /*optional*/int* captureSequenceId) {
123     ATRACE_CALL();
124     return setRepeatingRequestTemplate(session, cbs, numRequests, requests, captureSequenceId);
125 }
126 
127 
128 EXPORT
ACameraCaptureSession_logicalCamera_setRepeatingRequest(ACameraCaptureSession * session,ACameraCaptureSession_logicalCamera_captureCallbacks * lcbs,int numRequests,ACaptureRequest ** requests,int * captureSequenceId)129 camera_status_t ACameraCaptureSession_logicalCamera_setRepeatingRequest(
130         ACameraCaptureSession* session,
131         /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacks* lcbs,
132         int numRequests, ACaptureRequest** requests,
133         /*optional*/int* captureSequenceId) {
134     ATRACE_CALL();
135     return setRepeatingRequestTemplate(session, lcbs, numRequests, requests, captureSequenceId);
136 }
137 
138 
139 EXPORT
ACameraCaptureSession_logicalCamera_setRepeatingRequestV2(ACameraCaptureSession * session,ACameraCaptureSession_logicalCamera_captureCallbacksV2 * lcbs,int numRequests,ACaptureRequest ** requests,int * captureSequenceId)140 camera_status_t ACameraCaptureSession_logicalCamera_setRepeatingRequestV2(
141         ACameraCaptureSession* session,
142         /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacksV2* lcbs,
143         int numRequests, ACaptureRequest** requests,
144         /*optional*/int* captureSequenceId) {
145     ATRACE_CALL();
146     return setRepeatingRequestTemplate(session, lcbs, numRequests, requests, captureSequenceId);
147 }
148 
149 EXPORT
ACameraCaptureSession_stopRepeating(ACameraCaptureSession * session)150 camera_status_t ACameraCaptureSession_stopRepeating(ACameraCaptureSession* session) {
151     ATRACE_CALL();
152     if (session == nullptr) {
153         ALOGE("%s: Error: session is null", __FUNCTION__);
154         return ACAMERA_ERROR_INVALID_PARAMETER;
155     }
156 
157     if (session->isClosed()) {
158         ALOGE("%s: session %p is already closed", __FUNCTION__, session);
159         return ACAMERA_ERROR_SESSION_CLOSED;
160     }
161     return session->stopRepeating();
162 }
163 
164 EXPORT
ACameraCaptureSession_abortCaptures(ACameraCaptureSession * session)165 camera_status_t ACameraCaptureSession_abortCaptures(ACameraCaptureSession* session) {
166     ATRACE_CALL();
167     if (session == nullptr) {
168         ALOGE("%s: Error: session is null", __FUNCTION__);
169         return ACAMERA_ERROR_INVALID_PARAMETER;
170     }
171 
172     if (session->isClosed()) {
173         ALOGE("%s: session %p is already closed", __FUNCTION__, session);
174         return ACAMERA_ERROR_SESSION_CLOSED;
175     }
176     return session->abortCaptures();
177 }
178 
179 EXPORT
ACameraCaptureSession_updateSharedOutput(ACameraCaptureSession * session,ACaptureSessionOutput * output)180 camera_status_t ACameraCaptureSession_updateSharedOutput(ACameraCaptureSession* session,
181         ACaptureSessionOutput* output) {
182     ATRACE_CALL();
183     if (session == nullptr) {
184         ALOGE("%s: Error: session is null", __FUNCTION__);
185         return ACAMERA_ERROR_INVALID_PARAMETER;
186     }
187 
188     if (session->isClosed()) {
189         ALOGE("%s: session %p is already closed", __FUNCTION__, session);
190         return ACAMERA_ERROR_SESSION_CLOSED;
191     }
192     return session->updateOutputConfiguration(output);
193 }
194 
195 EXPORT
ACameraCaptureSession_setWindowPreparedCallback(ACameraCaptureSession * session,void * context,ACameraCaptureSession_prepareCallback cb)196 camera_status_t ACameraCaptureSession_setWindowPreparedCallback(
197         ACameraCaptureSession* session, void *context,
198         ACameraCaptureSession_prepareCallback cb) {
199     ATRACE_CALL();
200     if (session == nullptr || cb == nullptr) {
201         ALOGE("%s: Error: session %p / callback %p is null", __FUNCTION__, session, cb);
202         return ACAMERA_ERROR_INVALID_PARAMETER;
203     }
204 
205     if (session->isClosed()) {
206         ALOGE("%s: session %p is already closed", __FUNCTION__, session);
207         return ACAMERA_ERROR_SESSION_CLOSED;
208     }
209     session->setWindowPreparedCallback(context, cb);
210     return ACAMERA_OK;
211 }
212 
213 EXPORT
ACameraCaptureSession_prepareWindow(ACameraCaptureSession * session,ANativeWindow * window)214 camera_status_t ACameraCaptureSession_prepareWindow(
215         ACameraCaptureSession* session,
216         ANativeWindow *window) {
217     ATRACE_CALL();
218     if (session == nullptr || window == nullptr) {
219         ALOGE("%s: Error: session %p / window %p is null", __FUNCTION__, session, window);
220         return ACAMERA_ERROR_INVALID_PARAMETER;
221     }
222 
223     if (session->isClosed()) {
224         ALOGE("%s: session %p is already closed", __FUNCTION__, session);
225         return ACAMERA_ERROR_SESSION_CLOSED;
226     }
227     return session->prepare(window);
228 }
229