diff --git a/src/CoreAudio/AudioToolbox/AudioComponentManager.mm b/src/CoreAudio/AudioToolbox/AudioComponentManager.mm
index 28619c78a..5a5f7c856 100644
--- a/src/CoreAudio/AudioToolbox/AudioComponentManager.mm
+++ b/src/CoreAudio/AudioToolbox/AudioComponentManager.mm
@@ -72,15 +72,19 @@ static bool isString(CFStringRef str)
static UInt32 stringToFourCC(CFStringRef str)
{
union {
- char chars[4];
+ char chars[5]; // CFStringGetCString requires space for the NUL character
uint32_t code;
} cc;
if (CFStringGetLength(str) != 4)
return 0;
- if (!CFStringGetCString(str, cc.chars, 4, kCFStringEncodingUTF8))
+ if (!CFStringGetCString(str, cc.chars, 5, kCFStringEncodingUTF8))
return 0;
+#if __LITTLE_ENDIAN__
+ cc.code = __builtin_bswap32(cc.code);
+#endif
+
return cc.code;
}
diff --git a/src/CoreAudio/CoreAudioComponent/CMakeLists.txt b/src/CoreAudio/CoreAudioComponent/CMakeLists.txt
index f6d2ea002..afd7a386e 100644
--- a/src/CoreAudio/CoreAudioComponent/CMakeLists.txt
+++ b/src/CoreAudio/CoreAudioComponent/CMakeLists.txt
@@ -29,6 +29,7 @@ set(component_sources
PublicUtility/CAVectorUnit.cpp
AUHAL.cpp
SystemOutputAU.cpp
+ DefaultOutputAU.cpp
)
add_darling_bundle(CoreAudioComponent "" ${component_sources})
diff --git a/src/CoreAudio/CoreAudioComponent/DefaultOutputAU.cpp b/src/CoreAudio/CoreAudioComponent/DefaultOutputAU.cpp
new file mode 100644
index 000000000..8b92b6c50
--- /dev/null
+++ b/src/CoreAudio/CoreAudioComponent/DefaultOutputAU.cpp
@@ -0,0 +1,54 @@
+/*
+This file is part of Darling.
+
+Copyright (C) 2020 Lubos Dolezel
+
+Darling is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Darling is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Darling. If not, see .
+*/
+#include "DefaultOutputAU.h"
+
+#pragma GCC visibility push(default)
+AUDIOCOMPONENT_ENTRY(AUOutputBaseFactory, DefaultOutputAU);
+#pragma GCC visibility pop
+
+enum {
+ kOutputBus = 0,
+ kInputBus
+};
+
+DefaultOutputAU::DefaultOutputAU(AudioComponentInstance inInstance)
+: AUHAL(inInstance)
+{
+}
+
+OSStatus DefaultOutputAU::GetPropertyInfo(AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, UInt32& outDataSize, Boolean& outWritable)
+{
+ OSStatus status = AUHAL::GetPropertyInfo(inID, inScope, inElement, outDataSize, outWritable);
+
+ if (inID == kAudioOutputUnitProperty_CurrentDevice)
+ outWritable = false;
+
+ return status;
+}
+
+OSStatus DefaultOutputAU::SetProperty(AudioUnitPropertyID inID, AudioUnitScope inScope,
+ AudioUnitElement inElement, const void* inData, UInt32 inDataSize)
+{
+ switch (inID)
+ {
+ case kAudioOutputUnitProperty_CurrentDevice:
+ return kAudioUnitErr_InvalidProperty;
+ }
+ return AUHAL::SetProperty(inID, inScope, inElement, inData, inDataSize);
+}
diff --git a/src/CoreAudio/CoreAudioComponent/DefaultOutputAU.h b/src/CoreAudio/CoreAudioComponent/DefaultOutputAU.h
new file mode 100644
index 000000000..9c9fab022
--- /dev/null
+++ b/src/CoreAudio/CoreAudioComponent/DefaultOutputAU.h
@@ -0,0 +1,32 @@
+/*
+This file is part of Darling.
+
+Copyright (C) 2020 Lubos Dolezel
+
+Darling is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Darling is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Darling. If not, see .
+*/
+
+#ifndef _CA_DEFAULT_OUTPUT_AU_H
+#define _CA_DEFAULT_OUTPUT_AU_H
+#include "AUHAL.h"
+
+class DefaultOutputAU : public AUHAL
+{
+public:
+ DefaultOutputAU(AudioComponentInstance inInstance);
+ OSStatus GetPropertyInfo(AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, UInt32& outDataSize, Boolean& outWritable) override;
+ OSStatus SetProperty(AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, const void* inData, UInt32 inDataSize) override;
+};
+
+#endif
diff --git a/src/CoreAudio/CoreAudioComponent/SystemOutputAU.cpp b/src/CoreAudio/CoreAudioComponent/SystemOutputAU.cpp
index 9b58205a5..49ff8a71d 100644
--- a/src/CoreAudio/CoreAudioComponent/SystemOutputAU.cpp
+++ b/src/CoreAudio/CoreAudioComponent/SystemOutputAU.cpp
@@ -34,6 +34,16 @@ SystemOutputAU::SystemOutputAU(AudioComponentInstance inInstance)
AudioHardwareGetProperty(kAudioHardwarePropertyDefaultSystemOutputDevice, &propSize, &m_outputDevice);
}
+OSStatus SystemOutputAU::GetPropertyInfo(AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, UInt32& outDataSize, Boolean& outWritable)
+{
+ OSStatus status = AUHAL::GetPropertyInfo(inID, inScope, inElement, outDataSize, outWritable);
+
+ if (inID == kAudioOutputUnitProperty_CurrentDevice)
+ outWritable = false;
+
+ return status;
+}
+
OSStatus SystemOutputAU::SetProperty(AudioUnitPropertyID inID, AudioUnitScope inScope,
AudioUnitElement inElement, const void* inData, UInt32 inDataSize)
{
diff --git a/src/CoreAudio/CoreAudioComponent/SystemOutputAU.h b/src/CoreAudio/CoreAudioComponent/SystemOutputAU.h
index 495ff5ea8..0c86b75a7 100644
--- a/src/CoreAudio/CoreAudioComponent/SystemOutputAU.h
+++ b/src/CoreAudio/CoreAudioComponent/SystemOutputAU.h
@@ -25,6 +25,7 @@ class SystemOutputAU : public AUHAL
{
public:
SystemOutputAU(AudioComponentInstance inInstance);
+ OSStatus GetPropertyInfo(AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, UInt32& outDataSize, Boolean& outWritable) override;
OSStatus SetProperty(AudioUnitPropertyID inID, AudioUnitScope inScope, AudioUnitElement inElement, const void* inData, UInt32 inDataSize) override;
};
diff --git a/src/CoreAudio/include/AudioToolbox/AudioComponent.h b/src/CoreAudio/include/AudioToolbox/AudioComponent.h
index bc236fb0e..5144b158a 100644
--- a/src/CoreAudio/include/AudioToolbox/AudioComponent.h
+++ b/src/CoreAudio/include/AudioToolbox/AudioComponent.h
@@ -23,7 +23,7 @@ along with Darling. If not, see .
#include
#include
-#ifndef __cplusplus
+#ifdef __cplusplus
extern "C" {
#endif
@@ -119,7 +119,7 @@ typedef UInt32 AudioComponentValidationResult;
OSStatus AudioComponentValidate(AudioComponent component, CFDictionaryRef validationParams, AudioComponentValidationResult* result);
-#ifndef __cplusplus
+#ifdef __cplusplus
}
#endif