blob: 474bdace728b9c02995538aaf360fd86e2dfb1ce [file] [log] [blame]
Eino-Ville Talvalada6665c2012-08-29 17:37:16 -07001/*
2 * Copyright (C) 2012 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
17#ifndef ANDROID_SERVERS_CAMERA_CAMERA2_CAPTURESEQUENCER_H
18#define ANDROID_SERVERS_CAMERA_CAMERA2_CAPTURESEQUENCER_H
19
20#include <utils/Thread.h>
21#include <utils/String16.h>
22#include <utils/Vector.h>
23#include <utils/Mutex.h>
24#include <utils/Condition.h>
25#include "CameraMetadata.h"
26#include "Parameters.h"
27#include "FrameProcessor.h"
28
29namespace android {
30
31class Camera2Client;
32
33namespace camera2 {
34
35class ZslProcessor;
James Paintere5382062012-09-05 18:02:32 -070036class BurstCapture;
Eino-Ville Talvalada6665c2012-08-29 17:37:16 -070037
38/**
39 * Manages the still image capture process for
40 * zero-shutter-lag, regular, and video snapshots.
41 */
42class CaptureSequencer:
43 virtual public Thread,
44 virtual public FrameProcessor::FilteredListener {
45 public:
46 CaptureSequencer(wp<Camera2Client> client);
47 ~CaptureSequencer();
48
49 // Get reference to the ZslProcessor, which holds the ZSL buffers and frames
50 void setZslProcessor(wp<ZslProcessor> processor);
51
52 // Begin still image capture
53 status_t startCapture();
54
55 // Notifications about AE state changes
56 void notifyAutoExposure(uint8_t newState, int triggerId);
57
58 // Notifications from the frame processor
59 virtual void onFrameAvailable(int32_t frameId, CameraMetadata &frame);
60
61 // Notifications from the capture processor
62 void onCaptureAvailable(nsecs_t timestamp);
63
64 void dump(int fd, const Vector<String16>& args);
65
66 private:
67 /**
68 * Accessed by other threads
69 */
70 Mutex mInputMutex;
71
72 bool mStartCapture;
73 bool mBusy;
74 Condition mStartCaptureSignal;
75
76 bool mNewAEState;
77 uint8_t mAEState;
78 int mAETriggerId;
79 Condition mNewNotifySignal;
80
81 bool mNewFrameReceived;
82 int32_t mNewFrameId;
83 CameraMetadata mNewFrame;
84 Condition mNewFrameSignal;
85
86 bool mNewCaptureReceived;
87 nsecs_t mCaptureTimestamp;
88 Condition mNewCaptureSignal;
89
90 /**
91 * Internal to CaptureSequencer
92 */
93 static const nsecs_t kWaitDuration = 100000000; // 100 ms
94 static const int kMaxTimeoutsForPrecaptureStart = 2; // 200 ms
Eino-Ville Talvalac5531182012-09-19 16:12:18 -070095 static const int kMaxTimeoutsForPrecaptureEnd = 20; // 2 sec
Eino-Ville Talvala1f266ef2012-09-18 16:01:11 -070096 static const int kMaxTimeoutsForCaptureEnd = 40; // 4 sec
Eino-Ville Talvalada6665c2012-08-29 17:37:16 -070097
98 wp<Camera2Client> mClient;
99 wp<ZslProcessor> mZslProcessor;
James Paintere5382062012-09-05 18:02:32 -0700100 sp<BurstCapture> mBurstCapture;
Eino-Ville Talvalada6665c2012-08-29 17:37:16 -0700101
102 enum CaptureState {
103 IDLE,
104 START,
105 ZSL_START,
106 ZSL_WAITING,
107 ZSL_REPROCESSING,
108 STANDARD_START,
109 STANDARD_PRECAPTURE_WAIT,
110 STANDARD_CAPTURE,
111 STANDARD_CAPTURE_WAIT,
James Paintere5382062012-09-05 18:02:32 -0700112 BURST_CAPTURE_START,
113 BURST_CAPTURE_WAIT,
Eino-Ville Talvalada6665c2012-08-29 17:37:16 -0700114 DONE,
115 ERROR,
116 NUM_CAPTURE_STATES
117 } mCaptureState;
118 static const char* kStateNames[];
119
120 typedef CaptureState (CaptureSequencer::*StateManager)(sp<Camera2Client> &client);
121 static const StateManager kStateManagers[];
122
123 CameraMetadata mCaptureRequest;
124
125 int mTriggerId;
126 int mTimeoutCount;
127 bool mAeInPrecapture;
128
129 int32_t mCaptureId;
130
131 // Main internal methods
132
133 virtual bool threadLoop();
134
135 CaptureState manageIdle(sp<Camera2Client> &client);
136 CaptureState manageStart(sp<Camera2Client> &client);
137
138 CaptureState manageZslStart(sp<Camera2Client> &client);
139 CaptureState manageZslWaiting(sp<Camera2Client> &client);
140 CaptureState manageZslReprocessing(sp<Camera2Client> &client);
141
142 CaptureState manageStandardStart(sp<Camera2Client> &client);
143 CaptureState manageStandardPrecaptureWait(sp<Camera2Client> &client);
144 CaptureState manageStandardCapture(sp<Camera2Client> &client);
145 CaptureState manageStandardCaptureWait(sp<Camera2Client> &client);
146
James Paintere5382062012-09-05 18:02:32 -0700147 CaptureState manageBurstCaptureStart(sp<Camera2Client> &client);
148 CaptureState manageBurstCaptureWait(sp<Camera2Client> &client);
149
Eino-Ville Talvalada6665c2012-08-29 17:37:16 -0700150 CaptureState manageDone(sp<Camera2Client> &client);
151
152 // Utility methods
153
154 status_t updateCaptureRequest(const Parameters &params,
155 sp<Camera2Client> &client);
156};
157
158}; // namespace camera2
159}; // namespace android
160
161#endif