2013-05-19 23:12:28 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* audio/audio.c
|
|
|
|
*
|
2024-09-09 08:54:34 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-04-10 08:50:57 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2013-05-19 23:12:28 +02:00
|
|
|
*
|
2021-04-10 08:50:57 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-05-19 23:12:28 +02:00
|
|
|
*
|
2021-04-10 08:50:57 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2013-05-19 23:12:28 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/kmalloc.h>
|
2017-10-10 16:43:10 +02:00
|
|
|
#include <nuttx/mqueue.h>
|
2013-05-19 23:12:28 +02:00
|
|
|
#include <nuttx/arch.h>
|
2017-10-10 16:43:10 +02:00
|
|
|
#include <nuttx/fs/fs.h>
|
2013-05-21 21:13:05 +02:00
|
|
|
#include <nuttx/audio/audio.h>
|
2022-09-06 08:18:45 +02:00
|
|
|
#include <nuttx/mutex.h>
|
2013-05-19 23:12:28 +02:00
|
|
|
|
|
|
|
#include <arch/irq.h>
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
2018-08-24 13:51:44 +02:00
|
|
|
|
2013-05-19 23:12:28 +02:00
|
|
|
/* Debug ********************************************************************/
|
2020-04-21 09:45:24 +02:00
|
|
|
|
2013-05-19 23:12:28 +02:00
|
|
|
/* Non-standard debug that may be enabled just for testing Audio */
|
|
|
|
|
|
|
|
#ifndef AUDIO_MAX_DEVICE_PATH
|
|
|
|
# define AUDIO_MAX_DEVICE_PATH 32
|
|
|
|
#endif
|
|
|
|
|
2013-10-27 14:44:53 +01:00
|
|
|
#ifndef CONFIG_AUDIO_BUFFER_DEQUEUE_PRIO
|
|
|
|
# define CONFIG_AUDIO_BUFFER_DEQUEUE_PRIO 1
|
|
|
|
#endif
|
|
|
|
|
2013-05-19 23:12:28 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Type Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* This structure describes the state of the upper half driver */
|
|
|
|
|
|
|
|
struct audio_upperhalf_s
|
|
|
|
{
|
2020-04-21 09:45:24 +02:00
|
|
|
uint8_t crefs; /* The number of times the device has been opened */
|
|
|
|
volatile bool started; /* True: playback is active */
|
2022-09-06 08:18:45 +02:00
|
|
|
mutex_t lock; /* Supports mutual exclusion */
|
2013-05-19 23:12:28 +02:00
|
|
|
FAR struct audio_lowerhalf_s *dev; /* lower-half state */
|
2020-12-24 13:53:17 +01:00
|
|
|
struct file *usermq; /* User mode app's message queue */
|
2013-05-19 23:12:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-05-21 21:13:05 +02:00
|
|
|
static int audio_open(FAR struct file *filep);
|
|
|
|
static int audio_close(FAR struct file *filep);
|
2020-04-21 09:45:24 +02:00
|
|
|
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);
|
2013-10-27 14:44:53 +01:00
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2020-04-21 09:45:24 +02:00
|
|
|
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);
|
2013-10-27 14:44:53 +01:00
|
|
|
#else
|
|
|
|
static int audio_start(FAR struct audio_upperhalf_s *upper);
|
2020-04-21 09:45:24 +02:00
|
|
|
static void audio_callback(FAR void *priv,
|
|
|
|
uint16_t reason,
|
|
|
|
FAR struct ap_buffer_s *apb,
|
|
|
|
uint16_t status);
|
2013-10-27 14:44:53 +01:00
|
|
|
#endif /* CONFIG_AUDIO_MULTI_SESSION */
|
2013-05-19 23:12:28 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static const struct file_operations g_audioops =
|
|
|
|
{
|
|
|
|
audio_open, /* open */
|
|
|
|
audio_close, /* close */
|
|
|
|
audio_read, /* read */
|
|
|
|
audio_write, /* write */
|
2019-05-22 02:57:54 +02:00
|
|
|
NULL, /* seek */
|
2019-05-22 16:23:59 +02:00
|
|
|
audio_ioctl, /* ioctl */
|
2013-05-19 23:12:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-21 09:45:24 +02:00
|
|
|
/****************************************************************************
|
2013-05-19 23:12:28 +02:00
|
|
|
* Name: audio_open
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is called whenever the Audio device is opened.
|
|
|
|
*
|
2020-04-21 09:45:24 +02:00
|
|
|
****************************************************************************/
|
2013-05-19 23:12:28 +02:00
|
|
|
|
|
|
|
static int audio_open(FAR struct file *filep)
|
|
|
|
{
|
2013-10-27 14:44:53 +01:00
|
|
|
FAR struct inode *inode = filep->f_inode;
|
2013-05-19 23:12:28 +02:00
|
|
|
FAR struct audio_upperhalf_s *upper = inode->i_private;
|
2013-10-27 14:44:53 +01:00
|
|
|
uint8_t tmp;
|
|
|
|
int ret;
|
2013-05-19 23:12:28 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("crefs: %d\n", upper->crefs);
|
2013-05-19 23:12:28 +02:00
|
|
|
|
|
|
|
/* Get exclusive access to the device structures */
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&upper->lock);
|
2013-05-19 23:12:28 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Increment the count of references to the device. If this the first
|
|
|
|
* time that the driver has been opened for this device, then initialize
|
|
|
|
* the device.
|
|
|
|
*/
|
|
|
|
|
|
|
|
tmp = upper->crefs + 1;
|
|
|
|
if (tmp == 0)
|
|
|
|
{
|
|
|
|
/* More than 255 opens; uint8_t overflows to zero */
|
|
|
|
|
|
|
|
ret = -EMFILE;
|
2022-09-06 08:18:45 +02:00
|
|
|
goto errout_with_lock;
|
2013-05-19 23:12:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Save the new open count on success */
|
|
|
|
|
|
|
|
upper->crefs = tmp;
|
|
|
|
ret = OK;
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
errout_with_lock:
|
|
|
|
nxmutex_unlock(&upper->lock);
|
2013-05-21 21:13:05 +02:00
|
|
|
|
2013-05-19 23:12:28 +02:00
|
|
|
errout:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-04-21 09:45:24 +02:00
|
|
|
/****************************************************************************
|
2013-05-19 23:12:28 +02:00
|
|
|
* Name: audio_close
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is called when the Audio device is closed.
|
|
|
|
*
|
2020-04-21 09:45:24 +02:00
|
|
|
****************************************************************************/
|
2013-05-19 23:12:28 +02:00
|
|
|
|
|
|
|
static int audio_close(FAR struct file *filep)
|
|
|
|
{
|
2013-10-27 14:44:53 +01:00
|
|
|
FAR struct inode *inode = filep->f_inode;
|
2013-05-19 23:12:28 +02:00
|
|
|
FAR struct audio_upperhalf_s *upper = inode->i_private;
|
2013-10-27 14:44:53 +01:00
|
|
|
int ret;
|
2013-05-19 23:12:28 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("crefs: %d\n", upper->crefs);
|
2013-05-19 23:12:28 +02:00
|
|
|
|
|
|
|
/* Get exclusive access to the device structures */
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&upper->lock);
|
2013-05-19 23:12:28 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Decrement the references to the driver. If the reference count will
|
|
|
|
* decrement to 0, then uninitialize the driver.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (upper->crefs > 1)
|
|
|
|
{
|
|
|
|
upper->crefs--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FAR struct audio_lowerhalf_s *lower = upper->dev;
|
|
|
|
|
|
|
|
/* There are no more references to the port */
|
|
|
|
|
|
|
|
upper->crefs = 0;
|
|
|
|
|
|
|
|
/* Disable the Audio device */
|
|
|
|
|
|
|
|
DEBUGASSERT(lower->ops->shutdown != NULL);
|
2020-11-27 06:19:40 +01:00
|
|
|
audinfo("calling shutdown\n");
|
2013-05-19 23:12:28 +02:00
|
|
|
|
|
|
|
lower->ops->shutdown(lower);
|
2020-12-17 11:20:34 +01:00
|
|
|
upper->usermq = NULL;
|
2013-05-19 23:12:28 +02:00
|
|
|
}
|
2018-02-04 14:34:31 +01:00
|
|
|
|
2013-05-19 23:12:28 +02:00
|
|
|
ret = OK;
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&upper->lock);
|
2013-05-21 21:13:05 +02:00
|
|
|
|
2013-05-19 23:12:28 +02:00
|
|
|
errout:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-04-21 09:45:24 +02:00
|
|
|
/****************************************************************************
|
2013-05-19 23:12:28 +02:00
|
|
|
* Name: audio_read
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* A dummy read method. This is provided only to satsify the VFS layer.
|
|
|
|
*
|
2020-04-21 09:45:24 +02:00
|
|
|
****************************************************************************/
|
2013-05-19 23:12:28 +02:00
|
|
|
|
2020-04-21 09:45:24 +02:00
|
|
|
static ssize_t audio_read(FAR struct file *filep,
|
|
|
|
FAR char *buffer,
|
|
|
|
size_t buflen)
|
2013-05-19 23:12:28 +02:00
|
|
|
{
|
2013-10-27 14:44:53 +01:00
|
|
|
FAR struct inode *inode = filep->f_inode;
|
|
|
|
FAR struct audio_upperhalf_s *upper = inode->i_private;
|
|
|
|
FAR struct audio_lowerhalf_s *lower = upper->dev;
|
|
|
|
|
|
|
|
/* TODO: Should we check permissions here? */
|
|
|
|
|
|
|
|
/* Audio read operations get passed directly to the lower-level */
|
|
|
|
|
|
|
|
if (lower->ops->read != NULL)
|
|
|
|
{
|
|
|
|
return lower->ops->read(lower, buffer, buflen);
|
|
|
|
}
|
2013-05-19 23:12:28 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-21 09:45:24 +02:00
|
|
|
/****************************************************************************
|
2013-05-19 23:12:28 +02:00
|
|
|
* Name: audio_write
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* A dummy write method. This is provided only to satsify the VFS layer.
|
|
|
|
*
|
2020-04-21 09:45:24 +02:00
|
|
|
****************************************************************************/
|
2013-05-19 23:12:28 +02:00
|
|
|
|
2020-04-21 09:45:24 +02:00
|
|
|
static ssize_t audio_write(FAR struct file *filep,
|
|
|
|
FAR const char *buffer,
|
|
|
|
size_t buflen)
|
2013-05-19 23:12:28 +02:00
|
|
|
{
|
2013-10-27 14:44:53 +01:00
|
|
|
FAR struct inode *inode = filep->f_inode;
|
|
|
|
FAR struct audio_upperhalf_s *upper = inode->i_private;
|
|
|
|
FAR struct audio_lowerhalf_s *lower = upper->dev;
|
|
|
|
|
|
|
|
/* TODO: Should we check permissions here? */
|
|
|
|
|
|
|
|
/* Audio write operations get passed directly to the lower-level */
|
|
|
|
|
|
|
|
if (lower->ops->write != NULL)
|
|
|
|
{
|
|
|
|
return lower->ops->write(lower, buffer, buflen);
|
|
|
|
}
|
|
|
|
|
2013-05-19 23:12:28 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-21 09:45:24 +02:00
|
|
|
/****************************************************************************
|
2013-05-19 23:12:28 +02:00
|
|
|
* Name: audio_start
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Handle the AUDIOIOC_START ioctl command
|
2013-05-21 21:13:05 +02:00
|
|
|
*
|
2020-04-21 09:45:24 +02:00
|
|
|
****************************************************************************/
|
2013-05-19 23:12:28 +02:00
|
|
|
|
2013-10-27 14:44:53 +01:00
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2020-04-21 09:45:24 +02:00
|
|
|
static int audio_start(FAR struct audio_upperhalf_s *upper,
|
|
|
|
FAR void *session)
|
2013-10-27 14:44:53 +01:00
|
|
|
#else
|
|
|
|
static int audio_start(FAR struct audio_upperhalf_s *upper)
|
|
|
|
#endif
|
2013-05-19 23:12:28 +02:00
|
|
|
{
|
|
|
|
FAR struct audio_lowerhalf_s *lower = upper->dev;
|
|
|
|
int ret = OK;
|
|
|
|
|
|
|
|
DEBUGASSERT(upper != NULL && lower->ops->start != NULL);
|
|
|
|
|
|
|
|
/* Verify that the Audio is not already running */
|
|
|
|
|
|
|
|
if (!upper->started)
|
|
|
|
{
|
2013-10-27 14:44:53 +01:00
|
|
|
/* Invoke the bottom half method to start the audio stream */
|
2013-05-19 23:12:28 +02:00
|
|
|
|
2013-10-27 14:44:53 +01:00
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
|
|
|
ret = lower->ops->start(lower, session);
|
|
|
|
#else
|
2013-05-19 23:12:28 +02:00
|
|
|
ret = lower->ops->start(lower);
|
2013-10-27 14:44:53 +01:00
|
|
|
#endif
|
2013-05-19 23:12:28 +02:00
|
|
|
|
2013-10-27 14:44:53 +01:00
|
|
|
/* A return value of zero means that the audio stream was started
|
2013-05-19 23:12:28 +02:00
|
|
|
* successfully.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ret == OK)
|
|
|
|
{
|
2013-10-27 14:44:53 +01:00
|
|
|
/* Indicate that the audio stream has started */
|
2013-05-19 23:12:28 +02:00
|
|
|
|
|
|
|
upper->started = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-04-21 09:45:24 +02:00
|
|
|
/****************************************************************************
|
2013-05-19 23:12:28 +02:00
|
|
|
* Name: audio_ioctl
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The standard ioctl method. This is where ALL of the Audio work is done.
|
2013-05-21 21:13:05 +02:00
|
|
|
*
|
2020-04-21 09:45:24 +02:00
|
|
|
****************************************************************************/
|
2013-05-19 23:12:28 +02:00
|
|
|
|
|
|
|
static int audio_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
|
|
|
|
{
|
2013-10-27 14:44:53 +01:00
|
|
|
FAR struct inode *inode = filep->f_inode;
|
2013-05-19 23:12:28 +02:00
|
|
|
FAR struct audio_upperhalf_s *upper = inode->i_private;
|
|
|
|
FAR struct audio_lowerhalf_s *lower = upper->dev;
|
2013-10-27 14:44:53 +01:00
|
|
|
FAR struct audio_buf_desc_s *bufdesc;
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
|
|
|
FAR void *session;
|
|
|
|
#endif
|
|
|
|
int ret;
|
2013-05-19 23:12:28 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("cmd: %d arg: %ld\n", cmd, arg);
|
2013-05-19 23:12:28 +02:00
|
|
|
|
|
|
|
/* Get exclusive access to the device structures */
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&upper->lock);
|
2013-05-19 23:12:28 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle built-in ioctl commands */
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
/* AUDIOIOC_GETCAPS - Get the audio device capabilities.
|
|
|
|
*
|
|
|
|
* ioctl argument: A pointer to the audio_caps_s structure.
|
|
|
|
*/
|
|
|
|
|
|
|
|
case AUDIOIOC_GETCAPS:
|
|
|
|
{
|
2020-04-21 09:45:24 +02:00
|
|
|
FAR struct audio_caps_s *caps =
|
|
|
|
(FAR struct audio_caps_s *)((uintptr_t)arg);
|
2013-05-19 23:12:28 +02:00
|
|
|
DEBUGASSERT(lower->ops->getcaps != NULL);
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("AUDIOIOC_GETCAPS: Device=%d\n", caps->ac_type);
|
2013-05-19 23:12:28 +02:00
|
|
|
|
|
|
|
/* Call the lower-half driver capabilities handler */
|
2014-07-23 03:23:05 +02:00
|
|
|
|
2013-05-19 23:12:28 +02:00
|
|
|
ret = lower->ops->getcaps(lower, caps->ac_type, caps);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUDIOIOC_CONFIGURE:
|
|
|
|
{
|
2013-10-27 14:44:53 +01:00
|
|
|
FAR const struct audio_caps_desc_s *caps =
|
2015-10-08 17:10:22 +02:00
|
|
|
(FAR const struct audio_caps_desc_s *)((uintptr_t)arg);
|
2013-05-19 23:12:28 +02:00
|
|
|
DEBUGASSERT(lower->ops->configure != NULL);
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("AUDIOIOC_INITIALIZE: Device=%d\n", caps->caps.ac_type);
|
2013-05-19 23:12:28 +02:00
|
|
|
|
|
|
|
/* Call the lower-half driver configure handler */
|
2013-05-21 21:13:05 +02:00
|
|
|
|
2013-10-27 14:44:53 +01:00
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
|
|
|
ret = lower->ops->configure(lower, caps->session, &caps->caps);
|
|
|
|
#else
|
|
|
|
ret = lower->ops->configure(lower, &caps->caps);
|
|
|
|
#endif
|
2013-05-19 23:12:28 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AUDIOIOC_SHUTDOWN:
|
|
|
|
{
|
|
|
|
DEBUGASSERT(lower->ops->shutdown != NULL);
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("AUDIOIOC_SHUTDOWN\n");
|
2013-05-19 23:12:28 +02:00
|
|
|
|
|
|
|
/* Call the lower-half driver initialize handler */
|
2018-08-24 13:51:44 +02:00
|
|
|
|
2013-05-19 23:12:28 +02:00
|
|
|
ret = lower->ops->shutdown(lower);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-04-21 09:45:24 +02:00
|
|
|
/* AUDIOIOC_START - Start the audio stream.
|
|
|
|
* The AUDIOIOC_SETCHARACTERISTICS
|
2013-05-19 23:12:28 +02:00
|
|
|
* command must have previously been sent.
|
|
|
|
*
|
2013-10-27 14:44:53 +01:00
|
|
|
* ioctl argument: Audio session
|
2013-05-19 23:12:28 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
case AUDIOIOC_START:
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("AUDIOIOC_START\n");
|
2013-05-19 23:12:28 +02:00
|
|
|
DEBUGASSERT(lower->ops->start != NULL);
|
|
|
|
|
2013-10-27 14:44:53 +01:00
|
|
|
/* Start the audio stream */
|
2013-05-19 23:12:28 +02:00
|
|
|
|
2013-10-27 14:44:53 +01:00
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
|
|
|
session = (FAR void *) arg;
|
|
|
|
ret = audio_start(upper, session);
|
|
|
|
#else
|
|
|
|
ret = audio_start(upper);
|
|
|
|
#endif
|
2013-05-19 23:12:28 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-10-27 14:44:53 +01:00
|
|
|
/* AUDIOIOC_STOP - Stop the audio stream.
|
2013-05-19 23:12:28 +02:00
|
|
|
*
|
2013-10-27 14:44:53 +01:00
|
|
|
* ioctl argument: Audio session
|
2013-05-19 23:12:28 +02:00
|
|
|
*/
|
|
|
|
|
2013-10-27 14:44:53 +01:00
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
|
2013-05-19 23:12:28 +02:00
|
|
|
case AUDIOIOC_STOP:
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("AUDIOIOC_STOP\n");
|
2013-05-19 23:12:28 +02:00
|
|
|
DEBUGASSERT(lower->ops->stop != NULL);
|
|
|
|
|
|
|
|
if (upper->started)
|
|
|
|
{
|
2013-10-27 14:44:53 +01:00
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
|
|
|
session = (FAR void *) arg;
|
|
|
|
ret = lower->ops->stop(lower, session);
|
|
|
|
#else
|
2013-05-19 23:12:28 +02:00
|
|
|
ret = lower->ops->stop(lower);
|
2013-10-27 14:44:53 +01:00
|
|
|
#endif
|
2013-05-19 23:12:28 +02:00
|
|
|
upper->started = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* CONFIG_AUDIO_EXCLUDE_STOP */
|
2013-10-27 14:44:53 +01:00
|
|
|
|
|
|
|
/* AUDIOIOC_PAUSE - Pause the audio stream.
|
|
|
|
*
|
|
|
|
* ioctl argument: Audio session
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME
|
|
|
|
|
|
|
|
case AUDIOIOC_PAUSE:
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("AUDIOIOC_PAUSE\n");
|
2013-10-27 14:44:53 +01:00
|
|
|
DEBUGASSERT(lower->ops->pause != NULL);
|
|
|
|
|
|
|
|
if (upper->started)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
|
|
|
session = (FAR void *) arg;
|
|
|
|
ret = lower->ops->pause(lower, session);
|
|
|
|
#else
|
|
|
|
ret = lower->ops->pause(lower);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* AUDIOIOC_RESUME - Resume the audio stream.
|
|
|
|
*
|
|
|
|
* ioctl argument: Audio session
|
|
|
|
*/
|
|
|
|
|
|
|
|
case AUDIOIOC_RESUME:
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("AUDIOIOC_RESUME\n");
|
2013-10-27 14:44:53 +01:00
|
|
|
DEBUGASSERT(lower->ops->resume != NULL);
|
|
|
|
|
|
|
|
if (upper->started)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
|
|
|
session = (FAR void *) arg;
|
|
|
|
ret = lower->ops->resume(lower, session);
|
|
|
|
#else
|
|
|
|
ret = lower->ops->resume(lower);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-01-31 19:07:39 +01:00
|
|
|
#endif /* CONFIG_AUDIO_EXCLUDE_PAUSE_RESUME */
|
2013-10-27 14:44:53 +01:00
|
|
|
|
|
|
|
/* AUDIOIOC_ALLOCBUFFER - Allocate an audio buffer
|
|
|
|
*
|
|
|
|
* ioctl argument: pointer to an audio_buf_desc_s structure
|
|
|
|
*/
|
|
|
|
|
|
|
|
case AUDIOIOC_ALLOCBUFFER:
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("AUDIOIOC_ALLOCBUFFER\n");
|
2013-10-27 14:44:53 +01:00
|
|
|
|
|
|
|
bufdesc = (FAR struct audio_buf_desc_s *) arg;
|
|
|
|
if (lower->ops->allocbuffer)
|
|
|
|
{
|
|
|
|
ret = lower->ops->allocbuffer(lower, bufdesc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-01 00:24:24 +02:00
|
|
|
/* Perform a simple kumm_malloc operation assuming 1 session */
|
2013-10-27 14:44:53 +01:00
|
|
|
|
|
|
|
ret = apb_alloc(bufdesc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* AUDIOIOC_FREEBUFFER - Free an audio buffer
|
|
|
|
*
|
|
|
|
* ioctl argument: pointer to an audio_buf_desc_s structure
|
|
|
|
*/
|
|
|
|
|
|
|
|
case AUDIOIOC_FREEBUFFER:
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("AUDIOIOC_FREEBUFFER\n");
|
2013-10-27 14:44:53 +01:00
|
|
|
|
|
|
|
bufdesc = (FAR struct audio_buf_desc_s *) arg;
|
|
|
|
if (lower->ops->freebuffer)
|
|
|
|
{
|
|
|
|
ret = lower->ops->freebuffer(lower, bufdesc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-09-01 00:15:11 +02:00
|
|
|
/* Perform a simple apb_free operation */
|
2013-10-27 14:44:53 +01:00
|
|
|
|
2020-04-21 10:55:41 +02:00
|
|
|
DEBUGASSERT(bufdesc->u.buffer != NULL);
|
|
|
|
apb_free(bufdesc->u.buffer);
|
2013-10-27 14:44:53 +01:00
|
|
|
ret = sizeof(struct audio_buf_desc_s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* AUDIOIOC_ENQUEUEBUFFER - Enqueue an audio buffer
|
|
|
|
*
|
|
|
|
* ioctl argument: pointer to an audio_buf_desc_s structure
|
|
|
|
*/
|
|
|
|
|
|
|
|
case AUDIOIOC_ENQUEUEBUFFER:
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("AUDIOIOC_ENQUEUEBUFFER\n");
|
2013-10-27 14:44:53 +01:00
|
|
|
|
|
|
|
DEBUGASSERT(lower->ops->enqueuebuffer != NULL);
|
|
|
|
|
|
|
|
bufdesc = (FAR struct audio_buf_desc_s *) arg;
|
2020-04-21 10:55:41 +02:00
|
|
|
ret = lower->ops->enqueuebuffer(lower, bufdesc->u.buffer);
|
2013-10-27 14:44:53 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* AUDIOIOC_REGISTERMQ - Register a client Message Queue
|
|
|
|
*
|
|
|
|
* TODO: This needs to have multi session support.
|
|
|
|
*/
|
|
|
|
|
|
|
|
case AUDIOIOC_REGISTERMQ:
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("AUDIOIOC_REGISTERMQ\n");
|
2014-07-31 23:00:12 +02:00
|
|
|
|
2020-12-24 13:53:17 +01:00
|
|
|
ret = fs_getfilep((mqd_t)arg, &upper->usermq);
|
2013-10-27 14:44:53 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* AUDIOIOC_UNREGISTERMQ - Register a client Message Queue
|
|
|
|
*
|
|
|
|
* TODO: This needs to have multi session support.
|
|
|
|
*/
|
|
|
|
|
|
|
|
case AUDIOIOC_UNREGISTERMQ:
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("AUDIOIOC_UNREGISTERMQ\n");
|
2014-07-31 23:00:12 +02:00
|
|
|
|
2013-10-27 14:44:53 +01:00
|
|
|
upper->usermq = NULL;
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* AUDIOIOC_RESERVE - Reserve a session with the driver
|
|
|
|
*
|
|
|
|
* ioctl argument - pointer to receive the session context
|
|
|
|
*/
|
|
|
|
|
|
|
|
case AUDIOIOC_RESERVE:
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("AUDIOIOC_RESERVE\n");
|
2013-10-27 14:44:53 +01:00
|
|
|
DEBUGASSERT(lower->ops->reserve != NULL);
|
|
|
|
|
|
|
|
/* Call lower-half to perform the reservation */
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
|
|
|
ret = lower->ops->reserve(lower, (FAR void **) arg);
|
|
|
|
#else
|
|
|
|
ret = lower->ops->reserve(lower);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* AUDIOIOC_RESERVE - Reserve a session with the driver
|
|
|
|
*
|
|
|
|
* ioctl argument - pointer to receive the session context
|
|
|
|
*/
|
|
|
|
|
|
|
|
case AUDIOIOC_RELEASE:
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("AUDIOIOC_RELEASE\n");
|
2013-10-27 14:44:53 +01:00
|
|
|
DEBUGASSERT(lower->ops->release != NULL);
|
|
|
|
|
|
|
|
/* Call lower-half to perform the release */
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
|
|
|
ret = lower->ops->release(lower, (FAR void *) arg);
|
|
|
|
#else
|
|
|
|
ret = lower->ops->release(lower);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
2013-05-19 23:12:28 +02:00
|
|
|
|
2020-04-21 09:45:24 +02:00
|
|
|
/* Any unrecognized IOCTL commands might be
|
|
|
|
* platform-specific ioctl commands
|
|
|
|
*/
|
2013-05-19 23:12:28 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("Forwarding unrecognized cmd: %d arg: %ld\n", cmd, arg);
|
2013-05-19 23:12:28 +02:00
|
|
|
DEBUGASSERT(lower->ops->ioctl != NULL);
|
|
|
|
ret = lower->ops->ioctl(lower, cmd, arg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&upper->lock);
|
2013-05-19 23:12:28 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-10-27 14:44:53 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: audio_dequeuebuffer
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Dequeues a previously enqueued Audio Pipeline Buffer.
|
|
|
|
*
|
|
|
|
* 1. The upper half driver calls the enqueuebuffer method, providing the
|
|
|
|
* lower half driver with the ab_buffer to process.
|
|
|
|
* 2. The lower half driver's enqueuebuffer will either processes the
|
|
|
|
* buffer directly, or more likely add it to a queue for processing
|
|
|
|
* by a background thread or worker task.
|
|
|
|
* 3. When the lower half driver has completed processing of the enqueued
|
|
|
|
* ab_buffer, it will call this routine to indicate processing of the
|
|
|
|
* buffer is complete.
|
|
|
|
* 4. When this routine is called, it will check if any threads are waiting
|
|
|
|
* to enqueue additional buffers and "wake them up" for further
|
|
|
|
* processing.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2013-10-27 14:44:53 +01:00
|
|
|
* handle - This is the handle that was provided to the lower-half
|
|
|
|
* start() method.
|
|
|
|
* apb - A pointer to the previsously enqueued ap_buffer_s
|
|
|
|
* status - Status of the dequeue operation
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* This function may be called from an interrupt handler.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
|
|
|
static inline void audio_dequeuebuffer(FAR struct audio_upperhalf_s *upper,
|
|
|
|
FAR struct ap_buffer_s *apb, uint16_t status,
|
|
|
|
FAR void *session)
|
|
|
|
#else
|
|
|
|
static inline void audio_dequeuebuffer(FAR struct audio_upperhalf_s *upper,
|
|
|
|
FAR struct ap_buffer_s *apb, uint16_t status)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
struct audio_msg_s msg;
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
audinfo("Entry\n");
|
2013-10-27 14:44:53 +01:00
|
|
|
|
|
|
|
/* Send a dequeue message to the user if a message queue is registered */
|
|
|
|
|
|
|
|
if (upper->usermq != NULL)
|
|
|
|
{
|
2020-04-21 09:45:24 +02:00
|
|
|
msg.msg_id = AUDIO_MSG_DEQUEUE;
|
|
|
|
msg.u.ptr = apb;
|
2013-10-27 14:44:53 +01:00
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
|
|
|
msg.session = session;
|
|
|
|
#endif
|
|
|
|
apb->flags |= AUDIO_APB_DEQUEUED;
|
2020-12-24 13:53:17 +01:00
|
|
|
file_mq_send(upper->usermq, (FAR const char *)&msg, sizeof(msg),
|
|
|
|
CONFIG_AUDIO_BUFFER_DEQUEUE_PRIO);
|
2013-10-27 14:44:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: audio_complete
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Send an AUDIO_MSG_COMPLETE message to the client to indicate that the
|
|
|
|
* active playback has completed. The lower-half driver initiates this
|
|
|
|
* call via its callback pointer to our upper-half driver.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
|
|
|
static inline void audio_complete(FAR struct audio_upperhalf_s *upper,
|
|
|
|
FAR struct ap_buffer_s *apb, uint16_t status,
|
|
|
|
FAR void *session)
|
|
|
|
#else
|
|
|
|
static inline void audio_complete(FAR struct audio_upperhalf_s *upper,
|
|
|
|
FAR struct ap_buffer_s *apb, uint16_t status)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
struct audio_msg_s msg;
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
audinfo("Entry\n");
|
2013-10-27 14:44:53 +01:00
|
|
|
|
|
|
|
/* Send a dequeue message to the user if a message queue is registered */
|
|
|
|
|
|
|
|
upper->started = false;
|
|
|
|
if (upper->usermq != NULL)
|
|
|
|
{
|
2020-04-21 09:45:24 +02:00
|
|
|
msg.msg_id = AUDIO_MSG_COMPLETE;
|
|
|
|
msg.u.ptr = NULL;
|
2013-10-27 14:44:53 +01:00
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
|
|
|
msg.session = session;
|
|
|
|
#endif
|
2020-12-24 13:53:17 +01:00
|
|
|
file_mq_send(upper->usermq, (FAR const char *)&msg, sizeof(msg),
|
|
|
|
CONFIG_AUDIO_BUFFER_DEQUEUE_PRIO);
|
2013-10-27 14:44:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-04 02:52:18 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: audio_message
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Send an custom message to the client to indicate that the
|
|
|
|
* active message has delivered. The lower-half driver initiates this
|
|
|
|
* call via its callback pointer to our upper-half driver.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
|
|
|
static inline void audio_message(FAR struct audio_upperhalf_s *upper,
|
|
|
|
FAR struct ap_buffer_s *apb, uint16_t status,
|
|
|
|
FAR void *session)
|
|
|
|
#else
|
|
|
|
static inline void audio_message(FAR struct audio_upperhalf_s *upper,
|
|
|
|
FAR struct ap_buffer_s *apb, uint16_t status)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
struct audio_msg_s *msg = (FAR struct audio_msg_s *)apb;
|
|
|
|
|
|
|
|
/* Send a message to the user if a message queue is registered */
|
|
|
|
|
|
|
|
if (upper->usermq != NULL)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
2020-12-08 07:01:44 +01:00
|
|
|
msg->session = session;
|
2019-11-04 02:52:18 +01:00
|
|
|
#endif
|
2020-12-24 13:53:17 +01:00
|
|
|
file_mq_send(upper->usermq, (FAR const char *)msg, sizeof(*msg),
|
|
|
|
CONFIG_AUDIO_BUFFER_DEQUEUE_PRIO);
|
2019-11-04 02:52:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-27 14:44:53 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: audio_callback
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Provides a callback interface for lower-half drivers to call to the
|
|
|
|
* upper-half for buffer dequeueing, error reporting, etc.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2013-10-27 14:44:53 +01:00
|
|
|
* priv - Private context data owned by the upper-half
|
|
|
|
* reason - The reason code for the callback
|
|
|
|
* apb - A pointer to the previsously enqueued ap_buffer_s
|
|
|
|
* status - Status information associated with the callback
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* This function may be called from an interrupt handler.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
|
|
|
static void audio_callback(FAR void *handle, uint16_t reason,
|
|
|
|
FAR struct ap_buffer_s *apb, uint16_t status,
|
|
|
|
FAR void *session)
|
|
|
|
#else
|
|
|
|
static void audio_callback(FAR void *handle, uint16_t reason,
|
|
|
|
FAR struct ap_buffer_s *apb, uint16_t status)
|
|
|
|
#endif
|
|
|
|
{
|
2020-04-21 09:45:24 +02:00
|
|
|
FAR struct audio_upperhalf_s *upper =
|
|
|
|
(FAR struct audio_upperhalf_s *)handle;
|
2013-10-27 14:44:53 +01:00
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
audinfo("Entry\n");
|
2013-10-27 14:44:53 +01:00
|
|
|
|
|
|
|
/* Perform operation based on reason code */
|
|
|
|
|
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case AUDIO_CALLBACK_DEQUEUE:
|
|
|
|
{
|
|
|
|
/* Call the dequeue routine */
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
|
|
|
audio_dequeuebuffer(upper, apb, status, session);
|
|
|
|
#else
|
|
|
|
audio_dequeuebuffer(upper, apb, status);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lower-half I/O error occurred */
|
|
|
|
|
|
|
|
case AUDIO_CALLBACK_IOERR:
|
|
|
|
{
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Lower-half driver has completed a playback */
|
|
|
|
|
|
|
|
case AUDIO_CALLBACK_COMPLETE:
|
|
|
|
{
|
2020-04-21 09:45:24 +02:00
|
|
|
/* Send a complete message to the user if a message queue
|
|
|
|
* is registered
|
|
|
|
*/
|
2013-10-27 14:44:53 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
|
|
|
audio_complete(upper, apb, status, session);
|
|
|
|
#else
|
|
|
|
audio_complete(upper, apb, status);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-11-04 02:52:18 +01:00
|
|
|
case AUDIO_CALLBACK_MESSAGE:
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_AUDIO_MULTI_SESSION
|
|
|
|
audio_message(upper, apb, status, session);
|
|
|
|
#else
|
|
|
|
audio_message(upper, apb, status);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-10-27 14:44:53 +01:00
|
|
|
default:
|
|
|
|
{
|
2016-06-12 17:46:23 +02:00
|
|
|
auderr("ERROR: Unknown callback reason code %d\n", reason);
|
2013-10-27 14:44:53 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-19 23:12:28 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: audio_register
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function binds an instance of a "lower half" audio driver with the
|
|
|
|
* "upper half" Audio device and registers that device so that can be used
|
|
|
|
* by application code.
|
|
|
|
*
|
|
|
|
* When this function is called, the "lower half" driver should be in the
|
|
|
|
* reset state (as if the shutdown() method had already been called).
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2013-05-19 23:12:28 +02:00
|
|
|
* path - The full path to the driver to be registers in the NuttX pseudo-
|
|
|
|
* filesystem. The recommended convention is to name Audio drivers
|
2013-05-21 21:13:05 +02:00
|
|
|
* based on the function they provide, such as "/dev/pcm0", "/dev/mp31",
|
|
|
|
* etc.
|
2020-04-21 09:45:24 +02:00
|
|
|
* 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.
|
2013-05-19 23:12:28 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero on success; a negated errno value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int audio_register(FAR const char *name, FAR struct audio_lowerhalf_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct audio_upperhalf_s *upper;
|
2013-10-27 14:44:53 +01:00
|
|
|
char path[AUDIO_MAX_DEVICE_PATH];
|
2013-05-19 23:12:28 +02:00
|
|
|
static bool dev_audio_created = false;
|
2013-05-21 21:13:05 +02:00
|
|
|
#ifndef CONFIG_AUDIO_CUSTOM_DEV_PATH
|
2015-10-08 17:10:22 +02:00
|
|
|
FAR const char *devname = "/dev/audio";
|
2013-05-21 21:13:05 +02:00
|
|
|
#elif !defined(CONFIG_AUDIO_DEV_ROOT)
|
2015-10-08 17:10:22 +02:00
|
|
|
FAR const char *devname = CONFIG_AUDIO_DEV_PATH;
|
|
|
|
FAR const char *ptr;
|
|
|
|
FAR char *pathptr;
|
2013-05-21 21:13:05 +02:00
|
|
|
#endif
|
2013-05-19 23:12:28 +02:00
|
|
|
|
|
|
|
/* Allocate the upper-half data structure */
|
|
|
|
|
2023-08-28 09:39:47 +02:00
|
|
|
upper = kmm_zalloc(sizeof(struct audio_upperhalf_s));
|
2013-05-19 23:12:28 +02:00
|
|
|
if (!upper)
|
|
|
|
{
|
2016-06-12 17:46:23 +02:00
|
|
|
auderr("ERROR: Allocation failed\n");
|
2013-05-19 23:12:28 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2020-04-21 09:45:24 +02:00
|
|
|
/* Initialize the Audio device structure
|
|
|
|
* (it was already zeroed by kmm_zalloc())
|
|
|
|
*/
|
2013-05-19 23:12:28 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_init(&upper->lock);
|
2013-05-19 23:12:28 +02:00
|
|
|
upper->dev = dev;
|
|
|
|
|
2013-05-21 21:13:05 +02:00
|
|
|
#ifdef CONFIG_AUDIO_CUSTOM_DEV_PATH
|
|
|
|
|
|
|
|
#ifdef CONFIG_AUDIO_DEV_ROOT
|
|
|
|
|
|
|
|
/* This is the simple case ... No need to make a directory */
|
|
|
|
|
2023-02-08 04:29:09 +01:00
|
|
|
strlcpy(path, "/dev/", sizeof(path));
|
|
|
|
strlcat(path, name, sizeof(path));
|
2013-05-21 21:13:05 +02:00
|
|
|
|
|
|
|
#else
|
|
|
|
/* Ensure the path begins with "/dev" as we don't support placing device
|
|
|
|
* anywhere but in the /dev directory
|
|
|
|
*/
|
|
|
|
|
|
|
|
DEBUGASSERT(strncmp(devname, "/dev", 4) == 0);
|
|
|
|
|
|
|
|
/* Create a /dev/audio directory. */
|
|
|
|
|
|
|
|
if (!dev_audio_created)
|
|
|
|
{
|
|
|
|
/* Get path name after "/dev" */
|
|
|
|
|
|
|
|
ptr = &devname[4];
|
|
|
|
if (*ptr == '/')
|
|
|
|
{
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
2023-02-08 04:29:09 +01:00
|
|
|
strlcpy(path, "/dev/", sizeof(path));
|
2013-05-21 21:13:05 +02:00
|
|
|
pathptr = &path[5];
|
|
|
|
|
|
|
|
/* Do mkdir for each segment of the path */
|
|
|
|
|
|
|
|
while (*ptr != '\0')
|
|
|
|
{
|
|
|
|
/* Build next path segment into path variable */
|
|
|
|
|
|
|
|
while (*ptr != '/' && *ptr != '\0')
|
|
|
|
{
|
|
|
|
*pathptr++ = *ptr++;
|
|
|
|
}
|
2020-04-21 09:45:24 +02:00
|
|
|
|
2013-05-21 21:13:05 +02:00
|
|
|
*pathptr = '\0';
|
|
|
|
|
|
|
|
/* Make this level of directory */
|
|
|
|
|
|
|
|
mkdir(path, 0644);
|
|
|
|
|
|
|
|
/* Check for another level */
|
|
|
|
|
|
|
|
*pathptr++ = '/';
|
|
|
|
if (*ptr == '/')
|
|
|
|
{
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Indicate we have created the audio dev path */
|
|
|
|
|
|
|
|
dev_audio_created = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now build the path for registration */
|
|
|
|
|
2023-02-08 04:29:09 +01:00
|
|
|
strlcpy(path, devname, sizeof(path));
|
2013-05-21 21:13:05 +02:00
|
|
|
if (devname[sizeof(devname)-1] != '/')
|
|
|
|
{
|
2023-02-08 04:29:09 +01:00
|
|
|
strlcat(path, "/", sizeof(path));
|
2013-05-21 21:13:05 +02:00
|
|
|
}
|
2014-02-11 02:11:56 +01:00
|
|
|
|
2023-02-08 04:29:09 +01:00
|
|
|
strlcat(path, name, sizeof(path));
|
2013-05-21 21:13:05 +02:00
|
|
|
|
|
|
|
#endif /* CONFIG_AUDIO_DEV_PATH=="/dev" */
|
|
|
|
|
|
|
|
#else /* CONFIG_AUDIO_CUSTOM_DEV_PATH */
|
|
|
|
|
2013-05-19 23:12:28 +02:00
|
|
|
/* Create a /dev/audio directory. */
|
|
|
|
|
|
|
|
if (!dev_audio_created)
|
|
|
|
{
|
|
|
|
/* We don't check for error here because even if it fails, then
|
|
|
|
* the register_driver call below will return an error condition
|
|
|
|
* for us.
|
|
|
|
*/
|
|
|
|
|
|
|
|
mkdir(devname, 0644);
|
|
|
|
dev_audio_created = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register the Audio device */
|
|
|
|
|
2023-02-08 04:29:09 +01:00
|
|
|
strlcpy(path, devname, sizeof(path));
|
|
|
|
strlcat(path, "/", sizeof(path));
|
|
|
|
strlcat(path, name, sizeof(path));
|
2013-05-21 21:13:05 +02:00
|
|
|
#endif
|
2013-05-19 23:12:28 +02:00
|
|
|
|
2013-10-27 14:44:53 +01:00
|
|
|
/* Give the lower-half a context to the upper half */
|
2013-05-19 23:12:28 +02:00
|
|
|
|
2013-10-27 14:44:53 +01:00
|
|
|
dev->upper = audio_callback;
|
|
|
|
dev->priv = upper;
|
2013-05-21 21:13:05 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
audinfo("Registering %s\n", path);
|
2013-10-27 14:44:53 +01:00
|
|
|
return register_driver(path, &g_audioops, 0666, upper);
|
2013-05-21 21:13:05 +02:00
|
|
|
}
|
|
|
|
|
2013-05-19 23:12:28 +02:00
|
|
|
#endif /* CONFIG_AUDIO */
|