AudioAdapterImpl.cpp revision 26d2a42f095ded346df2e41cc4837cb426b4753a
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/** @file
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync *
c5b9358e561295f178bc3e0d299bf9c02d357d0evboxsync * VirtualBox COM class implementation
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/*
c58f1213e628a545081c70e26c6b67a841cff880vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync *
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * available from http://www.virtualbox.org. This file is free software;
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync *
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * additional information or have any questions.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync */
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync#include "AudioAdapterImpl.h"
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync#include "MachineImpl.h"
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync#include "Logging.h"
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync#include <iprt/cpputils.h>
8c99dcd207cf5b7bee01f95fbe19728a94076f94vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync// constructor / destructor
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/////////////////////////////////////////////////////////////////////////////
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
715e49c31b15c23c17a9ce3be42a75e7c48d4b78vboxsyncDEFINE_EMPTY_CTOR_DTOR (AudioAdapter)
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
8c99dcd207cf5b7bee01f95fbe19728a94076f94vboxsyncHRESULT AudioAdapter::FinalConstruct()
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync{
8c99dcd207cf5b7bee01f95fbe19728a94076f94vboxsync return S_OK;
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync}
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
cbd4e5863be36b70c59ebeb02a611a763f9d58f1vboxsyncvoid AudioAdapter::FinalRelease()
cbd4e5863be36b70c59ebeb02a611a763f9d58f1vboxsync{
cbd4e5863be36b70c59ebeb02a611a763f9d58f1vboxsync uninit ();
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync}
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync// public initializer/uninitializer for internal purposes only
9c11b89c71ca727d975c39f2719063501ddcd03dvboxsync/////////////////////////////////////////////////////////////////////////////
8c99dcd207cf5b7bee01f95fbe19728a94076f94vboxsync
8c99dcd207cf5b7bee01f95fbe19728a94076f94vboxsync/**
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * Initializes the audio adapter object.
3bad884471a4755d52abffc98cc326f153750ca1vboxsync *
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * @param aParent Handle of the parent object.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsyncHRESULT AudioAdapter::init (Machine *aParent)
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync{
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync LogFlowThisFunc (("aParent=%p\n", aParent));
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync ComAssertRet (aParent, E_INVALIDARG);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync /* Enclose the state transition NotReady->InInit->Ready */
3bad884471a4755d52abffc98cc326f153750ca1vboxsync AutoInitSpan autoInitSpan (this);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync AssertReturn (autoInitSpan.isOk(), E_FAIL);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync unconst (mParent) = aParent;
3bad884471a4755d52abffc98cc326f153750ca1vboxsync /* mPeer is left null */
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
5eb8c49f193655f19bb89b653df8643091fa987bvboxsync mData.allocate();
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
5eb8c49f193655f19bb89b653df8643091fa987bvboxsync /* Confirm a successful initialization */
4030b8473736055cd02947418ef4f8f9b1945323vboxsync autoInitSpan.setSucceeded();
4030b8473736055cd02947418ef4f8f9b1945323vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync return S_OK;
3bad884471a4755d52abffc98cc326f153750ca1vboxsync}
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync/**
3bad884471a4755d52abffc98cc326f153750ca1vboxsync * Initializes the audio adapter object given another audio adapter object
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * (a kind of copy constructor). This object shares data with
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * the object passed as an argument.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync *
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * @note This object must be destroyed before the original object
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * it shares data with is destroyed.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync *
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * @note Locks @a aThat object for reading.
c1a925cf66044662d1265e27eab1337d409f124dvboxsync */
c1a925cf66044662d1265e27eab1337d409f124dvboxsyncHRESULT AudioAdapter::init (Machine *aParent, AudioAdapter *aThat)
dc95659cf2f6c5830e66313b6046e4317881035bvboxsync{
dc95659cf2f6c5830e66313b6046e4317881035bvboxsync LogFlowThisFunc (("aParent=%p, aThat=%p\n", aParent, aThat));
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
e961f5bfe1727c6816d3dad3805ebe21b6ba1c64vboxsync ComAssertRet (aParent && aThat, E_INVALIDARG);
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
b34f0f200ed0778053a2a1d93381c2c6b60cb2d5vboxsync /* Enclose the state transition NotReady->InInit->Ready */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync AutoInitSpan autoInitSpan (this);
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync AssertReturn (autoInitSpan.isOk(), E_FAIL);
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync unconst (mParent) = aParent;
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync unconst (mPeer) = aThat;
9c11b89c71ca727d975c39f2719063501ddcd03dvboxsync
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync AutoCaller thatCaller (aThat);
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync AssertComRCReturnRC (thatCaller.rc());
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync AutoReadLock thatLock (aThat);
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync mData.share (aThat->mData);
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync /* Confirm a successful initialization */
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync autoInitSpan.setSucceeded();
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync
418b9db49fbc652ef9c3f030fdc0f1a322403d95vboxsync return S_OK;
418b9db49fbc652ef9c3f030fdc0f1a322403d95vboxsync}
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync
9c11b89c71ca727d975c39f2719063501ddcd03dvboxsync/**
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * Initializes the guest object given another guest object
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync * (a kind of copy constructor). This object makes a private copy of data
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync * of the original object passed as an argument.
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync *
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync * @note Locks @a aThat object for reading.
c1a925cf66044662d1265e27eab1337d409f124dvboxsync */
dc95659cf2f6c5830e66313b6046e4317881035bvboxsyncHRESULT AudioAdapter::initCopy (Machine *aParent, AudioAdapter *aThat)
dc95659cf2f6c5830e66313b6046e4317881035bvboxsync{
3bad884471a4755d52abffc98cc326f153750ca1vboxsync LogFlowThisFunc (("aParent=%p, aThat=%p\n", aParent, aThat));
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync ComAssertRet (aParent && aThat, E_INVALIDARG);
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync /* Enclose the state transition NotReady->InInit->Ready */
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync AutoInitSpan autoInitSpan (this);
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync AssertReturn (autoInitSpan.isOk(), E_FAIL);
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync unconst (mParent) = aParent;
3bad884471a4755d52abffc98cc326f153750ca1vboxsync /* mPeer is left null */
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync AutoCaller thatCaller (aThat);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync AssertComRCReturnRC (thatCaller.rc());
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync AutoReadLock thatLock (aThat);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync mData.attachCopy (aThat->mData);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync /* Confirm a successful initialization */
175770d4533d92ff4ef576d5ea97e566cc488472vboxsync autoInitSpan.setSucceeded();
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync return S_OK;
3bad884471a4755d52abffc98cc326f153750ca1vboxsync}
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync/**
3bad884471a4755d52abffc98cc326f153750ca1vboxsync * Uninitializes the instance and sets the ready flag to FALSE.
3bad884471a4755d52abffc98cc326f153750ca1vboxsync * Called either from FinalRelease() or by the parent when it gets destroyed.
3bad884471a4755d52abffc98cc326f153750ca1vboxsync */
3bad884471a4755d52abffc98cc326f153750ca1vboxsyncvoid AudioAdapter::uninit()
3bad884471a4755d52abffc98cc326f153750ca1vboxsync{
3bad884471a4755d52abffc98cc326f153750ca1vboxsync LogFlowThisFunc (("\n"));
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync /* Enclose the state transition Ready->InUninit->NotReady */
3bad884471a4755d52abffc98cc326f153750ca1vboxsync AutoUninitSpan autoUninitSpan (this);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync if (autoUninitSpan.uninitDone())
3bad884471a4755d52abffc98cc326f153750ca1vboxsync return;
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync mData.free();
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync unconst (mPeer).setNull();
3bad884471a4755d52abffc98cc326f153750ca1vboxsync unconst (mParent).setNull();
3bad884471a4755d52abffc98cc326f153750ca1vboxsync}
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync// IAudioAdapter properties
3bad884471a4755d52abffc98cc326f153750ca1vboxsync/////////////////////////////////////////////////////////////////////////////
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsyncSTDMETHODIMP AudioAdapter::COMGETTER(Enabled)(BOOL *aEnabled)
3bad884471a4755d52abffc98cc326f153750ca1vboxsync{
3bad884471a4755d52abffc98cc326f153750ca1vboxsync if (!aEnabled)
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync return E_POINTER;
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync AutoCaller autoCaller (this);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync CheckComRCReturnRC (autoCaller.rc());
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync AutoReadLock alock (this);
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync *aEnabled = mData->mEnabled;
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync return S_OK;
3bad884471a4755d52abffc98cc326f153750ca1vboxsync}
8c99dcd207cf5b7bee01f95fbe19728a94076f94vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsyncSTDMETHODIMP AudioAdapter::COMSETTER(Enabled)(BOOL aEnabled)
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync{
d66f73c3fe5c4de905e6b8623d2d3fe170628358vboxsync AutoCaller autoCaller (this);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync CheckComRCReturnRC (autoCaller.rc());
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync /* the machine needs to be mutable */
3bad884471a4755d52abffc98cc326f153750ca1vboxsync Machine::AutoMutableStateDependency adep (mParent);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync CheckComRCReturnRC (adep.rc());
d66f73c3fe5c4de905e6b8623d2d3fe170628358vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync AutoWriteLock alock (this);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync if (mData->mEnabled != aEnabled)
3bad884471a4755d52abffc98cc326f153750ca1vboxsync {
3bad884471a4755d52abffc98cc326f153750ca1vboxsync mData.backup();
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync mData->mEnabled = aEnabled;
3bad884471a4755d52abffc98cc326f153750ca1vboxsync }
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync return S_OK;
3bad884471a4755d52abffc98cc326f153750ca1vboxsync}
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsyncSTDMETHODIMP AudioAdapter::COMGETTER(AudioDriver)(AudioDriverType_T *aAudioDriver)
3bad884471a4755d52abffc98cc326f153750ca1vboxsync{
3bad884471a4755d52abffc98cc326f153750ca1vboxsync if (!aAudioDriver)
3bad884471a4755d52abffc98cc326f153750ca1vboxsync return E_POINTER;
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync AutoCaller autoCaller (this);
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync CheckComRCReturnRC (autoCaller.rc());
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync AutoReadLock alock (this);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync *aAudioDriver = mData->mAudioDriver;
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync
8c99dcd207cf5b7bee01f95fbe19728a94076f94vboxsync return S_OK;
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync}
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync
8c99dcd207cf5b7bee01f95fbe19728a94076f94vboxsyncSTDMETHODIMP AudioAdapter::COMSETTER(AudioDriver)(AudioDriverType_T aAudioDriver)
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync{
3bad884471a4755d52abffc98cc326f153750ca1vboxsync AutoCaller autoCaller (this);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync CheckComRCReturnRC (autoCaller.rc());
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
69dc0354ae98899256f5e73898f1dc973345ee65vboxsync /* the machine needs to be mutable */
3bad884471a4755d52abffc98cc326f153750ca1vboxsync Machine::AutoMutableStateDependency adep (mParent);
69dc0354ae98899256f5e73898f1dc973345ee65vboxsync CheckComRCReturnRC (adep.rc());
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync AutoWriteLock alock (this);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync HRESULT rc = S_OK;
69dc0354ae98899256f5e73898f1dc973345ee65vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync if (mData->mAudioDriver != aAudioDriver)
542b82b1871753dc94a2a17b504094112f9df306vboxsync {
3bad884471a4755d52abffc98cc326f153750ca1vboxsync /*
3bad884471a4755d52abffc98cc326f153750ca1vboxsync * which audio driver type are we supposed to use?
3bad884471a4755d52abffc98cc326f153750ca1vboxsync */
3bad884471a4755d52abffc98cc326f153750ca1vboxsync switch (aAudioDriver)
542b82b1871753dc94a2a17b504094112f9df306vboxsync {
69dc0354ae98899256f5e73898f1dc973345ee65vboxsync case AudioDriverType_Null:
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync#ifdef RT_OS_WINDOWS
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync# ifdef VBOX_WITH_WINMM
3bad884471a4755d52abffc98cc326f153750ca1vboxsync case AudioDriverType_WinMM:
2ee7a36e525389d535649872c492332c9d92b139vboxsync# endif
858960add9f9dc845ad839300639ca2d932a1715vboxsync case AudioDriverType_DirectSound:
858960add9f9dc845ad839300639ca2d932a1715vboxsync#endif /* RT_OS_WINDOWS */
858960add9f9dc845ad839300639ca2d932a1715vboxsync#ifdef RT_OS_SOLARIS
858960add9f9dc845ad839300639ca2d932a1715vboxsync case AudioDriverType_SolAudio:
8c99dcd207cf5b7bee01f95fbe19728a94076f94vboxsync#endif
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync#ifdef RT_OS_LINUX
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync case AudioDriverType_OSS:
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync# ifdef VBOX_WITH_ALSA
8c99dcd207cf5b7bee01f95fbe19728a94076f94vboxsync case AudioDriverType_ALSA:
3bad884471a4755d52abffc98cc326f153750ca1vboxsync# endif
3bad884471a4755d52abffc98cc326f153750ca1vboxsync# ifdef VBOX_WITH_PULSE
3bad884471a4755d52abffc98cc326f153750ca1vboxsync case AudioDriverType_Pulse:
3bad884471a4755d52abffc98cc326f153750ca1vboxsync# endif
3bad884471a4755d52abffc98cc326f153750ca1vboxsync#endif /* RT_OS_LINUX */
3bad884471a4755d52abffc98cc326f153750ca1vboxsync#ifdef RT_OS_DARWIN
3bad884471a4755d52abffc98cc326f153750ca1vboxsync case AudioDriverType_CoreAudio:
3bad884471a4755d52abffc98cc326f153750ca1vboxsync#endif
3bad884471a4755d52abffc98cc326f153750ca1vboxsync#ifdef RT_OS_OS2
3bad884471a4755d52abffc98cc326f153750ca1vboxsync case AudioDriverType_MMPM:
3bad884471a4755d52abffc98cc326f153750ca1vboxsync#endif
0e7d0c39cbbe71e242bb3c9376a736f6169b7efbvboxsync {
0e7d0c39cbbe71e242bb3c9376a736f6169b7efbvboxsync mData.backup();
3bad884471a4755d52abffc98cc326f153750ca1vboxsync mData->mAudioDriver = aAudioDriver;
0e7d0c39cbbe71e242bb3c9376a736f6169b7efbvboxsync break;
3bad884471a4755d52abffc98cc326f153750ca1vboxsync }
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync default:
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync {
3bad884471a4755d52abffc98cc326f153750ca1vboxsync AssertMsgFailed (("Wrong audio driver type %d\n",
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync aAudioDriver));
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync rc = E_FAIL;
3bad884471a4755d52abffc98cc326f153750ca1vboxsync }
3bad884471a4755d52abffc98cc326f153750ca1vboxsync }
3bad884471a4755d52abffc98cc326f153750ca1vboxsync }
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync return rc;
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync}
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsyncSTDMETHODIMP AudioAdapter::COMGETTER(AudioController)(AudioControllerType_T *aAudioController)
3bad884471a4755d52abffc98cc326f153750ca1vboxsync{
3bad884471a4755d52abffc98cc326f153750ca1vboxsync if (!aAudioController)
3bad884471a4755d52abffc98cc326f153750ca1vboxsync return E_POINTER;
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync AutoCaller autoCaller (this);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync CheckComRCReturnRC (autoCaller.rc());
56665b35e85d3cd7d4232957d09b488ab44d81cfvboxsync
5eb8c49f193655f19bb89b653df8643091fa987bvboxsync AutoReadLock alock (this);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync *aAudioController = mData->mAudioController;
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync return S_OK;
3bad884471a4755d52abffc98cc326f153750ca1vboxsync}
56665b35e85d3cd7d4232957d09b488ab44d81cfvboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsyncSTDMETHODIMP AudioAdapter::COMSETTER(AudioController)(AudioControllerType_T aAudioController)
3bad884471a4755d52abffc98cc326f153750ca1vboxsync{
3bad884471a4755d52abffc98cc326f153750ca1vboxsync AutoCaller autoCaller (this);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync CheckComRCReturnRC (autoCaller.rc());
0e7d0c39cbbe71e242bb3c9376a736f6169b7efbvboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync /* the machine needs to be mutable */
3bad884471a4755d52abffc98cc326f153750ca1vboxsync Machine::AutoMutableStateDependency adep (mParent);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync CheckComRCReturnRC (adep.rc());
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
0e7d0c39cbbe71e242bb3c9376a736f6169b7efbvboxsync AutoWriteLock alock (this);
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync HRESULT rc = S_OK;
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync if (mData->mAudioController != aAudioController)
0e7d0c39cbbe71e242bb3c9376a736f6169b7efbvboxsync {
3bad884471a4755d52abffc98cc326f153750ca1vboxsync /*
3bad884471a4755d52abffc98cc326f153750ca1vboxsync * which audio hardware type are we supposed to use?
4030b8473736055cd02947418ef4f8f9b1945323vboxsync */
0e7d0c39cbbe71e242bb3c9376a736f6169b7efbvboxsync switch (aAudioController)
3bad884471a4755d52abffc98cc326f153750ca1vboxsync {
0e7d0c39cbbe71e242bb3c9376a736f6169b7efbvboxsync case AudioControllerType_AC97:
3bad884471a4755d52abffc98cc326f153750ca1vboxsync case AudioControllerType_SB16:
56665b35e85d3cd7d4232957d09b488ab44d81cfvboxsync mData.backup();
dc95659cf2f6c5830e66313b6046e4317881035bvboxsync mData->mAudioController = aAudioController;
3bad884471a4755d52abffc98cc326f153750ca1vboxsync break;
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync default:
d66f73c3fe5c4de905e6b8623d2d3fe170628358vboxsync {
d66f73c3fe5c4de905e6b8623d2d3fe170628358vboxsync AssertMsgFailed (("Wrong audio controller type %d\n",
a734bb626f889ee3334bfc381be194b4ec56aae6vboxsync aAudioController));
3bad884471a4755d52abffc98cc326f153750ca1vboxsync rc = E_FAIL;
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync }
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync }
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync }
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync return rc;
727cf0d6c794dffee1023d2bbb6e94eda7f35ca9vboxsync}
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync// IAudioAdapter methods
3bad884471a4755d52abffc98cc326f153750ca1vboxsync/////////////////////////////////////////////////////////////////////////////
3bad884471a4755d52abffc98cc326f153750ca1vboxsync
3bad884471a4755d52abffc98cc326f153750ca1vboxsync// public methods only for internal purposes
3bad884471a4755d52abffc98cc326f153750ca1vboxsync/////////////////////////////////////////////////////////////////////////////
727cf0d6c794dffee1023d2bbb6e94eda7f35ca9vboxsync
727cf0d6c794dffee1023d2bbb6e94eda7f35ca9vboxsync/**
727cf0d6c794dffee1023d2bbb6e94eda7f35ca9vboxsync * Loads settings from the given machine node.
3bad884471a4755d52abffc98cc326f153750ca1vboxsync * May be called once right after this object creation.
3bad884471a4755d52abffc98cc326f153750ca1vboxsync *
727cf0d6c794dffee1023d2bbb6e94eda7f35ca9vboxsync * @param aMachineNode <Machine> node.
3bad884471a4755d52abffc98cc326f153750ca1vboxsync *
3bad884471a4755d52abffc98cc326f153750ca1vboxsync * @note Locks this object for writing.
727cf0d6c794dffee1023d2bbb6e94eda7f35ca9vboxsync */
c1a925cf66044662d1265e27eab1337d409f124dvboxsyncHRESULT AudioAdapter::loadSettings (const settings::Key &aMachineNode)
e0e7da0420be1398d23ffa9953686d3a43619abdvboxsync{
e0e7da0420be1398d23ffa9953686d3a43619abdvboxsync using namespace settings;
e0e7da0420be1398d23ffa9953686d3a43619abdvboxsync
e0e7da0420be1398d23ffa9953686d3a43619abdvboxsync AssertReturn (!aMachineNode.isNull(), E_FAIL);
e0e7da0420be1398d23ffa9953686d3a43619abdvboxsync
e0e7da0420be1398d23ffa9953686d3a43619abdvboxsync AutoCaller autoCaller (this);
AssertComRCReturnRC (autoCaller.rc());
AutoWriteLock alock (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) */
Key audioAdapterNode = aMachineNode.key ("AudioAdapter");
/* is the adapter enabled? (required) */
mData->mEnabled = audioAdapterNode.value <bool> ("enabled");
/* now check the audio adapter (not required, default is AC97) */
const char *controller = audioAdapterNode.stringValue ("controller");
if (strcmp (controller, "SB16") == 0)
mData->mAudioController = AudioControllerType_SB16;
else
mData->mAudioController = AudioControllerType_AC97;
/* now check the audio driver (required) */
const char *driver = audioAdapterNode.stringValue ("driver");
mData->mAudioDriver = AudioDriverType_Null;
if (strcmp (driver, "Null") == 0)
; /* Null has been set above */
#ifdef RT_OS_WINDOWS
else if (strcmp (driver, "WinMM") == 0)
#ifdef VBOX_WITH_WINMM
mData->mAudioDriver = AudioDriverType_WinMM;
#else
/* fall back to dsound */
mData->mAudioDriver = AudioDriverType_DirectSound;
#endif
else if (strcmp (driver, "DirectSound") == 0)
mData->mAudioDriver = AudioDriverType_DirectSound;
#endif // RT_OS_WINDOWS
#ifdef RT_OS_SOLARIS
else if (strcmp (driver, "SolAudio") == 0)
mData->mAudioDriver = AudioDriverType_SolAudio;
#endif // RT_OS_SOLARIS
#ifdef RT_OS_LINUX
else if (strcmp (driver, "OSS") == 0)
mData->mAudioDriver = AudioDriverType_OSS;
else if (strcmp (driver, "ALSA") == 0)
# ifdef VBOX_WITH_ALSA
mData->mAudioDriver = AudioDriverType_ALSA;
# else
/* fall back to OSS */
mData->mAudioDriver = AudioDriverType_OSS;
# endif
else if (strcmp (driver, "Pulse") == 0)
# ifdef VBOX_WITH_PULSE
mData->mAudioDriver = AudioDriverType_Pulse;
# else
/* fall back to OSS */
mData->mAudioDriver = AudioDriverType_OSS;
# endif
#endif // RT_OS_LINUX
#ifdef RT_OS_DARWIN
else if (strcmp (driver, "CoreAudio") == 0)
mData->mAudioDriver = AudioDriverType_CoreAudio;
#endif
#ifdef RT_OS_OS2
else if (strcmp (driver, "MMPM") == 0)
mData->mAudioDriver = AudioDriverType_MMPM;
#endif
else
AssertMsgFailed (("Invalid driver '%s'\n", driver));
return S_OK;
}
/**
* Saves settings to the given machine node.
*
* @param aMachineNode <Machine> node.
*
* @note Locks this object for reading.
*/
HRESULT AudioAdapter::saveSettings (settings::Key &aMachineNode)
{
using namespace settings;
AssertReturn (!aMachineNode.isNull(), E_FAIL);
AutoCaller autoCaller (this);
AssertComRCReturnRC (autoCaller.rc());
AutoReadLock alock (this);
Key node = aMachineNode.createKey ("AudioAdapter");
const char *controllerStr = NULL;
switch (mData->mAudioController)
{
case AudioControllerType_SB16:
{
controllerStr = "SB16";
break;
}
default:
{
controllerStr = "AC97";
break;
}
}
node.setStringValue ("controller", controllerStr);
const char *driverStr = NULL;
switch (mData->mAudioDriver)
{
case AudioDriverType_Null:
{
driverStr = "Null";
break;
}
#ifdef RT_OS_WINDOWS
case AudioDriverType_WinMM:
# ifdef VBOX_WITH_WINMM
{
driverStr = "WinMM";
break;
}
# endif
case AudioDriverType_DirectSound:
{
driverStr = "DirectSound";
break;
}
#endif /* RT_OS_WINDOWS */
#ifdef RT_OS_SOLARIS
case AudioDriverType_SolAudio:
{
driverStr = "SolAudio";
break;
}
#endif
#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
case AudioDriverType_CoreAudio:
{
driverStr = "CoreAudio";
break;
}
#endif
#ifdef RT_OS_OS2
case AudioDriverType_MMPM:
{
driverStr = "MMPM";
break;
}
#endif
default:
ComAssertMsgFailedRet (("Wrong audio driver type! driver = %d\n",
mData->mAudioDriver),
E_FAIL);
}
node.setStringValue ("driver", driverStr);
node.setValue <bool> ("enabled", !!mData->mEnabled);
return S_OK;
}
/**
* @note Locks this object for writing.
*/
bool AudioAdapter::rollback()
{
/* sanity */
AutoCaller autoCaller (this);
AssertComRCReturn (autoCaller.rc(), false);
AutoWriteLock alock (this);
bool changed = false;
if (mData.isBackedUp())
{
/* we need to check all data to see whether anything will be changed
* after rollback */
changed = mData.hasActualChanges();
mData.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);
AssertComRCReturnVoid (autoCaller.rc());
/* sanity too */
AutoCaller peerCaller (mPeer);
AssertComRCReturnVoid (peerCaller.rc());
/* lock both for writing since we modify both (mPeer is "master" so locked
* first) */
AutoMultiWriteLock2 alock (mPeer, this);
if (mData.isBackedUp())
{
mData.commit();
if (mPeer)
{
/* attach new data to the peer and reshare it */
mPeer->mData.attach (mData);
}
}
}
/**
* @note Locks this object for writing, together with the peer object
* represented by @a aThat (locked for reading).
*/
void AudioAdapter::copyFrom (AudioAdapter *aThat)
{
AssertReturnVoid (aThat != NULL);
/* sanity */
AutoCaller autoCaller (this);
AssertComRCReturnVoid (autoCaller.rc());
/* sanity too */
AutoCaller thatCaller (aThat);
AssertComRCReturnVoid (thatCaller.rc());
/* peer is not modified, lock it for reading (aThat is "master" so locked
* first) */
AutoMultiLock2 alock (aThat->rlock(), this->wlock());
/* this will back up current data */
mData.assignCopy (aThat->mData);
}