blob: b1ea5edea1eba7987175acea29d403e0a25479b4 [file] [log] [blame]
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001/*
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 Talvalaf76e0272013-02-27 18:02:26 -080017#ifndef ANDROID_SERVERS_CAMERA3DEVICE_H
18#define ANDROID_SERVERS_CAMERA3DEVICE_H
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080019
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 Talvala7b82efe2013-07-25 17:12:35 -070025#include <utils/KeyedVector.h>
26#include <hardware/camera3.h>
Jianing Weicb0652e2014-03-12 18:29:36 -070027#include <camera/CaptureResult.h>
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080028
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070029#include "common/CameraDeviceBase.h"
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070030#include "device3/StatusTracker.h"
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080031
32/**
33 * Function pointer types with C calling convention to
34 * use for HAL callback functions.
35 */
36extern "C" {
37 typedef void (callbacks_process_capture_result_t)(
38 const struct camera3_callback_ops *,
39 const camera3_capture_result_t *);
40
41 typedef void (callbacks_notify_t)(
42 const struct camera3_callback_ops *,
43 const camera3_notify_msg_t *);
44}
45
46namespace android {
47
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070048namespace camera3 {
49
50class Camera3Stream;
51class Camera3ZslStream;
52class Camera3OutputStreamInterface;
53class Camera3StreamInterface;
54
55}
56
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080057/**
Zhijun He95dd5ba2014-03-26 18:18:00 -070058 * CameraDevice for HAL devices with version CAMERA_DEVICE_API_VERSION_3_0 or higher.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080059 */
60class Camera3Device :
61 public CameraDeviceBase,
62 private camera3_callback_ops {
63 public:
64 Camera3Device(int id);
65
66 virtual ~Camera3Device();
67
68 /**
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080069 * CameraDeviceBase interface
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080070 */
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080071
Igor Murashkin71381052013-03-04 14:53:08 -080072 virtual int getId() const;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080073
74 // Transitions to idle state on success.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080075 virtual status_t initialize(camera_module_t *module);
76 virtual status_t disconnect();
77 virtual status_t dump(int fd, const Vector<String16> &args);
78 virtual const CameraMetadata& info() const;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080079
80 // Capture and setStreamingRequest will configure streams if currently in
81 // idle state
Jianing Weicb0652e2014-03-12 18:29:36 -070082 virtual status_t capture(CameraMetadata &request, int64_t *lastFrameNumber = NULL);
83 virtual status_t captureList(const List<const CameraMetadata> &requests,
84 int64_t *lastFrameNumber = NULL);
85 virtual status_t setStreamingRequest(const CameraMetadata &request,
86 int64_t *lastFrameNumber = NULL);
87 virtual status_t setStreamingRequestList(const List<const CameraMetadata> &requests,
88 int64_t *lastFrameNumber = NULL);
89 virtual status_t clearStreamingRequest(int64_t *lastFrameNumber = NULL);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080090
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080091 virtual status_t waitUntilRequestReceived(int32_t requestId, nsecs_t timeout);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080092
93 // Actual stream creation/deletion is delayed until first request is submitted
94 // If adding streams while actively capturing, will pause device before adding
95 // stream, reconfiguring device, and unpausing.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080096 virtual status_t createStream(sp<ANativeWindow> consumer,
97 uint32_t width, uint32_t height, int format, size_t size,
98 int *id);
Igor Murashkin5a269fa2013-04-15 14:59:22 -070099 virtual status_t createInputStream(
100 uint32_t width, uint32_t height, int format,
101 int *id);
Igor Murashkin2fba5842013-04-22 14:03:54 -0700102 virtual status_t createZslStream(
103 uint32_t width, uint32_t height,
104 int depth,
105 /*out*/
106 int *id,
107 sp<camera3::Camera3ZslStream>* zslStream);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800108 virtual status_t createReprocessStreamFromStream(int outputId, int *id);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800109
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800110 virtual status_t getStreamInfo(int id,
111 uint32_t *width, uint32_t *height, uint32_t *format);
112 virtual status_t setStreamTransform(int id, int transform);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800113
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800114 virtual status_t deleteStream(int id);
115 virtual status_t deleteReprocessStream(int id);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800116
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800117 virtual status_t createDefaultRequest(int templateId, CameraMetadata *request);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800118
119 // Transitions to the idle state on success
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800120 virtual status_t waitUntilDrained();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800121
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800122 virtual status_t setNotifyCallback(NotificationListener *listener);
Eino-Ville Talvala46910bd2013-07-18 19:15:17 -0700123 virtual bool willNotify3A();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800124 virtual status_t waitForNextFrame(nsecs_t timeout);
Jianing Weicb0652e2014-03-12 18:29:36 -0700125 virtual status_t getNextResult(CaptureResult *frame);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800126
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800127 virtual status_t triggerAutofocus(uint32_t id);
128 virtual status_t triggerCancelAutofocus(uint32_t id);
129 virtual status_t triggerPrecaptureMetering(uint32_t id);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800130
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800131 virtual status_t pushReprocessBuffer(int reprocessStreamId,
132 buffer_handle_t *buffer, wp<BufferReleasedListener> listener);
133
Jianing Weicb0652e2014-03-12 18:29:36 -0700134 virtual status_t flush(int64_t *lastFrameNumber = NULL);
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700135
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700136 // Methods called by subclasses
137 void notifyStatus(bool idle); // updates from StatusTracker
138
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800139 private:
Igor Murashkin1e479c02013-09-06 16:55:14 -0700140 static const size_t kDumpLockAttempts = 10;
141 static const size_t kDumpSleepDuration = 100000; // 0.10 sec
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700142 static const size_t kInFlightWarnLimit = 20;
143 static const nsecs_t kShutdownTimeout = 5000000000; // 5 sec
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700144 static const nsecs_t kActiveTimeout = 500000000; // 500 ms
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700145 struct RequestTrigger;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800146
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700147 // A lock to enforce serialization on the input/configure side
148 // of the public interface.
149 // Only locked by public methods inherited from CameraDeviceBase.
150 // Not locked by methods guarded by mOutputLock, since they may act
151 // concurrently to the input/configure side of the interface.
152 // Must be locked before mLock if both will be locked by a method
153 Mutex mInterfaceLock;
154
155 // The main lock on internal state
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800156 Mutex mLock;
157
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700158 // Camera device ID
159 const int mId;
160
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800161 /**** Scope for mLock ****/
162
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800163 camera3_device_t *mHal3Device;
164
165 CameraMetadata mDeviceInfo;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800166
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700167 enum Status {
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800168 STATUS_ERROR,
169 STATUS_UNINITIALIZED,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700170 STATUS_UNCONFIGURED,
171 STATUS_CONFIGURED,
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800172 STATUS_ACTIVE
173 } mStatus;
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700174 Vector<Status> mRecentStatusUpdates;
175 Condition mStatusChanged;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800176
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700177 // Tracking cause of fatal errors when in STATUS_ERROR
178 String8 mErrorCause;
179
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800180 // Mapping of stream IDs to stream instances
Igor Murashkin2fba5842013-04-22 14:03:54 -0700181 typedef KeyedVector<int, sp<camera3::Camera3OutputStreamInterface> >
182 StreamSet;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800183
184 StreamSet mOutputStreams;
185 sp<camera3::Camera3Stream> mInputStream;
186 int mNextStreamId;
Eino-Ville Talvalaea26c772013-06-11 16:04:06 -0700187 bool mNeedConfig;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800188
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700189 // Whether to send state updates upstream
190 // Pause when doing transparent reconfiguration
191 bool mPauseStateNotify;
192
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800193 // Need to hold on to stream references until configure completes.
Igor Murashkin2fba5842013-04-22 14:03:54 -0700194 Vector<sp<camera3::Camera3StreamInterface> > mDeletedStreams;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800195
Eino-Ville Talvalafd6ecdd2013-10-11 09:51:09 -0700196 // Whether quirk ANDROID_QUIRKS_USE_PARTIAL_RESULT is enabled
197 bool mUsePartialResultQuirk;
198
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800199 /**** End scope for mLock ****/
200
201 class CaptureRequest : public LightRefBase<CaptureRequest> {
202 public:
203 CameraMetadata mSettings;
204 sp<camera3::Camera3Stream> mInputStream;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700205 Vector<sp<camera3::Camera3OutputStreamInterface> >
206 mOutputStreams;
Jianing Weicb0652e2014-03-12 18:29:36 -0700207 CaptureResultExtras mResultExtras;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800208 };
209 typedef List<sp<CaptureRequest> > RequestList;
210
Jianing Wei90e59c92014-03-12 18:29:36 -0700211 status_t checkStatusOkToCaptureLocked();
212
213 status_t convertMetadataListToRequestListLocked(
214 const List<const CameraMetadata> &metadataList,
215 /*out*/RequestList *requestList);
216
Jianing Weicb0652e2014-03-12 18:29:36 -0700217 status_t submitRequestsHelper(const List<const CameraMetadata> &requests, bool repeating,
218 int64_t *lastFrameNumber = NULL);
Jianing Wei90e59c92014-03-12 18:29:36 -0700219
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800220 /**
Igor Murashkin1e479c02013-09-06 16:55:14 -0700221 * Get the last request submitted to the hal by the request thread.
222 *
223 * Takes mLock.
224 */
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700225 virtual CameraMetadata getLatestRequestLocked();
Igor Murashkin1e479c02013-09-06 16:55:14 -0700226
227 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700228 * Pause processing and flush everything, but don't tell the clients.
229 * This is for reconfiguring outputs transparently when according to the
230 * CameraDeviceBase interface we shouldn't need to.
231 * Must be called with mLock and mInterfaceLock both held.
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800232 */
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700233 status_t internalPauseAndWaitLocked();
234
235 /**
236 * Resume work after internalPauseAndWaitLocked()
237 * Must be called with mLock and mInterfaceLock both held.
238 */
239 status_t internalResumeLocked();
240
241 /**
242 * Wait until status tracker tells us we've transitioned to the target state
243 * set, which is either ACTIVE when active==true or IDLE (which is any
244 * non-ACTIVE state) when active==false.
245 *
246 * Needs to be called with mLock and mInterfaceLock held. This means there
247 * can ever only be one waiter at most.
248 *
249 * During the wait mLock is released.
250 *
251 */
252 status_t waitUntilStateThenRelock(bool active, nsecs_t timeout);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800253
254 /**
Zhijun He69a37482014-03-23 18:44:49 -0700255 * Implementation of waitUntilDrained. On success, will transition to IDLE state.
256 *
257 * Need to be called with mLock and mInterfaceLock held.
258 */
259 status_t waitUntilDrainedLocked();
260
261 /**
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800262 * Do common work for setting up a streaming or single capture request.
263 * On success, will transition to ACTIVE if in IDLE.
264 */
265 sp<CaptureRequest> setUpRequestLocked(const CameraMetadata &request);
266
267 /**
268 * Build a CaptureRequest request from the CameraDeviceBase request
269 * settings.
270 */
271 sp<CaptureRequest> createCaptureRequest(const CameraMetadata &request);
272
273 /**
274 * Take the currently-defined set of streams and configure the HAL to use
275 * them. This is a long-running operation (may be several hundered ms).
276 */
277 status_t configureStreamsLocked();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800278
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700279 /**
280 * Set device into an error state due to some fatal failure, and set an
281 * error message to indicate why. Only the first call's message will be
282 * used. The message is also sent to the log.
283 */
284 void setErrorState(const char *fmt, ...);
285 void setErrorStateV(const char *fmt, va_list args);
286 void setErrorStateLocked(const char *fmt, ...);
287 void setErrorStateLockedV(const char *fmt, va_list args);
288
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700289 /**
290 * Debugging trylock/spin method
291 * Try to acquire a lock a few times with sleeps between before giving up.
292 */
293 bool tryLockSpinRightRound(Mutex& lock);
294
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700295 struct RequestTrigger {
296 // Metadata tag number, e.g. android.control.aePrecaptureTrigger
297 uint32_t metadataTag;
298 // Metadata value, e.g. 'START' or the trigger ID
299 int32_t entryValue;
300
301 // The last part of the fully qualified path, e.g. afTrigger
302 const char *getTagName() const {
303 return get_camera_metadata_tag_name(metadataTag) ?: "NULL";
304 }
305
306 // e.g. TYPE_BYTE, TYPE_INT32, etc.
307 int getTagType() const {
308 return get_camera_metadata_tag_type(metadataTag);
309 }
310 };
311
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800312 /**
313 * Thread for managing capture request submission to HAL device.
314 */
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800315 class RequestThread : public Thread {
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800316
317 public:
318
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800319 RequestThread(wp<Camera3Device> parent,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700320 sp<camera3::StatusTracker> statusTracker,
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800321 camera3_device_t *hal3Device);
322
323 /**
324 * Call after stream (re)-configuration is completed.
325 */
326 void configurationComplete();
327
328 /**
329 * Set or clear the list of repeating requests. Does not block
330 * on either. Use waitUntilPaused to wait until request queue
331 * has emptied out.
332 */
333 status_t setRepeatingRequests(const RequestList& requests);
334 status_t clearRepeatingRequests();
335
336 status_t queueRequest(sp<CaptureRequest> request);
337
Jianing Wei90e59c92014-03-12 18:29:36 -0700338 status_t queueRequestList(List<sp<CaptureRequest> > &requests);
339
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800340 /**
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700341 * Remove all queued and repeating requests, and pending triggers
342 */
343 status_t clear();
344
345 /**
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700346 * Queue a trigger to be dispatched with the next outgoing
347 * process_capture_request. The settings for that request only
348 * will be temporarily rewritten to add the trigger tag/value.
349 * Subsequent requests will not be rewritten (for this tag).
350 */
351 status_t queueTrigger(RequestTrigger trigger[], size_t count);
352
353 /**
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800354 * Pause/unpause the capture thread. Doesn't block, so use
355 * waitUntilPaused to wait until the thread is paused.
356 */
357 void setPaused(bool paused);
358
359 /**
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700360 * Wait until thread processes the capture request with settings'
361 * android.request.id == requestId.
362 *
363 * Returns TIMED_OUT in case the thread does not process the request
364 * within the timeout.
365 */
366 status_t waitUntilRequestProcessed(int32_t requestId, nsecs_t timeout);
367
Igor Murashkin1e479c02013-09-06 16:55:14 -0700368 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700369 * Shut down the thread. Shutdown is asynchronous, so thread may
370 * still be running once this method returns.
371 */
372 virtual void requestExit();
373
374 /**
Igor Murashkin1e479c02013-09-06 16:55:14 -0700375 * Get the latest request that was sent to the HAL
376 * with process_capture_request.
377 */
378 CameraMetadata getLatestRequest() const;
379
Jianing Weicb0652e2014-03-12 18:29:36 -0700380 int64_t getLastFrameNumber();
381
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800382 protected:
383
384 virtual bool threadLoop();
385
386 private:
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700387 static int getId(const wp<Camera3Device> &device);
388
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700389 status_t queueTriggerLocked(RequestTrigger trigger);
390 // Mix-in queued triggers into this request
391 int32_t insertTriggers(const sp<CaptureRequest> &request);
392 // Purge the queued triggers from this request,
393 // restoring the old field values for those tags.
394 status_t removeTriggers(const sp<CaptureRequest> &request);
395
Eino-Ville Talvala2f876f92013-09-13 11:39:24 -0700396 // HAL workaround: Make sure a trigger ID always exists if
397 // a trigger does
398 status_t addDummyTriggerIds(const sp<CaptureRequest> &request);
399
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800400 static const nsecs_t kRequestTimeout = 50e6; // 50 ms
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800401
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800402 // Waits for a request, or returns NULL if times out.
403 sp<CaptureRequest> waitForNextRequest();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800404
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800405 // Return buffers, etc, for a request that couldn't be fully
406 // constructed. The buffers will be returned in the ERROR state
407 // to mark them as not having valid data.
408 // All arguments will be modified.
409 void cleanUpFailedRequest(camera3_capture_request_t &request,
410 sp<CaptureRequest> &nextRequest,
411 Vector<camera3_stream_buffer_t> &outputBuffers);
412
413 // Pause handling
414 bool waitIfPaused();
Eino-Ville Talvala26fe6c72013-08-29 12:46:18 -0700415 void unpauseForNewRequests();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800416
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700417 // Relay error to parent device object setErrorState
418 void setErrorState(const char *fmt, ...);
419
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800420 wp<Camera3Device> mParent;
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700421 wp<camera3::StatusTracker> mStatusTracker;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800422 camera3_device_t *mHal3Device;
423
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700424 const int mId; // The camera ID
425 int mStatusId; // The RequestThread's component ID for
426 // status tracking
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700427
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800428 Mutex mRequestLock;
429 Condition mRequestSignal;
430 RequestList mRequestQueue;
431 RequestList mRepeatingRequests;
432
433 bool mReconfigured;
434
435 // Used by waitIfPaused, waitForNextRequest, and waitUntilPaused
436 Mutex mPauseLock;
437 bool mDoPause;
438 Condition mDoPauseSignal;
439 bool mPaused;
440 Condition mPausedSignal;
441
442 sp<CaptureRequest> mPrevRequest;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700443 int32_t mPrevTriggers;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800444
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700445 uint32_t mFrameNumber;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700446
Igor Murashkin1e479c02013-09-06 16:55:14 -0700447 mutable Mutex mLatestRequestMutex;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700448 Condition mLatestRequestSignal;
449 // android.request.id for latest process_capture_request
450 int32_t mLatestRequestId;
Igor Murashkin1e479c02013-09-06 16:55:14 -0700451 CameraMetadata mLatestRequest;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700452
453 typedef KeyedVector<uint32_t/*tag*/, RequestTrigger> TriggerMap;
454 Mutex mTriggerMutex;
455 TriggerMap mTriggerMap;
456 TriggerMap mTriggerRemovedMap;
457 TriggerMap mTriggerReplacedMap;
Jianing Weicb0652e2014-03-12 18:29:36 -0700458
459 int64_t mLastFrameNumber;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800460 };
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800461 sp<RequestThread> mRequestThread;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800462
463 /**
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700464 * In-flight queue for tracking completion of capture requests.
465 */
466
467 struct InFlightRequest {
468 // Set by notify() SHUTTER call.
469 nsecs_t captureTimestamp;
Zhijun He1d1f8462013-10-02 16:29:51 -0700470 int requestStatus;
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700471 // Set by process_capture_result call with valid metadata
472 bool haveResultMetadata;
473 // Decremented by calls to process_capture_result with valid output
474 // buffers
475 int numBuffersLeft;
Jianing Weicb0652e2014-03-12 18:29:36 -0700476 CaptureResultExtras resultExtras;
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700477
Eino-Ville Talvalafd6ecdd2013-10-11 09:51:09 -0700478 // Fields used by the partial result quirk only
479 struct PartialResultQuirkInFlight {
480 // Set by process_capture_result once 3A has been sent to clients
481 bool haveSent3A;
482 // Result metadata collected so far, when partial results are in use
483 CameraMetadata collectedResult;
484
485 PartialResultQuirkInFlight():
486 haveSent3A(false) {
487 }
488 } partialResultQuirk;
489
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700490 // Default constructor needed by KeyedVector
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700491 InFlightRequest() :
492 captureTimestamp(0),
Zhijun He1d1f8462013-10-02 16:29:51 -0700493 requestStatus(OK),
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700494 haveResultMetadata(false),
495 numBuffersLeft(0) {
496 }
497
Jianing Weicb0652e2014-03-12 18:29:36 -0700498 InFlightRequest(int numBuffers) :
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700499 captureTimestamp(0),
Zhijun Hecc27e112013-10-03 16:12:43 -0700500 requestStatus(OK),
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700501 haveResultMetadata(false),
502 numBuffersLeft(numBuffers) {
503 }
Jianing Weicb0652e2014-03-12 18:29:36 -0700504
505 InFlightRequest(int numBuffers, CaptureResultExtras extras) :
506 captureTimestamp(0),
507 requestStatus(OK),
508 haveResultMetadata(false),
509 numBuffersLeft(numBuffers),
510 resultExtras(extras) {
511 }
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700512 };
513 // Map from frame number to the in-flight request state
514 typedef KeyedVector<uint32_t, InFlightRequest> InFlightMap;
515
516 Mutex mInFlightLock; // Protects mInFlightMap
517 InFlightMap mInFlightMap;
518
Jianing Weicb0652e2014-03-12 18:29:36 -0700519 status_t registerInFlight(uint32_t frameNumber,
520 int32_t numBuffers, CaptureResultExtras resultExtras);
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700521
522 /**
Eino-Ville Talvalafd6ecdd2013-10-11 09:51:09 -0700523 * For the partial result quirk, check if all 3A state fields are available
524 * and if so, queue up 3A-only result to the client. Returns true if 3A
525 * is sent.
526 */
Jianing Weicb0652e2014-03-12 18:29:36 -0700527 bool processPartial3AQuirk(uint32_t frameNumber,
528 const CameraMetadata& partial, const CaptureResultExtras& resultExtras);
Eino-Ville Talvalafd6ecdd2013-10-11 09:51:09 -0700529
530 // Helpers for reading and writing 3A metadata into to/from partial results
531 template<typename T>
532 bool get3AResult(const CameraMetadata& result, int32_t tag,
Jianing Weicb0652e2014-03-12 18:29:36 -0700533 T* value, uint32_t frameNumber);
Eino-Ville Talvalafd6ecdd2013-10-11 09:51:09 -0700534
535 template<typename T>
536 bool insert3AResult(CameraMetadata &result, int32_t tag, const T* value,
Jianing Weicb0652e2014-03-12 18:29:36 -0700537 uint32_t frameNumber);
Eino-Ville Talvalafd6ecdd2013-10-11 09:51:09 -0700538 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700539 * Tracking for idle detection
540 */
541 sp<camera3::StatusTracker> mStatusTracker;
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700542
543 /**
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700544 * Output result queue and current HAL device 3A state
545 */
546
547 // Lock for output side of device
548 Mutex mOutputLock;
549
550 /**** Scope for mOutputLock ****/
551
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700552 uint32_t mNextResultFrameNumber;
553 uint32_t mNextShutterFrameNumber;
Jianing Weicb0652e2014-03-12 18:29:36 -0700554 List<CaptureResult> mResultQueue;
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700555 Condition mResultSignal;
556 NotificationListener *mListener;
557
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700558 /**** End scope for mOutputLock ****/
559
560 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800561 * Callback functions from HAL device
562 */
563 void processCaptureResult(const camera3_capture_result *result);
564
565 void notify(const camera3_notify_msg *msg);
566
567 /**
568 * Static callback forwarding methods from HAL to instance
569 */
570 static callbacks_process_capture_result_t sProcessCaptureResult;
571
572 static callbacks_notify_t sNotify;
573
574}; // class Camera3Device
575
576}; // namespace android
577
578#endif