blob: 8a3acf3e47743dd41896334bda43b35a9e24ca89 [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 }
Jayant Chowdhary09b368b2023-02-13 06:53:05 +000043
Yin-Chia Yehead91462016-01-06 16:45:08 -080044 return;
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080045}
46
47EXPORT
48camera_status_t ACameraCaptureSession_getDevice(
Yin-Chia Yehead91462016-01-06 16:45:08 -080049 ACameraCaptureSession* session, ACameraDevice **device) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080050 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -080051 if (session == nullptr || device == nullptr) {
52 ALOGE("%s: Error: invalid input: session %p, device %p",
53 __FUNCTION__, session, device);
54 return ACAMERA_ERROR_INVALID_PARAMETER;
55 }
56
57 if (session->isClosed()) {
58 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
59 *device = nullptr;
60 return ACAMERA_ERROR_SESSION_CLOSED;
61 }
62
63 *device = session->getDevice();
64 if (*device == nullptr) {
65 // Should not reach here
66 ALOGE("%s: unknown failure: device is null", __FUNCTION__);
67 return ACAMERA_ERROR_UNKNOWN;
68 }
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080069 return ACAMERA_OK;
70}
71
72EXPORT
73camera_status_t ACameraCaptureSession_capture(
Yin-Chia Yehead91462016-01-06 16:45:08 -080074 ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs,
75 int numRequests, ACaptureRequest** requests,
76 /*optional*/int* captureSequenceId) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080077 ATRACE_CALL();
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +000078 return captureTemplate(session, cbs, numRequests, requests, captureSequenceId);
79}
Yin-Chia Yehead91462016-01-06 16:45:08 -080080
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +000081EXPORT
82camera_status_t ACameraCaptureSession_captureV2(
83 ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacksV2* cbs,
84 int numRequests, ACaptureRequest** requests,
85 /*optional*/int* captureSequenceId) {
86 ATRACE_CALL();
87 return captureTemplate(session, cbs, numRequests, requests, captureSequenceId);
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -080088}
89
90EXPORT
91camera_status_t ACameraCaptureSession_logicalCamera_capture(
92 ACameraCaptureSession* session,
93 /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacks* lcbs,
94 int numRequests, ACaptureRequest** requests,
95 /*optional*/int* captureSequenceId) {
96 ATRACE_CALL();
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +000097 return captureTemplate(session, lcbs, numRequests, requests, captureSequenceId);
98}
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -080099
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +0000100EXPORT
101camera_status_t ACameraCaptureSession_logicalCamera_captureV2(
102 ACameraCaptureSession* session,
103 /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacksV2* lcbs,
104 int numRequests, ACaptureRequest** requests,
105 /*optional*/int* captureSequenceId) {
106 ATRACE_CALL();
107 return captureTemplate(session, lcbs, numRequests, requests, captureSequenceId);
108}
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800109
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +0000110EXPORT
111camera_status_t ACameraCaptureSession_setRepeatingRequestV2(
112 ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacksV2* cbs,
113 int numRequests, ACaptureRequest** requests,
114 /*optional*/int* captureSequenceId) {
115 ATRACE_CALL();
116 return setRepeatingRequestTemplate(session, cbs, numRequests, requests, captureSequenceId);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800117}
118
119EXPORT
120camera_status_t ACameraCaptureSession_setRepeatingRequest(
Yin-Chia Yehead91462016-01-06 16:45:08 -0800121 ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs,
122 int numRequests, ACaptureRequest** requests,
123 /*optional*/int* captureSequenceId) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800124 ATRACE_CALL();
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +0000125 return setRepeatingRequestTemplate(session, cbs, numRequests, requests, captureSequenceId);
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800126}
127
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +0000128
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800129EXPORT
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800130camera_status_t ACameraCaptureSession_logicalCamera_setRepeatingRequest(
131 ACameraCaptureSession* session,
132 /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacks* lcbs,
133 int numRequests, ACaptureRequest** requests,
134 /*optional*/int* captureSequenceId) {
135 ATRACE_CALL();
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +0000136 return setRepeatingRequestTemplate(session, lcbs, numRequests, requests, captureSequenceId);
137}
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800138
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800139
Jayant Chowdhary04ba13f2022-01-14 00:21:19 +0000140EXPORT
141camera_status_t ACameraCaptureSession_logicalCamera_setRepeatingRequestV2(
142 ACameraCaptureSession* session,
143 /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacksV2* lcbs,
144 int numRequests, ACaptureRequest** requests,
145 /*optional*/int* captureSequenceId) {
146 ATRACE_CALL();
147 return setRepeatingRequestTemplate(session, lcbs, numRequests, requests, captureSequenceId);
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800148}
149
150EXPORT
Yin-Chia Yehead91462016-01-06 16:45:08 -0800151camera_status_t ACameraCaptureSession_stopRepeating(ACameraCaptureSession* session) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800152 ATRACE_CALL();
Yin-Chia Yehead91462016-01-06 16:45:08 -0800153 if (session == nullptr) {
154 ALOGE("%s: Error: session is null", __FUNCTION__);
155 return ACAMERA_ERROR_INVALID_PARAMETER;
156 }
157
158 if (session->isClosed()) {
159 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
160 return ACAMERA_ERROR_SESSION_CLOSED;
161 }
162 return session->stopRepeating();
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800163}
164
165EXPORT
Yin-Chia Yeh309d05d2016-03-28 10:15:31 -0700166camera_status_t ACameraCaptureSession_abortCaptures(ACameraCaptureSession* session) {
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800167 ATRACE_CALL();
Yin-Chia Yeh309d05d2016-03-28 10:15:31 -0700168 if (session == nullptr) {
169 ALOGE("%s: Error: session is null", __FUNCTION__);
170 return ACAMERA_ERROR_INVALID_PARAMETER;
171 }
172
173 if (session->isClosed()) {
174 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
175 return ACAMERA_ERROR_SESSION_CLOSED;
176 }
177 return session->abortCaptures();
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -0800178}
Emilian Peev40ead602017-09-26 15:46:36 +0100179
180EXPORT
181camera_status_t ACameraCaptureSession_updateSharedOutput(ACameraCaptureSession* session,
182 ACaptureSessionOutput* output) {
183 ATRACE_CALL();
184 if (session == nullptr) {
185 ALOGE("%s: Error: session is null", __FUNCTION__);
186 return ACAMERA_ERROR_INVALID_PARAMETER;
187 }
188
189 if (session->isClosed()) {
190 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
191 return ACAMERA_ERROR_SESSION_CLOSED;
192 }
193 return session->updateOutputConfiguration(output);
194}
Jayant Chowdhary09b368b2023-02-13 06:53:05 +0000195EXPORT
196camera_status_t ACameraCaptureSession_setWindowPreparedCallback(
197 ACameraCaptureSession* session, ACameraCaptureSession_prepareCallbacks *cb) {
198 ATRACE_CALL();
199 if (session == nullptr || cb == nullptr) {
200 ALOGE("%s: Error: session %p / callback %p is null", __FUNCTION__, session, cb);
201 return ACAMERA_ERROR_INVALID_PARAMETER;
202 }
203
204 if (cb->reserved0 != nullptr || cb->reserved1 != nullptr) {
205 ALOGE("%s: Setting reserved 0 and reserved 1 fields of "
206 "ACameraCaptureSession_prepareCallbacks is currently not supported "
207 " .They must be set to null", __FUNCTION__);
208 return ACAMERA_ERROR_INVALID_PARAMETER;
209 }
210 if (session->isClosed()) {
211 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
212 return ACAMERA_ERROR_SESSION_CLOSED;
213 }
214 session->setWindowPreparedCallback(cb);
215 return ACAMERA_OK;
216}
217
218EXPORT
219camera_status_t ACameraCaptureSession_prepareWindow(
220 ACameraCaptureSession* session,
221 ACameraWindowType *window) {
222 ATRACE_CALL();
223 if (session == nullptr || window == nullptr) {
224 ALOGE("%s: Error: session %p / window %p is null", __FUNCTION__, session, window);
225 return ACAMERA_ERROR_INVALID_PARAMETER;
226 }
227
228 if (session->isClosed()) {
229 ALOGE("%s: session %p is already closed", __FUNCTION__, session);
230 return ACAMERA_ERROR_SESSION_CLOSED;
231 }
232 return session->prepare(window);
233}