1 /*
2 Copyright (c) 2012-2016, 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 // System dependencies
31 #include <assert.h>
32 #include <errno.h>
33 #include <fcntl.h>
34 #include <semaphore.h>
35 #include <stdio.h>
36 #include <sys/ioctl.h>
37 #include <sys/mman.h>
38 #define MMAN_H <SYSTEM_HEADER_PREFIX/mman.h>
39 #include MMAN_H
40 #include <unistd.h>
41
42 // Camera dependencies
43 #include "mm_qcamera_app.h"
44 #include "mm_qcamera_dbg.h"
45 #include "mm_qcamera_app.h"
46
mm_app_metadata_notify_cb(mm_camera_super_buf_t * bufs,void * user_data)47 static void mm_app_metadata_notify_cb(mm_camera_super_buf_t *bufs,
48 void *user_data)
49 {
50 uint32_t i = 0;
51 mm_camera_channel_t *channel = NULL;
52 mm_camera_stream_t *p_stream = NULL;
53 mm_camera_test_obj_t *pme = (mm_camera_test_obj_t *)user_data;
54 mm_camera_buf_def_t *frame;
55 metadata_buffer_t *pMetadata;
56
57 if (NULL == bufs || NULL == user_data) {
58 LOGE("bufs or user_data are not valid ");
59 return;
60 }
61 frame = bufs->bufs[0];
62
63 /* find channel */
64 for (i = 0; i < MM_CHANNEL_TYPE_MAX; i++) {
65 if (pme->channels[i].ch_id == bufs->ch_id) {
66 channel = &pme->channels[i];
67 break;
68 }
69 }
70
71 if (NULL == channel) {
72 LOGE("Channel object is NULL ");
73 return;
74 }
75
76 /* find preview stream */
77 for (i = 0; i < channel->num_streams; i++) {
78 if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_METADATA) {
79 p_stream = &channel->streams[i];
80 break;
81 }
82 }
83
84 if (NULL == p_stream) {
85 LOGE("cannot find metadata stream");
86 return;
87 }
88
89 /* find preview frame */
90 for (i = 0; i < bufs->num_bufs; i++) {
91 if (bufs->bufs[i]->stream_id == p_stream->s_id) {
92 frame = bufs->bufs[i];
93 break;
94 }
95 }
96
97 if (pme->metadata == NULL) {
98 /* The app will free the meta data, we don't need to bother here */
99 pme->metadata = malloc(sizeof(metadata_buffer_t));
100 if (NULL == pme->metadata) {
101 LOGE("Canot allocate metadata memory\n");
102 return;
103 }
104 }
105 memcpy(pme->metadata, frame->buffer, sizeof(metadata_buffer_t));
106
107 pMetadata = (metadata_buffer_t *)frame->buffer;
108 IF_META_AVAILABLE(uint32_t, afState, CAM_INTF_META_AF_STATE, pMetadata) {
109 if ((cam_af_state_t)(*afState) == CAM_AF_STATE_FOCUSED_LOCKED ||
110 (cam_af_state_t)(*afState) == CAM_AF_STATE_NOT_FOCUSED_LOCKED) {
111 LOGE("AutoFocus Done Call Back Received\n");
112 mm_camera_app_done();
113 } else if ((cam_af_state_t)(*afState) == CAM_AF_STATE_NOT_FOCUSED_LOCKED) {
114 LOGE("AutoFocus failed\n");
115 mm_camera_app_done();
116 }
117 }
118
119 if (pme->user_metadata_cb) {
120 LOGD("[DBG] %s, user defined own metadata cb. calling it...");
121 pme->user_metadata_cb(frame);
122 }
123
124 if (MM_CAMERA_OK != pme->cam->ops->qbuf(bufs->camera_handle,
125 bufs->ch_id,
126 frame)) {
127 LOGE("Failed in Preview Qbuf\n");
128 }
129 mm_app_cache_ops((mm_camera_app_meminfo_t *)frame->mem_info,
130 ION_IOC_INV_CACHES);
131 }
132
mm_app_snapshot_notify_cb(mm_camera_super_buf_t * bufs,void * user_data)133 static void mm_app_snapshot_notify_cb(mm_camera_super_buf_t *bufs,
134 void *user_data)
135 {
136
137 int rc = 0;
138 uint32_t i = 0;
139 mm_camera_test_obj_t *pme = (mm_camera_test_obj_t *)user_data;
140 mm_camera_channel_t *channel = NULL;
141 mm_camera_stream_t *p_stream = NULL;
142 mm_camera_stream_t *m_stream = NULL;
143 mm_camera_buf_def_t *p_frame = NULL;
144 mm_camera_buf_def_t *m_frame = NULL;
145
146 /* find channel */
147 for (i = 0; i < MM_CHANNEL_TYPE_MAX; i++) {
148 if (pme->channels[i].ch_id == bufs->ch_id) {
149 channel = &pme->channels[i];
150 break;
151 }
152 }
153 if (NULL == channel) {
154 LOGE("Wrong channel id (%d)", bufs->ch_id);
155 rc = -1;
156 goto error;
157 }
158
159 /* find snapshot stream */
160 for (i = 0; i < channel->num_streams; i++) {
161 if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_SNAPSHOT) {
162 m_stream = &channel->streams[i];
163 break;
164 }
165 }
166 if (NULL == m_stream) {
167 LOGE("cannot find snapshot stream");
168 rc = -1;
169 goto error;
170 }
171
172 /* find snapshot frame */
173 for (i = 0; i < bufs->num_bufs; i++) {
174 if (bufs->bufs[i]->stream_id == m_stream->s_id) {
175 m_frame = bufs->bufs[i];
176 break;
177 }
178 }
179 if (NULL == m_frame) {
180 LOGE("main frame is NULL");
181 rc = -1;
182 goto error;
183 }
184
185 mm_app_dump_frame(m_frame, "main", "yuv", m_frame->frame_idx);
186
187 /* find postview stream */
188 for (i = 0; i < channel->num_streams; i++) {
189 if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_POSTVIEW) {
190 p_stream = &channel->streams[i];
191 break;
192 }
193 }
194 if (NULL != p_stream) {
195 /* find preview frame */
196 for (i = 0; i < bufs->num_bufs; i++) {
197 if (bufs->bufs[i]->stream_id == p_stream->s_id) {
198 p_frame = bufs->bufs[i];
199 break;
200 }
201 }
202 if (NULL != p_frame) {
203 mm_app_dump_frame(p_frame, "postview", "yuv", p_frame->frame_idx);
204 }
205 }
206
207 mm_app_cache_ops((mm_camera_app_meminfo_t *)m_frame->mem_info,
208 ION_IOC_CLEAN_INV_CACHES);
209
210 pme->jpeg_buf.buf.buffer = (uint8_t *)malloc(m_frame->frame_len);
211 if ( NULL == pme->jpeg_buf.buf.buffer ) {
212 LOGE("error allocating jpeg output buffer");
213 goto error;
214 }
215
216 pme->jpeg_buf.buf.frame_len = m_frame->frame_len;
217 /* create a new jpeg encoding session */
218 rc = createEncodingSession(pme, m_stream, m_frame);
219 if (0 != rc) {
220 LOGE("error creating jpeg session");
221 free(pme->jpeg_buf.buf.buffer);
222 goto error;
223 }
224
225 /* start jpeg encoding job */
226 rc = encodeData(pme, bufs, m_stream);
227 if (0 != rc) {
228 LOGE("error creating jpeg session");
229 free(pme->jpeg_buf.buf.buffer);
230 goto error;
231 }
232
233 error:
234 /* buf done rcvd frames in error case */
235 if ( 0 != rc ) {
236 for (i=0; i<bufs->num_bufs; i++) {
237 if (MM_CAMERA_OK != pme->cam->ops->qbuf(bufs->camera_handle,
238 bufs->ch_id,
239 bufs->bufs[i])) {
240 LOGE("Failed in Qbuf\n");
241 }
242 mm_app_cache_ops((mm_camera_app_meminfo_t *)bufs->bufs[i]->mem_info,
243 ION_IOC_INV_CACHES);
244 }
245 }
246
247 LOGD(" END\n");
248 }
249
mm_app_preview_notify_cb(mm_camera_super_buf_t * bufs,void * user_data)250 static void mm_app_preview_notify_cb(mm_camera_super_buf_t *bufs,
251 void *user_data)
252 {
253 uint32_t i = 0;
254 mm_camera_channel_t *channel = NULL;
255 mm_camera_stream_t *p_stream = NULL;
256 mm_camera_buf_def_t *frame = NULL;
257 mm_camera_test_obj_t *pme = (mm_camera_test_obj_t *)user_data;
258
259 if (NULL == bufs || NULL == user_data) {
260 LOGE("bufs or user_data are not valid ");
261 return;
262 }
263
264 frame = bufs->bufs[0];
265
266 /* find channel */
267 for (i = 0; i < MM_CHANNEL_TYPE_MAX; i++) {
268 if (pme->channels[i].ch_id == bufs->ch_id) {
269 channel = &pme->channels[i];
270 break;
271 }
272 }
273 if (NULL == channel) {
274 LOGE("Channel object is NULL ");
275 return;
276 }
277 /* find preview stream */
278 for (i = 0; i < channel->num_streams; i++) {
279 if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_PREVIEW) {
280 p_stream = &channel->streams[i];
281 break;
282 }
283 }
284
285 if (NULL == p_stream) {
286 LOGE("cannot find preview stream");
287 return;
288 }
289
290 /* find preview frame */
291 for (i = 0; i < bufs->num_bufs; i++) {
292 if (bufs->bufs[i]->stream_id == p_stream->s_id) {
293 frame = bufs->bufs[i];
294 break;
295 }
296 }
297
298 if ( 0 < pme->fb_fd ) {
299 mm_app_overlay_display(pme, frame->fd);
300 }
301 #ifdef DUMP_PRV_IN_FILE
302 {
303 char file_name[64];
304 snprintf(file_name, sizeof(file_name), "P_C%d", pme->cam->camera_handle);
305 mm_app_dump_frame(frame, file_name, "yuv", frame->frame_idx);
306 }
307 #endif
308 if (pme->user_preview_cb) {
309 LOGE("[DBG] %s, user defined own preview cb. calling it...");
310 pme->user_preview_cb(frame);
311 }
312 if (MM_CAMERA_OK != pme->cam->ops->qbuf(bufs->camera_handle,
313 bufs->ch_id,
314 frame)) {
315 LOGE("Failed in Preview Qbuf\n");
316 }
317 mm_app_cache_ops((mm_camera_app_meminfo_t *)frame->mem_info,
318 ION_IOC_INV_CACHES);
319
320 LOGD(" END\n");
321 }
322
mm_app_zsl_notify_cb(mm_camera_super_buf_t * bufs,void * user_data)323 static void mm_app_zsl_notify_cb(mm_camera_super_buf_t *bufs,
324 void *user_data)
325 {
326 int rc = MM_CAMERA_OK;
327 uint32_t i = 0;
328 mm_camera_test_obj_t *pme = (mm_camera_test_obj_t *)user_data;
329 mm_camera_channel_t *channel = NULL;
330 mm_camera_stream_t *p_stream = NULL;
331 mm_camera_stream_t *m_stream = NULL;
332 mm_camera_stream_t *md_stream = NULL;
333 mm_camera_buf_def_t *p_frame = NULL;
334 mm_camera_buf_def_t *m_frame = NULL;
335 mm_camera_buf_def_t *md_frame = NULL;
336
337 LOGD(" BEGIN\n");
338
339 if (NULL == bufs || NULL == user_data) {
340 LOGE("bufs or user_data are not valid ");
341 return;
342 }
343
344 /* find channel */
345 for (i = 0; i < MM_CHANNEL_TYPE_MAX; i++) {
346 if (pme->channels[i].ch_id == bufs->ch_id) {
347 channel = &pme->channels[i];
348 break;
349 }
350 }
351 if (NULL == channel) {
352 LOGE("Wrong channel id (%d)", bufs->ch_id);
353 return;
354 }
355
356 /* find preview stream */
357 for (i = 0; i < channel->num_streams; i++) {
358 if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_PREVIEW) {
359 p_stream = &channel->streams[i];
360 break;
361 }
362 }
363 if (NULL == p_stream) {
364 LOGE("cannot find preview stream");
365 return;
366 }
367
368 /* find snapshot stream */
369 for (i = 0; i < channel->num_streams; i++) {
370 if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_SNAPSHOT) {
371 m_stream = &channel->streams[i];
372 break;
373 }
374 }
375 if (NULL == m_stream) {
376 LOGE("cannot find snapshot stream");
377 return;
378 }
379
380 /* find metadata stream */
381 for (i = 0; i < channel->num_streams; i++) {
382 if (channel->streams[i].s_config.stream_info->stream_type == CAM_STREAM_TYPE_METADATA) {
383 md_stream = &channel->streams[i];
384 break;
385 }
386 }
387 if (NULL == md_stream) {
388 LOGE("cannot find metadata stream");
389 }
390
391 /* find preview frame */
392 for (i = 0; i < bufs->num_bufs; i++) {
393 if (bufs->bufs[i]->stream_id == p_stream->s_id) {
394 p_frame = bufs->bufs[i];
395 break;
396 }
397 }
398
399 if(md_stream) {
400 /* find metadata frame */
401 for (i = 0; i < bufs->num_bufs; i++) {
402 if (bufs->bufs[i]->stream_id == md_stream->s_id) {
403 md_frame = bufs->bufs[i];
404 break;
405 }
406 }
407 if (!md_frame) {
408 LOGE("md_frame is null\n");
409 return;
410 }
411 if (!pme->metadata) {
412 /* App will free the metadata */
413 pme->metadata = malloc(sizeof(metadata_buffer_t));
414 if (!pme->metadata) {
415 ALOGE("not enough memory\n");
416 return;
417 }
418 }
419
420 memcpy(pme->metadata , md_frame->buffer, sizeof(metadata_buffer_t));
421 }
422 /* find snapshot frame */
423 for (i = 0; i < bufs->num_bufs; i++) {
424 if (bufs->bufs[i]->stream_id == m_stream->s_id) {
425 m_frame = bufs->bufs[i];
426 break;
427 }
428 }
429
430 if (!m_frame || !p_frame) {
431 LOGE("cannot find preview/snapshot frame");
432 return;
433 }
434
435 LOGD(" ZSL CB with fb_fd = %d, m_frame = %p, p_frame = %p \n",
436 pme->fb_fd,
437 m_frame,
438 p_frame);
439
440 if ( 0 < pme->fb_fd ) {
441 mm_app_overlay_display(pme, p_frame->fd);
442 }/* else {
443 mm_app_dump_frame(p_frame, "zsl_preview", "yuv", p_frame->frame_idx);
444 mm_app_dump_frame(m_frame, "zsl_main", "yuv", m_frame->frame_idx);
445 }*/
446
447 if ( pme->enable_reproc && ( NULL != pme->reproc_stream ) ) {
448
449 if (NULL != md_frame) {
450 rc = mm_app_do_reprocess(pme,
451 m_frame,
452 md_frame->buf_idx,
453 bufs,
454 md_stream);
455
456 if (MM_CAMERA_OK != rc ) {
457 LOGE("reprocess failed rc = %d", rc);
458 }
459 } else {
460 LOGE("md_frame is null\n");
461 }
462
463 return;
464 }
465
466 if ( pme->encodeJpeg ) {
467 pme->jpeg_buf.buf.buffer = (uint8_t *)malloc(m_frame->frame_len);
468 if ( NULL == pme->jpeg_buf.buf.buffer ) {
469 LOGE("error allocating jpeg output buffer");
470 goto exit;
471 }
472
473 pme->jpeg_buf.buf.frame_len = m_frame->frame_len;
474 /* create a new jpeg encoding session */
475 rc = createEncodingSession(pme, m_stream, m_frame);
476 if (0 != rc) {
477 LOGE("error creating jpeg session");
478 free(pme->jpeg_buf.buf.buffer);
479 goto exit;
480 }
481
482 /* start jpeg encoding job */
483 rc = encodeData(pme, bufs, m_stream);
484 pme->encodeJpeg = 0;
485 } else {
486 if (MM_CAMERA_OK != pme->cam->ops->qbuf(bufs->camera_handle,
487 bufs->ch_id,
488 m_frame)) {
489 LOGE("Failed in main Qbuf\n");
490 }
491 mm_app_cache_ops((mm_camera_app_meminfo_t *)m_frame->mem_info,
492 ION_IOC_INV_CACHES);
493 }
494
495 exit:
496
497 if (MM_CAMERA_OK != pme->cam->ops->qbuf(bufs->camera_handle,
498 bufs->ch_id,
499 p_frame)) {
500 LOGE("Failed in preview Qbuf\n");
501 }
502 mm_app_cache_ops((mm_camera_app_meminfo_t *)p_frame->mem_info,
503 ION_IOC_INV_CACHES);
504
505 if(md_frame) {
506 if (MM_CAMERA_OK != pme->cam->ops->qbuf(bufs->camera_handle,
507 bufs->ch_id,
508 md_frame)) {
509 LOGE("Failed in metadata Qbuf\n");
510 }
511 mm_app_cache_ops((mm_camera_app_meminfo_t *)md_frame->mem_info,
512 ION_IOC_INV_CACHES);
513 }
514
515 LOGD(" END\n");
516 }
517
mm_app_add_metadata_stream(mm_camera_test_obj_t * test_obj,mm_camera_channel_t * channel,mm_camera_buf_notify_t stream_cb,void * userdata,uint8_t num_bufs)518 mm_camera_stream_t * mm_app_add_metadata_stream(mm_camera_test_obj_t *test_obj,
519 mm_camera_channel_t *channel,
520 mm_camera_buf_notify_t stream_cb,
521 void *userdata,
522 uint8_t num_bufs)
523 {
524 int rc = MM_CAMERA_OK;
525 mm_camera_stream_t *stream = NULL;
526 cam_capability_t *cam_cap = (cam_capability_t *)(test_obj->cap_buf.buf.buffer);
527 stream = mm_app_add_stream(test_obj, channel);
528 if (NULL == stream) {
529 LOGE("add stream failed\n");
530 return NULL;
531 }
532
533 stream->s_config.mem_vtbl.get_bufs = mm_app_stream_initbuf;
534 stream->s_config.mem_vtbl.put_bufs = mm_app_stream_deinitbuf;
535 stream->s_config.mem_vtbl.clean_invalidate_buf =
536 mm_app_stream_clean_invalidate_buf;
537 stream->s_config.mem_vtbl.invalidate_buf = mm_app_stream_invalidate_buf;
538 stream->s_config.mem_vtbl.user_data = (void *)stream;
539 stream->s_config.stream_cb = stream_cb;
540 stream->s_config.stream_cb_sync = NULL;
541 stream->s_config.userdata = userdata;
542 stream->num_of_bufs = num_bufs;
543
544 stream->s_config.stream_info = (cam_stream_info_t *)stream->s_info_buf.buf.buffer;
545 memset(stream->s_config.stream_info, 0, sizeof(cam_stream_info_t));
546 stream->s_config.stream_info->stream_type = CAM_STREAM_TYPE_METADATA;
547 stream->s_config.stream_info->streaming_mode = CAM_STREAMING_MODE_CONTINUOUS;
548 stream->s_config.stream_info->fmt = DEFAULT_PREVIEW_FORMAT;
549 stream->s_config.stream_info->dim.width = sizeof(metadata_buffer_t);
550 stream->s_config.stream_info->dim.height = 1;
551 stream->s_config.padding_info = cam_cap->padding_info;
552
553 rc = mm_app_config_stream(test_obj, channel, stream, &stream->s_config);
554 if (MM_CAMERA_OK != rc) {
555 LOGE("config preview stream err=%d\n", rc);
556 return NULL;
557 }
558
559 return stream;
560 }
561
mm_app_get_analysis_stream_dim(const mm_camera_test_obj_t * test_obj,const cam_dimension_t * preview_dim)562 cam_dimension_t mm_app_get_analysis_stream_dim(
563 const mm_camera_test_obj_t *test_obj,
564 const cam_dimension_t* preview_dim)
565 {
566 cam_capability_t *cam_cap = (cam_capability_t *)(test_obj->cap_buf.buf.buffer);
567 cam_dimension_t max_analysis_dim =
568 cam_cap->analysis_info[CAM_ANALYSIS_INFO_FD_STILL].analysis_max_res;
569 cam_dimension_t analysis_dim = {0, 0};
570
571 if (preview_dim->width > max_analysis_dim.width ||
572 preview_dim->height > max_analysis_dim.height) {
573 double max_ratio, requested_ratio;
574
575 max_ratio = (double)max_analysis_dim.width / (double)max_analysis_dim.height;
576 requested_ratio = (double)preview_dim->width / (double)preview_dim->height;
577
578 if (max_ratio < requested_ratio) {
579 analysis_dim.width = analysis_dim.width;
580 analysis_dim.height = (int32_t)((double)analysis_dim.width / requested_ratio);
581 } else {
582 analysis_dim.height = analysis_dim.height;
583 analysis_dim.width = (int32_t)((double)analysis_dim.height * requested_ratio);
584 }
585 analysis_dim.width &= ~0x1;
586 analysis_dim.height &= ~0x1;
587 } else {
588 analysis_dim = *preview_dim;
589 }
590
591 LOGI("analysis stream dim (%d x %d)\n", analysis_dim.width, analysis_dim.height);
592 return analysis_dim;
593 }
594
mm_app_add_analysis_stream(mm_camera_test_obj_t * test_obj,mm_camera_channel_t * channel,mm_camera_buf_notify_t stream_cb,void * userdata,uint8_t num_bufs)595 mm_camera_stream_t * mm_app_add_analysis_stream(mm_camera_test_obj_t *test_obj,
596 mm_camera_channel_t *channel,
597 mm_camera_buf_notify_t stream_cb,
598 void *userdata,
599 uint8_t num_bufs)
600 {
601 int rc = MM_CAMERA_OK;
602 mm_camera_stream_t *stream = NULL;
603 cam_capability_t *cam_cap = (cam_capability_t *)(test_obj->cap_buf.buf.buffer);
604 cam_dimension_t preview_dim = {0, 0};
605 cam_dimension_t analysis_dim = {0, 0};
606
607
608 stream = mm_app_add_stream(test_obj, channel);
609 if (NULL == stream) {
610 LOGE("add stream failed\n");
611 return NULL;
612 }
613
614 if ((test_obj->preview_resolution.user_input_display_width == 0) ||
615 ( test_obj->preview_resolution.user_input_display_height == 0)) {
616 preview_dim.width = DEFAULT_PREVIEW_WIDTH;
617 preview_dim.height = DEFAULT_PREVIEW_HEIGHT;
618 } else {
619 preview_dim.width = test_obj->preview_resolution.user_input_display_width;
620 preview_dim.height = test_obj->preview_resolution.user_input_display_height;
621 }
622
623 analysis_dim = mm_app_get_analysis_stream_dim(test_obj, &preview_dim);
624 LOGI("analysis stream dimesion: %d x %d\n",
625 analysis_dim.width, analysis_dim.height);
626
627 stream->s_config.mem_vtbl.get_bufs = mm_app_stream_initbuf;
628 stream->s_config.mem_vtbl.put_bufs = mm_app_stream_deinitbuf;
629 stream->s_config.mem_vtbl.clean_invalidate_buf =
630 mm_app_stream_clean_invalidate_buf;
631 stream->s_config.mem_vtbl.invalidate_buf = mm_app_stream_invalidate_buf;
632 stream->s_config.mem_vtbl.user_data = (void *)stream;
633 stream->s_config.stream_cb = stream_cb;
634 stream->s_config.userdata = userdata;
635 stream->num_of_bufs = num_bufs;
636
637 stream->s_config.stream_info = (cam_stream_info_t *)stream->s_info_buf.buf.buffer;
638 memset(stream->s_config.stream_info, 0, sizeof(cam_stream_info_t));
639 stream->s_config.stream_info->stream_type = CAM_STREAM_TYPE_ANALYSIS;
640 stream->s_config.stream_info->streaming_mode = CAM_STREAMING_MODE_CONTINUOUS;
641 stream->s_config.stream_info->fmt = DEFAULT_PREVIEW_FORMAT;
642 stream->s_config.stream_info->dim = analysis_dim;
643 stream->s_config.padding_info =
644 cam_cap->analysis_info[CAM_ANALYSIS_INFO_FD_STILL].analysis_padding_info;
645
646 rc = mm_app_config_stream(test_obj, channel, stream, &stream->s_config);
647 if (MM_CAMERA_OK != rc) {
648 LOGE("config preview stream err=%d\n", rc);
649 return NULL;
650 }
651
652 return stream;
653 }
654
mm_app_add_preview_stream(mm_camera_test_obj_t * test_obj,mm_camera_channel_t * channel,mm_camera_buf_notify_t stream_cb,void * userdata,uint8_t num_bufs)655 mm_camera_stream_t * mm_app_add_preview_stream(mm_camera_test_obj_t *test_obj,
656 mm_camera_channel_t *channel,
657 mm_camera_buf_notify_t stream_cb,
658 void *userdata,
659 uint8_t num_bufs)
660 {
661 int rc = MM_CAMERA_OK;
662 mm_camera_stream_t *stream = NULL;
663 cam_capability_t *cam_cap = (cam_capability_t *)(test_obj->cap_buf.buf.buffer);
664 cam_dimension_t preview_dim = {0, 0};
665 cam_dimension_t analysis_dim = {0, 0};
666
667 if ((test_obj->preview_resolution.user_input_display_width == 0) ||
668 ( test_obj->preview_resolution.user_input_display_height == 0)) {
669 preview_dim.width = DEFAULT_PREVIEW_WIDTH;
670 preview_dim.height = DEFAULT_PREVIEW_HEIGHT;
671 } else {
672 preview_dim.width = test_obj->preview_resolution.user_input_display_width;
673 preview_dim.height = test_obj->preview_resolution.user_input_display_height;
674 }
675 LOGI("preview dimesion: %d x %d\n", preview_dim.width, preview_dim.height);
676
677 analysis_dim = mm_app_get_analysis_stream_dim(test_obj, &preview_dim);
678 LOGI("analysis stream dimesion: %d x %d\n",
679 analysis_dim.width, analysis_dim.height);
680
681 uint32_t analysis_pp_mask = cam_cap->qcom_supported_feature_mask &
682 (CAM_QCOM_FEATURE_SHARPNESS |
683 CAM_QCOM_FEATURE_EFFECT |
684 CAM_QCOM_FEATURE_DENOISE2D);
685 LOGI("analysis stream pp mask:%x\n", analysis_pp_mask);
686
687 cam_stream_size_info_t abc ;
688 memset (&abc , 0, sizeof (cam_stream_size_info_t));
689
690 abc.num_streams = 2;
691 abc.postprocess_mask[0] = 2178;
692 abc.stream_sizes[0].width = preview_dim.width;
693 abc.stream_sizes[0].height = preview_dim.height;
694 abc.type[0] = CAM_STREAM_TYPE_PREVIEW;
695
696 abc.postprocess_mask[1] = analysis_pp_mask;
697 abc.stream_sizes[1].width = analysis_dim.width;
698 abc.stream_sizes[1].height = analysis_dim.height;
699 abc.type[1] = CAM_STREAM_TYPE_ANALYSIS;
700
701 abc.buffer_info.min_buffers = 10;
702 abc.buffer_info.max_buffers = 10;
703 abc.is_type = IS_TYPE_NONE;
704
705 rc = setmetainfoCommand(test_obj, &abc);
706 if (rc != MM_CAMERA_OK) {
707 LOGE("meta info command failed\n");
708 }
709
710 stream = mm_app_add_stream(test_obj, channel);
711 if (NULL == stream) {
712 LOGE("add stream failed\n");
713 return NULL;
714 }
715 stream->s_config.mem_vtbl.get_bufs = mm_app_stream_initbuf;
716 stream->s_config.mem_vtbl.put_bufs = mm_app_stream_deinitbuf;
717 stream->s_config.mem_vtbl.clean_invalidate_buf =
718 mm_app_stream_clean_invalidate_buf;
719 stream->s_config.mem_vtbl.invalidate_buf = mm_app_stream_invalidate_buf;
720 stream->s_config.mem_vtbl.user_data = (void *)stream;
721 stream->s_config.stream_cb = stream_cb;
722 stream->s_config.stream_cb_sync = NULL;
723 stream->s_config.userdata = userdata;
724 stream->num_of_bufs = num_bufs;
725
726 stream->s_config.stream_info = (cam_stream_info_t *)stream->s_info_buf.buf.buffer;
727 memset(stream->s_config.stream_info, 0, sizeof(cam_stream_info_t));
728 stream->s_config.stream_info->stream_type = CAM_STREAM_TYPE_PREVIEW;
729 stream->s_config.stream_info->streaming_mode = CAM_STREAMING_MODE_CONTINUOUS;
730 stream->s_config.stream_info->fmt = DEFAULT_PREVIEW_FORMAT;
731
732 stream->s_config.stream_info->dim.width = preview_dim.width;
733 stream->s_config.stream_info->dim.height = preview_dim.height;
734
735 stream->s_config.padding_info = cam_cap->padding_info;
736
737 rc = mm_app_config_stream(test_obj, channel, stream, &stream->s_config);
738 if (MM_CAMERA_OK != rc) {
739 LOGE("config preview stream err=%d\n", rc);
740 return NULL;
741 }
742
743 return stream;
744 }
745
mm_app_add_raw_stream(mm_camera_test_obj_t * test_obj,mm_camera_channel_t * channel,mm_camera_buf_notify_t stream_cb,void * userdata,uint8_t num_bufs,uint8_t num_burst)746 mm_camera_stream_t * mm_app_add_raw_stream(mm_camera_test_obj_t *test_obj,
747 mm_camera_channel_t *channel,
748 mm_camera_buf_notify_t stream_cb,
749 void *userdata,
750 uint8_t num_bufs,
751 uint8_t num_burst)
752 {
753 int rc = MM_CAMERA_OK;
754 mm_camera_stream_t *stream = NULL;
755 cam_capability_t *cam_cap = (cam_capability_t *)(test_obj->cap_buf.buf.buffer);
756
757 cam_stream_size_info_t abc ;
758 memset (&abc , 0, sizeof (cam_stream_size_info_t));
759
760 abc.num_streams = 1;
761 abc.postprocess_mask[0] = 0;
762
763 if ( test_obj->buffer_width == 0 || test_obj->buffer_height == 0 ) {
764 abc.stream_sizes[0].width = DEFAULT_SNAPSHOT_WIDTH;
765 abc.stream_sizes[0].height = DEFAULT_SNAPSHOT_HEIGHT;
766 } else {
767 abc.stream_sizes[0].width = (int32_t)test_obj->buffer_width;
768 abc.stream_sizes[0].height = (int32_t)test_obj->buffer_height;
769 }
770 abc.type[0] = CAM_STREAM_TYPE_RAW;
771
772 abc.buffer_info.min_buffers = num_bufs;
773 abc.buffer_info.max_buffers = num_bufs;
774 abc.is_type = IS_TYPE_NONE;
775
776 rc = setmetainfoCommand(test_obj, &abc);
777 if (rc != MM_CAMERA_OK) {
778 LOGE("meta info command failed\n");
779 }
780
781 stream = mm_app_add_stream(test_obj, channel);
782 if (NULL == stream) {
783 LOGE("add stream failed\n");
784 return NULL;
785 }
786
787 stream->s_config.mem_vtbl.get_bufs = mm_app_stream_initbuf;
788 stream->s_config.mem_vtbl.put_bufs = mm_app_stream_deinitbuf;
789 stream->s_config.mem_vtbl.invalidate_buf = mm_app_stream_invalidate_buf;
790 stream->s_config.mem_vtbl.user_data = (void *)stream;
791 stream->s_config.stream_cb = stream_cb;
792 stream->s_config.stream_cb_sync = NULL;
793 stream->s_config.userdata = userdata;
794 stream->num_of_bufs = num_bufs;
795
796 stream->s_config.stream_info = (cam_stream_info_t *)stream->s_info_buf.buf.buffer;
797 memset(stream->s_config.stream_info, 0, sizeof(cam_stream_info_t));
798 stream->s_config.stream_info->stream_type = CAM_STREAM_TYPE_RAW;
799 if (num_burst == 0) {
800 stream->s_config.stream_info->streaming_mode = CAM_STREAMING_MODE_CONTINUOUS;
801 } else {
802 stream->s_config.stream_info->streaming_mode = CAM_STREAMING_MODE_BURST;
803 stream->s_config.stream_info->num_of_burst = num_burst;
804 }
805 stream->s_config.stream_info->fmt = test_obj->buffer_format;
806 if ( test_obj->buffer_width == 0 || test_obj->buffer_height == 0 ) {
807 stream->s_config.stream_info->dim.width = DEFAULT_SNAPSHOT_WIDTH;
808 stream->s_config.stream_info->dim.height = DEFAULT_SNAPSHOT_HEIGHT;
809 } else {
810 stream->s_config.stream_info->dim.width = (int32_t)test_obj->buffer_width;
811 stream->s_config.stream_info->dim.height = (int32_t)test_obj->buffer_height;
812 }
813 stream->s_config.padding_info = cam_cap->padding_info;
814
815 rc = mm_app_config_stream(test_obj, channel, stream, &stream->s_config);
816 if (MM_CAMERA_OK != rc) {
817 LOGE("config preview stream err=%d\n", rc);
818 return NULL;
819 }
820
821 return stream;
822 }
823
mm_app_add_snapshot_stream(mm_camera_test_obj_t * test_obj,mm_camera_channel_t * channel,mm_camera_buf_notify_t stream_cb,void * userdata,uint8_t num_bufs,uint8_t num_burst)824 mm_camera_stream_t * mm_app_add_snapshot_stream(mm_camera_test_obj_t *test_obj,
825 mm_camera_channel_t *channel,
826 mm_camera_buf_notify_t stream_cb,
827 void *userdata,
828 uint8_t num_bufs,
829 uint8_t num_burst)
830 {
831 int rc = MM_CAMERA_OK;
832 mm_camera_stream_t *stream = NULL;
833 cam_capability_t *cam_cap = (cam_capability_t *)(test_obj->cap_buf.buf.buffer);
834 cam_stream_size_info_t abc_snap ;
835 memset (&abc_snap , 0, sizeof (cam_stream_size_info_t));
836
837 abc_snap.num_streams = 2;
838 abc_snap.postprocess_mask[1] = 2178;
839 abc_snap.stream_sizes[1].width = DEFAULT_PREVIEW_WIDTH;
840 abc_snap.stream_sizes[1].height = DEFAULT_PREVIEW_HEIGHT;
841 abc_snap.type[1] = CAM_STREAM_TYPE_POSTVIEW;
842
843 abc_snap.postprocess_mask[0] = 0;
844 abc_snap.stream_sizes[0].width = DEFAULT_SNAPSHOT_WIDTH;
845 abc_snap.stream_sizes[0].height = DEFAULT_SNAPSHOT_HEIGHT;
846 abc_snap.type[0] = CAM_STREAM_TYPE_SNAPSHOT;
847
848 abc_snap.buffer_info.min_buffers = 7;
849 abc_snap.buffer_info.max_buffers = 7;
850 abc_snap.is_type = IS_TYPE_NONE;
851
852 rc = setmetainfoCommand(test_obj, &abc_snap);
853 if (rc != MM_CAMERA_OK) {
854 LOGE("meta info command snapshot failed\n");
855 }
856
857 stream = mm_app_add_stream(test_obj, channel);
858 if (NULL == stream) {
859 LOGE("add stream failed\n");
860 return NULL;
861 }
862
863 stream->s_config.mem_vtbl.get_bufs = mm_app_stream_initbuf;
864 stream->s_config.mem_vtbl.put_bufs = mm_app_stream_deinitbuf;
865 stream->s_config.mem_vtbl.clean_invalidate_buf =
866 mm_app_stream_clean_invalidate_buf;
867 stream->s_config.mem_vtbl.invalidate_buf = mm_app_stream_invalidate_buf;
868 stream->s_config.mem_vtbl.user_data = (void *)stream;
869 stream->s_config.stream_cb = stream_cb;
870 stream->s_config.stream_cb_sync = NULL;
871 stream->s_config.userdata = userdata;
872 stream->num_of_bufs = num_bufs;
873
874 stream->s_config.stream_info = (cam_stream_info_t *)stream->s_info_buf.buf.buffer;
875 memset(stream->s_config.stream_info, 0, sizeof(cam_stream_info_t));
876 stream->s_config.stream_info->stream_type = CAM_STREAM_TYPE_SNAPSHOT;
877 if (num_burst == 0) {
878 stream->s_config.stream_info->streaming_mode = CAM_STREAMING_MODE_CONTINUOUS;
879 } else {
880 stream->s_config.stream_info->streaming_mode = CAM_STREAMING_MODE_BURST;
881 stream->s_config.stream_info->num_of_burst = num_burst;
882 }
883 stream->s_config.stream_info->fmt = DEFAULT_SNAPSHOT_FORMAT;
884 if ( test_obj->buffer_width == 0 || test_obj->buffer_height == 0 ) {
885 stream->s_config.stream_info->dim.width = DEFAULT_SNAPSHOT_WIDTH;
886 stream->s_config.stream_info->dim.height = DEFAULT_SNAPSHOT_HEIGHT;
887 } else {
888 stream->s_config.stream_info->dim.width = DEFAULT_SNAPSHOT_WIDTH;
889 stream->s_config.stream_info->dim.height = DEFAULT_SNAPSHOT_HEIGHT;
890 }
891 stream->s_config.padding_info = cam_cap->padding_info;
892
893 rc = mm_app_config_stream(test_obj, channel, stream, &stream->s_config);
894 if (MM_CAMERA_OK != rc) {
895 LOGE("config preview stream err=%d\n", rc);
896 return NULL;
897 }
898
899 return stream;
900 }
901
mm_app_add_preview_channel(mm_camera_test_obj_t * test_obj)902 mm_camera_channel_t * mm_app_add_preview_channel(mm_camera_test_obj_t *test_obj)
903 {
904 mm_camera_channel_t *channel = NULL;
905 mm_camera_stream_t *stream = NULL;
906
907 channel = mm_app_add_channel(test_obj,
908 MM_CHANNEL_TYPE_PREVIEW,
909 NULL,
910 NULL,
911 NULL);
912 if (NULL == channel) {
913 LOGE("add channel failed");
914 return NULL;
915 }
916
917 stream = mm_app_add_preview_stream(test_obj,
918 channel,
919 mm_app_preview_notify_cb,
920 (void *)test_obj,
921 PREVIEW_BUF_NUM);
922 if (NULL == stream) {
923 LOGE("add stream failed\n");
924 mm_app_del_channel(test_obj, channel);
925 return NULL;
926 }
927
928 return channel;
929 }
930
mm_app_stop_and_del_channel(mm_camera_test_obj_t * test_obj,mm_camera_channel_t * channel)931 int mm_app_stop_and_del_channel(mm_camera_test_obj_t *test_obj,
932 mm_camera_channel_t *channel)
933 {
934 int rc = MM_CAMERA_OK;
935 mm_camera_stream_t *stream = NULL;
936 uint8_t i;
937 cam_stream_size_info_t abc ;
938 memset (&abc , 0, sizeof (cam_stream_size_info_t));
939
940 rc = mm_app_stop_channel(test_obj, channel);
941 if (MM_CAMERA_OK != rc) {
942 LOGE("Stop Preview failed rc=%d\n", rc);
943 }
944
945 if (channel->num_streams <= MAX_STREAM_NUM_IN_BUNDLE) {
946 for (i = 0; i < channel->num_streams; i++) {
947 stream = &channel->streams[i];
948 rc = mm_app_del_stream(test_obj, channel, stream);
949 if (MM_CAMERA_OK != rc) {
950 LOGE("del stream(%d) failed rc=%d\n", i, rc);
951 }
952 }
953 } else {
954 LOGE("num_streams = %d. Should not be more than %d\n",
955 channel->num_streams, MAX_STREAM_NUM_IN_BUNDLE);
956 }
957
958 rc = setmetainfoCommand(test_obj, &abc);
959 if (rc != MM_CAMERA_OK) {
960 LOGE("meta info command failed\n");
961 }
962
963 rc = mm_app_del_channel(test_obj, channel);
964 if (MM_CAMERA_OK != rc) {
965 LOGE("delete channel failed rc=%d\n", rc);
966 }
967
968 return rc;
969 }
970
mm_app_start_preview(mm_camera_test_obj_t * test_obj)971 int mm_app_start_preview(mm_camera_test_obj_t *test_obj)
972 {
973 int rc = MM_CAMERA_OK;
974 mm_camera_channel_t *channel = NULL;
975 mm_camera_stream_t *stream = NULL;
976 mm_camera_stream_t *s_metadata = NULL;
977 mm_camera_stream_t *s_analysis = NULL;
978 uint8_t i;
979
980 channel = mm_app_add_preview_channel(test_obj);
981 if (NULL == channel) {
982 LOGE("add channel failed");
983 return -MM_CAMERA_E_GENERAL;
984 }
985
986 s_metadata = mm_app_add_metadata_stream(test_obj,
987 channel,
988 mm_app_metadata_notify_cb,
989 (void *)test_obj,
990 PREVIEW_BUF_NUM);
991 if (NULL == s_metadata) {
992 LOGE("add metadata stream failed\n");
993 mm_app_del_channel(test_obj, channel);
994 return rc;
995 }
996
997 s_analysis = mm_app_add_analysis_stream(test_obj,
998 channel,
999 NULL,
1000 (void *)test_obj,
1001 PREVIEW_BUF_NUM);
1002 if (NULL == s_analysis) {
1003 LOGE("add metadata stream failed\n");
1004 mm_app_del_channel(test_obj, channel);
1005 return rc;
1006 }
1007
1008 rc = mm_app_start_channel(test_obj, channel);
1009 if (MM_CAMERA_OK != rc) {
1010 LOGE("start preview failed rc=%d\n", rc);
1011 if (channel->num_streams <= MAX_STREAM_NUM_IN_BUNDLE) {
1012 for (i = 0; i < channel->num_streams; i++) {
1013 stream = &channel->streams[i];
1014 mm_app_del_stream(test_obj, channel, stream);
1015 }
1016 }
1017 mm_app_del_channel(test_obj, channel);
1018 return rc;
1019 }
1020
1021 return rc;
1022 }
1023
mm_app_stop_preview(mm_camera_test_obj_t * test_obj)1024 int mm_app_stop_preview(mm_camera_test_obj_t *test_obj)
1025 {
1026 int rc = MM_CAMERA_OK;
1027 mm_camera_channel_t *channel =
1028 mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_PREVIEW);
1029
1030 rc = mm_app_stop_and_del_channel(test_obj, channel);
1031 if (MM_CAMERA_OK != rc) {
1032 LOGE("Stop Preview failed rc=%d\n", rc);
1033 }
1034
1035 return rc;
1036 }
1037
mm_app_start_preview_zsl(mm_camera_test_obj_t * test_obj)1038 int mm_app_start_preview_zsl(mm_camera_test_obj_t *test_obj)
1039 {
1040 int32_t rc = MM_CAMERA_OK;
1041 mm_camera_channel_t *channel = NULL;
1042 mm_camera_stream_t *s_preview = NULL;
1043 mm_camera_stream_t *s_metadata = NULL;
1044 mm_camera_stream_t *s_main = NULL;
1045 mm_camera_channel_attr_t attr;
1046 memset(&attr, 0, sizeof(mm_camera_channel_attr_t));
1047 attr.notify_mode = MM_CAMERA_SUPER_BUF_NOTIFY_CONTINUOUS;
1048 attr.look_back = 2;
1049 attr.post_frame_skip = 0;
1050 attr.water_mark = 2;
1051 attr.max_unmatched_frames = 3;
1052 channel = mm_app_add_channel(test_obj,
1053 MM_CHANNEL_TYPE_ZSL,
1054 &attr,
1055 mm_app_zsl_notify_cb,
1056 test_obj);
1057 if (NULL == channel) {
1058 LOGE("add channel failed");
1059 return -MM_CAMERA_E_GENERAL;
1060 }
1061
1062 s_preview = mm_app_add_preview_stream(test_obj,
1063 channel,
1064 mm_app_preview_notify_cb,
1065 (void *)test_obj,
1066 PREVIEW_BUF_NUM);
1067 if (NULL == s_preview) {
1068 LOGE("add preview stream failed\n");
1069 mm_app_del_channel(test_obj, channel);
1070 return rc;
1071 }
1072
1073 s_main = mm_app_add_snapshot_stream(test_obj,
1074 channel,
1075 mm_app_snapshot_notify_cb,
1076 (void *)test_obj,
1077 PREVIEW_BUF_NUM,
1078 0);
1079 if (NULL == s_main) {
1080 LOGE("add main snapshot stream failed\n");
1081 mm_app_del_stream(test_obj, channel, s_preview);
1082 mm_app_del_channel(test_obj, channel);
1083 return rc;
1084 }
1085
1086 s_metadata = mm_app_add_metadata_stream(test_obj,
1087 channel,
1088 mm_app_metadata_notify_cb,
1089 (void *)test_obj,
1090 PREVIEW_BUF_NUM);
1091 if (NULL == s_metadata) {
1092 LOGE("add metadata stream failed\n");
1093 mm_app_del_channel(test_obj, channel);
1094 return rc;
1095 }
1096
1097 rc = mm_app_start_channel(test_obj, channel);
1098 if (MM_CAMERA_OK != rc) {
1099 LOGE("start zsl failed rc=%d\n", rc);
1100 mm_app_del_stream(test_obj, channel, s_preview);
1101 mm_app_del_stream(test_obj, channel, s_metadata);
1102 mm_app_del_stream(test_obj, channel, s_main);
1103 mm_app_del_channel(test_obj, channel);
1104 return rc;
1105 }
1106
1107 if ( test_obj->enable_reproc ) {
1108 if ( NULL == mm_app_add_reprocess_channel(test_obj, s_main) ) {
1109 LOGE("Reprocess channel failed to initialize \n");
1110 mm_app_del_stream(test_obj, channel, s_preview);
1111 #ifdef USE_METADATA_STREAM
1112 mm_app_del_stream(test_obj, channel, s_metadata);
1113 #endif
1114 mm_app_del_stream(test_obj, channel, s_main);
1115 mm_app_del_channel(test_obj, channel);
1116 return rc;
1117 }
1118 rc = mm_app_start_reprocess(test_obj);
1119 if (MM_CAMERA_OK != rc) {
1120 LOGE("reprocess start failed rc=%d\n", rc);
1121 mm_app_del_stream(test_obj, channel, s_preview);
1122 #ifdef USE_METADATA_STREAM
1123 mm_app_del_stream(test_obj, channel, s_metadata);
1124 #endif
1125 mm_app_del_stream(test_obj, channel, s_main);
1126 mm_app_del_channel(test_obj, channel);
1127 return rc;
1128 }
1129 }
1130
1131 return rc;
1132 }
1133
mm_app_stop_preview_zsl(mm_camera_test_obj_t * test_obj)1134 int mm_app_stop_preview_zsl(mm_camera_test_obj_t *test_obj)
1135 {
1136 int rc = MM_CAMERA_OK;
1137
1138 mm_camera_channel_t *channel =
1139 mm_app_get_channel_by_type(test_obj, MM_CHANNEL_TYPE_ZSL);
1140
1141 rc = mm_app_stop_and_del_channel(test_obj, channel);
1142 if (MM_CAMERA_OK != rc) {
1143 LOGE("Stop Preview failed rc=%d\n", rc);
1144 }
1145
1146 if ( test_obj->enable_reproc ) {
1147 rc |= mm_app_stop_reprocess(test_obj);
1148 }
1149
1150 return rc;
1151 }
1152
mm_app_initialize_fb(mm_camera_test_obj_t * test_obj)1153 int mm_app_initialize_fb(mm_camera_test_obj_t *test_obj)
1154 {
1155 int rc = MM_CAMERA_OK;
1156 int brightness_fd;
1157 const char brightness_level[] = BACKLIGHT_LEVEL;
1158 void *fb_base = NULL;
1159
1160 assert( ( NULL != test_obj ) && ( 0 == test_obj->fb_fd ) );
1161
1162 test_obj->fb_fd = open(FB_PATH, O_RDWR);
1163 if ( 0 > test_obj->fb_fd ) {
1164 LOGE("FB device open failed rc=%d, %s\n",
1165 -errno,
1166 strerror(errno));
1167 rc = -errno;
1168 goto FAIL;
1169 }
1170
1171 rc = ioctl(test_obj->fb_fd, FBIOGET_VSCREENINFO, &test_obj->vinfo);
1172 if ( MM_CAMERA_OK != rc ) {
1173 LOGE("Can not retrieve screen info rc=%d, %s\n",
1174 -errno,
1175 strerror(errno));
1176 rc = -errno;
1177 goto FAIL;
1178 }
1179
1180 if ( ( 0 == test_obj->vinfo.yres_virtual ) ||
1181 ( 0 == test_obj->vinfo.yres ) ||
1182 ( test_obj->vinfo.yres > test_obj->vinfo.yres_virtual ) ) {
1183 LOGE("Invalid FB virtual yres: %d, yres: %d\n",
1184 test_obj->vinfo.yres_virtual,
1185 test_obj->vinfo.yres);
1186 rc = MM_CAMERA_E_GENERAL;
1187 goto FAIL;
1188 }
1189
1190 if ( ( 0 == test_obj->vinfo.xres_virtual ) ||
1191 ( 0 == test_obj->vinfo.xres ) ||
1192 ( test_obj->vinfo.xres > test_obj->vinfo.xres_virtual ) ) {
1193 LOGE("Invalid FB virtual xres: %d, xres: %d\n",
1194 test_obj->vinfo.xres_virtual,
1195 test_obj->vinfo.xres);
1196 rc = MM_CAMERA_E_GENERAL;
1197 goto FAIL;
1198 }
1199
1200 brightness_fd = open(BACKLIGHT_CONTROL, O_RDWR);
1201 if ( brightness_fd >= 0 ) {
1202 write(brightness_fd, brightness_level, strlen(brightness_level));
1203 close(brightness_fd);
1204 }
1205
1206 test_obj->slice_size = test_obj->vinfo.xres * ( test_obj->vinfo.yres - 1 ) * DEFAULT_OV_FORMAT_BPP;
1207 memset(&test_obj->data_overlay, 0, sizeof(struct mdp_overlay));
1208 test_obj->data_overlay.src.width = test_obj->buffer_width;
1209 test_obj->data_overlay.src.height = test_obj->buffer_height;
1210 test_obj->data_overlay.src_rect.w = test_obj->buffer_width;
1211 test_obj->data_overlay.src_rect.h = test_obj->buffer_height;
1212 test_obj->data_overlay.dst_rect.w = test_obj->buffer_width;
1213 test_obj->data_overlay.dst_rect.h = test_obj->buffer_height;
1214 test_obj->data_overlay.src.format = DEFAULT_OV_FORMAT;
1215 test_obj->data_overlay.src_rect.x = 0;
1216 test_obj->data_overlay.src_rect.y = 0;
1217 test_obj->data_overlay.dst_rect.x = 0;
1218 test_obj->data_overlay.dst_rect.y = 0;
1219 test_obj->data_overlay.z_order = 2;
1220 test_obj->data_overlay.alpha = 0x80;
1221 test_obj->data_overlay.transp_mask = 0xffe0;
1222 test_obj->data_overlay.flags = MDP_FLIP_LR | MDP_FLIP_UD;
1223
1224 // Map and clear FB portion
1225 fb_base = mmap(0,
1226 test_obj->slice_size,
1227 PROT_WRITE,
1228 MAP_SHARED,
1229 test_obj->fb_fd,
1230 0);
1231 if ( MAP_FAILED == fb_base ) {
1232 LOGE("( Error while memory mapping frame buffer %s",
1233 strerror(errno));
1234 rc = -errno;
1235 goto FAIL;
1236 }
1237
1238 memset(fb_base, 0, test_obj->slice_size);
1239
1240 if (ioctl(test_obj->fb_fd, FBIOPAN_DISPLAY, &test_obj->vinfo) < 0) {
1241 LOGE("FBIOPAN_DISPLAY failed!");
1242 rc = -errno;
1243 goto FAIL;
1244 }
1245
1246 munmap(fb_base, test_obj->slice_size);
1247 test_obj->data_overlay.id = (uint32_t)MSMFB_NEW_REQUEST;
1248 rc = ioctl(test_obj->fb_fd, MSMFB_OVERLAY_SET, &test_obj->data_overlay);
1249 if (rc < 0) {
1250 LOGE("MSMFB_OVERLAY_SET failed! err=%d\n",
1251 test_obj->data_overlay.id);
1252 return MM_CAMERA_E_GENERAL;
1253 }
1254 LOGE("Overlay set with overlay id: %d", test_obj->data_overlay.id);
1255
1256 return rc;
1257
1258 FAIL:
1259
1260 if ( 0 < test_obj->fb_fd ) {
1261 close(test_obj->fb_fd);
1262 }
1263
1264 return rc;
1265 }
1266
mm_app_close_fb(mm_camera_test_obj_t * test_obj)1267 int mm_app_close_fb(mm_camera_test_obj_t *test_obj)
1268 {
1269 int rc = MM_CAMERA_OK;
1270
1271 assert( ( NULL != test_obj ) && ( 0 < test_obj->fb_fd ) );
1272
1273 if (ioctl(test_obj->fb_fd, MSMFB_OVERLAY_UNSET, &test_obj->data_overlay.id)) {
1274 LOGE("\nERROR! MSMFB_OVERLAY_UNSET failed! (Line %d)\n");
1275 }
1276
1277 if (ioctl(test_obj->fb_fd, FBIOPAN_DISPLAY, &test_obj->vinfo) < 0) {
1278 LOGE("ERROR: FBIOPAN_DISPLAY failed! line=%d\n");
1279 }
1280
1281 close(test_obj->fb_fd);
1282 test_obj->fb_fd = -1;
1283
1284 return rc;
1285 }
1286
memset16(void * pDst,uint16_t value,int count)1287 void memset16(void *pDst, uint16_t value, int count)
1288 {
1289 uint16_t *ptr = pDst;
1290 while (count--)
1291 *ptr++ = value;
1292 }
1293
mm_app_overlay_display(mm_camera_test_obj_t * test_obj,int bufferFd)1294 int mm_app_overlay_display(mm_camera_test_obj_t *test_obj, int bufferFd)
1295 {
1296 int rc = MM_CAMERA_OK;
1297 struct msmfb_overlay_data ovdata;
1298
1299
1300 memset(&ovdata, 0, sizeof(struct msmfb_overlay_data));
1301 ovdata.id = test_obj->data_overlay.id;
1302 ovdata.data.memory_id = bufferFd;
1303
1304 if (ioctl(test_obj->fb_fd, MSMFB_OVERLAY_PLAY, &ovdata)) {
1305 LOGE("MSMFB_OVERLAY_PLAY failed!");
1306 return MM_CAMERA_E_GENERAL;
1307 }
1308
1309 if (ioctl(test_obj->fb_fd, FBIOPAN_DISPLAY, &test_obj->vinfo) < 0) {
1310 LOGE("FBIOPAN_DISPLAY failed!");
1311 return MM_CAMERA_E_GENERAL;
1312 }
1313
1314 return rc;
1315 }
1316