15 #include <CoreServices/CoreServices.h>
16 #include <CoreAudio/CoreAudio.h>
17 #include <AudioUnit/AudioUnit.h>
18 #include <AudioToolbox/AudioFormat.h>
25 #define LOC QString("CoreAudio: ")
27 #define CHANNELS_MIN 1
28 #define CHANNELS_MAX 8
30 #define OSS_STATUS(x) UInt32ToFourCC((UInt32*)&x)
34 char* pIn = (
char*)&inVal;
35 static char fourCC[5];
46 UInt32 formatId = desc.mFormatID;
50 switch (desc.mFormatID)
52 case kAudioFormatLinearPCM:
53 str = QString(
"[%1] %2%3 Channel %4-bit %5 %6 (%7Hz)")
55 .arg((desc.mFormatFlags & kAudioFormatFlagIsNonMixable) ?
"" :
"Mixable ")
56 .arg(desc.mChannelsPerFrame)
57 .arg(desc.mBitsPerChannel)
58 .arg((desc.mFormatFlags & kAudioFormatFlagIsFloat) ?
"Floating Point" :
"Signed Integer")
59 .arg((desc.mFormatFlags & kAudioFormatFlagIsBigEndian) ?
"BE" :
"LE")
60 .arg((UInt32)desc.mSampleRate);
63 str = QString(
"[%1] AC-3/DTS (%2Hz)")
65 .arg((UInt32)desc.mSampleRate);
67 case kAudioFormat60958AC3:
68 str = QString(
"[%1] AC-3/DTS for S/PDIF %2 (%3Hz)")
70 .arg((desc.mFormatFlags & kAudioFormatFlagIsBigEndian) ?
"BE" :
"LE")
71 .arg((UInt32)desc.mSampleRate);
75 str = QString(
"[%1]").arg(fourCC);
118 AudioStreamBasicDescription *
FormatsList(AudioStreamID s);
121 AudioStreamBasicDescription
format);
125 { LOG(VB_AUDIO, LOG_INFO,
"CoreAudioData::" + msg); }
128 { LOG(VB_GENERAL, LOG_ERR,
"CoreAudioData Error:" + msg); }
131 { LOG(VB_GENERAL, LOG_WARNING,
"CoreAudioData Warning:" + msg); }
146 AudioStreamBasicDescription
158 AudioUnitRenderActionFlags *ioActionFlags,
159 const AudioTimeStamp *inTimeStamp,
161 UInt32 inNumberFrames,
162 AudioBufferList *ioData);
164 const AudioTimeStamp *inNow,
165 const void *inInputData,
166 const AudioTimeStamp *inInputTime,
167 AudioBufferList *outOutputData,
168 const AudioTimeStamp *inOutputTime,
169 void *threadGlobals);
179 VBAUDIO(QString(
"AudioOutputCA::AudioOutputCA searching %1").arg(
main_device));
211 int *p_rates = rates;
214 if (*p_rates == rate)
229 if (channels == NULL)
236 for (
int i = CHANNELS_MIN; i <= CHANNELS_MAX; i++)
240 Debug(QString(
"Support %1 channels").arg(i));
242 if (i == 8 && !channels[6])
259 bool deviceOpened =
false;
264 Debug(
"OpenDevice: Entering");
267 Debug(
"OpenDevice() Trying Digital.");
274 Debug(
"OpenDevice() Trying Analog.");
279 Debug(QString(
"OpenDevice: OpenAnalog = %1").arg(result));
286 deviceOpened = (result > 0);
291 Error(
"Couldn't open any audio device!");
299 controlLabel +=
"MixerVolume";
308 VBAUDIO(QString(
"CloseDevice [%1]: Entering")
316 template <
class AudioDataType>
319 AudioDataType tmpLS, tmpRS, tmpRLs, tmpRRs, *buf2;
322 buf = buf2 = buf + 4;
347 int size,
unsigned long long timestamp)
363 if (written_size && (size > written_size))
366 memset(aubuf + written_size, 0, size - written_size);
376 UInt64 nanos = AudioConvertHostTimeToNanos(timestamp -
377 AudioGetCurrentHostTime());
382 return (written_size > 0);
404 if (!audbuf_timecode)
409 return audbuf_timecode - (
int)(totalbuffer * 100000.0 /
416 AudioUnitRenderActionFlags *ioActionFlags,
417 const AudioTimeStamp *inTimeStamp,
419 UInt32 inNumberFrames,
420 AudioBufferList *ioData)
423 (
void)inNumberFrames;
427 if (!inst->
RenderAudio((
unsigned char *)(ioData->mBuffers[0].mData),
428 ioData->mBuffers[0].mDataByteSize,
429 inTimeStamp->mHostTime))
432 memset(ioData->mBuffers[0].mData, 0, ioData->mBuffers[0].mDataByteSize);
433 *ioActionFlags = kAudioUnitRenderAction_OutputIsSilence;
445 kHALOutputParam_Volume,
446 kAudioUnitScope_Global, 0, &volume))
447 return (
int)lroundf(volume * 100.0f);
456 AudioUnitSetParameter(
d->
mOutputUnit, kHALOutputParam_Volume,
457 kAudioUnitScope_Global, 0, (volume * 0.01f), 0);
462 const AudioTimeStamp *inNow,
463 const void *inInputData,
464 const AudioTimeStamp *inInputTime,
465 AudioBufferList *outOutputData,
466 const AudioTimeStamp *inOutputTime,
487 if (!a->
RenderAudio((
unsigned char *)(outOutputData->mBuffers[index].mData),
488 outOutputData->mBuffers[index].mDataByteSize,
489 inOutputTime->mHostTime))
492 memset(outOutputData->mBuffers[index].mData, 0,
493 outOutputData->mBuffers[index].mDataByteSize);
544 if (deviceName !=
"Default Output Device")
546 Warn(QString(
"CoreAudioData: \"%1\" not found, using default device %2.")
550 Debug(QString(
"CoreAudioData: device number is %1")
557 AudioDeviceID deviceID = 0;
559 AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &size, NULL);
560 UInt32 deviceCount = size /
sizeof(AudioDeviceID);
561 AudioDeviceID* pDevices =
new AudioDeviceID[deviceCount];
563 OSStatus err = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &size, pDevices);
566 Warn(QString(
"GetDeviceWithName: Unable to retrieve the list of available devices. "
572 for (UInt32 dev = 0; dev < deviceCount; dev++)
578 if (name && name == deviceName)
580 Debug(QString(
"GetDeviceWithName: Found: %1").arg(*name));
581 deviceID = pDevices[dev];
596 AudioDeviceID deviceId = 0;
599 paramSize =
sizeof(deviceId);
600 err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice,
601 ¶mSize, &deviceId);
603 Debug(QString(
"GetDefaultOutputDevice: default device ID = %1").arg(deviceId));
606 Warn(QString(
"GetDefaultOutputDevice: could not get default audio device: [%1]")
607 .arg(OSS_STATUS(err)));
619 AudioDeviceGetPropertyInfo(
mDeviceID, 0,
false,
620 kAudioDevicePropertyStreamConfiguration,
622 AudioBufferList *pList = (AudioBufferList *)malloc(size);
623 OSStatus err = AudioDeviceGetProperty(
mDeviceID, 0,
false,
624 kAudioDevicePropertyStreamConfiguration,
629 channels += pList->mBuffers[
buffer].mNumberChannels;
633 Warn(QString(
"GetTotalOutputChannels: Unable to get "
634 "total device output channels - id: %1 Error = [%2]")
638 Debug(QString(
"GetTotalOutputChannels: Found %1 channels in %2 buffers")
639 .arg(channels).arg(pList->mNumberBuffers));
649 AudioObjectPropertyAddress propertyAddress;
652 propertySize =
sizeof(CFStringRef);
653 propertyAddress.mSelector = kAudioObjectPropertyName;
654 propertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
655 propertyAddress.mElement = kAudioObjectPropertyElementMaster;
656 OSStatus err = AudioObjectGetPropertyData(
mDeviceID, &propertyAddress,
657 0, NULL, &propertySize, &name);
660 Error(QString(
"AudioObjectGetPropertyData for kAudioObjectPropertyName error: [%1]")
664 char *cname =
new char[CFStringGetLength(name) + 1];
665 CFStringGetCString(name, cname, CFStringGetLength(name) + 1, kCFStringEncodingUTF8);
666 QString *qname =
new QString(cname);
674 UInt32
size =
sizeof(val);
675 OSStatus err = AudioHardwareGetProperty(kAudioHardwarePropertyHogModeIsAllowed,
679 Warn(QString(
"GetAutoHogMode: Unable to get auto 'hog' mode. Error = [%1]")
688 UInt32 val = enable ? 1 : 0;
689 OSStatus err = AudioHardwareSetProperty(kAudioHardwarePropertyHogModeIsAllowed,
693 Warn(QString(
"SetAutoHogMode: Unable to set auto 'hog' mode. Error = [%1]")
702 UInt32 PIDsize =
sizeof(PID);
704 err = AudioDeviceGetProperty(
mDeviceID, 0, FALSE,
705 kAudioDevicePropertyHogMode,
711 Debug(QString(
"GetHogStatus: unable to check: [%1]")
730 Debug(QString(
"SetHogStatus: Setting 'hog' status on device %1")
732 OSStatus err = AudioDeviceSetProperty(
mDeviceID, NULL, 0,
false,
733 kAudioDevicePropertyHogMode,
735 if (err ||
mHog != getpid())
737 Warn(QString(
"SetHogStatus: Unable to set 'hog' status. Error = [%1]")
738 .arg(OSS_STATUS(err)));
741 Debug(QString(
"SetHogStatus: Successfully set 'hog' status on device %1")
749 Debug(QString(
"SetHogStatus: Releasing 'hog' status on device %1")
752 OSStatus err = AudioDeviceSetProperty(
mDeviceID, NULL, 0,
false,
753 kAudioDevicePropertyHogMode,
754 sizeof(hogPid), &hogPid);
755 if (err || hogPid == getpid())
757 Warn(QString(
"SetHogStatus: Unable to release 'hog' status. Error = [%1]")
758 .arg(OSS_STATUS(err)));
774 UInt32 mixEnable = mix ? 1 : 0;
775 Debug(QString(
"SetMixingSupport: %1abling mixing for device %2")
776 .arg(mix ?
"En" :
"Dis")
778 OSStatus err = AudioDeviceSetProperty(
mDeviceID, NULL, 0,
false,
779 kAudioDevicePropertySupportsMixing,
780 sizeof(mixEnable), &mixEnable);
783 Warn(QString(
"SetMixingSupport: Unable to set MixingSupport to %1. Error = [%2]")
784 .arg(mix ?
"'On'" :
"'Off'")
785 .arg(OSS_STATUS(err)));
798 UInt32
size =
sizeof(val);
799 OSStatus err = AudioDeviceGetProperty(
mDeviceID, 0,
false,
800 kAudioDevicePropertySupportsMixing,
817 err = AudioDeviceGetPropertyInfo(d, 0, FALSE,
818 kAudioDevicePropertyStreams,
822 Error(QString(
"StreamsList: could not get list size: [%1]")
823 .arg(OSS_STATUS(err)));
828 listSize +=
sizeof(AudioStreamID);
829 list = (AudioStreamID *)malloc(listSize);
833 Error(
"StreamsList(): out of memory?");
837 err = AudioDeviceGetProperty(d, 0, FALSE,
838 kAudioDevicePropertyStreams,
842 Error(QString(
"StreamsList: could not get list: [%1]")
843 .arg(OSS_STATUS(err)));
847 list[listSize/
sizeof(AudioStreamID)] = kAudioHardwareBadStreamError;
855 AudioStreamBasicDescription *list;
857 AudioDevicePropertyID
p;
862 p = kAudioStreamPropertyPhysicalFormats;
865 err = AudioStreamGetPropertyInfo(s, 0, p, &listSize, NULL);
868 Warn(QString(
"FormatsList(): couldn't get list size: [%1]")
869 .arg(OSS_STATUS(err)));
874 listSize +=
sizeof(AudioStreamBasicDescription);
875 list = (AudioStreamBasicDescription *)malloc(listSize);
879 Error(
"FormatsList(): out of memory?");
883 err = AudioStreamGetProperty(s, 0, p, &listSize, list);
886 Warn(QString(
"FormatsList: couldn't get list: [%1]")
887 .arg(OSS_STATUS(err)));
893 list[listSize/
sizeof(AudioStreamBasicDescription)].mFormatID = 0;
900 8000.0, 11025.0, 12000.0,
901 16000.0, 22050.0, 24000.0,
902 32000.0, 44100.0, 48000.0,
903 64000.0, 88200.0, 96000.0,
904 128000.0, 176400.0, 192000.0 };
908 bool theAnswer =
false;
919 AudioValueRange *list;
925 err = AudioDeviceGetPropertyInfo(d, 0, 0,
926 kAudioDevicePropertyAvailableNominalSampleRates,
930 Warn(QString(
"RatesList(): couldn't get data rate list size: [%1]")
935 list = (AudioValueRange *)malloc(listSize);
938 Error(
"RatesList(): out of memory?");
942 err = AudioDeviceGetProperty(
943 d, 0, 0, kAudioDevicePropertyAvailableNominalSampleRates,
947 Warn(QString(
"RatesList(): couldn't get list: [%1]")
953 finallist = (
int *)malloc(((listSize /
sizeof(AudioValueRange)) + 1)
955 if (finallist == NULL)
957 Error(
"RatesList(): out of memory?");
963 UInt32 theFirstIndex = 0, theLastIndex = 0;
964 for(UInt32 i = 0; i < listSize /
sizeof(AudioValueRange); i++)
966 theFirstIndex = theLastIndex;
974 theLastIndex = theFirstIndex;
982 finallist[nbitems++] = list[i].mMinimum;
984 finallist[nbitems++] = list[i].mMaximum;
989 finallist[nbitems] = -1;
996 AudioStreamID *streams;
997 AudioStreamBasicDescription *
formats;
998 bool founddigital =
false;
1001 if ((list = (
bool *)malloc((CHANNELS_MAX+1) *
sizeof(
bool))) == NULL)
1004 memset(list, 0, (CHANNELS_MAX+1) *
sizeof(
bool));
1015 for (
int i = 0; streams[i] != kAudioHardwareBadStreamError; i++)
1022 for (
int j = 0; formats[j].mFormatID != 0; j++)
1024 if (formats[j].mFormatID ==
'IAC3' ||
1025 formats[j].mFormatID == kAudioFormat60958AC3)
1027 list[formats[j].mChannelsPerFrame] =
true;
1028 founddigital =
true;
1037 for (
int i = 0; streams[i] != kAudioHardwareBadStreamError; i++)
1042 for (
int j = 0; formats[j].mFormatID != 0; j++)
1043 if (formats[j].mChannelsPerFrame <= CHANNELS_MAX)
1044 list[formats[j].mChannelsPerFrame] =
true;
1053 ComponentDescription desc;
1054 AudioStreamBasicDescription DeviceFormat;
1055 AudioChannelLayout *layout;
1056 AudioChannelLayout new_layout;
1059 Debug(
"OpenAnalog: Entering");
1061 desc.componentType = kAudioUnitType_Output;
1064 desc.componentSubType = kAudioUnitSubType_DefaultOutput;
1068 desc.componentSubType = kAudioUnitSubType_HALOutput;
1070 desc.componentManufacturer = kAudioUnitManufacturer_Apple;
1071 desc.componentFlags = 0;
1072 desc.componentFlagsMask = 0;
1075 Component
comp = FindNextComponent(NULL, &desc);
1078 Error(
"OpenAnalog: AudioComponentFindNext failed");
1085 Error(QString(
"OpenAnalog: AudioComponentInstanceNew returned %1")
1092 UInt32 size_hasIO =
sizeof(hasIO);
1094 kAudioOutputUnitProperty_HasIO,
1095 kAudioUnitScope_Output,
1097 &hasIO, &size_hasIO);
1098 Debug(QString(
"OpenAnalog: HasIO (output) = %1").arg(hasIO));
1101 UInt32 enableIO = 1;
1103 kAudioOutputUnitProperty_EnableIO,
1104 kAudioUnitScope_Global,
1106 &enableIO,
sizeof(enableIO));
1109 Warn(QString(
"OpenAnalog: failed enabling IO: %1")
1114 kAudioOutputUnitProperty_HasIO,
1115 kAudioUnitScope_Output,
1117 &hasIO, &size_hasIO);
1118 Debug(QString(
"HasIO = %1").arg(hasIO));
1128 kAudioOutputUnitProperty_CurrentDevice,
1129 kAudioUnitScope_Global,
1134 Error(QString(
"OpenAnalog: Unable to set current device to %1. Error = %2")
1141 UInt32 param_size =
sizeof(AudioStreamBasicDescription);
1144 kAudioUnitProperty_StreamFormat,
1145 kAudioUnitScope_Input,
1151 Warn(QString(
"OpenAnalog: Unable to retrieve current stream format: [%1]")
1156 Debug(QString(
"OpenAnalog: current format is: %1")
1161 kAudioDevicePropertyPreferredChannelLayout,
1162 kAudioUnitScope_Output,
1169 layout = (AudioChannelLayout *) malloc(param_size);
1172 kAudioDevicePropertyPreferredChannelLayout,
1173 kAudioUnitScope_Output,
1179 if(layout->mChannelLayoutTag == kAudioChannelLayoutTag_UseChannelBitmap)
1182 err = AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForBitmap,
1183 sizeof(UInt32), &layout->mChannelBitmap,
1187 Warn(
"OpenAnalog: Can't retrieve current channel layout");
1189 else if(layout->mChannelLayoutTag != kAudioChannelLayoutTag_UseChannelDescriptions )
1192 err = AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForTag,
1193 sizeof(AudioChannelLayoutTag),
1194 &layout->mChannelLayoutTag,
1198 Warn(
"OpenAnalog: Can't retrieve current channel layout");
1201 Debug(QString(
"OpenAnalog: Layout of AUHAL has %1 channels")
1202 .arg(layout->mNumberChannelDescriptions));
1204 int channels_found = 0;
1205 for(UInt32 i = 0; i < layout->mNumberChannelDescriptions; i++)
1207 Debug(QString(
"OpenAnalog: this is channel: %1")
1208 .arg(layout->mChannelDescriptions[i].mChannelLabel));
1210 switch( layout->mChannelDescriptions[i].mChannelLabel)
1212 case kAudioChannelLabel_Left:
1213 case kAudioChannelLabel_Right:
1214 case kAudioChannelLabel_Center:
1215 case kAudioChannelLabel_LFEScreen:
1216 case kAudioChannelLabel_LeftSurround:
1217 case kAudioChannelLabel_RightSurround:
1218 case kAudioChannelLabel_RearSurroundLeft:
1219 case kAudioChannelLabel_RearSurroundRight:
1220 case kAudioChannelLabel_CenterSurround:
1224 Debug(QString(
"unrecognized channel form provided by driver: %1")
1225 .arg(layout->mChannelDescriptions[i].mChannelLabel));
1228 if(channels_found == 0)
1230 Warn(
"Audio device is not configured. "
1231 "You should configure your speaker layout with "
1232 "the \"Audio Midi Setup\" utility in /Applications/"
1239 Warn(
"this driver does not support kAudioDevicePropertyPreferredChannelLayout.");
1242 memset (&new_layout, 0,
sizeof(new_layout));
1246 new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_Mono;
1249 new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
1253 new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_AudioUnit_5_1;
1258 new_layout.mChannelLayoutTag = kAudioChannelLayoutTag_MPEG_7_1_A;
1263 kAudioUnitProperty_AudioChannelLayout,
1264 kAudioUnitScope_Input,
1266 &new_layout,
sizeof(new_layout));
1269 Warn(QString(
"OpenAnalog: couldn't set channels layout [%1]")
1273 if(new_layout.mNumberChannelDescriptions > 0)
1274 free(new_layout.mChannelDescriptions);
1281 formatFlags = kLinearPCMFormatFlagIsSignedInteger;
1284 formatFlags = kLinearPCMFormatFlagIsFloat;
1287 formatFlags = kLinearPCMFormatFlagIsSignedInteger;
1291 AudioStreamBasicDescription conv_in_desc;
1292 memset(&conv_in_desc, 0,
sizeof(AudioStreamBasicDescription));
1294 conv_in_desc.mFormatID = kAudioFormatLinearPCM;
1295 conv_in_desc.mFormatFlags = formatFlags |
1296 kAudioFormatFlagsNativeEndian |
1297 kLinearPCMFormatFlagIsPacked;
1300 conv_in_desc.mFramesPerPacket = 1;
1303 conv_in_desc.mBitsPerChannel =
1308 kAudioUnitProperty_StreamFormat,
1309 kAudioUnitScope_Input,
1312 sizeof(AudioStreamBasicDescription));
1315 Error(QString(
"OpenAnalog: AudioUnitSetProperty returned [%1]")
1319 Debug(QString(
"OpenAnalog: set format as %1")
1323 kAudioUnitProperty_StreamFormat,
1324 kAudioUnitScope_Input,
1329 Debug(QString(
"OpenAnalog: the actual set AU format is %1")
1333 AURenderCallbackStruct input;
1335 input.inputProcRefCon =
this;
1338 kAudioUnitProperty_SetRenderCallback,
1339 kAudioUnitScope_Input,
1340 0, &input,
sizeof(input));
1343 Error(QString(
"OpenAnalog: AudioUnitSetProperty (callback) returned [%1]")
1350 ComponentResult res = AudioUnitInitialize(
mOutputUnit);
1353 Error(QString(
"OpenAnalog: AudioUnitInitialize error: [%1]")
1362 Error(QString(
"OpenAnalog: AudioOutputUnitStart error: [%1]")
1374 Debug(QString(
"CloseAnalog: Entering: %1")
1380 err = AudioOutputUnitStop(mOutputUnit);
1381 Debug(QString(
"CloseAnalog: AudioOutputUnitStop %1")
1386 err = AudioUnitUninitialize(mOutputUnit);
1387 Debug(QString(
"CloseAnalog: AudioUnitUninitialize %1")
1390 err = CloseComponent(mOutputUnit);
1391 Debug(QString(
"CloseAnalog: CloseComponent %1")
1404 AudioStreamID *streams;
1405 AudioStreamBasicDescription outputFormat = {0};
1407 Debug(
"OpenSPDIF: Entering");
1412 Warn(
"OpenSPDIF: Couldn't retrieve list of streams");
1416 for (
int i = 0; streams[i] != kAudioHardwareBadStreamError; ++i)
1423 for (
int j = 0; formats[j].mFormatID != 0; j++)
1425 Debug(QString(
"OpenSPDIF: Considering Physical Format: %1")
1427 if ((formats[j].mFormatID ==
'IAC3' ||
1428 formats[j].mFormatID == kAudioFormat60958AC3) &&
1431 Debug(
"OpenSPDIF: Found digital format");
1434 outputFormat = formats[j];
1440 if (outputFormat.mFormatID)
1445 if (!outputFormat.mFormatID)
1447 Error(QString(
"OpenSPDIF: Couldn't find suitable output"));
1456 err = AudioStreamGetProperty(
mStreamID, 0,
1457 kAudioStreamPropertyPhysicalFormat,
1461 Warn(QString(
"OpenSPDIF - could not retrieve the original streamformat: [%1]")
1462 .arg(OSS_STATUS(err)));
1495 Error(QString(
"OpenSPDIF: AudioDeviceAddIOProc failed: [%1]")
1496 .arg(OSS_STATUS(err)));
1502 err = AudioDeviceStart(
mDeviceID, (AudioDeviceIOProc)RenderCallbackSPDIF);
1505 Error(QString(
"OpenSPDIF: AudioDeviceStart failed: [%1]")
1506 .arg(OSS_STATUS(err)));
1526 Error(QString(
"CloseSPDIF: AudioDeviceStop failed: [%1]")
1527 .arg(OSS_STATUS(err)));
1534 err = AudioDeviceRemoveIOProc(
mDeviceID,
1537 Error(QString(
"CloseSPDIF: AudioDeviceRemoveIOProc failed: [%1]")
1538 .arg(OSS_STATUS(err)));
1551 AudioHardwareUnload();
1559 AudioStreamBasicDescription
format)
1561 Debug(QString(
"AudioStreamChangeFormat: %1 -> %2")
1565 OSStatus err = AudioStreamSetProperty(s, 0, 0,
1566 kAudioStreamPropertyPhysicalFormat,
1567 sizeof(format), &format);
1570 Error(QString(
"AudioStreamChangeFormat couldn't set stream format: [%1]")
1571 .arg(OSS_STATUS(err)));
1579 bool foundAC3Stream =
false;
1580 AudioStreamID *streams;
1588 for (
int i = 0; !foundAC3Stream &&
1589 streams[i] != kAudioHardwareBadStreamError; ++i)
1596 for (
int j = 0; formats[j].mFormatID != 0; j++)
1597 if (formats[j].mFormatID ==
'IAC3' ||
1598 formats[j].mFormatID == kAudioFormat60958AC3)
1600 Debug(
"FindAC3Stream: found digital format");
1601 foundAC3Stream =
true;
1609 return foundAC3Stream;
1618 AudioDeviceID *devices;
1623 AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &size, NULL);
1624 devices = (AudioDeviceID*)malloc(size);
1627 Error(
"ResetAudioDevices: out of memory?");
1630 numDevices = size /
sizeof(AudioDeviceID);
1631 AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &size, devices);
1633 for (
int i = 0; i < numDevices; i++)
1635 AudioStreamID *streams;
1640 for (
int j = 0; streams[j] != kAudioHardwareBadStreamError; j++)
1650 AudioStreamBasicDescription currentFormat;
1655 paramSize =
sizeof(currentFormat);
1656 AudioStreamGetProperty(s, 0, kAudioStreamPropertyPhysicalFormat,
1657 ¶mSize, ¤tFormat);
1660 if (currentFormat.mFormatID ==
'IAC3' ||
1661 currentFormat.mFormatID == kAudioFormat60958AC3)
1664 bool streamReset =
false;
1670 for (
int i = 0; !streamReset && formats[i].mFormatID != 0; i++)
1671 if (formats[i].mFormatID == kAudioFormatLinearPCM)
1673 err = AudioStreamSetProperty(s, NULL, 0,
1674 kAudioStreamPropertyPhysicalFormat,
1675 sizeof(formats[i]), &(formats[i]));
1678 Warn(QString(
"ResetStream: could not set physical format: [%1]")
1679 .arg(OSS_STATUS(err)));
1695 QMap<QString, QString> *devs =
new QMap<QString, QString>();
1699 AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &size, NULL);
1700 UInt32 deviceCount = size /
sizeof(AudioDeviceID);
1701 AudioDeviceID* pDevices =
new AudioDeviceID[deviceCount];
1702 OSStatus err = AudioHardwareGetProperty(kAudioHardwarePropertyDevices,
1705 VBAUDIO(QString(
"AudioOutputCA::GetDevices: Unable to retrieve the list of "
1706 "available devices. Error [%1]")
1710 VBAUDIO(QString(
"GetDevices: Number of devices: %1").arg(deviceCount));
1712 for (UInt32 dev = 0; dev < deviceCount; dev++)
1720 devs->insert(*name, QString());