system/audio: check if channels are valid
check ac_channels upper four bits which means min channels. Signed-off-by: jinxiuxu <jinxiuxu@xiaomi.com>
This commit is contained in:
parent
eb36c15171
commit
df418bea81
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user