1 /* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved. 2 * 3 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions are 5 * met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above 9 * copyright notice, this list of conditions and the following 10 * disclaimer in the documentation and/or other materials provided 11 * with the distribution. 12 * * Neither the name of The Linux Foundation nor the names of its 13 * contributors may be used to endorse or promote products derived 14 * from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 */ 29 30 #ifndef __QCAMERA_CHANNEL_H__ 31 #define __QCAMERA_CHANNEL_H__ 32 33 #include "camera.h" 34 #include "QCameraMem.h" 35 #include "QCameraParameters.h" 36 #include "QCameraStream.h" 37 38 extern "C" { 39 #include "mm_camera_interface.h" 40 } 41 42 namespace qcamera { 43 44 class QCameraChannel 45 { 46 public: 47 QCameraChannel(uint32_t cam_handle, 48 mm_camera_ops_t *cam_ops); 49 QCameraChannel(); 50 virtual ~QCameraChannel(); 51 virtual int32_t init(mm_camera_channel_attr_t *attr, 52 mm_camera_buf_notify_t dataCB, // data CB for channel data 53 void *userData); 54 // Owner of memory is transferred from the caller to the caller with this call. 55 virtual int32_t addStream(QCameraAllocator& allocator, 56 QCameraHeapMemory *streamInfoBuf, QCameraHeapMemory *miscBuf, 57 cam_padding_info_t *paddingInfo, 58 stream_cb_routine stream_cb, void *userdata, bool bDynAllocBuf, 59 bool bDeffAlloc = false, cam_rotation_t online_rotation = ROTATE_0); 60 virtual int32_t linkStream(QCameraChannel *ch, QCameraStream *stream); 61 virtual int32_t start(); 62 virtual int32_t stop(); 63 virtual int32_t bufDone(mm_camera_super_buf_t *recvd_frame); 64 virtual int32_t bufDone(mm_camera_super_buf_t *recvd_frame, uint32_t stream_id); 65 virtual int32_t processZoomDone(preview_stream_ops_t *previewWindow, 66 cam_crop_data_t &crop_info); 67 QCameraStream *getStreamByHandle(uint32_t streamHandle); 68 uint32_t getMyHandle() const {return m_handle;}; 69 uint32_t getNumOfStreams() const {return (uint32_t) mStreams.size();}; 70 QCameraStream *getStreamByIndex(uint32_t index); 71 QCameraStream *getStreamByServerID(uint32_t serverID); 72 int32_t UpdateStreamBasedParameters(QCameraParametersIntf ¶m); 73 void deleteChannel(); 74 int32_t setStreamSyncCB (cam_stream_type_t stream_type, 75 stream_cb_routine stream_cb); 76 bool isActive() { return m_bIsActive; } 77 uint32_t getChHandleForStream(cam_stream_type_t stream_type); 78 int32_t switchChannelCb(); 79 int32_t processCameraControl(uint32_t camState); 80 bool isDualChannel(){return mDualChannel;}; 81 protected: 82 uint32_t m_camHandle; 83 mm_camera_ops_t *m_camOps; 84 bool m_bIsActive; 85 bool m_bAllowDynBufAlloc; // if buf allocation can be in two steps 86 87 uint32_t m_handle; 88 uint32_t mActiveHandle; 89 uint32_t mActiveCamera; 90 Vector<QCameraStream *> mStreams; 91 mm_camera_buf_notify_t mDataCB; 92 void *mUserData; 93 Mutex mStreamLock; 94 bool mDualChannel; 95 }; 96 97 // burst pic channel: i.e. zsl burst mode 98 class QCameraPicChannel : public QCameraChannel 99 { 100 public: 101 QCameraPicChannel(uint32_t cam_handle, 102 mm_camera_ops_t *cam_ops); 103 QCameraPicChannel(); 104 virtual ~QCameraPicChannel(); 105 int32_t takePicture(mm_camera_req_buf_t *buf); 106 int32_t cancelPicture(); 107 int32_t stopAdvancedCapture(mm_camera_advanced_capture_t type); 108 int32_t startAdvancedCapture(mm_camera_advanced_capture_t type, 109 cam_capture_frame_config_t *config = NULL); 110 int32_t flushSuperbuffer(uint32_t frame_idx); 111 }; 112 113 // video channel class 114 class QCameraVideoChannel : public QCameraChannel 115 { 116 public: 117 QCameraVideoChannel(uint32_t cam_handle, 118 mm_camera_ops_t *cam_ops); 119 QCameraVideoChannel(); 120 virtual ~QCameraVideoChannel(); 121 int32_t takePicture(mm_camera_req_buf_t *buf); 122 int32_t cancelPicture(); 123 int32_t releaseFrame(const void *opaque, bool isMetaData); 124 }; 125 126 // reprocess channel class 127 class QCameraReprocessChannel : public QCameraChannel 128 { 129 public: 130 QCameraReprocessChannel(uint32_t cam_handle, 131 mm_camera_ops_t *cam_ops); 132 QCameraReprocessChannel(); 133 virtual ~QCameraReprocessChannel(); 134 int32_t addReprocStreamsFromSource(QCameraAllocator& allocator, 135 cam_pp_feature_config_t &config, 136 QCameraChannel *pSrcChannel, 137 uint8_t minStreamBufNum, 138 uint8_t burstNum, 139 cam_padding_info_t *paddingInfo, 140 QCameraParametersIntf ¶m, 141 bool contStream, 142 bool offline); 143 // online reprocess 144 int32_t doReprocess(mm_camera_super_buf_t *frame, 145 QCameraParametersIntf ¶m, QCameraStream *pMetaStream, 146 uint8_t meta_buf_index); 147 148 // offline reprocess 149 int32_t doReprocess(int buf_fd, void *buffer, size_t buf_length, int32_t &ret_val); 150 151 int32_t doReprocessOffline(mm_camera_super_buf_t *frame, 152 mm_camera_buf_def_t *meta_buf, QCameraParametersIntf ¶m); 153 154 int32_t doReprocessOffline(mm_camera_buf_def_t *frame, 155 mm_camera_buf_def_t *meta_buf, QCameraStream *pStream = NULL); 156 157 int32_t stop(); 158 QCameraChannel *getSrcChannel(){return m_pSrcChannel;}; 159 int8_t getReprocCount(){return mPassCount;}; 160 void setReprocCount(int8_t count) {mPassCount = count;}; 161 162 private: 163 QCameraStream *getStreamBySrouceHandle(uint32_t srcHandle); 164 165 typedef struct { 166 QCameraStream *stream; 167 cam_mapping_buf_type type; 168 uint32_t index; 169 } OfflineBuffer; 170 171 uint32_t mSrcStreamHandles[MAX_STREAM_NUM_IN_BUNDLE]; 172 QCameraChannel *m_pSrcChannel; // ptr to source channel for reprocess 173 android::List<OfflineBuffer> mOfflineBuffers; 174 int8_t mPassCount; 175 }; 176 177 }; // namespace qcamera 178 179 #endif /* __QCAMERA_CHANNEL_H__ */ 180