This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 0af7c985b430c164e6f9efcecc8b71533a91c1f8 Author: yangyalei <[email protected]> AuthorDate: Thu May 29 16:31:13 2025 +0800 nuttx/audio: add AUDIOIOC_GETAUDIOINFO ioctl use AUDIOIOC_GETAUDIOINFO get current audio format Signed-off-by: yangyalei <[email protected]> --- audio/audio.c | 66 +++++++++++++++++++++++++++++++++++++-------- include/nuttx/audio/audio.h | 1 + 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/audio/audio.c b/audio/audio.c index 154b8f5f417..62ab35090b9 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -73,11 +73,12 @@ struct audio_upperhalf_s { - uint8_t crefs; /* The number of times the device has been opened */ - volatile bool started; /* True: playback is active */ - mutex_t lock; /* Supports mutual exclusion */ - FAR struct audio_lowerhalf_s *dev; /* lower-half state */ - struct file *usermq; /* User mode app's message queue */ + uint8_t crefs; /* The number of times the device has been opened */ + volatile bool started; /* True: playback is active */ + struct audio_info_s info; /* Record the last playing audio format */ + mutex_t lock; /* Supports mutual exclusion */ + FAR struct audio_lowerhalf_s *dev; /* lower-half state */ + struct file *usermq; /* User mode app's message queue */ }; /**************************************************************************** @@ -292,6 +293,42 @@ static ssize_t audio_write(FAR struct file *filep, return 0; } +/**************************************************************************** + * Name: audio_configure + * + * Description: + * Handle the AUDIOIOC_CONFIGURE ioctl command + * + ****************************************************************************/ + +static int audio_configure(FAR struct audio_upperhalf_s *upper, + FAR const struct audio_caps_desc_s *cap_desc) +{ + FAR struct audio_lowerhalf_s *lower = upper->dev; + FAR const struct audio_caps_s *caps = &cap_desc->caps; + int ret = OK; + + DEBUGASSERT(lower->ops->configure != NULL); + +#ifdef CONFIG_AUDIO_MULTI_SESSION + ret = lower->ops->configure(lower, cap_desc->session, caps); +#else + ret = lower->ops->configure(lower, caps); +#endif + + if (ret == OK && (caps->ac_type == AUDIO_TYPE_INPUT || + caps->ac_type == AUDIO_TYPE_OUTPUT)) + { + upper->info.format = caps->ac_subtype; + upper->info.channels = caps->ac_channels; + upper->info.subformat = caps->ac_controls.b[2]; + upper->info.samplerate = caps->ac_controls.hw[0] | + (caps->ac_controls.b[3] << 16); + } + + return ret; +} + /**************************************************************************** * Name: audio_start * @@ -395,17 +432,12 @@ static int audio_ioctl(FAR struct file *filep, int cmd, unsigned long arg) { FAR const struct audio_caps_desc_s *caps = (FAR const struct audio_caps_desc_s *)((uintptr_t)arg); - DEBUGASSERT(lower->ops->configure != NULL); audinfo("AUDIOIOC_INITIALIZE: Device=%d\n", caps->caps.ac_type); /* Call the lower-half driver configure handler */ -#ifdef CONFIG_AUDIO_MULTI_SESSION - ret = lower->ops->configure(lower, caps->session, &caps->caps); -#else - ret = lower->ops->configure(lower, &caps->caps); -#endif + ret = audio_configure(upper, caps); } break; @@ -649,6 +681,18 @@ static int audio_ioctl(FAR struct file *filep, int cmd, unsigned long arg) } break; + /* AUDIOIOC_GETAUDIOINFO - Get the last playing audio format + * + * ioctl argument - pointer to receive the audio info + */ + + case AUDIOIOC_GETAUDIOINFO: + { + memcpy((void *)arg, &upper->info, sizeof(struct audio_info_s)); + ret = OK; + } + break; + /* Any unrecognized IOCTL commands might be * platform-specific ioctl commands */ diff --git a/include/nuttx/audio/audio.h b/include/nuttx/audio/audio.h index 1d1ae1fe3ff..d6b88af18d6 100644 --- a/include/nuttx/audio/audio.h +++ b/include/nuttx/audio/audio.h @@ -117,6 +117,7 @@ #define AUDIOIOC_GETLATENCY _AUDIOIOC(19) #define AUDIOIOC_FLUSH _AUDIOIOC(20) #define AUDIOIOC_GETPOSITION _AUDIOIOC(21) +#define AUDIOIOC_GETAUDIOINFO _AUDIOIOC(22) /* Audio Device Types *******************************************************/
