VirtualBox

source: vbox/trunk/src/VBox/Main/AudioAdapterImpl.cpp@ 2981

Last change on this file since 2981 was 2981, checked in by vboxsync, 18 years ago

InnoTek -> innotek: all the headers and comments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#include "AudioAdapterImpl.h"
23#include "MachineImpl.h"
24#include "Logging.h"
25
26// constructor / destructor
27/////////////////////////////////////////////////////////////////////////////
28
29HRESULT AudioAdapter::FinalConstruct()
30{
31 return S_OK;
32}
33
34void AudioAdapter::FinalRelease()
35{
36 if (isReady())
37 uninit ();
38}
39
40// public initializer/uninitializer for internal purposes only
41/////////////////////////////////////////////////////////////////////////////
42
43/**
44 * Initializes the audio adapter object.
45 *
46 * @returns COM result indicator
47 */
48HRESULT AudioAdapter::init (Machine *parent)
49{
50 LogFlowMember (("AudioAdapter::init (%p)\n", parent));
51
52 ComAssertRet (parent, E_INVALIDARG);
53
54 AutoLock alock (this);
55 ComAssertRet (!isReady(), E_UNEXPECTED);
56
57 mParent = parent;
58 // mPeer is left null
59
60 mData.allocate();
61
62 setReady (true);
63 return S_OK;
64}
65
66/**
67 * Initializes the audio adapter object given another audio adapter object
68 * (a kind of copy constructor). This object shares data with
69 * the object passed as an argument.
70 *
71 * @note This object must be destroyed before the original object
72 * it shares data with is destroyed.
73 */
74HRESULT AudioAdapter::init (Machine *parent, AudioAdapter *that)
75{
76 LogFlowMember (("AudioAdapter::init (%p, %p)\n", parent, that));
77
78 ComAssertRet (parent && that, E_INVALIDARG);
79
80 AutoLock alock (this);
81 ComAssertRet (!isReady(), E_UNEXPECTED);
82
83 mParent = parent;
84 mPeer = that;
85
86 AutoLock thatlock (that);
87 mData.share (that->mData);
88
89 setReady (true);
90 return S_OK;
91}
92
93/**
94 * Initializes the guest object given another guest object
95 * (a kind of copy constructor). This object makes a private copy of data
96 * of the original object passed as an argument.
97 */
98HRESULT AudioAdapter::initCopy (Machine *parent, AudioAdapter *that)
99{
100 LogFlowMember (("AudioAdapter::initCopy (%p, %p)\n", parent, that));
101
102 ComAssertRet (parent && that, E_INVALIDARG);
103
104 AutoLock alock (this);
105 ComAssertRet (!isReady(), E_UNEXPECTED);
106
107 mParent = parent;
108 // mPeer is left null
109
110 AutoLock thatlock (that);
111 mData.attachCopy (that->mData);
112
113 setReady (true);
114 return S_OK;
115}
116
117/**
118 * Uninitializes the instance and sets the ready flag to FALSE.
119 * Called either from FinalRelease() or by the parent when it gets destroyed.
120 */
121void AudioAdapter::uninit()
122{
123 LogFlowMember (("AudioAdapter::uninit()\n"));
124
125 AutoLock alock (this);
126 AssertReturn (isReady(), (void) 0);
127
128 mData.free();
129
130 mPeer.setNull();
131 mParent.setNull();
132
133 setReady(false);
134}
135
136// IAudioAdapter properties
137/////////////////////////////////////////////////////////////////////////////
138
139/**
140 * Returns the enabled status
141 *
142 * @returns COM status code
143 * @param enabled address of result variable
144 */
145STDMETHODIMP AudioAdapter::COMGETTER(Enabled)(BOOL *enabled)
146{
147 if (!enabled)
148 return E_POINTER;
149
150 AutoLock lock(this);
151 CHECK_READY();
152
153 *enabled = mData->mEnabled;
154 return S_OK;
155}
156
157/**
158 * Sets the enabled state
159 *
160 * @returns COM status code
161 * @param enabled address of result variable
162 */
163STDMETHODIMP AudioAdapter::COMSETTER(Enabled)(BOOL enabled)
164{
165 AutoLock lock(this);
166 CHECK_READY();
167
168 CHECK_MACHINE_MUTABILITY (mParent);
169
170 if (mData->mEnabled != enabled)
171 {
172 mData.backup();
173 mData->mEnabled = enabled;
174 }
175
176 return S_OK;
177}
178
179/**
180 * Returns the current audio driver type
181 *
182 * @returns COM status code
183 * @param audioDriver address of result variable
184 */
185STDMETHODIMP AudioAdapter::COMGETTER(AudioDriver)(AudioDriverType_T *audioDriver)
186{
187 if (!audioDriver)
188 return E_POINTER;
189
190 AutoLock lock(this);
191 CHECK_READY();
192
193 *audioDriver = mData->mAudioDriver;
194 return S_OK;
195}
196
197/**
198 * Sets the audio driver type
199 *
200 * @returns COM status code
201 * @param audioDriver audio driver type to use
202 */
203STDMETHODIMP AudioAdapter::COMSETTER(AudioDriver)(AudioDriverType_T audioDriver)
204{
205 AutoLock lock(this);
206 CHECK_READY();
207
208 CHECK_MACHINE_MUTABILITY (mParent);
209
210 HRESULT rc = S_OK;
211
212 if (mData->mAudioDriver != audioDriver)
213 {
214 /*
215 * which audio driver type are we supposed to use?
216 */
217 switch (audioDriver)
218 {
219 case AudioDriverType_NullAudioDriver:
220#ifdef __WIN__
221#ifdef VBOX_WITH_WINMM
222 case AudioDriverType_WINMMAudioDriver:
223#endif
224 case AudioDriverType_DSOUNDAudioDriver:
225#endif /* __WIN__ */
226#ifdef __LINUX__
227 case AudioDriverType_OSSAudioDriver:
228#ifdef VBOX_WITH_ALSA
229 case AudioDriverType_ALSAAudioDriver:
230#endif
231#endif /* __LINUX__ */
232#ifdef __DARWIN__
233 case AudioDriverType_CoreAudioDriver:
234#endif
235 {
236 mData.backup();
237 mData->mAudioDriver = audioDriver;
238 break;
239 }
240
241 default:
242 {
243 Log(("wrong audio driver type specified!\n"));
244 rc = E_FAIL;
245 }
246 }
247 }
248
249 return rc;
250}
251
252// IAudioAdapter methods
253/////////////////////////////////////////////////////////////////////////////
254
255// public methods only for internal purposes
256/////////////////////////////////////////////////////////////////////////////
257
258void AudioAdapter::commit()
259{
260 AutoLock alock (this);
261 if (mData.isBackedUp())
262 {
263 mData.commit();
264 if (mPeer)
265 {
266 // attach new data to the peer and reshare it
267 AutoLock peerlock (mPeer);
268 mPeer->mData.attach (mData);
269 }
270 }
271}
272
273void AudioAdapter::copyFrom (AudioAdapter *aThat)
274{
275 AutoLock alock (this);
276
277 // this will back up current data
278 mData.assignCopy (aThat->mData);
279}
280
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette