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