/* * Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2019. All rights reserved. * Description: implement of aenc mpi layer * Author: audio * Create: 2019-06-21 */ #include "mpi_aenc_debug.h" #include "mpi_ao_ext.h" #include "mpi_aenc_ext.h" #include "mpi_aenc_core.h" #ifdef __cplusplus #if __cplusplus extern "C" { #endif #endif /* __cplusplus */ #define aenc_get_real_chn(aenc) \ do { \ (aenc) = (aenc) & 0xffff; \ } while (0) td_s32 ext_mpi_aenc_init(td_void) { return aenc_init(); } td_s32 ext_mpi_aenc_register_encoder(const td_char *codec_name) { return aenc_register_encoder(codec_name); } td_s32 ext_mpi_aenc_deinit(td_void) { return aenc_deinit(); } td_s32 ext_mpi_aenc_open(td_handle *aenc, const ext_aenc_attr *aenc_attr) { td_s32 ret; if ((aenc == TD_NULL) || (aenc_attr == TD_NULL)) { return SOC_ERR_AENC_NULL_PTR; } ret = aenc_open(aenc, aenc_attr); if (ret != TD_SUCCESS) { soc_log_err("aenc_open failed(0x%x)\n", ret); return ret; } *aenc = *aenc | (SOC_ID_AENC << 16); /* low 16 bit store handle, high 16 bit store module ID */ return ret; } td_s32 ext_mpi_aenc_close(td_handle aenc) { aenc_get_real_chn(aenc); return aenc_close(aenc); } td_s32 ext_mpi_aenc_send_buffer(td_handle aenc, const ext_ao_frame *ao_frame) { aenc_get_real_chn(aenc); return aenc_send_buffer(aenc, ao_frame); } td_s32 ext_mpi_aenc_receive_stream(td_handle aenc, aenc_stream *stream, td_u32 timeout_ms) { aenc_get_real_chn(aenc); return aenc_receive_stream(aenc, stream, timeout_ms); } td_s32 ext_mpi_aenc_release_stream(td_handle aenc, const aenc_stream *stream) { aenc_get_real_chn(aenc); return aenc_release_stream(aenc, stream); } td_s32 ext_mpi_aenc_set_config_encoder(td_handle aenc, td_void *config) { aenc_get_real_chn(aenc); return aenc_set_config_encoder(aenc, config); } td_s32 ext_mpi_aenc_set_enable(td_handle aenc, td_bool enable) { aenc_get_real_chn(aenc); return aenc_set_enable(aenc, enable); } #define check_ai_handle(ai) (((ai) >> 16) == SOC_ID_AI) static td_s32 mpi_aenc_attach_ai(td_handle aenc, td_handle ai) { td_s32 ret = TD_SUCCESS; ext_ao_ext_module_fn ext_ao_func = { TD_NULL, TD_NULL }; if (!check_ai_handle(ai)) { return TD_SUCCESS; } ret = ext_mpi_ao_get_extern_func(SOC_ID_AI, &ext_ao_func); if (ret != TD_SUCCESS) { soc_err_print_call_fun_err(ext_mpi_ao_get_extern_func, ret); return ret; } if (ext_ao_func.attach == TD_NULL) { return SOC_ERR_AENC_NULL_PTR; } return ext_ao_func.attach(ai, aenc); } static td_s32 mpi_aenc_detach_ai(td_handle aenc, td_handle ai) { td_s32 ret; ext_ao_ext_module_fn ao_func = { TD_NULL, TD_NULL }; if (!check_ai_handle(ai)) { return TD_SUCCESS; } ret = ext_mpi_ao_get_extern_func(SOC_ID_AI, &ao_func); if (ret != TD_SUCCESS) { soc_err_print_call_fun_err(ext_mpi_ao_get_extern_func, ret); return ret; } if (ao_func.detach == TD_NULL) { return SOC_ERR_AENC_NULL_PTR; } return ao_func.detach(ai, aenc); } static td_s32 mpi_aenc_get_attach_src(td_handle aenc, td_handle *src) { aenc_get_real_chn(aenc); if (src == TD_NULL) { return SOC_ERR_AENC_NULL_PTR; } *src = TD_INVALID_HANDLE; return aenc_get_attach_src(aenc, src); } td_s32 ext_mpi_aenc_attach_input(td_handle aenc, td_handle src) { td_s32 ret; ret = mpi_aenc_attach_ai(aenc, src); if (ret != TD_SUCCESS) { soc_err_print_h32(src); soc_err_print_call_fun_err(mpi_aenc_attach_ai, ret); return ret; } aenc_get_real_chn(aenc); ret = aenc_attach_input(aenc, src); if (ret != TD_SUCCESS) { soc_log_err("aenc_attach_input failed(0x%x)\n", ret); return ret; } return aenc_set_enable(aenc, TD_TRUE); } td_s32 ext_mpi_aenc_detach_input(td_handle aenc) { td_s32 ret; td_handle source = TD_INVALID_HANDLE; ret = mpi_aenc_get_attach_src(aenc, &source); if (ret != TD_SUCCESS) { soc_err_print_h32(aenc); soc_err_print_call_fun_err(mpi_aenc_get_attach_src, ret); return ret; } ret = mpi_aenc_detach_ai(aenc, source); if (ret != TD_SUCCESS) { soc_err_print_h32(source); soc_err_print_call_fun_err(mpi_aenc_attach_ai, ret); return ret; } aenc_get_real_chn(aenc); ret = aenc_detach_input(aenc); if (ret != TD_SUCCESS) { soc_err_print_call_fun_err(aenc_detach_input, ret); return ret; } return aenc_set_enable(aenc, TD_FALSE); } td_s32 ext_mpi_aenc_set_attr(td_handle aenc, const ext_aenc_attr *aenc_attr) { aenc_get_real_chn(aenc); return aenc_set_attr(aenc, aenc_attr); } td_s32 ext_mpi_aenc_get_attr(td_handle aenc, ext_aenc_attr *aenc_attr) { aenc_get_real_chn(aenc); return aenc_get_attr(aenc, aenc_attr); } #ifdef __cplusplus #if __cplusplus } #endif #endif /* __cplusplus */