Camera2Client.h revision 7b82efe7a376c882f8f938e1c41b8311a8cdda4a
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_CAMERA2CLIENT_H 18#define ANDROID_SERVERS_CAMERA_CAMERA2CLIENT_H 19 20#include "CameraService.h" 21#include "common/CameraDeviceBase.h" 22#include "common/Camera2ClientBase.h" 23#include "api1/client2/Parameters.h" 24#include "api1/client2/FrameProcessor.h" 25//#include "api1/client2/StreamingProcessor.h" 26//#include "api1/client2/JpegProcessor.h" 27//#include "api1/client2/ZslProcessorInterface.h" 28//#include "api1/client2/CaptureSequencer.h" 29//#include "api1/client2/CallbackProcessor.h" 30 31namespace android { 32 33namespace camera2 { 34 35class StreamingProcessor; 36class JpegProcessor; 37class ZslProcessorInterface; 38class CaptureSequencer; 39class CallbackProcessor; 40 41} 42 43class IMemory; 44/** 45 * Interface between android.hardware.Camera API and Camera HAL device for versions 46 * CAMERA_DEVICE_API_VERSION_2_0 and 3_0. 47 */ 48class Camera2Client : 49 public Camera2ClientBase<CameraService::Client> 50{ 51public: 52 /** 53 * ICamera interface (see ICamera for details) 54 */ 55 56 virtual void disconnect(); 57 virtual status_t connect(const sp<ICameraClient>& client); 58 virtual status_t lock(); 59 virtual status_t unlock(); 60 virtual status_t setPreviewDisplay(const sp<Surface>& surface); 61 virtual status_t setPreviewTexture( 62 const sp<IGraphicBufferProducer>& bufferProducer); 63 virtual void setPreviewCallbackFlag(int flag); 64 virtual status_t setPreviewCallbackTarget( 65 const sp<IGraphicBufferProducer>& callbackProducer); 66 67 virtual status_t startPreview(); 68 virtual void stopPreview(); 69 virtual bool previewEnabled(); 70 virtual status_t storeMetaDataInBuffers(bool enabled); 71 virtual status_t startRecording(); 72 virtual void stopRecording(); 73 virtual bool recordingEnabled(); 74 virtual void releaseRecordingFrame(const sp<IMemory>& mem); 75 virtual status_t autoFocus(); 76 virtual status_t cancelAutoFocus(); 77 virtual status_t takePicture(int msgType); 78 virtual status_t setParameters(const String8& params); 79 virtual String8 getParameters() const; 80 virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2); 81 82 /** 83 * Interface used by CameraService 84 */ 85 86 Camera2Client(const sp<CameraService>& cameraService, 87 const sp<ICameraClient>& cameraClient, 88 const String16& clientPackageName, 89 int cameraId, 90 int cameraFacing, 91 int clientPid, 92 uid_t clientUid, 93 int servicePid, 94 int deviceVersion); 95 96 virtual ~Camera2Client(); 97 98 status_t initialize(camera_module_t *module); 99 100 virtual status_t dump(int fd, const Vector<String16>& args); 101 102 /** 103 * Interface used by CameraDeviceBase 104 */ 105 106 virtual void notifyAutoFocus(uint8_t newState, int triggerId); 107 virtual void notifyAutoExposure(uint8_t newState, int triggerId); 108 109 /** 110 * Interface used by independent components of Camera2Client. 111 */ 112 113 camera2::SharedParameters& getParameters(); 114 115 int getPreviewStreamId() const; 116 int getCaptureStreamId() const; 117 int getCallbackStreamId() const; 118 int getRecordingStreamId() const; 119 int getZslStreamId() const; 120 121 status_t registerFrameListener(int32_t minId, int32_t maxId, 122 wp<camera2::FrameProcessor::FilteredListener> listener); 123 status_t removeFrameListener(int32_t minId, int32_t maxId, 124 wp<camera2::FrameProcessor::FilteredListener> listener); 125 126 status_t stopStream(); 127 128 static size_t calculateBufferSize(int width, int height, 129 int format, int stride); 130 131 static const int32_t kPreviewRequestIdStart = 10000000; 132 static const int32_t kPreviewRequestIdEnd = 20000000; 133 134 static const int32_t kRecordingRequestIdStart = 20000000; 135 static const int32_t kRecordingRequestIdEnd = 30000000; 136 137 static const int32_t kCaptureRequestIdStart = 30000000; 138 static const int32_t kCaptureRequestIdEnd = 40000000; 139 140private: 141 /** ICamera interface-related private members */ 142 typedef camera2::Parameters Parameters; 143 144 status_t setPreviewWindowL(const sp<IBinder>& binder, 145 sp<ANativeWindow> window); 146 status_t startPreviewL(Parameters ¶ms, bool restart); 147 void stopPreviewL(); 148 status_t startRecordingL(Parameters ¶ms, bool restart); 149 bool recordingEnabledL(); 150 151 // Individual commands for sendCommand() 152 status_t commandStartSmoothZoomL(); 153 status_t commandStopSmoothZoomL(); 154 status_t commandSetDisplayOrientationL(int degrees); 155 status_t commandEnableShutterSoundL(bool enable); 156 status_t commandPlayRecordingSoundL(); 157 status_t commandStartFaceDetectionL(int type); 158 status_t commandStopFaceDetectionL(Parameters ¶ms); 159 status_t commandEnableFocusMoveMsgL(bool enable); 160 status_t commandPingL(); 161 status_t commandSetVideoBufferCountL(size_t count); 162 163 // Current camera device configuration 164 camera2::SharedParameters mParameters; 165 166 /** Camera device-related private members */ 167 168 void setPreviewCallbackFlagL(Parameters ¶ms, int flag); 169 status_t updateRequests(Parameters ¶ms); 170 int mDeviceVersion; 171 172 // Used with stream IDs 173 static const int NO_STREAM = -1; 174 175 template <typename ProcessorT> 176 status_t updateProcessorStream(sp<ProcessorT> processor, Parameters params); 177 template <typename ProcessorT, 178 status_t (ProcessorT::*updateStreamF)(const Parameters &)> 179 status_t updateProcessorStream(sp<ProcessorT> processor, Parameters params); 180 181 sp<camera2::FrameProcessor> mFrameProcessor; 182 183 /* Preview/Recording related members */ 184 185 sp<IBinder> mPreviewSurface; 186 sp<camera2::StreamingProcessor> mStreamingProcessor; 187 188 /** Preview callback related members */ 189 190 sp<camera2::CallbackProcessor> mCallbackProcessor; 191 192 /* Still image capture related members */ 193 194 sp<camera2::CaptureSequencer> mCaptureSequencer; 195 sp<camera2::JpegProcessor> mJpegProcessor; 196 sp<camera2::ZslProcessorInterface> mZslProcessor; 197 sp<Thread> mZslProcessorThread; 198 199 /** Notification-related members */ 200 201 bool mAfInMotion; 202 203 /** Utility members */ 204 205 // Wait until the camera device has received the latest control settings 206 status_t syncWithDevice(); 207}; 208 209}; // namespace android 210 211#endif 212