From 3552d5cba36f4e889f4ce57dfd7e7e7a43fdda64 Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Fri, 9 Apr 2021 17:24:52 +0900 Subject: [PATCH] camera_test: Update preview callback function [Version] 0.4.52 [Issue Type] Test Change-Id: If9eaa6f22294e5382f565bd6a47cc22c460dd7a6 Signed-off-by: Jeongmo Yang --- packaging/capi-media-camera.spec | 2 +- test/CMakeLists.txt | 2 +- test/camera_test.c | 152 ++++++++++++++++++++++++++------------- 3 files changed, 105 insertions(+), 51 deletions(-) diff --git a/packaging/capi-media-camera.spec b/packaging/capi-media-camera.spec index 2c6d174..ed93607 100644 --- a/packaging/capi-media-camera.spec +++ b/packaging/capi-media-camera.spec @@ -1,6 +1,6 @@ Name: capi-media-camera Summary: A Camera API -Version: 0.4.51 +Version: 0.4.52 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 11b9936..9bb2baa 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -5,7 +5,7 @@ SET(fw_test "${fw_name}-test") #link_directories(${CMAKE_SOURCE_DIR}/../) INCLUDE(FindPkgConfig) -pkg_check_modules(${fw_test} REQUIRED elementary evas ecore appcore-efl) +pkg_check_modules(${fw_test} REQUIRED elementary evas ecore appcore-efl libtbm) FOREACH(flag ${${fw_test}_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") MESSAGE(${flag}) diff --git a/test/camera_test.c b/test/camera_test.c index 87ef1a6..1d69566 100644 --- a/test/camera_test.c +++ b/test/camera_test.c @@ -31,6 +31,7 @@ #include #include #include +#include /*----------------------------------------------------------------------- | GLOBAL VARIABLE DEFINITIONS: | @@ -66,6 +67,7 @@ static GTimer *timer; static int g_camera_device_state_changed_cb_id; static int g_camera_device_list_changed_cb_id; static int g_camera_preview_cb_file_write; +static int g_camera_mp_preview_cb_file_write; static struct timeval previous_time; static struct timeval current_time; @@ -91,6 +93,7 @@ static struct timeval result_time; -----------------------------------------------------------------------*/ #define DEFAULT_FILE_PATH "/home/owner/media" #define PREVIEW_CB_DUMP_FILE_NAME "preview.data" +#define MP_PREVIEW_CB_DUMP_FILE_NAME "mp_preview.data" #define MAX_FILE_NAME_LENGTH 256 #define MAX_FILE_PATH_LENGTH (MAX_FILE_NAME_LENGTH - 20) @@ -486,68 +489,71 @@ static void _camera_interrupt_started_cb(camera_policy_e policy, camera_state_e void _camera_preview_cb(camera_preview_data_s *frame, void *user_data) { - if (g_camera_preview_cb_file_write) { - char preview_dump[MAX_FILE_NAME_LENGTH] = {'\0',}; - FILE *fp = NULL; - - snprintf(preview_dump, MAX_FILE_NAME_LENGTH, "%s/%s", DEFAULT_FILE_PATH, PREVIEW_CB_DUMP_FILE_NAME); - - fp = fopen(preview_dump, "a"); - if (fp == NULL) { - g_print("\n==== file[%s] open failed ====\n", preview_dump); - return; - } - - if (frame->format == CAMERA_PIXEL_FORMAT_RGBA || - frame->format == CAMERA_PIXEL_FORMAT_ARGB) { - fwrite(frame->data.rgb_plane.data, 1, frame->data.rgb_plane.size, fp); - } else if (frame->format == CAMERA_PIXEL_FORMAT_INVZ) { - fwrite(frame->data.depth_plane.data, 1, frame->data.depth_plane.size, fp); - } else if (frame->format == CAMERA_PIXEL_FORMAT_MJPEG) { - fwrite(frame->data.encoded_plane.data, 1, frame->data.encoded_plane.size, fp); - } else { - switch (frame->num_of_planes) { - case 1: - fwrite(frame->data.single_plane.yuv, 1, frame->data.single_plane.size, fp); - break; - case 2: - fwrite(frame->data.double_plane.y, 1, frame->data.double_plane.y_size, fp); - fwrite(frame->data.double_plane.uv, 1, frame->data.double_plane.uv_size, fp); - break; - case 3: - fwrite(frame->data.triple_plane.y, 1, frame->data.triple_plane.y_size, fp); - fwrite(frame->data.triple_plane.u, 1, frame->data.triple_plane.u_size, fp); - fwrite(frame->data.triple_plane.v, 1, frame->data.triple_plane.v_size, fp); - break; - default: - break; - } - } - - g_print("==== file[%s] write done ====\n", preview_dump); - - fclose(fp); + char preview_dump[MAX_FILE_NAME_LENGTH] = {'\0',}; + FILE *fp = NULL; + if (!frame) { + g_print("\n[PREVIEW_CB] NULL frame!\n"); return; } - g_print("----- preview callback - format %d, %dx%d, num plane %d\n", + g_print("[PREVIEW_CB] preview callback - format[%d] res[%dx%d] num plane[%d] ", frame->format, frame->width, frame->height, frame->num_of_planes); + if (frame->num_of_planes == 1) { - g_print("----- length YUV %d\n", + g_print("size YUV[%d]\n", frame->data.single_plane.size); } else if (frame->num_of_planes == 2) { - g_print("----- length Y %d, UV %d\n", + g_print("size Y[%d] UV[%d]\n", frame->data.double_plane.y_size, frame->data.double_plane.uv_size); } else if (frame->num_of_planes == 3) { - g_print("----- length Y %d, U %d, V %d\n", + g_print("size Y[%d] U[%d] V[%d]\n", frame->data.triple_plane.y_size, frame->data.triple_plane.u_size, frame->data.triple_plane.v_size); + } + + if (!g_camera_preview_cb_file_write) + return; + + snprintf(preview_dump, MAX_FILE_NAME_LENGTH, "%s/%s", DEFAULT_FILE_PATH, PREVIEW_CB_DUMP_FILE_NAME); + + fp = fopen(preview_dump, "a"); + if (fp == NULL) { + g_print("\n[PREVIEW_CB] file[%s] open failed\n", preview_dump); + return; + } + + if (frame->format == CAMERA_PIXEL_FORMAT_RGBA || + frame->format == CAMERA_PIXEL_FORMAT_ARGB) { + fwrite(frame->data.rgb_plane.data, 1, frame->data.rgb_plane.size, fp); + } else if (frame->format == CAMERA_PIXEL_FORMAT_INVZ) { + fwrite(frame->data.depth_plane.data, 1, frame->data.depth_plane.size, fp); + } else if (frame->format == CAMERA_PIXEL_FORMAT_MJPEG) { + fwrite(frame->data.encoded_plane.data, 1, frame->data.encoded_plane.size, fp); } else { - g_print("invalid num of planes %d\n", frame->num_of_planes); + switch (frame->num_of_planes) { + case 1: + fwrite(frame->data.single_plane.yuv, 1, frame->data.single_plane.size, fp); + break; + case 2: + fwrite(frame->data.double_plane.y, 1, frame->data.double_plane.y_size, fp); + fwrite(frame->data.double_plane.uv, 1, frame->data.double_plane.uv_size, fp); + break; + case 3: + fwrite(frame->data.triple_plane.y, 1, frame->data.triple_plane.y_size, fp); + fwrite(frame->data.triple_plane.u, 1, frame->data.triple_plane.u_size, fp); + fwrite(frame->data.triple_plane.v, 1, frame->data.triple_plane.v_size, fp); + break; + default: + break; + } } + + g_print("[PREVIEW_CB] file[%s] write done\n", preview_dump); + + fclose(fp); } @@ -556,24 +562,69 @@ static void _camera_media_packet_preview_cb(media_packet_h pkt, void *user_data) int ret = 0; int width = 0; int height = 0; + unsigned int i = 0; + char mp_preview_dump[MAX_FILE_NAME_LENGTH] = {'\0',}; + FILE *fp = NULL; media_format_h fmt = NULL; media_format_mimetype_e type = MEDIA_FORMAT_I420; + tbm_surface_h surface = NULL; + tbm_surface_info_s s_info; + + if (!pkt) { + g_print("\n[MP_PREVIEW_CB] NULL packet!\n"); + return; + } ret = media_packet_get_format(pkt, &fmt); if (ret != MEDIA_PACKET_ERROR_NONE) { - g_print("get media format failed[0x%x]", ret); + g_print("\n[MP_PREVIEW_CB] get media format failed[0x%x]", ret); goto _MEDIA_PACKET_PREVIEW_CB_OUT; } ret = media_format_get_video_info(fmt, &type, &width, &height, NULL, NULL); if (ret != MEDIA_FORMAT_ERROR_NONE) { - g_print("get video info failed[0x%x]", ret); + g_print("\n[MP_PREVIEW_CB] get video info failed[0x%x]", ret); + goto _MEDIA_PACKET_PREVIEW_CB_OUT; + } + + g_print("[MP_PREVIEW_CB] media_packet_preview_cb[mimetype:0x%x, %dx%d]\n", type, width, height); + + ret = media_packet_get_tbm_surface(pkt, &surface); + if (ret != MEDIA_PACKET_ERROR_NONE) { + g_print("\n[MP_PREVIEW_CB] get tbm surface failed[0x%x] ====\n", ret); + goto _MEDIA_PACKET_PREVIEW_CB_OUT; + } + + ret = tbm_surface_get_info(surface, &s_info); + if (ret != TBM_SURFACE_ERROR_NONE) { + g_print("\n[MP_PREVIEW_CB] get tbm surface info failed[0x%x] ====\n", ret); goto _MEDIA_PACKET_PREVIEW_CB_OUT; } - g_print("==== media_packet_preview_cb[mimetype:0x%x, %dx%d]\n", type, width, height); + g_print(" tbm surface [%dx%d], total size[%u]\n", + s_info.width, s_info.height, s_info.size); + + if (g_camera_mp_preview_cb_file_write) { + snprintf(mp_preview_dump, MAX_FILE_NAME_LENGTH, "%s/%s", DEFAULT_FILE_PATH, MP_PREVIEW_CB_DUMP_FILE_NAME); + + fp = fopen(mp_preview_dump, "a"); + if (fp == NULL) { + g_print("\n[MP_PREVIEW_CB] file[%s] open failed ====\n", mp_preview_dump); + goto _MEDIA_PACKET_PREVIEW_CB_OUT; + } + } + + for (i = 0 ; i < s_info.num_planes ; i++) { + g_print(" plane[%d][%p] stride[%u] size[%u]\n", + i, s_info.planes[i].ptr, s_info.planes[i].stride, s_info.planes[i].size); + if (fp) + fwrite(s_info.planes[i].ptr, 1, s_info.planes[i].size, fp); + } _MEDIA_PACKET_PREVIEW_CB_OUT: + if (fp) + fclose(fp); + media_packet_unref(pkt); } @@ -920,6 +971,9 @@ static void main_menu(gchar buf) camera_unset_preview_cb(hcamcorder->camera); break; case '7': + g_print("\n\tWrite preview data to file(0:NO, Others:YES) : "); + err = scanf("%d", &g_camera_mp_preview_cb_file_write); + flush_stdin(); camera_set_media_packet_preview_cb(hcamcorder->camera, _camera_media_packet_preview_cb, hcamcorder->camera); break; case '8': -- 2.7.4