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