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