| 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 | 
|  | 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 | } |