1 /* Copyright (c) 2012-2014, The Linux Foundataion. 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 <hardware/camera.h>
34 #include "QCameraStream.h"
35 
36 extern "C" {
37 #include <mm_camera_interface.h>
38 }
39 
40 namespace qcamera {
41 
42 class QCameraChannel
43 {
44 public:
45     QCameraChannel(uint32_t cam_handle,
46                    mm_camera_ops_t *cam_ops);
47     QCameraChannel();
48     virtual ~QCameraChannel();
49     virtual int32_t init(mm_camera_channel_attr_t *attr,
50                          mm_camera_buf_notify_t dataCB, // data CB for channel data
51                          void *userData);
52     // Owner of memory is transferred from the caller to the caller with this call.
53     virtual int32_t addStream(QCameraAllocator& allocator,
54                               QCameraHeapMemory *streamInfoBuf,
55                               uint8_t minStreamBufnum,
56                               cam_padding_info_t *paddingInfo,
57                               stream_cb_routine stream_cb,
58                               void *userdata,
59                               bool bDynAllocBuf,
60                               bool bDeffAlloc = false);
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 processZoomDone(preview_stream_ops_t *previewWindow,
65                                     cam_crop_data_t &crop_info);
66     int32_t config();
67     QCameraStream *getStreamByHandle(uint32_t streamHandle);
getMyHandle()68     uint32_t getMyHandle() const {return m_handle;};
getNumOfStreams()69     uint8_t getNumOfStreams() const {return m_numStreams;};
70     QCameraStream *getStreamByIndex(uint8_t index);
71     QCameraStream *getStreamByServerID(uint32_t serverID);
72     int32_t UpdateStreamBasedParameters(QCameraParameters &param);
73     void deleteChannel();
74 
75 protected:
76     uint32_t m_camHandle;
77     mm_camera_ops_t *m_camOps;
78     bool m_bIsActive;
79     bool m_bAllowDynBufAlloc; // if buf allocation can be in two steps
80 
81     uint32_t m_handle;
82     uint8_t m_numStreams;
83     QCameraStream *mStreams[MAX_STREAM_NUM_IN_BUNDLE];
84     mm_camera_buf_notify_t mDataCB;
85     void *mUserData;
86 };
87 
88 // burst pic channel: i.e. zsl burst mode
89 class QCameraPicChannel : public QCameraChannel
90 {
91 public:
92     QCameraPicChannel(uint32_t cam_handle,
93                       mm_camera_ops_t *cam_ops);
94     QCameraPicChannel();
95     virtual ~QCameraPicChannel();
96     int32_t takePicture(uint8_t num_of_snapshot, uint8_t num_of_retro_snapshot);
97     int32_t cancelPicture();
98     int32_t startAdvancedCapture(mm_camera_advanced_capture_t type);
99 };
100 
101 // video channel class
102 class QCameraVideoChannel : public QCameraChannel
103 {
104 public:
105     QCameraVideoChannel(uint32_t cam_handle,
106                         mm_camera_ops_t *cam_ops);
107     QCameraVideoChannel();
108     virtual ~QCameraVideoChannel();
109     int32_t releaseFrame(const void *opaque, bool isMetaData);
110 };
111 
112 // reprocess channel class
113 class QCameraReprocessChannel : public QCameraChannel
114 {
115 public:
116     QCameraReprocessChannel(uint32_t cam_handle,
117                             mm_camera_ops_t *cam_ops);
118     QCameraReprocessChannel();
119     virtual ~QCameraReprocessChannel();
120     int32_t addReprocStreamsFromSource(QCameraAllocator& allocator,
121                                        cam_pp_feature_config_t &config,
122                                        QCameraChannel *pSrcChannel,
123                                        uint8_t minStreamBufNum,
124                                        uint32_t burstNum,
125                                        cam_padding_info_t *paddingInfo,
126                                        QCameraParameters &param,
127                                        bool contStream,
128                                        bool offline);
129     // online reprocess
130     int32_t doReprocess(mm_camera_super_buf_t *frame);
131     // offline reprocess
132     int32_t doReprocess(int buf_fd, uint32_t buf_length, int32_t &ret_val);
133     int32_t doReprocessOffline(mm_camera_super_buf_t *frame);
134     int32_t stop();
135 
136 private:
137     QCameraStream *getStreamBySrouceHandle(uint32_t srcHandle);
138 
139     typedef struct {
140         QCameraStream *stream;
141         cam_mapping_buf_type type;
142         int index;
143     } OfflineBuffer;
144 
145     uint32_t mSrcStreamHandles[MAX_STREAM_NUM_IN_BUNDLE];
146     QCameraChannel *m_pSrcChannel; // ptr to source channel for reprocess
147     android::List<OfflineBuffer> mOfflineBuffers;
148 
149 };
150 
151 }; // namespace qcamera
152 
153 #endif /* __QCAMERA_CHANNEL_H__ */
154