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