41 #include "ComponentBase.h"
42 #include "CAXException.h"
45 pthread_mutex_t ComponentInitLocker::sComponentOpenMutex = PTHREAD_MUTEX_INITIALIZER;
47 CAGuard ComponentInitLocker::sComponentOpenGuard(
"sComponentOpenGuard");
50 #if CA_DO_NOT_USE_AUDIO_COMPONENT
54 ComponentBase::~ComponentBase()
58 void ComponentBase::PostConstructor()
62 void ComponentBase::PreDestructor()
67 OSStatus ComponentBase::Version()
72 OSStatus ComponentBase::ComponentEntryDispatch(ComponentParameters *p, ComponentBase *This)
74 if (This == NULL)
return paramErr;
76 OSStatus result = noErr;
79 case kComponentCloseSelect:
80 This->PreDestructor();
84 case kComponentVersionSelect:
85 result = This->Version();
88 case kComponentCanDoSelect:
89 switch (p->params[0]) {
90 case kComponentOpenSelect:
91 case kComponentCloseSelect:
92 case kComponentVersionSelect:
93 case kComponentCanDoSelect:
100 result = badComponentSelector;
107 #if CA_DO_NOT_USE_AUDIO_COMPONENT
108 static OSStatus ComponentBase_GetComponentDescription (
const AudioComponentInstance & inInstance, AudioComponentDescription &outDesc);
111 AudioComponentDescription ComponentBase::GetComponentDescription()
const
113 AudioComponentDescription desc;
116 #if CA_DO_NOT_USE_AUDIO_COMPONENT
117 ca_require_noerr (result = ComponentBase_GetComponentDescription (mComponentInstance, desc), home);
119 AudioComponent comp = AudioComponentInstanceGetComponent(mComponentInstance);
122 ca_require_noerr(result = AudioComponentGetDescription(comp, &desc), home);
124 ca_require_noerr(result = -1, home);
129 memset (&desc, 0,
sizeof(AudioComponentDescription));
134 #if CA_DO_NOT_USE_AUDIO_COMPONENT
135 OSStatus ComponentBase_GetComponentDescription (
const AudioComponentInstance & inInstance, AudioComponentDescription & outDesc)
138 typedef AudioComponent (*AudioComponentInstanceGetComponentProc) (AudioComponentInstance);
139 static AudioComponentInstanceGetComponentProc aciGCProc = NULL;
141 typedef OSStatus (*AudioComponentGetDescriptionProc)(AudioComponent, AudioComponentDescription *);
142 static AudioComponentGetDescriptionProc acGDProc = NULL;
144 typedef OSErr (*GetComponentInfoProc)(Component, ComponentDescription *,
void*,
void*,
void*);
145 static GetComponentInfoProc gciProc = NULL;
147 static int doneInit = 0;
150 bool loadCMgr =
true;
152 void* theImage = dlopen(
"/System/Library/Frameworks/AudioUnit.framework/AudioUnit", RTLD_LAZY);
153 if (theImage != NULL)
157 aciGCProc = (AudioComponentInstanceGetComponentProc)dlsym (theImage,
"AudioComponentInstanceGetComponent");
159 acGDProc = (AudioComponentGetDescriptionProc)dlsym (theImage,
"AudioComponentGetDescription");
165 theImage = dlopen(
"/System/Library/Frameworks/CoreServices.framework/CoreServices", RTLD_LAZY);
166 if (theImage != NULL)
168 gciProc = (GetComponentInfoProc)dlsym (theImage,
"GetComponentInfo");
173 OSStatus result = noErr;
174 if (acGDProc && aciGCProc) {
175 AudioComponent comp = (*aciGCProc)(inInstance);
178 ca_require_noerr(result = (*acGDProc)(comp, &outDesc), home);
180 ca_require_noerr(result = -1, home);
182 }
else if (gciProc) {
184 ca_require_noerr(result = (*gciProc)((Component)inInstance, (ComponentDescription*)&outDesc, NULL, NULL, NULL), home);
189 #endif //CA_DO_NOT_USE_AUDIO_COMPONENT