Skip to content

Commit

Permalink
Adding audio config specifics
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Jun 25, 2024
1 parent 4e464c4 commit 72d412b
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 22 deletions.
6 changes: 5 additions & 1 deletion divinus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ http_post:
login: <your login>
password: <yout pass>

audio:
enable: false
srate: 8000

rtsp:
enable: true

Expand All @@ -74,4 +78,4 @@ mjpeg:
width: 3840
height: 2160
fps: 20
bitrate: 1024
bitrate: 1024
13 changes: 10 additions & 3 deletions src/app_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum ConfigError parse_app_config(void) {
app_config.rtsp_enable = false;

app_config.sensor_config[0] = 0;
app_config.audio_enable = false;
app_config.jpeg_enable = false;
app_config.mp4_enable = false;

Expand Down Expand Up @@ -134,9 +135,15 @@ enum ConfigError parse_app_config(void) {
if (err != CONFIG_OK)
goto RET_ERR;

err = parse_bool(&ini, "mp4", "enable", &app_config.mp4_enable);
if (err != CONFIG_OK)
goto RET_ERR;
parse_bool(&ini, "audio", "enable", &app_config.audio_enable);
if (app_config.audio_enable) {
parse_int(&ini, "audio", "srate", 8000, 48000,
&app_config.audio_srate);
if (err != CONFIG_OK)
goto RET_ERR;
}

parse_bool(&ini, "mp4", "enable", &app_config.mp4_enable);
if (app_config.mp4_enable) {
{
const char *possible_values[] = {"H.264", "H.265", "H264", "H265", "AVC", "HEVC"};
Expand Down
4 changes: 4 additions & 0 deletions src/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ struct AppConfig {
bool osd_enable;
bool rtsp_enable;

// [audio]
bool audio_enable;
unsigned int audio_srate;

// [video_0]
bool mp4_enable;
bool mp4_codecH265;
Expand Down
4 changes: 2 additions & 2 deletions src/hal/hisi/v3_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ void v3_audio_deinit(void)
v3_aud.fnDisableDevice(_v3_aud_dev);
}

int v3_audio_init(void)
int v3_audio_init(short samplerate)
{
int ret;

{
v3_aud_cnf config;
config.rate = 8000;
config.rate = samplerate;
config.bit = V3_AUD_BIT_16;
config.intf = V3_AUD_INTF_I2S_MASTER;
config.stereoOn = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/hal/hisi/v3_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void v3_hal_deinit(void);
int v3_hal_init(void);

void v3_audio_deinit(void);
int v3_audio_init(void);
int v3_audio_init(short samplerate);
void *v3_audio_thread(void);

int v3_channel_bind(char index);
Expand Down
4 changes: 2 additions & 2 deletions src/hal/hisi/v4_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ void v4_audio_deinit(void)
v4_aud.fnDisableDevice(_v4_aud_dev);
}

int v4_audio_init(void)
int v4_audio_init(short samplerate)
{
int ret;

{
v4_aud_cnf config;
config.rate = 8000;
config.rate = samplerate;
config.bit = V4_AUD_BIT_16;
config.intf = V4_AUD_INTF_I2S_MASTER;
config.stereoOn = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/hal/hisi/v4_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int v4_hal_init(void);
void *v4_audio_thread(void);

void v4_audio_deinit(void);
int v4_audio_init(void);
int v4_audio_init(short samplerate);

int v4_channel_bind(char index);
int v4_channel_create(char index, char mirror, char flip, char framerate);
Expand Down
4 changes: 2 additions & 2 deletions src/hal/inge/t31_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ void t31_audio_deinit(void)
t31_aud.fnDisableDevice(_t31_aud_dev);
}

int t31_audio_init(void)
int t31_audio_init(short samplerate)
{
int ret;

{
t31_aud_cnf config;
config.rate = 48000;
config.rate = samplerate;
config.bit = T31_AUD_BIT_16;
config.mode = T31_AUD_SND_MONO;
config.frmNum = 40;
Expand Down
2 changes: 1 addition & 1 deletion src/hal/inge/t31_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void t31_hal_deinit(void);
int t31_hal_init(void);

void t31_audio_deinit(void);
int t31_audio_init(void);
int t31_audio_init(short samplerate);

int t31_channel_bind(char index);
int t31_channel_create(char index, short width, short height, char framerate);
Expand Down
4 changes: 2 additions & 2 deletions src/hal/star/i6_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ void i6_audio_deinit(void)
i6_aud.fnDisableDevice(_i6_aud_dev);
}

int i6_audio_init(void)
int i6_audio_init(short samplerate)
{
int ret;

{
i6_aud_cnf config;
config.rate = 8000;
config.rate = samplerate;
config.bit24On = 0;
config.intf = I6_AUD_INTF_I2S_SLAVE;
config.sound = I6_AUD_SND_MONO;
Expand Down
2 changes: 1 addition & 1 deletion src/hal/star/i6_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int i6_hal_init(void);
void *i6_audio_thread(void);

void i6_audio_deinit(void);
int i6_audio_init(void);
int i6_audio_init(short samplerate);

int i6_channel_bind(char index, char framerate);
int i6_channel_create(char index, short width, short height, char mirror, char flip, char jpeg);
Expand Down
4 changes: 2 additions & 2 deletions src/hal/star/i6c_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ void i6c_audio_deinit(void)
i6c_aud.fnDisableDevice(_i6c_aud_dev);
}

int i6c_audio_init(void)
int i6c_audio_init(short samplerate)
{
int ret;

{
i6c_aud_cnf config;
config.reserved = 0;
config.sound = I6C_AUD_SND_MONO;
config.rate = 8000;
config.rate = samplerate;
config.periodSize = 0x400;
config.interleavedOn = 0;
if (ret = i6c_aud.fnEnableDevice(_i6c_aud_dev, &config))
Expand Down
2 changes: 1 addition & 1 deletion src/hal/star/i6c_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void i6c_hal_deinit(void);
int i6c_hal_init(void);

void i6c_audio_deinit(void);
int i6c_audio_init(void);
int i6c_audio_init(short samplerate);
void *i6c_audio_thread(void);

int i6c_channel_bind(char index, char framerate);
Expand Down
4 changes: 2 additions & 2 deletions src/hal/star/i6f_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ void i6f_audio_deinit(void)
}


int i6f_audio_init(void)
int i6f_audio_init(short samplerate)
{
int ret;

{
i6f_aud_cnf config;
config.rate = 8000;
config.rate = samplerate;
config.bit = I6F_AUD_BIT_16;
config.intf = I6F_AUD_INTF_I2S_SLAVE;
config.sound = I6F_AUD_SND_MONO;
Expand Down
2 changes: 1 addition & 1 deletion src/hal/star/i6f_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void i6f_hal_deinit(void);
int i6f_hal_init(void);

void i6f_audio_deinit(void);
int i6f_audio_init(void);
int i6f_audio_init(short samplerate);
void *i6f_audio_thread(void);

int i6f_channel_bind(char index, char framerate);
Expand Down
57 changes: 57 additions & 0 deletions src/media.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ pthread_t vidPid = 0;
int save_audio_stream(hal_audframe *frame) {
int ret = EXIT_SUCCESS;

#ifdef DEBUG
printf("[audio] data:%p - %02x %02x %02x %02x %02x %02x %02x %02x\n",
frame->data, frame->data[0][0], frame->data[0][1], frame->data[0][2], frame->data[0][3],
frame->data[0][4], frame->data[0][5], frame->data[0][6], frame->data[0][7]);
printf(" len:%d\n", frame->length);
printf(" seq:%d\n", frame->seq);
printf(" ts:%d\n", frame->timestamp);
#endif

return ret;
}

Expand Down Expand Up @@ -438,6 +447,41 @@ int start_sdk(void) {
return EXIT_FAILURE;
}

if (app_config.audio_enable) switch (plat) {
#if defined(__arm__)
case HAL_PLATFORM_I6: ret = i6_audio_init(app_config.audio_srate); break;
case HAL_PLATFORM_I6C: ret = i6c_audio_init(app_config.audio_srate); break;
case HAL_PLATFORM_I6F: ret = i6f_audio_init(app_config.audio_srate); break;
case HAL_PLATFORM_V3: ret = v3_audio_init(app_config.audio_srate); break;
case HAL_PLATFORM_V4: ret = v4_audio_init(app_config.audio_srate); break;
#endif
}
if (ret) {
fprintf(stderr, "Audio initialization failed with %#x!\n%s\n",
ret, errstr(ret));
return EXIT_FAILURE;
}

if (app_config.audio_enable) {
pthread_attr_t thread_attr;
pthread_attr_init(&thread_attr);
size_t stacksize;
pthread_attr_getstacksize(&thread_attr, &stacksize);
size_t new_stacksize = app_config.venc_stream_thread_stack_size;
if (pthread_attr_setstacksize(&thread_attr, new_stacksize)) {
fprintf(stderr, "Can't set stack size %zu\n", new_stacksize);
}
if (pthread_create(
&audPid, &thread_attr, (void *(*)(void *))aud_thread, NULL)) {
fprintf(stderr, "Starting the audio encoding thread failed!\n");
return EXIT_FAILURE;
}
if (pthread_attr_setstacksize(&thread_attr, stacksize)) {
fprintf(stderr, "Can't set stack size %zu\n", stacksize);
}
pthread_attr_destroy(&thread_attr);
}

short width = MAX(app_config.mp4_width, app_config.mjpeg_width);
short height = MAX(app_config.mp4_height, app_config.mjpeg_height);
short framerate = MAX(app_config.mp4_fps, app_config.mjpeg_fps);
Expand Down Expand Up @@ -577,6 +621,9 @@ int stop_sdk(void) {
#endif
}

if (app_config.audio_enable)
pthread_join(audPid, NULL);

if (isp_thread)
pthread_join(ispPid, NULL);

Expand All @@ -593,6 +640,16 @@ int stop_sdk(void) {
#endif
}

if (app_config.audio_enable) switch (plat) {
#if defined(__arm__)
case HAL_PLATFORM_I6: i6_audio_deinit(); break;
case HAL_PLATFORM_I6C: i6c_audio_deinit(); break;
case HAL_PLATFORM_I6F: i6f_audio_deinit(); break;
case HAL_PLATFORM_V3: v3_audio_deinit(); break;
case HAL_PLATFORM_V4: v4_audio_deinit(); break;
#endif
}

switch (plat) {
#if defined(__arm__)
case HAL_PLATFORM_V3: v3_sensor_deinit(); break;
Expand Down

0 comments on commit 72d412b

Please sign in to comment.