46 #include "CAHALAudioObject.h"
49 #include "CAAutoDisposer.h"
50 #include "CADebugMacros.h"
51 #include "CAException.h"
52 #include "CAPropertyAddress.h"
58 CAHALAudioObject::CAHALAudioObject(AudioObjectID inObjectID)
64 CAHALAudioObject::~CAHALAudioObject()
68 AudioObjectID CAHALAudioObject::GetObjectID()
const
73 void CAHALAudioObject::SetObjectID(AudioObjectID inObjectID)
75 mObjectID = inObjectID;
78 AudioClassID CAHALAudioObject::GetClassID()
const
81 AudioClassID theAnswer = 0;
84 CAPropertyAddress theAddress(kAudioObjectPropertyClass);
87 if(HasProperty(theAddress))
89 UInt32 theSize =
sizeof(AudioClassID);
90 GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
96 AudioObjectID CAHALAudioObject::GetOwnerObjectID()
const
99 AudioObjectID theAnswer = 0;
102 CAPropertyAddress theAddress(kAudioObjectPropertyOwner);
105 if(HasProperty(theAddress))
108 UInt32 theSize =
sizeof(AudioObjectID);
109 GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
115 CFStringRef CAHALAudioObject::CopyOwningPlugInBundleID()
const
118 CFStringRef theAnswer = NULL;
121 CAPropertyAddress theAddress(kAudioObjectPropertyCreator);
124 if(HasProperty(theAddress))
127 UInt32 theSize =
sizeof(CFStringRef);
128 GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
134 CFStringRef CAHALAudioObject::CopyName()
const
137 CFStringRef theAnswer = NULL;
140 CAPropertyAddress theAddress(kAudioObjectPropertyName);
143 if(HasProperty(theAddress))
146 UInt32 theSize =
sizeof(CFStringRef);
147 GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
153 CFStringRef CAHALAudioObject::CopyManufacturer()
const
156 CFStringRef theAnswer = NULL;
159 CAPropertyAddress theAddress(kAudioObjectPropertyManufacturer);
162 if(HasProperty(theAddress))
165 UInt32 theSize =
sizeof(CFStringRef);
166 GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
172 CFStringRef CAHALAudioObject::CopyNameForElement(AudioObjectPropertyScope inScope, AudioObjectPropertyElement inElement)
const
175 CFStringRef theAnswer = NULL;
178 CAPropertyAddress theAddress(kAudioObjectPropertyElementName, inScope, inElement);
181 if(HasProperty(theAddress))
184 UInt32 theSize =
sizeof(CFStringRef);
185 GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
191 CFStringRef CAHALAudioObject::CopyCategoryNameForElement(AudioObjectPropertyScope inScope, AudioObjectPropertyElement inElement)
const
194 CFStringRef theAnswer = NULL;
197 CAPropertyAddress theAddress(kAudioObjectPropertyElementCategoryName, inScope, inElement);
200 if(HasProperty(theAddress))
203 UInt32 theSize =
sizeof(CFStringRef);
204 GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
210 CFStringRef CAHALAudioObject::CopyNumberNameForElement(AudioObjectPropertyScope inScope, AudioObjectPropertyElement inElement)
const
213 CFStringRef theAnswer = NULL;
216 CAPropertyAddress theAddress(kAudioObjectPropertyElementNumberName, inScope, inElement);
219 if(HasProperty(theAddress))
222 UInt32 theSize =
sizeof(CFStringRef);
223 GetPropertyData(theAddress, 0, NULL, theSize, &theAnswer);
229 UInt32 CAHALAudioObject::GetNumberOwnedObjects(AudioClassID inClass)
const
232 UInt32 theAnswer = 0;
235 CAPropertyAddress theAddress(kAudioObjectPropertyOwnedObjects);
238 UInt32 theQualifierSize = 0;
239 void* theQualifierData = NULL;
242 theQualifierSize =
sizeof(AudioObjectID);
243 theQualifierData = &inClass;
247 theAnswer = GetPropertyDataSize(theAddress, theQualifierSize, theQualifierData);
250 theAnswer /=
sizeof(AudioObjectID);
255 void CAHALAudioObject::GetAllOwnedObjects(AudioClassID inClass, UInt32& ioNumberObjects, AudioObjectID* ioObjectIDs)
const
258 CAPropertyAddress theAddress(kAudioObjectPropertyOwnedObjects);
261 UInt32 theQualifierSize = 0;
262 void* theQualifierData = NULL;
265 theQualifierSize =
sizeof(AudioObjectID);
266 theQualifierData = &inClass;
270 UInt32 theDataSize = ioNumberObjects *
sizeof(AudioClassID);
271 GetPropertyData(theAddress, theQualifierSize, theQualifierData, theDataSize, ioObjectIDs);
274 ioNumberObjects = theDataSize /
sizeof(AudioObjectID);
277 AudioObjectID CAHALAudioObject::GetOwnedObjectByIndex(AudioClassID inClass, UInt32 inIndex)
280 CAPropertyAddress theAddress(kAudioObjectPropertyOwnedObjects);
283 UInt32 theQualifierSize = 0;
284 void* theQualifierData = NULL;
287 theQualifierSize =
sizeof(AudioObjectID);
288 theQualifierData = &inClass;
292 UInt32 theDataSize = GetPropertyDataSize(theAddress, theQualifierSize, theQualifierData);
293 UInt32 theNumberObjectIDs = theDataSize /
sizeof(AudioObjectID);
296 AudioObjectID theAnswer = 0;
299 if(inIndex < theNumberObjectIDs)
302 CAAutoArrayDelete<AudioObjectID> theObjectList(theDataSize /
sizeof(AudioObjectID));
305 GetPropertyData(theAddress, theQualifierSize, theQualifierData, theDataSize, theObjectList);
308 theAnswer = theObjectList[inIndex];
314 bool CAHALAudioObject::HasProperty(
const AudioObjectPropertyAddress& inAddress)
const
316 return AudioObjectHasProperty(mObjectID, &inAddress);
319 bool CAHALAudioObject::IsPropertySettable(
const AudioObjectPropertyAddress& inAddress)
const
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;
327 UInt32 CAHALAudioObject::GetPropertyDataSize(
const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize,
const void* inQualifierData)
const
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");
335 void CAHALAudioObject::GetPropertyData(
const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize,
const void* inQualifierData, UInt32& ioDataSize,
void* outData)
const
337 OSStatus theError = AudioObjectGetPropertyData(mObjectID, &inAddress, inQualifierDataSize, inQualifierData, &ioDataSize, outData);
338 ThrowIfError(theError, CAException(theError),
"CAHALAudioObject::GetPropertyData: got an error getting the property data");
341 void CAHALAudioObject::SetPropertyData(
const AudioObjectPropertyAddress& inAddress, UInt32 inQualifierDataSize,
const void* inQualifierData, UInt32 inDataSize,
const void* inData)
343 OSStatus theError = AudioObjectSetPropertyData(mObjectID, &inAddress, inQualifierDataSize, inQualifierData, inDataSize, inData);
344 ThrowIfError(theError, CAException(theError),
"CAHALAudioObject::SetPropertyData: got an error setting the property data");
347 void CAHALAudioObject::AddPropertyListener(
const AudioObjectPropertyAddress& inAddress, AudioObjectPropertyListenerProc inListenerProc,
void* inClientData)
349 OSStatus theError = AudioObjectAddPropertyListener(mObjectID, &inAddress, inListenerProc, inClientData);
350 ThrowIfError(theError, CAException(theError),
"CAHALAudioObject::AddPropertyListener: got an error adding a property listener");
353 void CAHALAudioObject::RemovePropertyListener(
const AudioObjectPropertyAddress& inAddress, AudioObjectPropertyListenerProc inListenerProc,
void* inClientData)
355 OSStatus theError = AudioObjectRemovePropertyListener(mObjectID, &inAddress, inListenerProc, inClientData);
356 ThrowIfError(theError, CAException(theError),
"CAHALAudioObject::RemovePropertyListener: got an error removing a property listener");