You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
250 lines
5.8 KiB
250 lines
5.8 KiB
/*
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2019. All rights reserved.
|
|
* Description: implement of aenc iapi interface
|
|
* Author: audio
|
|
* Create: 2019-06-21
|
|
*/
|
|
#include "mpi_aenc_trans.h"
|
|
#include "mpi_aenc_debug.h"
|
|
#include "uapi_aenc.h"
|
|
#include "securec.h"
|
|
#include "mpi_aenc_ext.h"
|
|
|
|
#ifdef __cplusplus
|
|
#if __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
#endif /* __cplusplus */
|
|
|
|
#define AENC_INSTANCE_MASK 0xffff
|
|
|
|
static inline td_s32 aenc_check_handle(td_handle aenc)
|
|
{
|
|
if (((aenc >> 16) != SOC_ID_AENC) || /* high 16 bit store module ID */
|
|
((aenc & AENC_INSTANCE_MASK) >= AENC_INSTANCE_MAXNUM)) {
|
|
soc_log_err("invalid aenc handle(0x%x).\n", aenc);
|
|
return SOC_ERR_AENC_INVALID_PARA;
|
|
}
|
|
|
|
return TD_SUCCESS;
|
|
}
|
|
|
|
td_s32 uapi_aenc_init(td_void)
|
|
{
|
|
return ext_mpi_aenc_init();
|
|
}
|
|
|
|
td_s32 uapi_aenc_deinit(td_void)
|
|
{
|
|
return ext_mpi_aenc_deinit();
|
|
}
|
|
|
|
td_s32 uapi_aenc_create(const uapi_aenc_attr *aenc_attr, td_handle *aenc)
|
|
{
|
|
td_s32 ret;
|
|
ext_aenc_attr mpi_aenc_attr;
|
|
|
|
if ((aenc_attr == TD_NULL) || (aenc == TD_NULL)) {
|
|
return SOC_ERR_AENC_NULL_PTR;
|
|
}
|
|
|
|
(td_void)memset_s(&mpi_aenc_attr, sizeof(mpi_aenc_attr), 0, sizeof(ext_aenc_attr));
|
|
ret = trans_aenc_attr_from_iapi_to_mpi(aenc_attr, &mpi_aenc_attr);
|
|
if (ret != TD_SUCCESS) {
|
|
return ret;
|
|
}
|
|
|
|
return ext_mpi_aenc_open(aenc, &mpi_aenc_attr);
|
|
}
|
|
|
|
td_s32 uapi_aenc_destroy(td_handle aenc)
|
|
{
|
|
td_s32 ret;
|
|
|
|
ret = aenc_check_handle(aenc);
|
|
if (ret != TD_SUCCESS) {
|
|
return ret;
|
|
}
|
|
|
|
return ext_mpi_aenc_close(aenc);
|
|
}
|
|
|
|
td_s32 uapi_aenc_attach_input(td_handle aenc, td_handle src)
|
|
{
|
|
td_s32 ret;
|
|
|
|
ret = aenc_check_handle(aenc);
|
|
if (ret != TD_SUCCESS) {
|
|
return ret;
|
|
}
|
|
|
|
return ext_mpi_aenc_attach_input(aenc, src);
|
|
}
|
|
|
|
td_s32 uapi_aenc_detach_input(td_handle aenc)
|
|
{
|
|
td_s32 ret;
|
|
|
|
ret = aenc_check_handle(aenc);
|
|
if (ret != TD_SUCCESS) {
|
|
return ret;
|
|
}
|
|
|
|
return ext_mpi_aenc_detach_input(aenc);
|
|
}
|
|
|
|
td_s32 uapi_aenc_start(td_handle aenc)
|
|
{
|
|
td_s32 ret;
|
|
|
|
ret = aenc_check_handle(aenc);
|
|
if (ret != TD_SUCCESS) {
|
|
return ret;
|
|
}
|
|
|
|
return ext_mpi_aenc_set_enable(aenc, TD_TRUE);
|
|
}
|
|
|
|
td_s32 uapi_aenc_stop(td_handle aenc)
|
|
{
|
|
td_s32 ret;
|
|
|
|
ret = aenc_check_handle(aenc);
|
|
if (ret != TD_SUCCESS) {
|
|
return ret;
|
|
}
|
|
|
|
return ext_mpi_aenc_set_enable(aenc, TD_FALSE);
|
|
}
|
|
|
|
td_s32 uapi_aenc_send_frame(td_handle aenc, const uapi_audio_frame *ao_frame)
|
|
{
|
|
td_s32 ret;
|
|
ext_ao_frame mpi_ao_frame;
|
|
|
|
ret = aenc_check_handle(aenc);
|
|
if (ret != TD_SUCCESS) {
|
|
return ret;
|
|
}
|
|
|
|
(td_void)memset_s(&mpi_ao_frame, sizeof(mpi_ao_frame), 0, sizeof(ext_ao_frame));
|
|
ret = trans_ao_frame_from_iapi_to_mpi(ao_frame, &mpi_ao_frame);
|
|
if (ret != TD_SUCCESS) {
|
|
return ret;
|
|
}
|
|
|
|
return ext_mpi_aenc_send_buffer(aenc, &mpi_ao_frame);
|
|
}
|
|
|
|
td_s32 uapi_aenc_acquire_stream(td_handle aenc, uapi_es_buf *stream, td_u32 timeout_ms)
|
|
{
|
|
td_s32 ret;
|
|
aenc_stream stream_info = {TD_NULL, 0, TD_INVALID_PTS};
|
|
|
|
if (stream == TD_NULL) {
|
|
return SOC_ERR_AENC_NULL_PTR;
|
|
}
|
|
|
|
ret = aenc_check_handle(aenc);
|
|
if (ret != TD_SUCCESS) {
|
|
return ret;
|
|
}
|
|
|
|
ret = ext_mpi_aenc_receive_stream(aenc, &stream_info, timeout_ms);
|
|
if (ret != TD_SUCCESS) {
|
|
return ret;
|
|
}
|
|
|
|
stream->buf = stream_info.data;
|
|
stream->buf_len = stream_info.bytes;
|
|
stream->pts = stream_info.pts;
|
|
|
|
stream->private_es_buf_addr.kernel_vir_addr = 0;
|
|
stream->private_es_buf_addr.buf_handle.mem_handle = 0;
|
|
stream->private_es_buf_addr.buf_handle.addr_offset = 0;
|
|
return TD_SUCCESS;
|
|
}
|
|
|
|
td_s32 uapi_aenc_release_stream(td_handle aenc, const uapi_es_buf *stream)
|
|
{
|
|
td_s32 ret;
|
|
aenc_stream stream_info = {TD_NULL, 0, TD_INVALID_PTS};
|
|
|
|
ret = aenc_check_handle(aenc);
|
|
if (ret != TD_SUCCESS) {
|
|
return ret;
|
|
}
|
|
|
|
if (stream == TD_NULL) {
|
|
return SOC_ERR_AENC_NULL_PTR;
|
|
}
|
|
|
|
stream_info.data = stream->buf;
|
|
stream_info.bytes = stream->buf_len;
|
|
stream_info.pts = stream->pts;
|
|
|
|
return ext_mpi_aenc_release_stream(aenc, &stream_info);
|
|
}
|
|
|
|
td_s32 uapi_aenc_register_encoder(const td_char *encoder_name)
|
|
{
|
|
return ext_mpi_aenc_register_encoder(encoder_name);
|
|
}
|
|
|
|
td_s32 uapi_aenc_set_attr(td_handle aenc, const uapi_aenc_attr *attr)
|
|
{
|
|
td_s32 ret;
|
|
ext_aenc_attr mpi_attr;
|
|
|
|
ret = aenc_check_handle(aenc);
|
|
if (ret != TD_SUCCESS) {
|
|
return ret;
|
|
}
|
|
|
|
(td_void)memset_s(&mpi_attr, sizeof(mpi_attr), 0, sizeof(ext_aenc_attr));
|
|
ret = trans_aenc_attr_from_iapi_to_mpi(attr, &mpi_attr);
|
|
if (ret != TD_SUCCESS) {
|
|
return ret;
|
|
}
|
|
return ext_mpi_aenc_set_attr(aenc, &mpi_attr);
|
|
}
|
|
|
|
td_s32 uapi_aenc_get_attr(td_handle aenc, uapi_aenc_attr *attr)
|
|
{
|
|
td_s32 ret;
|
|
ext_aenc_attr mpi_aenc_attr;
|
|
|
|
ret = aenc_check_handle(aenc);
|
|
if (ret != TD_SUCCESS) {
|
|
return ret;
|
|
}
|
|
|
|
(td_void)memset_s(&mpi_aenc_attr, sizeof(mpi_aenc_attr), 0, sizeof(ext_aenc_attr));
|
|
ret = trans_aenc_attr_from_iapi_to_mpi(attr, &mpi_aenc_attr);
|
|
if (ret != TD_SUCCESS) {
|
|
return ret;
|
|
}
|
|
|
|
ret = ext_mpi_aenc_get_attr(aenc, &mpi_aenc_attr);
|
|
|
|
(td_void)trans_aenc_attr_from_mpi_to_iapi(attr, &mpi_aenc_attr);
|
|
return ret;
|
|
}
|
|
|
|
td_s32 uapi_aenc_get_capability(uapi_aenc_cap *capability)
|
|
{
|
|
check_aenc_null_ptr(capability);
|
|
|
|
capability->support_type_num = UAPI_AENC_MAX_TYPE;
|
|
capability->max_aenc_instance = AENC_INSTANCE_MAXNUM;
|
|
capability->cap_info[0].codec_type = UAPI_ACODEC_ID_AAC;
|
|
|
|
return TD_SUCCESS;
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
#if __cplusplus
|
|
}
|
|
#endif
|
|
#endif /* __cplusplus */
|