1 /* 2 ** Copyright (c) 2012 The Linux Foundation. All rights reserved. 3 ** 4 ** Not a Contribution, Apache license notifications and license are retained 5 ** for attribution purposes only. 6 ** 7 ** Licensed under the Apache License, Version 2.0 (the "License"); 8 ** you may not use this file except in compliance with the License. 9 ** You may obtain a copy of the License at 10 ** 11 ** http://www.apache.org/licenses/LICENSE-2.0 12 ** 13 ** Unless required by applicable law or agreed to in writing, software 14 ** distributed under the License is distributed on an "AS IS" BASIS, 15 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 ** See the License for the specific language governing permissions and 17 ** limitations under the License. 18 */ 19 20 #ifndef ANDROID_HARDWARE_QCAMERA_STREAM_H 21 #define ANDROID_HARDWARE_QCAMERA_STREAM_H 22 23 24 #include <binder/MemoryBase.h> 25 #include <binder/MemoryHeapBase.h> 26 #include <pthread.h> 27 #include <semaphore.h> 28 29 30 #include "QCameraHWI.h" 31 #include "QCameraHWI_Mem.h" 32 #include "mm_camera_interface.h" 33 #include "mm_jpeg_interface.h" 34 35 extern "C" { 36 #define DEFAULT_STREAM_WIDTH 320 37 #define DEFAULT_STREAM_HEIGHT 240 38 #define DEFAULT_LIVESHOT_WIDTH 2592 39 #define DEFAULT_LIVESHOT_HEIGHT 1944 40 41 #define MM_CAMERA_CH_PREVIEW_MASK (0x01 << MM_CAMERA_CH_PREVIEW) 42 #define MM_CAMERA_CH_VIDEO_MASK (0x01 << MM_CAMERA_CH_VIDEO) 43 #define MM_CAMERA_CH_SNAPSHOT_MASK (0x01 << MM_CAMERA_CH_SNAPSHOT) 44 #define MM_CAMERA_CH_RDI_MASK (0x01 << MM_CAMERA_CH_RDI) 45 46 } /* extern C*/ 47 48 namespace android { 49 50 class QCameraHardwareInterface; 51 52 class QCameraStream { //: public virtual RefBase 53 54 public: 55 bool mInit; 56 bool mActive; 57 58 uint32_t mCameraHandle; 59 uint32_t mChannelId; 60 uint32_t mStreamId; 61 uint32_t mWidth; 62 uint32_t mHeight; 63 uint32_t mFormat; 64 uint8_t mNumBuffers; 65 mm_camera_frame_len_offset mFrameOffsetInfo; 66 mm_camera_vtbl_t *p_mm_ops; 67 mm_camera_img_mode mExtImgMode; 68 uint8_t m_flag_no_cb; 69 uint8_t m_flag_stream_on; 70 image_crop_t mCrop; 71 QCameraHardwareInterface* mHalCamCtrl; 72 73 void setResolution(mm_camera_dimension_t *res); 74 bool isResolutionSame(mm_camera_dimension_t *res); 75 void getResolution(mm_camera_dimension_t *res); 76 virtual void release(); 77 78 status_t setFormat(); 79 80 //static status_t openChannel(mm_camera_t *, mm_camera_channel_type_t ch_type); 81 void dataCallback(mm_camera_super_buf_t *bufs); 82 virtual int32_t streamOn(); 83 virtual int32_t streamOff(bool aSync); 84 virtual status_t initStream(uint8_t no_cb_needed, uint8_t stream_on); 85 virtual status_t deinitStream(); releaseRecordingFrame(const void * opaque)86 virtual void releaseRecordingFrame(const void *opaque) 87 { 88 ; 89 } getHeap()90 virtual sp<IMemoryHeap> getHeap() const{return NULL;} getRawHeap()91 virtual sp<IMemoryHeap> getRawHeap() const {return NULL;} getLastQueuedFrame(void)92 virtual void *getLastQueuedFrame(void){return NULL;} notifyROIEvent(fd_roi_t roi)93 virtual void notifyROIEvent(fd_roi_t roi) {;} notifyWDenoiseEvent(cam_ctrl_status_t status,void * cookie)94 virtual void notifyWDenoiseEvent(cam_ctrl_status_t status, void * cookie) {;} notifyHdrEvent(cam_ctrl_status_t status,void * cookie)95 virtual void notifyHdrEvent(cam_ctrl_status_t status, void * cookie){}; 96 virtual int32_t setCrop(); 97 virtual int getBuf(mm_camera_frame_len_offset *frame_offset_info, 98 uint8_t num_bufs, 99 uint8_t *initial_reg_flag, 100 mm_camera_buf_def_t *bufs) = 0; 101 virtual int putBuf(uint8_t num_bufs, 102 mm_camera_buf_def_t *bufs) = 0; 103 104 QCameraStream(); 105 QCameraStream(uint32_t CameraHandle, 106 uint32_t ChannelId, 107 uint32_t Width, 108 uint32_t Height, 109 uint32_t Format, 110 uint8_t NumBuffers, 111 mm_camera_vtbl_t *mm_ops, 112 mm_camera_img_mode imgmode, 113 camera_mode_t mode, 114 QCameraHardwareInterface* camCtrl); 115 virtual ~QCameraStream(); 116 117 }; 118 /* 119 * Record Class 120 */ 121 class QCameraStream_record : public QCameraStream { 122 public: 123 void release() ; 124 125 QCameraStream_record(uint32_t CameraHandle, 126 uint32_t ChannelId, 127 uint32_t Width, 128 uint32_t Height, 129 uint32_t Format, 130 uint8_t NumBuffers, 131 mm_camera_vtbl_t *mm_ops, 132 mm_camera_img_mode imgmode, 133 camera_mode_t mode, 134 QCameraHardwareInterface* camCtrl); 135 virtual ~QCameraStream_record(); 136 137 status_t processRecordFrame(mm_camera_super_buf_t *data); 138 status_t initEncodeBuffers(); 139 status_t getBufferInfo(sp<IMemory>& Frame, size_t *alignedSize); 140 141 void releaseRecordingFrame(const void *opaque); 142 void debugShowVideoFPS() const; 143 144 void releaseEncodeBuffer(); 145 146 int getBuf(mm_camera_frame_len_offset *frame_offset_info, 147 uint8_t num_bufs, 148 uint8_t *initial_reg_flag, 149 mm_camera_buf_def_t *bufs); 150 int putBuf(uint8_t num_bufs, 151 mm_camera_buf_def_t *bufs); 152 status_t initStream(uint8_t no_cb_needed, uint8_t stream_on); 153 154 private: 155 bool mDebugFps; 156 mm_camera_super_buf_t mRecordedFrames[MM_CAMERA_MAX_NUM_FRAMES]; 157 mm_camera_buf_def_t mRecordBuf[2*VIDEO_BUFFER_COUNT]; 158 int mJpegMaxSize; 159 QCameraStream *mStreamSnap; 160 }; 161 162 class QCameraStream_preview : public QCameraStream { 163 public: 164 QCameraStream_preview(uint32_t CameraHandle, 165 uint32_t ChannelId, 166 uint32_t Width, 167 uint32_t Height, 168 uint32_t Format, 169 uint8_t NumBuffers, 170 mm_camera_vtbl_t *mm_ops, 171 mm_camera_img_mode imgmode, 172 camera_mode_t mode, 173 QCameraHardwareInterface* camCtrl); 174 virtual ~QCameraStream_preview(); 175 void release() ; 176 void *getLastQueuedFrame(void); 177 /*init preview buffers with display case*/ 178 status_t initDisplayBuffers(); 179 /*init preview buffers without display case*/ 180 status_t initPreviewOnlyBuffers(); 181 status_t initStream(uint8_t no_cb_needed, uint8_t stream_on); 182 status_t processPreviewFrame(mm_camera_super_buf_t *frame); 183 /*init preview buffers with display case*/ 184 status_t processPreviewFrameWithDisplay(mm_camera_super_buf_t *frame); 185 /*init preview buffers without display case*/ 186 status_t processPreviewFrameWithOutDisplay(mm_camera_super_buf_t *frame); 187 188 void notifyROIEvent(fd_roi_t roi); 189 int32_t setCrop(); 190 int getBuf(mm_camera_frame_len_offset *frame_offset_info, 191 uint8_t num_bufs, 192 uint8_t *initial_reg_flag, 193 mm_camera_buf_def_t *bufs); 194 int putBuf(uint8_t num_bufs, 195 mm_camera_buf_def_t *bufs); 196 197 friend class QCameraHardwareInterface; 198 199 private: 200 /*allocate and free buffers with display case*/ 201 status_t getBufferFromSurface(); 202 status_t putBufferToSurface(); 203 204 /*allocate and free buffers without display case*/ 205 status_t getBufferNoDisplay(); 206 status_t freeBufferNoDisplay(); 207 208 void dumpFrameToFile(mm_camera_buf_def_t* newFrame); 209 bool mFirstFrameRcvd; 210 211 int8_t my_id; 212 mm_camera_op_mode_type_t op_mode; 213 mm_camera_buf_def_t *mLastQueuedFrame; 214 mm_camera_buf_def_t mDisplayBuf[2*PREVIEW_BUFFER_COUNT]; 215 Mutex mDisplayLock; 216 preview_stream_ops_t *mPreviewWindow; 217 mm_camera_super_buf_t mNotifyBuffer[2*PREVIEW_BUFFER_COUNT]; 218 int8_t mNumFDRcvd; 219 int mVFEOutputs; 220 int mHFRFrameCnt; 221 int mHFRFrameSkip; 222 }; 223 224 class QCameraStream_SnapshotMain : public QCameraStream { 225 public: 226 void release(); 227 status_t initStream(uint8_t no_cb_needed, uint8_t stream_on); 228 status_t initMainBuffers(); 229 void deInitMainBuffers(); 230 mm_camera_buf_def_t mSnapshotStreamBuf[MM_CAMERA_MAX_NUM_FRAMES]; 231 QCameraStream_SnapshotMain(uint32_t CameraHandle, 232 uint32_t ChannelId, 233 uint32_t Width, 234 uint32_t Height, 235 uint32_t Format, 236 uint8_t NumBuffers, 237 mm_camera_vtbl_t *mm_ops, 238 mm_camera_img_mode imgmode, 239 camera_mode_t mode, 240 QCameraHardwareInterface* camCtrl); 241 ~QCameraStream_SnapshotMain(); 242 int getBuf(mm_camera_frame_len_offset *frame_offset_info, 243 uint8_t num_bufs, 244 uint8_t *initial_reg_flag, 245 mm_camera_buf_def_t *bufs); 246 int putBuf(uint8_t num_bufs, 247 mm_camera_buf_def_t *bufs); 248 249 private: 250 /*Member variables*/ 251 int mSnapshotState; 252 }; 253 254 class QCameraStream_SnapshotThumbnail : public QCameraStream { 255 public: 256 void release(); 257 QCameraStream_SnapshotThumbnail(uint32_t CameraHandle, 258 uint32_t ChannelId, 259 uint32_t Width, 260 uint32_t Height, 261 uint32_t Format, 262 uint8_t NumBuffers, 263 mm_camera_vtbl_t *mm_ops, 264 mm_camera_img_mode imgmode, 265 camera_mode_t mode, 266 QCameraHardwareInterface* camCtrl); 267 ~QCameraStream_SnapshotThumbnail(); 268 int getBuf(mm_camera_frame_len_offset *frame_offset_info, 269 uint8_t num_bufs, 270 uint8_t *initial_reg_flag, 271 mm_camera_buf_def_t *bufs); 272 int putBuf(uint8_t num_bufs, 273 mm_camera_buf_def_t *bufs); 274 status_t initStream(uint8_t no_cb_needed, uint8_t stream_on); 275 276 private: 277 mm_camera_buf_def_t mPostviewStreamBuf[MM_CAMERA_MAX_NUM_FRAMES]; 278 }; 279 280 class QCameraStream_Rdi : public QCameraStream { 281 public: 282 void release() ; 283 284 QCameraStream_Rdi(uint32_t CameraHandle, 285 uint32_t ChannelId, 286 uint32_t Width, 287 uint32_t Height, 288 uint32_t Format, 289 uint8_t NumBuffers, 290 mm_camera_vtbl_t *mm_ops, 291 mm_camera_img_mode imgmode, 292 camera_mode_t mode, 293 QCameraHardwareInterface* camCtrl); 294 virtual ~QCameraStream_Rdi(); 295 status_t processRdiFrame (mm_camera_super_buf_t *data); 296 int getBuf(mm_camera_frame_len_offset *frame_offset_info, 297 uint8_t num_bufs, 298 uint8_t *initial_reg_flag, 299 mm_camera_buf_def_t *bufs); 300 int putBuf(uint8_t num_bufs, 301 mm_camera_buf_def_t *bufs); 302 status_t initStream(uint8_t no_cb_needed, uint8_t stream_on); 303 304 friend class QCameraHardwareInterface; 305 306 private: 307 void dumpFrameToFile(mm_camera_buf_def_t* newFrame); 308 309 int8_t my_id; 310 mm_camera_op_mode_type_t op_mode; 311 mm_camera_buf_def_t mRdiBuf[PREVIEW_BUFFER_COUNT]; 312 }; 313 314 }; // namespace android 315 316 #endif 317