41 #include "CAComponent.h"
42 #include "CAComponentDescription.h"
43 #include "CACFDictionary.h"
45 #include "CAAutoDisposer.h"
47 CAComponent::CAComponent (
const AudioComponentDescription& inDesc, CAComponent* next)
48 : mManuName(0), mAUName(0), mCompName(0)
50 mComp = AudioComponentFindNext ((next ? next->Comp() : NULL), &inDesc);
52 AudioComponentGetDescription(Comp(), &mDesc);
54 memcpy (&mDesc, &inDesc,
sizeof(AudioComponentDescription));
57 CAComponent::CAComponent (
const AudioComponent& comp)
63 AudioComponentGetDescription (Comp(), &mDesc);
66 CAComponent::CAComponent (
const AudioComponentInstance& compInst)
72 mComp = AudioComponentInstanceGetComponent (compInst);
73 AudioComponentGetDescription (Comp(), &mDesc);
76 CAComponent::CAComponent (OSType inType, OSType inSubtype, OSType inManu)
77 : mDesc (inType, inSubtype, inManu),
78 mManuName(0), mAUName(0), mCompName(0)
80 mComp = AudioComponentFindNext (NULL, &mDesc);
81 AudioComponentGetDescription (Comp(), &mDesc);
84 CAComponent::~CAComponent ()
89 OSStatus CAComponent::GetVersion (UInt32 &outVersion)
const
91 return AudioComponentGetVersion (mComp, &outVersion);
94 void CAComponent::Clear ()
96 if (mManuName) { CFRelease (mManuName); mManuName = 0; }
97 if (mAUName) { CFRelease (mAUName); mAUName = 0; }
98 if (mCompName) { CFRelease (mCompName); mCompName = 0; }
101 CAComponent& CAComponent::operator= (
const CAComponent& y)
108 if (y.mManuName) { mManuName = y.mManuName; CFRetain (mManuName); }
109 if (y.mAUName) { mAUName = y.mAUName; CFRetain (mAUName); }
110 if (y.mCompName) { mCompName = y.mCompName; CFRetain (mCompName); }
115 void CAComponent::SetCompNames ()
const
119 CFStringRef compName;
120 OSStatus result = AudioComponentCopyName (Comp(), &compName);
123 const_cast<CAComponent*
>(
this)->mCompName = compName;
126 CFArrayRef splitStrArray = CFStringCreateArrayBySeparatingStrings(NULL, compName, CFSTR(
":"));
129 CFRetain(CFArrayGetValueAtIndex(splitStrArray, 0));
130 const_cast<CAComponent*
>(
this)->mManuName = (CFStringRef)CFArrayGetValueAtIndex(splitStrArray, 0);
131 if (CFArrayGetCount(splitStrArray) > 1)
133 CFStringRef str = (CFStringRef)CFArrayGetValueAtIndex(splitStrArray, 1);
135 CFMutableStringRef mstr = CFStringCreateMutableCopy (NULL, CFStringGetLength(str), str);
139 CFStringTrimWhitespace (mstr);
141 const_cast<CAComponent*
>(
this)->mAUName = mstr;
143 const_cast<CAComponent*
>(
this)->mAUName = NULL;
145 CFRelease(splitStrArray);
150 static void _ShowCF (FILE* file, CFStringRef str)
152 if (CFGetTypeID(str) != CFStringGetTypeID()) {
157 UInt32 len = CFStringGetLength(str);
158 char* chars = (
char*)CA_malloc (len * 2);
159 if (CFStringGetCString (str, chars, len * 2, kCFStringEncodingUTF8))
160 fprintf (file,
"%s", chars);
167 void CAComponent::Print(FILE* file)
const
169 fprintf (file,
"CAComponent: %p", Comp());
171 fprintf (file,
", Manu:"); _ShowCF (file, mManuName);
172 if (mAUName) fprintf (file,
", Name:"); _ShowCF (file, mAUName);
174 fprintf (file,
", ");