acassis commented on code in PR #17459:
URL: https://github.com/apache/nuttx/pull/17459#discussion_r2602220960
##########
audio/audio.c:
##########
@@ -707,23 +1410,47 @@ static inline void audio_dequeuebuffer(FAR struct
audio_upperhalf_s *upper,
FAR struct ap_buffer_s *apb, uint16_t status)
#endif
{
+ FAR struct audio_openpriv_s *priv;
struct audio_msg_s msg;
+ pollevent_t eventset;
+ irqstate_t flags;
audinfo("Entry\n");
- /* Send a dequeue message to the user if a message queue is registered */
+ if (upper->info.type == AUDIO_TYPE_OUTPUT)
+ {
+ apb->nbytes = 0;
+ memset(apb->samp, 0, apb->nmaxbytes);
+ }
- if (upper->usermq != NULL)
+ flags = spin_lock_irqsave_nopreempt(&upper->spinlock);
+ upper->status->tail++;
+ audio_try_enqueue(upper);
+ for (priv = upper->head; priv != NULL; priv = priv->flink)
{
- msg.msg_id = AUDIO_MSG_DEQUEUE;
- msg.u.ptr = apb;
+ if (priv->fd)
Review Comment:
```suggestion
if (priv->fd > 0)
##########
audio/audio.c:
##########
@@ -323,17 +619,230 @@ static int audio_start(FAR struct audio_upperhalf_s
*upper)
#else
ret = lower->ops->start(lower);
#endif
-
- /* A return value of zero means that the audio stream was started
+ /* A return value of zero means that the audio stream was running
* successfully.
*/
- if (ret == OK)
+ if (ret != OK)
+ {
+ return ret;
+ }
+
+ audio_setstate(upper, AUDIO_STATE_RUNNING);
+ }
+
+ priv->state = AUDIO_STATE_RUNNING;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: audio_stop
+ *
+ * Description:
+ * Handle the AUDIOIOC_STOP ioctl command
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_AUDIO_MULTI_SESSION
+static int audio_stop(FAR struct file *filep, FAR void *session)
+#else
+static int audio_stop(FAR struct file *filep)
+#endif
+{
+ FAR struct inode *inode = filep->f_inode;
+ FAR struct audio_upperhalf_s *upper = inode->i_private;
+ FAR struct audio_lowerhalf_s *lower = upper->dev;
+ FAR struct audio_openpriv_s *priv = filep->f_priv;
+ int nstate;
+ int ret;
+
+ DEBUGASSERT(upper != NULL && lower->ops->stop != NULL);
+
+ nstate = audio_getnstate(upper, priv);
+ if ((upper->status->state == AUDIO_STATE_RUNNING ||
+ upper->status->state == AUDIO_STATE_PAUSED) &&
+ nstate == AUDIO_STATE_OPEN)
+ {
+#ifdef CONFIG_AUDIO_MULTI_SESSION
+ ret = lower->ops->stop(lower, session);
+#else
+ ret = lower->ops->stop(lower);
+#endif
+ if (ret != OK)
+ {
+ return ret;
+ }
+
+ memset(&upper->info, 0, sizeof(upper->info));
+
+ /* Audio_complete may have set state to AUDIO_STATE_OPEN */
+
+ if (upper->status->state != AUDIO_STATE_OPEN)
+ {
+ audio_setstate(upper, AUDIO_STATE_DRAINING);
+ }
+ }
+ else if (nstate == AUDIO_STATE_PAUSED)
+ {
+ ret = audio_pause(filep);
+ if (ret != OK)
+ {
+ return ret;
+ }
+ }
+
+ priv->state = AUDIO_STATE_OPEN;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: audio_freebuffer
+ *
+ * Description:
+ * Handle the AUDIOIOC_FREEBUFFER ioctl command
+ *
+ ****************************************************************************/
+
+static int audio_freebuffer(FAR struct audio_upperhalf_s *upper,
+ FAR struct audio_buf_desc_s *bufdesc)
+{
+ FAR struct audio_lowerhalf_s *lower = upper->dev;
+ bool share = false;
+ int ret;
+
+ if (bufdesc->u.buffer == NULL)
+ {
+ bufdesc->u.buffer = upper->apbs[upper->periods - 1];
+ share = true;
+ }
+
+ if (lower->ops->freebuffer)
+ {
+ ret = lower->ops->freebuffer(lower, bufdesc);
+ }
+ else
+ {
+ /* Perform a simple apb_free operation */
+
+ DEBUGASSERT(bufdesc->u.buffer != NULL);
+ apb_free(bufdesc->u.buffer);
+ ret = sizeof(struct audio_buf_desc_s);
+ }
+
+ if (ret > 0 && share)
+ {
+ bufdesc->u.buffer = NULL;
+ upper->periods--;
+ upper->apbs[upper->periods] = NULL;
+ if (upper->periods == 0)
+ {
+ kmm_free(upper->apbs);
+ upper->apbs = NULL;
+ }
+ }
+
+ return ret;
+}
+
+/****************************************************************************
+ * Name: audio_allocbuffer
+ *
+ * Description:
+ * Handle the AUDIOIOC_ALLOCBUFFER ioctl command
+ *
+ ****************************************************************************/
+
+static int audio_allocbuffer(FAR struct audio_upperhalf_s *upper,
+ FAR struct audio_buf_desc_s *bufdesc)
+{
+ FAR struct audio_lowerhalf_s *lower = upper->dev;
+ FAR struct ap_buffer_s *apb;
+ bool share = false;
+ FAR void *newaddr;
+ int ret;
+
+ if (upper->periods >= upper->nbuffers)
+ {
+ return 0;
+ }
+
+ if (bufdesc->u.pbuffer == NULL)
+ {
+ bufdesc->u.pbuffer = &apb;
+ share = true;
+ }
+
+ if (lower->ops->allocbuffer)
Review Comment:
```suggestion
if (lower->ops->allocbuffer != NULL)
##########
audio/audio.c:
##########
@@ -649,6 +1122,97 @@ 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:
+ {
+ if (!lower->ops->ioctl ||
+ lower->ops->ioctl(lower, AUDIOIOC_GETAUDIOINFO, arg) < 0)
Review Comment:
```suggestion
if (lower->ops->ioctl == NULL ||
lower->ops->ioctl(lower, AUDIOIOC_GETAUDIOINFO, arg) < 0)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]