1 /* 2 * Copyright (C) 2008 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_HARDWARE_CAMERA_H 18 #define ANDROID_HARDWARE_CAMERA_H 19 20 #include <utils/Timers.h> 21 #include <gui/IGraphicBufferProducer.h> 22 #include <system/camera.h> 23 #include <camera/ICameraClient.h> 24 #include <camera/ICameraRecordingProxy.h> 25 #include <camera/ICameraRecordingProxyListener.h> 26 #include <camera/ICameraService.h> 27 #include <camera/ICamera.h> 28 #include <camera/CameraBase.h> 29 30 namespace android { 31 32 class Surface; 33 class String8; 34 class String16; 35 36 // ref-counted object for callbacks 37 class CameraListener: virtual public RefBase 38 { 39 public: 40 virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0; 41 virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr, 42 camera_frame_metadata_t *metadata) = 0; 43 virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0; 44 }; 45 46 class Camera; 47 48 template <> 49 struct CameraTraits<Camera> 50 { 51 typedef CameraListener TCamListener; 52 typedef ICamera TCamUser; 53 typedef ICameraClient TCamCallbacks; 54 typedef status_t (ICameraService::*TCamConnectService)(const sp<ICameraClient>&, 55 int, const String16&, int, 56 /*out*/ 57 sp<ICamera>&); 58 static TCamConnectService fnConnectService; 59 }; 60 61 62 class Camera : 63 public CameraBase<Camera>, 64 public BnCameraClient 65 { 66 public: 67 enum { 68 USE_CALLING_UID = ICameraService::USE_CALLING_UID 69 }; 70 71 // construct a camera client from an existing remote 72 static sp<Camera> create(const sp<ICamera>& camera); 73 static sp<Camera> connect(int cameraId, 74 const String16& clientPackageName, 75 int clientUid); 76 77 static status_t connectLegacy(int cameraId, int halVersion, 78 const String16& clientPackageName, 79 int clientUid, sp<Camera>& camera); 80 81 virtual ~Camera(); 82 83 status_t reconnect(); 84 status_t lock(); 85 status_t unlock(); 86 87 // pass the buffered IGraphicBufferProducer to the camera service 88 status_t setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer); 89 90 // start preview mode, must call setPreviewTarget first 91 status_t startPreview(); 92 93 // stop preview mode 94 void stopPreview(); 95 96 // get preview state 97 bool previewEnabled(); 98 99 // start recording mode, must call setPreviewTarget first 100 status_t startRecording(); 101 102 // stop recording mode 103 void stopRecording(); 104 105 // get recording state 106 bool recordingEnabled(); 107 108 // release a recording frame 109 void releaseRecordingFrame(const sp<IMemory>& mem); 110 111 // autoFocus - status returned from callback 112 status_t autoFocus(); 113 114 // cancel auto focus 115 status_t cancelAutoFocus(); 116 117 // take a picture - picture returned from callback 118 status_t takePicture(int msgType); 119 120 // set preview/capture parameters - key/value pairs 121 status_t setParameters(const String8& params); 122 123 // get preview/capture parameters - key/value pairs 124 String8 getParameters() const; 125 126 // send command to camera driver 127 status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2); 128 129 // tell camera hal to store meta data or real YUV in video buffers. 130 status_t storeMetaDataInBuffers(bool enabled); 131 132 void setListener(const sp<CameraListener>& listener); 133 void setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener); 134 135 // Configure preview callbacks to app. Only one of the older 136 // callbacks or the callback surface can be active at the same time; 137 // enabling one will disable the other if active. Flags can be 138 // disabled by calling it with CAMERA_FRAME_CALLBACK_FLAG_NOOP, and 139 // Target by calling it with a NULL interface. 140 void setPreviewCallbackFlags(int preview_callback_flag); 141 status_t setPreviewCallbackTarget( 142 const sp<IGraphicBufferProducer>& callbackProducer); 143 144 sp<ICameraRecordingProxy> getRecordingProxy(); 145 146 // ICameraClient interface 147 virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2); 148 virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr, 149 camera_frame_metadata_t *metadata); 150 virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr); 151 152 class RecordingProxy : public BnCameraRecordingProxy 153 { 154 public: 155 RecordingProxy(const sp<Camera>& camera); 156 157 // ICameraRecordingProxy interface 158 virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener); 159 virtual void stopRecording(); 160 virtual void releaseRecordingFrame(const sp<IMemory>& mem); 161 162 private: 163 sp<Camera> mCamera; 164 }; 165 166 protected: 167 Camera(int cameraId); 168 Camera(const Camera&); 169 Camera& operator=(const Camera); 170 171 sp<ICameraRecordingProxyListener> mRecordingProxyListener; 172 173 friend class CameraBase; 174 }; 175 176 }; // namespace android 177 178 #endif 179