Skip to content

Commit

Permalink
Audio support on hisi-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed May 21, 2024
1 parent 28d255c commit 7b3db72
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 4 deletions.
133 changes: 133 additions & 0 deletions src/hal/hisi/v3_aud.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#pragma once

#include "v3_common.h"

#define V3_AUD_CHN_NUM 2

typedef enum {
V3_AUD_BIT_8,
V3_AUD_BIT_16,
V3_AUD_BIT_24
} v3_aud_bit;

typedef enum {
V3_AUD_INTF_I2S_MASTER,
V3_AUD_INTF_I2S_SLAVE,
V3_AUD_INTF_PCM_SLAVE_STD,
V3_AUD_INTF_PCM_SLAVE_NSTD,
V3_AUD_INTF_PCM_MASTER_STD,
V3_AUD_INTF_PCM_MASTER_NSTD,
V3_AUD_INTF_END
} v3_aud_intf;

typedef struct {
// Accept industry standards from
// 8000 to 96000Hz, plus 64000Hz
int rate;
v3_aud_bit bit;
v3_aud_intf intf;
int stereoOn;
// 8-to-16 bit, expand mode
int expandOn;
unsigned int frmNum;
unsigned int packNumPerFrm;
unsigned int chnNum;
unsigned int syncRxClkOn;
} v3_aud_cnf;

typedef struct {
v3_aud_bit bit;
int stereoOn;
void *addr[2];
unsigned int phy[2];
unsigned long long timestamp;
unsigned int sequence;
unsigned int length;
unsigned int poolId[2];
} v3_aud_frm;

typedef struct {
v3_aud_frm frame;
char isValid;
char isSysBound;
} v3_aud_efrm;

typedef struct {
void *handle;

int (*fnDisableDevice)(int device);
int (*fnEnableDevice)(int device);
int (*fnSetDeviceConfig)(int device, v3_aud_cnf *config);

int (*fnDisableChannel)(int device, int channel);
int (*fnEnableChannel)(int device, int channel);

int (*fnSetVolume)(int device, int channel, int dbLevel);

int (*fnFreeFrame)(int device, int channel, v3_aud_frm *frame, v3_aud_efrm *encFrame);
int (*fnGetFrame)(int device, int channel, v3_aud_frm *frame, v3_aud_efrm *encFrame, int millis);
} v3_aud_impl;

static int v3_aud_load(v3_aud_impl *aud_lib) {
if (!(aud_lib->handle = dlopen("libmi_ai.so", RTLD_LAZY | RTLD_GLOBAL))) {
fprintf(stderr, "[v3_aud] Failed to load library!\nError: %s\n", dlerror());
return EXIT_FAILURE;
}

if (!(aud_lib->fnDisableDevice = (int(*)(int device))
dlsym(aud_lib->handle, "HI_MPI_AI_Disable"))) {
fprintf(stderr, "[v3_aud] Failed to acquire symbol HI_MPI_AI_Disable!\n");
return EXIT_FAILURE;
}

if (!(aud_lib->fnEnableDevice = (int(*)(int device))
dlsym(aud_lib->handle, "HI_MPI_AI_Enable"))) {
fprintf(stderr, "[v3_aud] Failed to acquire symbol HI_MPI_AI_Enable!\n");
return EXIT_FAILURE;
}

if (!(aud_lib->fnSetDeviceConfig = (int(*)(int device, v3_aud_cnf *config))
dlsym(aud_lib->handle, "HI_MPI_AI_SetPubAttr"))) {
fprintf(stderr, "[v3_aud] Failed to acquire symbol HI_MPI_AI_SetPubAttr!\n");
return EXIT_FAILURE;
}

if (!(aud_lib->fnDisableChannel = (int(*)(int device, int channel))
dlsym(aud_lib->handle, "HI_MPI_AI_DisableChn"))) {
fprintf(stderr, "[v3_aud] Failed to acquire symbol HI_MPI_AI_DisableChn!\n");
return EXIT_FAILURE;
}

if (!(aud_lib->fnEnableChannel = (int(*)(int device, int channel))
dlsym(aud_lib->handle, "HI_MPI_AI_EnableChn"))) {
fprintf(stderr, "[v3_aud] Failed to acquire symbol HI_MPI_AI_EnableChn!\n");
return EXIT_FAILURE;
}


if (!(aud_lib->fnSetVolume = (int(*)(int device, int channel, int dbLevel))
dlsym(aud_lib->handle, "HI_MPI_AI_SetVqeVolume"))) {
fprintf(stderr, "[v3_aud] Failed to acquire symbol HI_MPI_AI_SetVqeVolume!\n");
return EXIT_FAILURE;
}

if (!(aud_lib->fnFreeFrame = (int(*)(int device, int channel, v3_aud_frm *frame, v3_aud_efrm *encFrame))
dlsym(aud_lib->handle, "HI_MPI_AI_ReleaseFrame"))) {
fprintf(stderr, "[v3_aud] Failed to acquire symbol HI_MPI_AI_ReleaseFrame!\n");
return EXIT_FAILURE;
}

if (!(aud_lib->fnGetFrame = (int(*)(int device, int channel, v3_aud_frm *frame, v3_aud_efrm *encFrame, int millis))
dlsym(aud_lib->handle, "HI_MPI_AI_GetFrame"))) {
fprintf(stderr, "[v3_aud] Failed to acquire symbol HI_MPI_AI_GetFrame!\n");
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}

static void v3_aud_unload(v3_aud_impl *aud_lib) {
if (aud_lib->handle) dlclose(aud_lib->handle);
aud_lib->handle = NULL;
memset(aud_lib, 0, sizeof(*aud_lib));
}
44 changes: 43 additions & 1 deletion src/hal/hisi/v3_hal.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "v3_hal.h"

v3_aud_impl v3_aud;
v3_config_impl v3_config;
v3_drv_impl v3_drv;
v3_isp_impl v3_isp;
Expand All @@ -13,6 +14,8 @@ v3_vpss_impl v3_vpss;
hal_chnstate v3_state[V3_VENC_CHN_NUM] = {0};
int (*v3_venc_cb)(char, hal_vidstream*);

char _v3_aud_chn = 0;
char _v3_aud_dev = 0;
char _v3_isp_chn = 0;
char _v3_isp_dev = 0;
char _v3_venc_dev = 0;
Expand All @@ -28,6 +31,7 @@ void v3_hal_deinit(void)
v3_vb_unload(&v3_vb);
v3_rgn_unload(&v3_rgn);
v3_isp_unload(&v3_isp);
v3_aud_unload(&v3_aud);
v3_sys_unload(&v3_sys);
}

