#include "shm.h" #include #include #include #include #include #include #include #include #include #include #include #include #define DISPLAY_NUM_RUN_COUNT 100 //#define FILE_DIR "/opt/vision_apps/test_data/dttest" typedef struct { const char *name; uint32_t pipeId; uint32_t dataFormat; uint32_t inWidth; uint32_t inHeight; uint32_t bpp; uint32_t pitchY; uint32_t pitchUV; uint32_t outWidth; uint32_t outHeight; uint32_t posX; uint32_t posY; uint32_t loopCount; } Arg; /** * @brief Add time stamp to bt1120 image * @param addr: Bt1120 binary image sequence * @param timestamp: 64 bit timestamp, small end representation */ static int fill_time_stamp(void *addr, unsigned long long *timestamp) { char *addrp = (char *)addr; int i = 0; for (i = 15; i >= 0; i--) addrp[15 - i] = 0x50 | ((uint8_t)(((*timestamp) & ((uint64_t)0xf << (i * 4))) >> (i * 4))); return 0; } #if 1 static vx_status readYUV422Input(char *file_name, unsigned char *data_ptr) { vx_status status = VX_SUCCESS; if (status == VX_SUCCESS) { FILE *fp = fopen(file_name, "rb"); if (fp == NULL) { printf("Unable to open file %s \n", file_name); return (VX_FAILURE); } vx_uint32 img_width = 1920; vx_uint32 img_height = 1080; // Copy YuYv vx_uint32 num_bytes = fread(data_ptr, 1, img_width * img_height * 2, fp); if (num_bytes != (img_width * img_height * 2)) printf("CbCr bytes read = %d, expected = %d \n", num_bytes, img_width * img_height * 2); fclose(fp); } return (status); } #endif vx_status app_tidl_od_main(vx_int32 argc, vx_char *argv[]) { vx_status status = VX_SUCCESS; unsigned char gTiovxCtDisplayArray1[1920 * 1080 * 2] = {0}; Arg arg_; arg_.pipeId = 2; arg_.dataFormat = VX_DF_IMAGE_YUYV; arg_.inWidth = 1920; arg_.inHeight = 1080; arg_.bpp = 2; arg_.pitchY = 1920; arg_.pitchUV = 0; arg_.outWidth = 1920; arg_.outHeight = 1080; arg_.posX = 0; arg_.posY = 0; vx_context context = vxCreateContext(); status = vxGetStatus((vx_reference)context); if (status != VX_SUCCESS) { printf("vxGetStatus is failed! \n"); } vx_image disp_image = 0; vx_imagepatch_addressing_t image_addr; tivx_display_params_t params; vx_user_data_object param_obj; vx_graph graph = 0; vx_node node = 0; //uint32_t loop_count = arg_.loopCount; if (vx_true_e == tivxIsTargetEnabled(TIVX_TARGET_DISPLAY1)) { tivxHwaLoadKernels(context); disp_image = vxCreateImage(context, arg_.inWidth, arg_.inHeight, arg_.dataFormat); image_addr.dim_x = arg_.inWidth; image_addr.dim_y = arg_.inHeight; image_addr.stride_x = arg_.bpp; image_addr.stride_y = arg_.pitchY * 2; image_addr.scale_x = VX_SCALE_UNITY; image_addr.scale_y = VX_SCALE_UNITY; image_addr.step_x = 1; image_addr.step_y = 1; vx_rectangle_t rect; rect.start_x = 0; rect.start_y = 0; rect.end_x = arg_.inWidth; rect.end_y = arg_.inHeight; DIR * dir; char *FILE_DIR = "/opt/vision_apps/test_data/dttest"; struct dirent * ptr; dir = opendir(FILE_DIR); if(NULL == dir) { printf("opendir error...!\n"); printf("%s\n",strerror(errno)); return -1; } char file_name[512] = {0}; loop1: ptr = readdir(dir); sprintf(file_name,"%s/%s",FILE_DIR,ptr->d_name); if(!(strcmp(ptr->d_name,".")) || !(strcmp(ptr->d_name,".."))) { goto loop1; } printf("filename is-->%s\n",file_name); if(ptr != NULL) { status = readYUV422Input(file_name,gTiovxCtDisplayArray1); if (status != VX_SUCCESS) { printf("readYUV422Input is failed! \n"); } } long long current_time = time(0); fill_time_stamp((void *)gTiovxCtDisplayArray1,(unsigned long long*)¤t_time); status = vxCopyImagePatch(disp_image, &rect, 0, &image_addr, (void *)gTiovxCtDisplayArray1, VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST); if (status != VX_SUCCESS) { printf("vxCopyImagePatch 0 is failed! \n"); } memset(¶ms, 0, sizeof(tivx_display_params_t)); params.opMode = TIVX_KERNEL_DISPLAY_BUFFER_COPY_MODE; params.pipeId = arg_.pipeId; params.outWidth = arg_.outWidth; params.outHeight = arg_.outHeight; params.posX = arg_.posX; params.posY = arg_.posY; param_obj = vxCreateUserDataObject(context, "tivx_display_params_t", sizeof(tivx_display_params_t), ¶ms); graph = vxCreateGraph(context); node = tivxDisplayNode(graph, param_obj, disp_image); status = vxSetNodeTarget(node, VX_TARGET_STRING, TIVX_TARGET_DISPLAY1); if (status != VX_SUCCESS) { printf("vxSetNodeTarget is failed! \n"); } status = vxVerifyGraph(graph); if (status != VX_SUCCESS) { printf("vxVerifyGraph is failed! \n"); } while(1) { while ((ptr=readdir(dir))!= NULL) { if(!(strcmp(ptr->d_name,".")) || !(strcmp(ptr->d_name,".."))) { continue; } sprintf(file_name,"%s/%s",FILE_DIR,ptr->d_name); printf("filename is-->%s\n",file_name); status = readYUV422Input(file_name,gTiovxCtDisplayArray1); if(status != VX_SUCCESS) { printf("readYUV422Input is failed! \n"); } current_time = time(0); fill_time_stamp((void *)gTiovxCtDisplayArray1,(unsigned long long*)¤t_time); status = vxProcessGraph(graph); if (status != VX_SUCCESS) { printf("vxProcessGraph is failed!\n"); } else { printf("vxProcessGraph is successed!\n"); } status = vxCopyImagePatch(disp_image, &rect, 0, &image_addr, (void *)gTiovxCtDisplayArray1, VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST); if (status == VX_SUCCESS) { printf("vxCopyImagePatch 1 is success! \n"); } else { printf("in while(1),vxCopyImagePatch error\n"); //goto exit; } } dir = opendir(FILE_DIR); if(NULL == dir) { printf("opendir2 error...!\n"); printf("%s\n",strerror(errno)); printf("break while(1)...!!!\n"); break; } } vxReleaseNode(&node); vxReleaseGraph(&graph); vxReleaseImage(&disp_image); vxReleaseUserDataObject(¶m_obj); tivxHwaUnLoadKernels(context); } return status; } #if 0 TEST_WITH_ARG(tivxHwaDisplay, testZeroBufferCopyMode, Arg, PARAMETERS) { vx_context context = context_->vx_context_; vx_image disp_image[2]; vx_imagepatch_addressing_t image_addr; tivx_display_params_t params; vx_user_data_object param_obj; vx_graph graph = 0; vx_node node = 0; vx_image disp_image_temp; uint32_t num_refs; uint32_t loop_count = arg_.loopCount; vx_graph_parameter_queue_params_t graph_parameters_queue_params_list[1]; if (vx_true_e == tivxIsTargetEnabled(TIVX_TARGET_DISPLAY1)) { tivxHwaLoadKernels(context); CT_RegisterForGarbageCollection(context, ct_teardown_hwa_kernels, CT_GC_OBJECT); ASSERT_VX_OBJECT(disp_image[0] = vxCreateImage(context, arg_.inWidth, arg_.inHeight, arg_.dataFormat), VX_TYPE_IMAGE); ASSERT_VX_OBJECT(disp_image[1] = vxCreateImage(context, arg_.inWidth, arg_.inHeight, arg_.dataFormat), VX_TYPE_IMAGE); image_addr.dim_x = arg_.inWidth; image_addr.dim_y = arg_.inHeight; image_addr.stride_x = arg_.bpp; image_addr.stride_y = arg_.pitchY; image_addr.scale_x = VX_SCALE_UNITY; image_addr.scale_y = VX_SCALE_UNITY; image_addr.step_x = 1; image_addr.step_y = 1; vx_rectangle_t rect; rect.start_x = 0; rect.start_y = 0; rect.end_x = arg_.inWidth; rect.end_y = arg_.inHeight; vxCopyImagePatch(disp_image[0], &rect, 0, &image_addr, (void *)gTiovxCtDisplayArray1, VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST ); vxCopyImagePatch(disp_image[1], &rect, 0, &image_addr, (void *)gTiovxCtDisplayArray2, VX_WRITE_ONLY, VX_MEMORY_TYPE_HOST ); memset(¶ms, 0, sizeof(tivx_display_params_t)); params.opMode=TIVX_KERNEL_DISPLAY_ZERO_BUFFER_COPY_MODE; params.pipeId=arg_.pipeId; params.outWidth=arg_.outWidth; params.outHeight=arg_.outHeight; params.posX=arg_.posX; params.posY=arg_.posY; ASSERT_VX_OBJECT(param_obj = vxCreateUserDataObject(context, "tivx_display_params_t", sizeof(tivx_display_params_t), ¶ms), (enum vx_type_e)VX_TYPE_USER_DATA_OBJECT); ASSERT_VX_OBJECT(graph = vxCreateGraph(context), VX_TYPE_GRAPH); ASSERT_VX_OBJECT(node = tivxDisplayNode(graph, param_obj, disp_image[0]), VX_TYPE_NODE); VX_CALL(vxSetNodeTarget(node, VX_TARGET_STRING, TIVX_TARGET_DISPLAY1)); /* Image is parameter number 1 for Display Node and becomes graph parameter 0 */ add_graph_parameter_by_node_index(graph, node, 1); /* Set graph schedule config such that graph parameter @ index 0 is enqueuable */ graph_parameters_queue_params_list[0].graph_parameter_index = 0; graph_parameters_queue_params_list[0].refs_list_size = 2; /* Two images */ graph_parameters_queue_params_list[0].refs_list = (vx_reference*)&disp_image[0]; /* Schedule mode auto is used, here we don't need to call vxScheduleGraph * Graph gets scheduled automatically as refs are enqueued to it */ vxSetGraphScheduleConfig(graph, VX_GRAPH_SCHEDULE_MODE_QUEUE_AUTO, 1, graph_parameters_queue_params_list ); /* Explicitly set graph pipeline depth */ ASSERT_EQ_VX_STATUS(VX_SUCCESS, set_graph_pipeline_depth(graph, 2)); VX_CALL(vxVerifyGraph(graph)); /* Enqueue input references */ vxGraphParameterEnqueueReadyRef(graph, 0, (vx_reference*)&disp_image[0], 1); vxGraphParameterEnqueueReadyRef(graph, 0, (vx_reference*)&disp_image[1], 1); /* Wait for the loop count */ while(loop_count-- > 0) { /* Dequeue one image buffer */ vxGraphParameterDequeueDoneRef(graph, 0, (vx_reference*)&disp_image_temp, 1, &num_refs); /* Enqueue the same image buffer */ vxGraphParameterEnqueueReadyRef(graph, 0, (vx_reference*)&disp_image_temp, 1); } /* ensure all graph processing is complete */ vxWaitGraph(graph); VX_CALL(vxReleaseNode(&node)); VX_CALL(vxReleaseGraph(&graph)); VX_CALL(vxReleaseImage(&disp_image[0])); VX_CALL(vxReleaseImage(&disp_image[1])); VX_CALL(vxReleaseUserDataObject(¶m_obj)); ASSERT(node == 0); ASSERT(graph == 0); ASSERT(disp_image[0] == 0); ASSERT(disp_image[1] == 0); ASSERT(param_obj == 0); tivxHwaUnLoadKernels(context); } } TESTCASE_TESTS(tivxHwaDisplay, testBufferCopyMode, testZeroBufferCopyMode ) #endif