* [maixcam2] fix fps() return error value

* [maixcam2] add scale param to limit audio volume
* update libmaixcam_lib
This commit is contained in:
lxowalle
2025-12-22 10:36:41 +08:00
parent b7ed4bafee
commit c5f9b791c3
7 changed files with 67 additions and 7 deletions

View File

@@ -8,7 +8,7 @@ if (compile_from_src)
set(libdatachannel_version_str "${CONFIG_LIBDATACHANNEL_VERSION_MAJOR}.${CONFIG_LIBDATACHANNEL_VERSION_MINOR}.${CONFIG_LIBDATACHANNEL_VERSION_PATCH}")
set(srcs_path "${DL_EXTRACTED_PATH}/libdatachannel_srcs/libdatachannel-${libdatachannel_version_str}")
list(APPEND ADD_INCLUDE "${srcs_path}/include" ".")
list(APPEND ADD_PRIVATE_INCLUDE "${srcs_path}/include/rtc" "${srcs_path}/src")
list(APPEND ADD_PRIVATE_INCLUDE "${srcs_path}/include" "${srcs_path}/src")
if(PLATFORM_MAIXCAM)
list(APPEND ADD_SRCS "private/atomic.cpp")

View File

@@ -1271,37 +1271,67 @@ namespace maix::middleware::maixcam2 {
return 0;
}
static SAMPLE_VIN_CASE_E __get_vi_case(char *sensor_name, int w = -1, int h = -1, int fps = 30) {
static SAMPLE_VIN_CASE_E __get_vi_case(char *sensor_name, int &w, int &h, int &fps) {
if (strcmp(sensor_name, "os04a10") == 0) {
w = 2688;
h = 1520;
fps = 30;
return SAMPLE_VIN_SINGLE_OS04A10;
} else if (strcmp(sensor_name, "sc450ai") == 0) {
w = 2688;
h = 1520;
fps = 30;
return SAMPLE_VIN_SINGLE_SC450AI;
} else if (strcmp(sensor_name, "sc850sl") == 0) {
if (w == -1 || h == -1) {
w = 3840;
h = 2160;
fps = 30;
return SAMPLE_VIN_SINGLE_SC850SL;
}
if (fps > 30 || fps <= 0) {
if (w > 1920 || h > 1080) {
w = 3840;
h = 2160;
fps = 30;
return SAMPLE_VIN_SINGLE_SC850SL;
} else {
w = 1920;
h = 1080;
fps = 60;
return SAMPLE_VIN_SINGLE_SC850SL_1080P60;
}
} else {
w = 3840;
h = 2160;
fps = 30;
return SAMPLE_VIN_SINGLE_SC850SL;
}
} else if (strcmp(sensor_name, "os04d10") == 0) {
if (w == -1 || h == -1) {
w = 2560;
h = 1440;
fps = 30;
return SAMPLE_VIN_SINGLE_OS04D10;
}
if (fps > 30 || fps <= 0) {
if (w > 1280 || h > 720) {
w = 2560;
h = 1440;
fps = 30;
return SAMPLE_VIN_SINGLE_OS04D10;
} else {
w = 1280;
h = 720;
fps = 60;
return SAMPLE_VIN_SINGLE_OS04D10_720P60;
}
} else {
w = 2560;
h = 1440;
fps = 30;
return SAMPLE_VIN_SINGLE_OS04D10;
}
} else {
@@ -1485,7 +1515,9 @@ namespace maix::middleware::maixcam2 {
log::error("get sensor name failed");
return err::ERR_RUNTIME;
}
tVinParam.eSysCase = __get_vi_case((char *)get_sensor_res.second.c_str());
int w = -1, h = -1, fps = 30;
tVinParam.eSysCase = __get_vi_case((char *)get_sensor_res.second.c_str(), w, h, fps);
// check if enable ai-isp
AX_BOOL ai_isp_on = app::get_sys_config_kv("npu", "ai_isp", "1") == "1" ? AX_TRUE : AX_FALSE;
@@ -1601,7 +1633,7 @@ namespace maix::middleware::maixcam2 {
return __get_sensor_name();
}
SAMPLE_VIN_CASE_E get_vi_case(char *sensor_name, int w, int h, int fps) {
SAMPLE_VIN_CASE_E get_vi_case(char *sensor_name, int &w, int &h, int &fps) {
return __get_vi_case(sensor_name, w, h, fps);
}

View File

@@ -533,7 +533,10 @@ namespace maix::camera
log::error("get sensor name failed");
return err::ERR_RUNTIME;
}
tVinParam.eSysCase = ax_vi->get_vi_case((char *)get_sensor_res.second.c_str(), _width, _height, _fps);
int tmp_w = _width, tmp_h = _height, tmp_fps = _fps;
tVinParam.eSysCase = ax_vi->get_vi_case((char *)get_sensor_res.second.c_str(), tmp_w, tmp_h, tmp_fps);
_fps = tmp_fps;
tVinParam.bAiispEnable = app::get_sys_config_kv("npu", "ai_isp", "1") == "1" ? AX_TRUE : AX_FALSE;
ax_vi->config_sample_case(&tVinParam, &tCommonArgs, &tPrivArgs);
err = ax_vi->init();

View File

@@ -152,6 +152,8 @@ namespace maix::audio
FILE *file = nullptr;
wav_header_t wav_header;
bool block;
double volume_scale;
} audio_param_t;
enum pcm_format to_tinyalsa_format(audio::Format format) {
@@ -289,6 +291,9 @@ namespace maix::audio
}
}
param->volume_scale = atof(app::get_sys_config_kv("audio", "input_volume_scale", "1.0").c_str());
param->volume_scale = param->volume_scale > 1.0 ? 1.0 : param->volume_scale;
param->volume_scale = param->volume_scale < 0.01 ? 0.01 : param->volume_scale;
_param = param;
}
@@ -348,6 +353,7 @@ namespace maix::audio
if (!mixer) {
err::check_raise(err::ERR_RUNTIME, "Open mixer failed");
}
value = value * param->volume_scale;
auto ctl = mixer_get_ctl_by_name_and_device(mixer, "ADC Capture Volume", param->device);
if (!ctl) {
@@ -369,7 +375,7 @@ namespace maix::audio
curr_volume = dist_volume;
}
curr_volume = (int)((double)curr_volume / param->volume_scale);
mixer_close(mixer);
return curr_volume;
}
@@ -672,6 +678,10 @@ namespace maix::audio
pcm_close(param->pcm);
err::check_raise(err::ERR_RUNTIME, "failed to open PCM");
}
param->volume_scale = atof(app::get_sys_config_kv("audio", "output_volume_scale", "1.0").c_str());
param->volume_scale = param->volume_scale > 1.0 ? 1.0 : param->volume_scale;
param->volume_scale = param->volume_scale < 0.01 ? 0.01 : param->volume_scale;
_param = param;
}
@@ -706,6 +716,7 @@ namespace maix::audio
err::check_raise(err::ERR_RUNTIME, "Get mixer volume ctl failed");
}
value = value * param->volume_scale;
auto num_values = mixer_ctl_get_num_values(ctl);
auto curr_volume = mixer_ctl_get_percent(ctl, 0);
curr_volume = 100 - curr_volume;
@@ -722,7 +733,7 @@ namespace maix::audio
curr_volume = 100 - dist_volume;
}
curr_volume = (int)((double)curr_volume / param->volume_scale);
mixer_close(mixer);
return curr_volume;
}

