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 | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Function pointer types with C calling convention to |
| 32 | * use for HAL callback functions. |
| 33 | */ |
| 34 | extern "C" { |
| 35 | typedef void (callbacks_process_capture_result_t)( |
| 36 | const struct camera3_callback_ops *, |
| 37 | const camera3_capture_result_t *); |
| 38 | |
| 39 | typedef void (callbacks_notify_t)( |
| 40 | const struct camera3_callback_ops *, |
| 41 | const camera3_notify_msg_t *); |
| 42 | } |
| 43 | |
| 44 | namespace android { |
| 45 | |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 46 | namespace camera3 { |
| 47 | |
| 48 | class Camera3Stream; |
| 49 | class Camera3ZslStream; |
| 50 | class Camera3OutputStreamInterface; |
| 51 | class Camera3StreamInterface; |
| 52 | |
| 53 | } |
| 54 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 55 | /** |
| 56 | * CameraDevice for HAL devices with version CAMERA_DEVICE_API_VERSION_3_0 |
| 57 | */ |
| 58 | class Camera3Device : |
| 59 | public CameraDeviceBase, |
| 60 | private camera3_callback_ops { |
| 61 | public: |
| 62 | Camera3Device(int id); |
| 63 | |
| 64 | virtual ~Camera3Device(); |
| 65 | |
| 66 | /** |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 67 | * CameraDeviceBase interface |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 68 | */ |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 69 | |
Igor Murashkin | 7138105 | 2013-03-04 14:53:08 -0800 | [diff] [blame] | 70 | virtual int getId() const; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 71 | |
| 72 | // Transitions to idle state on success. |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 73 | virtual status_t initialize(camera_module_t *module); |
| 74 | virtual status_t disconnect(); |
| 75 | virtual status_t dump(int fd, const Vector<String16> &args); |
| 76 | virtual const CameraMetadata& info() const; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 77 | |
| 78 | // Capture and setStreamingRequest will configure streams if currently in |
| 79 | // idle state |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 80 | virtual status_t capture(CameraMetadata &request); |
| 81 | virtual status_t setStreamingRequest(const CameraMetadata &request); |
| 82 | virtual status_t clearStreamingRequest(); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 83 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 84 | virtual status_t waitUntilRequestReceived(int32_t requestId, nsecs_t timeout); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 85 | |
| 86 | // Actual stream creation/deletion is delayed until first request is submitted |
| 87 | // If adding streams while actively capturing, will pause device before adding |
| 88 | // stream, reconfiguring device, and unpausing. |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 89 | virtual status_t createStream(sp<ANativeWindow> consumer, |
| 90 | uint32_t width, uint32_t height, int format, size_t size, |
| 91 | int *id); |
Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 92 | virtual status_t createInputStream( |
| 93 | uint32_t width, uint32_t height, int format, |
| 94 | int *id); |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 95 | virtual status_t createZslStream( |
| 96 | uint32_t width, uint32_t height, |
| 97 | int depth, |
| 98 | /*out*/ |
| 99 | int *id, |
| 100 | sp<camera3::Camera3ZslStream>* zslStream); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 101 | virtual status_t createReprocessStreamFromStream(int outputId, int *id); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 102 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 103 | virtual status_t getStreamInfo(int id, |
| 104 | uint32_t *width, uint32_t *height, uint32_t *format); |
| 105 | virtual status_t setStreamTransform(int id, int transform); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 106 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 107 | virtual status_t deleteStream(int id); |
| 108 | virtual status_t deleteReprocessStream(int id); |
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 createDefaultRequest(int templateId, CameraMetadata *request); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 111 | |
| 112 | // Transitions to the idle state on success |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 113 | virtual status_t waitUntilDrained(); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 114 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 115 | virtual status_t setNotifyCallback(NotificationListener *listener); |
Eino-Ville Talvala | 46910bd | 2013-07-18 19:15:17 -0700 | [diff] [blame] | 116 | virtual bool willNotify3A(); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 117 | virtual status_t waitForNextFrame(nsecs_t timeout); |
| 118 | virtual status_t getNextFrame(CameraMetadata *frame); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 119 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 120 | virtual status_t triggerAutofocus(uint32_t id); |
| 121 | virtual status_t triggerCancelAutofocus(uint32_t id); |
| 122 | virtual status_t triggerPrecaptureMetering(uint32_t id); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 123 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 124 | virtual status_t pushReprocessBuffer(int reprocessStreamId, |
| 125 | buffer_handle_t *buffer, wp<BufferReleasedListener> listener); |
| 126 | |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 127 | virtual status_t flush(); |
| 128 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 129 | private: |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 130 | static const size_t kDumpLockAttempts = 10; |
| 131 | static const size_t kDumpSleepDuration = 100000; // 0.10 sec |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 132 | static const size_t kInFlightWarnLimit = 20; |
| 133 | static const nsecs_t kShutdownTimeout = 5000000000; // 5 sec |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 134 | struct RequestTrigger; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 135 | |
| 136 | Mutex mLock; |
| 137 | |
| 138 | /**** Scope for mLock ****/ |
| 139 | |
| 140 | const int mId; |
| 141 | camera3_device_t *mHal3Device; |
| 142 | |
| 143 | CameraMetadata mDeviceInfo; |
| 144 | vendor_tag_query_ops_t mVendorTagOps; |
| 145 | |
| 146 | enum { |
| 147 | STATUS_ERROR, |
| 148 | STATUS_UNINITIALIZED, |
| 149 | STATUS_IDLE, |
| 150 | STATUS_ACTIVE |
| 151 | } mStatus; |
| 152 | |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 153 | // Tracking cause of fatal errors when in STATUS_ERROR |
| 154 | String8 mErrorCause; |
| 155 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 156 | // Mapping of stream IDs to stream instances |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 157 | typedef KeyedVector<int, sp<camera3::Camera3OutputStreamInterface> > |
| 158 | StreamSet; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 159 | |
| 160 | StreamSet mOutputStreams; |
| 161 | sp<camera3::Camera3Stream> mInputStream; |
| 162 | int mNextStreamId; |
Eino-Ville Talvala | ea26c77 | 2013-06-11 16:04:06 -0700 | [diff] [blame] | 163 | bool mNeedConfig; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 164 | |
| 165 | // Need to hold on to stream references until configure completes. |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 166 | Vector<sp<camera3::Camera3StreamInterface> > mDeletedStreams; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 167 | |
| 168 | /**** End scope for mLock ****/ |
| 169 | |
| 170 | class CaptureRequest : public LightRefBase<CaptureRequest> { |
| 171 | public: |
| 172 | CameraMetadata mSettings; |
| 173 | sp<camera3::Camera3Stream> mInputStream; |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 174 | Vector<sp<camera3::Camera3OutputStreamInterface> > |
| 175 | mOutputStreams; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 176 | }; |
| 177 | typedef List<sp<CaptureRequest> > RequestList; |
| 178 | |
| 179 | /** |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 180 | * Get the last request submitted to the hal by the request thread. |
| 181 | * |
| 182 | * Takes mLock. |
| 183 | */ |
| 184 | virtual CameraMetadata getLatestRequest(); |
| 185 | |
| 186 | /** |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 187 | * Lock-held version of waitUntilDrained. Will transition to IDLE on |
| 188 | * success. |
| 189 | */ |
| 190 | status_t waitUntilDrainedLocked(); |
| 191 | |
| 192 | /** |
| 193 | * Do common work for setting up a streaming or single capture request. |
| 194 | * On success, will transition to ACTIVE if in IDLE. |
| 195 | */ |
| 196 | sp<CaptureRequest> setUpRequestLocked(const CameraMetadata &request); |
| 197 | |
| 198 | /** |
| 199 | * Build a CaptureRequest request from the CameraDeviceBase request |
| 200 | * settings. |
| 201 | */ |
| 202 | sp<CaptureRequest> createCaptureRequest(const CameraMetadata &request); |
| 203 | |
| 204 | /** |
| 205 | * Take the currently-defined set of streams and configure the HAL to use |
| 206 | * them. This is a long-running operation (may be several hundered ms). |
| 207 | */ |
| 208 | status_t configureStreamsLocked(); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 209 | |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 210 | /** |
| 211 | * Set device into an error state due to some fatal failure, and set an |
| 212 | * error message to indicate why. Only the first call's message will be |
| 213 | * used. The message is also sent to the log. |
| 214 | */ |
| 215 | void setErrorState(const char *fmt, ...); |
| 216 | void setErrorStateV(const char *fmt, va_list args); |
| 217 | void setErrorStateLocked(const char *fmt, ...); |
| 218 | void setErrorStateLockedV(const char *fmt, va_list args); |
| 219 | |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 220 | struct RequestTrigger { |
| 221 | // Metadata tag number, e.g. android.control.aePrecaptureTrigger |
| 222 | uint32_t metadataTag; |
| 223 | // Metadata value, e.g. 'START' or the trigger ID |
| 224 | int32_t entryValue; |
| 225 | |
| 226 | // The last part of the fully qualified path, e.g. afTrigger |
| 227 | const char *getTagName() const { |
| 228 | return get_camera_metadata_tag_name(metadataTag) ?: "NULL"; |
| 229 | } |
| 230 | |
| 231 | // e.g. TYPE_BYTE, TYPE_INT32, etc. |
| 232 | int getTagType() const { |
| 233 | return get_camera_metadata_tag_type(metadataTag); |
| 234 | } |
| 235 | }; |
| 236 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 237 | /** |
| 238 | * Thread for managing capture request submission to HAL device. |
| 239 | */ |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 240 | class RequestThread : public Thread { |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 241 | |
| 242 | public: |
| 243 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 244 | RequestThread(wp<Camera3Device> parent, |
| 245 | camera3_device_t *hal3Device); |
| 246 | |
| 247 | /** |
| 248 | * Call after stream (re)-configuration is completed. |
| 249 | */ |
| 250 | void configurationComplete(); |
| 251 | |
| 252 | /** |
| 253 | * Set or clear the list of repeating requests. Does not block |
| 254 | * on either. Use waitUntilPaused to wait until request queue |
| 255 | * has emptied out. |
| 256 | */ |
| 257 | status_t setRepeatingRequests(const RequestList& requests); |
| 258 | status_t clearRepeatingRequests(); |
| 259 | |
| 260 | status_t queueRequest(sp<CaptureRequest> request); |
| 261 | |
| 262 | /** |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 263 | * Remove all queued and repeating requests, and pending triggers |
| 264 | */ |
| 265 | status_t clear(); |
| 266 | |
| 267 | /** |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 268 | * Queue a trigger to be dispatched with the next outgoing |
| 269 | * process_capture_request. The settings for that request only |
| 270 | * will be temporarily rewritten to add the trigger tag/value. |
| 271 | * Subsequent requests will not be rewritten (for this tag). |
| 272 | */ |
| 273 | status_t queueTrigger(RequestTrigger trigger[], size_t count); |
| 274 | |
| 275 | /** |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 276 | * Pause/unpause the capture thread. Doesn't block, so use |
| 277 | * waitUntilPaused to wait until the thread is paused. |
| 278 | */ |
| 279 | void setPaused(bool paused); |
| 280 | |
| 281 | /** |
| 282 | * Wait until thread is paused, either due to setPaused(true) |
| 283 | * or due to lack of input requests. Returns TIMED_OUT in case |
| 284 | * the thread does not pause within the timeout. |
| 285 | */ |
| 286 | status_t waitUntilPaused(nsecs_t timeout); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 287 | |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 288 | /** |
| 289 | * Wait until thread processes the capture request with settings' |
| 290 | * android.request.id == requestId. |
| 291 | * |
| 292 | * Returns TIMED_OUT in case the thread does not process the request |
| 293 | * within the timeout. |
| 294 | */ |
| 295 | status_t waitUntilRequestProcessed(int32_t requestId, nsecs_t timeout); |
| 296 | |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 297 | /** |
| 298 | * Get the latest request that was sent to the HAL |
| 299 | * with process_capture_request. |
| 300 | */ |
| 301 | CameraMetadata getLatestRequest() const; |
| 302 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 303 | protected: |
| 304 | |
| 305 | virtual bool threadLoop(); |
| 306 | |
| 307 | private: |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 308 | static int getId(const wp<Camera3Device> &device); |
| 309 | |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 310 | status_t queueTriggerLocked(RequestTrigger trigger); |
| 311 | // Mix-in queued triggers into this request |
| 312 | int32_t insertTriggers(const sp<CaptureRequest> &request); |
| 313 | // Purge the queued triggers from this request, |
| 314 | // restoring the old field values for those tags. |
| 315 | status_t removeTriggers(const sp<CaptureRequest> &request); |
| 316 | |
Eino-Ville Talvala | 2f876f9 | 2013-09-13 11:39:24 -0700 | [diff] [blame] | 317 | // HAL workaround: Make sure a trigger ID always exists if |
| 318 | // a trigger does |
| 319 | status_t addDummyTriggerIds(const sp<CaptureRequest> &request); |
| 320 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 321 | static const nsecs_t kRequestTimeout = 50e6; // 50 ms |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 322 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 323 | // Waits for a request, or returns NULL if times out. |
| 324 | sp<CaptureRequest> waitForNextRequest(); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 325 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 326 | // Return buffers, etc, for a request that couldn't be fully |
| 327 | // constructed. The buffers will be returned in the ERROR state |
| 328 | // to mark them as not having valid data. |
| 329 | // All arguments will be modified. |
| 330 | void cleanUpFailedRequest(camera3_capture_request_t &request, |
| 331 | sp<CaptureRequest> &nextRequest, |
| 332 | Vector<camera3_stream_buffer_t> &outputBuffers); |
| 333 | |
| 334 | // Pause handling |
| 335 | bool waitIfPaused(); |
Eino-Ville Talvala | 26fe6c7 | 2013-08-29 12:46:18 -0700 | [diff] [blame] | 336 | void unpauseForNewRequests(); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 337 | |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 338 | // Relay error to parent device object setErrorState |
| 339 | void setErrorState(const char *fmt, ...); |
| 340 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 341 | wp<Camera3Device> mParent; |
| 342 | camera3_device_t *mHal3Device; |
| 343 | |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 344 | const int mId; |
| 345 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 346 | Mutex mRequestLock; |
| 347 | Condition mRequestSignal; |
| 348 | RequestList mRequestQueue; |
| 349 | RequestList mRepeatingRequests; |
| 350 | |
| 351 | bool mReconfigured; |
| 352 | |
| 353 | // Used by waitIfPaused, waitForNextRequest, and waitUntilPaused |
| 354 | Mutex mPauseLock; |
| 355 | bool mDoPause; |
| 356 | Condition mDoPauseSignal; |
| 357 | bool mPaused; |
| 358 | Condition mPausedSignal; |
| 359 | |
| 360 | sp<CaptureRequest> mPrevRequest; |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 361 | int32_t mPrevTriggers; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 362 | |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 363 | uint32_t mFrameNumber; |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 364 | |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 365 | mutable Mutex mLatestRequestMutex; |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 366 | Condition mLatestRequestSignal; |
| 367 | // android.request.id for latest process_capture_request |
| 368 | int32_t mLatestRequestId; |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 369 | CameraMetadata mLatestRequest; |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 370 | |
| 371 | typedef KeyedVector<uint32_t/*tag*/, RequestTrigger> TriggerMap; |
| 372 | Mutex mTriggerMutex; |
| 373 | TriggerMap mTriggerMap; |
| 374 | TriggerMap mTriggerRemovedMap; |
| 375 | TriggerMap mTriggerReplacedMap; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 376 | }; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 377 | sp<RequestThread> mRequestThread; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 378 | |
| 379 | /** |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 380 | * In-flight queue for tracking completion of capture requests. |
| 381 | */ |
| 382 | |
| 383 | struct InFlightRequest { |
| 384 | // Set by notify() SHUTTER call. |
| 385 | nsecs_t captureTimestamp; |
Zhijun He | 1d1f846 | 2013-10-02 16:29:51 -0700 | [diff] [blame^] | 386 | int requestStatus; |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 387 | // Set by process_capture_result call with valid metadata |
| 388 | bool haveResultMetadata; |
| 389 | // Decremented by calls to process_capture_result with valid output |
| 390 | // buffers |
| 391 | int numBuffersLeft; |
| 392 | |
| 393 | InFlightRequest() : |
| 394 | captureTimestamp(0), |
Zhijun He | 1d1f846 | 2013-10-02 16:29:51 -0700 | [diff] [blame^] | 395 | requestStatus(OK), |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 396 | haveResultMetadata(false), |
| 397 | numBuffersLeft(0) { |
| 398 | } |
| 399 | |
| 400 | explicit InFlightRequest(int numBuffers) : |
| 401 | captureTimestamp(0), |
| 402 | haveResultMetadata(false), |
| 403 | numBuffersLeft(numBuffers) { |
| 404 | } |
| 405 | }; |
| 406 | // Map from frame number to the in-flight request state |
| 407 | typedef KeyedVector<uint32_t, InFlightRequest> InFlightMap; |
| 408 | |
| 409 | Mutex mInFlightLock; // Protects mInFlightMap |
| 410 | InFlightMap mInFlightMap; |
| 411 | |
| 412 | status_t registerInFlight(int32_t frameNumber, int32_t numBuffers); |
| 413 | |
| 414 | /** |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 415 | * Output result queue and current HAL device 3A state |
| 416 | */ |
| 417 | |
| 418 | // Lock for output side of device |
| 419 | Mutex mOutputLock; |
| 420 | |
| 421 | /**** Scope for mOutputLock ****/ |
| 422 | |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 423 | uint32_t mNextResultFrameNumber; |
| 424 | uint32_t mNextShutterFrameNumber; |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 425 | List<CameraMetadata> mResultQueue; |
| 426 | Condition mResultSignal; |
| 427 | NotificationListener *mListener; |
| 428 | |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 429 | /**** End scope for mOutputLock ****/ |
| 430 | |
| 431 | /** |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 432 | * Callback functions from HAL device |
| 433 | */ |
| 434 | void processCaptureResult(const camera3_capture_result *result); |
| 435 | |
| 436 | void notify(const camera3_notify_msg *msg); |
| 437 | |
| 438 | /** |
| 439 | * Static callback forwarding methods from HAL to instance |
| 440 | */ |
| 441 | static callbacks_process_capture_result_t sProcessCaptureResult; |
| 442 | |
| 443 | static callbacks_notify_t sNotify; |
| 444 | |
| 445 | }; // class Camera3Device |
| 446 | |
| 447 | }; // namespace android |
| 448 | |
| 449 | #endif |