DrvAudioCommon.cpp revision 3ab9febd96202da54e2461400fa0b694a28f5707
/* $Id$ */
/** @file
* Intermedia audio driver, common routines. These are also used
* in the drivers which are bound to Main, e.g. the VRDE or the
* video audio recording drivers.
*/
/*
* Copyright (C) 2006-2014 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.
* --------------------------------------------------------------------
*
* This code is based on: audio_template.h from QEMU AUDIO subsystem.
*
* QEMU Audio subsystem header
*
* Copyright (c) 2005 Vassili Karpov (malc)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <iprt/asm-math.h>
#ifdef LOG_GROUP
#endif
#define LOG_GROUP LOG_GROUP_DEV_AUDIO
#include <ctype.h>
#include <stdlib.h>
#include "DrvAudio.h"
#include "AudioMixBuffer.h"
{
switch (enmRecSource)
{
case PDMAUDIORECSOURCE_MIC: return "Microphone In";
case PDMAUDIORECSOURCE_CD: return "CD";
case PDMAUDIORECSOURCE_VIDEO: return "Video";
case PDMAUDIORECSOURCE_AUX: return "AUX";
case PDMAUDIORECSOURCE_LINE_IN: return "Line In";
case PDMAUDIORECSOURCE_PHONE: return "Phone";
default:
break;
}
return "Unknown";
}
{
switch (enmFormat)
{
case AUD_FMT_U8:
return "U8";
case AUD_FMT_U16:
return "U16";
case AUD_FMT_U32:
return "U32";
case AUD_FMT_S8:
return "S8";
case AUD_FMT_S16:
return "S16";
case AUD_FMT_S32:
return "S32";
default:
break;
}
return "Invalid";
}
{
return AUD_FMT_U8;
return AUD_FMT_U16;
return AUD_FMT_U32;
return AUD_FMT_S8;
return AUD_FMT_S16;
return AUD_FMT_S32;
return AUD_FMT_INVALID;
}
/*********************************** In Stream Functions **********************************************/
{
{
}
}
{
}
{
if (!pGstStrmOut)
return;
{
}
}
#if 0
/**
* Finds the minimum number of not yet captured samples of all
* attached guest input streams for a certain host input stream.
*
* @return uint32_t Minimum number of not yet captured samples.
* UINT32_MAX if none found.
* @param pHstStrmIn Host input stream to check for.
*/
{
{
}
#ifdef DEBUG_andy
#endif
return cMinSamples;
}
{
}
{
#ifdef DEBUG_andy
#endif
return cSamplesLive;
}
#endif
{
}
#if 0
/**
* Returns the number of live sample data (in bytes) of a certain
* guest input stream.
*
* @return uint32_t Live sample data (in bytes), 0 if none.
* @param pGstStrmIn Guest input stream to check for.
*/
{
uint32_t cSamplesLive = pGstStrmIn->pHstStrmIn->cTotalSamplesCaptured - pGstStrmIn->cTotalHostSamplesRead;
if (!cSamplesLive)
return 0;
/** @todo Document / refactor this! */
}
/**
* Returns the total number of unused sample data (in bytes) of a certain
* guest output stream.
*
* @return uint32_t Number of unused sample data (in bytes), 0 if all used up.
* @param pGstStrmOut Guest output stream to check for.
*/
{
if (!cSamplesFree)
return 0;
/** @todo Document / refactor this! */
return (((int64_t) cSamplesFree << 32) / pGstStrmOut->State.uFreqRatio) << pGstStrmOut->Props.cShift;
}
#endif
{
int cBits = 8;
bool fSigned = false;
{
case AUD_FMT_S8:
fSigned = true;
case AUD_FMT_U8:
break;
case AUD_FMT_S16:
fSigned = true;
case AUD_FMT_U16:
cBits = 16;
break;
case AUD_FMT_S32:
fSigned = true;
case AUD_FMT_U32:
cBits = 32;
break;
default:
break;
}
return fEqual;
}
{
int rc = VINF_SUCCESS;
bool fSigned = false;
{
case AUD_FMT_S8:
fSigned = true;
case AUD_FMT_U8:
break;
case AUD_FMT_S16:
fSigned = true;
case AUD_FMT_U16:
cBits = 16;
cShift = 1;
break;
case AUD_FMT_S32:
fSigned = true;
case AUD_FMT_U32:
cBits = 32;
cShift = 2;
break;
default:
break;
}
if (RT_SUCCESS(rc))
{
}
#ifdef DEBUG
#endif
return rc;
}
{
LogFlowFunc(("uHz=%RU32, cChannels=%RU8, enmFormat=",
{
case AUD_FMT_S8:
LogFlow(("S8"));
break;
case AUD_FMT_U8:
LogFlow(("U8"));
break;
case AUD_FMT_S16:
LogFlow(("S16"));
break;
case AUD_FMT_U16:
LogFlow(("U16"));
break;
case AUD_FMT_S32:
LogFlow(("S32"));
break;
case AUD_FMT_U32:
LogFlow(("U32"));
break;
default:
break;
}
LogFlow((", endianness="));
switch (pCfg->enmEndianness)
{
case PDMAUDIOENDIANESS_LITTLE:
LogFlow(("little\n"));
break;
case PDMAUDIOENDIANESS_BIG:
LogFlow(("big\n"));
break;
default:
LogFlow(("invalid\n"));
break;
}
}
/**
* Returns the minimum number of live samples already written to all associated
* guest output streams of a specific host output stream.
*
* @return uint32_t Minimum number of total live samples already written to all
* associated guest output streams, UINT32_MAX if none found.
* @param pHstStrmOut Host output stream to search in.
* @param pcStreamsLive Returns the number of live guest streams associated to
* this host output stream. Optional.
*/
static uint32_t drvAudioHstOutMinSamplesMixed(PPDMAUDIOHSTSTRMOUT pHstStrmOut, uint32_t *pcStreamsLive)
{
/* pcStreamsLive is optional. */
uint32_t cStreamsLive = 0;
{
{
cStreamsLive++;
}
}
if (pcStreamsLive)
return cMinSamplesMixed;
}
/**
* Finds the number of live (guest) samples of a specific host output stream.
*
* @return uint32_t Minimum number of live host output samples processed
* by all connected guest output streams.
* @param pHstStrmOut Host output stream to search in.
* @param pcStreamsLive Number of associated guest live streams. Optional.
*/
{
/* pcStreamsLive is optional. */
if (pcStreamsLive)
if (cStreamsLive) /* Any live streams at all? */
{
if ( cSamplesMin == UINT32_MAX
{
return 0;
}
return cSamplesMin;
}
return 0;
}