AudioAdapterImpl.cpp revision 6f0c02346cb86a521150bb90b064f439e03e2a6d
/** @file
*
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* 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.
*/
#include "AudioAdapterImpl.h"
#include "MachineImpl.h"
#include "Logging.h"
#include <iprt/cpputils.h>
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
return S_OK;
}
void AudioAdapter::FinalRelease()
{
uninit ();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the audio adapter object.
*
* @param aParent Handle of the parent object.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan (this);
/* mPeer is left null */
/* Confirm a successful initialization */
return S_OK;
}
/**
* Initializes the audio adapter object given another audio adapter object
* (a kind of copy constructor). This object shares data with
* the object passed as an argument.
*
* @note This object must be destroyed before the original object
* it shares data with is destroyed.
*
* @note Locks @a aThat object for reading.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan (this);
/* Confirm a successful initialization */
return S_OK;
}
/**
* Initializes the guest object given another guest object
* (a kind of copy constructor). This object makes a private copy of data
* of the original object passed as an argument.
*
* @note Locks @a aThat object for reading.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan (this);
/* mPeer is left null */
/* Confirm a successful initialization */
return S_OK;
}
/**
* Uninitializes the instance and sets the ready flag to FALSE.
* Called either from FinalRelease() or by the parent when it gets destroyed.
*/
void AudioAdapter::uninit()
{
LogFlowThisFunc (("\n"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan (this);
if (autoUninitSpan.uninitDone())
return;
}
// IAudioAdapter properties
/////////////////////////////////////////////////////////////////////////////
{
if (!aEnabled)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
{
}
return S_OK;
}
{
if (!aAudioDriver)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
{
/*
* which audio driver type are we supposed to use?
*/
switch (aAudioDriver)
{
case AudioDriverType_Null:
#ifdef RT_OS_WINDOWS
# ifdef VBOX_WITH_WINMM
case AudioDriverType_WinMM:
# endif
#endif /* RT_OS_WINDOWS */
#ifdef RT_OS_LINUX
case AudioDriverType_OSS:
# ifdef VBOX_WITH_ALSA
case AudioDriverType_ALSA:
# endif
# ifdef VBOX_WITH_PULSE
case AudioDriverType_Pulse:
# endif
#endif /* RT_OS_LINUX */
#ifdef RT_OS_DARWIN
#endif
#ifdef RT_OS_OS2
case AudioDriverType_MMPM:
#endif
{
break;
}
default:
{
AssertMsgFailed (("Wrong audio driver type %d\n",
aAudioDriver));
}
}
}
return rc;
}
{
if (!aAudioController)
return E_POINTER;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
{
/*
* which audio hardware type are we supposed to use?
*/
switch (aAudioController)
{
case AudioControllerType_AC97:
case AudioControllerType_SB16:
break;
default:
{
AssertMsgFailed (("Wrong audio controller type %d\n",
}
}
}
return rc;
}
// IAudioAdapter methods
/////////////////////////////////////////////////////////////////////////////
// public methods only for internal purposes
/////////////////////////////////////////////////////////////////////////////
/**
* Loads settings from the given machine node.
* May be called once right after this object creation.
*
* @param aMachineNode <Machine> node.
*
* @note Locks this object for writing.
*/
{
using namespace settings;
AutoCaller autoCaller (this);
/* Note: we assume that the default values for attributes of optional
* nodes are assigned in the Data::Data() constructor and don't do it
* here. It implies that this method may only be called after constructing
* a new BIOSSettings object while all its data fields are in the default
* values. Exceptions are fields whose creation time defaults don't match
* values that should be applied when these fields are not explicitly set
* in the settings file (for backwards compatibility reasons). This takes
* place when a setting of a newly created object must default to A while
* the same setting of an object loaded from the old settings file must
* default to B. */
/* AudioAdapter node (required) */
/* is the adapter enabled? (required) */
/* now check the audio adapter (not required, default is AC97) */
else
/* now check the audio driver (required) */
; /* Null has been set above */
#ifdef RT_OS_WINDOWS
#ifdef VBOX_WITH_WINMM
#else
/* fall back to dsound */
#endif
#endif // RT_OS_WINDOWS
#ifdef RT_OS_LINUX
# ifdef VBOX_WITH_ALSA
# else
/* fall back to OSS */
# endif
# ifdef VBOX_WITH_PULSE
# else
/* fall back to OSS */
# endif
#endif // RT_OS_LINUX
#ifdef RT_OS_DARWIN
#endif
#ifdef RT_OS_OS2
#endif
else
return S_OK;
}
/**
* Saves settings to the given machine node.
*
* @param aMachineNode <Machine> node.
*
* @note Locks this object for reading.
*/
{
using namespace settings;
AutoCaller autoCaller (this);
AutoReaderLock alock (this);
const char *controllerStr = NULL;
switch (mData->mAudioController)
{
case AudioControllerType_SB16:
{
controllerStr = "SB16";
break;
}
default:
{
controllerStr = "AC97";
break;
}
}
switch (mData->mAudioDriver)
{
case AudioDriverType_Null:
{
driverStr = "Null";
break;
}
#ifdef RT_OS_WINDOWS
case AudioDriverType_WinMM:
# ifdef VBOX_WITH_WINMM
{
driverStr = "WinMM";
break;
}
# endif
{
driverStr = "DirectSound";
break;
}
#endif /* RT_OS_WINDOWS */
#ifdef RT_OS_LINUX
case AudioDriverType_ALSA:
# ifdef VBOX_WITH_ALSA
{
driverStr = "ALSA";
break;
}
# endif
case AudioDriverType_Pulse:
# ifdef VBOX_WITH_PULSE
{
driverStr = "Pulse";
break;
}
# endif
case AudioDriverType_OSS:
{
driverStr = "OSS";
break;
}
#endif /* RT_OS_LINUX */
#ifdef RT_OS_DARWIN
{
driverStr = "CoreAudio";
break;
}
#endif
#ifdef RT_OS_OS2
case AudioDriverType_MMPM:
{
driverStr = "MMPM";
break;
}
#endif
default:
ComAssertMsgFailedRet (("Wrong audio driver type! driver = %d\n",
E_FAIL);
}
return S_OK;
}
/**
* @note Locks this object for writing.
*/
bool AudioAdapter::rollback()
{
/* sanity */
AutoCaller autoCaller (this);
bool changed = false;
if (mData.isBackedUp())
{
/* we need to check all data to see whether anything will be changed
* after rollback */
}
return changed;
}
/**
* @note Locks this object for writing, together with the peer object (also
* for writing) if there is one.
*/
void AudioAdapter::commit()
{
/* sanity */
AutoCaller autoCaller (this);
/* sanity too */
/* lock both for writing since we modify both */
if (mData.isBackedUp())
{
if (mPeer)
{
/* attach new data to the peer and reshare it */
}
}
}
/**
* @note Locks this object for writing, together with the peer object
* represented by @a aThat (locked for reading).
*/
{
/* sanity */
AutoCaller autoCaller (this);
/* sanity too */
/* peer is not modified, lock it for reading */
/* this will back up current data */
}