mm_qcamera_video.c revision a1724bc599bec5b2fbe3f4a34d0eca2406ba4c5f
1/* 2Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. 3 4Redistribution and use in source and binary forms, with or without 5modification, are permitted provided that the following conditions are 6met: 7 * Redistributions of source code must retain the above copyright 8 notice, this list of conditions and the following disclaimer. 9 * Redistributions in binary form must reproduce the above 10 copyright notice, this list of conditions and the following 11 disclaimer in the documentation and/or other materials provided 12 with the distribution. 13 * Neither the name of The Linux Foundation nor the names of its 14 contributors may be used to endorse or promote products derived 15 from this software without specific prior written permission. 16 17THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 18WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 20ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 21BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28*/ 29 30#include "mm_qcamera_dbg.h" 31#include "mm_qcamera_app.h" 32 33static void mm_app_video_notify_cb(mm_camera_super_buf_t *bufs, 34 void *user_data) 35{ 36 char file_name[64]; 37 mm_camera_buf_def_t *frame = bufs->bufs[0]; 38 mm_camera_test_obj_t *pme = (mm_camera_test_obj_t *)user_data; 39 40 CDBG("%s: BEGIN - length=%d, frame idx = %d\n", 41 __func__, frame->frame_len, frame->frame_idx); 42 snprintf(file_name, sizeof(file_name), "V_C%d", pme->cam->camera_handle); 43 mm_app_dump_frame(frame, file_name, "yuv", frame->frame_idx); 44 45 if (MM_CAMERA_OK != pme->cam->ops->qbuf(bufs->camera_handle, 46 bufs->ch_id, 47 frame)) { 48 CDBG_ERROR("%s: Failed in Preview Qbuf\n", __func__); 49 } 50 mm_app_cache_ops((mm_camera_app_meminfo_t *)frame->mem_info, 51 ION_IOC_INV_CACHES); 52 53 CDBG("%s: END\n", __func__); 54} 55 56mm_camera_stream_t * mm_app_add_video_stream(mm_camera_test_obj_t *test_obj, 57 mm_camera_channel_t *channel, 58 mm_camera_buf_notify_t stream_cb, 59 void *userdata, 60 uint8_t num_bufs) 61{ 62 int rc = MM_CAMERA_OK; 63 mm_camera_stream_t *stream = NULL; 64 cam_capability_t *cam_cap = (cam_capability_t *)(test_obj->cap_buf.buf.buffer); 65 66 stream = mm_app_add_stream(test_obj, channel); 67 if (NULL == stream) { 68 CDBG_ERROR("%s: add stream failed\n", __func__); 69 return NULL; 70 } 71 72 stream->s_config.mem_vtbl.get_bufs = mm_app_stream_initbuf; 73 stream->s_config.mem_vtbl.put_bufs = mm_app_stream_deinitbuf; 74 stream->s_config.mem_vtbl.clean_invalidate_buf = 75 mm_app_stream_clean_invalidate_buf; 76 stream->s_config.mem_vtbl.user_data = (void *)stream; 77 stream->s_config.stream_cb = stream_cb; 78 stream->s_config.userdata = userdata; 79 stream->num_of_bufs = num_bufs; 80 81 stream->s_config.stream_info = (cam_stream_info_t *)stream->s_info_buf.buf.buffer; 82 memset(stream->s_config.stream_info, 0, sizeof(cam_stream_info_t)); 83 stream->s_config.stream_info->stream_type = CAM_STREAM_TYPE_VIDEO; 84 stream->s_config.stream_info->streaming_mode = CAM_STREAMING_MODE_CONTINUOUS; 85 stream->s_config.stream_info->fmt = DEFAULT_VIDEO_FORMAT; 86 stream->s_config.stream_info->dim.width = DEFAULT_VIDEO_WIDTH; 87 stream->s_config.stream_info->dim.height = DEFAULT_VIDEO_HEIGHT; 88 stream->s_config.padding_info = cam_cap->padding_info; 89 90 rc = mm_app_config_stream(test_obj, channel, stream, &stream->s_config); 91 if (MM_CAMERA_OK != rc) { 92 CDBG_ERROR("%s:config preview stream err=%d\n", __func__, rc); 93 return NULL; 94 } 95 96 return stream; 97} 98 99mm_camera_channel_t * mm_app_add_video_channel(mm_camera_test_obj_t *test_obj) 100{ 101 mm_camera_channel_t *channel = NULL; 102 mm_camera_stream_t *stream = NULL; 103 104 channel = mm_app_add_channel(test_obj, 105 MM_CHANNEL_TYPE_VIDEO, 106 NULL, 107 NULL, 108 NULL); 109 if (NULL == channel) { 110 CDBG_ERROR("%s: add channel failed", __func__); 111 return NULL; 112 } 113 114 stream = mm_app_add_video_stream(test_obj, 115 channel, 116 mm_app_video_notify_cb, 117 (void *)test_obj, 118 1); 119 if (NULL == stream) { 120 CDBG_ERROR("%s: add video stream failed\n", __func__); 121 mm_app_del_channel(test_obj, channel); 122 return NULL; 123 } 124 125 return channel; 126} 127 128int mm_app_start_record_preview(mm_camera_test_obj_t *test_obj) 129{ 130 int rc = MM_CAMERA_OK; 131 mm_camera_channel_t *p_ch = NULL; 132 mm_camera_channel_t *v_ch = NULL; 133 mm_camera_channel_t *s_ch = NULL; 134 135 p_ch = mm_app_add_preview_channel(test_obj); 136 if (NULL == p_ch) { 137 CDBG_ERROR("%s: add preview channel failed", __func__); 138 return -MM_CAMERA_E_GENERAL; 139 } 140 141 v_ch = mm_app_add_video_channel(test_obj); 142 if (NULL == v_ch) { 143 CDBG_ERROR("%s: add video channel failed", __func__); 144 mm_app_del_channel(test_obj, p_ch); 145 return -MM_CAMERA_E_GENERAL; 146 } 147 148 s_ch = mm_app_add_snapshot_channel(test_obj); 149 if (NULL == s_ch) { 150 CDBG_ERROR("%s: add snapshot channel failed", __func__); 151 mm_app_del_channel(test_obj, p_ch); 152 mm_app_del_channel(test_obj, v_ch); 153 return -MM_CAMERA_E_GENERAL; 154 } 155 156 rc = mm_app_start_channel(test_obj, p_ch); 157 if (MM_CAMERA_OK != rc) { 158 CDBG_ERROR("%s:start preview failed rc=%d\n", __func__, rc); 159 mm_app_del_channel(test_obj, p_ch); 160 mm_app_del_channel(test_obj, v_ch); 161 mm_app_del_channel(test_obj, s_ch); 162 return rc; 163 } 164 165 return rc; 166} 167 168int mm_app_stop_record_preview(mm_camera_test_obj_t *test_obj) 169{ 170 int rc = MM_CAMERA_OK; 171 mm_camera_channel_t *p_ch = NULL; 172 mm_camera_channel_t *v_ch = NULL; 173 mm_camera_channel_t *s_ch = NULL; 174 175 p_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_PREVIEW); 176 v_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_VIDEO); 177 s_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_SNAPSHOT); 178 179 rc = mm_app_stop_and_del_channel(test_obj, p_ch); 180 if (MM_CAMERA_OK != rc) { 181 CDBG_ERROR("%s:Stop Preview failed rc=%d\n", __func__, rc); 182 } 183 184 rc = mm_app_stop_and_del_channel(test_obj, v_ch); 185 if (MM_CAMERA_OK != rc) { 186 CDBG_ERROR("%s:Stop Preview failed rc=%d\n", __func__, rc); 187 } 188 189 rc = mm_app_stop_and_del_channel(test_obj, s_ch); 190 if (MM_CAMERA_OK != rc) { 191 CDBG_ERROR("%s:Stop Preview failed rc=%d\n", __func__, rc); 192 } 193 194 return rc; 195} 196 197int mm_app_start_record(mm_camera_test_obj_t *test_obj) 198{ 199 int rc = MM_CAMERA_OK; 200 mm_camera_channel_t *v_ch = NULL; 201 202 v_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_VIDEO); 203 204 rc = mm_app_start_channel(test_obj, v_ch); 205 if (MM_CAMERA_OK != rc) { 206 CDBG_ERROR("%s:start recording failed rc=%d\n", __func__, rc); 207 } 208 209 return rc; 210} 211 212int mm_app_stop_record(mm_camera_test_obj_t *test_obj) 213{ 214 int rc = MM_CAMERA_OK; 215 mm_camera_channel_t *v_ch = NULL; 216 217 v_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_VIDEO); 218 219 rc = mm_app_stop_channel(test_obj, v_ch); 220 if (MM_CAMERA_OK != rc) { 221 CDBG_ERROR("%s:stop recording failed rc=%d\n", __func__, rc); 222 } 223 224 return rc; 225} 226 227int mm_app_start_live_snapshot(mm_camera_test_obj_t *test_obj) 228{ 229 int rc = MM_CAMERA_OK; 230 mm_camera_channel_t *s_ch = NULL; 231 232 s_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_SNAPSHOT); 233 234 rc = mm_app_start_channel(test_obj, s_ch); 235 if (MM_CAMERA_OK != rc) { 236 CDBG_ERROR("%s:start recording failed rc=%d\n", __func__, rc); 237 } 238 239 return rc; 240} 241 242int mm_app_stop_live_snapshot(mm_camera_test_obj_t *test_obj) 243{ 244 int rc = MM_CAMERA_OK; 245 mm_camera_channel_t *s_ch = NULL; 246 247 s_ch = mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_SNAPSHOT); 248 249 rc = mm_app_stop_channel(test_obj, s_ch); 250 if (MM_CAMERA_OK != rc) { 251 CDBG_ERROR("%s:stop recording failed rc=%d\n", __func__, rc); 252 } 253 254 return rc; 255} 256