Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 29 | namespace android { |
| 30 | |
| 31 | class Camera2Client; |
| 32 | |
| 33 | namespace camera2 { |
| 34 | |
| 35 | class ZslProcessor; |
James Painter | e538206 | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 36 | class BurstCapture; |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Manages the still image capture process for |
| 40 | * zero-shutter-lag, regular, and video snapshots. |
| 41 | */ |
| 42 | class 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 Talvala | c553118 | 2012-09-19 16:12:18 -0700 | [diff] [blame^] | 95 | static const int kMaxTimeoutsForPrecaptureEnd = 20; // 2 sec |
Eino-Ville Talvala | 1f266ef | 2012-09-18 16:01:11 -0700 | [diff] [blame] | 96 | static const int kMaxTimeoutsForCaptureEnd = 40; // 4 sec |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 97 | |
| 98 | wp<Camera2Client> mClient; |
| 99 | wp<ZslProcessor> mZslProcessor; |
James Painter | e538206 | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 100 | sp<BurstCapture> mBurstCapture; |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 101 | |
| 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 Painter | e538206 | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 112 | BURST_CAPTURE_START, |
| 113 | BURST_CAPTURE_WAIT, |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 114 | 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 Painter | e538206 | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 147 | CaptureState manageBurstCaptureStart(sp<Camera2Client> &client); |
| 148 | CaptureState manageBurstCaptureWait(sp<Camera2Client> &client); |
| 149 | |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 150 | CaptureState manageDone(sp<Camera2Client> &client); |
| 151 | |
| 152 | // Utility methods |
| 153 | |
| 154 | status_t updateCaptureRequest(const Parameters ¶ms, |
| 155 | sp<Camera2Client> &client); |
| 156 | }; |
| 157 | |
| 158 | }; // namespace camera2 |
| 159 | }; // namespace android |
| 160 | |
| 161 | #endif |