16f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev/* Copyright (c) 2012, The Linux Foundataion. All rights reserved.
26f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
36f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * Redistribution and use in source and binary forms, with or without
46f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * modification, are permitted provided that the following conditions are
56f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * met:
66f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *     * Redistributions of source code must retain the above copyright
76f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *       notice, this list of conditions and the following disclaimer.
86f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *     * Redistributions in binary form must reproduce the above
96f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *       copyright notice, this list of conditions and the following
106f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *       disclaimer in the documentation and/or other materials provided
116f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *       with the distribution.
126f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *     * Neither the name of The Linux Foundation nor the names of its
136f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *       contributors may be used to endorse or promote products derived
146f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *       from this software without specific prior written permission.
156f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
166f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
176f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
186f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
196f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
206f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
216f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
226f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
236f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
246f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
256f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
266f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev *
286f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev */
296f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
306f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#ifndef __QCAMERA_STREAM_H__
316f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#define __QCAMERA_STREAM_H__
326f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
336f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#include <hardware/camera.h>
346f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#include "QCameraCmdThread.h"
356f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#include "QCameraMem.h"
366f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#include "QCameraAllocator.h"
376f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
386f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevextern "C" {
396f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#include <mm_camera_interface.h>
406f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}
416f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
426f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevnamespace qcamera {
436f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
446f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevclass QCameraStream;
456f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevtypedef void (*stream_cb_routine)(mm_camera_super_buf_t *frame,
466f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                                  QCameraStream *stream,
476f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                                  void *userdata);
486f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
496f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevclass QCameraStream
506f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev{
516f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevpublic:
526f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCameraStream(QCameraAllocator &allocator,
536f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                  uint32_t camHandle,
546f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                  uint32_t chId,
556f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                  mm_camera_ops_t *camOps,
566f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                  cam_padding_info_t *paddingInfo);
576f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    virtual ~QCameraStream();
586f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    virtual int32_t init(QCameraHeapMemory *streamInfoBuf,
596f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                         uint8_t minStreamBufNum,
606f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                         stream_cb_routine stream_cb,
616f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                         void *userdata);
626f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    virtual int32_t processZoomDone(preview_stream_ops_t *previewWindow,
636f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                                    cam_crop_data_t &crop_info);
646f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    virtual int32_t bufDone(int index);
656f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    virtual int32_t bufDone(const void *opaque, bool isMetaData);
666f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    virtual int32_t processDataNotify(mm_camera_super_buf_t *bufs);
676f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    virtual int32_t start();
686f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    virtual int32_t stop();
696f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
706f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    static void dataNotifyCB(mm_camera_super_buf_t *recvd_frame, void *userdata);
716f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    static void *dataProcRoutine(void *data);
726f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    uint32_t getMyHandle() const {return mHandle;}
736f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    bool isTypeOf(cam_stream_type_t type);
74744f5403bebb0e27140d16a5df7a341713c24a13Nagesh Subba Reddy    bool isOrignalTypeOf(cam_stream_type_t type);
756f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t getFrameOffset(cam_frame_len_offset_t &offset);
766f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t getCropInfo(cam_rect_t &crop);
776f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t getFrameDimension(cam_dimension_t &dim);
786f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t getFormat(cam_format_t &fmt);
796f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCameraMemory *getStreamBufs() {return mStreamBufs;};
806f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    uint32_t getMyServerID();
816f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    cam_stream_type_t getMyType();
826f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
836f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t mapBuf(uint8_t buf_type, uint32_t buf_idx,
846f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                   int32_t plane_idx, int fd, uint32_t size);
856f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t unmapBuf(uint8_t buf_type, uint32_t buf_idx, int32_t plane_idx);
866f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t setParameter(cam_stream_parm_buffer_t &param);
876f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
886f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchevprivate:
896f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    uint32_t mCamHandle;
906f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    uint32_t mChannelHandle;
916f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    uint32_t mHandle; // stream handle from mm-camera-interface
926f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    mm_camera_ops_t *mCamOps;
936f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    cam_stream_info_t *mStreamInfo; // ptr to stream info buf
946f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    mm_camera_stream_mem_vtbl_t mMemVtbl;
956f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    uint8_t mNumBufs;
966f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    stream_cb_routine mDataCB;
976f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    void *mUserData;
986f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
996f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCameraQueue     mDataQ;
1006f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCameraCmdThread mProcTh; // thread for dataCB
1016f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1026f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCameraHeapMemory *mStreamInfoBuf;
1036f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCameraMemory *mStreamBufs;
1046f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    QCameraAllocator &mAllocator;
1056f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    mm_camera_buf_def_t *mBufDefs;
1066f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    cam_frame_len_offset_t mFrameLenOffset;
1076f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    cam_padding_info_t mPaddingInfo;
1086f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    cam_rect_t mCropInfo;
1096f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    pthread_mutex_t mCropLock; // lock to protect crop info
1106f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1116f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    static int32_t get_bufs(
1126f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                     cam_frame_len_offset_t *offset,
1136f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                     uint8_t *num_bufs,
1146f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                     uint8_t **initial_reg_flag,
1156f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                     mm_camera_buf_def_t **bufs,
1166f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                     mm_camera_map_unmap_ops_tbl_t *ops_tbl,
1176f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                     void *user_data);
1186f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    static int32_t put_bufs(
1196f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                     mm_camera_map_unmap_ops_tbl_t *ops_tbl,
1206f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                     void *user_data);
1216f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    static int32_t invalidate_buf(int index, void *user_data);
122a1724bc599bec5b2fbe3f4a34d0eca2406ba4c5fIvan Evlogiev    static int32_t clean_invalidate_buf(int index, void *user_data);
1236f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1246f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t getBufs(cam_frame_len_offset_t *offset,
1256f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                     uint8_t *num_bufs,
1266f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                     uint8_t **initial_reg_flag,
1276f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                     mm_camera_buf_def_t **bufs,
1286f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev                     mm_camera_map_unmap_ops_tbl_t *ops_tbl);
1296f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t putBufs(mm_camera_map_unmap_ops_tbl_t *ops_tbl);
1306f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev    int32_t invalidateBuf(int index);
131a1724bc599bec5b2fbe3f4a34d0eca2406ba4c5fIvan Evlogiev    int32_t cleanInvalidateBuf(int index);
1326f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1336f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev};
1346f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1356f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev}; // namespace qcamera
1366f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev
1376f83d735d8e3b918da42e6b559fcd0efb78133e5Iliyan Malchev#endif /* __QCAMERA_STREAM_H__ */
138