solaudio.c revision 4a7922a63c8704e7d5cb5af1264745117d037d1d
/* $Id$ */
/** @file
* VirtualBox Audio Driver - Solaris host.
*/
/*
* Copyright (C) 2006-2007 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <unistd.h>
#include <errno.h>
#include <stropts.h>
#include <fcntl.h>
#define LOG_GROUP LOG_GROUP_DEV_AUDIO
#include "VBoxDD.h"
#include "vl_vbox.h"
#include "audio.h"
#define AUDIO_CAP "solaudio"
#include "audio_int.h"
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
typedef struct solaudioVoiceOut
{
void *pPCMBuf;
typedef struct solaudioVoiceIn
{
void *pPCMBuf;
/*******************************************************************************
* Global Variables *
*******************************************************************************/
static struct
{
int cbPlayBuffer;
int cbRecordBuffer;
} conf =
{
};
static int g_AudioDev = -1;
static int g_RecordDev = -1;
static int g_AudioCtl = -1;
static char *g_pszAudioDev = NULL;
static char *g_pszAudioCtl = NULL;
typedef enum
{
enmPlay = 6,
enmRecord = 9,
enmRecordPassive = 15
} audio_dest_t;
{
switch (fmt)
{
case AUD_FMT_S8:
case AUD_FMT_U8:
return AUDIO_PRECISION_8;
case AUD_FMT_S16:
case AUD_FMT_U16:
return AUDIO_PRECISION_16;
default:
return AUDIO_PRECISION_8;
}
}
{
switch (fmt)
{
case AUDIO_PRECISION_8:
{
if (encoding == AUDIO_ENCODING_LINEAR8)
return AUD_FMT_U8;
else
return AUD_FMT_S8;
break;
}
case AUDIO_PRECISION_16:
{
if (encoding == AUDIO_ENCODING_LINEAR)
return AUD_FMT_S16;
else
return AUD_FMT_U16;
break;
}
default:
return AUD_FMT_S8;
}
}
static char *solaudio_getdevice (void)
{
/*
* This is for multiple audio devices where env. var determines current one,
* otherwise else we fallback to default.
*/
if (!pszAudioDev)
return pszAudioDev;
}
{
LogFlow(("solaudio: solaudio_close_device\n"));
switch (dst)
{
case enmPlay:
{
g_AudioDev = -1;
break;
}
case enmRecord:
case enmRecordPassive:
{
g_RecordDev = -1;
break;
}
default:
}
}
{
int rc = 0;
switch (dst)
{
case enmPlay:
{
LogFlow(("solaudio: open_device for enmPlay\n"));
if (g_AudioDev < 0)
{
rc = -1;
}
break;
}
case enmRecord:
case enmRecordPassive:
{
LogFlow(("solaudio: open_device for enmRecord\n"));
if (g_RecordDev < 0)
{
rc = -1;
}
break;
}
default:
LogRel(("solaudio: Invalid audio destination.\n"));
break;
}
return rc;
}
{
if (!info)
return -1;
{
LogRel(("solaudio: AUDIO_GETINFO failed\n"));
return -1;
}
{
}
else
{
}
{
LogRel(("solaudio: AUDIO_SETINFO failed\n"));
return -1;
}
return 0;
}
{
else
/* Open device for playback. */
if (solaudio_open_device(enmPlay))
{
LogRel(("solaudio: solaudio_open failed\n"));
return -1;
}
/* Specify playback attributes to device. */
{
LogRel(("solaudio: failed to set playback attributes.\n"));
return -1;
}
/* Copy obtained playback attributes. */
pSol->cBuffersPlayed = 0;
{
LogRel(("solaudio: failed to alloc %d %d bytes to pPCMBuf\n", hw->samples << hw->info.shift, hw->samples));
return -1;
}
LogFlow(("solaudio: init_out hw->samples=%d play.buffer_size=%d\n", hw->samples, pSol->AudioInfo.play.buffer_size));
return 0;
}
{
LogFlow(("solaudio: fini_out\n"));
{
}
}
{
LogFlow(("solaudio: voice_enable\n"));
#if 0
pSol->cBuffersPlayed = 0;
#endif
}
{
LogFlow(("solaudio: stop_out\n"));
{
Log(("solaudio: failed to stop signalling\n"));
return;
}
{
LogRel(("solaudio: failed to drop unplayed buffers\n"));
return;
}
#if 0
sol->cBuffersPlayed = 0;
#endif
{
LogRel(("solaudio: AUDIO_SETINFO failed during stop_out.\n"));
return;
}
}
{
int cbPlayBuffer = 0;
{
LogRel(("solaudio: AUDIO_GETINFO ioctl failed\n"));
return -1;
}
/* Check for overflow */
{
}
LogFlow(("avail: eof=%d samples=%d bufplayed=%d avail=%d\n", sol->AudioInfo.play.eof, sol->AudioInfo.play.samples,
return cbPlayBuffer;
}
{
if (!csLive)
return 0;
if (cbAvail <= 0)
return 0;
while (csSamples)
{
/* split request at the end of our samples buffer */
if (cbWritten < 0)
break;
}
/* Increment eof marker for synchronous buffer processed */
pSol->cBuffersPlayed++;
return csDecr;
}
{
switch (cmd)
{
case VOICE_ENABLE:
{
LogFlow(("solaudio: voice_enable\n"));
break;
}
case VOICE_DISABLE:
{
LogFlow(("solaudio: voice_disable\n"));
break;
}
}
return 0;
}
{
}
static void *solaudio_audio_init (void)
{
LogFlow(("solaudio_audio_init\n"));
if (!g_pszAudioDev)
{
if (!g_pszAudioDev)
{
LogRel(("solaudio: solaudio_getdevice() failed to return a valid device.\n"));
return NULL;
}
}
{
return NULL;
}
{
return NULL;
}
if (!g_pszAudioCtl)
if (g_AudioCtl < 0)
{
if (g_AudioCtl < 0)
{
return NULL;
}
}
return &conf;
}
static void solaudio_audio_fini (void *opaque)
{
LogFlow(("solaudio_audio_fini\n"));
if (g_pszAudioDev)
{
}
if (g_pszAudioCtl)
{
}
g_AudioCtl = -1;
}
/* -=-=-=-=- Audio Input -=-=-=-=- */
static void solaudio_pause_record(void)
{
{
LogRel(("solaudio: failed to get info. to pause recording.\n"));
return;
}
LogRel(("solaudio: failed to pause recording.\n"));
}
static void solaudio_resume_record(void)
{
{
LogRel(("solaudio: failed to get info. to resume recording.\n"));
return;
}
LogRel(("solaudio: failed to resume recording.\n"));
}
{
LogFlow(("solaudio: stop_in\n"));
{
Log(("solaudio: failed to stop signalling\n"));
return;
}
{
LogRel(("solaudio: failed to drop record buffers\n"));
return;
}
{
LogRel(("solaudio: AUDIO_SETINFO failed during stop_in.\n"));
return;
}
}
{
LogFlow(("solaudio: start_in\n"));
{
LogRel(("solaudio: failed to open for recording.\n"));
}
{
LogRel(("solaudio: solaudio_setattrs for recording failed.\n"));
return;
}
}
{
else
/*
* Open device for recording in passive mode (O_WRONLY) as we do not
* want to start buffering audio immediately. This is what is recommended.
*/
{
LogRel(("solaudio: solaudio_open failed.\n"));
return -1;
}
/* Specify playback attributes to device. */
{
LogRel(("solaudio: failed to set playback attributes.\n"));
return -1;
}
/* Copy obtained record attributes. */
ObtAudioInfo.fmt = sol_to_audfmt(pSol->AudioInfo.record.precision, pSol->AudioInfo.record.encoding);
{
LogRel(("solaudio: init_in: failed to alloc %d %d bytes to pPCMBuf\n", hw->samples << hw->info.shift, hw->samples));
return -1;
}
LogFlow(("solaudio: init_in: hw->samples=%d record.buffer_size=%d rate=%d\n", hw->samples, pSol->AudioInfo.record.buffer_size,
return 0;
}
{
LogFlow(("solaudio: fini_in done\n"));
{
}
}
{
#if 0
void *pu8Src;
if (!csDead)
return 0;
{
LogRel(("solaudio: I_NREAD failed\n"));
return 0;
}
if (!cbAvail)
return 0;
if (cbRead <= 0)
return 0;
while (csSamples)
{
/* split request at the end of our samples buffer */
}
return csDecr;
#else
int i;
size_t read_samples = 0;
struct
{
int add;
int len;
} bufs[2];
if (!dead) {
return 0;
}
{
}
else
for (i = 0; i < 2; ++i)
{
{
if (nread > 0)
{
}
if (nread == -1)
break;
}
}
return read_samples;
#endif
}
{
}
{
switch (cmd)
{
case VOICE_ENABLE:
{
LogRel(("solaudio: solaudio_ctl_in voice_enable\n"));
break;
}
case VOICE_DISABLE:
{
LogRel(("solaudio: solaudio_ctl_in voice_disable\n"));
break;
}
}
return 0;
}
static struct audio_pcm_ops solaudio_pcm_ops =
{
NULL,
NULL,
NULL,
NULL,
};
static struct audio_option solaudio_options[] =
{
"Size of the buffer in bytes", NULL, 0},
#if 0
"Size of the record bufffer in bytes", NULL, 0},
#endif
};
struct audio_driver solaudio_audio_driver =
{
INIT_FIELD (voice_size_in = ) 0
};