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 "NdkCameraDevice" |
| 19 | #define ATRACE_TAG ATRACE_TAG_CAMERA |
| 20 | |
| 21 | #include <utils/Log.h> |
| 22 | #include <utils/Trace.h> |
| 23 | |
Colin Cross | 7e8d4ba | 2017-05-04 16:17:42 -0700 | [diff] [blame] | 24 | #include <camera/NdkCameraDevice.h> |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 25 | #include "impl/ACameraCaptureSession.h" |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 26 | |
| 27 | using namespace android; |
| 28 | |
| 29 | EXPORT |
| 30 | camera_status_t ACameraDevice_close(ACameraDevice* device) { |
| 31 | ATRACE_CALL(); |
| 32 | if (device == nullptr) { |
| 33 | ALOGE("%s: invalid argument! device is null", __FUNCTION__); |
| 34 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 35 | } |
| 36 | delete device; |
| 37 | return ACAMERA_OK; |
| 38 | } |
| 39 | |
| 40 | EXPORT |
| 41 | const char* ACameraDevice_getId(const ACameraDevice* device) { |
| 42 | ATRACE_CALL(); |
| 43 | if (device == nullptr) { |
| 44 | ALOGE("%s: invalid argument! device is null", __FUNCTION__); |
| 45 | return nullptr; |
| 46 | } |
| 47 | return device->getId(); |
| 48 | } |
| 49 | |
| 50 | EXPORT |
| 51 | camera_status_t ACameraDevice_createCaptureRequest( |
| 52 | const ACameraDevice* device, |
| 53 | ACameraDevice_request_template templateId, |
| 54 | ACaptureRequest** request) { |
| 55 | ATRACE_CALL(); |
| 56 | if (device == nullptr || request == nullptr) { |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 57 | ALOGE("%s: invalid argument! device %p request %p", |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 58 | __FUNCTION__, device, request); |
| 59 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 60 | } |
| 61 | switch (templateId) { |
| 62 | case TEMPLATE_PREVIEW: |
| 63 | case TEMPLATE_STILL_CAPTURE: |
| 64 | case TEMPLATE_RECORD: |
| 65 | case TEMPLATE_VIDEO_SNAPSHOT: |
| 66 | case TEMPLATE_ZERO_SHUTTER_LAG: |
| 67 | case TEMPLATE_MANUAL: |
| 68 | break; |
| 69 | default: |
| 70 | ALOGE("%s: unknown template ID %d", __FUNCTION__, templateId); |
| 71 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 72 | } |
| 73 | return device->createCaptureRequest(templateId, request); |
| 74 | } |
| 75 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 76 | EXPORT |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 77 | camera_status_t ACaptureSessionOutputContainer_create( |
| 78 | /*out*/ACaptureSessionOutputContainer** out) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 79 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 80 | if (out == nullptr) { |
| 81 | ALOGE("%s: Error: out null", __FUNCTION__); |
| 82 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 83 | } |
| 84 | *out = new ACaptureSessionOutputContainer(); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 85 | return ACAMERA_OK; |
| 86 | } |
| 87 | |
| 88 | EXPORT |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 89 | void ACaptureSessionOutputContainer_free(ACaptureSessionOutputContainer* container) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 90 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 91 | if (container != nullptr) { |
| 92 | delete container; |
| 93 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 94 | return; |
| 95 | } |
| 96 | |
| 97 | EXPORT |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 98 | camera_status_t ACaptureSessionOutput_create( |
| 99 | ANativeWindow* window, /*out*/ACaptureSessionOutput** out) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 100 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 101 | if (window == nullptr || out == nullptr) { |
| 102 | ALOGE("%s: Error: bad argument. window %p, out %p", |
| 103 | __FUNCTION__, window, out); |
| 104 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 105 | } |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 106 | *out = new ACaptureSessionOutput(window, false); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 107 | return ACAMERA_OK; |
| 108 | } |
| 109 | |
| 110 | EXPORT |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 111 | camera_status_t ACaptureSessionSharedOutput_create( |
| 112 | ANativeWindow* window, /*out*/ACaptureSessionOutput** out) { |
| 113 | ATRACE_CALL(); |
| 114 | if (window == nullptr || out == nullptr) { |
| 115 | ALOGE("%s: Error: bad argument. window %p, out %p", |
| 116 | __FUNCTION__, window, out); |
| 117 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 118 | } |
| 119 | *out = new ACaptureSessionOutput(window, true); |
| 120 | return ACAMERA_OK; |
| 121 | } |
| 122 | |
| 123 | EXPORT |
| 124 | camera_status_t ACaptureSessionSharedOutput_add(ACaptureSessionOutput *out, |
| 125 | ANativeWindow* window) { |
| 126 | ATRACE_CALL(); |
| 127 | if ((window == nullptr) || (out == nullptr)) { |
| 128 | ALOGE("%s: Error: bad argument. window %p, out %p", |
| 129 | __FUNCTION__, window, out); |
| 130 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 131 | } |
| 132 | if (!out->mIsShared) { |
| 133 | ALOGE("%s: Error trying to insert a new window in non-shared output configuration", |
| 134 | __FUNCTION__); |
| 135 | return ACAMERA_ERROR_INVALID_OPERATION; |
| 136 | } |
| 137 | if (out->mWindow == window) { |
| 138 | ALOGE("%s: Error trying to add the same window associated with the output configuration", |
| 139 | __FUNCTION__); |
| 140 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 141 | } |
| 142 | |
| 143 | auto insert = out->mSharedWindows.insert(window); |
| 144 | camera_status_t ret = (insert.second) ? ACAMERA_OK : ACAMERA_ERROR_INVALID_PARAMETER; |
| 145 | return ret; |
| 146 | } |
| 147 | |
| 148 | EXPORT |
| 149 | camera_status_t ACaptureSessionSharedOutput_remove(ACaptureSessionOutput *out, |
| 150 | ANativeWindow* window) { |
| 151 | ATRACE_CALL(); |
| 152 | if ((window == nullptr) || (out == nullptr)) { |
| 153 | ALOGE("%s: Error: bad argument. window %p, out %p", |
| 154 | __FUNCTION__, window, out); |
| 155 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 156 | } |
| 157 | if (!out->mIsShared) { |
| 158 | ALOGE("%s: Error trying to remove a window in non-shared output configuration", |
| 159 | __FUNCTION__); |
| 160 | return ACAMERA_ERROR_INVALID_OPERATION; |
| 161 | } |
| 162 | if (out->mWindow == window) { |
| 163 | ALOGE("%s: Error trying to remove the same window associated with the output configuration", |
| 164 | __FUNCTION__); |
| 165 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 166 | } |
| 167 | |
| 168 | auto remove = out->mSharedWindows.erase(window); |
| 169 | camera_status_t ret = (remove) ? ACAMERA_OK : ACAMERA_ERROR_INVALID_PARAMETER; |
| 170 | return ret; |
| 171 | } |
| 172 | |
| 173 | EXPORT |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 174 | void ACaptureSessionOutput_free(ACaptureSessionOutput* output) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 175 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 176 | if (output != nullptr) { |
| 177 | delete output; |
| 178 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 179 | return; |
| 180 | } |
| 181 | |
| 182 | EXPORT |
| 183 | camera_status_t ACaptureSessionOutputContainer_add( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 184 | ACaptureSessionOutputContainer* container, const ACaptureSessionOutput* output) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 185 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 186 | if (container == nullptr || output == nullptr) { |
| 187 | ALOGE("%s: Error: invalid input: container %p, output %p", |
| 188 | __FUNCTION__, container, output); |
| 189 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 190 | } |
| 191 | auto pair = container->mOutputs.insert(*output); |
| 192 | if (!pair.second) { |
| 193 | ALOGW("%s: output %p already exists!", __FUNCTION__, output); |
| 194 | } |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 195 | return ACAMERA_OK; |
| 196 | } |
| 197 | |
| 198 | EXPORT |
| 199 | camera_status_t ACaptureSessionOutputContainer_remove( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 200 | ACaptureSessionOutputContainer* container, const ACaptureSessionOutput* output) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 201 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 202 | if (container == nullptr || output == nullptr) { |
| 203 | ALOGE("%s: Error: invalid input: container %p, output %p", |
| 204 | __FUNCTION__, container, output); |
| 205 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 206 | } |
| 207 | container->mOutputs.erase(*output); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 208 | return ACAMERA_OK; |
| 209 | } |
| 210 | |
| 211 | EXPORT |
| 212 | camera_status_t ACameraDevice_createCaptureSession( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 213 | ACameraDevice* device, |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 214 | const ACaptureSessionOutputContainer* outputs, |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 215 | const ACameraCaptureSession_stateCallbacks* callbacks, |
| 216 | /*out*/ACameraCaptureSession** session) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 217 | ATRACE_CALL(); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 218 | if (device == nullptr || outputs == nullptr || callbacks == nullptr || session == nullptr) { |
| 219 | ALOGE("%s: Error: invalid input: device %p, outputs %p, callbacks %p, session %p", |
| 220 | __FUNCTION__, device, outputs, callbacks, session); |
| 221 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 222 | } |
Emilian Peev | 5fbe0ba | 2017-10-20 15:45:45 +0100 | [diff] [blame^] | 223 | return device->createCaptureSession(outputs, nullptr, callbacks, session); |
| 224 | } |
| 225 | |
| 226 | EXPORT |
| 227 | camera_status_t ACameraDevice_createCaptureSessionWithSessionParameters( |
| 228 | ACameraDevice* device, |
| 229 | const ACaptureSessionOutputContainer* outputs, |
| 230 | const ACaptureRequest* sessionParameters, |
| 231 | const ACameraCaptureSession_stateCallbacks* callbacks, |
| 232 | /*out*/ACameraCaptureSession** session) { |
| 233 | ATRACE_CALL(); |
| 234 | if (device == nullptr || outputs == nullptr || callbacks == nullptr || session == nullptr) { |
| 235 | ALOGE("%s: Error: invalid input: device %p, outputs %p, callbacks %p, session %p", |
| 236 | __FUNCTION__, device, outputs, callbacks, session); |
| 237 | return ACAMERA_ERROR_INVALID_PARAMETER; |
| 238 | } |
| 239 | return device->createCaptureSession(outputs, sessionParameters, callbacks, session); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 240 | } |