blob: 9007a9b777509a8c7aa601fb4ca51101ae6901cc [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>
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080027
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070028#include "common/CameraDeviceBase.h"
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -070029#include "device3/StatusTracker.h"
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080030
31/**
32 * Function pointer types with C calling convention to
33 * use for HAL callback functions.
34 */
35extern "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
45namespace android {
46
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070047namespace camera3 {
48
49class Camera3Stream;
50class Camera3ZslStream;
51class Camera3OutputStreamInterface;
52class Camera3StreamInterface;
53
54}
55
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080056/**
57 * CameraDevice for HAL devices with version CAMERA_DEVICE_API_VERSION_3_0
58 */
59class Camera3Device :
60 public CameraDeviceBase,
61 private camera3_callback_ops {
62 public:
63 Camera3Device(int id);
64
65 virtual ~Camera3Device();
66
67 /**
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080068 * CameraDeviceBase interface
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080069 */
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080070
Igor Murashkin71381052013-03-04 14:53:08 -080071 virtual int getId() const;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080072
73 // Transitions to idle state on success.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080074 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 Talvalaf76e0272013-02-27 18:02:26 -080078
79 // Capture and setStreamingRequest will configure streams if currently in
80 // idle state
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080081 virtual status_t capture(CameraMetadata &request);
82 virtual status_t setStreamingRequest(const CameraMetadata &request);
83 virtual status_t clearStreamingRequest();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080084
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080085 virtual status_t waitUntilRequestReceived(int32_t requestId, nsecs_t timeout);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080086
87 // Actual stream creation/deletion is delayed until first request is submitted
88 // If adding streams while actively capturing, will pause device before adding
89 // stream, reconfiguring device, and unpausing.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080090 virtual status_t createStream(sp<ANativeWindow> consumer,
91 uint32_t width, uint32_t height, int format, size_t size,
92 int *id);
Igor Murashkin5a269fa2013-04-15 14:59:22 -070093 virtual status_t createInputStream(
94 uint32_t width, uint32_t height, int format,
95 int *id);
Igor Murashkin2fba5842013-04-22 14:03:54 -070096 virtual status_t createZslStream(
97 uint32_t width, uint32_t height,
98 int depth,
99 /*out*/
100 int *id,
101 sp<camera3::Camera3ZslStream>* zslStream);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800102 virtual status_t createReprocessStreamFromStream(int outputId, int *id);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800103
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800104 virtual status_t getStreamInfo(int id,
105 uint32_t *width, uint32_t *height, uint32_t *format);
106 virtual status_t setStreamTransform(int id, int transform);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800107
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800108 virtual status_t deleteStream(int id);
109 virtual status_t deleteReprocessStream(int id);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800110
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800111 virtual status_t createDefaultRequest(int templateId, CameraMetadata *request);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800112
113 // Transitions to the idle state on success
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800114 virtual status_t waitUntilDrained();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800115
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800116 virtual status_t setNotifyCallback(NotificationListener *listener);
Eino-Ville Talvala46910bd2013-07-18 19:15:17 -0700117 virtual bool willNotify3A();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800118 virtual status_t waitForNextFrame(nsecs_t timeout);
119 virtual status_t getNextFrame(CameraMetadata *frame);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800120
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800121 virtual status_t triggerAutofocus(uint32_t id);
122 virtual status_t triggerCancelAutofocus(uint32_t id);
123 virtual status_t triggerPrecaptureMetering(uint32_t id);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800124
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800125 virtual status_t pushReprocessBuffer(int reprocessStreamId,
126 buffer_handle_t *buffer, wp<BufferReleasedListener> listener);
127
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700128 virtual status_t flush();
129
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700130 // Methods called by subclasses
131 void notifyStatus(bool idle); // updates from StatusTracker
132
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800133 private:
Igor Murashkin1e479c02013-09-06 16:55:14 -0700134 static const size_t kDumpLockAttempts = 10;
135 static const size_t kDumpSleepDuration = 100000; // 0.10 sec
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700136 static const size_t kInFlightWarnLimit = 20;
137 static const nsecs_t kShutdownTimeout = 5000000000; // 5 sec
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700138 static const nsecs_t kActiveTimeout = 500000000; // 500 ms
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700139 struct RequestTrigger;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800140
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700141 // A lock to enforce serialization on the input/configure side
142 // of the public interface.
143 // Only locked by public methods inherited from CameraDeviceBase.
144 // Not locked by methods guarded by mOutputLock, since they may act
145 // concurrently to the input/configure side of the interface.
146 // Must be locked before mLock if both will be locked by a method
147 Mutex mInterfaceLock;
148
149 // The main lock on internal state
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800150 Mutex mLock;
151
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700152 // Camera device ID
153 const int mId;
154
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800155 /**** Scope for mLock ****/
156
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800157 camera3_device_t *mHal3Device;
158
159 CameraMetadata mDeviceInfo;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800160
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700161 enum Status {
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800162 STATUS_ERROR,
163 STATUS_UNINITIALIZED,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700164 STATUS_UNCONFIGURED,
165 STATUS_CONFIGURED,
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800166 STATUS_ACTIVE
167 } mStatus;
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700168 Vector<Status> mRecentStatusUpdates;
169 Condition mStatusChanged;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800170
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700171 // Tracking cause of fatal errors when in STATUS_ERROR
172 String8 mErrorCause;
173
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800174 // Mapping of stream IDs to stream instances
Igor Murashkin2fba5842013-04-22 14:03:54 -0700175 typedef KeyedVector<int, sp<camera3::Camera3OutputStreamInterface> >
176 StreamSet;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800177
178 StreamSet mOutputStreams;
179 sp<camera3::Camera3Stream> mInputStream;
180 int mNextStreamId;
Eino-Ville Talvalaea26c772013-06-11 16:04:06 -0700181 bool mNeedConfig;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800182
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700183 // Whether to send state updates upstream
184 // Pause when doing transparent reconfiguration
185 bool mPauseStateNotify;
186
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800187 // Need to hold on to stream references until configure completes.
Igor Murashkin2fba5842013-04-22 14:03:54 -0700188 Vector<sp<camera3::Camera3StreamInterface> > mDeletedStreams;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800189
Eino-Ville Talvalafd6ecdd2013-10-11 09:51:09 -0700190 // Whether quirk ANDROID_QUIRKS_USE_PARTIAL_RESULT is enabled
191 bool mUsePartialResultQuirk;
192
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800193 /**** End scope for mLock ****/
194
195 class CaptureRequest : public LightRefBase<CaptureRequest> {
196 public:
197 CameraMetadata mSettings;
198 sp<camera3::Camera3Stream> mInputStream;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700199 Vector<sp<camera3::Camera3OutputStreamInterface> >
200 mOutputStreams;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800201 };
202 typedef List<sp<CaptureRequest> > RequestList;
203
204 /**
Igor Murashkin1e479c02013-09-06 16:55:14 -0700205 * Get the last request submitted to the hal by the request thread.
206 *
207 * Takes mLock.
208 */
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700209 virtual CameraMetadata getLatestRequestLocked();
Igor Murashkin1e479c02013-09-06 16:55:14 -0700210
211 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700212 * Pause processing and flush everything, but don't tell the clients.
213 * This is for reconfiguring outputs transparently when according to the
214 * CameraDeviceBase interface we shouldn't need to.
215 * Must be called with mLock and mInterfaceLock both held.
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800216 */
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700217 status_t internalPauseAndWaitLocked();
218
219 /**
220 * Resume work after internalPauseAndWaitLocked()
221 * Must be called with mLock and mInterfaceLock both held.
222 */
223 status_t internalResumeLocked();
224
225 /**
226 * Wait until status tracker tells us we've transitioned to the target state
227 * set, which is either ACTIVE when active==true or IDLE (which is any
228 * non-ACTIVE state) when active==false.
229 *
230 * Needs to be called with mLock and mInterfaceLock held. This means there
231 * can ever only be one waiter at most.
232 *
233 * During the wait mLock is released.
234 *
235 */
236 status_t waitUntilStateThenRelock(bool active, nsecs_t timeout);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800237
238 /**
239 * Do common work for setting up a streaming or single capture request.
240 * On success, will transition to ACTIVE if in IDLE.
241 */
242 sp<CaptureRequest> setUpRequestLocked(const CameraMetadata &request);
243
244 /**
245 * Build a CaptureRequest request from the CameraDeviceBase request
246 * settings.
247 */
248 sp<CaptureRequest> createCaptureRequest(const CameraMetadata &request);
249
250 /**
251 * Take the currently-defined set of streams and configure the HAL to use
252 * them. This is a long-running operation (may be several hundered ms).
253 */
254 status_t configureStreamsLocked();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800255
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700256 /**
257 * Set device into an error state due to some fatal failure, and set an
258 * error message to indicate why. Only the first call's message will be
259 * used. The message is also sent to the log.
260 */
261 void setErrorState(const char *fmt, ...);
262 void setErrorStateV(const char *fmt, va_list args);
263 void setErrorStateLocked(const char *fmt, ...);
264 void setErrorStateLockedV(const char *fmt, va_list args);
265
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700266 /**
267 * Debugging trylock/spin method
268 * Try to acquire a lock a few times with sleeps between before giving up.
269 */
270 bool tryLockSpinRightRound(Mutex& lock);
271
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700272 struct RequestTrigger {
273 // Metadata tag number, e.g. android.control.aePrecaptureTrigger
274 uint32_t metadataTag;
275 // Metadata value, e.g. 'START' or the trigger ID
276 int32_t entryValue;
277
278 // The last part of the fully qualified path, e.g. afTrigger
279 const char *getTagName() const {
280 return get_camera_metadata_tag_name(metadataTag) ?: "NULL";
281 }
282
283 // e.g. TYPE_BYTE, TYPE_INT32, etc.
284 int getTagType() const {
285 return get_camera_metadata_tag_type(metadataTag);
286 }
287 };
288
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800289 /**
290 * Thread for managing capture request submission to HAL device.
291 */
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800292 class RequestThread : public Thread {
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800293
294 public:
295
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800296 RequestThread(wp<Camera3Device> parent,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700297 sp<camera3::StatusTracker> statusTracker,
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800298 camera3_device_t *hal3Device);
299
300 /**
301 * Call after stream (re)-configuration is completed.
302 */
303 void configurationComplete();
304
305 /**
306 * Set or clear the list of repeating requests. Does not block
307 * on either. Use waitUntilPaused to wait until request queue
308 * has emptied out.
309 */
310 status_t setRepeatingRequests(const RequestList& requests);
311 status_t clearRepeatingRequests();
312
313 status_t queueRequest(sp<CaptureRequest> request);
314
315 /**
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700316 * Remove all queued and repeating requests, and pending triggers
317 */
318 status_t clear();
319
320 /**
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700321 * Queue a trigger to be dispatched with the next outgoing
322 * process_capture_request. The settings for that request only
323 * will be temporarily rewritten to add the trigger tag/value.
324 * Subsequent requests will not be rewritten (for this tag).
325 */
326 status_t queueTrigger(RequestTrigger trigger[], size_t count);
327
328 /**
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800329 * Pause/unpause the capture thread. Doesn't block, so use
330 * waitUntilPaused to wait until the thread is paused.
331 */
332 void setPaused(bool paused);
333
334 /**
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700335 * Wait until thread processes the capture request with settings'
336 * android.request.id == requestId.
337 *
338 * Returns TIMED_OUT in case the thread does not process the request
339 * within the timeout.
340 */
341 status_t waitUntilRequestProcessed(int32_t requestId, nsecs_t timeout);
342
Igor Murashkin1e479c02013-09-06 16:55:14 -0700343 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700344 * Shut down the thread. Shutdown is asynchronous, so thread may
345 * still be running once this method returns.
346 */
347 virtual void requestExit();
348
349 /**
Igor Murashkin1e479c02013-09-06 16:55:14 -0700350 * Get the latest request that was sent to the HAL
351 * with process_capture_request.
352 */
353 CameraMetadata getLatestRequest() const;
354
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800355 protected:
356
357 virtual bool threadLoop();
358
359 private:
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700360 static int getId(const wp<Camera3Device> &device);
361
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700362 status_t queueTriggerLocked(RequestTrigger trigger);
363 // Mix-in queued triggers into this request
364 int32_t insertTriggers(const sp<CaptureRequest> &request);
365 // Purge the queued triggers from this request,
366 // restoring the old field values for those tags.
367 status_t removeTriggers(const sp<CaptureRequest> &request);
368
Eino-Ville Talvala2f876f92013-09-13 11:39:24 -0700369 // HAL workaround: Make sure a trigger ID always exists if
370 // a trigger does
371 status_t addDummyTriggerIds(const sp<CaptureRequest> &request);
372
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800373 static const nsecs_t kRequestTimeout = 50e6; // 50 ms
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800374
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800375 // Waits for a request, or returns NULL if times out.
376 sp<CaptureRequest> waitForNextRequest();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800377
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800378 // Return buffers, etc, for a request that couldn't be fully
379 // constructed. The buffers will be returned in the ERROR state
380 // to mark them as not having valid data.
381 // All arguments will be modified.
382 void cleanUpFailedRequest(camera3_capture_request_t &request,
383 sp<CaptureRequest> &nextRequest,
384 Vector<camera3_stream_buffer_t> &outputBuffers);
385
386 // Pause handling
387 bool waitIfPaused();
Eino-Ville Talvala26fe6c72013-08-29 12:46:18 -0700388 void unpauseForNewRequests();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800389
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700390 // Relay error to parent device object setErrorState
391 void setErrorState(const char *fmt, ...);
392
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800393 wp<Camera3Device> mParent;
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700394 wp<camera3::StatusTracker> mStatusTracker;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800395 camera3_device_t *mHal3Device;
396
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700397 const int mId; // The camera ID
398 int mStatusId; // The RequestThread's component ID for
399 // status tracking
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700400
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800401 Mutex mRequestLock;
402 Condition mRequestSignal;
403 RequestList mRequestQueue;
404 RequestList mRepeatingRequests;
405
406 bool mReconfigured;
407
408 // Used by waitIfPaused, waitForNextRequest, and waitUntilPaused
409 Mutex mPauseLock;
410 bool mDoPause;
411 Condition mDoPauseSignal;
412 bool mPaused;
413 Condition mPausedSignal;
414
415 sp<CaptureRequest> mPrevRequest;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700416 int32_t mPrevTriggers;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800417
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700418 uint32_t mFrameNumber;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700419
Igor Murashkin1e479c02013-09-06 16:55:14 -0700420 mutable Mutex mLatestRequestMutex;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700421 Condition mLatestRequestSignal;
422 // android.request.id for latest process_capture_request
423 int32_t mLatestRequestId;
Igor Murashkin1e479c02013-09-06 16:55:14 -0700424 CameraMetadata mLatestRequest;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700425
426 typedef KeyedVector<uint32_t/*tag*/, RequestTrigger> TriggerMap;
427 Mutex mTriggerMutex;
428 TriggerMap mTriggerMap;
429 TriggerMap mTriggerRemovedMap;
430 TriggerMap mTriggerReplacedMap;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800431 };
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800432 sp<RequestThread> mRequestThread;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800433
434 /**
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700435 * In-flight queue for tracking completion of capture requests.
436 */
437
438 struct InFlightRequest {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700439 // android.request.id for the request
440 int requestId;
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700441 // Set by notify() SHUTTER call.
442 nsecs_t captureTimestamp;
Zhijun He1d1f8462013-10-02 16:29:51 -0700443 int requestStatus;
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700444 // Set by process_capture_result call with valid metadata
445 bool haveResultMetadata;
446 // Decremented by calls to process_capture_result with valid output
447 // buffers
448 int numBuffersLeft;
449
Eino-Ville Talvalafd6ecdd2013-10-11 09:51:09 -0700450 // Fields used by the partial result quirk only
451 struct PartialResultQuirkInFlight {
452 // Set by process_capture_result once 3A has been sent to clients
453 bool haveSent3A;
454 // Result metadata collected so far, when partial results are in use
455 CameraMetadata collectedResult;
456
457 PartialResultQuirkInFlight():
458 haveSent3A(false) {
459 }
460 } partialResultQuirk;
461
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700462 // Default constructor needed by KeyedVector
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700463 InFlightRequest() :
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700464 requestId(0),
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700465 captureTimestamp(0),
Zhijun He1d1f8462013-10-02 16:29:51 -0700466 requestStatus(OK),
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700467 haveResultMetadata(false),
468 numBuffersLeft(0) {
469 }
470
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700471 InFlightRequest(int id, int numBuffers) :
472 requestId(id),
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700473 captureTimestamp(0),
Zhijun Hecc27e112013-10-03 16:12:43 -0700474 requestStatus(OK),
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700475 haveResultMetadata(false),
476 numBuffersLeft(numBuffers) {
477 }
478 };
479 // Map from frame number to the in-flight request state
480 typedef KeyedVector<uint32_t, InFlightRequest> InFlightMap;
481
482 Mutex mInFlightLock; // Protects mInFlightMap
483 InFlightMap mInFlightMap;
484
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700485 status_t registerInFlight(int32_t frameNumber, int32_t requestId,
486 int32_t numBuffers);
487
488 /**
Eino-Ville Talvalafd6ecdd2013-10-11 09:51:09 -0700489 * For the partial result quirk, check if all 3A state fields are available
490 * and if so, queue up 3A-only result to the client. Returns true if 3A
491 * is sent.
492 */
Eino-Ville Talvala184dfe42013-11-07 15:13:16 -0800493 bool processPartial3AQuirk(int32_t frameNumber, int32_t requestId,
494 const CameraMetadata& partial);
Eino-Ville Talvalafd6ecdd2013-10-11 09:51:09 -0700495
496 // Helpers for reading and writing 3A metadata into to/from partial results
497 template<typename T>
498 bool get3AResult(const CameraMetadata& result, int32_t tag,
499 T* value, int32_t frameNumber);
500
501 template<typename T>
502 bool insert3AResult(CameraMetadata &result, int32_t tag, const T* value,
503 int32_t frameNumber);
504 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700505 * Tracking for idle detection
506 */
507 sp<camera3::StatusTracker> mStatusTracker;
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700508
509 /**
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700510 * Output result queue and current HAL device 3A state
511 */
512
513 // Lock for output side of device
514 Mutex mOutputLock;
515
516 /**** Scope for mOutputLock ****/
517
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700518 uint32_t mNextResultFrameNumber;
519 uint32_t mNextShutterFrameNumber;
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700520 List<CameraMetadata> mResultQueue;
521 Condition mResultSignal;
522 NotificationListener *mListener;
523
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700524 /**** End scope for mOutputLock ****/
525
526 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800527 * Callback functions from HAL device
528 */
529 void processCaptureResult(const camera3_capture_result *result);
530
531 void notify(const camera3_notify_msg *msg);
532
533 /**
534 * Static callback forwarding methods from HAL to instance
535 */
536 static callbacks_process_capture_result_t sProcessCaptureResult;
537
538 static callbacks_notify_t sNotify;
539
540}; // class Camera3Device
541
542}; // namespace android
543
544#endif