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 }; 55 56 class Camera : 57 public CameraBase<Camera>, 58 public BnCameraClient 59 { 60 public: 61 enum { 62 USE_CALLING_UID = ICameraService::USE_CALLING_UID 63 }; 64 65 // construct a camera client from an existing remote 66 static sp<Camera> create(const sp<ICamera>& camera); 67 static sp<Camera> connect(int cameraId, 68 const String16& clientPackageName, 69 int clientUid); 70 71 virtual ~Camera(); 72 73 status_t reconnect(); 74 status_t lock(); 75 status_t unlock(); 76 77 // pass the buffered IGraphicBufferProducer to the camera service 78 status_t setPreviewTexture(const sp<IGraphicBufferProducer>& bufferProducer); 79 80 // start preview mode, must call setPreviewDisplay first 81 status_t startPreview(); 82 83 // stop preview mode 84 void stopPreview(); 85 86 // get preview state 87 bool previewEnabled(); 88 89 // start recording mode, must call setPreviewDisplay first 90 status_t startRecording(); 91 92 // stop recording mode 93 void stopRecording(); 94 95 // get recording state 96 bool recordingEnabled(); 97 98 // release a recording frame 99 void releaseRecordingFrame(const sp<IMemory>& mem); 100 101 // autoFocus - status returned from callback 102 status_t autoFocus(); 103 104 // cancel auto focus 105 status_t cancelAutoFocus(); 106 107 // take a picture - picture returned from callback 108 status_t takePicture(int msgType); 109 110 // set preview/capture parameters - key/value pairs 111 status_t setParameters(const String8& params); 112 113 // get preview/capture parameters - key/value pairs 114 String8 getParameters() const; 115 116 // send command to camera driver 117 status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2); 118 119 // tell camera hal to store meta data or real YUV in video buffers. 120 status_t storeMetaDataInBuffers(bool enabled); 121 122 void setListener(const sp<CameraListener>& listener); 123 void setRecordingProxyListener(const sp<ICameraRecordingProxyListener>& listener); 124 void setPreviewCallbackFlags(int preview_callback_flag); 125 126 sp<ICameraRecordingProxy> getRecordingProxy(); 127 128 // ICameraClient interface 129 virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2); 130 virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr, 131 camera_frame_metadata_t *metadata); 132 virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr); 133 134 class RecordingProxy : public BnCameraRecordingProxy 135 { 136 public: 137 RecordingProxy(const sp<Camera>& camera); 138 139 // ICameraRecordingProxy interface 140 virtual status_t startRecording(const sp<ICameraRecordingProxyListener>& listener); 141 virtual void stopRecording(); 142 virtual void releaseRecordingFrame(const sp<IMemory>& mem); 143 144 private: 145 sp<Camera> mCamera; 146 }; 147 148 protected: 149 Camera(int cameraId); 150 Camera(const Camera&); 151 Camera& operator=(const Camera); 152 153 sp<ICameraRecordingProxyListener> mRecordingProxyListener; 154 155 friend class CameraBase; 156 }; 157 158 }; // namespace android 159 160 #endif 161