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 aCFDictionaryRefvalid on global scope.kAudioUnitProperty_ElementName- Takes aCFStringRefvalid on any scope.kAudioUnitProperty_PresentPreset- Takes anAUPresetstruct valid on global scope.presetNameis aCFStringRefcontaining 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, wherepresetNameis aCFStringRefcontaining the preset name.kAudioUnitProperty_ParameterStringFromValue- Returns aAudioUnitParameterStringFromValuestruct whereoutStringis aCFStringRef(may beNULL).kAudioUnitProperty_ParameterIDName- Returns aAudioUnitParameterNameInfostruct whereoutNameis aCFStringRef.kAudioUnitProperty_ParameterClumpName- Returns aAudioUnitParameterNameInfostruct whereoutNameis aCFStringRef.kAudioUnitProperty_CocoaUI- Returns aAudioUnitCocoaViewInfostruct where theCFStringRefclass name(s) are returned in themCocoaAUViewClassfield.
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 aAudioUnitParameterInfostruct. Only releaseunitNameandcfNameStringCFStringRefsif thekAudioUnitParameterFlag_CFNameReleaseflag 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