mirror of
https://github.com/apache/nuttx.git
synced 2026-05-20 12:33:27 +08:00
nuttx/audio: add AUDIOIOC_GETAUDIOINFO ioctl
use AUDIOIOC_GETAUDIOINFO get current audio format Signed-off-by: yangyalei <yangyalei@xiaomi.com>
This commit is contained in:
+55
-11
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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 *******************************************************/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user