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 | #ifndef _ACAMERA_DEVICE_H |
| 17 | #define _ACAMERA_DEVICE_H |
| 18 | |
| 19 | #include <memory> |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 20 | #include <map> |
| 21 | #include <set> |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 22 | #include <atomic> |
Yin-Chia Yeh | e081c59 | 2016-03-29 18:26:44 -0700 | [diff] [blame] | 23 | #include <utility> |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 24 | #include <utils/StrongPointer.h> |
| 25 | #include <utils/Mutex.h> |
| 26 | #include <utils/String8.h> |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 27 | #include <utils/List.h> |
| 28 | #include <utils/Vector.h> |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 29 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 30 | #include <android/hardware/camera2/BnCameraDeviceCallbacks.h> |
| 31 | #include <android/hardware/camera2/ICameraDeviceUser.h> |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 32 | #include <media/stagefright/foundation/ALooper.h> |
| 33 | #include <media/stagefright/foundation/AHandler.h> |
| 34 | #include <media/stagefright/foundation/AMessage.h> |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 35 | #include <camera/CaptureResult.h> |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 36 | #include <camera/camera2/OutputConfiguration.h> |
| 37 | #include <camera/camera2/CaptureRequest.h> |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 38 | |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 39 | #include <camera/NdkCameraManager.h> |
| 40 | #include <camera/NdkCameraCaptureSession.h> |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 41 | #include "ACameraMetadata.h" |
| 42 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 43 | namespace android { |
| 44 | |
Yin-Chia Yeh | d21c46b | 2017-10-10 11:59:46 -0700 | [diff] [blame] | 45 | // Wrap ACameraCaptureFailure so it can be ref-counted |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 46 | struct CameraCaptureFailure : public RefBase, public ACameraCaptureFailure {}; |
| 47 | |
| 48 | class CameraDevice final : public RefBase { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 49 | public: |
| 50 | CameraDevice(const char* id, ACameraDevice_StateCallbacks* cb, |
| 51 | std::unique_ptr<ACameraMetadata> chars, |
| 52 | ACameraDevice* wrapper); |
| 53 | ~CameraDevice(); |
| 54 | |
| 55 | inline const char* getId() const { return mCameraId.string(); } |
| 56 | |
| 57 | camera_status_t createCaptureRequest( |
| 58 | ACameraDevice_request_template templateId, |
| 59 | ACaptureRequest** request) const; |
| 60 | |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 61 | camera_status_t createCaptureSession( |
| 62 | const ACaptureSessionOutputContainer* outputs, |
Emilian Peev | 5fbe0ba | 2017-10-20 15:45:45 +0100 | [diff] [blame] | 63 | const ACaptureRequest* sessionParameters, |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 64 | const ACameraCaptureSession_stateCallbacks* callbacks, |
| 65 | /*out*/ACameraCaptureSession** session); |
| 66 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 67 | // Callbacks from camera service |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 68 | class ServiceCallback : public hardware::camera2::BnCameraDeviceCallbacks { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 69 | public: |
Chih-Hung Hsieh | d19d994 | 2016-08-29 14:21:14 -0700 | [diff] [blame] | 70 | explicit ServiceCallback(CameraDevice* device) : mDevice(device) {} |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 71 | binder::Status onDeviceError(int32_t errorCode, |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 72 | const CaptureResultExtras& resultExtras) override; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 73 | binder::Status onDeviceIdle() override; |
| 74 | binder::Status onCaptureStarted(const CaptureResultExtras& resultExtras, |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 75 | int64_t timestamp) override; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 76 | binder::Status onResultReceived(const CameraMetadata& metadata, |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 77 | const CaptureResultExtras& resultExtras) override; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 78 | binder::Status onPrepared(int streamId) override; |
Shuzhen Wang | 9d06601 | 2016-09-30 11:30:20 -0700 | [diff] [blame] | 79 | binder::Status onRequestQueueEmpty() override; |
Yin-Chia Yeh | 8ca23dc | 2017-09-05 18:15:56 -0700 | [diff] [blame] | 80 | binder::Status onRepeatingRequestError(int64_t lastFrameNumber, |
| 81 | int32_t stoppedSequenceId) override; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 82 | private: |
| 83 | const wp<CameraDevice> mDevice; |
| 84 | }; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 85 | inline sp<hardware::camera2::ICameraDeviceCallbacks> getServiceCallback() { |
| 86 | return mServiceCallback; |
| 87 | }; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 88 | |
| 89 | // Camera device is only functional after remote being set |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 90 | void setRemoteDevice(sp<hardware::camera2::ICameraDeviceUser> remote); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 91 | |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 92 | inline ACameraDevice* getWrapper() const { return mWrapper; }; |
| 93 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 94 | private: |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 95 | friend ACameraCaptureSession; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 96 | camera_status_t checkCameraClosedOrErrorLocked() const; |
| 97 | |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 98 | // device goes into fatal error state after this |
| 99 | void setCameraDeviceErrorLocked(camera_status_t error); |
| 100 | |
Yin-Chia Yeh | 6e2353b | 2017-10-24 16:35:20 -0700 | [diff] [blame] | 101 | void disconnectLocked(sp<ACameraCaptureSession>& session); // disconnect from camera service |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 102 | |
| 103 | camera_status_t stopRepeatingLocked(); |
| 104 | |
Yin-Chia Yeh | 309d05d | 2016-03-28 10:15:31 -0700 | [diff] [blame] | 105 | camera_status_t flushLocked(ACameraCaptureSession*); |
| 106 | |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 107 | camera_status_t waitUntilIdleLocked(); |
| 108 | |
| 109 | |
| 110 | camera_status_t captureLocked(sp<ACameraCaptureSession> session, |
| 111 | /*optional*/ACameraCaptureSession_captureCallbacks* cbs, |
| 112 | int numRequests, ACaptureRequest** requests, |
| 113 | /*optional*/int* captureSequenceId); |
| 114 | |
| 115 | camera_status_t setRepeatingRequestsLocked(sp<ACameraCaptureSession> session, |
| 116 | /*optional*/ACameraCaptureSession_captureCallbacks* cbs, |
| 117 | int numRequests, ACaptureRequest** requests, |
| 118 | /*optional*/int* captureSequenceId); |
| 119 | |
| 120 | camera_status_t submitRequestsLocked( |
| 121 | sp<ACameraCaptureSession> session, |
| 122 | /*optional*/ACameraCaptureSession_captureCallbacks* cbs, |
| 123 | int numRequests, ACaptureRequest** requests, |
| 124 | /*out*/int* captureSequenceId, |
| 125 | bool isRepeating); |
| 126 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 127 | camera_status_t updateOutputConfigurationLocked(ACaptureSessionOutput *output); |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 128 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 129 | camera_status_t allocateCaptureRequest( |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 130 | const ACaptureRequest* request, sp<CaptureRequest>& outReq); |
| 131 | |
| 132 | static ACaptureRequest* allocateACaptureRequest(sp<CaptureRequest>& req); |
| 133 | static void freeACaptureRequest(ACaptureRequest*); |
| 134 | |
| 135 | // only For session to hold device lock |
| 136 | // Always grab device lock before grabbing session lock |
| 137 | void lockDeviceForSessionOps() const { mDeviceLock.lock(); }; |
| 138 | void unlockDevice() const { mDeviceLock.unlock(); }; |
| 139 | |
| 140 | // For capture session to notify its end of life |
| 141 | void notifySessionEndOfLifeLocked(ACameraCaptureSession* session); |
| 142 | |
Emilian Peev | 5fbe0ba | 2017-10-20 15:45:45 +0100 | [diff] [blame] | 143 | camera_status_t configureStreamsLocked(const ACaptureSessionOutputContainer* outputs, |
| 144 | const ACaptureRequest* sessionParameters); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 145 | |
Yin-Chia Yeh | 6e2353b | 2017-10-24 16:35:20 -0700 | [diff] [blame] | 146 | // Input message will be posted and cleared after this returns |
| 147 | void postSessionMsgAndCleanup(sp<AMessage>& msg); |
| 148 | |
Yin-Chia Yeh | e081c59 | 2016-03-29 18:26:44 -0700 | [diff] [blame] | 149 | static camera_status_t getIGBPfromAnw( |
| 150 | ANativeWindow* anw, sp<IGraphicBufferProducer>& out); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 151 | |
| 152 | static camera_status_t getSurfaceFromANativeWindow( |
| 153 | ANativeWindow* anw, sp<Surface>& out); |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 154 | |
| 155 | mutable Mutex mDeviceLock; |
| 156 | const String8 mCameraId; // Camera ID |
| 157 | const ACameraDevice_StateCallbacks mAppCallbacks; // Callback to app |
| 158 | const std::unique_ptr<ACameraMetadata> mChars; // Camera characteristics |
| 159 | const sp<ServiceCallback> mServiceCallback; |
| 160 | ACameraDevice* mWrapper; |
| 161 | |
Yin-Chia Yeh | e081c59 | 2016-03-29 18:26:44 -0700 | [diff] [blame] | 162 | // stream id -> pair of (ANW* from application, OutputConfiguration used for camera service) |
| 163 | std::map<int, std::pair<ANativeWindow*, OutputConfiguration>> mConfiguredOutputs; |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 164 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 165 | // TODO: maybe a bool will suffice for synchronous implementation? |
| 166 | std::atomic_bool mClosing; |
| 167 | inline bool isClosed() { return mClosing; } |
| 168 | |
Yin-Chia Yeh | 309d05d | 2016-03-28 10:15:31 -0700 | [diff] [blame] | 169 | bool mInError = false; |
| 170 | camera_status_t mError = ACAMERA_OK; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 171 | void onCaptureErrorLocked( |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 172 | int32_t errorCode, |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 173 | const CaptureResultExtras& resultExtras); |
| 174 | |
Yin-Chia Yeh | 309d05d | 2016-03-28 10:15:31 -0700 | [diff] [blame] | 175 | bool mIdle = true; |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 176 | // This will avoid a busy session being deleted before it's back to idle state |
| 177 | sp<ACameraCaptureSession> mBusySession; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 178 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 179 | sp<hardware::camera2::ICameraDeviceUser> mRemote; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 180 | |
| 181 | // Looper thread to handle callback to app |
| 182 | sp<ALooper> mCbLooper; |
| 183 | // definition of handler and message |
| 184 | enum { |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 185 | // Device state callbacks |
Yin-Chia Yeh | e081c59 | 2016-03-29 18:26:44 -0700 | [diff] [blame] | 186 | kWhatOnDisconnected, // onDisconnected |
| 187 | kWhatOnError, // onError |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 188 | // Session state callbacks |
Yin-Chia Yeh | e081c59 | 2016-03-29 18:26:44 -0700 | [diff] [blame] | 189 | kWhatSessionStateCb, // onReady, onActive |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 190 | // Capture callbacks |
Yin-Chia Yeh | e081c59 | 2016-03-29 18:26:44 -0700 | [diff] [blame] | 191 | kWhatCaptureStart, // onCaptureStarted |
| 192 | kWhatCaptureResult, // onCaptureProgressed, onCaptureCompleted |
| 193 | kWhatCaptureFail, // onCaptureFailed |
| 194 | kWhatCaptureSeqEnd, // onCaptureSequenceCompleted |
| 195 | kWhatCaptureSeqAbort, // onCaptureSequenceAborted |
Yin-Chia Yeh | 6e2353b | 2017-10-24 16:35:20 -0700 | [diff] [blame] | 196 | kWhatCaptureBufferLost,// onCaptureBufferLost |
| 197 | // Internal cleanup |
| 198 | kWhatCleanUpSessions // Cleanup cached sp<ACameraCaptureSession> |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 199 | }; |
| 200 | static const char* kContextKey; |
| 201 | static const char* kDeviceKey; |
| 202 | static const char* kErrorCodeKey; |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 203 | static const char* kCallbackFpKey; |
| 204 | static const char* kSessionSpKey; |
| 205 | static const char* kCaptureRequestKey; |
| 206 | static const char* kTimeStampKey; |
| 207 | static const char* kCaptureResultKey; |
| 208 | static const char* kCaptureFailureKey; |
| 209 | static const char* kSequenceIdKey; |
| 210 | static const char* kFrameNumberKey; |
Yin-Chia Yeh | e081c59 | 2016-03-29 18:26:44 -0700 | [diff] [blame] | 211 | static const char* kAnwKey; |
Yin-Chia Yeh | 6e2353b | 2017-10-24 16:35:20 -0700 | [diff] [blame] | 212 | |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 213 | class CallbackHandler : public AHandler { |
| 214 | public: |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 215 | void onMessageReceived(const sp<AMessage> &msg) override; |
Yin-Chia Yeh | 6e2353b | 2017-10-24 16:35:20 -0700 | [diff] [blame] | 216 | |
| 217 | private: |
| 218 | // This handler will cache all capture session sp until kWhatCleanUpSessions |
| 219 | // is processed. This is used to guarantee the last session reference is always |
| 220 | // being removed in callback thread without holding camera device lock |
| 221 | Vector<sp<ACameraCaptureSession>> mCachedSessions; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 222 | }; |
| 223 | sp<CallbackHandler> mHandler; |
| 224 | |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 225 | /*********************************** |
| 226 | * Capture session related members * |
| 227 | ***********************************/ |
| 228 | // The current active session |
Yin-Chia Yeh | 6e2353b | 2017-10-24 16:35:20 -0700 | [diff] [blame] | 229 | wp<ACameraCaptureSession> mCurrentSession; |
Yin-Chia Yeh | 309d05d | 2016-03-28 10:15:31 -0700 | [diff] [blame] | 230 | bool mFlushing = false; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 231 | |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 232 | int mNextSessionId = 0; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 233 | // TODO: might need another looper/handler to handle callbacks from service |
| 234 | |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 235 | static const int REQUEST_ID_NONE = -1; |
| 236 | int mRepeatingSequenceId = REQUEST_ID_NONE; |
| 237 | |
| 238 | // sequence id -> last frame number map |
| 239 | std::map<int, int64_t> mSequenceLastFrameNumberMap; |
| 240 | |
| 241 | struct CallbackHolder { |
| 242 | CallbackHolder(sp<ACameraCaptureSession> session, |
| 243 | const Vector<sp<CaptureRequest> >& requests, |
| 244 | bool isRepeating, |
| 245 | ACameraCaptureSession_captureCallbacks* cbs); |
| 246 | |
| 247 | static ACameraCaptureSession_captureCallbacks fillCb( |
| 248 | ACameraCaptureSession_captureCallbacks* cbs) { |
| 249 | if (cbs != nullptr) { |
| 250 | return *cbs; |
| 251 | } |
Yin-Chia Yeh | e081c59 | 2016-03-29 18:26:44 -0700 | [diff] [blame] | 252 | return { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr }; |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | sp<ACameraCaptureSession> mSession; |
| 256 | Vector<sp<CaptureRequest> > mRequests; |
| 257 | const bool mIsRepeating; |
| 258 | ACameraCaptureSession_captureCallbacks mCallbacks; |
| 259 | }; |
| 260 | // sequence id -> callbacks map |
| 261 | std::map<int, CallbackHolder> mSequenceCallbackMap; |
| 262 | |
| 263 | static const int64_t NO_FRAMES_CAPTURED = -1; |
| 264 | class FrameNumberTracker { |
| 265 | public: |
| 266 | // TODO: Called in onResultReceived and onCaptureErrorLocked |
| 267 | void updateTracker(int64_t frameNumber, bool isError); |
| 268 | inline int64_t getCompletedFrameNumber() { return mCompletedFrameNumber; } |
| 269 | private: |
| 270 | void update(); |
| 271 | void updateCompletedFrameNumber(int64_t frameNumber); |
| 272 | |
| 273 | int64_t mCompletedFrameNumber = NO_FRAMES_CAPTURED; |
| 274 | List<int64_t> mSkippedFrameNumbers; |
| 275 | std::set<int64_t> mFutureErrorSet; |
| 276 | }; |
| 277 | FrameNumberTracker mFrameNumberTracker; |
| 278 | |
| 279 | void checkRepeatingSequenceCompleteLocked(const int sequenceId, const int64_t lastFrameNumber); |
| 280 | void checkAndFireSequenceCompleteLocked(); |
| 281 | |
| 282 | // Misc variables |
| 283 | int32_t mShadingMapSize[2]; // const after constructor |
| 284 | int32_t mPartialResultCount; // const after constructor |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 285 | |
| 286 | }; |
| 287 | |
| 288 | } // namespace android; |
| 289 | |
| 290 | /** |
| 291 | * ACameraDevice opaque struct definition |
| 292 | * Leave outside of android namespace because it's NDK struct |
| 293 | */ |
| 294 | struct ACameraDevice { |
| 295 | ACameraDevice(const char* id, ACameraDevice_StateCallbacks* cb, |
| 296 | std::unique_ptr<ACameraMetadata> chars) : |
| 297 | mDevice(new CameraDevice(id, cb, std::move(chars), this)) {} |
| 298 | |
| 299 | ~ACameraDevice() {}; |
| 300 | |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 301 | /******************* |
| 302 | * NDK public APIs * |
| 303 | *******************/ |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 304 | inline const char* getId() const { return mDevice->getId(); } |
| 305 | |
| 306 | camera_status_t createCaptureRequest( |
| 307 | ACameraDevice_request_template templateId, |
| 308 | ACaptureRequest** request) const { |
| 309 | return mDevice->createCaptureRequest(templateId, request); |
| 310 | } |
| 311 | |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 312 | camera_status_t createCaptureSession( |
| 313 | const ACaptureSessionOutputContainer* outputs, |
Emilian Peev | 5fbe0ba | 2017-10-20 15:45:45 +0100 | [diff] [blame] | 314 | const ACaptureRequest* sessionParameters, |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 315 | const ACameraCaptureSession_stateCallbacks* callbacks, |
| 316 | /*out*/ACameraCaptureSession** session) { |
Emilian Peev | 5fbe0ba | 2017-10-20 15:45:45 +0100 | [diff] [blame] | 317 | return mDevice->createCaptureSession(outputs, sessionParameters, callbacks, session); |
Yin-Chia Yeh | ead9146 | 2016-01-06 16:45:08 -0800 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | /*********************** |
| 321 | * Device interal APIs * |
| 322 | ***********************/ |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 323 | inline android::sp<android::hardware::camera2::ICameraDeviceCallbacks> getServiceCallback() { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 324 | return mDevice->getServiceCallback(); |
| 325 | }; |
| 326 | |
| 327 | // Camera device is only functional after remote being set |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 328 | inline void setRemoteDevice(android::sp<android::hardware::camera2::ICameraDeviceUser> remote) { |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 329 | mDevice->setRemoteDevice(remote); |
| 330 | } |
| 331 | |
| 332 | private: |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 333 | android::sp<android::CameraDevice> mDevice; |
Yin-Chia Yeh | 0dea57f | 2015-12-09 16:46:07 -0800 | [diff] [blame] | 334 | }; |
| 335 | |
| 336 | #endif // _ACAMERA_DEVICE_H |