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" |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame^] | 32 | #include "NdkCameraCaptureSession.inc" |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 33 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 34 | using namespace android; |
| 35 | |
| 36 | EXPORT |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 37 | void ACameraCaptureSession_close(ACameraCaptureSession* session) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 38 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 39 | if (session != nullptr) { |
| 40 | session->closeByApp(); |
| 41 | } |
| 42 | return; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | EXPORT |
| 46 | camera_status_t ACameraCaptureSession_getDevice( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 47 | ACameraCaptureSession* session, ACameraDevice **device) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 48 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 49 | if (session == nullptr || device == nullptr) { |
| 50 | ALOGE("%s: Error: invalid input: session %p, device %p", |
| 51 | __FUNCTION__, session, device); |
| 52 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 53 | } |
| 54 | |
| 55 | if (session->isClosed()) { |
| 56 | ALOGE("%s: session %p is already closed", __FUNCTION__, session); |
| 57 | *device = nullptr; |
| 58 | return ACAMERA_ERROR_SESSION_CLOSED; |
| 59 | } |
| 60 | |
| 61 | *device = session->getDevice(); |
| 62 | if (*device == nullptr) { |
| 63 | // Should not reach here |
| 64 | ALOGE("%s: unknown failure: device is null", __FUNCTION__); |
| 65 | return ACAMERA_ERROR_UNKNOWN; |
| 66 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 67 | return ACAMERA_OK; |
| 68 | } |
| 69 | |
| 70 | EXPORT |
| 71 | camera_status_t ACameraCaptureSession_capture( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 72 | ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs, |
| 73 | int numRequests, ACaptureRequest** requests, |
| 74 | /*optional*/int* captureSequenceId) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 75 | ATRACE_CALL(); |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame^] | 76 | return captureTemplate(session, cbs, numRequests, requests, captureSequenceId); |
| 77 | } |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 78 | |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame^] | 79 | EXPORT |
| 80 | camera_status_t ACameraCaptureSession_captureV2( |
| 81 | ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacksV2* cbs, |
| 82 | int numRequests, ACaptureRequest** requests, |
| 83 | /*optional*/int* captureSequenceId) { |
| 84 | ATRACE_CALL(); |
| 85 | return captureTemplate(session, cbs, numRequests, requests, captureSequenceId); |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | EXPORT |
| 89 | camera_status_t ACameraCaptureSession_logicalCamera_capture( |
| 90 | ACameraCaptureSession* session, |
| 91 | /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacks* lcbs, |
| 92 | int numRequests, ACaptureRequest** requests, |
| 93 | /*optional*/int* captureSequenceId) { |
| 94 | ATRACE_CALL(); |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame^] | 95 | return captureTemplate(session, lcbs, numRequests, requests, captureSequenceId); |
| 96 | } |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 97 | |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame^] | 98 | EXPORT |
| 99 | camera_status_t ACameraCaptureSession_logicalCamera_captureV2( |
| 100 | ACameraCaptureSession* session, |
| 101 | /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacksV2* lcbs, |
| 102 | int numRequests, ACaptureRequest** requests, |
| 103 | /*optional*/int* captureSequenceId) { |
| 104 | ATRACE_CALL(); |
| 105 | return captureTemplate(session, lcbs, numRequests, requests, captureSequenceId); |
| 106 | } |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 107 | |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame^] | 108 | EXPORT |
| 109 | camera_status_t ACameraCaptureSession_setRepeatingRequestV2( |
| 110 | ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacksV2* cbs, |
| 111 | int numRequests, ACaptureRequest** requests, |
| 112 | /*optional*/int* captureSequenceId) { |
| 113 | ATRACE_CALL(); |
| 114 | return setRepeatingRequestTemplate(session, cbs, numRequests, requests, captureSequenceId); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | EXPORT |
| 118 | camera_status_t ACameraCaptureSession_setRepeatingRequest( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 119 | ACameraCaptureSession* session, /*optional*/ACameraCaptureSession_captureCallbacks* cbs, |
| 120 | int numRequests, ACaptureRequest** requests, |
| 121 | /*optional*/int* captureSequenceId) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 122 | ATRACE_CALL(); |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame^] | 123 | return setRepeatingRequestTemplate(session, cbs, numRequests, requests, captureSequenceId); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 124 | } |
| 125 | |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame^] | 126 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 127 | EXPORT |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 128 | camera_status_t ACameraCaptureSession_logicalCamera_setRepeatingRequest( |
| 129 | ACameraCaptureSession* session, |
| 130 | /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacks* lcbs, |
| 131 | int numRequests, ACaptureRequest** requests, |
| 132 | /*optional*/int* captureSequenceId) { |
| 133 | ATRACE_CALL(); |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame^] | 134 | return setRepeatingRequestTemplate(session, lcbs, numRequests, requests, captureSequenceId); |
| 135 | } |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 136 | |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 137 | |
Jayant Chowdhary | 04ba13f | 2022-01-14 00:21:19 +0000 | [diff] [blame^] | 138 | EXPORT |
| 139 | camera_status_t ACameraCaptureSession_logicalCamera_setRepeatingRequestV2( |
| 140 | ACameraCaptureSession* session, |
| 141 | /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacksV2* lcbs, |
| 142 | int numRequests, ACaptureRequest** requests, |
| 143 | /*optional*/int* captureSequenceId) { |
| 144 | ATRACE_CALL(); |
| 145 | return setRepeatingRequestTemplate(session, lcbs, numRequests, requests, captureSequenceId); |
Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | EXPORT |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 149 | camera_status_t ACameraCaptureSession_stopRepeating(ACameraCaptureSession* session) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 150 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 151 | if (session == nullptr) { |
| 152 | ALOGE("%s: Error: session is null", __FUNCTION__); |
| 153 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 154 | } |
| 155 | |
| 156 | if (session->isClosed()) { |
| 157 | ALOGE("%s: session %p is already closed", __FUNCTION__, session); |
| 158 | return ACAMERA_ERROR_SESSION_CLOSED; |
| 159 | } |
| 160 | return session->stopRepeating(); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | EXPORT |
Yin-Chia Yeh | 309d05d | 2016-03-28 10:15:31 -0700 | [diff] [blame] | 164 | camera_status_t ACameraCaptureSession_abortCaptures(ACameraCaptureSession* session) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 165 | ATRACE_CALL(); |
Yin-Chia Yeh | 309d05d | 2016-03-28 10:15:31 -0700 | [diff] [blame] | 166 | if (session == nullptr) { |
| 167 | ALOGE("%s: Error: session is null", __FUNCTION__); |
| 168 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 169 | } |
| 170 | |
| 171 | if (session->isClosed()) { |
| 172 | ALOGE("%s: session %p is already closed", __FUNCTION__, session); |
| 173 | return ACAMERA_ERROR_SESSION_CLOSED; |
| 174 | } |
| 175 | return session->abortCaptures(); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 176 | } |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 177 | |
| 178 | EXPORT |
| 179 | camera_status_t ACameraCaptureSession_updateSharedOutput(ACameraCaptureSession* session, |
| 180 | ACaptureSessionOutput* output) { |
| 181 | ATRACE_CALL(); |
| 182 | if (session == nullptr) { |
| 183 | ALOGE("%s: Error: session is null", __FUNCTION__); |
| 184 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 185 | } |
| 186 | |
| 187 | if (session->isClosed()) { |
| 188 | ALOGE("%s: session %p is already closed", __FUNCTION__, session); |
| 189 | return ACAMERA_ERROR_SESSION_CLOSED; |
| 190 | } |
| 191 | return session->updateOutputConfiguration(output); |
| 192 | } |