Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 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 | |
Colin Cross | 7e8d4ba | 2017-05-04 16:17:42 -0700 | [diff] [blame] | 26 | #include <camera/NdkCameraDevice.h> |
| 27 | #include <camera/NdkCaptureRequest.h> |
| 28 | #include <camera/NdkCameraCaptureSession.h> |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 29 | #include "impl/ACameraCaptureSession.h" |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 30 | |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 31 | #include "impl/ACameraCaptureSession.inc" |
Avichal Rakesh | f099b23 | 2022-10-27 15:44:50 -0700 | [diff] [blame] | 32 | |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 33 | #include "NdkCameraCaptureSession.inc" |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 34 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 35 | using namespace android; |
| 36 | |
| 37 | EXPORT |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 38 | void ACameraCaptureSession_close(ACameraCaptureSession* session) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 39 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 40 | if (session != nullptr) { |
| 41 | session->closeByApp(); |
| 42 | } |
| 43 | return; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | EXPORT |
| 47 | camera_status_t ACameraCaptureSession_getDevice( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 48 | ACameraCaptureSession* session, ACameraDevice **device) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 49 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 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 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 68 | return ACAMERA_OK; |
| 69 | } |
| 70 | |
| 71 | EXPORT |
| 72 | camera_status_t ACameraCaptureSession_capture( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 73 | ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs, |
| 74 | int numRequests, ACaptureRequest** requests, |
| 75 | /*optional*/int* captureSequenceId) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 76 | ATRACE_CALL(); |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 77 | return captureTemplate(session, cbs, numRequests, requests, captureSequenceId); |
| 78 | } |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 79 | |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 80 | EXPORT |
| 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); |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | EXPORT |
| 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(); |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 96 | return captureTemplate(session, lcbs, numRequests, requests, captureSequenceId); |
| 97 | } |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 98 | |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 99 | EXPORT |
| 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 | } |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 108 | |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 109 | EXPORT |
| 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); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | EXPORT |
| 119 | camera_status_t ACameraCaptureSession_setRepeatingRequest( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 120 | ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs, |
| 121 | int numRequests, ACaptureRequest** requests, |
| 122 | /*optional*/int* captureSequenceId) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 123 | ATRACE_CALL(); |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 124 | return setRepeatingRequestTemplate(session, cbs, numRequests, requests, captureSequenceId); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 125 | } |
| 126 | |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 127 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 128 | EXPORT |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 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(); |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 135 | return setRepeatingRequestTemplate(session, lcbs, numRequests, requests, captureSequenceId); |
| 136 | } |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 137 | |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 138 | |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 139 | EXPORT |
| 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); |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | EXPORT |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 150 | camera_status_t ACameraCaptureSession_stopRepeating(ACameraCaptureSession* session) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 151 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 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(); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | EXPORT |
Yin-Chia Yeh | 309d05d | 2016-03-28 10:15:31 -0700 | [diff] [blame] | 165 | camera_status_t ACameraCaptureSession_abortCaptures(ACameraCaptureSession* session) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 166 | ATRACE_CALL(); |
Yin-Chia Yeh | 309d05d | 2016-03-28 10:15:31 -0700 | [diff] [blame] | 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(); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 177 | } |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 178 | |
| 179 | EXPORT |
Jyoti Bhayana | 1f9600b | 2024-10-29 20:25:32 -0700 | [diff] [blame] | 180 | camera_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 | |
| 189 | EXPORT |
| 190 | camera_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 | |
| 200 | EXPORT |
| 201 | camera_status_t ACameraCaptureSessionShared_stopStreaming(ACameraCaptureSession* /*session*/) { |
| 202 | ATRACE_CALL(); |
| 203 | // Todo: need to add implementation |
| 204 | return ACAMERA_OK; |
| 205 | } |
| 206 | |
| 207 | EXPORT |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 208 | camera_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 Chowdhary | 0f2cb99 | 2023-02-17 18:25:53 +0000 | [diff] [blame] | 222 | |
Jayant Chowdhary | 09b368b | 2023-02-13 06:53:05 +0000 | [diff] [blame] | 223 | EXPORT |
| 224 | camera_status_t ACameraCaptureSession_setWindowPreparedCallback( |
Jayant Chowdhary | 719b466 | 2023-03-14 20:30:57 +0000 | [diff] [blame] | 225 | ACameraCaptureSession* session, void *context, |
| 226 | ACameraCaptureSession_prepareCallback cb) { |
Jayant Chowdhary | 09b368b | 2023-02-13 06:53:05 +0000 | [diff] [blame] | 227 | 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 Chowdhary | 09b368b | 2023-02-13 06:53:05 +0000 | [diff] [blame] | 233 | if (session->isClosed()) { |
| 234 | ALOGE("%s: session %p is already closed", __FUNCTION__, session); |
| 235 | return ACAMERA_ERROR_SESSION_CLOSED; |
| 236 | } |
Jayant Chowdhary | 719b466 | 2023-03-14 20:30:57 +0000 | [diff] [blame] | 237 | session->setWindowPreparedCallback(context, cb); |
Jayant Chowdhary | 09b368b | 2023-02-13 06:53:05 +0000 | [diff] [blame] | 238 | return ACAMERA_OK; |
| 239 | } |
| 240 | |
| 241 | EXPORT |
| 242 | camera_status_t ACameraCaptureSession_prepareWindow( |
| 243 | ACameraCaptureSession* session, |
Avichal Rakesh | 8effe98 | 2023-11-13 18:53:40 -0800 | [diff] [blame] | 244 | ANativeWindow *window) { |
Jayant Chowdhary | 09b368b | 2023-02-13 06:53:05 +0000 | [diff] [blame] | 245 | 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 Chowdhary | 0f2cb99 | 2023-02-17 18:25:53 +0000 | [diff] [blame] | 256 | } |