1 /*
2 Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
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
17 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include <pthread.h>
31 #include "mm_camera_dbg.h"
32 #include <errno.h>
33 #include <sys/ioctl.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <fcntl.h>
37 #include <poll.h>
38 #include <linux/msm_ion.h>
39 #include "mm_qcamera_app.h"
40
41 int mm_app_start_preview(int cam_id);
42 int mm_app_start_preview_zsl(int cam_id);
43 int mm_app_stop_preview_zsl(int cam_id);
44 int mm_app_stop_preview_stats(int cam_id);
45 int mm_app_start_preview_stats(int cam_id);
46
47 extern int mm_stream_alloc_bufs(mm_camera_app_obj_t *pme,
48 mm_camear_app_buf_t* app_bufs,
49 mm_camera_frame_len_offset *frame_offset_info,
50 uint8_t num_bufs);
51 extern int mm_stream_release_bufs(mm_camera_app_obj_t *pme,
52 mm_camear_app_buf_t* app_bufs);
53 extern int mm_app_unprepare_video(int cam_id);
54 extern int mm_stream_invalid_cache(mm_camera_app_obj_t *pme,
55 mm_camera_buf_def_t *frame);
56
57 /*===========================================================================
58 * FUNCTION - mm_camera_do_mmap_ion -
59 *
60 * DESCRIPTION:
61 *==========================================================================*/
mm_camera_do_mmap_ion(int ion_fd,struct ion_allocation_data * alloc,struct ion_fd_data * ion_info_fd,int * mapFd)62 uint8_t *mm_camera_do_mmap_ion(int ion_fd, struct ion_allocation_data *alloc,
63 struct ion_fd_data *ion_info_fd, int *mapFd)
64 {
65 void *ret; /* returned virtual address */
66 int rc = 0;
67 struct ion_handle_data handle_data;
68
69 /* to make it page size aligned */
70 alloc->len = (alloc->len + 4095) & (~4095);
71
72 rc = ioctl(ion_fd, ION_IOC_ALLOC, alloc);
73 if (rc < 0) {
74 CDBG_ERROR("ION allocation failed %s\n", strerror(errno));
75 goto ION_ALLOC_FAILED;
76 }
77
78 ion_info_fd->handle = alloc->handle;
79 rc = ioctl(ion_fd, ION_IOC_SHARE, ion_info_fd);
80 if (rc < 0) {
81 CDBG_ERROR("ION map failed %s\n", strerror(errno));
82 goto ION_MAP_FAILED;
83 }
84 *mapFd = ion_info_fd->fd;
85 ret = mmap(NULL,
86 alloc->len,
87 PROT_READ | PROT_WRITE,
88 MAP_SHARED,
89 *mapFd,
90 0);
91
92 if (ret == MAP_FAILED) {
93 CDBG_ERROR("ION_MMAP_FAILED: %s (%d)\n", strerror(errno), errno);
94 goto ION_MAP_FAILED;
95 }
96
97 return ret;
98
99 ION_MAP_FAILED:
100 handle_data.handle = ion_info_fd->handle;
101 ioctl(ion_fd, ION_IOC_FREE, &handle_data);
102 ION_ALLOC_FAILED:
103 return NULL;
104 }
105
106 /*===========================================================================
107 * FUNCTION - mm_camera_do_munmap_ion -
108 *
109 * DESCRIPTION:
110 *==========================================================================*/
mm_camera_do_munmap_ion(int ion_fd,struct ion_fd_data * ion_info_fd,void * addr,size_t size)111 int mm_camera_do_munmap_ion (int ion_fd, struct ion_fd_data *ion_info_fd,
112 void *addr, size_t size)
113 {
114 int rc = 0;
115 rc = munmap(addr, size);
116 close(ion_info_fd->fd);
117
118 struct ion_handle_data handle_data;
119 handle_data.handle = ion_info_fd->handle;
120 ioctl(ion_fd, ION_IOC_FREE, &handle_data);
121 return rc;
122 }
123
124
mm_app_set_preview_fmt(int cam_id,mm_camera_image_fmt_t * fmt)125 int mm_app_set_preview_fmt(int cam_id,mm_camera_image_fmt_t *fmt)
126 {
127 int rc = MM_CAMERA_OK;
128 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
129
130 fmt->meta_header = MM_CAMEAR_META_DATA_TYPE_DEF;
131 fmt->fmt = pme->dim.prev_format;
132 fmt->width = pme->dim.display_width;
133 fmt->height = pme->dim.display_height;
134 return rc;
135 }
136
mm_app_set_aec_stats_fmt(int cam_id,mm_camera_image_fmt_t * fmt)137 int mm_app_set_aec_stats_fmt(int cam_id,mm_camera_image_fmt_t *fmt)
138 {
139 int rc = MM_CAMERA_OK;
140 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
141
142 fmt->meta_header = MM_CAMEAR_META_DATA_TYPE_DEF;
143 fmt->fmt = CAMERA_SAEC;
144 fmt->width = 1060; //hard code for testing
145 fmt->height = 1;
146 return rc;
147 }
148
mm_app_set_awb_stats_fmt(int cam_id,mm_camera_image_fmt_t * fmt)149 int mm_app_set_awb_stats_fmt(int cam_id,mm_camera_image_fmt_t *fmt)
150 {
151 int rc = MM_CAMERA_OK;
152 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
153
154 fmt->meta_header = MM_CAMEAR_META_DATA_TYPE_DEF;
155 fmt->fmt = CAMERA_SAWB;
156 fmt->width = 1060; //hard code for testing
157 fmt->height = 1;
158 return rc;
159 }
160
mm_app_set_af_stats_fmt(int cam_id,mm_camera_image_fmt_t * fmt)161 int mm_app_set_af_stats_fmt(int cam_id,mm_camera_image_fmt_t *fmt)
162 {
163 int rc = MM_CAMERA_OK;
164 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
165
166 fmt->meta_header = MM_CAMEAR_META_DATA_TYPE_DEF;
167 fmt->fmt = CAMERA_SAFC;
168 fmt->width = 1060; //hard code for testing
169 fmt->height = 1;
170 return rc;
171 }
172
173
mm_app_set_ihist_stats_fmt(int cam_id,mm_camera_image_fmt_t * fmt)174 int mm_app_set_ihist_stats_fmt(int cam_id,mm_camera_image_fmt_t *fmt)
175 {
176 int rc = MM_CAMERA_OK;
177 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
178
179 fmt->meta_header = MM_CAMEAR_META_DATA_TYPE_DEF;
180 fmt->fmt = CAMERA_SHST;
181 fmt->width = 1060; //hard code for testing
182 fmt->height = 1;
183 return rc;
184 }
185
186 //void dumpFrameToFile(struct msm_frame* newFrame, int w, int h, char* name, int main_422)
dumpFrameToFile(mm_camera_buf_def_t * newFrame,int w,int h,char * name,int main_422,char * ext)187 void dumpFrameToFile(mm_camera_buf_def_t* newFrame, int w, int h, char* name, int main_422,char *ext)
188 {
189 char buf[50];
190 int file_fd;
191 int i;
192 if ( newFrame != NULL) {
193 char * str;
194 snprintf(buf, sizeof(buf), "/data/%s.%s", name, ext);
195 file_fd = open(buf, O_RDWR | O_CREAT, 0777);
196 if (file_fd < 0) {
197 CDBG_ERROR("%s: cannot open file %s \n", __func__, buf);
198 } else {
199 void* y_off = newFrame->buffer + newFrame->planes[0].data_offset;
200 void* cbcr_off = newFrame->buffer + newFrame->planes[0].length;
201
202 CDBG("%s: %s Y_off = %p cbcr_off = %p", __func__, name, y_off,cbcr_off);
203 CDBG("%s: Y_off length = %d cbcr_off length = %d", __func__, newFrame->planes[0].length,newFrame->planes[1].length);
204
205 write(file_fd, (const void *)(y_off), (w * h));
206 if (newFrame->num_planes > 1)
207 write(file_fd, (const void *)(cbcr_off), (w * h/2 * main_422));
208
209 close(file_fd);
210 CDBG("dump %s", buf);
211 }
212 }
213 }
214
mm_app_open_camera(int cam_id)215 int mm_app_open_camera(int cam_id)
216 {
217 int rc = MM_CAMERA_OK;
218 int value = 0;
219 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
220
221 if (pme->cam_mode == CAMERA_MODE) {
222 return rc;
223 }
224
225 if (MM_CAMERA_OK != (rc = mm_app_stop_preview(cam_id))) {
226 CDBG_ERROR("%s:Stop preview err=%d\n", __func__, rc);
227 goto end;
228 }
229
230 pme->cam->ops->set_parm(pme->cam->camera_handle,MM_CAMERA_PARM_RECORDING_HINT, &value);
231
232 if (MM_CAMERA_OK != (rc = mm_app_start_preview(cam_id))) {
233 CDBG_ERROR("%s:Start preview err=%d\n", __func__, rc);
234 goto end;
235 }
236
237 pme->cam_mode = CAMERA_MODE;
238 end:
239 CDBG("%s: END, rc=%d\n", __func__, rc);
240 return rc;
241 }
242
mm_app_open_camera_stats(int cam_id)243 int mm_app_open_camera_stats(int cam_id)
244 {
245 int rc = MM_CAMERA_OK;
246 int value = 0;
247 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
248
249 if (pme->cam_mode == CAMERA_MODE) {
250 return rc;
251 }
252
253 if (MM_CAMERA_OK != (rc = mm_app_stop_preview_stats(cam_id))) {
254 CDBG_ERROR("%s:Stop preview err=%d\n", __func__, rc);
255 goto end;
256 }
257
258 pme->cam->ops->set_parm(pme->cam->camera_handle,MM_CAMERA_PARM_RECORDING_HINT, &value);
259
260 if (MM_CAMERA_OK != (rc = mm_app_start_preview_stats(cam_id))) {
261 CDBG_ERROR("%s:Start preview err=%d\n", __func__, rc);
262 goto end;
263 }
264
265 pme->cam_mode = CAMERA_MODE;
266 end:
267 CDBG("%s: END, rc=%d\n", __func__, rc);
268 return rc;
269 }
270
mm_app_open_zsl(int cam_id)271 int mm_app_open_zsl(int cam_id)
272 {
273 int rc = MM_CAMERA_OK;
274 int value = 0;
275 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
276
277 if (pme->cam_mode == ZSL_MODE) {
278 return rc;
279 }
280
281 if (MM_CAMERA_OK != (rc = mm_app_stop_preview(cam_id))) {
282 CDBG_ERROR("%s:Stop preview err=%d\n", __func__, rc);
283 goto end;
284 }
285
286 pme->cam->ops->set_parm(pme->cam->camera_handle,MM_CAMERA_PARM_RECORDING_HINT, &value);
287
288 if (MM_CAMERA_OK != (rc = mm_app_start_preview_zsl(cam_id))) {
289 CDBG_ERROR("%s:stream on preview err=%d\n", __func__, rc);
290 goto end;
291 }
292 pme->cam_mode = ZSL_MODE;
293 end:
294 CDBG("%s: END, rc=%d\n", __func__, rc);
295 return rc;
296 }
297 #if 0
298 int mm_stream_deinit_preview_buf(uint32_t camera_handle,
299 uint32_t ch_id, uint32_t stream_id,
300 void *user_data, uint8_t num_bufs,
301 mm_camera_buf_def_t *bufs)
302 {
303 int i, rc = MM_CAMERA_OK;
304 mm_camera_app_obj_t *pme = (mm_camera_app_obj_t *)user_data;
305 for (i = 0; i < num_bufs; i++) {
306 rc = my_cam_app.hal_lib.mm_camera_do_munmap_ion (pme->ionfd, &(pme->preview_buf.frame[i].fd_data),
307 (void *)pme->preview_buf.frame[i].buffer, bufs[i].frame_len);
308 if (rc != MM_CAMERA_OK) {
309 CDBG("%s: mm_camera_do_munmap err, pmem_fd = %d, rc = %d",
310 __func__, bufs[i].fd, rc);
311 }
312 }
313 close(pme->ionfd);
314 return rc;
315 }
316
317 int mm_stream_init_preview_buf(uint32_t camera_handle,
318 uint32_t ch_id, uint32_t stream_id,
319 void *user_data,
320 mm_camera_frame_len_offset *frame_offset_info,
321 uint8_t num_bufs,
322 uint8_t *initial_reg_flag,
323 mm_camera_buf_def_t *bufs)
324 {
325 int i,j,num_planes, frame_len, y_off, cbcr_off;
326 uint32_t planes[VIDEO_MAX_PLANES];
327 uint32_t pmem_addr = 0;
328
329 mm_camera_app_obj_t *pme = (mm_camera_app_obj_t *)user_data;
330
331 num_planes = frame_offset_info->num_planes;
332 for ( i = 0; i < num_planes; i++) {
333 planes[i] = frame_offset_info->mp[i].len;
334 }
335
336 frame_len = frame_offset_info->frame_len;
337 y_off = frame_offset_info->mp[0].offset;
338 cbcr_off = frame_offset_info->mp[1].offset;
339
340 CDBG("Allocating Preview Memory for %d buffers frame_len = %d",num_bufs,frame_offset_info->frame_len);
341
342 for (i = 0; i < num_bufs ; i++) {
343 int j;
344 pme->preview_buf.reg[i] = 1;
345 initial_reg_flag[i] = 1;
346
347 pme->preview_buf.frame_len = frame_len;
348 pme->preview_buf.frame[i].ion_alloc.len = pme->preview_buf.frame_len;
349 pme->preview_buf.frame[i].ion_alloc.flags =
350 (0x1 << CAMERA_ION_HEAP_ID | 0x1 << ION_IOMMU_HEAP_ID);
351 pme->preview_buf.frame[i].ion_alloc.align = 4096;
352
353 pmem_addr = (unsigned long) my_cam_app.hal_lib.mm_camera_do_mmap_ion(pme->ionfd,
354 &(pme->preview_buf.frame[i].ion_alloc), &(pme->preview_buf.frame[i].fd_data),
355 &pme->preview_buf.frame[i].fd);
356
357 pme->preview_buf.frame[i].buffer = pmem_addr;
358 pme->preview_buf.frame[i].path = OUTPUT_TYPE_P;
359 pme->preview_buf.frame[i].y_off = 0;
360 pme->preview_buf.frame[i].cbcr_off = planes[0];
361 pme->preview_buf.frame[i].phy_offset = 0;
362
363 CDBG("Buffer allocated Successfully fd = %d",pme->preview_buf.frame[i].fd);
364
365 bufs[i].fd = pme->preview_buf.frame[i].fd;
366 //bufs[i].buffer = pmem_addr;
367 bufs[i].frame_len = pme->preview_buf.frame[i].ion_alloc.len;
368 bufs[i].num_planes = num_planes;
369
370 bufs[i].frame = &pme->preview_buf.frame[i];
371
372 /* Plane 0 needs to be set seperately. Set other planes
373 * in a loop. */
374 bufs[i].planes[0].length = planes[0];
375 bufs[i].planes[0].m.userptr = bufs[i].fd;
376 bufs[i].planes[0].data_offset = y_off;
377 bufs[i].planes[0].reserved[0] = 0;
378 //buf_def->buf.mp[i].frame_offset;
379 for (j = 1; j < num_planes; j++) {
380 bufs[i].planes[j].length = planes[j];
381 bufs[i].planes[j].m.userptr = bufs[i].fd;
382 bufs[i].planes[j].data_offset = cbcr_off;
383 bufs[i].planes[j].reserved[0] =
384 bufs[i].planes[j-1].reserved[0] +
385 bufs[i].planes[j-1].length;
386 }
387 }
388 return MM_CAMERA_OK;
389 }
390 #endif
391
mm_stream_initbuf(uint32_t camera_handle,uint32_t ch_id,uint32_t stream_id,void * user_data,mm_camera_frame_len_offset * frame_offset_info,uint8_t num_bufs,uint8_t * initial_reg_flag,mm_camera_buf_def_t * bufs)392 int mm_stream_initbuf(uint32_t camera_handle,
393 uint32_t ch_id, uint32_t stream_id,
394 void *user_data,
395 mm_camera_frame_len_offset *frame_offset_info,
396 uint8_t num_bufs,
397 uint8_t *initial_reg_flag,
398 mm_camera_buf_def_t *bufs)
399 {
400 mm_camera_app_obj_t *pme = (mm_camera_app_obj_t *)user_data;
401 mm_camear_app_buf_t* app_bufs = NULL;
402 int i, rc;
403
404 if (MM_CAMERA_MAX_NUM_FRAMES < num_bufs) {
405 CDBG_ERROR("%s: num_bufs (%d) exceeds max (%d)",
406 __func__, num_bufs, MM_CAMERA_MAX_NUM_FRAMES);
407 return -1;
408 }
409 for (i = 0; i < MM_QCAM_APP_MAX_STREAM_NUM; i++) {
410 if (pme->stream[i].id == stream_id) {
411 app_bufs = &pme->stream [i].app_bufs;
412 break;
413 }
414 }
415
416 if (app_bufs == NULL) {
417 CDBG_ERROR("%s: no matching stream for stream_id %d", __func__, stream_id);
418 return -1;
419 }
420
421 CDBG("%s: alloc buf for stream_id %d, len=%d",
422 __func__, stream_id, frame_offset_info->frame_len);
423 rc = mm_stream_alloc_bufs(pme,
424 app_bufs,
425 frame_offset_info,
426 num_bufs);
427
428 if (rc != 0) {
429 CDBG_ERROR("%s: mm_stream_alloc_bufs err = %d", __func__, rc);
430 return rc;
431 }
432
433 memcpy(bufs, app_bufs->bufs, sizeof(mm_camera_buf_def_t) * num_bufs);
434 for (i = 0; i < num_bufs ; i++) {
435 initial_reg_flag[i] = 1;
436 }
437
438 CDBG("%s: X",__func__);
439 return MM_CAMERA_OK;
440 }
441
442 #if 0
443 int mm_stream_initbuf_1(uint32_t camera_handle,
444 uint32_t ch_id, uint32_t stream_id,
445 void *user_data,
446 mm_camera_frame_len_offset *frame_offset_info,
447 uint8_t num_bufs,
448 uint8_t *initial_reg_flag,
449 mm_camera_buf_def_t *bufs)
450 {
451 int i;
452 int streamType = 0;
453
454 mm_camera_app_obj_t *pme = (mm_camera_app_obj_t *)user_data;
455
456 CDBG("%s : E ", __FUNCTION__);
457
458 for (i= 0; i < 5; i++) {
459 if (pme->stream[i].id == stream_id) {
460 CDBG("Allocate Memory for Stream %d",i);
461 streamType = i;
462 break;
463 }
464 }
465
466 streamType = MM_CAMERA_PREVIEW;
467 switch (streamType) {
468 case MM_CAMERA_PREVIEW:
469 mm_stream_init_preview_buf( camera_handle,
470 ch_id, stream_id,
471 user_data,
472 frame_offset_info,
473 num_bufs,
474 initial_reg_flag,
475 bufs);
476 break;
477 case MM_CAMERA_VIDEO:
478 mm_stream_init_video_buf( camera_handle,
479 ch_id, stream_id,
480 user_data,
481 frame_offset_info,
482 num_bufs,
483 initial_reg_flag,
484 bufs);
485 break;
486 case MM_CAMERA_SNAPSHOT_MAIN:
487 mm_stream_init_main_buf( camera_handle,
488 ch_id, stream_id,
489 user_data,
490 frame_offset_info,
491 num_bufs,
492 initial_reg_flag,
493 bufs);
494 break;
495 case MM_CAMERA_SNAPSHOT_THUMBNAIL:
496 mm_stream_init_thumbnail_buf( camera_handle,
497 ch_id, stream_id,
498 user_data,
499 frame_offset_info,
500 num_bufs,
501 initial_reg_flag,
502 bufs);
503 break;
504 default:
505 break;
506 }
507
508 CDBG(" %s : X ",__FUNCTION__);
509 return MM_CAMERA_OK;
510 }
511 #endif
mm_stream_deinitbuf(uint32_t camera_handle,uint32_t ch_id,uint32_t stream_id,void * user_data,uint8_t num_bufs,mm_camera_buf_def_t * bufs)512 int mm_stream_deinitbuf(uint32_t camera_handle,
513 uint32_t ch_id, uint32_t stream_id,
514 void *user_data, uint8_t num_bufs,
515 mm_camera_buf_def_t *bufs)
516 {
517 int i, rc = MM_CAMERA_OK;
518 mm_camera_app_obj_t *pme = (mm_camera_app_obj_t *)user_data;
519 mm_camear_app_buf_t* app_bufs = NULL;
520
521 for (i = 0; i < MM_QCAM_APP_MAX_STREAM_NUM; i++) {
522 if (pme->stream[i].id == stream_id) {
523 app_bufs = &pme->stream [i].app_bufs;
524 break;
525 }
526 }
527
528 if (app_bufs == NULL) {
529 CDBG_ERROR("%s: no matching stream for stream_id %d", __func__, stream_id);
530 return -1;
531 }
532
533 rc = mm_stream_release_bufs(pme, app_bufs);
534
535 if (rc != 0) {
536 CDBG_ERROR("%s: mm_stream_release_bufs err = %d", __func__, rc);
537 }
538
539 return rc;
540 }
541
542 #if 0
543 static int mm_stream_deinitbuf_1(uint32_t camera_handle,
544 uint32_t ch_id, uint32_t stream_id,
545 void *user_data, uint8_t num_bufs,
546 mm_camera_buf_def_t *bufs)
547 {
548 int i, rc = MM_CAMERA_OK;
549 int streamType = 0;
550 mm_camera_app_obj_t *pme = (mm_camera_app_obj_t *)user_data;
551 CDBG("%s: BEGIN",__func__);
552
553 for (i= 0; i < 5; i++) {
554 if (pme->stream[i].id == stream_id) {
555 CDBG("Allocate Memory for Stream %d",i);
556 streamType = i;
557 break;
558 }
559 }
560 streamType = MM_CAMERA_PREVIEW;
561 switch (streamType) {
562 case MM_CAMERA_PREVIEW:
563 mm_stream_deinit_preview_buf(camera_handle,
564 ch_id, stream_id,
565 user_data, num_bufs,
566 bufs);
567 break;
568 case MM_CAMERA_VIDEO:
569 mm_stream_deinit_video_buf(camera_handle,
570 ch_id, stream_id,
571 user_data, num_bufs,
572 bufs);
573 break;
574 case MM_CAMERA_SNAPSHOT_MAIN:
575 mm_stream_deinit_main_buf(camera_handle,
576 ch_id, stream_id,
577 user_data, num_bufs,
578 bufs);
579 break;
580 case MM_CAMERA_SNAPSHOT_THUMBNAIL:
581 mm_stream_deinit_thumbnail_buf(camera_handle,
582 ch_id, stream_id,
583 user_data, num_bufs,
584 bufs);
585 break;
586 default:
587 break;
588 }
589
590 /* zero out the buf stuct */
591 CDBG("%s: END",__func__);
592 return MM_CAMERA_OK;
593 }
594 #endif
595
preview_cb_signal(mm_camera_app_obj_t * pme)596 void preview_cb_signal(mm_camera_app_obj_t *pme)
597 {
598 if (pme->cam_state == CAMERA_STATE_PREVIEW && pme->cam_mode == CAMERA_MODE) {
599 mm_camera_app_done();
600 }
601 }
602
previewzsl_cb_signal(mm_camera_app_obj_t * pme)603 void previewzsl_cb_signal(mm_camera_app_obj_t *pme)
604 {
605 if (pme->cam_state == CAMERA_STATE_PREVIEW && pme->cam_mode == ZSL_MODE) {
606 mm_camera_app_done();
607 }
608 }
609
610
mm_app_preview_notify_cb(mm_camera_super_buf_t * bufs,void * user_data)611 void mm_app_preview_notify_cb(mm_camera_super_buf_t *bufs,
612 void *user_data)
613 {
614 int rc, cam = 0;
615 char buf[32];
616 mm_camera_buf_def_t *frame = NULL;
617 mm_camera_app_obj_t *pme = NULL;
618 CDBG("%s: BEGIN\n", __func__);
619 frame = bufs->bufs[MM_CAMERA_PREVIEW];
620 pme = (mm_camera_app_obj_t *)user_data;
621
622 CDBG("%s: BEGIN - length=%d, frame idx = %d\n", __func__, frame->frame_len, frame->frame_idx);
623
624 snprintf(buf, sizeof(buf), "P_%dx%d_C%d", pme->dim.display_width,
625 pme->dim.display_height, pme->cam->camera_info->camera_id);
626
627 dumpFrameToFile(frame, pme->dim.display_width,
628 pme->dim.display_height, buf, 1,"yuv");
629
630 if (!my_cam_app.run_sanity) {
631 if (0 != (rc = mm_app_dl_render(frame->fd, NULL))) {
632 CDBG("%s:DL rendering err=%d, frame fd=%d,frame idx = %d\n",
633 __func__, rc, frame->fd, frame->frame_idx);
634 }
635 }
636
637 CDBG("In CB function i/p = %p o/p = %p",bufs->bufs[MM_CAMERA_PREVIEW],frame);
638
639 if (MM_CAMERA_OK != pme->cam->ops->qbuf(pme->cam->camera_handle,pme->ch_id,frame)) {
640 CDBG_ERROR("%s: Failed in Preview Qbuf\n", __func__);
641 return;
642 }
643 mm_stream_invalid_cache(pme,frame);
644 if (my_cam_app.run_sanity) {
645 preview_cb_signal(pme);
646 }
647 CDBG("%s: END\n", __func__);
648
649 }
650
mm_app_aec_stats_notify_cb(mm_camera_super_buf_t * bufs,void * user_data)651 void mm_app_aec_stats_notify_cb(mm_camera_super_buf_t *bufs,
652 void *user_data)
653 {
654 int rc;
655 mm_camera_buf_def_t *frame = NULL;
656 mm_camera_app_obj_t *pme = NULL;
657 CDBG("%s: BEGIN\n", __func__);
658 frame = bufs->bufs[0];
659 pme = (mm_camera_app_obj_t *)user_data;
660
661 CDBG("%s: BEGIN - length=%d, frame idx = %d\n", __func__, frame->frame_len, frame->frame_idx);
662
663 CDBG("%s:DL rendering err=%d, frame fd=%d,frame idx = %d\n",
664 __func__, rc, frame->fd, frame->frame_idx);
665 CDBG("In CB function i/p = %p o/p = %p",bufs->bufs[MM_CAMERA_SAEC],frame);
666
667 if (MM_CAMERA_OK != pme->cam->ops->qbuf(pme->cam->camera_handle,pme->ch_id,frame)) {
668 CDBG_ERROR("%s: Failed in Preview Qbuf\n", __func__);
669 return;
670 }
671 mm_stream_invalid_cache(pme,frame);
672 CDBG("%s: END\n", __func__);
673 }
674
mm_app_awb_stats_notify_cb(mm_camera_super_buf_t * bufs,void * user_data)675 void mm_app_awb_stats_notify_cb(mm_camera_super_buf_t *bufs,
676 void *user_data)
677 {
678 int rc;
679 mm_camera_buf_def_t *frame = NULL;
680 mm_camera_app_obj_t *pme = NULL;
681 CDBG("%s: BEGIN\n", __func__);
682 frame = bufs->bufs[0];
683 pme = (mm_camera_app_obj_t *)user_data;
684
685 CDBG("%s: BEGIN - length=%d, frame idx = %d\n", __func__, frame->frame_len, frame->frame_idx);
686
687 CDBG("%s:DL rendering err=%d, frame fd=%d,frame idx = %d\n",
688 __func__, rc, frame->fd, frame->frame_idx);
689 CDBG("In CB function i/p = %p o/p = %p",bufs->bufs[MM_CAMERA_SAWB],frame);
690
691 if (MM_CAMERA_OK != pme->cam->ops->qbuf(pme->cam->camera_handle,pme->ch_id,frame)) {
692 CDBG_ERROR("%s: Failed in Preview Qbuf\n", __func__);
693 return;
694 }
695 mm_stream_invalid_cache(pme,frame);
696 CDBG("%s: END\n", __func__);
697 }
698
mm_app_af_stats_notify_cb(mm_camera_super_buf_t * bufs,void * user_data)699 void mm_app_af_stats_notify_cb(mm_camera_super_buf_t *bufs,
700 void *user_data)
701 {
702 int rc;
703 mm_camera_buf_def_t *frame = NULL;
704 mm_camera_app_obj_t *pme = NULL;
705 CDBG("%s: BEGIN\n", __func__);
706 frame = bufs->bufs[0] ;
707 pme = (mm_camera_app_obj_t *)user_data;
708
709 CDBG("%s: BEGIN - length=%d, frame idx = %d\n", __func__, frame->frame_len, frame->frame_idx);
710
711 CDBG("%s:DL rendering err=%d, frame fd=%d,frame idx = %d\n",
712 __func__, rc, frame->fd, frame->frame_idx);
713 CDBG("In CB function i/p = %p o/p = %p",bufs->bufs[MM_CAMERA_SAFC],frame);
714
715 if (MM_CAMERA_OK != pme->cam->ops->qbuf(pme->cam->camera_handle,pme->ch_id,frame)) {
716 CDBG_ERROR("%s: Failed in Preview Qbuf\n", __func__);
717 return;
718 }
719 mm_stream_invalid_cache(pme,frame);
720 CDBG("%s: END\n", __func__);
721 }
722
mm_app_ihist_stats_notify_cb(mm_camera_super_buf_t * bufs,void * user_data)723 void mm_app_ihist_stats_notify_cb(mm_camera_super_buf_t *bufs,
724 void *user_data)
725 {
726 int rc;
727 mm_camera_buf_def_t *frame = NULL;
728 mm_camera_app_obj_t *pme = NULL;
729 CDBG("%s: BEGIN\n", __func__);
730 frame = bufs->bufs[0] ;
731 pme = (mm_camera_app_obj_t *)user_data;
732
733 CDBG("%s: BEGIN - length=%d, frame idx = %d\n", __func__, frame->frame_len, frame->frame_idx);
734
735 CDBG("%s:DL rendering err=%d, frame fd=%d,frame idx = %d\n",
736 __func__, rc, frame->fd, frame->frame_idx);
737 CDBG("In CB function i/p = %p o/p = %p",bufs->bufs[MM_CAMERA_IHST],frame);
738
739 if (MM_CAMERA_OK != pme->cam->ops->qbuf(pme->cam->camera_handle,pme->ch_id,frame)) {
740 CDBG_ERROR("%s: Failed in Preview Qbuf\n", __func__);
741 return;
742 }
743 mm_stream_invalid_cache(pme,frame);
744 CDBG("%s: END\n", __func__);
745 }
746
mm_app_zsl_notify_cb(mm_camera_super_buf_t * bufs,void * user_data)747 static void mm_app_zsl_notify_cb(mm_camera_super_buf_t *bufs,
748 void *user_data)
749 {
750 int rc;
751 int i = 0;
752 mm_camera_buf_def_t *preview_frame = NULL;
753 mm_camera_buf_def_t *main_frame = NULL;
754 mm_camera_buf_def_t *thumb_frame = NULL;
755 mm_camera_app_obj_t *pme = NULL;
756 CDBG("%s: BEGIN\n", __func__);
757
758 pme = (mm_camera_app_obj_t *)user_data;
759
760 CDBG("%s : total streams = %d",__func__,bufs->num_bufs);
761 preview_frame = bufs->bufs[0] ;
762 main_frame = bufs->bufs[1];
763 thumb_frame = bufs->bufs[0];
764
765 //dumpFrameToFile(preview_frame->frame,pme->dim.display_width,pme->dim.display_height,"preview", 1);
766 dumpFrameToFile(preview_frame,pme->dim.display_width,pme->dim.display_height,"zsl_preview", 1,"yuv");
767 if (0 != (rc = mm_app_dl_render(preview_frame->fd, NULL))) {
768 CDBG("%s:DL rendering err=%d, frame fd=%d,frame idx = %d\n",
769 __func__, rc, preview_frame->fd, preview_frame->frame_idx);
770 }
771
772 if (bufs->num_bufs == 2 && main_frame != NULL) {
773 CDBG("mainframe frame_idx = %d fd = %d frame length = %d",main_frame->frame_idx,main_frame->fd,main_frame->frame_len);
774 CDBG("thumnail frame_idx = %d fd = %d frame length = %d",thumb_frame->frame_idx,thumb_frame->fd,thumb_frame->frame_len);
775
776 //dumpFrameToFile(main_frame->frame,pme->dim.picture_width,pme->dim.picture_height,"main", 1);
777 //dumpFrameToFile(thumb_frame->frame,pme->dim.thumbnail_width,pme->dim.thumbnail_height,"thumb", 1);
778
779 dumpFrameToFile(main_frame,pme->dim.picture_width,pme->dim.picture_height,"zsl_main", 1,"yuv");
780 dumpFrameToFile(thumb_frame,pme->dim.thumbnail_width,pme->dim.thumbnail_height,"zsl_thumb", 1,"yuv");
781
782 if (MM_CAMERA_OK != pme->cam->ops->qbuf(pme->cam->camera_handle,pme->ch_id,main_frame)) {
783 CDBG_ERROR("%s: Failed in thumbnail Qbuf\n", __func__);
784 }
785 mm_stream_invalid_cache(pme,main_frame);
786 }
787
788 if (MM_CAMERA_OK != pme->cam->ops->qbuf(pme->cam->camera_handle,pme->ch_id,preview_frame)) {
789 CDBG_ERROR("%s: Failed in Preview Qbuf\n", __func__);
790 }
791 mm_stream_invalid_cache(pme,preview_frame);
792 if (my_cam_app.run_sanity) {
793 previewzsl_cb_signal(pme);
794 }
795 CDBG("%s: END\n", __func__);
796 }
797
mm_app_prepare_stats(int cam_id)798 int mm_app_prepare_stats(int cam_id)
799 {
800 int rc = MM_CAMERA_OK;
801 int op_mode;
802
803 CDBG("%s: E",__func__);
804 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
805
806 pme->mem_cam->get_buf = mm_stream_initbuf;
807 pme->mem_cam->put_buf = mm_stream_deinitbuf;
808 pme->mem_cam->user_data = pme;
809 // AEC Stream
810 pme->stream[MM_CAMERA_SAEC].id =
811 pme->cam->ops->add_stream(pme->cam->camera_handle, pme->ch_id,
812 mm_app_aec_stats_notify_cb, pme,
813 MM_CAMERA_SAEC, 0);
814 if (!pme->stream[MM_CAMERA_SAEC].id) {
815 CDBG_ERROR("%s:Add MM_CAMERA_SAEC error =%d\n", __func__, rc);
816 rc = -1;
817 goto end;
818 }
819
820 CDBG_ERROR("%s :Add stream is successful stream ID = %d",__func__,pme->stream[MM_CAMERA_SAEC].id);
821
822 mm_app_set_aec_stats_fmt(cam_id,&pme->stream[MM_CAMERA_SAEC].str_config.fmt);
823 pme->stream[MM_CAMERA_SAEC].str_config.need_stream_on = 1;
824 pme->stream[MM_CAMERA_SAEC].str_config.num_of_bufs = STATS_BUF_NUM;
825
826 if (MM_CAMERA_OK != (rc = pme->cam->ops->config_stream(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_SAEC].id,
827 &pme->stream[MM_CAMERA_SAEC].str_config))) {
828 CDBG_ERROR("%s:preview streaming err=%d\n", __func__, rc);
829 goto end;
830 }
831 // AWB Stream
832 pme->stream[MM_CAMERA_SAWB].id =
833 pme->cam->ops->add_stream(pme->cam->camera_handle, pme->ch_id,
834 mm_app_awb_stats_notify_cb, pme,
835 MM_CAMERA_SAWB, 0);
836 if (!pme->stream[MM_CAMERA_SAWB].id) {
837 CDBG_ERROR("%s:Add MM_CAMERA_SAWB error =%d\n", __func__, rc);
838 rc = -1;
839 goto end;
840 }
841
842 CDBG_ERROR("%s :Add stream is successful stream ID = %d",__func__,pme->stream[MM_CAMERA_SAWB].id);
843
844 mm_app_set_awb_stats_fmt(cam_id,&pme->stream[MM_CAMERA_SAWB].str_config.fmt);
845 pme->stream[MM_CAMERA_SAWB].str_config.need_stream_on = 1;
846 pme->stream[MM_CAMERA_SAWB].str_config.num_of_bufs = STATS_BUF_NUM;
847
848 if (MM_CAMERA_OK != (rc = pme->cam->ops->config_stream(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_SAWB].id,
849 &pme->stream[MM_CAMERA_SAWB].str_config))) {
850 CDBG_ERROR("%s:preview streaming err=%d\n", __func__, rc);
851 goto end;
852 }
853
854 // AF Stream
855 pme->stream[MM_CAMERA_SAFC].id =
856 pme->cam->ops->add_stream(pme->cam->camera_handle, pme->ch_id,
857 mm_app_af_stats_notify_cb, pme,
858 MM_CAMERA_SAFC, 0);
859 if (!pme->stream[MM_CAMERA_SAFC].id) {
860 CDBG_ERROR("%s:Add MM_CAMERA_SAFC error =%d\n", __func__, rc);
861 rc = -1;
862 goto end;
863 }
864
865 CDBG_ERROR("%s :Add stream is successful stream ID = %d",__func__,pme->stream[MM_CAMERA_SAFC].id);
866
867 mm_app_set_af_stats_fmt(cam_id,&pme->stream[MM_CAMERA_SAFC].str_config.fmt);
868 pme->stream[MM_CAMERA_SAFC].str_config.need_stream_on = 1;
869 pme->stream[MM_CAMERA_SAFC].str_config.num_of_bufs = STATS_BUF_NUM;
870
871 if (MM_CAMERA_OK != (rc = pme->cam->ops->config_stream(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_SAFC].id,
872 &pme->stream[MM_CAMERA_SAFC].str_config))) {
873 CDBG_ERROR("%s:preview streaming err=%d\n", __func__, rc);
874 goto end;
875 }
876
877 // HIST Stream
878 pme->stream[MM_CAMERA_IHST].id =
879 pme->cam->ops->add_stream(pme->cam->camera_handle, pme->ch_id,
880 mm_app_ihist_stats_notify_cb, pme,
881 MM_CAMERA_IHST, 0);
882 if (!pme->stream[MM_CAMERA_IHST].id) {
883 CDBG_ERROR("%s:Add MM_CAMERA_IHST error =%d\n", __func__, rc);
884 rc = -1;
885 goto end;
886 }
887
888 CDBG_ERROR("%s :Add stream is successful stream ID = %d",__func__,pme->stream[MM_CAMERA_IHST].id);
889
890 mm_app_set_ihist_stats_fmt(cam_id,&pme->stream[MM_CAMERA_IHST].str_config.fmt);
891 pme->stream[MM_CAMERA_IHST].str_config.need_stream_on = 1;
892 pme->stream[MM_CAMERA_IHST].str_config.num_of_bufs = STATS_BUF_NUM;
893
894 if (MM_CAMERA_OK != (rc = pme->cam->ops->config_stream(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_IHST].id,
895 &pme->stream[MM_CAMERA_IHST].str_config))) {
896 CDBG_ERROR("%s:preview streaming err=%d\n", __func__, rc);
897 goto end;
898 }
899
900 end:
901 return rc;
902 }
903
mm_app_prepare_preview(int cam_id)904 int mm_app_prepare_preview(int cam_id)
905 {
906 int rc = MM_CAMERA_OK;
907 int op_mode;
908
909 CDBG("%s: E",__func__);
910 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
911
912 pme->mem_cam->get_buf = mm_stream_initbuf;
913 pme->mem_cam->put_buf = mm_stream_deinitbuf;
914 pme->mem_cam->user_data = pme;
915
916 op_mode = MM_CAMERA_OP_MODE_VIDEO;
917 if (MM_CAMERA_OK != (rc = pme->cam->ops->set_parm(
918 pme->cam->camera_handle,MM_CAMERA_PARM_OP_MODE, &op_mode))) {
919 CDBG_ERROR("%s: Set preview op mode error",__func__);
920 goto end;
921 }
922
923 pme->stream[MM_CAMERA_PREVIEW].id = pme->cam->ops->add_stream(pme->cam->camera_handle,pme->ch_id,
924 mm_app_preview_notify_cb,pme,
925 MM_CAMERA_PREVIEW, 0);
926
927 if (!pme->stream[MM_CAMERA_PREVIEW].id) {
928 CDBG_ERROR("%s:Add stream preview error =%d\n", __func__, rc);
929 rc = -1;
930 goto end;
931 }
932
933 CDBG("%s :Add stream is successfull stream ID = %d",__func__,pme->stream[MM_CAMERA_PREVIEW].id);
934
935 mm_app_set_preview_fmt(cam_id,&pme->stream[MM_CAMERA_PREVIEW].str_config.fmt);
936 pme->stream[MM_CAMERA_PREVIEW].str_config.need_stream_on = 1;
937 pme->stream[MM_CAMERA_PREVIEW].str_config.num_of_bufs = PREVIEW_BUF_NUM;
938
939 if (MM_CAMERA_OK != (rc = pme->cam->ops->config_stream(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_PREVIEW].id,
940 &pme->stream[MM_CAMERA_PREVIEW].str_config))) {
941 CDBG_ERROR("%s:preview streaming err=%d\n", __func__, rc);
942 goto end;
943 }
944 end:
945 return rc;
946 }
947
mm_app_unprepare_preview(int cam_id)948 int mm_app_unprepare_preview(int cam_id)
949 {
950 int rc = MM_CAMERA_OK;
951 return rc;
952 }
953
mm_app_streamon_stats(int cam_id)954 int mm_app_streamon_stats(int cam_id)
955 {
956 int rc = MM_CAMERA_OK;
957 uint32_t stream_aec[2], stream_af[2], stream_awb[2], stream_ihist[2];
958 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
959 mm_camera_frame_len_offset frame_offset_info;
960
961 stream_aec[0] = pme->stream[MM_CAMERA_SAEC].id;
962 stream_aec[1] = 0;
963
964 if (MM_CAMERA_OK != (rc = pme->cam->ops->start_streams(pme->cam->camera_handle,pme->ch_id,1,stream_aec))) {
965 CDBG_ERROR("%s : Start Stats Stream Error",__func__);
966 goto end;
967 }
968 stream_awb[0] = pme->stream[MM_CAMERA_SAWB].id;
969 stream_awb[1] = 0;
970
971 if (MM_CAMERA_OK != (rc = pme->cam->ops->start_streams(pme->cam->camera_handle,pme->ch_id,1,stream_awb))) {
972 CDBG_ERROR("%s : Start Stats Stream Error",__func__);
973 goto end;
974 }
975
976 stream_af[0] = pme->stream[MM_CAMERA_SAFC].id;
977 stream_af[1] = 0;
978
979 if (MM_CAMERA_OK != (rc = pme->cam->ops->start_streams(pme->cam->camera_handle,pme->ch_id,1,stream_af))) {
980 CDBG_ERROR("%s : Start Stats Stream Error",__func__);
981 goto end;
982 }
983
984 stream_ihist[0] = pme->stream[MM_CAMERA_IHST].id;
985 stream_ihist[1] = 0;
986
987 if (MM_CAMERA_OK != (rc = pme->cam->ops->start_streams(pme->cam->camera_handle,pme->ch_id,1,stream_ihist))) {
988 CDBG_ERROR("%s : Start Stats Stream Error",__func__);
989 goto end;
990 }
991
992 end:
993 CDBG("%s: X rc = %d",__func__,rc);
994 return rc;
995 }
996
997
mm_app_streamon_preview(int cam_id)998 int mm_app_streamon_preview(int cam_id)
999 {
1000 int rc = MM_CAMERA_OK;
1001 uint32_t stream;
1002 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
1003 mm_camera_frame_len_offset frame_offset_info;
1004
1005 stream = pme->stream[MM_CAMERA_PREVIEW].id;
1006
1007 pme->cam->ops->get_stream_parm(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_PREVIEW].id,MM_CAMERA_STREAM_OFFSET,&frame_offset_info);
1008 ALOGE("DEBUG : length = %d",frame_offset_info.frame_len);
1009 if (MM_CAMERA_OK != (rc = pme->cam->ops->start_streams(pme->cam->camera_handle,pme->ch_id,1,&stream))) {
1010 CDBG_ERROR("%s : Start Stream preview Error",__func__);
1011 goto end;
1012 }
1013 pme->cam_state = CAMERA_STATE_PREVIEW;
1014 end:
1015 CDBG("%s: X rc = %d",__func__,rc);
1016 return rc;
1017 }
1018
mm_app_prepare_preview_zsl(int cam_id)1019 int mm_app_prepare_preview_zsl(int cam_id)
1020 {
1021 int rc = MM_CAMERA_OK;
1022 mm_camera_bundle_attr_t attr;
1023 int stream[3];
1024
1025 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
1026 int op_mode = 0;
1027
1028 op_mode = MM_CAMERA_OP_MODE_ZSL;
1029 if (MM_CAMERA_OK != (rc = pme->cam->ops->set_parm(
1030 pme->cam->camera_handle,MM_CAMERA_PARM_OP_MODE, &op_mode))) {
1031 CDBG_ERROR("%s: Set preview op mode error",__func__);
1032 goto end;
1033 }
1034
1035 pme->stream[MM_CAMERA_PREVIEW].id = pme->cam->ops->add_stream(pme->cam->camera_handle,pme->ch_id,
1036 mm_app_preview_notify_cb,pme,
1037 MM_CAMERA_PREVIEW, 0);
1038
1039 if (!pme->stream[MM_CAMERA_PREVIEW].id) {
1040 CDBG_ERROR("%s:Add stream preview error =%d\n", __func__, rc);
1041 goto end;
1042 }
1043
1044 CDBG("%s :Add stream is successfull stream ID = %d",__func__,pme->stream[MM_CAMERA_PREVIEW].id);
1045
1046 mm_app_set_preview_fmt(cam_id,&pme->stream[MM_CAMERA_PREVIEW].str_config.fmt);
1047 pme->stream[MM_CAMERA_PREVIEW].str_config.need_stream_on = 1;
1048 pme->stream[MM_CAMERA_PREVIEW].str_config.num_of_bufs = PREVIEW_BUF_NUM;
1049
1050 if (MM_CAMERA_OK != (rc = pme->cam->ops->config_stream(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_PREVIEW].id,
1051 &pme->stream[MM_CAMERA_PREVIEW].str_config))) {
1052 CDBG_ERROR("%s:preview streaming err=%d\n", __func__, rc);
1053 goto end;
1054 }
1055
1056 pme->stream[MM_CAMERA_SNAPSHOT_MAIN].id = pme->cam->ops->add_stream(pme->cam->camera_handle,pme->ch_id,
1057 NULL,pme,
1058 MM_CAMERA_SNAPSHOT_MAIN, 0);
1059
1060 CDBG("Add Snapshot main is successfull stream ID = %d",pme->stream[MM_CAMERA_SNAPSHOT_MAIN].id);
1061 if (!pme->stream[MM_CAMERA_SNAPSHOT_MAIN].id) {
1062 CDBG_ERROR("%s:preview streaming err=%d\n", __func__, rc);
1063 rc = -1;
1064 goto end;
1065 }
1066
1067 pme->stream[MM_CAMERA_SNAPSHOT_MAIN].str_config.need_stream_on = 1;
1068 pme->stream[MM_CAMERA_SNAPSHOT_MAIN].str_config.num_of_bufs = 7;
1069
1070 mm_app_set_snapshot_fmt(cam_id,&pme->stream[MM_CAMERA_SNAPSHOT_MAIN].str_config.fmt);
1071
1072
1073 if (MM_CAMERA_OK != (rc = pme->cam->ops->config_stream(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_SNAPSHOT_MAIN].id,
1074 &pme->stream[MM_CAMERA_SNAPSHOT_MAIN].str_config))) {
1075 CDBG_ERROR("%s:preview streaming err=%d\n", __func__, rc);
1076 goto end;
1077 }
1078 end:
1079 CDBG("%s: END, rc=%d\n", __func__, rc);
1080 return rc;
1081 }
1082
mm_app_streamon_preview_zsl(int cam_id)1083 int mm_app_streamon_preview_zsl(int cam_id)
1084 {
1085 int rc = MM_CAMERA_OK;
1086 mm_camera_bundle_attr_t attr;
1087 uint32_t stream[2];
1088
1089 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
1090 int op_mode = 0;
1091
1092 stream[0] = pme->stream[MM_CAMERA_PREVIEW].id;
1093 stream[1] = pme->stream[MM_CAMERA_SNAPSHOT_MAIN].id;
1094
1095 attr.notify_mode = MM_CAMERA_SUPER_BUF_NOTIFY_BURST;
1096 attr.burst_num = 1;
1097 attr.look_back = 2;
1098 attr.post_frame_skip = 0;
1099 attr.water_mark = 2;
1100
1101 if (MM_CAMERA_OK != (rc = pme->cam->ops->init_stream_bundle(
1102 pme->cam->camera_handle,pme->ch_id,mm_app_zsl_notify_cb,pme,&attr,2,stream))) {
1103 CDBG_ERROR("%s:init_stream_bundle err=%d\n", __func__, rc);
1104 rc = -1;
1105 goto end;
1106 }
1107
1108 if (MM_CAMERA_OK != (rc = pme->cam->ops->start_streams(pme->cam->camera_handle,pme->ch_id,
1109 2, stream))) {
1110 CDBG_ERROR("%s:start_streams err=%d\n", __func__, rc);
1111 rc = -1;
1112 goto end;
1113 }
1114 pme->cam_state = CAMERA_STATE_PREVIEW;
1115 end:
1116 CDBG("%s: END, rc=%d\n", __func__, rc);
1117 return rc;
1118
1119 }
1120
initDisplay()1121 int initDisplay()
1122 {
1123 int rc = MM_CAMERA_OK;
1124
1125 use_overlay_fb_display_driver();
1126 if (launch_camframe_fb_thread()) {
1127 CDBG_ERROR("%s:launch_camframe_fb_thread failed!\n", __func__);
1128 //rc = -MM_CAMERA_E_GENERAL;
1129 }
1130 CDBG("%s: launch_camframe_fb_thread done\n", __func__);
1131 return rc;
1132 }
1133
deinitDisplay()1134 int deinitDisplay()
1135 {
1136 /* stop the display thread */
1137 release_camframe_fb_thread();
1138 return MM_CAMERA_OK;
1139 }
1140
mm_app_start_preview(int cam_id)1141 int mm_app_start_preview(int cam_id)
1142 {
1143 int rc = MM_CAMERA_OK;
1144
1145 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
1146 int op_mode = 0;
1147
1148 CDBG("pme = %p, pme->cam =%p, pme->cam->camera_handle = %d",
1149 pme,pme->cam,pme->cam->camera_handle);
1150
1151 if (pme->cam_state == CAMERA_STATE_PREVIEW) {
1152 return rc;
1153 }
1154
1155 if (!my_cam_app.run_sanity) {
1156 if (MM_CAMERA_OK != initDisplay()) {
1157 CDBG_ERROR("%s : Could not initalize display",__func__);
1158 goto end;
1159 }
1160 }
1161
1162 if (MM_CAMERA_OK != (rc = mm_app_prepare_preview(cam_id))) {
1163 CDBG_ERROR("%s:Stream On Preview failed rc=%d\n", __func__, rc);
1164 goto end;
1165 }
1166
1167 if (MM_CAMERA_OK != (rc = mm_app_streamon_preview(cam_id))) {
1168 CDBG_ERROR("%s:Stream On Preview failed rc=%d\n", __func__, rc);
1169 goto end;
1170 }
1171 end:
1172 CDBG("%s: END, rc=%d\n", __func__, rc);
1173 return rc;
1174 }
1175
mm_app_start_preview_stats(int cam_id)1176 int mm_app_start_preview_stats(int cam_id)
1177 {
1178 int rc = MM_CAMERA_OK;
1179
1180 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
1181 int op_mode = 0;
1182
1183 CDBG("pme = %p, pme->cam =%p, pme->cam->camera_handle = %d",
1184 pme,pme->cam,pme->cam->camera_handle);
1185
1186 if (pme->cam_state == CAMERA_STATE_PREVIEW) {
1187 return rc;
1188 }
1189
1190 if (!my_cam_app.run_sanity) {
1191 if (MM_CAMERA_OK != initDisplay()) {
1192 CDBG_ERROR("%s : Could not initalize display",__func__);
1193 goto end;
1194 }
1195 }
1196
1197 if (MM_CAMERA_OK != (rc = mm_app_prepare_stats(cam_id))) {
1198 CDBG_ERROR("%s:Prepare On Stats failed rc=%d\n", __func__, rc);
1199 goto end;
1200 }
1201
1202 if (MM_CAMERA_OK != (rc = mm_app_prepare_preview(cam_id))) {
1203 CDBG_ERROR("%s:Stream On Preview failed rc=%d\n", __func__, rc);
1204 goto end;
1205 }
1206
1207 if (MM_CAMERA_OK != (rc = mm_app_streamon_stats(cam_id))) {
1208 CDBG_ERROR("%s:Stream On Stats failed rc=%d\n", __func__, rc);
1209 goto end;
1210 }
1211
1212 if (MM_CAMERA_OK != (rc = mm_app_streamon_preview(cam_id))) {
1213 CDBG_ERROR("%s:Stream On Preview failed rc=%d\n", __func__, rc);
1214 goto end;
1215 }
1216 end:
1217 CDBG("%s: END, rc=%d\n", __func__, rc);
1218 return rc;
1219 }
1220
1221
mm_app_start_preview_zsl(int cam_id)1222 int mm_app_start_preview_zsl(int cam_id)
1223 {
1224 int rc = MM_CAMERA_OK;
1225
1226 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
1227
1228 CDBG("pme = %p, pme->cam =%p, pme->cam->camera_handle = %d",
1229 pme,pme->cam,pme->cam->camera_handle);
1230
1231 if (!my_cam_app.run_sanity) {
1232 if (MM_CAMERA_OK != initDisplay()) {
1233 CDBG_ERROR("%s : Could not initalize display",__func__);
1234 goto end;
1235 }
1236 }
1237
1238 pme->mem_cam->get_buf = mm_stream_initbuf;
1239 pme->mem_cam->put_buf = mm_stream_deinitbuf;
1240 pme->mem_cam->user_data = pme;
1241
1242 if (MM_CAMERA_OK != (rc = mm_app_prepare_preview_zsl(cam_id))) {
1243 CDBG_ERROR("%s:Prepare preview err=%d\n", __func__, rc);
1244 goto end;
1245 }
1246
1247 if (MM_CAMERA_OK != (rc = mm_app_streamon_preview_zsl(cam_id))) {
1248 CDBG_ERROR("%s:stream on preview err=%d\n", __func__, rc);
1249 goto end;
1250 }
1251
1252 /*if(MM_CAMERA_OK != (rc = mm_app_bundle_zsl_stream(cam_id))){
1253 CDBG_ERROR("%s: bundle and start of ZSl err=%d\n", __func__, rc);
1254 goto end;
1255 }*/
1256
1257 end:
1258 CDBG("%s: END, rc=%d\n", __func__, rc);
1259 return rc;
1260 }
1261
mm_app_streamoff_stats(int cam_id)1262 static int mm_app_streamoff_stats(int cam_id)
1263 {
1264 int rc = MM_CAMERA_OK;
1265 uint32_t stream_aec[2], stream_af[2],stream_awb[2], stream_ihist[2];
1266
1267 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
1268
1269 stream_aec[0] = pme->stream[MM_CAMERA_SAEC].id;
1270 stream_aec[1] = 0;
1271
1272 if (MM_CAMERA_OK != (rc = pme->cam->ops->stop_streams(pme->cam->camera_handle,pme->ch_id,1,stream_aec))) {
1273 CDBG_ERROR("%s : Stats Stream off Error",__func__);
1274 goto end;
1275 }
1276
1277 if (MM_CAMERA_OK != (rc = pme->cam->ops->del_stream(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_SAEC].id))) {
1278 CDBG_ERROR("%s : Delete Stats Stream error",__func__);
1279 goto end;
1280 }
1281 CDBG("AEC: del_stream successfull");
1282 stream_awb[0] = pme->stream[MM_CAMERA_SAWB].id;
1283 stream_awb[1] = 0;
1284
1285 if (MM_CAMERA_OK != (rc = pme->cam->ops->stop_streams(pme->cam->camera_handle,pme->ch_id,1,stream_awb))) {
1286 CDBG_ERROR("%s : Stats Stream off Error",__func__);
1287 goto end;
1288 }
1289
1290 if (MM_CAMERA_OK != (rc = pme->cam->ops->del_stream(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_SAWB].id))) {
1291 CDBG_ERROR("%s : Delete Stats Stream error",__func__);
1292 goto end;
1293 }
1294 CDBG("AWB: del_stream successfull");
1295
1296 stream_af[0] = pme->stream[MM_CAMERA_SAFC].id;
1297 stream_af[1] = 0;
1298
1299 if (MM_CAMERA_OK != (rc = pme->cam->ops->stop_streams(pme->cam->camera_handle,pme->ch_id,1, stream_af))) {
1300 CDBG_ERROR("%s : Stats Stream off Error",__func__);
1301 goto end;
1302 }
1303
1304 if (MM_CAMERA_OK != (rc = pme->cam->ops->del_stream(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_SAFC].id))) {
1305 CDBG_ERROR("%s : Delete Stats Stream error",__func__);
1306 goto end;
1307 }
1308 CDBG("AF: del_stream successfull");
1309
1310
1311 stream_ihist[0] = pme->stream[MM_CAMERA_IHST].id;
1312 stream_ihist[1] = 0;
1313
1314 if (MM_CAMERA_OK != (rc = pme->cam->ops->stop_streams(pme->cam->camera_handle,pme->ch_id,1,stream_ihist))) {
1315 CDBG_ERROR("%s : Stats Stream off Error",__func__);
1316 goto end;
1317 }
1318
1319 if (MM_CAMERA_OK != (rc = pme->cam->ops->del_stream(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_IHST].id))) {
1320 CDBG_ERROR("%s : Delete Stats Stream error",__func__);
1321 goto end;
1322 }
1323 CDBG("IHIST: del_stream successfull");
1324
1325 end:
1326 CDBG("%s: END, rc=%d\n", __func__, rc);
1327
1328 return rc;
1329 }
1330
mm_app_streamoff_preview(int cam_id)1331 static int mm_app_streamoff_preview(int cam_id)
1332 {
1333 int rc = MM_CAMERA_OK;
1334 uint32_t stream;
1335
1336 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
1337
1338 stream = pme->stream[MM_CAMERA_PREVIEW].id;
1339
1340 if (MM_CAMERA_OK != (rc = pme->cam->ops->stop_streams(pme->cam->camera_handle,pme->ch_id,1,&stream))) {
1341 CDBG_ERROR("%s : Preview Stream off Error",__func__);
1342 goto end;
1343 }
1344
1345 if (MM_CAMERA_OK != (rc = pme->cam->ops->del_stream(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_PREVIEW].id))) {
1346 CDBG_ERROR("%s : Delete Stream Preview error",__func__);
1347 goto end;
1348 }
1349 CDBG("del_stream successfull");
1350 pme->cam_state = CAMERA_STATE_OPEN;
1351 end:
1352 CDBG("%s: END, rc=%d\n", __func__, rc);
1353
1354 return rc;
1355 }
1356
mm_app_streamoff_preview_zsl(int cam_id)1357 static int mm_app_streamoff_preview_zsl(int cam_id)
1358 {
1359 int rc = MM_CAMERA_OK;
1360 uint32_t stream[2];
1361
1362 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
1363
1364 stream[0] = pme->stream[MM_CAMERA_PREVIEW].id;
1365 stream[1] = pme->stream[MM_CAMERA_SNAPSHOT_MAIN].id;
1366
1367 if (MM_CAMERA_OK != (rc = pme->cam->ops->stop_streams(pme->cam->camera_handle,pme->ch_id,2,stream))) {
1368 CDBG_ERROR("%s : Preview Stream off Error",__func__);
1369 goto end;
1370 }
1371
1372 if (MM_CAMERA_OK != (rc = pme->cam->ops->destroy_stream_bundle(pme->cam->camera_handle,pme->ch_id))) {
1373 CDBG_ERROR("%s : ZSL Snapshot destroy_stream_bundle Error",__func__);
1374 goto end;
1375 }
1376
1377 if (MM_CAMERA_OK != (rc = pme->cam->ops->del_stream(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_PREVIEW].id))) {
1378 CDBG_ERROR("%s : Delete Stream Preview error",__func__);
1379 goto end;
1380 }
1381
1382 if (MM_CAMERA_OK != (rc = pme->cam->ops->del_stream(pme->cam->camera_handle,pme->ch_id,pme->stream[MM_CAMERA_SNAPSHOT_MAIN].id))) {
1383 CDBG_ERROR("%s : Delete Stream Preview error",__func__);
1384 goto end;
1385 }
1386 CDBG("del_stream successfull");
1387 pme->cam_state = CAMERA_STATE_OPEN;
1388 end:
1389 CDBG("%s: END, rc=%d\n", __func__, rc);
1390
1391 return rc;
1392 }
1393
startPreview(int cam_id)1394 int startPreview(int cam_id)
1395 {
1396 int rc = MM_CAMERA_OK;
1397
1398 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
1399
1400 CDBG("%s: Start Preview",__func__);
1401
1402 if (pme->cam_mode == ZSL_MODE || pme->cam_mode == RECORDER_MODE) {
1403 switch (pme->cam_state) {
1404 case CAMERA_STATE_RECORD:
1405 if (MM_CAMERA_OK != mm_app_stop_video(cam_id)) {
1406 CDBG_ERROR("%s:Cannot stop video err=%d\n", __func__, rc);
1407 return -1;
1408 }
1409 case CAMERA_STATE_PREVIEW:
1410 if (MM_CAMERA_OK != mm_app_open_camera(cam_id)) {
1411 CDBG_ERROR("%s: Cannot switch to camera mode\n", __func__);
1412 return -1;
1413 }
1414 break;
1415 case CAMERA_STATE_SNAPSHOT:
1416 default:
1417 break;
1418 }
1419 } else if (pme->cam_mode == CAMERA_MODE && pme->cam_state == CAMERA_STATE_OPEN) {
1420
1421 if (MM_CAMERA_OK != (rc = mm_app_start_preview(cam_id))) {
1422 CDBG_ERROR("%s:preview streaming on err=%d\n", __func__, rc);
1423 return -1;
1424 }
1425 }
1426 CDBG("%s: END, rc=%d\n", __func__, rc);
1427 return rc;
1428 }
1429
stopPreview(int cam_id)1430 int stopPreview(int cam_id)
1431 {
1432 int rc = MM_CAMERA_OK;
1433 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
1434
1435 CDBG("%s : pme->cam_mode = %d, pme->cam_state = %d",__func__,pme->cam_mode,pme->cam_state);
1436
1437 if (pme->cam_mode == CAMERA_MODE && pme->cam_state == CAMERA_STATE_PREVIEW) {
1438 if (MM_CAMERA_OK != (rc = mm_app_stop_preview(cam_id))) {
1439 CDBG("%s:streamoff preview err=%d\n", __func__, rc);
1440 goto end;
1441 }
1442 } else if (pme->cam_mode == ZSL_MODE && pme->cam_state == CAMERA_STATE_PREVIEW) {
1443 if (MM_CAMERA_OK != (rc = mm_app_stop_preview_zsl(cam_id))) {
1444 CDBG("%s:streamoff preview err=%d\n", __func__, rc);
1445 goto end;
1446 }
1447 } else if (pme->cam_mode == RECORDER_MODE && pme->cam_state == CAMERA_STATE_PREVIEW) {
1448 if (MM_CAMERA_OK != (rc = mm_app_stop_preview(cam_id))) {
1449 CDBG("%s:streamoff preview err=%d\n", __func__, rc);
1450 goto end;
1451 }
1452 mm_app_unprepare_video(cam_id);
1453 }
1454 end:
1455 return rc;
1456 }
1457
startStats(int cam_id)1458 int startStats(int cam_id)
1459 {
1460 int rc = MM_CAMERA_OK;
1461
1462 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
1463
1464 CDBG("%s: Start Preview",__func__);
1465
1466 if (pme->cam_mode == ZSL_MODE || pme->cam_mode == RECORDER_MODE) {
1467 switch (pme->cam_state) {
1468 case CAMERA_STATE_RECORD:
1469 if (MM_CAMERA_OK != mm_app_stop_video(cam_id)) {
1470 CDBG_ERROR("%s:Cannot stop video err=%d\n", __func__, rc);
1471 return -1;
1472 }
1473 case CAMERA_STATE_PREVIEW:
1474 if (MM_CAMERA_OK != mm_app_open_camera_stats(cam_id)) {
1475 CDBG_ERROR("%s: Cannot switch to camera mode\n", __func__);
1476 return -1;
1477 }
1478 break;
1479 case CAMERA_STATE_SNAPSHOT:
1480 default:
1481 break;
1482 }
1483 } else if (pme->cam_mode == CAMERA_MODE && pme->cam_state == CAMERA_STATE_OPEN) {
1484
1485 if (MM_CAMERA_OK != (rc = mm_app_start_preview_stats(cam_id))) {
1486 CDBG_ERROR("%s:preview streaming on err=%d\n", __func__, rc);
1487 return -1;
1488 }
1489 }
1490 CDBG("%s: END, rc=%d\n", __func__, rc);
1491 return rc;
1492 }
1493
stopStats(int cam_id)1494 int stopStats(int cam_id)
1495 {
1496 int rc = MM_CAMERA_OK;
1497 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
1498
1499 CDBG("%s : pme->cam_mode = %d, pme->cam_state = %d",__func__,pme->cam_mode,pme->cam_state);
1500
1501 if (pme->cam_mode == CAMERA_MODE && pme->cam_state == CAMERA_STATE_PREVIEW) {
1502 if (MM_CAMERA_OK != (rc = mm_app_stop_preview_stats(cam_id))) {
1503 CDBG("%s:streamoff preview err=%d\n", __func__, rc);
1504 goto end;
1505 }
1506 } else if (pme->cam_mode == ZSL_MODE && pme->cam_state == CAMERA_STATE_PREVIEW) {
1507 if (MM_CAMERA_OK != (rc = mm_app_stop_preview_zsl(cam_id))) {
1508 CDBG("%s:streamoff preview err=%d\n", __func__, rc);
1509 goto end;
1510 }
1511 } else if (pme->cam_mode == RECORDER_MODE && pme->cam_state == CAMERA_STATE_PREVIEW) {
1512 if (MM_CAMERA_OK != (rc = mm_app_stop_preview_stats(cam_id))) {
1513 CDBG("%s:streamoff preview err=%d\n", __func__, rc);
1514 goto end;
1515 }
1516 mm_app_unprepare_video(cam_id);
1517 }
1518 end:
1519 return rc;
1520 }
1521
mm_app_stop_preview(int cam_id)1522 int mm_app_stop_preview(int cam_id)
1523 {
1524 int rc = MM_CAMERA_OK;
1525
1526 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
1527
1528 if (MM_CAMERA_OK != (rc = mm_app_streamoff_preview(cam_id))) {
1529 CDBG_ERROR("%s : Delete Stream Preview error",__func__);
1530 goto end;
1531 }
1532 CDBG("Stop Preview successfull");
1533
1534 if (!my_cam_app.run_sanity) {
1535 deinitDisplay();
1536 }
1537 end:
1538 CDBG("%s: END, rc=%d\n", __func__, rc);
1539 return rc;
1540 }
1541
mm_app_stop_preview_stats(int cam_id)1542 int mm_app_stop_preview_stats(int cam_id)
1543 {
1544 int rc = MM_CAMERA_OK;
1545
1546 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
1547
1548 if (MM_CAMERA_OK != (rc = mm_app_streamoff_stats(cam_id))) {
1549 CDBG_ERROR("%s : Delete Stream Stats error",__func__);
1550 goto end;
1551 }
1552 if (MM_CAMERA_OK != (rc = mm_app_streamoff_preview(cam_id))) {
1553 CDBG_ERROR("%s : Delete Stream Preview error",__func__);
1554 goto end;
1555 }
1556 CDBG("Stop Preview successfull");
1557
1558 if (!my_cam_app.run_sanity) {
1559 deinitDisplay();
1560 }
1561 end:
1562 CDBG("%s: END, rc=%d\n", __func__, rc);
1563 return rc;
1564 }
1565
mm_app_stop_preview_zsl(int cam_id)1566 int mm_app_stop_preview_zsl(int cam_id)
1567 {
1568 int rc = MM_CAMERA_OK;
1569
1570 mm_camera_app_obj_t *pme = mm_app_get_cam_obj(cam_id);
1571
1572 if (MM_CAMERA_OK != (rc = mm_app_streamoff_preview_zsl(cam_id))) {
1573 CDBG_ERROR("%s : Delete Stream Preview error",__func__);
1574 goto end;
1575 }
1576
1577 CDBG("Stop Preview successfull");
1578 if (!my_cam_app.run_sanity) {
1579 deinitDisplay();
1580 }
1581 end:
1582 CDBG("%s: END, rc=%d\n", __func__, rc);
1583 return rc;
1584 }
1585