Audio: Get rid of the decoder->driver IOCTLs that I added a couple of commits back; Use existing configure method

This commit is contained in:
Gregory Nutt 2014-07-24 09:56:39 -06:00
parent 27a082ddf4
commit dba43a9c75
5 changed files with 115 additions and 105 deletions

View File

@ -95,6 +95,12 @@ struct pcm_decode_s
FAR struct audio_lowerhalf_s *lower; FAR struct audio_lowerhalf_s *lower;
/* Session returned from the lower level driver */
#ifdef CONFIG_AUDIO_MULTI_SESSION
FAR void *session;
#endif
/* These are values extracted from WAV file header */ /* These are values extracted from WAV file header */
uint32_t samprate; /* 8000, 44100, ... */ uint32_t samprate; /* 8000, 44100, ... */
@ -701,7 +707,7 @@ static int pcm_enqueuebuffer(FAR struct audio_lowerhalf_s *dev,
audvdbg("Received buffer %p, streaming=%d\n", apb, priv->streaming); audvdbg("Received buffer %p, streaming=%d\n", apb, priv->streaming);
lower = priv->lower; lower = priv->lower;
DEBUGASSERT(lower && lower->ops->enqueuebuffer && lower->ops->ioctl); DEBUGASSERT(lower && lower->ops->enqueuebuffer && lower->ops->configure);
/* Are we streaming yet? */ /* Are we streaming yet? */
@ -731,6 +737,8 @@ static int pcm_enqueuebuffer(FAR struct audio_lowerhalf_s *dev,
if (pcm_parsewav(priv, &apb->samp[apb->curbyte])) if (pcm_parsewav(priv, &apb->samp[apb->curbyte]))
{ {
struct audio_caps_s caps;
/* Now we are streaming */ /* Now we are streaming */
priv->streaming = true; priv->streaming = true;
@ -739,27 +747,23 @@ static int pcm_enqueuebuffer(FAR struct audio_lowerhalf_s *dev,
* and sample bitwidth. * and sample bitwidth.
*/ */
ret = lower->ops->ioctl(lower, AUDIOIOC_BITRATE, DEBUGASSERT(priv->samprate < 65535);
(unsigned long)priv->samprate);
if (ret < 0)
{
auddbg("ERROR: Failed to set bit rate: %d\n", ret);
return ret;
}
ret = lower->ops->ioctl(lower, AUDIOIOC_NCHANNELS, caps.ac_len = sizeof(struct audio_caps_s);
(unsigned long)priv->nchannels); caps.ac_type = AUDIO_TYPE_OUTPUT;
if (ret < 0) caps.ac_channels = priv->nchannels;
{
auddbg("ERROR: Failed to set number of channels: %d\n", ret);
return ret;
}
ret = lower->ops->ioctl(lower, AUDIOIOC_SAMPWIDTH, *((uint16_t *)&caps.ac_controls[0]) = (uint16_t)priv->samprate;
(unsigned long)priv->bpsamp); caps.ac_controls[2] = priv->bpsamp;
#ifdef CONFIG_AUDIO_MULTI_SESSION
ret = lower->ops->configure(lower, priv->session, &caps);
#else
ret = lower->ops->configure(lower, &caps);
#endif
if (ret < 0) if (ret < 0)
{ {
auddbg("ERROR: Failed to set sample width: %d\n", ret); auddbg("ERROR: Failed to set PCM configuration: %d\n", ret);
return ret; return ret;
} }
@ -849,14 +853,22 @@ static int pcm_reserve(FAR struct audio_lowerhalf_s *dev)
{ {
FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev; FAR struct pcm_decode_s *priv = (FAR struct pcm_decode_s *)dev;
FAR struct audio_lowerhalf_s *lower; FAR struct audio_lowerhalf_s *lower;
int ret;
#ifdef CONFIG_AUDIO_MULTI_SESSION
DEBUGASSERT(priv && session);
#else
DEBUGASSERT(priv); DEBUGASSERT(priv);
#endif
/* It is not necessary to reserve the upper half. What we really need to /* It is not necessary to reserve the upper half. What we really need to
* do is to reserved the lower device driver for exclusive use by the PCM * do is to reserved the lower device driver for exclusive use by the PCM
* decoder. That effectively reserves the upper PCM decoder along with * decoder. That effectively reserves the upper PCM decoder along with
* the lower driver (which is then not available for use by other * the lower driver (which is then not available for use by other
* decoders). * decoders).
*
* We do, however, need to remember the session returned by the lower
* level.
*/ */
lower = priv->lower; lower = priv->lower;
@ -864,10 +876,17 @@ static int pcm_reserve(FAR struct audio_lowerhalf_s *dev)
audvdbg("Defer to lower reserve\n"); audvdbg("Defer to lower reserve\n");
#ifdef CONFIG_AUDIO_MULTI_SESSION #ifdef CONFIG_AUDIO_MULTI_SESSION
return lower->ops->reserve(lower, session); ret = lower->ops->reserve(lower, &priv->session);
/* Return a copy of the session to the caller */
*session = priv->session;
#else #else
return lower->ops->reserve(lower); ret = lower->ops->reserve(lower);
#endif #endif
return ret;
} }
/**************************************************************************** /****************************************************************************

View File

@ -349,6 +349,53 @@ static int null_configure(FAR struct audio_lowerhalf_s *dev,
FAR const struct audio_caps_s *caps) FAR const struct audio_caps_s *caps)
#endif #endif
{ {
audvdbg("ac_type: %d\n", caps->ac_type);
/* Process the configure operation */
switch (caps->ac_type)
{
case AUDIO_TYPE_FEATURE:
audvdbg(" AUDIO_TYPE_FEATURE\:n");
/* Process based on Feature Unit */
switch (*((uint16_t *)caps->ac_format))
{
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
case AUDIO_FU_VOLUME:
audvdbg(" Volume: %d\n", *(uint16_t *)caps->ac_controls);
break;
#endif /* CONFIG_AUDIO_EXCLUDE_VOLUME */
#ifndef CONFIG_AUDIO_EXCLUDE_TONE
case AUDIO_FU_BASS:
audvdbg(" Bass: %d\n", caps->ac_controls[0]);
break;
case AUDIO_FU_TREBLE:
audvdbg(" Treble: %d\n", caps->ac_controls[0]);
break;
#endif /* CONFIG_AUDIO_EXCLUDE_TONE */
default:
auddbg(" Unrecognized feature unit\n");
break;
}
break;
case AUDIO_TYPE_OUTPUT:
audvdbg(" AUDIO_TYPE_OUTPUT:\n");
audvdbg(" Number of channels: %u\n", caps->ac_channels);
audvdbg(" Sample rate: %u\n", *(uint16_t*)&ac_controls[0]);
audvdbg(" Sample width: %u\n", ac_controls[2]);
break;
case AUDIO_TYPE_PROCESSING:
audvdbg(" AUDIO_TYPE_PROCESSING:\n");
break;
}
audvdbg("Return OK\n"); audvdbg("Return OK\n");
return OK; return OK;
} }
@ -679,26 +726,6 @@ static int null_ioctl(FAR struct audio_lowerhalf_s *dev, int cmd,
break; break;
#endif #endif
/* Data stream configuration */
case AUDIOIOC_BITRATE:
{
audvdbg("AUDIOIOC_BITRATE: Set bit rate: %lu\n", arg);
}
break;
case AUDIOIOC_NCHANNELS:
{
audvdbg("AUDIOIOC_NCHANNELS: Set number of channels: %lu\n", arg);
}
break;
case AUDIOIOC_SAMPWIDTH:
{
audvdbg("AUDIOIOC_SAMPWIDTH: Set sample width: %lu\n", arg);
}
break;
default: default:
break; break;
} }

View File

@ -833,6 +833,9 @@ static int vs1053_configure(FAR struct audio_lowerhalf_s *lower,
break; break;
case AUDIO_TYPE_OUTPUT:
break;
case AUDIO_TYPE_PROCESSING: case AUDIO_TYPE_PROCESSING:
/* We only support STEREO_EXTENDER */ /* We only support STEREO_EXTENDER */

View File

@ -730,13 +730,14 @@ static int wm8904_configure(FAR struct audio_lowerhalf_s *dev,
#endif #endif
int ret = OK; int ret = OK;
audvdbg("Entry\n"); audvdbg("ac_type: %d\n", caps->ac_type);
/* Process the configure operation */ /* Process the configure operation */
switch (caps->ac_type) switch (caps->ac_type)
{ {
case AUDIO_TYPE_FEATURE: case AUDIO_TYPE_FEATURE:
audvdbg(" AUDIO_TYPE_FEATURE\:n");
/* Process based on Feature Unit */ /* Process based on Feature Unit */
@ -748,6 +749,8 @@ static int wm8904_configure(FAR struct audio_lowerhalf_s *dev,
/* Set the volume */ /* Set the volume */
uint16_t volume = *(uint16_t *)caps->ac_controls; uint16_t volume = *(uint16_t *)caps->ac_controls;
audvdbg(" Volume: %d\n", volume);
if (volume >= 0 && volume <= 1000) if (volume >= 0 && volume <= 1000)
{ {
/* Scale the volume setting to the range {0.. 63} */ /* Scale the volume setting to the range {0.. 63} */
@ -770,6 +773,8 @@ static int wm8904_configure(FAR struct audio_lowerhalf_s *dev,
*/ */
uint8_t bass = caps->ac_controls[0]; uint8_t bass = caps->ac_controls[0];
audvdbg(" Bass: %d\n", bass);
if (bass <= 100) if (bass <= 100)
{ {
wm8904_setbass(priv, bass); wm8904_setbass(priv, bass);
@ -788,6 +793,8 @@ static int wm8904_configure(FAR struct audio_lowerhalf_s *dev,
*/ */
uint8_t treble = caps->ac_controls[0]; uint8_t treble = caps->ac_controls[0];
audvdbg(" Treble: %d\n", treble);
if (treble <= 100) if (treble <= 100)
{ {
wm8904_settreble(priv, treble); wm8904_settreble(priv, treble);
@ -801,19 +808,21 @@ static int wm8904_configure(FAR struct audio_lowerhalf_s *dev,
#endif /* CONFIG_AUDIO_EXCLUDE_TONE */ #endif /* CONFIG_AUDIO_EXCLUDE_TONE */
default: default:
auddbg(" Unrecognized feature unit\n");
ret = -ENOTTY; ret = -ENOTTY;
break; break;
} }
break; break;
case AUDIO_TYPE_PROCESSING: case AUDIO_TYPE_OUTPUT:
{ audvdbg(" AUDIO_TYPE_OUTPUT:\n");
/* We only support STEREO_EXTENDER */ audvdbg(" Number of channels: %u\n", caps->ac_channels);
audvdbg(" Sample rate: %u\n", *(uint16_t*)&ac_controls[0]);
audvdbg(" Sample width: %u\n", ac_controls[2]);
#warning Missing logic
break;
if (*((uint16_t *) caps->ac_format) == AUDIO_PU_STEREO_EXTENDER) case AUDIO_TYPE_PROCESSING:
{
}
}
break; break;
} }
@ -1467,29 +1476,8 @@ static int wm8904_ioctl(FAR struct audio_lowerhalf_s *dev, int cmd,
break; break;
#endif #endif
/* Data stream configuration */
case AUDIOIOC_BITRATE:
{
audvdbg("AUDIOIOC_BITRATE: Set bit rate: %lu\n", arg);
#warning Missing logic
}
break;
case AUDIOIOC_NCHANNELS:
{
audvdbg("AUDIOIOC_NCHANNELS: Set number of channels: %lu\n", arg);
#warning Missing logic
}
break;
case AUDIOIOC_SAMPWIDTH:
{
audvdbg("AUDIOIOC_SAMPWIDTH: Set sample width: %lu\n", arg);
#warning Missing logic
}
break;
default: default:
audvdbg("Ignored\n");
break; break;
} }

View File

@ -122,33 +122,6 @@
#define AUDIOIOC_UNREGISTERMQ _AUDIOIOC(15) #define AUDIOIOC_UNREGISTERMQ _AUDIOIOC(15)
#define AUDIOIOC_HWRESET _AUDIOIOC(16) #define AUDIOIOC_HWRESET _AUDIOIOC(16)
/* Additional ioctl commands support operations between audio decoders
* and low-level audio drivers. This ioctls are not used by the higher
* level audio logic and need be implemented only in low-level audio
* drivers that are driven by a decoder.
*
* AUDIOIOC_BITRATE - Set bit rate
*
* ioctl argument: Audio bit rate in bits per second
* Range: 1-65535 BPS (Compare to AUDIO_BIT_RATE_* definitions)
*
* AUDIOIOC_NCHANNELS - Set number of audio channels
*
* ioctl argument: Number of audio channels. 1=MONO, 2=STEREO, etc.
* Range: 1-255, however most drivers will support only
* 1 and possibly 2
*
* AUDIOIOC_SAMPWIDTH - Set sample bit width
*
* ioctl argument: Sample bit width: 8=8-bit data, 16=16-bit data, etc.
* Range: 1-255, however, many drivers will support only
* one sample bit width.
*/
#define AUDIOIOC_BITRATE _AUDIOIOC(17)
#define AUDIOIOC_NCHANNELS _AUDIOIOC(18)
#define AUDIOIOC_SAMPWIDTH _AUDIOIOC(19)
/* Audio Device Types *******************************************************/ /* Audio Device Types *******************************************************/
/* The NuttX audio interface support different types of audio devices for /* The NuttX audio interface support different types of audio devices for
* input, output, synthesis, and manipulation of audio data. A given driver/ * input, output, synthesis, and manipulation of audio data. A given driver/
@ -184,8 +157,8 @@
#define AUDIO_FMT_WAV 0x07 #define AUDIO_FMT_WAV 0x07
#define AUDIO_FMT_MP3 0x08 #define AUDIO_FMT_MP3 0x08
#define AUDIO_FMT_MIDI 0x09 #define AUDIO_FMT_MIDI 0x09
#define AUDIO_FMT_OGG_VORBIS 0x0A #define AUDIO_FMT_OGG_VORBIS 0x0a
#define AUDIO_FMT_FLAC 0x0B #define AUDIO_FMT_FLAC 0x0b
/* Audio Sub-Format Types ***************************************************/ /* Audio Sub-Format Types ***************************************************/
@ -199,11 +172,11 @@
#define AUDIO_SUBFMT_PCM_S8 0x07 #define AUDIO_SUBFMT_PCM_S8 0x07
#define AUDIO_SUBFMT_PCM_U16_LE 0x08 #define AUDIO_SUBFMT_PCM_U16_LE 0x08
#define AUDIO_SUBFMT_PCM_S16_BE 0x09 #define AUDIO_SUBFMT_PCM_S16_BE 0x09
#define AUDIO_SUBFMT_PCM_S16_LE 0x0A #define AUDIO_SUBFMT_PCM_S16_LE 0x0a
#define AUDIO_SUBFMT_PCM_U16_BE 0x0B #define AUDIO_SUBFMT_PCM_U16_BE 0x0b
#define AUDIO_SUBFMT_MIDI_0 0x0C #define AUDIO_SUBFMT_MIDI_0 0x0c
#define AUDIO_SUBFMT_MIDI_1 0x0D #define AUDIO_SUBFMT_MIDI_1 0x0d
#define AUDIO_SUBFMT_MIDI_2 0x0E #define AUDIO_SUBFMT_MIDI_2 0x0e
/* Supported Sampling Rates *************************************************/ /* Supported Sampling Rates *************************************************/
@ -276,7 +249,7 @@
/* Audio Pipeline Buffer (AP Buffer) flags **********************************/ /* Audio Pipeline Buffer (AP Buffer) flags **********************************/
#define AUDIO_ABP_ALIGNMENT 0x000F /* Mask to define buffer alignment */ #define AUDIO_ABP_ALIGNMENT 0x000f /* Mask to define buffer alignment */
#define AUDIO_ABP_CANDMA 0x0010 /* Set if the data is DMA'able */ #define AUDIO_ABP_CANDMA 0x0010 /* Set if the data is DMA'able */
#define AUDIO_ABP_STATIC 0x0020 /* Set if statically allocated */ #define AUDIO_ABP_STATIC 0x0020 /* Set if statically allocated */
#define AUDIO_ABP_ACTIVE 0x0040 /* Set if this buffer is still active. #define AUDIO_ABP_ACTIVE 0x0040 /* Set if this buffer is still active.