CaptureSequencer.h revision 4865c526e681366481b0ab242ffa1ead57bb02cc
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 <binder/MemoryBase.h> 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 30namespace android { 31 32class Camera2Client; 33 34namespace camera2 { 35 36class ZslProcessor; 37class BurstCapture; 38 39/** 40 * Manages the still image capture process for 41 * zero-shutter-lag, regular, and video snapshots. 42 */ 43class 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 56 // Notifications about AE state changes 57 void notifyAutoExposure(uint8_t newState, int triggerId); 58 59 // Notifications from the frame processor 60 virtual void onFrameAvailable(int32_t frameId, const CameraMetadata &frame); 61 62 // Notifications from the JPEG processor 63 void onCaptureAvailable(nsecs_t timestamp, sp<MemoryBase> captureBuffer); 64 65 void dump(int fd, const Vector<String16>& args); 66 67 private: 68 /** 69 * Accessed by other threads 70 */ 71 Mutex mInputMutex; 72 73 bool mStartCapture; 74 bool mBusy; 75 Condition mStartCaptureSignal; 76 77 bool mNewAEState; 78 uint8_t mAEState; 79 int mAETriggerId; 80 Condition mNewNotifySignal; 81 82 bool mNewFrameReceived; 83 int32_t mNewFrameId; 84 CameraMetadata mNewFrame; 85 Condition mNewFrameSignal; 86 87 bool mNewCaptureReceived; 88 nsecs_t mCaptureTimestamp; 89 sp<MemoryBase> mCaptureBuffer; 90 Condition mNewCaptureSignal; 91 92 /** 93 * Internal to CaptureSequencer 94 */ 95 static const nsecs_t kWaitDuration = 100000000; // 100 ms 96 static const int kMaxTimeoutsForPrecaptureStart = 2; // 200 ms 97 static const int kMaxTimeoutsForPrecaptureEnd = 20; // 2 sec 98 static const int kMaxTimeoutsForCaptureEnd = 40; // 4 sec 99 100 wp<Camera2Client> mClient; 101 wp<ZslProcessor> mZslProcessor; 102 sp<BurstCapture> mBurstCapture; 103 104 enum CaptureState { 105 IDLE, 106 START, 107 ZSL_START, 108 ZSL_WAITING, 109 ZSL_REPROCESSING, 110 STANDARD_START, 111 STANDARD_PRECAPTURE_WAIT, 112 STANDARD_CAPTURE, 113 STANDARD_CAPTURE_WAIT, 114 BURST_CAPTURE_START, 115 BURST_CAPTURE_WAIT, 116 DONE, 117 ERROR, 118 NUM_CAPTURE_STATES 119 } mCaptureState; 120 static const char* kStateNames[]; 121 122 typedef CaptureState (CaptureSequencer::*StateManager)(sp<Camera2Client> &client); 123 static const StateManager kStateManagers[]; 124 125 CameraMetadata mCaptureRequest; 126 127 int mTriggerId; 128 int mTimeoutCount; 129 bool mAeInPrecapture; 130 131 int32_t mCaptureId; 132 133 // Main internal methods 134 135 virtual bool threadLoop(); 136 137 CaptureState manageIdle(sp<Camera2Client> &client); 138 CaptureState manageStart(sp<Camera2Client> &client); 139 140 CaptureState manageZslStart(sp<Camera2Client> &client); 141 CaptureState manageZslWaiting(sp<Camera2Client> &client); 142 CaptureState manageZslReprocessing(sp<Camera2Client> &client); 143 144 CaptureState manageStandardStart(sp<Camera2Client> &client); 145 CaptureState manageStandardPrecaptureWait(sp<Camera2Client> &client); 146 CaptureState manageStandardCapture(sp<Camera2Client> &client); 147 CaptureState manageStandardCaptureWait(sp<Camera2Client> &client); 148 149 CaptureState manageBurstCaptureStart(sp<Camera2Client> &client); 150 CaptureState manageBurstCaptureWait(sp<Camera2Client> &client); 151 152 CaptureState manageDone(sp<Camera2Client> &client); 153 154 // Utility methods 155 156 status_t updateCaptureRequest(const Parameters ¶ms, 157 sp<Camera2Client> &client); 158 159 // Emit Shutter/Raw callback to java, and maybe play a shutter sound 160 static void shutterNotifyLocked(const Parameters ¶ms, 161 sp<Camera2Client> client); 162}; 163 164}; // namespace camera2 165}; // namespace android 166 167#endif 168