This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new df418bea8 system/audio: check if channels are valid
df418bea8 is described below
commit df418bea8127bb98581071071c10872d239598df
Author: jinxiuxu <[email protected]>
AuthorDate: Mon May 22 16:06:47 2023 +0800
system/audio: check if channels are valid
check ac_channels upper four bits which means min channels.
Signed-off-by: jinxiuxu <[email protected]>
---
system/nxlooper/nxlooper.c | 18 ++++++++++++++++++
system/nxplayer/nxplayer.c | 18 ++++++++++++++++++
system/nxrecorder/nxrecorder.c | 18 ++++++++++++++++++
3 files changed, 54 insertions(+)
diff --git a/system/nxlooper/nxlooper.c b/system/nxlooper/nxlooper.c
index 452dd6d18..683a18c40 100644
--- a/system/nxlooper/nxlooper.c
+++ b/system/nxlooper/nxlooper.c
@@ -993,6 +993,8 @@ int nxlooper_loopback(FAR struct nxlooper_s *plooper, int
format,
pthread_attr_t tattr;
struct audio_caps_desc_s cap_desc;
struct ap_buffer_info_s buf_info;
+ struct audio_caps_s caps;
+ int min_channels;
int ret;
DEBUGASSERT(plooper != NULL);
@@ -1051,6 +1053,22 @@ int nxlooper_loopback(FAR struct nxlooper_s *plooper,
int format,
goto err_out_record;
}
+ caps.ac_len = sizeof(caps);
+ caps.ac_type = AUDIO_TYPE_INPUT;
+ caps.ac_subtype = AUDIO_TYPE_QUERY;
+
+ if (ioctl(plooper->recorddev_fd, AUDIOIOC_GETCAPS,
+ (unsigned long)&caps) == caps.ac_len)
+ {
+ min_channels = caps.ac_channels >> 4;
+
+ if (min_channels != 0 && nchannels < min_channels)
+ {
+ ret = -EINVAL;
+ goto err_out;
+ }
+ }
+
#ifdef CONFIG_AUDIO_MULTI_SESSION
cap_desc.session = plooper->precordses;
#endif
diff --git a/system/nxplayer/nxplayer.c b/system/nxplayer/nxplayer.c
index 14aa0134f..77a1d5913 100644
--- a/system/nxplayer/nxplayer.c
+++ b/system/nxplayer/nxplayer.c
@@ -1777,6 +1777,8 @@ static int nxplayer_playinternal(FAR struct nxplayer_s
*pplayer,
pthread_attr_t tattr;
struct audio_caps_desc_s cap_desc;
struct ap_buffer_info_s buf_info;
+ struct audio_caps_s caps;
+ int min_channels;
#ifdef CONFIG_NXPLAYER_INCLUDE_MEDIADIR
char path[PATH_MAX];
#endif
@@ -1917,6 +1919,22 @@ static int nxplayer_playinternal(FAR struct nxplayer_s
*pplayer,
goto err_out;
}
+ caps.ac_len = sizeof(caps);
+ caps.ac_type = AUDIO_TYPE_OUTPUT;
+ caps.ac_subtype = AUDIO_TYPE_QUERY;
+
+ if (ioctl(pplayer->dev_fd, AUDIOIOC_GETCAPS,
+ (unsigned long)&caps) == caps.ac_len)
+ {
+ min_channels = caps.ac_channels >> 4;
+
+ if (min_channels != 0 && nchannels < min_channels)
+ {
+ ret = -EINVAL;
+ goto err_out;
+ }
+ }
+
if (nchannels && samprate && bpsamp)
{
#ifdef CONFIG_AUDIO_MULTI_SESSION
diff --git a/system/nxrecorder/nxrecorder.c b/system/nxrecorder/nxrecorder.c
index fc6b21e8b..7f5bdbd06 100644
--- a/system/nxrecorder/nxrecorder.c
+++ b/system/nxrecorder/nxrecorder.c
@@ -1015,6 +1015,8 @@ int nxrecorder_recordinternal(FAR struct nxrecorder_s
*precorder,
pthread_attr_t tattr;
struct audio_caps_desc_s cap_desc;
struct ap_buffer_info_s buf_info;
+ struct audio_caps_s caps;
+ int min_channels;
int ret;
int subfmt = AUDIO_FMT_UNDEF;
@@ -1084,6 +1086,22 @@ int nxrecorder_recordinternal(FAR struct nxrecorder_s
*precorder,
goto err_out;
}
+ caps.ac_len = sizeof(caps);
+ caps.ac_type = AUDIO_TYPE_INPUT;
+ caps.ac_subtype = AUDIO_TYPE_QUERY;
+
+ if (ioctl(precorder->dev_fd, AUDIOIOC_GETCAPS,
+ (unsigned long)&caps) == caps.ac_len)
+ {
+ min_channels = caps.ac_channels >> 4;
+
+ if (min_channels != 0 && nchannels < min_channels)
+ {
+ ret = -EINVAL;
+ goto err_out;
+ }
+ }
+
#ifdef CONFIG_AUDIO_MULTI_SESSION
cap_desc.session = precorder->session;
#endif