mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
audio: nxstyle fixes for core and drivers
nxstyle fixes for the audio core and drivers Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
This commit is contained in:
+70
-41
@@ -68,6 +68,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/* Debug ********************************************************************/
|
||||
|
||||
/* Non-standard debug that may be enabled just for testing Audio */
|
||||
|
||||
#ifndef AUDIO_MAX_DEVICE_PATH
|
||||
@@ -86,11 +87,11 @@
|
||||
|
||||
struct audio_upperhalf_s
|
||||
{
|
||||
uint8_t crefs; /* The number of times the device has been opened */
|
||||
volatile bool started; /* True: playback is active */
|
||||
sem_t exclsem; /* Supports mutual exclusion */
|
||||
uint8_t crefs; /* The number of times the device has been opened */
|
||||
volatile bool started; /* True: playback is active */
|
||||
sem_t exclsem; /* Supports mutual exclusion */
|
||||
FAR struct audio_lowerhalf_s *dev; /* lower-half state */
|
||||
mqd_t usermq; /* User mode app's message queue */
|
||||
mqd_t usermq; /* User mode app's message queue */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
@@ -99,17 +100,29 @@ struct audio_upperhalf_s
|
||||
|
||||
static int audio_open(FAR struct file *filep);
|
||||
static int audio_close(FAR struct file *filep);
|
||||
static ssize_t audio_read(FAR struct file *filep, FAR char *buffer, size_t buflen);
|
||||
static ssize_t audio_write(FAR struct file *filep, FAR const char *buffer, size_t buflen);
|
||||
static int audio_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
|
||||
static ssize_t audio_read(FAR struct file *filep,
|
||||
FAR char *buffer,
|
||||
size_t buflen);
|
||||
static ssize_t audio_write(FAR struct file *filep,
|
||||
FAR const char *buffer,
|
||||
size_t buflen);
|
||||
static int audio_ioctl(FAR struct file *filep,
|
||||
int cmd,
|
||||
unsigned long arg);
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
static int audio_start(FAR struct audio_upperhalf_s *upper, FAR void *session);
|
||||
static void audio_callback(FAR void *priv, uint16_t reason,
|
||||
FAR struct ap_buffer_s *apb, uint16_t status, FAR void *session);
|
||||
static int audio_start(FAR struct audio_upperhalf_s *upper,
|
||||
FAR void *session);
|
||||
static void audio_callback(FAR void *priv,
|
||||
uint16_t reason,
|
||||
FAR struct ap_buffer_s *apb,
|
||||
uint16_t status,
|
||||
FAR void *session);
|
||||
#else
|
||||
static int audio_start(FAR struct audio_upperhalf_s *upper);
|
||||
static void audio_callback(FAR void *priv, uint16_t reason,
|
||||
FAR struct ap_buffer_s *apb, uint16_t status);
|
||||
static void audio_callback(FAR void *priv,
|
||||
uint16_t reason,
|
||||
FAR struct ap_buffer_s *apb,
|
||||
uint16_t status);
|
||||
#endif /* CONFIG_AUDIO_MULTI_SESSION */
|
||||
|
||||
/****************************************************************************
|
||||
@@ -131,13 +144,13 @@ static const struct file_operations g_audioops =
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: audio_open
|
||||
*
|
||||
* Description:
|
||||
* This function is called whenever the Audio device is opened.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int audio_open(FAR struct file *filep)
|
||||
{
|
||||
@@ -184,13 +197,13 @@ errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: audio_close
|
||||
*
|
||||
* Description:
|
||||
* This function is called when the Audio device is closed.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int audio_close(FAR struct file *filep)
|
||||
{
|
||||
@@ -241,15 +254,17 @@ errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: audio_read
|
||||
*
|
||||
* Description:
|
||||
* A dummy read method. This is provided only to satsify the VFS layer.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t audio_read(FAR struct file *filep, FAR char *buffer, size_t buflen)
|
||||
static ssize_t audio_read(FAR struct file *filep,
|
||||
FAR char *buffer,
|
||||
size_t buflen)
|
||||
{
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct audio_upperhalf_s *upper = inode->i_private;
|
||||
@@ -267,15 +282,17 @@ static ssize_t audio_read(FAR struct file *filep, FAR char *buffer, size_t bufle
|
||||
return 0;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: audio_write
|
||||
*
|
||||
* Description:
|
||||
* A dummy write method. This is provided only to satsify the VFS layer.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t audio_write(FAR struct file *filep, FAR const char *buffer, size_t buflen)
|
||||
static ssize_t audio_write(FAR struct file *filep,
|
||||
FAR const char *buffer,
|
||||
size_t buflen)
|
||||
{
|
||||
FAR struct inode *inode = filep->f_inode;
|
||||
FAR struct audio_upperhalf_s *upper = inode->i_private;
|
||||
@@ -293,16 +310,17 @@ static ssize_t audio_write(FAR struct file *filep, FAR const char *buffer, size_
|
||||
return 0;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: audio_start
|
||||
*
|
||||
* Description:
|
||||
* Handle the AUDIOIOC_START ioctl command
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
static int audio_start(FAR struct audio_upperhalf_s *upper, FAR void *session)
|
||||
static int audio_start(FAR struct audio_upperhalf_s *upper,
|
||||
FAR void *session)
|
||||
#else
|
||||
static int audio_start(FAR struct audio_upperhalf_s *upper)
|
||||
#endif
|
||||
@@ -339,13 +357,13 @@ static int audio_start(FAR struct audio_upperhalf_s *upper)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
/****************************************************************************
|
||||
* Name: audio_ioctl
|
||||
*
|
||||
* Description:
|
||||
* The standard ioctl method. This is where ALL of the Audio work is done.
|
||||
*
|
||||
************************************************************************************/
|
||||
****************************************************************************/
|
||||
|
||||
static int audio_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
{
|
||||
@@ -379,7 +397,8 @@ static int audio_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
|
||||
case AUDIOIOC_GETCAPS:
|
||||
{
|
||||
FAR struct audio_caps_s *caps = (FAR struct audio_caps_s *)((uintptr_t)arg);
|
||||
FAR struct audio_caps_s *caps =
|
||||
(FAR struct audio_caps_s *)((uintptr_t)arg);
|
||||
DEBUGASSERT(lower->ops->getcaps != NULL);
|
||||
|
||||
audinfo("AUDIOIOC_GETCAPS: Device=%d\n", caps->ac_type);
|
||||
@@ -420,7 +439,8 @@ static int audio_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
}
|
||||
break;
|
||||
|
||||
/* AUDIOIOC_START - Start the audio stream. The AUDIOIOC_SETCHARACTERISTICS
|
||||
/* AUDIOIOC_START - Start the audio stream.
|
||||
* The AUDIOIOC_SETCHARACTERISTICS
|
||||
* command must have previously been sent.
|
||||
*
|
||||
* ioctl argument: Audio session
|
||||
@@ -647,7 +667,9 @@ static int audio_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
||||
}
|
||||
break;
|
||||
|
||||
/* Any unrecognized IOCTL commands might be platform-specific ioctl commands */
|
||||
/* Any unrecognized IOCTL commands might be
|
||||
* platform-specific ioctl commands
|
||||
*/
|
||||
|
||||
default:
|
||||
{
|
||||
@@ -711,8 +733,8 @@ static inline void audio_dequeuebuffer(FAR struct audio_upperhalf_s *upper,
|
||||
|
||||
if (upper->usermq != NULL)
|
||||
{
|
||||
msg.msgId = AUDIO_MSG_DEQUEUE;
|
||||
msg.u.pPtr = apb;
|
||||
msg.msg_id = AUDIO_MSG_DEQUEUE;
|
||||
msg.u.ptr = apb;
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
msg.session = session;
|
||||
#endif
|
||||
@@ -750,8 +772,8 @@ static inline void audio_complete(FAR struct audio_upperhalf_s *upper,
|
||||
upper->started = false;
|
||||
if (upper->usermq != NULL)
|
||||
{
|
||||
msg.msgId = AUDIO_MSG_COMPLETE;
|
||||
msg.u.pPtr = NULL;
|
||||
msg.msg_id = AUDIO_MSG_COMPLETE;
|
||||
msg.u.ptr = NULL;
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
msg.session = session;
|
||||
#endif
|
||||
@@ -823,7 +845,8 @@ static void audio_callback(FAR void *handle, uint16_t reason,
|
||||
FAR struct ap_buffer_s *apb, uint16_t status)
|
||||
#endif
|
||||
{
|
||||
FAR struct audio_upperhalf_s *upper = (FAR struct audio_upperhalf_s *)handle;
|
||||
FAR struct audio_upperhalf_s *upper =
|
||||
(FAR struct audio_upperhalf_s *)handle;
|
||||
|
||||
audinfo("Entry\n");
|
||||
|
||||
@@ -854,7 +877,9 @@ static void audio_callback(FAR void *handle, uint16_t reason,
|
||||
|
||||
case AUDIO_CALLBACK_COMPLETE:
|
||||
{
|
||||
/* Send a complete message to the user if a message queue is registered */
|
||||
/* Send a complete message to the user if a message queue
|
||||
* is registered
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
audio_complete(upper, apb, status, session);
|
||||
@@ -902,9 +927,9 @@ static void audio_callback(FAR void *handle, uint16_t reason,
|
||||
* filesystem. The recommended convention is to name Audio drivers
|
||||
* based on the function they provide, such as "/dev/pcm0", "/dev/mp31",
|
||||
* etc.
|
||||
* dev - A pointer to an instance of lower half audio driver. This instance
|
||||
* is bound to the Audio driver and must persists as long as the driver
|
||||
* persists.
|
||||
* dev - A pointer to an instance of lower half audio driver.
|
||||
* This instance is bound to the Audio driver and must persists as long
|
||||
* as the driver persists.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
@@ -926,14 +951,17 @@ int audio_register(FAR const char *name, FAR struct audio_lowerhalf_s *dev)
|
||||
|
||||
/* Allocate the upper-half data structure */
|
||||
|
||||
upper = (FAR struct audio_upperhalf_s *)kmm_zalloc(sizeof(struct audio_upperhalf_s));
|
||||
upper = (FAR struct audio_upperhalf_s *)kmm_zalloc(
|
||||
sizeof(struct audio_upperhalf_s));
|
||||
if (!upper)
|
||||
{
|
||||
auderr("ERROR: Allocation failed\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Initialize the Audio device structure (it was already zeroed by kmm_zalloc()) */
|
||||
/* Initialize the Audio device structure
|
||||
* (it was already zeroed by kmm_zalloc())
|
||||
*/
|
||||
|
||||
nxsem_init(&upper->exclsem, 0, 1);
|
||||
upper->dev = dev;
|
||||
@@ -979,6 +1007,7 @@ int audio_register(FAR const char *name, FAR struct audio_lowerhalf_s *dev)
|
||||
{
|
||||
*pathptr++ = *ptr++;
|
||||
}
|
||||
|
||||
*pathptr = '\0';
|
||||
|
||||
/* Make this level of directory */
|
||||
|
||||
+4
-2
@@ -139,11 +139,13 @@ static int audio_comp_release(FAR struct audio_lowerhalf_s *dev);
|
||||
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
static void audio_comp_callback(FAR void *arg, uint16_t reason,
|
||||
FAR struct ap_buffer_s *apb, uint16_t status,
|
||||
FAR struct ap_buffer_s *apb,
|
||||
uint16_t status,
|
||||
FAR void *session);
|
||||
#else
|
||||
static void audio_comp_callback(FAR void *arg, uint16_t reason,
|
||||
FAR struct ap_buffer_s *apb, uint16_t status);
|
||||
FAR struct ap_buffer_s *apb,
|
||||
uint16_t status);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
+32
-23
@@ -215,13 +215,15 @@ static int pcm_ioctl(FAR struct audio_lowerhalf_s *dev,
|
||||
int cmd, unsigned long arg);
|
||||
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
static int pcm_reserve(FAR struct audio_lowerhalf_s *dev, FAR void **session);
|
||||
static int pcm_reserve(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR void **session);
|
||||
#else
|
||||
static int pcm_reserve(FAR struct audio_lowerhalf_s *dev);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
static int pcm_release(FAR struct audio_lowerhalf_s *dev, FAR void *session);
|
||||
static int pcm_release(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR void *session);
|
||||
#else
|
||||
static int pcm_release(FAR struct audio_lowerhalf_s *dev);
|
||||
#endif
|
||||
@@ -399,14 +401,14 @@ static bool pcm_parsewav(FAR struct pcm_decode_s *priv, uint8_t *data)
|
||||
|
||||
if (priv->bpsamp != 8 && priv->bpsamp != 16)
|
||||
{
|
||||
auderr("ERROR: Cannot support bits per sample of %d in this mode\n",
|
||||
auderr("ERROR: %d bits per sample are not suported in this mode\n",
|
||||
priv->bpsamp);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (priv->nchannels != 1 && priv->nchannels != 2)
|
||||
{
|
||||
auderr("ERROR: Cannot support number of channels of %d in this mode\n",
|
||||
auderr("ERROR: %d channels are not supported in this mode\n",
|
||||
priv->nchannels);
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -637,7 +639,9 @@ static void pcm_subsample(FAR struct pcm_decode_s *priv,
|
||||
priv->skip = skipsize;
|
||||
}
|
||||
|
||||
/* Now copy the sample from the end of audio buffer to the beginning. */
|
||||
/* Now copy the sample from the end of audio buffer
|
||||
* to the beginning.
|
||||
*/
|
||||
|
||||
for (i = 0; i < copysize; i++)
|
||||
{
|
||||
@@ -666,10 +670,11 @@ static void pcm_subsample(FAR struct pcm_decode_s *priv,
|
||||
* Description:
|
||||
* This method is called to retrieve the lower-half device capabilities.
|
||||
* It will be called with device type AUDIO_TYPE_QUERY to request the
|
||||
* overall capabilities, such as to determine the types of devices supported
|
||||
* audio formats supported, etc. Then it may be called once or more with
|
||||
* reported supported device types to determine the specific capabilities
|
||||
* of that device type (such as MP3 encoder, WMA encoder, PCM output, etc.).
|
||||
* overall capabilities, such as to determine the types of devices
|
||||
* supported audio formats supported, etc.
|
||||
* Then it may be called once or more with reported supported device types
|
||||
* to determine the specific capabilities of that device type
|
||||
* (such as MP3 encoder, WMA encoder, PCM output, etc.).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -696,9 +701,9 @@ static int pcm_getcaps(FAR struct audio_lowerhalf_s *dev, int type,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Modify the capabilities reported by the lower driver: PCM is the only
|
||||
* supported format that we will report, regardless of what the lower driver
|
||||
* reported.
|
||||
/* Modify the capabilities reported by the lower driver:
|
||||
* PCM is the only supported format that we will report,
|
||||
* regardless of what the lower driver reported.
|
||||
*/
|
||||
|
||||
if (caps->ac_subtype == AUDIO_TYPE_QUERY)
|
||||
@@ -724,7 +729,8 @@ static int pcm_getcaps(FAR struct audio_lowerhalf_s *dev, int type,
|
||||
|
||||
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
||||
static int pcm_configure(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR void *session, FAR const struct audio_caps_s *caps)
|
||||
FAR void *session,
|
||||
FAR const struct audio_caps_s *caps)
|
||||
#else
|
||||
static int pcm_configure(FAR struct audio_lowerhalf_s *dev,
|
||||
FAR const struct audio_caps_s *caps)
|
||||
@@ -776,8 +782,8 @@ static int pcm_configure(FAR struct audio_lowerhalf_s *dev,
|
||||
* output generation. It should also disable the audio hardware and put
|
||||
* it into the lowest possible power usage state.
|
||||
*
|
||||
* Any enqueued Audio Pipeline Buffers that have not been processed / dequeued
|
||||
* should be dequeued by this function.
|
||||
* Any enqueued Audio Pipeline Buffers that have not been
|
||||
* processed / dequeued should be dequeued by this function.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -805,10 +811,10 @@ static int pcm_shutdown(FAR struct audio_lowerhalf_s *dev)
|
||||
* Name: pcm_start
|
||||
*
|
||||
* Description:
|
||||
* Start audio streaming in the configured mode. For input and synthesis
|
||||
* devices, this means it should begin sending streaming audio data. For output
|
||||
* or processing type device, it means it should begin processing of any enqueued
|
||||
* Audio Pipeline Buffers.
|
||||
* Start audio streaming in the configured mode.
|
||||
* For input and synthesis devices, this means it should begin sending
|
||||
* streaming audio data. For output or processing type device, it means
|
||||
* it should begin processing of any enqueued Audio Pipeline Buffers.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -879,8 +885,9 @@ static int pcm_stop(FAR struct audio_lowerhalf_s *dev)
|
||||
* Name: pcm_pause
|
||||
*
|
||||
* Description:
|
||||
* Pause the audio stream. Should keep current playback context active
|
||||
* in case a resume is issued. Could be called and then followed by a stop.
|
||||
* Pause the audio stream.
|
||||
* Should keep current playback context active in case a resume is issued.
|
||||
* Could be called and then followed by a stop.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
@@ -1037,6 +1044,7 @@ static int pcm_enqueuebuffer(FAR struct audio_lowerhalf_s *dev,
|
||||
if (priv->streaming)
|
||||
{
|
||||
/* Yes, we are streaming */
|
||||
|
||||
/* Check for the last audio buffer in the stream */
|
||||
|
||||
if ((apb->flags & AUDIO_APB_FINAL) != 0)
|
||||
@@ -1120,8 +1128,9 @@ static int pcm_enqueuebuffer(FAR struct audio_lowerhalf_s *dev,
|
||||
|
||||
/* Then give the audio buffer to the lower driver */
|
||||
|
||||
audinfo("Pass to lower enqueuebuffer: apb=%p curbyte=%d nbytes=%d\n",
|
||||
apb, apb->curbyte, apb->nbytes);
|
||||
audinfo(
|
||||
"Pass to lower enqueuebuffer: apb=%p curbyte=%d nbytes=%d\n",
|
||||
apb, apb->curbyte, apb->nbytes);
|
||||
|
||||
ret = lower->ops->enqueuebuffer(lower, apb);
|
||||
if (ret == OK)
|
||||
|
||||
Reference in New Issue
Block a user