DrvHostALSAAudio.cpp revision 7a26bb8055882cf73ea492e915d08f112dd25aa1
0N/A * available from http://www.virtualbox.org. This file is free software;
0N/A * This code is based on: alsaaudio.c
0N/A #include "alsa_stubs.h"
536N/A #include "alsa_mangling.h"
502N/A#include "DrvAudio.h"
502N/A#include "AudioMixBuffer.h"
481N/Atypedef struct ALSAAUDIOSTREAMIN
typedef struct ALSAAUDIOSTREAMOUT
void *pvBuf;
typedef struct ALSAAUDIOCFG
int size_in_usec_in;
int size_in_usec_out;
const char *pcm_name_in;
const char *pcm_name_out;
unsigned int buffer_size_in;
unsigned int period_size_in;
unsigned int buffer_size_out;
unsigned int period_size_out;
unsigned int threshold;
#ifdef HIGH_LATENCY
#ifdef HIGH_LATENCY
typedef struct DRVHOSTALSAAUDIO
typedef struct ALSAAUDIOSTREAMCFG
unsigned int freq;
int nchannels;
unsigned long buffer_size;
unsigned long period_size;
return VINF_SUCCESS;
int rc;
if (rc2)
return rc;
switch (fmt)
case AUD_FMT_S8:
return SND_PCM_FORMAT_S8;
case AUD_FMT_U8:
return SND_PCM_FORMAT_U8;
case AUD_FMT_S16:
return SND_PCM_FORMAT_S16_LE;
case AUD_FMT_U16:
return SND_PCM_FORMAT_U16_LE;
case AUD_FMT_S32:
return SND_PCM_FORMAT_S32_LE;
case AUD_FMT_U32:
return SND_PCM_FORMAT_U32_LE;
return SND_PCM_FORMAT_U8;
switch (fmt)
case SND_PCM_FORMAT_S8:
if (pEndianness)
case SND_PCM_FORMAT_U8:
if (pEndianness)
case SND_PCM_FORMAT_S16_LE:
if (pEndianness)
case SND_PCM_FORMAT_U16_LE:
if (pEndianness)
case SND_PCM_FORMAT_S16_BE:
if (pEndianness)
case SND_PCM_FORMAT_U16_BE:
if (pEndianness)
case SND_PCM_FORMAT_S32_LE:
if (pEndianness)
case SND_PCM_FORMAT_U32_LE:
if (pEndianness)
case SND_PCM_FORMAT_S32_BE:
if (pEndianness)
case SND_PCM_FORMAT_U32_BE:
if (pEndianness)
return VERR_NOT_SUPPORTED;
return VINF_SUCCESS;
switch (fmt)
case SND_PCM_FORMAT_S8:
case SND_PCM_FORMAT_U8:
*puShift = 0;
case SND_PCM_FORMAT_S16_LE:
case SND_PCM_FORMAT_U16_LE:
case SND_PCM_FORMAT_S16_BE:
case SND_PCM_FORMAT_U16_BE:
case SND_PCM_FORMAT_S32_LE:
case SND_PCM_FORMAT_U32_LE:
case SND_PCM_FORMAT_S32_BE:
case SND_PCM_FORMAT_U32_BE:
return VERR_NOT_SUPPORTED;
return VINF_SUCCESS;
if (!pSWParms)
return VERR_NO_MEMORY;
int rc;
if (err < 0)
if (err < 0)
if (err < 0)
return rc;
int rc;
if (!pszDev)
if (err < 0)
if (err < 0)
if (err < 0)
if (err < 0)
if (err < 0)
if (err < 0)
if (!buffer_size)
if (buffer_size)
if (period_size)
&period_size, 0);
if (err < 0)
&buffer_size, 0);
if (err < 0)
if (period_size_f)
int dir = 0;
if (err < 0)
&period_size_f, 0);
if (err < 0)
if (err < 0)
if (err < 0)
if (err < 0)
if (err < 0)
int dir = 0;
if (err < 0)
if (err < 0)
if ( !fIn
unsigned uShift;
<< uShift;
return rc;
#ifdef DEBUG
int rc;
if (framesAvail < 0)
if (framesAvail >= 0)
return rc;
if (err < 0)
return VINF_SUCCESS;
if (err < 0)
return VINF_SUCCESS;
int err;
if (fPause)
if (err < 0)
return VERR_ACCESS_DENIED;
if (err < 0)
return VERR_ACCESS_DENIED;
return VINF_SUCCESS;
#ifdef DEBUG
return rc;
static DECLCALLBACK(int) drvHostALSAAudioCaptureIn(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMIN pHstStrmIn,
return rc;
switch (state)
case SND_PCM_STATE_PREPARED:
case SND_PCM_STATE_SUSPENDED:
if (!cAvail)
if (pcSamplesCaptured)
*pcSamplesCaptured = 0;
return VINF_SUCCESS;
while ( cbToRead
if (cRead <= 0)
switch (cRead)
case -EAGAIN:
cbToRead = 0;
case -EPIPE:
&cWritten);
if (cWrittenTotal)
&cProcessed);
if (pcSamplesCaptured)
return rc;
static DECLCALLBACK(int) drvHostALSAAudioPlayOut(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMOUT pHstStrmOut,
cAvail),
while (cbToRead)
if (cWritten <= 0)
switch (cWritten)
case -EPIPE:
case -ESTRPIPE:
if (cReadTotal)
if (pcSamplesPlayed)
return rc;
static DECLCALLBACK(int) drvHostALSAAudioFiniIn(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMIN pHstStrmIn)
return VINF_SUCCESS;
static DECLCALLBACK(int) drvHostALSAAudioFiniOut(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMOUT pHstStrmOut)
return VINF_SUCCESS;
int rc;
if (pcSamples)
return rc;
int rc;
if (pcSamples)
return rc;
static DECLCALLBACK(int) drvHostALSAAudioControlIn(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMIN pHstStrmIn,
int rc;
switch (enmStreamCmd)
case PDMAUDIOSTREAMCMD_ENABLE:
return rc;
static DECLCALLBACK(int) drvHostALSAAudioControlOut(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMOUT pHstStrmOut,
int rc;
switch (enmStreamCmd)
case PDMAUDIOSTREAMCMD_ENABLE:
return rc;
static DECLCALLBACK(int) drvHostALSAAudioGetConf(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDCFG pCfg)
return VINF_SUCCESS;
static DECLCALLBACK(void *) drvHostALSAAudioQueryInterface(PPDMIBASE pInterface, const char *pszIID)
return NULL;
static DECLCALLBACK(int) drvHostAlsaAudioConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
return VINF_SUCCESS;
sizeof(DRVHOSTALSAAUDIO),
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,