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