From 63774125d92c356c66023ca5460b108cd8f69bdf Mon Sep 17 00:00:00 2001 From: libei1 Date: Thu, 15 Jun 2023 20:14:50 +0800 Subject: [PATCH] arch/sim : Audio driver add AUDIOIOC_GETLATENCY ioctl add AUDIOIOC_GETLATENCY definition, and add reference code in sim alsa. Signed-off-by: libei1 --- arch/sim/src/sim/posix/sim_alsa.c | 32 +++++++++++++++++++++++++++++++ include/nuttx/audio/audio.h | 1 + 2 files changed, 33 insertions(+) diff --git a/arch/sim/src/sim/posix/sim_alsa.c b/arch/sim/src/sim/posix/sim_alsa.c index cf77448d80..640f824374 100644 --- a/arch/sim/src/sim/posix/sim_alsa.c +++ b/arch/sim/src/sim/posix/sim_alsa.c @@ -600,6 +600,38 @@ static int sim_audio_ioctl(struct audio_lowerhalf_s *dev, int cmd, audinfo("%s , arg: %s\n", __func__, (char *)arg); } break; + case AUDIOIOC_GETLATENCY: + { + long *latency = (long *)arg; + long remain = 0; + dq_entry_t *cur; + + if (!priv->pcm) + { + ret = -ENXIO; + break; + } + + ret = snd_pcm_delay(priv->pcm, latency); + if (ret < 0) + { + return ret; + } + else + { + remain = priv->aux->nbytes - priv->aux->curbyte; + + for (cur = dq_peek(&priv->pendq); cur; cur = dq_next(cur)) + { + struct ap_buffer_s *apb = (struct ap_buffer_s *)cur; + remain += apb->nbytes - apb->curbyte; + } + + *latency += remain / priv->frame_size; + } + } + break; + default: ret = -ENOTTY; break; diff --git a/include/nuttx/audio/audio.h b/include/nuttx/audio/audio.h index 7bb3021f98..49124360ff 100644 --- a/include/nuttx/audio/audio.h +++ b/include/nuttx/audio/audio.h @@ -112,6 +112,7 @@ #define AUDIOIOC_HWRESET _AUDIOIOC(16) #define AUDIOIOC_SETBUFFERINFO _AUDIOIOC(17) #define AUDIOIOC_SETPARAMTER _AUDIOIOC(18) +#define AUDIOIOC_GETLATENCY _AUDIOIOC(19) /* Audio Device Types *******************************************************/