Jamoma API  0.6.0.a19
CAHALAudioObject.cpp
1 /* Copyright © 2007 Apple Inc. All Rights Reserved.
2 
3  Disclaimer: IMPORTANT: This Apple software is supplied to you by
4  Apple Inc. ("Apple") in consideration of your agreement to the
5  following terms, and your use, installation, modification or
6  redistribution of this Apple software constitutes acceptance of these
7  terms. If you do not agree with these terms, please do not use,
8  install, modify or redistribute this Apple software.
9 
10  In consideration of your agreement to abide by the following terms, and
11  subject to these terms, Apple grants you a personal, non-exclusive
12  license, under Apple's copyrights in this original Apple software (the
13  "Apple Software"), to use, reproduce, modify and redistribute the Apple
14  Software, with or without modifications, in source and/or binary forms;
15  provided that if you redistribute the Apple Software in its entirety and
16  without modifications, you must retain this notice and the following
17  text and disclaimers in all such redistributions of the Apple Software.
18  Neither the name, trademarks, service marks or logos of Apple Inc.
19  may be used to endorse or promote products derived from the Apple
20  Software without specific prior written permission from Apple. Except
21  as expressly stated in this notice, no other rights or licenses, express
22  or implied, are granted by Apple herein, including but not limited to
23  any patent rights that may be infringed by your derivative works or by
24  other works in which the Apple Software may be incorporated.
25 
26  The Apple Software is provided by Apple on an "AS IS" basis. APPLE
27  MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
28  THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
29  FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
30  OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
31 
32  IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
33  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
36  MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
37  AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
38  STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
39  POSSIBILITY OF SUCH DAMAGE.
40 */
41 //==================================================================================================
42 // Includes
43 //==================================================================================================
44 
45 // Self Include
46 #include "CAHALAudioObject.h"
47 
48 // PublicUtility Includes
49 #include "CAAutoDisposer.h"
50 #include "CADebugMacros.h"
51 #include "CAException.h"
52 #include "CAPropertyAddress.h"
53 
54 //==================================================================================================
55 // CAHALAudioObject
56 //==================================================================================================
57 
58 CAHALAudioObject::CAHALAudioObject(AudioObjectID inObjectID)
59 :
60  mObjectID(inObjectID)
61 {
62 }
63 
64 CAHALAudioObject::~CAHALAudioObject()
65 {
66 }
67 
68 AudioObjectID CAHALAudioObject::GetObjectID() const
69 {
70  return mObjectID;
71 }
72 
73 void CAHALAudioObject::SetObjectID(AudioObjectID inObjectID)
74 {
75  mObjectID = inObjectID;
76 }
77 
78 AudioClassID CAHALAudioObject::GetClassID() const
79 {
80  // set up the return value
81  AudioClassID theAnswer = 0;
82 
83  // set up the property address
84  CAPropertyAddress theAddress(kAudioObjectPropertyClass);
85 
86  // make sure the property exists
87  if(HasProperty(theAddress))
88  {
89  UInt32 theSize = sizeof(AudioClassID);
90  GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
91  }
92 
93  return theAnswer;
94 }
95 
96 AudioObjectID CAHALAudioObject::GetOwnerObjectID() const
97 {
98  // set up the return value
99  AudioObjectID theAnswer = 0;
100 
101  // set up the property address
102  CAPropertyAddress theAddress(kAudioObjectPropertyOwner);
103 
104  // make sure the property exists
105  if(HasProperty(theAddress))
106  {
107  // get the property data
108  UInt32 theSize = sizeof(AudioObjectID);
109  GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
110  }
111 
112  return theAnswer;
113 }
114 
115 CFStringRef CAHALAudioObject::CopyOwningPlugInBundleID() const
116 {
117  // set up the return value
118  CFStringRef theAnswer = NULL;
119 
120  // set up the property address
121  CAPropertyAddress theAddress(kAudioObjectPropertyCreator);
122 
123  // make sure the property exists
124  if(HasProperty(theAddress))
125  {
126  // get the property data
127  UInt32 theSize = sizeof(CFStringRef);
128  GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
129  }
130 
131  return theAnswer;
132 }
133 
134 CFStringRef CAHALAudioObject::CopyName() const
135 {
136  // set up the return value
137  CFStringRef theAnswer = NULL;
138 
139  // set up the property address
140  CAPropertyAddress theAddress(kAudioObjectPropertyName);
141 
142  // make sure the property exists
143  if(HasProperty(theAddress))
144  {
145  // get the property data
146  UInt32 theSize = sizeof(CFStringRef);
147  GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
148  }
149 
150  return theAnswer;
151 }
152 
153 CFStringRef CAHALAudioObject::CopyManufacturer() const
154 {
155  // set up the return value
156  CFStringRef theAnswer = NULL;
157 
158  // set up the property address
159  CAPropertyAddress theAddress(kAudioObjectPropertyManufacturer);
160 
161  // make sure the property exists
162  if(HasProperty(theAddress))
163  {
164  // get the property data
165  UInt32 theSize = sizeof(CFStringRef);
166  GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
167  }
168 
169  return theAnswer;
170 }
171 
172 CFStringRef CAHALAudioObject::CopyNameForElement(AudioObjectPropertyScope inScope, AudioObjectPropertyElement inElement) const
173 {
174  // set up the return value
175  CFStringRef theAnswer = NULL;
176 
177  // set up the property address
178  CAPropertyAddress theAddress(kAudioObjectPropertyElementName, inScope, inElement);
179 
180  // make sure the property exists
181  if(HasProperty(theAddress))
182  {
183  // get the property data
184  UInt32 theSize = sizeof(CFStringRef);
185  GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
186  }
187 
188  return theAnswer;
189 }
190 
191 CFStringRef CAHALAudioObject::CopyCategoryNameForElement(AudioObjectPropertyScope inScope, AudioObjectPropertyElement inElement) const
192 {
193  // set up the return value
194  CFStringRef theAnswer = NULL;
195 
196  // set up the property address
197  CAPropertyAddress theAddress(kAudioObjectPropertyElementCategoryName, inScope, inElement);
198 
199  // make sure the property exists
200  if(HasProperty(theAddress))
201  {
202  // get the property data
203  UInt32 theSize = sizeof(CFStringRef);
204  GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
205  }
206 
207  return theAnswer;
208 }
209 
210 CFStringRef CAHALAudioObject::CopyNumberNameForElement(AudioObjectPropertyScope inScope, AudioObjectPropertyElement inElement) const
211 {
212  // set up the return value
213  CFStringRef theAnswer = NULL;
214 
215  // set up the property address
216  CAPropertyAddress theAddress(kAudioObjectPropertyElementNumberName, inScope, inElement);
217 
218  // make sure the property exists
219  if(HasProperty(theAddress))
220  {
221  // get the property data
222  UInt32 theSize = sizeof(CFStringRef);
223  GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
224  }
225 
226  return theAnswer;
227 }
228 
229 UInt32 CAHALAudioObject::GetNumberOwnedObjects(AudioClassID inClass) const
230 {
231  // set up the return value
232  UInt32 theAnswer = 0;
233 
234  // set up the property address
235  CAPropertyAddress theAddress(kAudioObjectPropertyOwnedObjects);
236 
237  // figure out the qualifier
238  UInt32 theQualifierSize = 0;
239  void* theQualifierData = NULL;
240  if(inClass != 0)
241  {
242  theQualifierSize = sizeof(AudioObjectID);
243  theQualifierData = &inClass;
244  }
245 
246  // get the property data size
247  theAnswer = GetPropertyDataSize(theAddress, theQualifierSize, theQualifierData);
248 
249  // calculate the number of object IDs
250  theAnswer /= sizeof(AudioObjectID);
251 
252  return theAnswer;
253 }
254 
255 void CAHALAudioObject::GetAllOwnedObjects(AudioClassID inClass, UInt32& ioNumberObjects, AudioObjectID* ioObjectIDs) const
256 {
257  // set up the property address
258  CAPropertyAddress theAddress(kAudioObjectPropertyOwnedObjects);
259 
260  // figure out the qualifier
261  UInt32 theQualifierSize = 0;
262  void* theQualifierData = NULL;
263  if(inClass != 0)
264  {
265  theQualifierSize = sizeof(AudioObjectID);
266  theQualifierData = &inClass;
267  }
268 
269  // get the property data
270  UInt32 theDataSize = ioNumberObjects * sizeof(AudioClassID);
271  GetPropertyData(theAddress, theQualifierSize, theQualifierData, theDataSize, ioObjectIDs);
272 
273  // set the number of object IDs being returned
274  ioNumberObjects = theDataSize / sizeof(AudioObjectID);
275 }
276 
277 AudioObjectID CAHALAudioObject::GetOwnedObjectByIndex(AudioClassID inClass, UInt32 inIndex)
278 {
279  // set up the property address
280  CAPropertyAddress theAddress(kAudioObjectPropertyOwnedObjects);
281 
282  // figure out the qualifier
283  UInt32 theQualifierSize = 0;
284  void* theQualifierData = NULL;
285  if(inClass != 0)
286  {
287  theQualifierSize = sizeof(AudioObjectID);
288  theQualifierData = &inClass;
289  }
290 
291  // figure out how much space to allocate
292  UInt32 theDataSize = GetPropertyDataSize(theAddress, theQualifierSize, theQualifierData);
293  UInt32 theNumberObjectIDs = theDataSize / sizeof(AudioObjectID);
294 
295  // set up the return value
296  AudioObjectID theAnswer = 0;
297 
298  // maker sure the index is in range
299  if(inIndex < theNumberObjectIDs)
300  {
301  // allocate it
302  CAAutoArrayDelete<AudioObjectID> theObjectList(theDataSize / sizeof(AudioObjectID));
303 
304  // get the property data
305  GetPropertyData(theAddress, theQualifierSize, theQualifierData, theDataSize, theObjectList);
306 
307  // get the return value
308  theAnswer = theObjectList[inIndex];
309  }
310 
311  return theAnswer;
312 }
313 
314 bool CAHALAudioObject::HasProperty(const AudioObjectPropertyAddress& inAddress) const
315 {
316  return AudioObjectHasProperty(mObjectID, &inAddress);
317 }
318 
319 bool CAHALAudioObject::IsPropertySettable(const AudioObjectPropertyAddress& inAddress) const
320 {
321  Boolean isSettable = false;
322  OSStatus theError = AudioObjectIsPropertySettable(mObjectID, &inAddress, &isSettable);
323  ThrowIfError(theError, CAException(theError), "CAHALAudioObject::IsPropertySettable: got an error getting info about a property");
324  return isSettable != 0;
325 }
326 
327 UInt32 CAHALAudioObject::GetPropertyDataSize(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData) const
328 {
329  UInt32 theDataSize = 0;
330  OSStatus theError = AudioObjectGetPropertyDataSize(mObjectID, &inAddress, inQualifierDataSize, inQualifierData, &theDataSize);
331  ThrowIfError(theError, CAException(theError), "CAHALAudioObject::GetPropertyDataSize: got an error getting the property data size");
332  return theDataSize;
333 }
334 
335 void CAHALAudioObject::GetPropertyData(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32& ioDataSize, void* outData) const
336 {
337  OSStatus theError = AudioObjectGetPropertyData(mObjectID, &inAddress, inQualifierDataSize, inQualifierData, &ioDataSize, outData);
338  ThrowIfError(theError, CAException(theError), "CAHALAudioObject::GetPropertyData: got an error getting the property data");
339 }
340 
341 void CAHALAudioObject::SetPropertyData(const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize, const void* inQualifierData, UInt32 inDataSize, const void* inData)
342 {
343  OSStatus theError = AudioObjectSetPropertyData(mObjectID, &inAddress, inQualifierDataSize, inQualifierData, inDataSize, inData);
344  ThrowIfError(theError, CAException(theError), "CAHALAudioObject::SetPropertyData: got an error setting the property data");
345 }
346 
347 void CAHALAudioObject::AddPropertyListener(const AudioObjectPropertyAddress& inAddress, AudioObjectPropertyListenerProc inListenerProc, void* inClientData)
348 {
349  OSStatus theError = AudioObjectAddPropertyListener(mObjectID, &inAddress, inListenerProc, inClientData);
350  ThrowIfError(theError, CAException(theError), "CAHALAudioObject::AddPropertyListener: got an error adding a property listener");
351 }
352 
353 void CAHALAudioObject::RemovePropertyListener(const AudioObjectPropertyAddress& inAddress, AudioObjectPropertyListenerProc inListenerProc, void* inClientData)
354 {
355  OSStatus theError = AudioObjectRemovePropertyListener(mObjectID, &inAddress, inListenerProc, inClientData);
356  ThrowIfError(theError, CAException(theError), "CAHALAudioObject::RemovePropertyListener: got an error removing a property listener");
357 }