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 | |
Eino-Ville Talvala | fe580e5 | 2012-09-19 17:09:15 -0700 | [diff] [blame] | 20 | #include <binder/MemoryBase.h> |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 21 | #include <utils/Thread.h> |
| 22 | #include <utils/String16.h> |
| 23 | #include <utils/Vector.h> |
| 24 | #include <utils/Mutex.h> |
| 25 | #include <utils/Condition.h> |
| 26 | #include "CameraMetadata.h" |
| 27 | #include "Parameters.h" |
| 28 | #include "FrameProcessor.h" |
| 29 | |
| 30 | namespace android { |
| 31 | |
| 32 | class Camera2Client; |
| 33 | |
| 34 | namespace camera2 { |
| 35 | |
| 36 | class ZslProcessor; |
James Painter | e538206 | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 37 | class BurstCapture; |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Manages the still image capture process for |
| 41 | * zero-shutter-lag, regular, and video snapshots. |
| 42 | */ |
| 43 | class CaptureSequencer: |
| 44 | virtual public Thread, |
| 45 | virtual public FrameProcessor::FilteredListener { |
| 46 | public: |
| 47 | CaptureSequencer(wp<Camera2Client> client); |
| 48 | ~CaptureSequencer(); |
| 49 | |
| 50 | // Get reference to the ZslProcessor, which holds the ZSL buffers and frames |
| 51 | void setZslProcessor(wp<ZslProcessor> processor); |
| 52 | |
| 53 | // Begin still image capture |
| 54 | status_t startCapture(); |
| 55 | |
Eino-Ville Talvala | d5087f9 | 2012-10-05 12:03:10 -0700 | [diff] [blame^] | 56 | // Wait until current image capture completes; returns immediately if no |
| 57 | // capture is active. Returns TIMED_OUT if capture does not complete during |
| 58 | // the specified duration. |
| 59 | status_t waitUntilIdle(nsecs_t timeout); |
| 60 | |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 61 | // Notifications about AE state changes |
| 62 | void notifyAutoExposure(uint8_t newState, int triggerId); |
| 63 | |
| 64 | // Notifications from the frame processor |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 65 | virtual void onFrameAvailable(int32_t frameId, const CameraMetadata &frame); |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 66 | |
Eino-Ville Talvala | fe580e5 | 2012-09-19 17:09:15 -0700 | [diff] [blame] | 67 | // Notifications from the JPEG processor |
| 68 | void onCaptureAvailable(nsecs_t timestamp, sp<MemoryBase> captureBuffer); |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 69 | |
| 70 | void dump(int fd, const Vector<String16>& args); |
| 71 | |
| 72 | private: |
| 73 | /** |
| 74 | * Accessed by other threads |
| 75 | */ |
| 76 | Mutex mInputMutex; |
| 77 | |
| 78 | bool mStartCapture; |
| 79 | bool mBusy; |
| 80 | Condition mStartCaptureSignal; |
| 81 | |
| 82 | bool mNewAEState; |
| 83 | uint8_t mAEState; |
| 84 | int mAETriggerId; |
| 85 | Condition mNewNotifySignal; |
| 86 | |
| 87 | bool mNewFrameReceived; |
| 88 | int32_t mNewFrameId; |
| 89 | CameraMetadata mNewFrame; |
| 90 | Condition mNewFrameSignal; |
| 91 | |
| 92 | bool mNewCaptureReceived; |
| 93 | nsecs_t mCaptureTimestamp; |
Eino-Ville Talvala | fe580e5 | 2012-09-19 17:09:15 -0700 | [diff] [blame] | 94 | sp<MemoryBase> mCaptureBuffer; |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 95 | Condition mNewCaptureSignal; |
| 96 | |
| 97 | /** |
| 98 | * Internal to CaptureSequencer |
| 99 | */ |
| 100 | static const nsecs_t kWaitDuration = 100000000; // 100 ms |
| 101 | static const int kMaxTimeoutsForPrecaptureStart = 2; // 200 ms |
Eino-Ville Talvala | c553118 | 2012-09-19 16:12:18 -0700 | [diff] [blame] | 102 | static const int kMaxTimeoutsForPrecaptureEnd = 20; // 2 sec |
Eino-Ville Talvala | 1f266ef | 2012-09-18 16:01:11 -0700 | [diff] [blame] | 103 | static const int kMaxTimeoutsForCaptureEnd = 40; // 4 sec |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 104 | |
| 105 | wp<Camera2Client> mClient; |
| 106 | wp<ZslProcessor> mZslProcessor; |
James Painter | e538206 | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 107 | sp<BurstCapture> mBurstCapture; |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 108 | |
| 109 | enum CaptureState { |
| 110 | IDLE, |
| 111 | START, |
| 112 | ZSL_START, |
| 113 | ZSL_WAITING, |
| 114 | ZSL_REPROCESSING, |
| 115 | STANDARD_START, |
| 116 | STANDARD_PRECAPTURE_WAIT, |
| 117 | STANDARD_CAPTURE, |
| 118 | STANDARD_CAPTURE_WAIT, |
James Painter | e538206 | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 119 | BURST_CAPTURE_START, |
| 120 | BURST_CAPTURE_WAIT, |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 121 | DONE, |
| 122 | ERROR, |
| 123 | NUM_CAPTURE_STATES |
| 124 | } mCaptureState; |
| 125 | static const char* kStateNames[]; |
Eino-Ville Talvala | d5087f9 | 2012-10-05 12:03:10 -0700 | [diff] [blame^] | 126 | Mutex mStateMutex; // Guards mCaptureState |
| 127 | Condition mStateChanged; |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 128 | |
| 129 | typedef CaptureState (CaptureSequencer::*StateManager)(sp<Camera2Client> &client); |
| 130 | static const StateManager kStateManagers[]; |
| 131 | |
| 132 | CameraMetadata mCaptureRequest; |
| 133 | |
| 134 | int mTriggerId; |
| 135 | int mTimeoutCount; |
| 136 | bool mAeInPrecapture; |
| 137 | |
| 138 | int32_t mCaptureId; |
| 139 | |
| 140 | // Main internal methods |
| 141 | |
| 142 | virtual bool threadLoop(); |
| 143 | |
| 144 | CaptureState manageIdle(sp<Camera2Client> &client); |
| 145 | CaptureState manageStart(sp<Camera2Client> &client); |
| 146 | |
| 147 | CaptureState manageZslStart(sp<Camera2Client> &client); |
| 148 | CaptureState manageZslWaiting(sp<Camera2Client> &client); |
| 149 | CaptureState manageZslReprocessing(sp<Camera2Client> &client); |
| 150 | |
| 151 | CaptureState manageStandardStart(sp<Camera2Client> &client); |
| 152 | CaptureState manageStandardPrecaptureWait(sp<Camera2Client> &client); |
| 153 | CaptureState manageStandardCapture(sp<Camera2Client> &client); |
| 154 | CaptureState manageStandardCaptureWait(sp<Camera2Client> &client); |
| 155 | |
James Painter | e538206 | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 156 | CaptureState manageBurstCaptureStart(sp<Camera2Client> &client); |
| 157 | CaptureState manageBurstCaptureWait(sp<Camera2Client> &client); |
| 158 | |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 159 | CaptureState manageDone(sp<Camera2Client> &client); |
| 160 | |
| 161 | // Utility methods |
| 162 | |
| 163 | status_t updateCaptureRequest(const Parameters ¶ms, |
| 164 | sp<Camera2Client> &client); |
Igor Murashkin | 1b65ae9 | 2012-09-20 15:18:50 -0700 | [diff] [blame] | 165 | |
| 166 | // Emit Shutter/Raw callback to java, and maybe play a shutter sound |
| 167 | static void shutterNotifyLocked(const Parameters ¶ms, |
| 168 | sp<Camera2Client> client); |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | }; // namespace camera2 |
| 172 | }; // namespace android |
| 173 | |
| 174 | #endif |