From: Jeongmo Yang Date: Wed, 23 Apr 2025 05:45:14 +0000 (+0900) Subject: TIDL: Separate message callback X-Git-Tag: accepted/tizen/unified/20250530.090452~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=72c12f15c8e99c488e697bddadcb902fdf62a6fe;p=platform%2Fhal%2Fapi%2Fcodec.git TIDL: Separate message callback - from single callback to 2 callbacks : Callback with fd which is used for decoder output. : Callback without fd which is used for encoder output and other messages. [Version] 1.5.0 [Issue Type] Improvement Change-Id: Ifdcf432d8611742fc55bf59736ef8564ad820ea5 Signed-off-by: Jeongmo Yang --- diff --git a/include/hal_codec_ipc_1.tidl b/include/hal_codec_ipc_1.tidl index 755e0a9..54060f1 100644 --- a/include/hal_codec_ipc_1.tidl +++ b/include/hal_codec_ipc_1.tidl @@ -10,10 +10,11 @@ interface codec { STOP } - void message(bundle msg, array fd) delegate; + void message_fd(bundle msg, array fd) delegate; + void message(bundle msg) delegate; void async_return(async_return_type type, int ret) delegate; - int init(int type, message msg_cb, async_return ret_cb); + int init(int type, message_fd msg_fd_cb, message msg_cb, async_return ret_cb); int deinit(); int configure(int width, int height, int in_format, int out_format, bool is_secure); diff --git a/packaging/hal-api-codec.spec b/packaging/hal-api-codec.spec index 56c87ea..b009576 100644 --- a/packaging/hal-api-codec.spec +++ b/packaging/hal-api-codec.spec @@ -6,7 +6,7 @@ ### main package ######### Name: %{name} Summary: %{name} interface -Version: 1.4.0 +Version: 1.5.0 Release: 0 Group: Development/Libraries License: Apache-2.0 diff --git a/src/hal-api-codec-ipc.c b/src/hal-api-codec-ipc.c index 32ee74c..eac6626 100644 --- a/src/hal-api-codec-ipc.c +++ b/src/hal-api-codec-ipc.c @@ -63,7 +63,8 @@ typedef struct _hal_codec_ipc_message_s { - rpc_port_proxy_codec_message_h handle; + rpc_port_proxy_codec_message_fd_h msg_fd_handle; + rpc_port_proxy_codec_message_h msg_handle; hal_codec_message_cb user_cb; void *user_cb_data; GMutex lock; @@ -336,7 +337,7 @@ static void __hal_codec_ipc_hal_buffer_release_encoder_output(hal_codec_buffer_s } -static void __hal_codec_ipc_message_cb(void *user_data, bundle *b_msg, rpc_port_proxy_array_file_desc_h fd_handle) +static void __hal_codec_ipc_message_fd_cb(void *user_data, bundle *b_msg, rpc_port_proxy_array_file_desc_h fd_handle) { int ret = 0; int ipc_ret = 0; @@ -364,6 +365,104 @@ static void __hal_codec_ipc_message_cb(void *user_data, bundle *b_msg, rpc_port_ return; } + if (handle->type != HAL_CODEC_TYPE_DECODER || + hal_message->type != HAL_CODEC_MESSAGE_TYPE_OUTPUT_BUFFER) { + SLOGE("Not DECODER OUTPUT: type[%d], message[%d]", handle->type, hal_message->type); + return; + } + + ipc_buffer = &handle->ipc_buffer; + ipc_message = &handle->ipc_message; + + /* get buffer */ + ipc_ret = bundle_get_byte(b_msg, HAL_CODEC_IPC_PARAM_KEY_BUFFER, (void **)&b_data, &hal_buffer_size); + if (ipc_ret != BUNDLE_ERROR_NONE || + hal_buffer_size != sizeof(hal_codec_buffer_s)) { + SLOGE("[OUTPUT] get buffer from bundle failed[0x%x], size[%zu:%zu]", + ipc_ret, hal_buffer_size, sizeof(hal_codec_buffer_s)); + return; + } + + hal_buffer = g_memdup2(b_data, hal_buffer_size); + + ret = __hal_codec_ipc_hal_buffer_set_decoder_output(hal_buffer, fd_handle); + if (ret != HAL_CODEC_ERROR_NONE) { + g_free(hal_buffer); + return; + } + + g_mutex_lock(&ipc_buffer->lock); + + if (ipc_buffer->output_buffers[hal_buffer->index]) { + SLOGE("[OUTPUT] duplicated buffer index[%d]", hal_buffer->index); + g_free(hal_buffer); + g_mutex_unlock(&ipc_buffer->lock); + return; + } + + hal_message->buffer = hal_buffer; + ipc_buffer->output_buffers[hal_buffer->index] = hal_buffer; + + ipc_buffer->output_buffer_count++; + + SLOGD("[DECODER][OUTPUT] buffer[%d] %p, count[%u -> %u]", + hal_buffer->index, hal_buffer, + ipc_buffer->output_buffer_count - 1, ipc_buffer->output_buffer_count); + + g_mutex_unlock(&ipc_buffer->lock); + + g_mutex_lock(&ipc_message->lock); + + if (ipc_message->user_cb) { + ((hal_codec_message_cb)ipc_message->user_cb)(hal_message, ipc_message->user_cb_data); + g_mutex_unlock(&ipc_message->lock); + return; + } + + g_mutex_unlock(&ipc_message->lock); + + SLOGW("no msg cb for handle[%p]", handle); + + if (hal_message->type == HAL_CODEC_MESSAGE_TYPE_OUTPUT_BUFFER) { + SLOGW("release output buffer[%d]", hal_message->buffer->index); + hal_codec_ipc_release_output_buffer(handle, hal_message->buffer->index); + } +} + + +static void __hal_codec_ipc_message_cb(void *user_data, bundle *b_msg) +{ + int ret = 0; + int ipc_ret = 0; + void *b_data = NULL; + size_t hal_message_size = 0; + size_t hal_buffer_size = 0; + + hal_codec_message_s *hal_message = NULL; + hal_codec_buffer_s *hal_buffer = NULL; + + hal_codec_ipc_s *handle = (hal_codec_ipc_s *)user_data; + hal_codec_ipc_buffer_s *ipc_buffer = NULL; + hal_codec_ipc_message_s *ipc_message = NULL; + + HAL_CODEC_RETURN_IF_FAILED(handle); + HAL_CODEC_RETURN_IF_FAILED(b_msg); + + /* message */ + ipc_ret = bundle_get_byte(b_msg, HAL_CODEC_IPC_PARAM_KEY_MESSAGE, (void **)&hal_message, &hal_message_size); + if (ipc_ret != BUNDLE_ERROR_NONE || + hal_message_size != sizeof(hal_codec_message_s)) { + SLOGE("get message from bundle failed[0x%x], size[%zu:%zu]", + ipc_ret, hal_message_size, sizeof(hal_codec_message_s)); + return; + } + + if (handle->type == HAL_CODEC_TYPE_DECODER && + hal_message->type == HAL_CODEC_MESSAGE_TYPE_OUTPUT_BUFFER) { + SLOGE("It's DECODER OUTPUT"); + return; + } + ipc_buffer = &handle->ipc_buffer; ipc_message = &handle->ipc_message; @@ -393,11 +492,7 @@ static void __hal_codec_ipc_message_cb(void *user_data, bundle *b_msg, rpc_port_ hal_buffer = g_memdup2(b_data, hal_buffer_size); - if (handle->type == HAL_CODEC_TYPE_DECODER) - ret = __hal_codec_ipc_hal_buffer_set_decoder_output(hal_buffer, fd_handle); - else - ret = __hal_codec_ipc_hal_buffer_set_encoder_output(hal_buffer, b_msg); - + ret = __hal_codec_ipc_hal_buffer_set_encoder_output(hal_buffer, b_msg); if (ret != HAL_CODEC_ERROR_NONE) { g_free(hal_buffer); return; @@ -407,6 +502,7 @@ static void __hal_codec_ipc_message_cb(void *user_data, bundle *b_msg, rpc_port_ if (ipc_buffer->output_buffers[hal_buffer->index]) { SLOGE("[OUTPUT] duplicated buffer index[%d]", hal_buffer->index); + g_free(hal_buffer->planes.plane[0].data); g_free(hal_buffer); g_mutex_unlock(&ipc_buffer->lock); return; @@ -417,8 +513,7 @@ static void __hal_codec_ipc_message_cb(void *user_data, bundle *b_msg, rpc_port_ ipc_buffer->output_buffer_count++; - SLOGD("[%s][OUTPUT] buffer[%d] %p, count[%u -> %u]", - handle->type == HAL_CODEC_TYPE_DECODER ? "DECODER" : "ENCODER", + SLOGD("[ENCODER][OUTPUT] buffer[%d] %p, count[%u -> %u]", hal_buffer->index, hal_buffer, ipc_buffer->output_buffer_count - 1, ipc_buffer->output_buffer_count); @@ -493,22 +588,41 @@ static int __hal_codec_ipc_cb_handle_new(hal_codec_ipc_s *handle) hal_codec_ipc_message_s *ipc_message = NULL; hal_codec_ipc_async_return_s *ipc_async_return = NULL; + rpc_port_proxy_codec_message_fd_h msg_fd_handle = NULL; rpc_port_proxy_codec_message_h msg_handle = NULL; rpc_port_proxy_codec_async_return_h async_return_handle = NULL; HAL_CODEC_RETURN_VAL_IF_FAILED(handle, HAL_CODEC_ERROR_INVALID_PARAMETER); - /* message callback */ - ipc_ret = rpc_port_proxy_codec_message_create(&msg_handle); + /* message fd callback for decoder output */ + ipc_ret = rpc_port_proxy_codec_message_fd_create(&msg_fd_handle); if (ipc_ret != RPC_PORT_ERROR_NONE) { - SLOGE("msg handle create failed[0x%x]", ipc_ret); + SLOGE("message_fd handle create failed[0x%x]", ipc_ret); return HAL_CODEC_ERROR_OUT_OF_MEMORY; } + ipc_ret = rpc_port_proxy_codec_message_fd_set_callback(msg_fd_handle, + __hal_codec_ipc_message_fd_cb, handle); + if (ipc_ret != RPC_PORT_ERROR_NONE) { + SLOGE("set message_fd callback failed[0x%x]", ipc_ret); + ret = HAL_CODEC_ERROR_INTERNAL; + goto _CB_HANDLE_NEW_FAILED; + } + + rpc_port_proxy_codec_message_fd_set_once(msg_fd_handle, false); + + /* message callback for encoder output and other messages */ + ipc_ret = rpc_port_proxy_codec_message_create(&msg_handle); + if (ipc_ret != RPC_PORT_ERROR_NONE) { + SLOGE("message handle create failed[0x%x]", ipc_ret); + ret = HAL_CODEC_ERROR_OUT_OF_MEMORY; + goto _CB_HANDLE_NEW_FAILED; + } + ipc_ret = rpc_port_proxy_codec_message_set_callback(msg_handle, __hal_codec_ipc_message_cb, handle); if (ipc_ret != RPC_PORT_ERROR_NONE) { - SLOGE("set msg callback failed[0x%x]", ipc_ret); + SLOGE("set message callback failed[0x%x]", ipc_ret); ret = HAL_CODEC_ERROR_INTERNAL; goto _CB_HANDLE_NEW_FAILED; } @@ -543,14 +657,19 @@ static int __hal_codec_ipc_cb_handle_new(hal_codec_ipc_s *handle) g_cond_init(&ipc_async_return->cond[i]); } - SLOGI("new cb handle: msg[%p], async_return[%p]", msg_handle, async_return_handle); + SLOGI("new cb handle: msg_fd[%p], msg[%p], async_return[%p]", + msg_fd_handle, msg_handle, async_return_handle); - ipc_message->handle = msg_handle; + ipc_message->msg_fd_handle = msg_fd_handle; + ipc_message->msg_handle = msg_handle; ipc_async_return->handle = async_return_handle; return HAL_CODEC_ERROR_NONE; _CB_HANDLE_NEW_FAILED: + if (msg_fd_handle) + rpc_port_proxy_codec_message_fd_destroy(msg_fd_handle); + if (msg_handle) rpc_port_proxy_codec_message_destroy(msg_handle); @@ -586,16 +705,28 @@ static void __hal_codec_ipc_cb_handle_release(hal_codec_ipc_s *handle) ipc_async_return->handle = NULL; } - if (ipc_message->handle) { - SLOGI("msg handle[%p]", ipc_message->handle); + if (ipc_message->msg_fd_handle) { + SLOGI("msg_fd handle[%p]", ipc_message->msg_fd_handle); + + ipc_ret = rpc_port_proxy_codec_message_fd_dispose(handle->rpc_handle, ipc_message->msg_fd_handle); + if (ipc_ret != RPC_PORT_ERROR_NONE) { + SLOGE("msg_fd handle dispose failed[0x%x], try to destroy", ipc_ret); + rpc_port_proxy_codec_message_fd_destroy(ipc_message->msg_fd_handle); + } + + ipc_message->msg_fd_handle = NULL; + } + + if (ipc_message->msg_handle) { + SLOGI("msg handle[%p]", ipc_message->msg_handle); - ipc_ret = rpc_port_proxy_codec_message_dispose(handle->rpc_handle, ipc_message->handle); + ipc_ret = rpc_port_proxy_codec_message_dispose(handle->rpc_handle, ipc_message->msg_handle); if (ipc_ret != RPC_PORT_ERROR_NONE) { SLOGE("msg handle dispose failed[0x%x], try to destroy", ipc_ret); - rpc_port_proxy_codec_message_destroy(ipc_message->handle); + rpc_port_proxy_codec_message_destroy(ipc_message->msg_handle); } - ipc_message->handle = NULL; + ipc_message->msg_handle = NULL; } g_mutex_clear(&ipc_message->lock); @@ -772,7 +903,8 @@ int hal_codec_ipc_init(hal_codec_type_e type, void **codec_handle) goto _INIT_FAILED; ipc_ret = rpc_port_proxy_codec_invoke_init(new_handle->rpc_handle, type, - new_handle->ipc_message.handle, new_handle->ipc_async_return.handle); + new_handle->ipc_message.msg_fd_handle, new_handle->ipc_message.msg_handle, + new_handle->ipc_async_return.handle); if (ipc_ret != RPC_PORT_ERROR_NONE) { SLOGE("invoke init failed[0x%x]", ret); ret = HAL_CODEC_ERROR_INTERNAL; diff --git a/src/service_plugin/hal-backend-service-codec.c b/src/service_plugin/hal-backend-service-codec.c index 706c322..786937e 100644 --- a/src/service_plugin/hal-backend-service-codec.c +++ b/src/service_plugin/hal-backend-service-codec.c @@ -124,6 +124,7 @@ typedef struct _hal_codec_service_task_s { typedef struct _hal_codec_service_s { hal_codec_type_e type; void *codec_handle; + rpc_port_stub_codec_message_fd_h msg_fd_handle; rpc_port_stub_codec_message_h msg_handle; rpc_port_stub_codec_async_return_h async_return_handle; GMutex cb_lock; @@ -170,8 +171,6 @@ static int __hal_codec_service_message_cb(hal_codec_message_s *message, void *us return HAL_CODEC_ERROR_INTERNAL; } - rpc_port_stub_array_file_desc_create(&fd_handle); - switch (message->type) { case HAL_CODEC_MESSAGE_TYPE_INPUT_BUFFER_USED: buffer = message->buffer; @@ -222,8 +221,10 @@ static int __hal_codec_service_message_cb(hal_codec_message_s *message, void *us bundle_add_byte(b_msg, HAL_CODEC_IPC_PARAM_KEY_BUFFER, (const void *)buffer, sizeof(hal_codec_buffer_s)); - if (buffer->memory.num_fd > 0) { - HAL_CODEC_SERVICE_LOGD("[OUTPUT_BUFFER] buffer[%d] num_fd[%u] fd[%d:%d]", + if (service_handle->type == HAL_CODEC_TYPE_DECODER) { + rpc_port_stub_array_file_desc_create(&fd_handle); + + HAL_CODEC_SERVICE_LOGD("[DECODER][OUTPUT] buffer[%d] num_fd[%u] fd[%d:%d]", buffer->index, buffer->memory.num_fd, buffer->memory.fd[0], buffer->memory.fd[1]); ipc_ret = rpc_port_stub_array_file_desc_set(fd_handle, (int *)buffer->memory.fd, buffer->memory.num_fd); @@ -231,10 +232,8 @@ static int __hal_codec_service_message_cb(hal_codec_message_s *message, void *us HAL_CODEC_SERVICE_LOGE("[OUTPUT_BUFFER] set fd failed: num_fd[%u], fd[%d:%d]", buffer->memory.num_fd, buffer->memory.fd[0], buffer->memory.fd[1]); } - } - - if (service_handle->type == HAL_CODEC_TYPE_ENCODER) { - HAL_CODEC_SERVICE_LOGD("[OUTPUT_BUFFER] buffer[%d] data[0] bytesused[%u]", + } else { + HAL_CODEC_SERVICE_LOGD("[ENCODER][OUTPUT] buffer[%d] data[0] bytesused[%u]", buffer->index, buffer->planes.plane[0].bytesused); ipc_ret = bundle_add_byte(b_msg, HAL_CODEC_IPC_PARAM_KEY_PLANE0_DATA, @@ -271,7 +270,10 @@ static int __hal_codec_service_message_cb(hal_codec_message_s *message, void *us goto _SERVICE_MESSAGE_CB_DONE; } - ipc_ret = rpc_port_stub_codec_message_invoke(service_handle->msg_handle, b_msg, fd_handle); + if (fd_handle) + ipc_ret = rpc_port_stub_codec_message_fd_invoke(service_handle->msg_fd_handle, b_msg, fd_handle); + else + ipc_ret = rpc_port_stub_codec_message_invoke(service_handle->msg_handle, b_msg); if (ipc_ret != RPC_PORT_ERROR_NONE) { HAL_CODEC_SERVICE_LOGE("Failed to invoke message_cb"); g_mutex_unlock(&service_handle->cb_lock); @@ -282,7 +284,8 @@ static int __hal_codec_service_message_cb(hal_codec_message_s *message, void *us _SERVICE_MESSAGE_CB_DONE: bundle_free(b_msg); - rpc_port_stub_array_file_desc_destroy(fd_handle); + if (fd_handle) + rpc_port_stub_array_file_desc_destroy(fd_handle); return HAL_CODEC_ERROR_NONE; } @@ -384,6 +387,7 @@ static gpointer __hal_codec_service_task_func(gpointer data) g_free(job); if (return_type != RPC_PORT_STUB_ASYNC_RETURN_TYPE_CODEC_NONE) { + SLOGD("async return type[%d]: ret[0x%x]", return_type, ret); ipc_ret = rpc_port_stub_codec_async_return_invoke(service_handle->async_return_handle, return_type, ret); if (ipc_ret != RPC_PORT_ERROR_NONE) HAL_CODEC_SERVICE_LOGE("Failed async_return_cb: type[%d], ret[0x%x]", return_type, ipc_ret); @@ -512,32 +516,44 @@ static void __hal_codec_service_task_deinit(rpc_port_stub_codec_context_h contex static int __hal_codec_service_cb_handle_new(hal_codec_service_s *service_handle, - rpc_port_stub_codec_message_h msg_handle, rpc_port_stub_codec_async_return_h async_return_handle) + rpc_port_stub_codec_message_fd_h msg_fd_handle, rpc_port_stub_codec_message_h msg_handle, + rpc_port_stub_codec_async_return_h async_return_handle) { int rpc_ret = RPC_PORT_ERROR_NONE; + rpc_port_stub_codec_message_fd_h msg_fd_handle_new = NULL; rpc_port_stub_codec_message_h msg_handle_new = NULL; rpc_port_stub_codec_async_return_h async_return_handle_new = NULL; HAL_CODEC_SERVICE_RETURN_VAL_IF_FAILED(service_handle, HAL_CODEC_ERROR_INVALID_PARAMETER); + HAL_CODEC_SERVICE_RETURN_VAL_IF_FAILED(msg_fd_handle, HAL_CODEC_ERROR_INVALID_PARAMETER); HAL_CODEC_SERVICE_RETURN_VAL_IF_FAILED(msg_handle, HAL_CODEC_ERROR_INVALID_PARAMETER); HAL_CODEC_SERVICE_RETURN_VAL_IF_FAILED(async_return_handle, HAL_CODEC_ERROR_INVALID_PARAMETER); + rpc_ret = rpc_port_stub_codec_message_fd_clone(msg_fd_handle, &msg_fd_handle_new); + if (rpc_ret != RPC_PORT_ERROR_NONE) { + HAL_CODEC_SERVICE_LOGE("message_fd handle clone failed[0x%x]", rpc_ret); + return HAL_CODEC_ERROR_INTERNAL; + } + rpc_ret = rpc_port_stub_codec_message_clone(msg_handle, &msg_handle_new); if (rpc_ret != RPC_PORT_ERROR_NONE) { HAL_CODEC_SERVICE_LOGE("message handle clone failed[0x%x]", rpc_ret); + rpc_port_stub_codec_message_fd_destroy(msg_fd_handle_new); return HAL_CODEC_ERROR_INTERNAL; } rpc_ret = rpc_port_stub_codec_async_return_clone(async_return_handle, &async_return_handle_new); if (rpc_ret != RPC_PORT_ERROR_NONE) { HAL_CODEC_SERVICE_LOGE("async return handle clone failed[0x%x]", rpc_ret); + rpc_port_stub_codec_message_fd_destroy(msg_fd_handle_new); rpc_port_stub_codec_message_destroy(msg_handle_new); return HAL_CODEC_ERROR_INTERNAL; } - HAL_CODEC_SERVICE_LOGI("new cb handle: message[%p], async_return[%p]", - msg_handle_new, async_return_handle); + HAL_CODEC_SERVICE_LOGI("new cb handle: message_fd[%p], message[%p], async_return[%p]", + msg_fd_handle_new, msg_handle_new, async_return_handle); + service_handle->msg_fd_handle = msg_fd_handle_new; service_handle->msg_handle = msg_handle_new; service_handle->async_return_handle = async_return_handle_new; @@ -567,7 +583,8 @@ static void __hal_codec_service_cb_handle_release(hal_codec_service_s *service_h static int _hal_codec_service_backend_init(rpc_port_stub_codec_context_h context, int type, - rpc_port_stub_codec_message_h msg_handle, rpc_port_stub_codec_async_return_h async_return_handle, void *user_data) + rpc_port_stub_codec_message_fd_h msg_fd_handle, rpc_port_stub_codec_message_h msg_handle, + rpc_port_stub_codec_async_return_h async_return_handle, void *user_data) { int ret = HAL_CODEC_ERROR_NONE; int rpc_ret = RPC_PORT_ERROR_NONE; @@ -593,7 +610,7 @@ static int _hal_codec_service_backend_init(rpc_port_stub_codec_context_h context goto _BACKEND_INIT_FAILED; } - ret = __hal_codec_service_cb_handle_new(service_handle, msg_handle, async_return_handle); + ret = __hal_codec_service_cb_handle_new(service_handle, msg_fd_handle, msg_handle, async_return_handle); if (ret != HAL_CODEC_ERROR_NONE) goto _BACKEND_INIT_FAILED; diff --git a/tests/codec_hal_test.cpp b/tests/codec_hal_test.cpp index 5b670c9..69b22b7 100644 --- a/tests/codec_hal_test.cpp +++ b/tests/codec_hal_test.cpp @@ -39,6 +39,8 @@ using namespace std; #define DECODE_FRAME_HEIGHT 1080 #define ENCODE_FRAME_WIDTH 1920 #define ENCODE_FRAME_HEIGHT 1080 +#define ENCODE_FRAME_TEST_NUM 60 +#define ENCODE_FRAME_INDEX_MAX 16 #define DECODER_SUPPORT_CHECK \ do {\ @@ -119,6 +121,10 @@ class CodecHalTest case HAL_CODEC_MESSAGE_TYPE_INPUT_BUFFER_USED: cout << "[INPUT_BUFFER_USED] buffer[" << message->buffer->index << "] "<< message->buffer; cout << " size[" << message->buffer->planes.plane[0].bytesused << "]" << endl; + if (gHalHandleEnc) { + g_free(message->buffer); + message->buffer = nullptr; + } break; case HAL_CODEC_MESSAGE_TYPE_OUTPUT_BUFFER: if (message->buffer->meta.flags & HAL_CODEC_BUFFER_FLAG_EOS) { @@ -196,7 +202,6 @@ class CodecHalTest gsize mappedFileLength_ {}; gchar *mappedFileContents_ {}; gsize mappedFileOffset_ {}; - hal_codec_buffer_s buffer_[CONTENTS_H264_FRAME_NUM + 1] {}; }; @@ -262,11 +267,13 @@ class CodecHalTestDecoder : public testing::Test, public CodecHalTest if (buffer_[gFeedCount].meta.flags & HAL_CODEC_BUFFER_FLAG_EOS) { cout << "[FeedDataDecode] Remove Feed thread" << endl; return G_SOURCE_REMOVE; - } else { - gFeedCount++; - return G_SOURCE_CONTINUE; } + + gFeedCount++; + return G_SOURCE_CONTINUE; } + + hal_codec_buffer_s buffer_[CONTENTS_H264_FRAME_NUM + 1] {}; }; @@ -363,39 +370,49 @@ class CodecHalTestEncoder : public testing::Test, public CodecHalTest int FeedDataEncode(void) { - memset(&buffer_[gFeedCount], 0x0, sizeof(hal_codec_buffer_s)); + int ret_get_state = 0; + hal_codec_buffer_s *inputBuffer = g_new0(hal_codec_buffer_s, 1); + hal_codec_state_e state = HAL_CODEC_STATE_INITIALIZED; - buffer_[gFeedCount].index = (int)gFeedCount; - buffer_[gFeedCount].meta.timestamp = (uint64_t)gFeedCount * 1000000000; /* ns */ + inputBuffer->index = (int)(gFeedCount % ENCODE_FRAME_INDEX_MAX); + inputBuffer->meta.timestamp = (uint64_t)gFeedCount * 1000000000; /* ns */ + + cout << "[FeedEncode] count: " << gFeedCount << ", tSurface_: " << tSurface_ << endl; - if (gFeedCount < CONTENTS_NV12_FRAME_NUM) { - buffer_[gFeedCount].size = tsInfo_.size; - buffer_[gFeedCount].planes.num_planes = tsInfo_.num_planes; + ret_get_state = hal_codec_get_state(gHalHandleEnc, &state); + if (ret_get_state != HAL_CODEC_ERROR_NONE) + cout << "[GET_STATE FAILED] " << ret_get_state << endl; + else + cout << "[GET_STATE] " << state << endl; + + if (gFeedCount < ENCODE_FRAME_TEST_NUM) { + inputBuffer->size = tsInfo_.size; + inputBuffer->planes.num_planes = tsInfo_.num_planes; for (uint32_t i = 0 ; i < tsInfo_.num_planes ; i++) { - buffer_[gFeedCount].planes.plane[i].data = tsInfo_.planes[i].ptr; - buffer_[gFeedCount].planes.plane[i].size = tsInfo_.planes[i].size; - buffer_[gFeedCount].planes.plane[i].bytesused = tsInfo_.planes[i].size; + inputBuffer->planes.plane[i].data = tsInfo_.planes[i].ptr; + inputBuffer->planes.plane[i].size = tsInfo_.planes[i].size; + inputBuffer->planes.plane[i].bytesused = tsInfo_.planes[i].size; } - buffer_[gFeedCount].memory.num_fd = tbm_surface_internal_get_num_bos(tSurface_); + inputBuffer->memory.num_fd = tbm_surface_internal_get_num_bos(tSurface_); for (int i = 0 ; i < tbm_surface_internal_get_num_bos(tSurface_) ; i++) { - buffer_[gFeedCount].memory.fd[i] = tFd_[i]; + inputBuffer->memory.fd[i] = tFd_[i]; } - cout << "[FeedDataEncode] buffer[" << gFeedCount << "] " << &buffer_[gFeedCount] << endl; + cout << "[FeedDataEncode] buffer[" << gFeedCount << "] " << inputBuffer << endl; } else { - buffer_[gFeedCount].memory.num_fd = 0; - buffer_[gFeedCount].meta.flags = HAL_CODEC_BUFFER_FLAG_EOS; + inputBuffer->memory.num_fd = 0; + inputBuffer->meta.flags = HAL_CODEC_BUFFER_FLAG_EOS; cout << "[FeedDataEncode] Send EOS" << endl; } - ret = hal_codec_encode(gHalHandleEnc, &buffer_[gFeedCount]); + ret = hal_codec_encode(gHalHandleEnc, inputBuffer); if (ret != HAL_CODEC_ERROR_NONE) cout << "[FeedDataEncode] failed " << ret << endl; - if (buffer_[gFeedCount].meta.flags & HAL_CODEC_BUFFER_FLAG_EOS) { + if (inputBuffer->meta.flags & HAL_CODEC_BUFFER_FLAG_EOS) { cout << "[FeedDataEncode] Remove Feed thread" << endl; return G_SOURCE_REMOVE; } @@ -747,8 +764,8 @@ TEST_F(CodecHalTestEncoder, EncoderEncodeP) return self->FeedDataEncode(); }, this); - gTimeoutSourceID = g_timeout_add(3000, [](gpointer user_data) -> gboolean { - cout << "[ENCODE] timeout(3000ms) encoded count: " << gOutputCount << endl; + gTimeoutSourceID = g_timeout_add(5000, [](gpointer user_data) -> gboolean { + cout << "[ENCODE] timeout(5000ms) encoded count: " << gOutputCount << endl; g_main_loop_quit(gMainLoop); return G_SOURCE_REMOVE; }, nullptr);