QCameraStream.h revision 6f83d735d8e3b918da42e6b559fcd0efb78133e5
1/* Copyright (c) 2012, 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_STREAM_H__
31#define __QCAMERA_STREAM_H__
32
33#include <hardware/camera.h>
34#include "QCameraCmdThread.h"
35#include "QCameraMem.h"
36#include "QCameraAllocator.h"
37
38extern "C" {
39#include <mm_camera_interface.h>
40}
41
42namespace qcamera {
43
44class QCameraStream;
45typedef void (*stream_cb_routine)(mm_camera_super_buf_t *frame,
46                                  QCameraStream *stream,
47                                  void *userdata);
48
49class QCameraStream
50{
51public:
52    QCameraStream(QCameraAllocator &allocator,
53                  uint32_t camHandle,
54                  uint32_t chId,
55                  mm_camera_ops_t *camOps,
56                  cam_padding_info_t *paddingInfo);
57    virtual ~QCameraStream();
58    virtual int32_t init(QCameraHeapMemory *streamInfoBuf,
59                         uint8_t minStreamBufNum,
60                         stream_cb_routine stream_cb,
61                         void *userdata);
62    virtual int32_t processZoomDone(preview_stream_ops_t *previewWindow,
63                                    cam_crop_data_t &crop_info);
64    virtual int32_t bufDone(int index);
65    virtual int32_t bufDone(const void *opaque, bool isMetaData);
66    virtual int32_t processDataNotify(mm_camera_super_buf_t *bufs);
67    virtual int32_t start();
68    virtual int32_t stop();
69
70    static void dataNotifyCB(mm_camera_super_buf_t *recvd_frame, void *userdata);
71    static void *dataProcRoutine(void *data);
72    uint32_t getMyHandle() const {return mHandle;}
73    bool isTypeOf(cam_stream_type_t type);
74    int32_t getFrameOffset(cam_frame_len_offset_t &offset);
75    int32_t getCropInfo(cam_rect_t &crop);
76    int32_t getFrameDimension(cam_dimension_t &dim);
77    int32_t getFormat(cam_format_t &fmt);
78    QCameraMemory *getStreamBufs() {return mStreamBufs;};
79    uint32_t getMyServerID();
80    cam_stream_type_t getMyType();
81
82    int32_t mapBuf(uint8_t buf_type, uint32_t buf_idx,
83                   int32_t plane_idx, int fd, uint32_t size);
84    int32_t unmapBuf(uint8_t buf_type, uint32_t buf_idx, int32_t plane_idx);
85    int32_t setParameter(cam_stream_parm_buffer_t &param);
86
87private:
88    uint32_t mCamHandle;
89    uint32_t mChannelHandle;
90    uint32_t mHandle; // stream handle from mm-camera-interface
91    mm_camera_ops_t *mCamOps;
92    cam_stream_info_t *mStreamInfo; // ptr to stream info buf
93    mm_camera_stream_mem_vtbl_t mMemVtbl;
94    uint8_t mNumBufs;
95    stream_cb_routine mDataCB;
96    void *mUserData;
97
98    QCameraQueue     mDataQ;
99    QCameraCmdThread mProcTh; // thread for dataCB
100
101    QCameraHeapMemory *mStreamInfoBuf;
102    QCameraMemory *mStreamBufs;
103    QCameraAllocator &mAllocator;
104    mm_camera_buf_def_t *mBufDefs;
105    cam_frame_len_offset_t mFrameLenOffset;
106    cam_padding_info_t mPaddingInfo;
107    cam_rect_t mCropInfo;
108    pthread_mutex_t mCropLock; // lock to protect crop info
109
110    static int32_t get_bufs(
111                     cam_frame_len_offset_t *offset,
112                     uint8_t *num_bufs,
113                     uint8_t **initial_reg_flag,
114                     mm_camera_buf_def_t **bufs,
115                     mm_camera_map_unmap_ops_tbl_t *ops_tbl,
116                     void *user_data);
117    static int32_t put_bufs(
118                     mm_camera_map_unmap_ops_tbl_t *ops_tbl,
119                     void *user_data);
120    static int32_t invalidate_buf(int index, void *user_data);
121
122    int32_t getBufs(cam_frame_len_offset_t *offset,
123                     uint8_t *num_bufs,
124                     uint8_t **initial_reg_flag,
125                     mm_camera_buf_def_t **bufs,
126                     mm_camera_map_unmap_ops_tbl_t *ops_tbl);
127    int32_t putBufs(mm_camera_map_unmap_ops_tbl_t *ops_tbl);
128    int32_t invalidateBuf(int index);
129
130};
131
132}; // namespace qcamera
133
134#endif /* __QCAMERA_STREAM_H__ */
135