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 virtual ~Camera(); 78 79 status_t reconnect(); 80 status_t lock(); 81 status_t unlock(); 82 83 // pass the buffered IGraphicBufferProducer to the camera service 84 status_t setPreviewTarget(const sp<IGraphicBufferProducer>& bufferProducer); 85 86 // start preview mode, must call setPreviewTarget first 87 status_t startPreview(); 88 89 // stop preview mode 90 void stopPreview(); 91 92 // get preview state 93 bool previewEnabled(); 94 95 // start recording mode, must call setPreviewTarget first 96 status_t startRecording(); 97 98 // stop recording mode 99 void stopRecording(); 100 101 // get recording state 102 bool recordingEnabled(); 103 104 // release a recording frame 105 void releaseRecordingFrame(const sp<IMemory>& mem); 106 107 // autoFocus - status returned from callback 108 status_t autoFocus(); 109 110 // cancel auto focus 111 status_t cancelAutoFocus(); 112 113 // take a picture - picture returned from callback 114 status_t takePicture(int msgType); 115 116 // set preview/capture parameters - key/value pairs 117 status_t setParameters(const String8& params); 118 119 // get preview/capture parameters - key/value pairs 120 String8 getParameters() const; 121 122 // send command to camera driver 123 status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2); 124 125 // tell camera hal to store meta data or real YUV in video buffers. 126 status_t storeMetaDataInBuffers(bool enabled); 127 128 void setListener(const sp<CameraListener>& listener); 129 void setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener); 130 131 // Configure preview callbacks to app. Only one of the older 132 // callbacks or the callback surface can be active at the same time; 133 // enabling one will disable the other if active. Flags can be 134 // disabled by calling it with CAMERA_FRAME_CALLBACK_FLAG_NOOP, and 135 // Target by calling it with a NULL interface. 136 void setPreviewCallbackFlags(int preview_callback_flag); 137 status_t setPreviewCallbackTarget( 138 const sp<IGraphicBufferProducer>& callbackProducer); 139 140 sp<ICameraRecordingProxy> getRecordingProxy(); 141 142 // ICameraClient interface 143 virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2); 144 virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr, 145 camera_frame_metadata_t *metadata); 146 virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr); 147 148 class RecordingProxy : public BnCameraRecordingProxy 149 { 150 public: 151 RecordingProxy(const sp<Camera>& camera); 152 153 // ICameraRecordingProxy interface 154 virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener); 155 virtual void stopRecording(); 156 virtual void releaseRecordingFrame(const sp<IMemory>& mem); 157 158 private: 159 sp<Camera> mCamera; 160 }; 161 162 protected: 163 Camera(int cameraId); 164 Camera(const Camera&); 165 Camera& operator=(const Camera); 166 167 sp<ICameraRecordingProxyListener> mRecordingProxyListener; 168 169 friend class CameraBase; 170 }; 171 172 }; // namespace android 173 174 #endif 175