| #define kMaxStringSize 1024
// CopyMyAudioDriverUID
//      Find your drivers UID and return it in
// a CFString you are responsible for releasing.
OSStatus CopyMyAudioDriverUID(CFStringRef *outUID)
{
    UInt32          theSize;
    char            theString[kMaxStringSize];
    UInt32          theNumberDevices;
    AudioDeviceID   *theDeviceList = NULL;
    UInt32          theDeviceIndex;
    CFStringRef     theCFString = NULL;
    OSStatus        theStatus = noErr;
    // this is our driver
    const char      *nameString = "BrownSound audio controller";
    const char      *manufacturerString = "Eddie";
    *outUID = NULL;
    // device list size
    theSize = 0;
    theStatus = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &theSize, NULL);
    if (theStatus) goto done;
    theNumberDevices = theSize / sizeof(AudioDeviceID);
    // allocate the device list
    theDeviceList = (AudioDeviceID*)malloc(theNumberDevices * sizeof(AudioDeviceID));
    // get the device list
    theSize = theNumberDevices * sizeof(AudioDeviceID);
    theStatus = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &theSize, theDeviceList);
    // iterate through the device list, find our device and return the UID
    for(theDeviceIndex = 0; theDeviceIndex < theNumberDevices; ++theDeviceIndex)
    {
        // get name
        theSize = kMaxStringSize;
        theStatus = AudioDeviceGetProperty(theDeviceList[theDeviceIndex],
                                      0, 0, kAudioDevicePropertyDeviceName, &theSize, theString);
        if (theStatus) goto done;
        // is it me?
        if (strncmp(theString, nameString, strlen(nameString)) == 0) {
            // get manufacturer
            theSize = kMaxStringSize;
            theStatus = AudioDeviceGetProperty(theDeviceList[theDeviceIndex], 0, 0,
                                     kAudioDevicePropertyDeviceManufacturer, &theSize, theString);
            if (theStatus) goto done;
            // is it really me?
            if (strncmp(theString, manufacturerString, strlen(manufacturerString)) == 0) {
                // get device UID
                theSize = sizeof(CFStringRef);
                theStatus = AudioDeviceGetProperty(theDeviceList[theDeviceIndex],
                                 0, 0, kAudioDevicePropertyDeviceUID, &theSize, &theCFString);
                if (theStatus) goto done;
                *outUID = theCFString;
                break;
            }
        }
    }
    // we didn't find ourselves, that's bad!
    if (NULL == *outUID) theStatus = badComponentType;
done:
    // free the device list
    if (theDeviceList) free(theDeviceList);
    return theStatus;
}
// QTVideoOutputGetIndSoundOutput
//      Return the sound output component associated with the video output component
// specified by the index parameter. The index of the first component should be 1.
pascal ComponentResult MyVOut_GetIndSoundOutput(MyVOutGlobalsPtr storage,
                                                 long index, Component *outputComponent)
{
    Component            c = 0;
    ComponentDescription cd = { kSoundOutputDeviceType, kHALCustomComponentSubType, 0, 0, 0 };
    CFStringRef          myUID = NULL;
    CFStringRef          halUID = NULL;
    SMStatus             ignore;
    ComponentResult      err;
    *outputComponent = NULL;
    // we only have one Sound Output Component so,
    // if index is anything other than 1 it's an error
    if (index != 1) return paramErr;
    // already have it, we're done
    if (storage->soundOutput) {
        *outputComponent = storage->soundOutput;
        return noErr;
    }
    // find our audio drivers UID using core audio
    err = CopyMyAudioDriverUID(&myUID);
    if (err) goto bail;
    // cheaply init the Sound Manager - must be done so the Sound Manager will
    // synthesize Sound Output Components for each Core Audio Driver on the system
    SndManagerStatus(sizeof(SMStatus), &ignore);
    // find our synthesized Sound Output Component
    while (c = FindNextComponent(c, &cd)) {
        // don't release the returned CFString
        err = SoundComponentGetInfo(c, 0, siHALAudioDeviceUniqueID, &halUID);
        if (err) goto bail;
        // if it's us, we're done
        if (CFEqual(myUID, halUID)) {
            *outputComponent = c;
            storage->soundOutput = c;
            break;
        }
    }
    // we didn't find the corresponding sDev, that's bad!
    if (NULL == *outputComponent) err = badComponentType;
bail:
    if (myUID) CFRelease(myUID);
    return err;
}                 |