1 /* Copyright (c) 2012, 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 __MM_QCAMERA_APP_H__ 31 #define __MM_QCAMERA_APP_H__ 32 33 #include <pthread.h> 34 #include <errno.h> 35 #include <sys/ioctl.h> 36 #include <sys/types.h> 37 #include <sys/stat.h> 38 #include <fcntl.h> 39 #include <poll.h> 40 41 #include "mm_camera_interface.h" 42 #include "mm_jpeg_interface.h" 43 44 #define MM_QCAMERA_APP_INTERATION 1 45 46 #define MM_APP_MAX_DUMP_FRAME_NUM 1000 47 48 #define PREVIEW_BUF_NUM 7 49 #define VIDEO_BUF_NUM 7 50 #define ISP_PIX_BUF_NUM 9 51 #define STATS_BUF_NUM 4 52 #define RDI_BUF_NUM 8 53 54 #define DEFAULT_PREVIEW_FORMAT CAM_FORMAT_YUV_420_NV21 55 #define DEFAULT_PREVIEW_WIDTH 800 56 #define DEFAULT_PREVIEW_HEIGHT 480 57 #define DEFAULT_PREVIEW_PADDING CAM_PAD_TO_WORD 58 #define DEFAULT_VIDEO_FORMAT CAM_FORMAT_YUV_420_NV12 59 #define DEFAULT_VIDEO_WIDTH 800 60 #define DEFAULT_VIDEO_HEIGHT 480 61 #define DEFAULT_VIDEO_PADDING CAM_PAD_TO_2K 62 #define DEFAULT_SNAPSHOT_FORMAT CAM_FORMAT_YUV_420_NV21 63 #define DEFAULT_SNAPSHOT_WIDTH 1280 64 #define DEFAULT_SNAPSHOT_HEIGHT 960 65 #define DEFAULT_SNAPSHOT_PADDING CAM_PAD_TO_WORD 66 67 #ifndef TRUE 68 #define TRUE 1 69 #endif 70 71 #ifndef FALSE 72 #define FALSE 0 73 #endif 74 75 typedef enum { 76 MM_CAMERA_OK, 77 MM_CAMERA_E_GENERAL, 78 MM_CAMERA_E_NO_MEMORY, 79 MM_CAMERA_E_NOT_SUPPORTED, 80 MM_CAMERA_E_INVALID_INPUT, 81 MM_CAMERA_E_INVALID_OPERATION, /* 5 */ 82 MM_CAMERA_E_ENCODE, 83 MM_CAMERA_E_BUFFER_REG, 84 MM_CAMERA_E_PMEM_ALLOC, 85 MM_CAMERA_E_CAPTURE_FAILED, 86 MM_CAMERA_E_CAPTURE_TIMEOUT, /* 10 */ 87 } mm_camera_status_type_t; 88 89 typedef enum { 90 MM_CHANNEL_TYPE_ZSL, /* preview, and snapshot main */ 91 MM_CHANNEL_TYPE_CAPTURE, /* snapshot main, and postview */ 92 MM_CHANNEL_TYPE_PREVIEW, /* preview only */ 93 MM_CHANNEL_TYPE_SNAPSHOT, /* snapshot main only */ 94 MM_CHANNEL_TYPE_VIDEO, /* video only */ 95 MM_CHANNEL_TYPE_RDI, /* rdi only */ 96 MM_CHANNEL_TYPE_MAX 97 } mm_camera_channel_type_t; 98 99 typedef struct { 100 int fd; 101 int main_ion_fd; 102 struct ion_handle * handle; 103 uint32_t size; 104 void * data; 105 } mm_camera_app_meminfo_t; 106 107 typedef struct { 108 mm_camera_buf_def_t buf; 109 mm_camera_app_meminfo_t mem_info; 110 } mm_camera_app_buf_t; 111 112 typedef struct { 113 uint32_t s_id; 114 mm_camera_stream_config_t s_config; 115 cam_frame_len_offset_t offset; 116 uint8_t num_of_bufs; 117 mm_camera_app_buf_t s_bufs[MM_CAMERA_MAX_NUM_FRAMES]; 118 mm_camera_app_buf_t s_info_buf; 119 } mm_camera_stream_t; 120 121 typedef struct { 122 uint32_t ch_id; 123 uint8_t num_streams; 124 mm_camera_stream_t streams[MAX_STREAM_NUM_IN_BUNDLE]; 125 } mm_camera_channel_t; 126 127 typedef struct { 128 mm_camera_vtbl_t *cam; 129 uint8_t num_channels; 130 mm_camera_channel_t channels[MM_CHANNEL_TYPE_MAX]; 131 mm_jpeg_ops_t jpeg_ops; 132 uint32_t jpeg_hdl; 133 mm_camera_app_buf_t cap_buf; 134 mm_camera_app_buf_t parm_buf; 135 136 uint32_t current_jpeg_sess_id; 137 mm_camera_super_buf_t* current_job_frames; 138 uint32_t current_job_id; 139 mm_camera_app_buf_t jpeg_buf; 140 } mm_camera_test_obj_t; 141 142 typedef struct { 143 void *ptr; 144 void* ptr_jpeg; 145 146 uint8_t (*get_num_of_cameras) (); 147 mm_camera_vtbl_t *(*mm_camera_open) (uint8_t camera_idx); 148 uint32_t (*jpeg_open) (mm_jpeg_ops_t *ops); 149 } hal_interface_lib_t; 150 151 typedef struct { 152 uint8_t num_cameras; 153 hal_interface_lib_t hal_lib; 154 } mm_camera_app_t; 155 156 typedef int (*mm_app_test_t) (mm_camera_app_t *cam_apps); 157 typedef struct { 158 mm_app_test_t f; 159 int r; 160 } mm_app_tc_t; 161 162 extern int mm_app_unit_test_entry(mm_camera_app_t *cam_app); 163 extern int mm_app_dual_test_entry(mm_camera_app_t *cam_app); 164 extern void mm_app_dump_frame(mm_camera_buf_def_t *frame, 165 char *name, 166 char *ext, 167 int frame_idx); 168 extern void mm_app_dump_jpeg_frame(const void * data, 169 uint32_t size, 170 char* name, 171 char* ext, 172 int index); 173 extern int mm_camera_app_timedwait(uint8_t seconds); 174 extern int mm_camera_app_wait(); 175 extern void mm_camera_app_done(); 176 extern int mm_app_alloc_bufs(mm_camera_app_buf_t* app_bufs, 177 cam_frame_len_offset_t *frame_offset_info, 178 uint8_t num_bufs, 179 uint8_t is_streambuf); 180 extern int mm_app_release_bufs(uint8_t num_bufs, 181 mm_camera_app_buf_t* app_bufs); 182 extern int mm_app_stream_initbuf(cam_frame_len_offset_t *frame_offset_info, 183 uint8_t *num_bufs, 184 uint8_t **initial_reg_flag, 185 mm_camera_buf_def_t **bufs, 186 mm_camera_map_unmap_ops_tbl_t *ops_tbl, 187 void *user_data); 188 extern int32_t mm_app_stream_deinitbuf(mm_camera_map_unmap_ops_tbl_t *ops_tbl, 189 void *user_data); 190 extern int mm_app_cache_ops(mm_camera_app_meminfo_t *mem_info, 191 unsigned int cmd); 192 extern int32_t mm_app_stream_clean_invalidate_buf(int index, void *user_data); 193 extern int32_t mm_app_stream_invalidate_buf(int index, void *user_data); 194 extern int mm_app_open(mm_camera_app_t *cam_app, 195 uint8_t cam_id, 196 mm_camera_test_obj_t *test_obj); 197 extern int mm_app_close(mm_camera_test_obj_t *test_obj); 198 extern mm_camera_channel_t * mm_app_add_channel( 199 mm_camera_test_obj_t *test_obj, 200 mm_camera_channel_type_t ch_type, 201 mm_camera_channel_attr_t *attr, 202 mm_camera_buf_notify_t channel_cb, 203 void *userdata); 204 extern int mm_app_del_channel(mm_camera_test_obj_t *test_obj, 205 mm_camera_channel_t *channel); 206 extern mm_camera_stream_t * mm_app_add_stream(mm_camera_test_obj_t *test_obj, 207 mm_camera_channel_t *channel); 208 extern int mm_app_del_stream(mm_camera_test_obj_t *test_obj, 209 mm_camera_channel_t *channel, 210 mm_camera_stream_t *stream); 211 extern int mm_app_config_stream(mm_camera_test_obj_t *test_obj, 212 mm_camera_channel_t *channel, 213 mm_camera_stream_t *stream, 214 mm_camera_stream_config_t *config); 215 extern int mm_app_start_channel(mm_camera_test_obj_t *test_obj, 216 mm_camera_channel_t *channel); 217 extern int mm_app_stop_channel(mm_camera_test_obj_t *test_obj, 218 mm_camera_channel_t *channel); 219 extern mm_camera_channel_t *mm_app_get_channel_by_type( 220 mm_camera_test_obj_t *test_obj, 221 mm_camera_channel_type_t ch_type); 222 223 extern int mm_app_start_preview(mm_camera_test_obj_t *test_obj); 224 extern int mm_app_stop_preview(mm_camera_test_obj_t *test_obj); 225 extern int mm_app_start_preview_zsl(mm_camera_test_obj_t *test_obj); 226 extern int mm_app_stop_preview_zsl(mm_camera_test_obj_t *test_obj); 227 extern mm_camera_channel_t * mm_app_add_preview_channel( 228 mm_camera_test_obj_t *test_obj); 229 extern int mm_app_stop_and_del_channel(mm_camera_test_obj_t *test_obj, 230 mm_camera_channel_t *channel); 231 extern mm_camera_channel_t * mm_app_add_snapshot_channel( 232 mm_camera_test_obj_t *test_obj); 233 extern mm_camera_stream_t * mm_app_add_snapshot_stream( 234 mm_camera_test_obj_t *test_obj, 235 mm_camera_channel_t *channel, 236 mm_camera_buf_notify_t stream_cb, 237 void *userdata, 238 uint8_t num_bufs, 239 uint8_t num_burst); 240 extern int mm_app_start_record_preview(mm_camera_test_obj_t *test_obj); 241 extern int mm_app_stop_record_preview(mm_camera_test_obj_t *test_obj); 242 extern int mm_app_start_record(mm_camera_test_obj_t *test_obj); 243 extern int mm_app_stop_record(mm_camera_test_obj_t *test_obj); 244 extern int mm_app_start_live_snapshot(mm_camera_test_obj_t *test_obj); 245 extern int mm_app_stop_live_snapshot(mm_camera_test_obj_t *test_obj); 246 extern int mm_app_start_capture(mm_camera_test_obj_t *test_obj, 247 uint8_t num_snapshots); 248 extern int mm_app_stop_capture(mm_camera_test_obj_t *test_obj); 249 extern int mm_app_start_rdi(mm_camera_test_obj_t *test_obj, uint8_t num_burst); 250 extern int mm_app_stop_rdi(mm_camera_test_obj_t *test_obj); 251 252 #endif /* __MM_QCAMERA_APP_H__ */ 253 254 255 256 257 258 259 260 261 262