blob: 58370e5fbf7f2fd57af54852fccc2cb83aec9f0e [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 "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
Colin Cross7e8d4ba2017-05-04 16:17:42 -070026#include <camera/NdkCameraDevice.h>
27#include <camera/NdkCaptureRequest.h>
28#include <camera/NdkCameraCaptureSession.h>
Yin-Chia Yehead91462016-01-06 16:45:08 -080029#include "impl/ACameraCaptureSession.h"
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080030
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -080031#include "impl/ACameraCaptureSession.inc"
Avichal Rakeshf099b232022-10-27 15:44:50 -070032
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +000033#include "NdkCameraCaptureSession.inc"
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -080034
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080035using namespace android;
36
37EXPORT
Yin-Chia Yehead91462016-01-06 16:45:08 -080038void ACameraCaptureSession_close(ACameraCaptureSession* session) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080039 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -080040 if (session != nullptr) {
41 session->closeByApp();
42 }
43 return;
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080044}
45
46EXPORT
47camera_status_t ACameraCaptureSession_getDevice(
Yin-Chia Yehead91462016-01-06 16:45:08 -080048 ACameraCaptureSession* session, ACameraDevice **device) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080049 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -080050 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 }
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080068 return ACAMERA_OK;
69}
70
71EXPORT
72camera_status_t ACameraCaptureSession_capture(
Yin-Chia Yehead91462016-01-06 16:45:08 -080073 ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs,
74 int numRequests, ACaptureRequest** requests,
75 /*optional*/int* captureSequenceId) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080076 ATRACE_CALL();
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +000077 return captureTemplate(session, cbs, numRequests, requests, captureSequenceId);
78}
Yin-Chia Yehead91462016-01-06 16:45:08 -080079
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +000080EXPORT
81camera_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);
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -080087}
88
89EXPORT
90camera_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();
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +000096 return captureTemplate(session, lcbs, numRequests, requests, captureSequenceId);
97}
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -080098
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +000099EXPORT
100camera_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}
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800108
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +0000109EXPORT
110camera_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);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800116}
117
118EXPORT
119camera_status_t ACameraCaptureSession_setRepeatingRequest(
Yin-Chia Yehead91462016-01-06 16:45:08 -0800120 ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs,
121 int numRequests, ACaptureRequest** requests,
122 /*optional*/int* captureSequenceId) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800123 ATRACE_CALL();
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +0000124 return setRepeatingRequestTemplate(session, cbs, numRequests, requests, captureSequenceId);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800125}
126
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +0000127
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800128EXPORT
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800129camera_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();
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +0000135 return setRepeatingRequestTemplate(session, lcbs, numRequests, requests, captureSequenceId);
136}
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800137
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800138
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +0000139EXPORT
140camera_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);
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800147}
148
149EXPORT
Yin-Chia Yehead91462016-01-06 16:45:08 -0800150camera_status_t ACameraCaptureSession_stopRepeating(ACameraCaptureSession* session) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800151 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -0800152 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();
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800162}
163
164EXPORT
Yin-Chia Yeh309d05d2016-03-28 10:15:31 -0700165camera_status_t ACameraCaptureSession_abortCaptures(ACameraCaptureSession* session) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800166 ATRACE_CALL();
Yin-Chia Yeh309d05d2016-03-28 10:15:31 -0700167 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();
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800177}
Emilian Peev40ead602017-09-26 15:46:36 +0100178
179EXPORT
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -0700180camera_status_t ACameraCaptureSessionShared_startStreaming(
181 ACameraCaptureSession* /*session*/, ACameraCaptureSession_captureCallbacksV2* /*callbacks*/,
182 int /*numOutputWindows*/, ANativeWindow** /*window*/,
183 int* /*captureSequenceId*/) {
184 ATRACE_CALL();
185 // Todo: need to add implementation
186 return ACAMERA_OK;
187}
188
189EXPORT
190camera_status_t ACameraCaptureSessionShared_logicalCamera_startStreaming(
191 ACameraCaptureSession* /*session*/,
192 ACameraCaptureSession_logicalCamera_captureCallbacksV2* /*callbacks*/,
193 int /*numOutputWindows*/, ANativeWindow** /*windows*/,
194 int* /*captureSequenceId*/) {
195 ATRACE_CALL();
196 // Todo: need to add implementation
197 return ACAMERA_OK;
198}
199
200EXPORT
201camera_status_t ACameraCaptureSessionShared_stopStreaming(ACameraCaptureSession* /*session*/) {
202 ATRACE_CALL();
203 // Todo: need to add implementation
204 return ACAMERA_OK;
205}
206
207EXPORT
Emilian Peev40ead602017-09-26 15:46:36 +0100208camera_status_t ACameraCaptureSession_updateSharedOutput(ACameraCaptureSession* session,
209 ACaptureSessionOutput* output) {
210 ATRACE_CALL();
211 if (session == nullptr) {
212 ALOGE("%s: Error: session is null", __FUNCTION__);
213 return ACAMERA_ERROR_INVALID_PARAMETER;
214 }
215
216 if (session->isClosed()) {
217 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
218 return ACAMERA_ERROR_SESSION_CLOSED;
219 }
220 return session->updateOutputConfiguration(output);
221}
Jayant Chowdhary0f2cb992023-02-17 18:25:53 +0000222
Jayant Chowdhary09b368b2023-02-13 06:53:05 +0000223EXPORT
224camera_status_t ACameraCaptureSession_setWindowPreparedCallback(
Jayant Chowdhary719b4662023-03-14 20:30:57 +0000225 ACameraCaptureSession* session, void *context,
226 ACameraCaptureSession_prepareCallback cb) {
Jayant Chowdhary09b368b2023-02-13 06:53:05 +0000227 ATRACE_CALL();
228 if (session == nullptr || cb == nullptr) {
229 ALOGE("%s: Error: session %p / callback %p is null", __FUNCTION__, session, cb);
230 return ACAMERA_ERROR_INVALID_PARAMETER;
231 }
232
Jayant Chowdhary09b368b2023-02-13 06:53:05 +0000233 if (session->isClosed()) {
234 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
235 return ACAMERA_ERROR_SESSION_CLOSED;
236 }
Jayant Chowdhary719b4662023-03-14 20:30:57 +0000237 session->setWindowPreparedCallback(context, cb);
Jayant Chowdhary09b368b2023-02-13 06:53:05 +0000238 return ACAMERA_OK;
239}
240
241EXPORT
242camera_status_t ACameraCaptureSession_prepareWindow(
243 ACameraCaptureSession* session,
Avichal Rakesh8effe982023-11-13 18:53:40 -0800244 ANativeWindow *window) {
Jayant Chowdhary09b368b2023-02-13 06:53:05 +0000245 ATRACE_CALL();
246 if (session == nullptr || window == nullptr) {
247 ALOGE("%s: Error: session %p / window %p is null", __FUNCTION__, session, window);
248 return ACAMERA_ERROR_INVALID_PARAMETER;
249 }
250
251 if (session->isClosed()) {
252 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
253 return ACAMERA_ERROR_SESSION_CLOSED;
254 }
255 return session->prepare(window);
Jayant Chowdhary0f2cb992023-02-17 18:25:53 +0000256}