41 #ifndef __ComponentBase_h__
42 #define __ComponentBase_h__
45 #include "CADebugMacros.h"
47 #if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
48 #include <CoreAudio/CoreAudioTypes.h>
49 #include <AudioUnit/AudioUnit.h>
52 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/Components.h>
54 #if (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5)
55 #define AudioComponentInstance ComponentInstance
56 #define AudioComponentDescription ComponentDescription
57 #define AudioComponent Component
58 #define CA_DO_NOT_USE_AUDIO_COMPONENT 1
62 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
63 typedef Float32 AudioUnitParameterValue;
65 #if COREAUDIOTYPES_VERSION < 1051
66 typedef Float32 AudioUnitSampleType;
71 #include "CoreAudioTypes.h"
72 #include "Components.h"
73 #include "AudioUnit.h"
77 #ifndef COMPONENT_THROW
78 #if VERBOSE_COMPONENT_THROW
79 #define COMPONENT_THROW(throw_err) \
80 do { DebugMessage(#throw_err); throw static_cast<OSStatus>(throw_err); } while (0)
82 #define COMPONENT_THROW(throw_err) \
83 throw static_cast<OSStatus>(throw_err)
87 #define COMPONENT_CATCH \
88 catch (std::bad_alloc &) { result = -108; } \
89 catch (OSStatus catch_err) { result = catch_err; } \
90 catch (OSErr catch_err) { result = catch_err; } \
91 catch (...) { result = -1; }
93 class ComponentInitLocker
97 ComponentInitLocker() { pthread_mutex_lock(&sComponentOpenMutex); }
98 ~ComponentInitLocker() { pthread_mutex_unlock(&sComponentOpenMutex); }
100 static pthread_mutex_t sComponentOpenMutex;
101 #elif TARGET_OS_WIN32
103 bool sNeedsUnlocking;
104 ComponentInitLocker() { sNeedsUnlocking = sComponentOpenGuard.Lock(); }
105 ~ComponentInitLocker() {
if(sNeedsUnlocking) { sComponentOpenGuard.Unlock(); } }
107 static CAGuard sComponentOpenGuard;
111 #if !TARGET_OS_IPHONE
113 template <
class Class>
114 class ComponentEntryPoint {
117 static OSStatus Dispatch(ComponentParameters *params, Class *obj)
119 OSStatus result = noErr;
122 if (params->what == kComponentOpenSelect) {
124 ComponentInitLocker lock;
126 ComponentInstance ci = (ComponentInstance)(params->params[0]);
127 Class *This =
new Class((AudioComponentInstance)ci);
128 This->PostConstructor();
131 #if !CA_AU_IS_ONLY_PLUGIN
132 SetComponentInstanceStorage(ci, (Handle)This);
135 result = Class::ComponentEntryDispatch(params, obj);
143 static Component Register(OSType compType, OSType subType, OSType manufacturer)
145 ComponentDescription description = {compType, subType, manufacturer, 0, 0};
146 Component component = RegisterComponent(&description, (ComponentRoutineUPP) Dispatch, registerComponentGlobal, NULL, NULL, NULL);
147 if (component != NULL) {
148 SetDefaultComponent(component, defaultComponentAnyFlagsAnyManufacturerAnySubType);
154 #if TARGET_OS_MAC && TARGET_CPU_PPC && !TARGET_RT_MAC_MACHO
156 #define COMPONENT_ENTRY(Class) \
157 extern "C" OSStatus Class##Entry(ComponentParameters *params, Class *obj); \
158 extern "C" OSStatus Class##Entry(ComponentParameters *params, Class *obj) { \
159 return ComponentEntryPoint<Class>::Dispatch(params, obj); \
162 struct RoutineDescriptor Class##EntryRD = \
163 BUILD_ROUTINE_DESCRIPTOR((kPascalStackBased | RESULT_SIZE (kFourByteCode) | \
164 STACK_ROUTINE_PARAMETER (1, kFourByteCode) | \
165 STACK_ROUTINE_PARAMETER (2, kFourByteCode)), Class##Entry);
167 #define COMPONENT_ENTRY(Class) \
168 extern "C" OSStatus Class##Entry(ComponentParameters *params, Class *obj); \
169 extern "C" OSStatus Class##Entry(ComponentParameters *params, Class *obj) { \
170 return ComponentEntryPoint<Class>::Dispatch(params, obj); \
175 template <
class Class, OSType Type, OSType Subtype, OSType Manufacturer>
176 class ComponentRegistrar {
179 ComponentRegistrar() { ComponentEntryPoint<Class>::Register(Type, Subtype, Manufacturer); }
182 #define COMPONENT_REGISTER(Class,Type,Subtype,Manufacturer) \
183 static ComponentRegistrar<Class, Type, Subtype, Manufacturer> gRegistrar##Class
185 #define COMPONENT_ENTRY(Class)
186 #define COMPONENT_REGISTER(Class)
187 #endif // !TARGET_OS_IPHONE
191 class ComponentBase {
194 enum { noErr = 0, paramErr = -50, memFullErr = -108 };
197 ComponentBase(AudioComponentInstance inInstance) : mComponentInstance(inInstance) { }
199 virtual ~ComponentBase();
202 virtual void PostConstructor();
205 virtual void PreDestructor();
207 #if !TARGET_OS_IPHONE
209 virtual OSStatus Version();
212 static OSStatus ComponentEntryDispatch(ComponentParameters *p, ComponentBase *This);
216 AudioComponentInstance GetComponentInstance()
const {
return mComponentInstance; }
219 AudioComponentDescription GetComponentDescription()
const;
223 AudioComponentInstance mComponentInstance;
226 #endif // __ComponentBase_h__