Home | History | Annotate | Download | only in HAL3
      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 __QCAMERA3_STREAM_H__
     31 #define __QCAMERA3_STREAM_H__
     32 
     33 // System dependencies
     34 #include <utils/Mutex.h>
     35 
     36 // Camera dependencies
     37 #include "QCamera3Mem.h"
     38 #include "QCamera3StreamMem.h"
     39 #include "QCameraCmdThread.h"
     40 #include "QCameraQueue.h"
     41 
     42 extern "C" {
     43 #include "mm_camera_interface.h"
     44 }
     45 
     46 namespace qcamera {
     47 
     48 class QCamera3Channel;
     49 class QCamera3Stream;
     50 
     51 typedef void (*hal3_stream_cb_routine)(mm_camera_super_buf_t *frame,
     52                                   QCamera3Stream *stream,
     53                                   void *userdata);
     54 
     55 class QCamera3Stream
     56 {
     57 public:
     58     QCamera3Stream(uint32_t camHandle,
     59                   uint32_t chId,
     60                   mm_camera_ops_t *camOps,
     61                   cam_padding_info_t *paddingInfo,
     62                   QCamera3Channel *channel);
     63     virtual ~QCamera3Stream();
     64     virtual int32_t init(cam_stream_type_t streamType,
     65                          cam_format_t streamFormat,
     66                          cam_dimension_t streamDim,
     67                          cam_rotation_t streamRotation,
     68                          cam_stream_reproc_config_t* reprocess_config,
     69                          uint8_t minStreamBufNum,
     70                          cam_feature_mask_t postprocess_mask,
     71                          cam_is_type_t is_type,
     72                          uint32_t batchSize,
     73                          hal3_stream_cb_routine stream_cb,
     74                          void *userdata);
     75     virtual int32_t bufDone(uint32_t index);
     76     virtual int32_t cancelBuffer(uint32_t index);
     77     virtual int32_t bufRelease(int32_t index);
     78     virtual int32_t processDataNotify(mm_camera_super_buf_t *bufs);
     79     virtual int32_t start();
     80     virtual int32_t stop();
     81     virtual int32_t queueBatchBuf();
     82 
     83     static void dataNotifyCB(mm_camera_super_buf_t *recvd_frame, void *userdata);
     84     static void *dataProcRoutine(void *data);
     85     uint32_t getMyHandle() const {return mHandle;}
     86     cam_stream_type_t getMyType() const;
     87     int32_t getFrameOffset(cam_frame_len_offset_t &offset);
     88     int32_t getFrameDimension(cam_dimension_t &dim);
     89     int32_t getFormat(cam_format_t &fmt);
     90     QCamera3StreamMem *getStreamBufs() {return mStreamBufs;};
     91     uint32_t getMyServerID();
     92 
     93     int32_t mapBuf(uint8_t buf_type, uint32_t buf_idx,
     94             int32_t plane_idx, int fd, void *buffer, size_t size);
     95     int32_t unmapBuf(uint8_t buf_type, uint32_t buf_idx, int32_t plane_idx);
     96     int32_t setParameter(cam_stream_parm_buffer_t &param);
     97     cam_stream_info_t* getStreamInfo() const {return mStreamInfo; };
     98 
     99     static void releaseFrameData(void *data, void *user_data);
    100     int32_t timeoutFrame(int32_t bufIdx);
    101 
    102 private:
    103     uint32_t mCamHandle;
    104     uint32_t mChannelHandle;
    105     uint32_t mHandle; // stream handle from mm-camera-interface
    106     mm_camera_ops_t *mCamOps;
    107     cam_stream_info_t *mStreamInfo; // ptr to stream info buf
    108     mm_camera_stream_mem_vtbl_t mMemVtbl;
    109     mm_camera_map_unmap_ops_tbl_t *mMemOps;
    110     uint8_t mNumBufs;
    111     hal3_stream_cb_routine mDataCB;
    112     void *mUserData;
    113 
    114     QCameraQueue     mDataQ;
    115 
    116     List<int32_t> mTimeoutFrameQ;
    117     Mutex mTimeoutFrameQLock;
    118 
    119     QCameraCmdThread mProcTh; // thread for dataCB
    120 
    121     QCamera3HeapMemory *mStreamInfoBuf;
    122     QCamera3StreamMem *mStreamBufs;
    123     mm_camera_buf_def_t *mBufDefs;
    124     cam_frame_len_offset_t mFrameLenOffset;
    125     cam_padding_info_t mPaddingInfo;
    126     QCamera3Channel *mChannel;
    127     Mutex mLock;    //Lock controlling access to 'mBufDefs'
    128 
    129     uint32_t mBatchSize; // 0: No batch, non-0: Number of imaage bufs in a batch
    130     uint8_t mNumBatchBufs; //Number of batch buffers which can hold image bufs
    131     QCamera3HeapMemory *mStreamBatchBufs; //Pointer to batch buffers memory
    132     mm_camera_buf_def_t *mBatchBufDefs; //Pointer to array of batch bufDefs
    133     mm_camera_buf_def_t *mCurrentBatchBufDef; //batch buffer in progress during
    134                                               //aggregation
    135     uint32_t    mBufsStaged; //Number of image buffers aggregated into
    136                              //currentBatchBufDef
    137     QCameraQueue mFreeBatchBufQ; //Buffer queue containing empty batch buffers
    138 
    139     static int32_t get_bufs(
    140                      cam_frame_len_offset_t *offset,
    141                      uint8_t *num_bufs,
    142                      uint8_t **initial_reg_flag,
    143                      mm_camera_buf_def_t **bufs,
    144                      mm_camera_map_unmap_ops_tbl_t *ops_tbl,
    145                      void *user_data);
    146     static int32_t put_bufs(
    147                      mm_camera_map_unmap_ops_tbl_t *ops_tbl,
    148                      void *user_data);
    149     static int32_t invalidate_buf(uint32_t index, void *user_data);
    150     static int32_t clean_invalidate_buf(uint32_t index, void *user_data);
    151     static int32_t clean_buf(uint32_t index, void *user_data);
    152 
    153     int32_t getBufs(cam_frame_len_offset_t *offset,
    154                      uint8_t *num_bufs,
    155                      uint8_t **initial_reg_flag,
    156                      mm_camera_buf_def_t **bufs,
    157                      mm_camera_map_unmap_ops_tbl_t *ops_tbl);
    158     int32_t putBufs(mm_camera_map_unmap_ops_tbl_t *ops_tbl);
    159     int32_t invalidateBuf(uint32_t index);
    160     int32_t cleanInvalidateBuf(uint32_t index);
    161     int32_t cleanBuf(uint32_t index);
    162     int32_t getBatchBufs(
    163             uint8_t *num_bufs, uint8_t **initial_reg_flag,
    164             mm_camera_buf_def_t **bufs,
    165             mm_camera_map_unmap_ops_tbl_t *ops_tbl);
    166     int32_t putBatchBufs(mm_camera_map_unmap_ops_tbl_t *ops_tbl);
    167     int32_t getBatchBufDef(mm_camera_buf_def_t& batchBufDef,
    168             int32_t index);
    169     int32_t aggregateBufToBatch(mm_camera_buf_def_t& bufDef);
    170     int32_t handleBatchBuffer(mm_camera_super_buf_t *superBuf);
    171 
    172     static const char* mStreamNames[CAM_STREAM_TYPE_MAX];
    173     void flushFreeBatchBufQ();
    174 };
    175 
    176 }; // namespace qcamera
    177 
    178 #endif /* __QCAMERA3_STREAM_H__ */
    179