From c8b396024865b0d7be734e0f7339508c2524fa3c Mon Sep 17 00:00:00 2001 From: Sejun Park Date: Fri, 14 Oct 2016 17:48:44 +0900 Subject: [PATCH] modify to fill yuv data in test suite Change-Id: I5c9339c89f029e66639d79019303a69334bfd94a --- include/media_codec_port_gst.h | 2 +- src/media_codec_port_gst.c | 25 +++++++-- test/media_codec_test.c | 115 +++++++++++++++++++++++++++++------------ 3 files changed, 106 insertions(+), 36 deletions(-) diff --git a/include/media_codec_port_gst.h b/include/media_codec_port_gst.h index ffcff60..3da69a8 100755 --- a/include/media_codec_port_gst.h +++ b/include/media_codec_port_gst.h @@ -49,7 +49,7 @@ extern "C" { #define SCMN_IMGB_MAX_PLANE 4 #define TBM_API_CHANGE -#define DEFAULT_POOL_SIZE 20 +#define DEFAULT_POOL_SIZE 13 #define AAC_CODECDATA_SIZE 16 #define WMA_CODECDATA_SIZE 64 #define VORBIS_CODECDATA_SIZE 4096 diff --git a/src/media_codec_port_gst.c b/src/media_codec_port_gst.c index d97c686..1590169 100755 --- a/src/media_codec_port_gst.c +++ b/src/media_codec_port_gst.c @@ -2308,6 +2308,7 @@ static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t* core, media_packet int num_bos; tbm_surface_h surface = NULL; tbm_surface_info_s surface_info; + tbm_bo_handle handle_bo; if (!pkt) { LOGE("output is null"); @@ -2357,6 +2358,24 @@ static MMVideoBuffer *__mc_gst_make_tbm_buffer(mc_gst_core_t* core, media_packet mm_vbuffer->stride_height[0] = surface_info.planes[0].size / surface_info.planes[0].stride; mm_vbuffer->stride_width[1] = surface_info.planes[1].stride; mm_vbuffer->stride_height[1] = surface_info.planes[1].size / surface_info.planes[1].stride; + + if (mm_vbuffer->handle.bo[0]) { + handle_bo = tbm_bo_get_handle(mm_vbuffer->handle.bo[0], TBM_DEVICE_CPU); + mm_vbuffer->data[0]= handle_bo.ptr; + + handle_bo = tbm_bo_get_handle(mm_vbuffer->handle.bo[0], TBM_DEVICE_MM); + mm_vbuffer->handle.dmabuf_fd[0]= handle_bo.u32; + } + + if (mm_vbuffer->handle.bo[1]) { + handle_bo = tbm_bo_get_handle(mm_vbuffer->handle.bo[1], TBM_DEVICE_CPU); + mm_vbuffer->data[1]= handle_bo.ptr; + + handle_bo = tbm_bo_get_handle(mm_vbuffer->handle.bo[1], TBM_DEVICE_MM); + mm_vbuffer->handle.dmabuf_fd[1]= handle_bo.u32; + } else { + mm_vbuffer->data[1] = mm_vbuffer->data[0] + mm_vbuffer->stride_width[0] * mm_vbuffer->stride_height[0]; + } mm_vbuffer->plane_num = 2; LOGD("size[0] : %d, size[1] : %d, bo[0] :%p, bo[1] :%p", mm_vbuffer->size[0], mm_vbuffer->size[1], mm_vbuffer->handle.bo[0], mm_vbuffer->handle.bo[1]); @@ -3150,14 +3169,14 @@ mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *pkt return MC_ERROR; } - media_packet_pool_get_size(pool, &min_size, &max_size, &curr_size); - LOGD("curr_size is %d min_size is %d and max_size is %d \n", curr_size, min_size, max_size); - ret = media_packet_pool_allocate(pool); if (ret != MEDIA_PACKET_ERROR_NONE) { LOGE("media_packet_pool_allocate failed"); return MC_OUT_OF_MEMORY; } + media_packet_pool_get_size(pool, &min_size, &max_size, &curr_size); + LOGD("curr_size is %d min_size is %d and max_size is %d \n", curr_size, min_size, max_size); + *pkt_pool = pool; return MC_ERROR_NONE; } diff --git a/test/media_codec_test.c b/test/media_codec_test.c index 2da9c6f..949f4ef 100755 --- a/test/media_codec_test.c +++ b/test/media_codec_test.c @@ -55,6 +55,7 @@ ((state & (expected_state)) == (expected_state)) #define AAC_CODECDATA_SIZE 16 +#define USE_POOL 1 unsigned char buf_adts[ADTS_HEADER_SIZE]; @@ -926,8 +927,9 @@ static void _mediacodec_process_input(App *app) media_packet_h pkt = NULL; unsigned char *tmp; int read; + int size; int offset; - int stride_width, stride_height; + int stride_width; for (i = 0; i < app->frame; i++) { g_print("----------read data------------\n"); @@ -935,10 +937,17 @@ static void _mediacodec_process_input(App *app) extractor(app, &tmp, &read, &have_frame); if (have_frame) { - if (media_packet_create_alloc(fmt, NULL, NULL, &pkt) != MEDIA_PACKET_ERROR_NONE) { - fprintf(stderr, "media_packet_create_alloc failed\n"); - return; - } +#ifdef USE_POOL + if (media_packet_pool_acquire_packet(pkt_pool, &pkt, -1) != MEDIA_PACKET_ERROR_NONE) { + fprintf(stderr, "media_packet_pool_aquire_packet failed\n"); + return; + } +#else + if (media_packet_create_alloc(fmt, NULL, NULL, &pkt) != MEDIA_PACKET_ERROR_NONE) { + fprintf(stderr, "media_packet_create_alloc failed\n"); + return; + } +#endif if (media_packet_set_pts(pkt, (uint64_t)(pts)) != MEDIA_PACKET_ERROR_NONE) { fprintf(stderr, "media_packet_set_pts failed\n"); @@ -955,28 +964,47 @@ static void _mediacodec_process_input(App *app) /* Y */ media_packet_get_video_plane_data_ptr(pkt, 0, &buf_data_ptr); media_packet_get_video_stride_width(pkt, 0, &stride_width); - media_packet_get_video_stride_height(pkt, 0, &stride_height); + offset = app->width*app->height; + + for (i = 0; i < app->height; i++) { + memcpy(buf_data_ptr, tmp, app->width); + buf_data_ptr += stride_width; + tmp += app->width; + } - offset = stride_width*stride_height; + if (app->hardware == TRUE) { + media_packet_get_video_plane_data_ptr(pkt, 1, &buf_data_ptr); + media_packet_get_video_stride_width(pkt, 1, &stride_width); + size = app->width * app->height / 2; - memcpy(buf_data_ptr, tmp, offset); + for (i = 0; i< app->height / 2; i++) { + memcpy(buf_data_ptr, tmp, app->width); + buf_data_ptr += stride_width; + tmp += app->width; + } + } else { + /* U */ + media_packet_get_video_plane_data_ptr(pkt, 1, &buf_data_ptr); + media_packet_get_video_stride_width(pkt, 1, &stride_width); + size = (app->width>>1) * (app->height>>1); - /* UV or U*/ - media_packet_get_video_plane_data_ptr(pkt, 1, &buf_data_ptr); - media_packet_get_video_stride_width(pkt, 1, &stride_width); - media_packet_get_video_stride_height(pkt, 1, &stride_height); - memcpy(buf_data_ptr, tmp + offset, stride_width*stride_height); + for (i = 0; i < app->height/2; i++) { + memcpy(buf_data_ptr, tmp, app->width/2); + buf_data_ptr += stride_width; + tmp += app->width/2; + } - if (app->hardware == FALSE) { /* V */ media_packet_get_video_plane_data_ptr(pkt, 2, &buf_data_ptr); media_packet_get_video_stride_width(pkt, 2, &stride_width); - media_packet_get_video_stride_height(pkt, 2, &stride_height); + offset += size; - offset += stride_width * stride_height; + for (i = 0; i < app->height/2; i++) { + memcpy(buf_data_ptr, tmp, app->width/2); + buf_data_ptr += stride_width; + tmp += app->width/2; + } - - memcpy(buf_data_ptr, tmp + offset, stride_width*stride_height); } } mc_hex_dump("inbuf", tmp, 48); @@ -999,9 +1027,11 @@ static gboolean read_data(App *app) void *buf_data_ptr = NULL; media_packet_h pkt = NULL; unsigned char *tmp; + int i; int read; + int size; int offset; - int stride_width, stride_height; + int stride_width; if (app->offset == 0) { app->frame_count = 0; @@ -1043,6 +1073,7 @@ static gboolean read_data(App *app) return FALSE; } + if (app->type != VIDEO_ENC) { media_packet_get_buffer_data_ptr(pkt, &buf_data_ptr); media_packet_set_buffer_size(pkt, (uint64_t)read); @@ -1053,28 +1084,48 @@ static gboolean read_data(App *app) /* Y */ media_packet_get_video_plane_data_ptr(pkt, 0, &buf_data_ptr); media_packet_get_video_stride_width(pkt, 0, &stride_width); - media_packet_get_video_stride_height(pkt, 0, &stride_height); + offset = app->width*app->height; + + for (i = 0; i < app->height; i++) { + memcpy(buf_data_ptr, tmp, app->width); + buf_data_ptr += stride_width; + tmp += app->width; + } + + if (app->hardware == TRUE) { + media_packet_get_video_plane_data_ptr(pkt, 1, &buf_data_ptr); + media_packet_get_video_stride_width(pkt, 1, &stride_width); + size = app->width * app->height>>1; - offset = stride_width*stride_height; + for (i = 0; i < app->height>>1; i++) { + memcpy(buf_data_ptr, tmp, app->width); + buf_data_ptr += stride_width; + tmp += app->width; + } - memcpy(buf_data_ptr, tmp, offset); + } else { + /* U */ + media_packet_get_video_plane_data_ptr(pkt, 1, &buf_data_ptr); + media_packet_get_video_stride_width(pkt, 1, &stride_width); + size = (app->width>>1) * (app->height>>1); - /* UV or U*/ - media_packet_get_video_plane_data_ptr(pkt, 1, &buf_data_ptr); - media_packet_get_video_stride_width(pkt, 1, &stride_width); - media_packet_get_video_stride_height(pkt, 1, &stride_height); - memcpy(buf_data_ptr, tmp + offset, stride_width*stride_height); + for (i = 0; i < app->height/2; i++) { + memcpy(buf_data_ptr, tmp, app->width>>1); + buf_data_ptr += stride_width; + tmp += (app->width>>1); + } - if (app->hardware == FALSE) { /* V */ media_packet_get_video_plane_data_ptr(pkt, 2, &buf_data_ptr); media_packet_get_video_stride_width(pkt, 2, &stride_width); - media_packet_get_video_stride_height(pkt, 2, &stride_height); - - offset += stride_width * stride_height; + offset += size; + for (i = 0; i < app->height/2; i++) { + memcpy(buf_data_ptr, tmp, app->width>>1); + buf_data_ptr += stride_width; + tmp += (app->width>>1); + } - memcpy(buf_data_ptr, tmp + offset, stride_width*stride_height); } } mc_hex_dump("inbuf", tmp, 48); -- 2.7.4