blob: 44c6260e12beaf92468ad0445ebb11256e14f80b [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);
Jianing Wei90e59c92014-03-12 18:29:36 -070082 virtual status_t captureList(const List<const CameraMetadata> &requests);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080083 virtual status_t setStreamingRequest(const CameraMetadata &request);
Jianing Wei90e59c92014-03-12 18:29:36 -070084 virtual status_t setStreamingRequestList(const List<const CameraMetadata> &requests);
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080085 virtual status_t clearStreamingRequest();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080086
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080087 virtual status_t waitUntilRequestReceived(int32_t requestId, nsecs_t timeout);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -080088
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 Talvala7fa43f32013-02-06 17:20:07 -080092 virtual status_t createStream(sp<ANativeWindow> consumer,
93 uint32_t width, uint32_t height, int format, size_t size,
94 int *id);
Igor Murashkin5a269fa2013-04-15 14:59:22 -070095 virtual status_t createInputStream(
96 uint32_t width, uint32_t height, int format,
97 int *id);
Igor Murashkin2fba5842013-04-22 14:03:54 -070098 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 Talvala7fa43f32013-02-06 17:20:07 -0800104 virtual status_t createReprocessStreamFromStream(int outputId, int *id);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800105
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800106 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 Talvalaf76e0272013-02-27 18:02:26 -0800109
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800110 virtual status_t deleteStream(int id);
111 virtual status_t deleteReprocessStream(int id);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800112
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800113 virtual status_t createDefaultRequest(int templateId, CameraMetadata *request);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800114
115 // Transitions to the idle state on success
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800116 virtual status_t waitUntilDrained();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800117
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800118 virtual status_t setNotifyCallback(NotificationListener *listener);
Eino-Ville Talvala46910bd2013-07-18 19:15:17 -0700119 virtual bool willNotify3A();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800120 virtual status_t waitForNextFrame(nsecs_t timeout);
121 virtual status_t getNextFrame(CameraMetadata *frame);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800122
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800123 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 Talvalaf76e0272013-02-27 18:02:26 -0800126
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800127 virtual status_t pushReprocessBuffer(int reprocessStreamId,
128 buffer_handle_t *buffer, wp<BufferReleasedListener> listener);
129
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700130 virtual status_t flush();
131
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700132 // Methods called by subclasses
133 void notifyStatus(bool idle); // updates from StatusTracker
134
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800135 private:
Igor Murashkin1e479c02013-09-06 16:55:14 -0700136 static const size_t kDumpLockAttempts = 10;
137 static const size_t kDumpSleepDuration = 100000; // 0.10 sec
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700138 static const size_t kInFlightWarnLimit = 20;
139 static const nsecs_t kShutdownTimeout = 5000000000; // 5 sec
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700140 static const nsecs_t kActiveTimeout = 500000000; // 500 ms
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700141 struct RequestTrigger;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800142
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700143 // 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 Talvalaf76e0272013-02-27 18:02:26 -0800152 Mutex mLock;
153
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700154 // Camera device ID
155 const int mId;
156
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800157 /**** Scope for mLock ****/
158
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800159 camera3_device_t *mHal3Device;
160
161 CameraMetadata mDeviceInfo;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800162
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700163 enum Status {
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800164 STATUS_ERROR,
165 STATUS_UNINITIALIZED,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700166 STATUS_UNCONFIGURED,
167 STATUS_CONFIGURED,
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800168 STATUS_ACTIVE
169 } mStatus;
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700170 Vector<Status> mRecentStatusUpdates;
171 Condition mStatusChanged;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800172
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700173 // Tracking cause of fatal errors when in STATUS_ERROR
174 String8 mErrorCause;
175
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800176 // Mapping of stream IDs to stream instances
Igor Murashkin2fba5842013-04-22 14:03:54 -0700177 typedef KeyedVector<int, sp<camera3::Camera3OutputStreamInterface> >
178 StreamSet;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800179
180 StreamSet mOutputStreams;
181 sp<camera3::Camera3Stream> mInputStream;
182 int mNextStreamId;
Eino-Ville Talvalaea26c772013-06-11 16:04:06 -0700183 bool mNeedConfig;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800184
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700185 // Whether to send state updates upstream
186 // Pause when doing transparent reconfiguration
187 bool mPauseStateNotify;
188
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800189 // Need to hold on to stream references until configure completes.
Igor Murashkin2fba5842013-04-22 14:03:54 -0700190 Vector<sp<camera3::Camera3StreamInterface> > mDeletedStreams;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800191
Eino-Ville Talvalafd6ecdd2013-10-11 09:51:09 -0700192 // Whether quirk ANDROID_QUIRKS_USE_PARTIAL_RESULT is enabled
193 bool mUsePartialResultQuirk;
194
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800195 /**** End scope for mLock ****/
196
197 class CaptureRequest : public LightRefBase<CaptureRequest> {
198 public:
199 CameraMetadata mSettings;
200 sp<camera3::Camera3Stream> mInputStream;
Igor Murashkin2fba5842013-04-22 14:03:54 -0700201 Vector<sp<camera3::Camera3OutputStreamInterface> >
202 mOutputStreams;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800203 };
204 typedef List<sp<CaptureRequest> > RequestList;
205
Jianing Wei90e59c92014-03-12 18:29:36 -0700206 status_t checkStatusOkToCaptureLocked();
207
208 status_t convertMetadataListToRequestListLocked(
209 const List<const CameraMetadata> &metadataList,
210 /*out*/RequestList *requestList);
211
212 status_t submitRequestsHelper(const List<const CameraMetadata> &requests, bool repeating);
213
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800214 /**
Igor Murashkin1e479c02013-09-06 16:55:14 -0700215 * Get the last request submitted to the hal by the request thread.
216 *
217 * Takes mLock.
218 */
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700219 virtual CameraMetadata getLatestRequestLocked();
Igor Murashkin1e479c02013-09-06 16:55:14 -0700220
221 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700222 * Pause processing and flush everything, but don't tell the clients.
223 * This is for reconfiguring outputs transparently when according to the
224 * CameraDeviceBase interface we shouldn't need to.
225 * Must be called with mLock and mInterfaceLock both held.
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800226 */
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700227 status_t internalPauseAndWaitLocked();
228
229 /**
230 * Resume work after internalPauseAndWaitLocked()
231 * Must be called with mLock and mInterfaceLock both held.
232 */
233 status_t internalResumeLocked();
234
235 /**
236 * Wait until status tracker tells us we've transitioned to the target state
237 * set, which is either ACTIVE when active==true or IDLE (which is any
238 * non-ACTIVE state) when active==false.
239 *
240 * Needs to be called with mLock and mInterfaceLock held. This means there
241 * can ever only be one waiter at most.
242 *
243 * During the wait mLock is released.
244 *
245 */
246 status_t waitUntilStateThenRelock(bool active, nsecs_t timeout);
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800247
248 /**
249 * Do common work for setting up a streaming or single capture request.
250 * On success, will transition to ACTIVE if in IDLE.
251 */
252 sp<CaptureRequest> setUpRequestLocked(const CameraMetadata &request);
253
254 /**
255 * Build a CaptureRequest request from the CameraDeviceBase request
256 * settings.
257 */
258 sp<CaptureRequest> createCaptureRequest(const CameraMetadata &request);
259
260 /**
261 * Take the currently-defined set of streams and configure the HAL to use
262 * them. This is a long-running operation (may be several hundered ms).
263 */
264 status_t configureStreamsLocked();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800265
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700266 /**
267 * Set device into an error state due to some fatal failure, and set an
268 * error message to indicate why. Only the first call's message will be
269 * used. The message is also sent to the log.
270 */
271 void setErrorState(const char *fmt, ...);
272 void setErrorStateV(const char *fmt, va_list args);
273 void setErrorStateLocked(const char *fmt, ...);
274 void setErrorStateLockedV(const char *fmt, va_list args);
275
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700276 /**
277 * Debugging trylock/spin method
278 * Try to acquire a lock a few times with sleeps between before giving up.
279 */
280 bool tryLockSpinRightRound(Mutex& lock);
281
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700282 struct RequestTrigger {
283 // Metadata tag number, e.g. android.control.aePrecaptureTrigger
284 uint32_t metadataTag;
285 // Metadata value, e.g. 'START' or the trigger ID
286 int32_t entryValue;
287
288 // The last part of the fully qualified path, e.g. afTrigger
289 const char *getTagName() const {
290 return get_camera_metadata_tag_name(metadataTag) ?: "NULL";
291 }
292
293 // e.g. TYPE_BYTE, TYPE_INT32, etc.
294 int getTagType() const {
295 return get_camera_metadata_tag_type(metadataTag);
296 }
297 };
298
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800299 /**
300 * Thread for managing capture request submission to HAL device.
301 */
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800302 class RequestThread : public Thread {
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800303
304 public:
305
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800306 RequestThread(wp<Camera3Device> parent,
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700307 sp<camera3::StatusTracker> statusTracker,
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800308 camera3_device_t *hal3Device);
309
310 /**
311 * Call after stream (re)-configuration is completed.
312 */
313 void configurationComplete();
314
315 /**
316 * Set or clear the list of repeating requests. Does not block
317 * on either. Use waitUntilPaused to wait until request queue
318 * has emptied out.
319 */
320 status_t setRepeatingRequests(const RequestList& requests);
321 status_t clearRepeatingRequests();
322
323 status_t queueRequest(sp<CaptureRequest> request);
324
Jianing Wei90e59c92014-03-12 18:29:36 -0700325 status_t queueRequestList(List<sp<CaptureRequest> > &requests);
326
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800327 /**
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700328 * Remove all queued and repeating requests, and pending triggers
329 */
330 status_t clear();
331
332 /**
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700333 * Queue a trigger to be dispatched with the next outgoing
334 * process_capture_request. The settings for that request only
335 * will be temporarily rewritten to add the trigger tag/value.
336 * Subsequent requests will not be rewritten (for this tag).
337 */
338 status_t queueTrigger(RequestTrigger trigger[], size_t count);
339
340 /**
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800341 * Pause/unpause the capture thread. Doesn't block, so use
342 * waitUntilPaused to wait until the thread is paused.
343 */
344 void setPaused(bool paused);
345
346 /**
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700347 * Wait until thread processes the capture request with settings'
348 * android.request.id == requestId.
349 *
350 * Returns TIMED_OUT in case the thread does not process the request
351 * within the timeout.
352 */
353 status_t waitUntilRequestProcessed(int32_t requestId, nsecs_t timeout);
354
Igor Murashkin1e479c02013-09-06 16:55:14 -0700355 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700356 * Shut down the thread. Shutdown is asynchronous, so thread may
357 * still be running once this method returns.
358 */
359 virtual void requestExit();
360
361 /**
Igor Murashkin1e479c02013-09-06 16:55:14 -0700362 * Get the latest request that was sent to the HAL
363 * with process_capture_request.
364 */
365 CameraMetadata getLatestRequest() const;
366
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800367 protected:
368
369 virtual bool threadLoop();
370
371 private:
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700372 static int getId(const wp<Camera3Device> &device);
373
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700374 status_t queueTriggerLocked(RequestTrigger trigger);
375 // Mix-in queued triggers into this request
376 int32_t insertTriggers(const sp<CaptureRequest> &request);
377 // Purge the queued triggers from this request,
378 // restoring the old field values for those tags.
379 status_t removeTriggers(const sp<CaptureRequest> &request);
380
Eino-Ville Talvala2f876f92013-09-13 11:39:24 -0700381 // HAL workaround: Make sure a trigger ID always exists if
382 // a trigger does
383 status_t addDummyTriggerIds(const sp<CaptureRequest> &request);
384
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800385 static const nsecs_t kRequestTimeout = 50e6; // 50 ms
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800386
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800387 // Waits for a request, or returns NULL if times out.
388 sp<CaptureRequest> waitForNextRequest();
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800389
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800390 // Return buffers, etc, for a request that couldn't be fully
391 // constructed. The buffers will be returned in the ERROR state
392 // to mark them as not having valid data.
393 // All arguments will be modified.
394 void cleanUpFailedRequest(camera3_capture_request_t &request,
395 sp<CaptureRequest> &nextRequest,
396 Vector<camera3_stream_buffer_t> &outputBuffers);
397
398 // Pause handling
399 bool waitIfPaused();
Eino-Ville Talvala26fe6c72013-08-29 12:46:18 -0700400 void unpauseForNewRequests();
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800401
Eino-Ville Talvalab2058d12013-04-09 13:49:56 -0700402 // Relay error to parent device object setErrorState
403 void setErrorState(const char *fmt, ...);
404
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800405 wp<Camera3Device> mParent;
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700406 wp<camera3::StatusTracker> mStatusTracker;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800407 camera3_device_t *mHal3Device;
408
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700409 const int mId; // The camera ID
410 int mStatusId; // The RequestThread's component ID for
411 // status tracking
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700412
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800413 Mutex mRequestLock;
414 Condition mRequestSignal;
415 RequestList mRequestQueue;
416 RequestList mRepeatingRequests;
417
418 bool mReconfigured;
419
420 // Used by waitIfPaused, waitForNextRequest, and waitUntilPaused
421 Mutex mPauseLock;
422 bool mDoPause;
423 Condition mDoPauseSignal;
424 bool mPaused;
425 Condition mPausedSignal;
426
427 sp<CaptureRequest> mPrevRequest;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700428 int32_t mPrevTriggers;
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800429
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700430 uint32_t mFrameNumber;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700431
Igor Murashkin1e479c02013-09-06 16:55:14 -0700432 mutable Mutex mLatestRequestMutex;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700433 Condition mLatestRequestSignal;
434 // android.request.id for latest process_capture_request
435 int32_t mLatestRequestId;
Igor Murashkin1e479c02013-09-06 16:55:14 -0700436 CameraMetadata mLatestRequest;
Igor Murashkin4d2f2e82013-04-01 17:29:07 -0700437
438 typedef KeyedVector<uint32_t/*tag*/, RequestTrigger> TriggerMap;
439 Mutex mTriggerMutex;
440 TriggerMap mTriggerMap;
441 TriggerMap mTriggerRemovedMap;
442 TriggerMap mTriggerReplacedMap;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800443 };
Eino-Ville Talvalaf76e0272013-02-27 18:02:26 -0800444 sp<RequestThread> mRequestThread;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800445
446 /**
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700447 * In-flight queue for tracking completion of capture requests.
448 */
449
450 struct InFlightRequest {
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700451 // android.request.id for the request
452 int requestId;
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700453 // Set by notify() SHUTTER call.
454 nsecs_t captureTimestamp;
Zhijun He1d1f8462013-10-02 16:29:51 -0700455 int requestStatus;
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700456 // Set by process_capture_result call with valid metadata
457 bool haveResultMetadata;
458 // Decremented by calls to process_capture_result with valid output
459 // buffers
460 int numBuffersLeft;
461
Eino-Ville Talvalafd6ecdd2013-10-11 09:51:09 -0700462 // Fields used by the partial result quirk only
463 struct PartialResultQuirkInFlight {
464 // Set by process_capture_result once 3A has been sent to clients
465 bool haveSent3A;
466 // Result metadata collected so far, when partial results are in use
467 CameraMetadata collectedResult;
468
469 PartialResultQuirkInFlight():
470 haveSent3A(false) {
471 }
472 } partialResultQuirk;
473
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700474 // Default constructor needed by KeyedVector
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700475 InFlightRequest() :
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700476 requestId(0),
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700477 captureTimestamp(0),
Zhijun He1d1f8462013-10-02 16:29:51 -0700478 requestStatus(OK),
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700479 haveResultMetadata(false),
480 numBuffersLeft(0) {
481 }
482
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700483 InFlightRequest(int id, int numBuffers) :
484 requestId(id),
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700485 captureTimestamp(0),
Zhijun Hecc27e112013-10-03 16:12:43 -0700486 requestStatus(OK),
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700487 haveResultMetadata(false),
488 numBuffersLeft(numBuffers) {
489 }
490 };
491 // Map from frame number to the in-flight request state
492 typedef KeyedVector<uint32_t, InFlightRequest> InFlightMap;
493
494 Mutex mInFlightLock; // Protects mInFlightMap
495 InFlightMap mInFlightMap;
496
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700497 status_t registerInFlight(int32_t frameNumber, int32_t requestId,
498 int32_t numBuffers);
499
500 /**
Eino-Ville Talvalafd6ecdd2013-10-11 09:51:09 -0700501 * For the partial result quirk, check if all 3A state fields are available
502 * and if so, queue up 3A-only result to the client. Returns true if 3A
503 * is sent.
504 */
Eino-Ville Talvala184dfe42013-11-07 15:13:16 -0800505 bool processPartial3AQuirk(int32_t frameNumber, int32_t requestId,
506 const CameraMetadata& partial);
Eino-Ville Talvalafd6ecdd2013-10-11 09:51:09 -0700507
508 // Helpers for reading and writing 3A metadata into to/from partial results
509 template<typename T>
510 bool get3AResult(const CameraMetadata& result, int32_t tag,
511 T* value, int32_t frameNumber);
512
513 template<typename T>
514 bool insert3AResult(CameraMetadata &result, int32_t tag, const T* value,
515 int32_t frameNumber);
516 /**
Eino-Ville Talvalaf1e98d82013-09-06 09:32:43 -0700517 * Tracking for idle detection
518 */
519 sp<camera3::StatusTracker> mStatusTracker;
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700520
521 /**
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700522 * Output result queue and current HAL device 3A state
523 */
524
525 // Lock for output side of device
526 Mutex mOutputLock;
527
528 /**** Scope for mOutputLock ****/
529
Eino-Ville Talvala42368d92013-04-09 14:13:50 -0700530 uint32_t mNextResultFrameNumber;
531 uint32_t mNextShutterFrameNumber;
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700532 List<CameraMetadata> mResultQueue;
533 Condition mResultSignal;
534 NotificationListener *mListener;
535
Eino-Ville Talvala7d346fa2013-03-11 14:13:50 -0700536 /**** End scope for mOutputLock ****/
537
538 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800539 * Callback functions from HAL device
540 */
541 void processCaptureResult(const camera3_capture_result *result);
542
543 void notify(const camera3_notify_msg *msg);
544
545 /**
546 * Static callback forwarding methods from HAL to instance
547 */
548 static callbacks_process_capture_result_t sProcessCaptureResult;
549
550 static callbacks_notify_t sNotify;
551
552}; // class Camera3Device
553
554}; // namespace android
555
556#endif