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 | } |
Jayant Chowdhary | 09b368b | 2023-02-13 06:53:05 +0000 | [diff] [blame^] | 43 | |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 44 | return; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | EXPORT |
| 48 | camera_status_t ACameraCaptureSession_getDevice( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 49 | ACameraCaptureSession* session, ACameraDevice **device) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 50 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 51 | 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 Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 69 | return ACAMERA_OK; |
| 70 | } |
| 71 | |
| 72 | EXPORT |
| 73 | camera_status_t ACameraCaptureSession_capture( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 74 | ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs, |
| 75 | int numRequests, ACaptureRequest** requests, |
| 76 | /*optional*/int* captureSequenceId) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 77 | ATRACE_CALL(); |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 78 | return captureTemplate(session, cbs, numRequests, requests, captureSequenceId); |
| 79 | } |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 80 | |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 81 | EXPORT |
| 82 | camera_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 Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | EXPORT |
| 91 | camera_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 Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 97 | return captureTemplate(session, lcbs, numRequests, requests, captureSequenceId); |
| 98 | } |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 99 | |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 100 | EXPORT |
| 101 | camera_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 Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 109 | |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 110 | EXPORT |
| 111 | camera_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 Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | EXPORT |
| 120 | camera_status_t ACameraCaptureSession_setRepeatingRequest( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 121 | ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs, |
| 122 | int numRequests, ACaptureRequest** requests, |
| 123 | /*optional*/int* captureSequenceId) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 124 | ATRACE_CALL(); |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 125 | return setRepeatingRequestTemplate(session, cbs, numRequests, requests, captureSequenceId); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 126 | } |
| 127 | |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 128 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 129 | EXPORT |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 130 | camera_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 Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 136 | return setRepeatingRequestTemplate(session, lcbs, numRequests, requests, captureSequenceId); |
| 137 | } |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 138 | |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 139 | |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame] | 140 | EXPORT |
| 141 | camera_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 Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | EXPORT |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 151 | camera_status_t ACameraCaptureSession_stopRepeating(ACameraCaptureSession* session) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 152 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 153 | 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 Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | EXPORT |
Yin-Chia Yeh | 309d05d | 2016-03-28 10:15:31 -0700 | [diff] [blame] | 166 | camera_status_t ACameraCaptureSession_abortCaptures(ACameraCaptureSession* session) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 167 | ATRACE_CALL(); |
Yin-Chia Yeh | 309d05d | 2016-03-28 10:15:31 -0700 | [diff] [blame] | 168 | 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 Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 178 | } |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 179 | |
| 180 | EXPORT |
| 181 | camera_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 Chowdhary | 09b368b | 2023-02-13 06:53:05 +0000 | [diff] [blame^] | 195 | EXPORT |
| 196 | camera_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 | |
| 218 | EXPORT |
| 219 | camera_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 | } |