Audio Unit Properties and Core Foundation Data Types
Q: When working with Audio Unit properties that take and return Core Foundation Data Types, who is responsible for retaining or releasing.
A: When working with Audio Unit properties that take and return Core Foundation Data Types, who is responsible for retaining or releasing.
Whenever an Audio Unit host is working with Audio Unit properties that are Core Foundation Data Types, the caller almost always owns the reference and is therefore responsible for releasing it as required.
Summary for AudioUnitSetProperty
kAudioUnitProperty_ClassInfo
- Takes aCFDictionaryRef
valid on global scope.kAudioUnitProperty_ElementName
- Takes aCFStringRef
valid on any scope.kAudioUnitProperty_PresentPreset
- Takes anAUPreset
struct valid on global scope.presetName
is aCFStringRef
containing the preset name owned by the caller after getting this property.
Summary for AudioUnitGetProperty
All Core Foundation objects returned by AudioUnitGetProperty
follow Core Foundation Copy semantics and are therefore owned by the caller. It is the callers responsibility to relinquish ownership (using CFRelease
) when done with the returned value.
The following properties return Core Foundation objects:
kAudioUnitProperty_ClassInfo
- Returns aCFDictionaryRef
.kAudioUnitProperty_ParameterValueStrings
- Returns aCFArrayRef
.kAudioUnitProperty_FactoryPresets
- Returns aCFArrayRef
.kAudioUnitProperty_ElementName
- Returns aCFStringRef
.kAudioUnitOfflineProperty_PreflightName
- Returns aCFStringRef
.kMusicDeviceProperty_BankName
- Returns aCFStringRef
.
The following properties return Core Foundation objects embedded as fields in C structures:
kAudioUnitProperty_PresentPreset
- Returns anAUPreset
, wherepresetName
is aCFStringRef
containing the preset name.kAudioUnitProperty_ParameterStringFromValue
- Returns aAudioUnitParameterStringFromValue
struct whereoutString
is aCFStringRef
(may beNULL
).kAudioUnitProperty_ParameterIDName
- Returns aAudioUnitParameterNameInfo
struct whereoutName
is aCFStringRef
.kAudioUnitProperty_ParameterClumpName
- Returns aAudioUnitParameterNameInfo
struct whereoutName
is aCFStringRef
.kAudioUnitProperty_CocoaUI
- Returns aAudioUnitCocoaViewInfo
struct where theCFStringRef
class name(s) are returned in themCocoaAUViewClass
field.
The number of class names in the mCocoaAUViewClass
field can be found by using the following code. dataSize
is the maximum size of the property returned by calling AudioUnitGetPropertyInfo
for the kAudioUnitProperty_CocoaUI
property.
UInt32 numberOfClasses = (dataSize - sizeof(CFURLRef)) / sizeof(CFStringRef); |
Handling Parameter Names
Ownership is based on the kAudioUnitParameterFlag_CFNameRelease
flag. This flag is normally always set.
kAudioUnitProperty_ParameterInfo
- Returns aAudioUnitParameterInfo
struct. Only releaseunitName
andcfNameString
CFStringRefs
if thekAudioUnitParameterFlag_CFNameRelease
flag is set. See Listing 1.
The Audio Unit Host should check for this flag and if set, should release the audio unit parameter name when it is done using it. If this flag is not set, the Host can assume that the Audio Unit will release its parameter names.
Listing 1 Illustrating use of kAudioUnitParameterFlag_CFNameRelease
.
AudioUnitParameterInfo auinfo; UInt32 propertySize = sizeof(AudioUnitParameterInfo); OSStatus err = AudioUnitGetProperty(mAudioUnit, kAudioUnitProperty_ParameterInfo, mScope, mParameterID, &auinfo, &propertySize); if (err) { // handle error }; ... if (auinfo.flags & kAudioUnitParameterFlag_CFNameRelease) { if (auinfo.flags & kAudioUnitParameterFlag_HasCFNameString && auinfo.cfNameString != NULL) CFRelease(auinfo.cfNameString); if (auinfo.unit == kAudioUnitParameterUnit_CustomUnit && auinfo.unitName != NULL) CFRelease(auinfo.unitName); } |
Document Revision History
Date | Notes |
---|---|
2010-03-03 | New document that describes the ownership of CF data types when Getting/Setting AU properties. |
Copyright © 2010 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2010-03-03