Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 17 | #ifndef ANDROID_SERVERS_CAMERA3DEVICE_H |
| 18 | #define ANDROID_SERVERS_CAMERA3DEVICE_H |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 19 | |
| 20 | #include <utils/Condition.h> |
| 21 | #include <utils/Errors.h> |
| 22 | #include <utils/List.h> |
| 23 | #include <utils/Mutex.h> |
| 24 | #include <utils/Thread.h> |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 25 | #include <utils/KeyedVector.h> |
| 26 | #include <hardware/camera3.h> |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 27 | |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 28 | #include "common/CameraDeviceBase.h" |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 29 | #include "device3/StatusTracker.h" |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Function pointer types with C calling convention to |
| 33 | * use for HAL callback functions. |
| 34 | */ |
| 35 | extern "C" { |
| 36 | typedef void (callbacks_process_capture_result_t)( |
| 37 | const struct camera3_callback_ops *, |
| 38 | const camera3_capture_result_t *); |
| 39 | |
| 40 | typedef void (callbacks_notify_t)( |
| 41 | const struct camera3_callback_ops *, |
| 42 | const camera3_notify_msg_t *); |
| 43 | } |
| 44 | |
| 45 | namespace android { |
| 46 | |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 47 | namespace camera3 { |
| 48 | |
| 49 | class Camera3Stream; |
| 50 | class Camera3ZslStream; |
| 51 | class Camera3OutputStreamInterface; |
| 52 | class Camera3StreamInterface; |
| 53 | |
| 54 | } |
| 55 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 56 | /** |
| 57 | * CameraDevice for HAL devices with version CAMERA_DEVICE_API_VERSION_3_0 |
| 58 | */ |
| 59 | class Camera3Device : |
| 60 | public CameraDeviceBase, |
| 61 | private camera3_callback_ops { |
| 62 | public: |
| 63 | Camera3Device(int id); |
| 64 | |
| 65 | virtual ~Camera3Device(); |
| 66 | |
| 67 | /** |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 68 | * CameraDeviceBase interface |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 69 | */ |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 70 | |
Igor Murashkin | 7138105 | 2013-03-04 14:53:08 -0800 | [diff] [blame] | 71 | virtual int getId() const; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 72 | |
| 73 | // Transitions to idle state on success. |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 74 | virtual status_t initialize(camera_module_t *module); |
| 75 | virtual status_t disconnect(); |
| 76 | virtual status_t dump(int fd, const Vector<String16> &args); |
| 77 | virtual const CameraMetadata& info() const; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 78 | |
| 79 | // Capture and setStreamingRequest will configure streams if currently in |
| 80 | // idle state |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 81 | virtual status_t capture(CameraMetadata &request); |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame^] | 82 | virtual status_t captureList(const List<const CameraMetadata> &requests); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 83 | virtual status_t setStreamingRequest(const CameraMetadata &request); |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame^] | 84 | virtual status_t setStreamingRequestList(const List<const CameraMetadata> &requests); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 85 | virtual status_t clearStreamingRequest(); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 86 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 87 | virtual status_t waitUntilRequestReceived(int32_t requestId, nsecs_t timeout); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 88 | |
| 89 | // Actual stream creation/deletion is delayed until first request is submitted |
| 90 | // If adding streams while actively capturing, will pause device before adding |
| 91 | // stream, reconfiguring device, and unpausing. |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 92 | virtual status_t createStream(sp<ANativeWindow> consumer, |
| 93 | uint32_t width, uint32_t height, int format, size_t size, |
| 94 | int *id); |
Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 95 | virtual status_t createInputStream( |
| 96 | uint32_t width, uint32_t height, int format, |
| 97 | int *id); |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 98 | virtual status_t createZslStream( |
| 99 | uint32_t width, uint32_t height, |
| 100 | int depth, |
| 101 | /*out*/ |
| 102 | int *id, |
| 103 | sp<camera3::Camera3ZslStream>* zslStream); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 104 | virtual status_t createReprocessStreamFromStream(int outputId, int *id); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 105 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 106 | virtual status_t getStreamInfo(int id, |
| 107 | uint32_t *width, uint32_t *height, uint32_t *format); |
| 108 | virtual status_t setStreamTransform(int id, int transform); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 109 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 110 | virtual status_t deleteStream(int id); |
| 111 | virtual status_t deleteReprocessStream(int id); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 112 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 113 | virtual status_t createDefaultRequest(int templateId, CameraMetadata *request); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 114 | |
| 115 | // Transitions to the idle state on success |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 116 | virtual status_t waitUntilDrained(); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 117 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 118 | virtual status_t setNotifyCallback(NotificationListener *listener); |
Eino-Ville Talvala | 46910bd | 2013-07-18 19:15:17 -0700 | [diff] [blame] | 119 | virtual bool willNotify3A(); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 120 | virtual status_t waitForNextFrame(nsecs_t timeout); |
| 121 | virtual status_t getNextFrame(CameraMetadata *frame); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 122 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 123 | virtual status_t triggerAutofocus(uint32_t id); |
| 124 | virtual status_t triggerCancelAutofocus(uint32_t id); |
| 125 | virtual status_t triggerPrecaptureMetering(uint32_t id); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 126 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 127 | virtual status_t pushReprocessBuffer(int reprocessStreamId, |
| 128 | buffer_handle_t *buffer, wp<BufferReleasedListener> listener); |
| 129 | |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 130 | virtual status_t flush(); |
| 131 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 132 | // Methods called by subclasses |
| 133 | void notifyStatus(bool idle); // updates from StatusTracker |
| 134 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 135 | private: |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 136 | static const size_t kDumpLockAttempts = 10; |
| 137 | static const size_t kDumpSleepDuration = 100000; // 0.10 sec |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 138 | static const size_t kInFlightWarnLimit = 20; |
| 139 | static const nsecs_t kShutdownTimeout = 5000000000; // 5 sec |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 140 | static const nsecs_t kActiveTimeout = 500000000; // 500 ms |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 141 | struct RequestTrigger; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 142 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 143 | // A lock to enforce serialization on the input/configure side |
| 144 | // of the public interface. |
| 145 | // Only locked by public methods inherited from CameraDeviceBase. |
| 146 | // Not locked by methods guarded by mOutputLock, since they may act |
| 147 | // concurrently to the input/configure side of the interface. |
| 148 | // Must be locked before mLock if both will be locked by a method |
| 149 | Mutex mInterfaceLock; |
| 150 | |
| 151 | // The main lock on internal state |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 152 | Mutex mLock; |
| 153 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 154 | // Camera device ID |
| 155 | const int mId; |
| 156 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 157 | /**** Scope for mLock ****/ |
| 158 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 159 | camera3_device_t *mHal3Device; |
| 160 | |
| 161 | CameraMetadata mDeviceInfo; |
| 162 | vendor_tag_query_ops_t mVendorTagOps; |
| 163 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 164 | enum Status { |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 165 | STATUS_ERROR, |
| 166 | STATUS_UNINITIALIZED, |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 167 | STATUS_UNCONFIGURED, |
| 168 | STATUS_CONFIGURED, |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 169 | STATUS_ACTIVE |
| 170 | } mStatus; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 171 | Vector<Status> mRecentStatusUpdates; |
| 172 | Condition mStatusChanged; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 173 | |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 174 | // Tracking cause of fatal errors when in STATUS_ERROR |
| 175 | String8 mErrorCause; |
| 176 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 177 | // Mapping of stream IDs to stream instances |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 178 | typedef KeyedVector<int, sp<camera3::Camera3OutputStreamInterface> > |
| 179 | StreamSet; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 180 | |
| 181 | StreamSet mOutputStreams; |
| 182 | sp<camera3::Camera3Stream> mInputStream; |
| 183 | int mNextStreamId; |
Eino-Ville Talvala | ea26c77 | 2013-06-11 16:04:06 -0700 | [diff] [blame] | 184 | bool mNeedConfig; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 185 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 186 | // Whether to send state updates upstream |
| 187 | // Pause when doing transparent reconfiguration |
| 188 | bool mPauseStateNotify; |
| 189 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 190 | // Need to hold on to stream references until configure completes. |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 191 | Vector<sp<camera3::Camera3StreamInterface> > mDeletedStreams; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 192 | |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 193 | // Whether quirk ANDROID_QUIRKS_USE_PARTIAL_RESULT is enabled |
| 194 | bool mUsePartialResultQuirk; |
| 195 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 196 | /**** End scope for mLock ****/ |
| 197 | |
| 198 | class CaptureRequest : public LightRefBase<CaptureRequest> { |
| 199 | public: |
| 200 | CameraMetadata mSettings; |
| 201 | sp<camera3::Camera3Stream> mInputStream; |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 202 | Vector<sp<camera3::Camera3OutputStreamInterface> > |
| 203 | mOutputStreams; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 204 | }; |
| 205 | typedef List<sp<CaptureRequest> > RequestList; |
| 206 | |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame^] | 207 | status_t checkStatusOkToCaptureLocked(); |
| 208 | |
| 209 | status_t convertMetadataListToRequestListLocked( |
| 210 | const List<const CameraMetadata> &metadataList, |
| 211 | /*out*/RequestList *requestList); |
| 212 | |
| 213 | status_t submitRequestsHelper(const List<const CameraMetadata> &requests, bool repeating); |
| 214 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 215 | /** |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 216 | * Get the last request submitted to the hal by the request thread. |
| 217 | * |
| 218 | * Takes mLock. |
| 219 | */ |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 220 | virtual CameraMetadata getLatestRequestLocked(); |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 221 | |
| 222 | /** |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 223 | * Pause processing and flush everything, but don't tell the clients. |
| 224 | * This is for reconfiguring outputs transparently when according to the |
| 225 | * CameraDeviceBase interface we shouldn't need to. |
| 226 | * Must be called with mLock and mInterfaceLock both held. |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 227 | */ |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 228 | status_t internalPauseAndWaitLocked(); |
| 229 | |
| 230 | /** |
| 231 | * Resume work after internalPauseAndWaitLocked() |
| 232 | * Must be called with mLock and mInterfaceLock both held. |
| 233 | */ |
| 234 | status_t internalResumeLocked(); |
| 235 | |
| 236 | /** |
| 237 | * Wait until status tracker tells us we've transitioned to the target state |
| 238 | * set, which is either ACTIVE when active==true or IDLE (which is any |
| 239 | * non-ACTIVE state) when active==false. |
| 240 | * |
| 241 | * Needs to be called with mLock and mInterfaceLock held. This means there |
| 242 | * can ever only be one waiter at most. |
| 243 | * |
| 244 | * During the wait mLock is released. |
| 245 | * |
| 246 | */ |
| 247 | status_t waitUntilStateThenRelock(bool active, nsecs_t timeout); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 248 | |
| 249 | /** |
| 250 | * Do common work for setting up a streaming or single capture request. |
| 251 | * On success, will transition to ACTIVE if in IDLE. |
| 252 | */ |
| 253 | sp<CaptureRequest> setUpRequestLocked(const CameraMetadata &request); |
| 254 | |
| 255 | /** |
| 256 | * Build a CaptureRequest request from the CameraDeviceBase request |
| 257 | * settings. |
| 258 | */ |
| 259 | sp<CaptureRequest> createCaptureRequest(const CameraMetadata &request); |
| 260 | |
| 261 | /** |
| 262 | * Take the currently-defined set of streams and configure the HAL to use |
| 263 | * them. This is a long-running operation (may be several hundered ms). |
| 264 | */ |
| 265 | status_t configureStreamsLocked(); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 266 | |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 267 | /** |
| 268 | * Set device into an error state due to some fatal failure, and set an |
| 269 | * error message to indicate why. Only the first call's message will be |
| 270 | * used. The message is also sent to the log. |
| 271 | */ |
| 272 | void setErrorState(const char *fmt, ...); |
| 273 | void setErrorStateV(const char *fmt, va_list args); |
| 274 | void setErrorStateLocked(const char *fmt, ...); |
| 275 | void setErrorStateLockedV(const char *fmt, va_list args); |
| 276 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 277 | /** |
| 278 | * Debugging trylock/spin method |
| 279 | * Try to acquire a lock a few times with sleeps between before giving up. |
| 280 | */ |
| 281 | bool tryLockSpinRightRound(Mutex& lock); |
| 282 | |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 283 | struct RequestTrigger { |
| 284 | // Metadata tag number, e.g. android.control.aePrecaptureTrigger |
| 285 | uint32_t metadataTag; |
| 286 | // Metadata value, e.g. 'START' or the trigger ID |
| 287 | int32_t entryValue; |
| 288 | |
| 289 | // The last part of the fully qualified path, e.g. afTrigger |
| 290 | const char *getTagName() const { |
| 291 | return get_camera_metadata_tag_name(metadataTag) ?: "NULL"; |
| 292 | } |
| 293 | |
| 294 | // e.g. TYPE_BYTE, TYPE_INT32, etc. |
| 295 | int getTagType() const { |
| 296 | return get_camera_metadata_tag_type(metadataTag); |
| 297 | } |
| 298 | }; |
| 299 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 300 | /** |
| 301 | * Thread for managing capture request submission to HAL device. |
| 302 | */ |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 303 | class RequestThread : public Thread { |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 304 | |
| 305 | public: |
| 306 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 307 | RequestThread(wp<Camera3Device> parent, |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 308 | sp<camera3::StatusTracker> statusTracker, |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 309 | camera3_device_t *hal3Device); |
| 310 | |
| 311 | /** |
| 312 | * Call after stream (re)-configuration is completed. |
| 313 | */ |
| 314 | void configurationComplete(); |
| 315 | |
| 316 | /** |
| 317 | * Set or clear the list of repeating requests. Does not block |
| 318 | * on either. Use waitUntilPaused to wait until request queue |
| 319 | * has emptied out. |
| 320 | */ |
| 321 | status_t setRepeatingRequests(const RequestList& requests); |
| 322 | status_t clearRepeatingRequests(); |
| 323 | |
| 324 | status_t queueRequest(sp<CaptureRequest> request); |
| 325 | |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame^] | 326 | status_t queueRequestList(List<sp<CaptureRequest> > &requests); |
| 327 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 328 | /** |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 329 | * Remove all queued and repeating requests, and pending triggers |
| 330 | */ |
| 331 | status_t clear(); |
| 332 | |
| 333 | /** |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 334 | * Queue a trigger to be dispatched with the next outgoing |
| 335 | * process_capture_request. The settings for that request only |
| 336 | * will be temporarily rewritten to add the trigger tag/value. |
| 337 | * Subsequent requests will not be rewritten (for this tag). |
| 338 | */ |
| 339 | status_t queueTrigger(RequestTrigger trigger[], size_t count); |
| 340 | |
| 341 | /** |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 342 | * Pause/unpause the capture thread. Doesn't block, so use |
| 343 | * waitUntilPaused to wait until the thread is paused. |
| 344 | */ |
| 345 | void setPaused(bool paused); |
| 346 | |
| 347 | /** |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 348 | * Wait until thread processes the capture request with settings' |
| 349 | * android.request.id == requestId. |
| 350 | * |
| 351 | * Returns TIMED_OUT in case the thread does not process the request |
| 352 | * within the timeout. |
| 353 | */ |
| 354 | status_t waitUntilRequestProcessed(int32_t requestId, nsecs_t timeout); |
| 355 | |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 356 | /** |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 357 | * Shut down the thread. Shutdown is asynchronous, so thread may |
| 358 | * still be running once this method returns. |
| 359 | */ |
| 360 | virtual void requestExit(); |
| 361 | |
| 362 | /** |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 363 | * Get the latest request that was sent to the HAL |
| 364 | * with process_capture_request. |
| 365 | */ |
| 366 | CameraMetadata getLatestRequest() const; |
| 367 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 368 | protected: |
| 369 | |
| 370 | virtual bool threadLoop(); |
| 371 | |
| 372 | private: |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 373 | static int getId(const wp<Camera3Device> &device); |
| 374 | |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 375 | status_t queueTriggerLocked(RequestTrigger trigger); |
| 376 | // Mix-in queued triggers into this request |
| 377 | int32_t insertTriggers(const sp<CaptureRequest> &request); |
| 378 | // Purge the queued triggers from this request, |
| 379 | // restoring the old field values for those tags. |
| 380 | status_t removeTriggers(const sp<CaptureRequest> &request); |
| 381 | |
Eino-Ville Talvala | 2f876f9 | 2013-09-13 11:39:24 -0700 | [diff] [blame] | 382 | // HAL workaround: Make sure a trigger ID always exists if |
| 383 | // a trigger does |
| 384 | status_t addDummyTriggerIds(const sp<CaptureRequest> &request); |
| 385 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 386 | static const nsecs_t kRequestTimeout = 50e6; // 50 ms |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 387 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 388 | // Waits for a request, or returns NULL if times out. |
| 389 | sp<CaptureRequest> waitForNextRequest(); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 390 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 391 | // Return buffers, etc, for a request that couldn't be fully |
| 392 | // constructed. The buffers will be returned in the ERROR state |
| 393 | // to mark them as not having valid data. |
| 394 | // All arguments will be modified. |
| 395 | void cleanUpFailedRequest(camera3_capture_request_t &request, |
| 396 | sp<CaptureRequest> &nextRequest, |
| 397 | Vector<camera3_stream_buffer_t> &outputBuffers); |
| 398 | |
| 399 | // Pause handling |
| 400 | bool waitIfPaused(); |
Eino-Ville Talvala | 26fe6c7 | 2013-08-29 12:46:18 -0700 | [diff] [blame] | 401 | void unpauseForNewRequests(); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 402 | |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 403 | // Relay error to parent device object setErrorState |
| 404 | void setErrorState(const char *fmt, ...); |
| 405 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 406 | wp<Camera3Device> mParent; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 407 | wp<camera3::StatusTracker> mStatusTracker; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 408 | camera3_device_t *mHal3Device; |
| 409 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 410 | const int mId; // The camera ID |
| 411 | int mStatusId; // The RequestThread's component ID for |
| 412 | // status tracking |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 413 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 414 | Mutex mRequestLock; |
| 415 | Condition mRequestSignal; |
| 416 | RequestList mRequestQueue; |
| 417 | RequestList mRepeatingRequests; |
| 418 | |
| 419 | bool mReconfigured; |
| 420 | |
| 421 | // Used by waitIfPaused, waitForNextRequest, and waitUntilPaused |
| 422 | Mutex mPauseLock; |
| 423 | bool mDoPause; |
| 424 | Condition mDoPauseSignal; |
| 425 | bool mPaused; |
| 426 | Condition mPausedSignal; |
| 427 | |
| 428 | sp<CaptureRequest> mPrevRequest; |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 429 | int32_t mPrevTriggers; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 430 | |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 431 | uint32_t mFrameNumber; |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 432 | |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 433 | mutable Mutex mLatestRequestMutex; |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 434 | Condition mLatestRequestSignal; |
| 435 | // android.request.id for latest process_capture_request |
| 436 | int32_t mLatestRequestId; |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 437 | CameraMetadata mLatestRequest; |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 438 | |
| 439 | typedef KeyedVector<uint32_t/*tag*/, RequestTrigger> TriggerMap; |
| 440 | Mutex mTriggerMutex; |
| 441 | TriggerMap mTriggerMap; |
| 442 | TriggerMap mTriggerRemovedMap; |
| 443 | TriggerMap mTriggerReplacedMap; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 444 | }; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 445 | sp<RequestThread> mRequestThread; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 446 | |
| 447 | /** |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 448 | * In-flight queue for tracking completion of capture requests. |
| 449 | */ |
| 450 | |
| 451 | struct InFlightRequest { |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 452 | // android.request.id for the request |
| 453 | int requestId; |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 454 | // Set by notify() SHUTTER call. |
| 455 | nsecs_t captureTimestamp; |
Zhijun He | 1d1f846 | 2013-10-02 16:29:51 -0700 | [diff] [blame] | 456 | int requestStatus; |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 457 | // Set by process_capture_result call with valid metadata |
| 458 | bool haveResultMetadata; |
| 459 | // Decremented by calls to process_capture_result with valid output |
| 460 | // buffers |
| 461 | int numBuffersLeft; |
| 462 | |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 463 | // Fields used by the partial result quirk only |
| 464 | struct PartialResultQuirkInFlight { |
| 465 | // Set by process_capture_result once 3A has been sent to clients |
| 466 | bool haveSent3A; |
| 467 | // Result metadata collected so far, when partial results are in use |
| 468 | CameraMetadata collectedResult; |
| 469 | |
| 470 | PartialResultQuirkInFlight(): |
| 471 | haveSent3A(false) { |
| 472 | } |
| 473 | } partialResultQuirk; |
| 474 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 475 | // Default constructor needed by KeyedVector |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 476 | InFlightRequest() : |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 477 | requestId(0), |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 478 | captureTimestamp(0), |
Zhijun He | 1d1f846 | 2013-10-02 16:29:51 -0700 | [diff] [blame] | 479 | requestStatus(OK), |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 480 | haveResultMetadata(false), |
| 481 | numBuffersLeft(0) { |
| 482 | } |
| 483 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 484 | InFlightRequest(int id, int numBuffers) : |
| 485 | requestId(id), |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 486 | captureTimestamp(0), |
Zhijun He | cc27e11 | 2013-10-03 16:12:43 -0700 | [diff] [blame] | 487 | requestStatus(OK), |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 488 | haveResultMetadata(false), |
| 489 | numBuffersLeft(numBuffers) { |
| 490 | } |
| 491 | }; |
| 492 | // Map from frame number to the in-flight request state |
| 493 | typedef KeyedVector<uint32_t, InFlightRequest> InFlightMap; |
| 494 | |
| 495 | Mutex mInFlightLock; // Protects mInFlightMap |
| 496 | InFlightMap mInFlightMap; |
| 497 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 498 | status_t registerInFlight(int32_t frameNumber, int32_t requestId, |
| 499 | int32_t numBuffers); |
| 500 | |
| 501 | /** |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 502 | * For the partial result quirk, check if all 3A state fields are available |
| 503 | * and if so, queue up 3A-only result to the client. Returns true if 3A |
| 504 | * is sent. |
| 505 | */ |
Eino-Ville Talvala | 184dfe4 | 2013-11-07 15:13:16 -0800 | [diff] [blame] | 506 | bool processPartial3AQuirk(int32_t frameNumber, int32_t requestId, |
| 507 | const CameraMetadata& partial); |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 508 | |
| 509 | // Helpers for reading and writing 3A metadata into to/from partial results |
| 510 | template<typename T> |
| 511 | bool get3AResult(const CameraMetadata& result, int32_t tag, |
| 512 | T* value, int32_t frameNumber); |
| 513 | |
| 514 | template<typename T> |
| 515 | bool insert3AResult(CameraMetadata &result, int32_t tag, const T* value, |
| 516 | int32_t frameNumber); |
| 517 | /** |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 518 | * Tracking for idle detection |
| 519 | */ |
| 520 | sp<camera3::StatusTracker> mStatusTracker; |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 521 | |
| 522 | /** |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 523 | * Output result queue and current HAL device 3A state |
| 524 | */ |
| 525 | |
| 526 | // Lock for output side of device |
| 527 | Mutex mOutputLock; |
| 528 | |
| 529 | /**** Scope for mOutputLock ****/ |
| 530 | |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 531 | uint32_t mNextResultFrameNumber; |
| 532 | uint32_t mNextShutterFrameNumber; |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 533 | List<CameraMetadata> mResultQueue; |
| 534 | Condition mResultSignal; |
| 535 | NotificationListener *mListener; |
| 536 | |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 537 | /**** End scope for mOutputLock ****/ |
| 538 | |
| 539 | /** |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 540 | * Callback functions from HAL device |
| 541 | */ |
| 542 | void processCaptureResult(const camera3_capture_result *result); |
| 543 | |
| 544 | void notify(const camera3_notify_msg *msg); |
| 545 | |
| 546 | /** |
| 547 | * Static callback forwarding methods from HAL to instance |
| 548 | */ |
| 549 | static callbacks_process_capture_result_t sProcessCaptureResult; |
| 550 | |
| 551 | static callbacks_notify_t sNotify; |
| 552 | |
| 553 | }; // class Camera3Device |
| 554 | |
| 555 | }; // namespace android |
| 556 | |
| 557 | #endif |