Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openal-soft: fix build on 10.4-10.6 #12732

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions audio/openal-soft/Portfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ depends_build-append port:pkgconfig
depends_lib-append port:libmysofa \
port:zlib

patchfiles-append patch-openal-soft-coreaudio.diff
patchfiles-append patch-openal-soft-dispatch.diff

compiler.cxx_standard 2014
compiler.thread_local_storage yes

Expand All @@ -59,6 +62,11 @@ configure.args-append -DALSOFT_EXAMPLES=OFF \
-DALSOFT_REQUIRE_SDL2=OFF \
-DALSOFT_BACKEND_SDL2=OFF

if {${os.platform} eq "darwin" && ${os.major} <= 10} {
# alc/backends/coreaudio.cpp:627:13: warning: spurious trailing '%' in format [-Wformat=]
configure.cxxflags-append -D__STDC_FORMAT_MACROS=1
}

variant gui description {Enable alsoft-config Qt GUI} {
configure.args-replace -DALSOFT_NO_CONFIG_UTIL=ON -DALSOFT_NO_CONFIG_UTIL=OFF
}
Expand Down
127 changes: 127 additions & 0 deletions audio/openal-soft/files/patch-openal-soft-coreaudio.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
--- alc/backends/coreaudio.cpp.orig
+++ alc/backends/coreaudio.cpp
@@ -40,6 +40,13 @@
#include <AudioUnit/AudioUnit.h>
#include <AudioToolbox/AudioToolbox.h>

+#ifndef LEGACY_COREAUDIO
+#if (defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1060)
+#define LEGACY_COREAUDIO 1
+#else
+#define LEGACY_COREAUDIO 0
+#endif
+#endif

namespace {

@@ -77,7 +83,11 @@
CoreAudioPlayback::~CoreAudioPlayback()
{
AudioUnitUninitialize(mAudioUnit);
+#if LEGACY_COREAUDIO
+ CloseComponent(mAudioUnit);
+#else
AudioComponentInstanceDispose(mAudioUnit);
+#endif
}


@@ -103,7 +113,11 @@
name};

/* open the default output unit */
+#if LEGACY_COREAUDIO
+ ComponentDescription desc{};
+#else
AudioComponentDescription desc{};
+#endif
desc.componentType = kAudioUnitType_Output;
#if TARGET_OS_IOS
desc.componentSubType = kAudioUnitSubType_RemoteIO;
@@ -114,11 +128,19 @@
desc.componentFlags = 0;
desc.componentFlagsMask = 0;

+#if LEGACY_COREAUDIO
+ Component comp{FindNextComponent(NULL, &desc)};
+#else
AudioComponent comp{AudioComponentFindNext(NULL, &desc)};
+#endif
if(comp == nullptr)
throw al::backend_exception{al::backend_error::NoDevice, "Could not find audio component"};

+#if LEGACY_COREAUDIO
+ OSStatus err{OpenAComponent(comp, &mAudioUnit)};
+#else
OSStatus err{AudioComponentInstanceNew(comp, &mAudioUnit)};
+#endif
if(err != noErr)
throw al::backend_exception{al::backend_error::NoDevice,
"Could not create component instance: %u", err};
@@ -329,7 +351,11 @@
CoreAudioCapture::~CoreAudioCapture()
{
if(mAudioUnit)
+#if LEGACY_COREAUDIO
+ CloseComponent(mAudioUnit);
+#else
AudioComponentInstanceDispose(mAudioUnit);
+#endif
mAudioUnit = 0;
}

@@ -387,10 +413,18 @@
AudioStreamBasicDescription hardwareFormat; // The hardware format
AudioStreamBasicDescription outputFormat; // The AudioUnit output format
AURenderCallbackStruct input;
+#if LEGACY_COREAUDIO
+ ComponentDescription desc;
+#else
AudioComponentDescription desc;
+#endif
UInt32 propertySize;
UInt32 enableIO;
+#if LEGACY_COREAUDIO
+ Component comp;
+#else
AudioComponent comp;
+#endif
OSStatus err;

if(!name)
@@ -410,12 +444,20 @@
desc.componentFlagsMask = 0;

// Search for component with given description
+#if LEGACY_COREAUDIO
+ comp = FindNextComponent(NULL, &desc);
+#else
comp = AudioComponentFindNext(NULL, &desc);
+#endif
if(comp == NULL)
throw al::backend_exception{al::backend_error::NoDevice, "Could not find audio component"};

// Open the component
+#if LEGACY_COREAUDIO
+ err = OpenAComponent(comp, &mAudioUnit);
+#else
err = AudioComponentInstanceNew(comp, &mAudioUnit);
+#endif
if(err != noErr)
throw al::backend_exception{al::backend_error::NoDevice,
"Could not create component instance: %u", err};
@@ -475,12 +517,14 @@
"Could not set capture callback: %u", err};

// Disable buffer allocation for capture
+#if !LEGACY_COREAUDIO
UInt32 flag{0};
err = AudioUnitSetProperty(mAudioUnit, kAudioUnitProperty_ShouldAllocateBuffer,
kAudioUnitScope_Output, 1, &flag, sizeof(flag));
if(err != noErr)
throw al::backend_exception{al::backend_error::DeviceError,
"Could not disable buffer allocation property: %u", err};
+#endif

// Initialize the device
err = AudioUnitInitialize(mAudioUnit);
70 changes: 70 additions & 0 deletions audio/openal-soft/files/patch-openal-soft-dispatch.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
--- CMakeLists.txt.orig
+++ CMakeLists.txt
@@ -478,6 +478,7 @@
if(NOT HAVE_GUIDDEF_H)
check_include_file(initguid.h HAVE_INITGUID_H)
endif()
+check_include_file(dispatch/dispatch.h HAVE_DISPATCH_H)

# Some systems need libm for some math functions to work
set(MATH_LIB )
--- config.h.in.orig
+++ config.h.in
@@ -92,6 +92,9 @@
/* Define if we have initguid.h */
#cmakedefine HAVE_INITGUID_H

+/* Define if we have dispatch.h */
+#cmakedefine HAVE_DISPATCH_H
+
/* Define if we have GCC's __get_cpuid() */
#cmakedefine HAVE_GCC_GET_CPUID

--- common/threads.h.orig
+++ common/threads.h
@@ -11,7 +11,7 @@
#define FORCE_ALIGN
#endif

-#if defined(__APPLE__)
+#if defined(HAVE_DISPATCH_H)
#include <dispatch/dispatch.h>
#elif !defined(_WIN32)
#include <semaphore.h>
@@ -24,7 +24,7 @@
class semaphore {
#ifdef _WIN32
using native_type = void*;
-#elif defined(__APPLE__)
+#elif defined(HAVE_DISPATCH_H)
using native_type = dispatch_semaphore_t;
#else
using native_type = sem_t;
--- common/threads.cpp.orig
+++ common/threads.cpp
@@ -114,7 +114,7 @@
void althrd_setname(const char*) { }
#endif

-#ifdef __APPLE__
+#ifdef HAVE_DISPATCH_H

namespace al {

@@ -139,7 +139,7 @@

} // namespace al

-#else /* !__APPLE__ */
+#else /* !HAVE_DISPATCH_H */

#include <cerrno>

@@ -171,6 +171,6 @@

} // namespace al

-#endif /* __APPLE__ */
+#endif /* HAVE_DISPATCH_H */

#endif /* _WIN32 */