View File

@@ -241,6 +241,8 @@ namespace maix::audio
int user_period_size;
int user_period_count;
double volume_scale;
} audio_param_t;
static AX_AUDIO_BIT_WIDTH_E __maix_to_ax_fmt(audio::Format format) {
@@ -346,6 +348,10 @@ namespace maix::audio
delete param;
err::check_raise(ret, "initializing AudioIn failed");
}
param->volume_scale = atof(app::get_sys_config_kv("audio", "input_volume_scale", "1.0").c_str());
param->volume_scale = param->volume_scale > 1.0 ? 1.0 : param->volume_scale;
param->volume_scale = param->volume_scale < 0.01 ? 0.01 : param->volume_scale;
_param = param;
int new_volume = atoi(app::get_sys_config_kv("audio", "input_volume", "-1").c_str());
@@ -408,10 +414,13 @@ namespace maix::audio
int Recorder::volume(int value) {
audio_param_t *param = (audio_param_t *)_param;
value = value * param->volume_scale;
if (param->ax_ai) {
auto f_value = __volume_int_to_float(value);
auto new_volume = param->ax_ai->volume(f_value);
auto new_volume_int = __volume_float_to_int(new_volume);
new_volume_int = (int)((double)new_volume_int / param->volume_scale);
if (value >= 0) {
app::set_sys_config_kv("audio", "input_volume", std::to_string(new_volume_int));
}
@@ -799,6 +808,9 @@ namespace maix::audio
auto ringbuffer_size = pcm_frame_to_bytes(param->channels, param->bits, period_size)* period_count;
param->ring_buffer = std::make_unique<RingBuffer>(ringbuffer_size);
param->thread_handle = std::make_unique<std::thread>(player_thread, param);
param->volume_scale = atof(app::get_sys_config_kv("audio", "output_volume_scale", "1.0").c_str());
param->volume_scale = param->volume_scale > 1.0 ? 1.0 : param->volume_scale;
param->volume_scale = param->volume_scale < 0.01 ? 0.01 : param->volume_scale;
_param = param;
int new_volume = atoi(app::get_sys_config_kv("audio", "output_volume", "-1").c_str());
@@ -841,10 +853,12 @@ namespace maix::audio
int Player::volume(int value) {
audio_param_t *param = (audio_param_t *)_param;
value = value * param->volume_scale;
if (param->ax_ao) {
auto f_value = __volume_int_to_float(value);
auto new_volume = param->ax_ao->volume(f_value);
auto new_volume_int = __volume_float_to_int(new_volume);
new_volume_int = (int)((double)new_volume_int / param->volume_scale);
if (value >= 0) {
app::set_sys_config_kv("audio", "output_volume", std::to_string(new_volume_int));
}