aboutsummaryrefslogtreecommitdiff
path: root/camera/QCamera2/HAL/QCameraChannel.h
blob: 695ddbde6243383afac613aa5813f8416d50c2ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above
 *       copyright notice, this list of conditions and the following
 *       disclaimer in the documentation and/or other materials provided
 *       with the distribution.
 *     * Neither the name of The Linux Foundation nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#ifndef __QCAMERA_CHANNEL_H__
#define __QCAMERA_CHANNEL_H__

#include "hardware/camera.h"
#include "QCameraMem.h"
#include "QCameraParameters.h"
#include "QCameraStream.h"

extern "C" {
#include "mm_camera_interface.h"
}

namespace qcamera {

class QCameraChannel
{
public:
    QCameraChannel(uint32_t cam_handle,
                   mm_camera_ops_t *cam_ops);
    QCameraChannel();
    virtual ~QCameraChannel();
    virtual int32_t init(mm_camera_channel_attr_t *attr,
                         mm_camera_buf_notify_t dataCB, // data CB for channel data
                         void *userData);
    // Owner of memory is transferred from the caller to the caller with this call.
    virtual int32_t addStream(QCameraAllocator& allocator,
            QCameraHeapMemory *streamInfoBuf, QCameraHeapMemory *miscBuf,
            uint8_t minStreamBufnum, cam_padding_info_t *paddingInfo,
            stream_cb_routine stream_cb, void *userdata, bool bDynAllocBuf,
            bool bDeffAlloc = false, cam_rotation_t online_rotation = ROTATE_0);
    virtual int32_t linkStream(QCameraChannel *ch, QCameraStream *stream);
    virtual int32_t start();
    virtual int32_t stop();
    virtual int32_t bufDone(mm_camera_super_buf_t *recvd_frame);
    virtual int32_t bufDone(mm_camera_super_buf_t *recvd_frame, uint32_t stream_id);
    virtual int32_t processZoomDone(preview_stream_ops_t *previewWindow,
                                    cam_crop_data_t &crop_info);
    QCameraStream *getStreamByHandle(uint32_t streamHandle);
    uint32_t getMyHandle() const {return m_handle;};
    uint32_t getNumOfStreams() const {return (uint32_t) mStreams.size();};
    QCameraStream *getStreamByIndex(uint32_t index);
    QCameraStream *getStreamByServerID(uint32_t serverID);
    int32_t UpdateStreamBasedParameters(QCameraParametersIntf &param);
    void deleteChannel();
    int32_t setStreamSyncCB (cam_stream_type_t stream_type,
            stream_cb_routine stream_cb);
    bool isActive() { return m_bIsActive; }
protected:
    uint32_t m_camHandle;
    mm_camera_ops_t *m_camOps;
    bool m_bIsActive;
    bool m_bAllowDynBufAlloc; // if buf allocation can be in two steps

    uint32_t m_handle;
    Vector<QCameraStream *> mStreams;
    mm_camera_buf_notify_t mDataCB;
    void *mUserData;
};

// burst pic channel: i.e. zsl burst mode
class QCameraPicChannel : public QCameraChannel
{
public:
    QCameraPicChannel(uint32_t cam_handle,
                      mm_camera_ops_t *cam_ops);
    QCameraPicChannel();
    virtual ~QCameraPicChannel();
    int32_t takePicture(mm_camera_req_buf_t *buf);
    int32_t cancelPicture();
    int32_t stopAdvancedCapture(mm_camera_advanced_capture_t type);
    int32_t startAdvancedCapture(mm_camera_advanced_capture_t type,
            cam_capture_frame_config_t *config = NULL);
    int32_t flushSuperbuffer(uint32_t frame_idx);
};

// video channel class
class QCameraVideoChannel : public QCameraChannel
{
public:
    QCameraVideoChannel(uint32_t cam_handle,
                        mm_camera_ops_t *cam_ops);
    QCameraVideoChannel();
    virtual ~QCameraVideoChannel();
    int32_t takePicture(mm_camera_req_buf_t *buf);
    int32_t cancelPicture();
    int32_t releaseFrame(const void *opaque, bool isMetaData);
};

// reprocess channel class
class QCameraReprocessChannel : public QCameraChannel
{
public:
    QCameraReprocessChannel(uint32_t cam_handle,
                            mm_camera_ops_t *cam_ops);
    QCameraReprocessChannel();
    virtual ~QCameraReprocessChannel();
    int32_t addReprocStreamsFromSource(QCameraAllocator& allocator,
                                       cam_pp_feature_config_t &config,
                                       QCameraChannel *pSrcChannel,
                                       uint8_t minStreamBufNum,
                                       uint8_t burstNum,
                                       cam_padding_info_t *paddingInfo,
                                       QCameraParametersIntf &param,
                                       bool contStream,
                                       bool offline);
    // online reprocess
    int32_t doReprocess(mm_camera_super_buf_t *frame,
            QCameraParametersIntf &param, QCameraStream *pMetaStream,
            uint8_t meta_buf_index);

    // offline reprocess
    int32_t doReprocess(int buf_fd, size_t buf_length, int32_t &ret_val);

    int32_t doReprocessOffline(mm_camera_super_buf_t *frame,
             mm_camera_buf_def_t *meta_buf, QCameraParametersIntf &param);

    int32_t doReprocessOffline(mm_camera_buf_def_t *frame,
             mm_camera_buf_def_t *meta_buf, QCameraStream *pStream = NULL);

    int32_t stop();
    QCameraChannel *getSrcChannel(){return m_pSrcChannel;};
    int8_t getReprocCount(){return mPassCount;};
    void setReprocCount(int8_t count) {mPassCount = count;};

private:
    QCameraStream *getStreamBySrouceHandle(uint32_t srcHandle);

    typedef struct {
        QCameraStream *stream;
        cam_mapping_buf_type type;
        uint32_t index;
    } OfflineBuffer;

    uint32_t mSrcStreamHandles[MAX_STREAM_NUM_IN_BUNDLE];
    QCameraChannel *m_pSrcChannel; // ptr to source channel for reprocess
    android::List<OfflineBuffer> mOfflineBuffers;
    int8_t mPassCount;
};

}; // namespace qcamera

#endif /* __QCAMERA_CHANNEL_H__ */