• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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             uint32_t cam_type = MM_CAMERA_TYPE_MAIN);
61     virtual int32_t linkStream(QCameraChannel *ch, QCameraStream *stream);
62     virtual int32_t start();
63     virtual int32_t stop();
64     virtual int32_t bufDone(mm_camera_super_buf_t *recvd_frame);
65     virtual int32_t bufDone(mm_camera_super_buf_t *recvd_frame, uint32_t stream_id);
66     virtual int32_t processZoomDone(preview_stream_ops_t *previewWindow,
67                                     cam_crop_data_t &crop_info);
68     QCameraStream *getStreamByHandle(uint32_t streamHandle);
getMyHandle()69     uint32_t getMyHandle() const {return m_handle;};
getNumOfStreams()70     uint32_t getNumOfStreams() const {return (uint32_t) mStreams.size();};
71     QCameraStream *getStreamByIndex(uint32_t index);
72     QCameraStream *getStreamByServerID(uint32_t serverID);
73     int32_t UpdateStreamBasedParameters(QCameraParametersIntf &param);
74     void deleteChannel();
75     int32_t setStreamSyncCB (cam_stream_type_t stream_type,
76             stream_cb_routine stream_cb);
isActive()77     bool isActive() { return m_bIsActive; }
78     uint32_t getChHandleForStream(cam_stream_type_t stream_type);
79     int32_t switchChannelCb(uint32_t camMaster);
80     int32_t processCameraControl(uint32_t camState, bool bundledSnapshot);
isDualChannel()81     bool isDualChannel(){return mDualChannel;};
82     uint32_t getSnapshotHandle();
83 protected:
84     uint32_t m_camHandle;
85     mm_camera_ops_t *m_camOps;
86     bool m_bIsActive;
87     bool m_bAllowDynBufAlloc; // if buf allocation can be in two steps
88 
89     uint32_t m_handle;
90     uint32_t mActiveCameras;
91     uint32_t mMasterCamera;
92     bool     mBundledSnapshot;
93     Vector<QCameraStream *> mStreams;
94     mm_camera_buf_notify_t mDataCB;
95     void *mUserData;
96     Mutex mStreamLock;
97     bool mDualChannel;
98 };
99 
100 // burst pic channel: i.e. zsl burst mode
101 class QCameraPicChannel : public QCameraChannel
102 {
103 public:
104     QCameraPicChannel(uint32_t cam_handle,
105                       mm_camera_ops_t *cam_ops);
106     QCameraPicChannel();
107     virtual ~QCameraPicChannel();
108     int32_t takePicture(mm_camera_req_buf_t *buf);
109     int32_t cancelPicture();
110     int32_t stopAdvancedCapture(mm_camera_advanced_capture_t type);
111     int32_t startAdvancedCapture(mm_camera_advanced_capture_t type,
112             cam_capture_frame_config_t *config = NULL);
113     int32_t flushSuperbuffer(uint32_t frame_idx);
114 };
115 
116 // video channel class
117 class QCameraVideoChannel : public QCameraChannel
118 {
119 public:
120     QCameraVideoChannel(uint32_t cam_handle,
121                         mm_camera_ops_t *cam_ops);
122     QCameraVideoChannel();
123     virtual ~QCameraVideoChannel();
124     int32_t takePicture(mm_camera_req_buf_t *buf);
125     int32_t cancelPicture();
126     int32_t releaseFrame(const void *opaque, bool isMetaData);
127 };
128 
129 // reprocess channel class
130 class QCameraReprocessChannel : public QCameraChannel
131 {
132 public:
133     QCameraReprocessChannel(uint32_t cam_handle,
134                             mm_camera_ops_t *cam_ops);
135     QCameraReprocessChannel();
136     virtual ~QCameraReprocessChannel();
137     int32_t addReprocStreamsFromSource(QCameraAllocator& allocator,
138                                        cam_pp_feature_config_t &config,
139                                        QCameraChannel *pSrcChannel,
140                                        uint8_t minStreamBufNum,
141                                        uint8_t burstNum,
142                                        cam_padding_info_t *paddingInfo,
143                                        QCameraParametersIntf &param,
144                                        bool contStream,
145                                        bool offline);
146     // online reprocess
147     int32_t doReprocess(mm_camera_super_buf_t *frame,
148             QCameraParametersIntf &param, QCameraStream *pMetaStream,
149             uint8_t meta_buf_index);
150 
151     // offline reprocess
152     int32_t doReprocess(int buf_fd, void *buffer, size_t buf_length, int32_t &ret_val);
153 
154     int32_t doReprocessOffline(mm_camera_super_buf_t *frame,
155              mm_camera_buf_def_t *meta_buf, QCameraParametersIntf &param);
156 
157     int32_t doReprocessOffline(mm_camera_buf_def_t *frame,
158              mm_camera_buf_def_t *meta_buf, QCameraStream *pStream = NULL);
159 
160     int32_t stop();
getSrcChannel()161     QCameraChannel *getSrcChannel(){return m_pSrcChannel;};
getReprocCount()162     int8_t getReprocCount(){return mPassCount;};
setReprocCount(int8_t count)163     void setReprocCount(int8_t count) {mPassCount = count;};
164 
165 private:
166     QCameraStream *getStreamBySrouceHandle(uint32_t srcHandle);
167 
168     typedef struct {
169         QCameraStream *stream;
170         cam_mapping_buf_type type;
171         uint32_t index;
172     } OfflineBuffer;
173 
174     uint32_t mSrcStreamHandles[MAX_STREAM_NUM_IN_BUNDLE];
175     QCameraChannel *m_pSrcChannel; // ptr to source channel for reprocess
176     android::List<OfflineBuffer> mOfflineBuffers;
177     int8_t mPassCount;
178 };
179 
180 }; // namespace qcamera
181 
182 #endif /* __QCAMERA_CHANNEL_H__ */
183