为什么默认麦克风的AudioDeviceID与从同一麦克风的UID获得的AudioDeviceID不同

时间:2015-05-29 16:44:47

标签: macos audio core-audio uid

问题背景:

我通过这种方式获取默认输入麦克风的AudioDeviceID:

OSStatus error = noErr;
AudioObjectPropertyAddress propertyAddress = {};
UInt32 propertySize;

/* get default device ID */
    AudioDeviceID deviceID = 0;
    propertyAddress.mSelector = kAudioHardwarePropertyDevices;
    propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
    propertyAddress.mElement = kAudioObjectPropertyElementMaster;
    propertySize = sizeof(AudioDeviceID);
    error = AudioHardwareServiceGetPropertyData(kAudioObjectSystemObject,
                                                &propertyAddress, 0,
                                                NULL, &propertySize, &deviceID);
    if(!error)
        ... // we get some AudioDeviceID, let it be ID_1

获取UID的AudioDeviceID是:

CFStringRef micUID = ... //my UID for the mic
CFStringRef *inDeviceUID = &micUID;
AudioObjectPropertyAddress proprtyAddress = {};
proprtyAddress.mSelector = kAudioHardwarePropertyDeviceForUID;
proprtyAddress.mScope = kAudioObjectPropertyScopeGlobal;
proprtyAddress.mElement = kAudioObjectPropertyElementMaster;
AudioValueTranslation translation = {};
translation.mInputData = inDeviceUID;
translation.mInputDataSize = sizeof(CFStringRef);
translation.mOutputData = outDeviceID;
translation.mOutputDataSize = sizeof(AudioDeviceID);
UInt32 inSize = sizeof(translation);
OSStatus result = AudioObjectGetPropertyData(kAudioObjectSystemObject,
                                             &proprtyAddress,
                                             0,
                                             nullptr,
                                             &inSize,
                                             &translation);

// if no error - we have another AudioDeviceID, let it be ID_2

问题是:

为什么ID_1 != ID_2

只有当我将两个相同的网络摄像头连接到Mac时才会发生这种情况。奇怪的是,这些麦克风有不同的UID。

当我尝试更改某些参数时,sampleRate例如,它不起作用(我得到kAudioHardwareUnknownPropertyError error)。

对于内置线路输入,它可以正常工作。

0 个答案:

没有答案