Expand All @@ -37,6 +41,8 @@ int v3_hal_init(void)

if (ret = v3_sys_load(&v3_sys))
return ret;
if (ret = v3_aud_load(&v3_aud))
return ret;
if (ret = v3_isp_load(&v3_isp))
return ret;
if (ret = v3_rgn_load(&v3_rgn))
Expand All @@ -53,6 +59,42 @@ int v3_hal_init(void)
return EXIT_SUCCESS;
}

void v3_audio_deinit(void)
{
v3_aud.fnDisableChannel(_v3_aud_dev, _v3_aud_chn);

v3_aud.fnDisableDevice(_v3_aud_dev);
}

int i6_audio_init(void)
{
int ret;

{
v3_aud_cnf config;
config.rate = 48000;
config.bit = V3_AUD_BIT_16;
config.intf = V3_AUD_INTF_I2S_SLAVE;
config.stereoOn = 0;
config.expandOn = 0;
config.frmNum = 0;
config.packNumPerFrm = 0;
config.chnNum = 0;
config.syncRxClkOn = 0;
if (ret = v3_aud.fnSetDeviceConfig(_v3_aud_dev, &config))
return ret;
}
if (ret = v3_aud.fnEnableDevice(_v3_aud_dev))
return ret;

if (ret = v3_aud.fnEnableChannel(_v3_aud_dev, _v3_aud_chn))
return ret;
if (ret = v3_aud.fnSetVolume(_v3_aud_dev, _v3_aud_chn, 0xF6))
return ret;

return EXIT_SUCCESS;
}

int v3_channel_bind(char index)
{
int ret;
Expand Down Expand Up @@ -160,7 +202,7 @@ int v3_pipeline_create(char mirror, char flip)
v3_vpss_grp group;
group.imgEnhOn = 0;
group.dciOn = 0;
group.noiseRedOn = 0;
group.noiseRedOn = 1;
group.histOn = 0;
group.deintMode = 1;
if (ret = v3_vpss.fnCreateGroup(_v3_vpss_grp, &group))
Expand Down
1 change: 1 addition & 0 deletions src/hal/hisi/v3_hal.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "v3_common.h"
#include "v3_aud.h"
#include "v3_config.h"
#include "v3_isp.h"
#include "v3_rgn.h"
Expand Down
2 changes: 1 addition & 1 deletion src/hal/sstar/i6_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ int i6_pipeline_create(char sensor, short width, short height, char framerate)
{
i6_vpe_para param;
param.hdr = I6_HDR_OFF;
param.level3DNR = 0;
param.level3DNR = 1;
param.mirror = 0;
param.flip = 0;
param.lensAdjOn = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/hal/sstar/i6c_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ int i6c_pipeline_create(char sensor, short width, short height, char framerate)
{
i6c_isp_para param;
param.hdr = I6C_HDR_OFF;
param.level3DNR = 0;
param.level3DNR = 1;
param.mirror = 0;
param.flip = 0;
param.rotate = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/hal/sstar/i6f_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ int i6f_pipeline_create(char sensor, short width, short height, char framerate)
{
i6f_isp_para param;
param.hdr = I6F_HDR_OFF;
param.level3DNR = 0;
param.level3DNR = 1;
param.mirror = 0;
param.flip = 0;
param.rotate = 0;
Expand Down
1 change: 1 addition & 0 deletions src/hal/support.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,6 @@ void hal_identify(void) {
plat = HAL_PLATFORM_V3;
chnCount = V3_VENC_CHN_NUM;
chnState = (hal_chnstate*)v3_state;
isp_thread = v3_image_thread;
venc_thread = v3_video_thread;
}

0 comments on commit 7b3db72

Please sign in to comment.